Search in sources :

Example 1 with Repo

use of io.github.mthli.Bitocle.Database.Repo.Repo in project Bitocle by mthli.

the class WatchItemAdapter method getView.

@Override
public View getView(final int position, final View convertView, ViewGroup viewGroup) {
    Holder holder;
    View view = convertView;
    if (view == null) {
        LayoutInflater layoutInflater = ((Activity) context).getLayoutInflater();
        view = layoutInflater.inflate(layoutResId, viewGroup, false);
        holder = new Holder();
        holder.icon = (ImageView) view.findViewById(R.id.watch_item_icon);
        holder.title = (TextView) view.findViewById(R.id.watch_item_title);
        holder.date = (TextView) view.findViewById(R.id.watch_item_date);
        holder.content = (TextView) view.findViewById(R.id.watch_item_content);
        holder.info = (TextView) view.findViewById(R.id.watch_item_info);
        holder.add = (ImageButton) view.findViewById(R.id.watch_item_add);
        view.setTag(holder);
    } else {
        holder = (Holder) view.getTag();
    }
    if (watchItemList.size() > 0) {
        final WatchItem watchItem = watchItemList.get(position);
        holder.icon.setImageDrawable(watchItem.getIcon());
        holder.title.setText(watchItem.getTitle());
        holder.date.setText(watchItem.getDate());
        holder.content.setText(watchItem.getContent());
        holder.info.setText(watchItem.getInfo());
        holder.add.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                mainFragment.getActionMenu().close(true);
                RAction rAction = new RAction(context);
                try {
                    rAction.openDatabase(true);
                } catch (SQLException s) {
                    rAction.closeDatabase();
                    return;
                }
                if (!rAction.checkRepo(watchItem.getGit())) {
                    Repo repo = new Repo();
                    repo.setTitle(watchItem.getTitle());
                    repo.setDate(watchItem.getDate());
                    repo.setContent(watchItem.getContent());
                    repo.setInfo(watchItem.getInfo());
                    repo.setOwner(watchItem.getOwner());
                    repo.setGit(watchItem.getGit());
                    rAction.addRepo(repo);
                }
                rAction.closeDatabase();
                Toast.makeText(context, context.getString(R.string.watch_word_pin) + " " + watchItem.getTitle(), Toast.LENGTH_SHORT).show();
            }
        });
    }
    return view;
}
Also used : Repo(io.github.mthli.Bitocle.Database.Repo.Repo) SQLException(android.database.SQLException) LayoutInflater(android.view.LayoutInflater) Activity(android.app.Activity) RAction(io.github.mthli.Bitocle.Database.Repo.RAction) View(android.view.View)

Example 2 with Repo

use of io.github.mthli.Bitocle.Database.Repo.Repo in project Bitocle by mthli.

the class AddTask method onPostExecute.

