Search in sources :

Example 1 with RAction

use of io.github.mthli.Bitocle.Database.Repo.RAction 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 RAction

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

the class MainActivity method logoutAction.

private void logoutAction() {
    RAction rAction = new RAction(MainActivity.this);
    BAction bAction = new BAction(MainActivity.this);
    try {
        rAction.openDatabase(true);
        bAction.openDatabase(true);
        rAction.deleteAll();
        bAction.unMarkAll();
        rAction.closeDatabase();
        bAction.closeDatabase();
    } catch (SQLException s) {
        rAction.closeDatabase();
        bAction.closeDatabase();
        SuperToast.create(MainActivity.this, getString(R.string.main_logout_failed), SuperToast.Duration.VERY_SHORT, Style.getStyle(Style.RED)).show();
    }
    SharedPreferences preferences = getSharedPreferences(getString(R.string.login_sp), MODE_PRIVATE);
    SharedPreferences.Editor editor = preferences.edit();
    editor.remove(getString(R.string.login_sp_oauth));
    editor.remove(getString(R.string.login_sp_username));
    editor.remove(getString(R.string.login_sp_highlight_num));
    editor.remove(getString(R.string.login_sp_highlight_css));
    editor.commit();
    fragment.allTaskDown();
    Intent intent = new Intent(MainActivity.this, LoginActivity.class);
    startActivity(intent);
    MainActivity.this.finish();
}
Also used : SQLException(android.database.SQLException) SharedPreferences(android.content.SharedPreferences) BAction(io.github.mthli.Bitocle.Database.Bookmark.BAction) Intent(android.content.Intent) RAction(io.github.mthli.Bitocle.Database.Repo.RAction)

Example 3 with RAction

use of io.github.mthli.Bitocle.Database.Repo.RAction 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 4 with RAction

use of io.github.mthli.Bitocle.Database.Repo.RAction 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 5 with RAction

use of io.github.mthli.Bitocle.Database.Repo.RAction 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)

Aggregations

SQLException (android.database.SQLException)8 RAction (io.github.mthli.Bitocle.Database.Repo.RAction)8 Repo (io.github.mthli.Bitocle.Database.Repo.Repo)6 Activity (android.app.Activity)3 LayoutInflater (android.view.LayoutInflater)3 View (android.view.View)3 MenuItem (android.view.MenuItem)2 SimpleAdapter (android.widget.SimpleAdapter)2 BAction (io.github.mthli.Bitocle.Database.Bookmark.BAction)2 IOException (java.io.IOException)2 SimpleDateFormat (java.text.SimpleDateFormat)2 Repository (org.eclipse.egit.github.core.Repository)2 Intent (android.content.Intent)1 SharedPreferences (android.content.SharedPreferences)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1