@Override
protected void onPostExecute(Boolean result) {
    pull.setRefreshing(false);
    if (result) {
        RAction action = new RAction(context);
        try {
            action.openDatabase(true);
        } catch (SQLException s) {
            SuperToast.create(fragment.getActivity(), context.getString(R.string.repo_add_failed), SuperToast.Duration.VERY_SHORT, Style.getStyle(Style.RED)).show();
            return;
        }
        List<Repo> repos = action.listRepos();
        Collections.sort(repos);
        List<Map<String, String>> autoList = new ArrayList<Map<String, String>>();
        list.clear();
        autoList.clear();
        for (Repo r : repos) {
            list.add(new RepoItem(r.getName(), r.getDate(), r.getDescription(), r.getLang(), r.getStar(), r.getFork(), r.getOwner(), r.getGit()));
            Map<String, String> map = new HashMap<String, String>();
            map.put("owner", r.getOwner());
            map.put("name", r.getName());
            autoList.add(map);
        }
        action.closeDatabase();
        SimpleAdapter autoAdapter = new SimpleAdapter(context, autoList, R.layout.auto_item, new String[] { "owner", "name" }, new int[] { R.id.auto_item_owner, R.id.auto_item_name });
        autoAdapter.notifyDataSetChanged();
        fragment.getSearch().setAdapter(autoAdapter);
        if (list.size() <= 0) {
            fragment.setContentEmpty(true);
            fragment.setEmptyText(R.string.repo_empty_list);
            fragment.setContentShown(true);
        } else {
            int position = 0;
            for (RepoItem r : list) {
                if (r.getGit().equals(git)) {
                    break;
                }
                position++;
            }
            fragment.setContentEmpty(false);
            adapter.notifyDataSetChanged();
            fragment.setContentShown(true);
            listView.smoothScrollToPosition(position);
            SuperToast.create(fragment.getActivity(), context.getString(R.string.repo_add_successful), SuperToast.Duration.VERY_SHORT, Style.getStyle(Style.BLUE)).show();
        }
    } else {
        SuperToast.create(fragment.getActivity(), context.getString(R.string.repo_add_failed), SuperToast.Duration.VERY_SHORT, Style.getStyle(Style.RED)).show();
    }
}
Also used : SQLException(android.database.SQLException) SimpleAdapter(android.widget.SimpleAdapter) Repo(io.github.mthli.Bitocle.Database.Repo.Repo) RAction(io.github.mthli.Bitocle.Database.Repo.RAction)

Example 3 with Repo

use of io.github.mthli.Bitocle.Database.Repo.Repo in project Bitocle by mthli.

the class AddTask method doInBackground.

@Override
protected Boolean doInBackground(Void... params) {
    String[] arr = query.split("/");
    if (arr.length < 2) {
        return false;
    }
    String owner = arr[0].toLowerCase();
    String name = arr[1].toLowerCase();
    Repository r;
    try {
        r = service.getRepository(owner, name);
    } catch (IOException i) {
        return false;
    }
    if (isCancelled()) {
        return false;
    }
    RAction action = new RAction(context);
    try {
        action.openDatabase(true);
    } catch (SQLException s) {
        action.closeDatabase();
        return false;
    }
    SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
    if (!action.checkRepo(r.getGitUrl())) {
        Repo repo = new Repo();
        repo.setName(r.getName());
        repo.setDate(format.format(r.getCreatedAt()));
        repo.setDescription(r.getDescription());
        repo.setLang(r.getLanguage());
        repo.setStar(r.getWatchers());
        repo.setFork(r.getForks());
        repo.setOwner(r.getOwner().getLogin());
        repo.setGit(r.getGitUrl());
        git = r.getGitUrl();
        action.addRepo(repo);
    }
    action.closeDatabase();
    if (isCancelled()) {
        return false;
    }
    return true;
}
Also used : Repository(org.eclipse.egit.github.core.Repository) Repo(io.github.mthli.Bitocle.Database.Repo.Repo) SQLException(android.database.SQLException) IOException(java.io.IOException) RAction(io.github.mthli.Bitocle.Database.Repo.RAction) SimpleDateFormat(java.text.SimpleDateFormat)

Example 4 with Repo

use of io.github.mthli.Bitocle.Database.Repo.Repo in project Bitocle by mthli.

the class RepoTask method onPostExecute.

@Override
protected void onPostExecute(Boolean result) {
    if (result) {
        RAction action = new RAction(context);
        try {
            action.openDatabase(true);
        } catch (SQLException s) {
            fragment.setContentEmpty(true);
            fragment.setEmptyText(R.string.repo_empty_error);
            fragment.setContentShown(true);
            return;
        }
        List<Repo> repos = action.listRepos();
        Collections.sort(repos);
        List<Map<String, String>> autoList = new ArrayList<Map<String, String>>();
        list.clear();
        autoList.clear();
        for (Repo r : repos) {
            list.add(new RepoItem(r.getName(), r.getDate(), r.getDescription(), r.getLang(), r.getStar(), r.getFork(), r.getOwner(), r.getGit()));
            Map<String, String> map = new HashMap<String, String>();
            map.put("owner", r.getOwner());
            map.put("name", r.getName());
            autoList.add(map);
        }
        action.closeDatabase();
        SimpleAdapter autoAdapter = new SimpleAdapter(context, autoList, R.layout.auto_item, new String[] { "owner", "name" }, new int[] { R.id.auto_item_owner, R.id.auto_item_name });
        autoAdapter.notifyDataSetChanged();
        fragment.getSearch().setAdapter(autoAdapter);
        if (list.size() <= 0) {
            fragment.setContentEmpty(true);
            fragment.setEmptyText(R.string.repo_empty_list);
            fragment.setContentShown(true);
        } else {
            fragment.setContentEmpty(false);
            adapter.notifyDataSetChanged();
            fragment.setContentShown(true);
        }
        if (flag == Flag.REPO_REFRESH) {
            SuperToast.create(context, context.getString(R.string.repo_refresh_successful), SuperToast.Duration.VERY_SHORT, Style.getStyle(Style.BLUE)).show();
        }
    } else {
        fragment.setContentEmpty(true);
        fragment.setEmptyText(R.string.repo_empty_error);
        fragment.setContentShown(true);
    }
}
Also used : Repo(io.github.mthli.Bitocle.Database.Repo.Repo) SQLException(android.database.SQLException) SimpleAdapter(android.widget.SimpleAdapter) RAction(io.github.mthli.Bitocle.Database.Repo.RAction)

Example 5 with Repo

use of io.github.mthli.Bitocle.Database.Repo.Repo in project Bitocle by mthli.

the class RepoTask method doInBackground.

@Override
protected Boolean doInBackground(Void... params) {
    if (flag == Flag.REPO_FIRST) {
        RAction action = new RAction(context);
        try {
            action.openDatabase(true);
        } catch (SQLException s) {
            action.closeDatabase();
            return false;
        }
        List<Repository> repositories;
        try {
            repositories = service.getRepositories();
        } catch (IOException i) {
            action.closeDatabase();
            return false;
        }
        if (isCancelled()) {
            action.closeDatabase();
            return false;
        }
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
        if (flag == Flag.REPO_FIRST) {
            for (Repository r : repositories) {
                if (!action.checkRepo(r.getGitUrl())) {
                    Repo repo = new Repo();
                    repo.setName(r.getName());
                    repo.setDate(format.format(r.getCreatedAt()));
                    repo.setDescription(r.getDescription());
                    repo.setLang(r.getLanguage());
                    repo.setStar(r.getWatchers());
                    repo.setFork(r.getForks());
                    repo.setOwner(r.getOwner().getLogin());
                    repo.setGit(r.getGitUrl());
                    action.addRepo(repo);
                }
            }
        }
        action.closeDatabase();
    }
    if (isCancelled()) {
        return false;
    }
    return true;
}
Also used : Repository(org.eclipse.egit.github.core.Repository) Repo(io.github.mthli.Bitocle.Database.Repo.Repo) SQLException(android.database.SQLException) RAction(io.github.mthli.Bitocle.Database.Repo.RAction) IOException(java.io.IOException) SimpleDateFormat(java.text.SimpleDateFormat)

Aggregations

SQLException (android.database.SQLException)6 RAction (io.github.mthli.Bitocle.Database.Repo.RAction)6 Repo (io.github.mthli.Bitocle.Database.Repo.Repo)6 Activity (android.app.Activity)2 LayoutInflater (android.view.LayoutInflater)2 View (android.view.View)2 SimpleAdapter (android.widget.SimpleAdapter)2 IOException (java.io.IOException)2 SimpleDateFormat (java.text.SimpleDateFormat)2 Repository (org.eclipse.egit.github.core.Repository)2 MenuItem (android.view.MenuItem)1