Search in sources :

Example 31 with SQLException

use of android.database.SQLException 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 32 with SQLException

use of android.database.SQLException 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 33 with SQLException

use of android.database.SQLException 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 34 with SQLException

use of android.database.SQLException 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)

Example 35 with SQLException

use of android.database.SQLException in project Bitocle by mthli.

the class StarItemAdapter method getView.

@Override
public View getView(final int position, final View convertView, ViewGroup viewGroup) {
    Holder holder;
    View view = convertView;
    if (view == null) {
        LayoutInflater inflater = ((Activity) context).getLayoutInflater();
        view = inflater.inflate(layoutResId, viewGroup, false);
        holder = new Holder();
        holder.icon = (ImageView) view.findViewById(R.id.repo_item_icon);
        holder.name = (TextView) view.findViewById(R.id.repo_item_name);
        holder.date = (TextView) view.findViewById(R.id.repo_item_date);
        holder.description = (TextView) view.findViewById(R.id.repo_item_description);
        holder.info = (TextView) view.findViewById(R.id.repo_item_info);
        holder.owner = (TextView) view.findViewById(R.id.repo_item_owner);
        holder.overflow = (ImageButton) view.findViewById(R.id.repo_item_overflow);
        view.setTag(holder);
    } else {
        holder = (Holder) view.getTag();
    }
    final StarItem starItem = list.get(position);
    holder.icon.setImageDrawable(context.getResources().getDrawable(R.drawable.ic_type_repo));
    holder.name.setText(starItem.getName());
    holder.date.setText(starItem.getDate());
    String description;
    try {
        description = starItem.getDescription();
        if (description.length() == 0) {
            description = context.getString(R.string.repo_empty_description);
        }
    } catch (NullPointerException n) {
        description = context.getString(R.string.repo_empty_description);
    }
    holder.description.setText(description);
    String lang;
    try {
        lang = starItem.getLang();
        if (lang.equals("null")) {
            lang = context.getString(R.string.repo_item_unknown);
        }
    } catch (NullPointerException n) {
        lang = context.getString(R.string.repo_item_unknown);
    }
    holder.info.setText(lang + "   " + context.getString(R.string.repo_item_star) + " " + starItem.getStar() + "   " + context.getString(R.string.repo_item_fork) + " " + starItem.getFork());
    holder.owner.setText(starItem.getOwner());
    final PopupMenu menu = new PopupMenu(context, holder.overflow);
    menu.getMenuInflater().inflate(R.menu.star_item_overflow, menu.getMenu());
    holder.overflow.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            menu.show();
        }
    });
    menu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {

        @Override
        public boolean onMenuItemClick(MenuItem item) {
            switch(item.getItemId()) {
                case R.id.star_item_overflow_commit:
                    fragment.setLocation(position);
                    fragment.changeToCommit(Flag.STAR_COMMIT_FIRST);
                    break;
                case R.id.star_item_overflow_add:
                    RAction action = new RAction(context);
                    try {
                        action.openDatabase(true);
                    } catch (SQLException s) {
                        action.closeDatabase();
                        SuperToast.create(context, context.getString(R.string.overflow_add_failed), SuperToast.Duration.VERY_SHORT, Style.getStyle(Style.RED)).show();
                        return false;
                    }
                    if (!action.checkRepo(starItem.getGit())) {
                        Repo repo = new Repo();
                        repo.setName(starItem.getName());
                        repo.setDate(starItem.getDate());
                        repo.setDescription(starItem.getDescription());
                        if (starItem.getLang() == null) {
                            repo.setLang(context.getString(R.string.repo_item_unknown));
                        } else {
                            repo.setLang(starItem.getLang());
                        }
                        repo.setStar(starItem.getStar());
                        repo.setFork(starItem.getFork());
                        repo.setOwner(starItem.getOwner());
                        repo.setGit(starItem.getGit());
                        action.addRepo(repo);
                    }
                    action.closeDatabase();
                    SuperToast.create(context, context.getString(R.string.overflow_add_successful), SuperToast.Duration.VERY_SHORT, Style.getStyle(Style.BLUE)).show();
                    break;
                default:
                    break;
            }
            //
            return true;
        }
    });
    return view;
}
Also used : SQLException(android.database.SQLException) Activity(android.app.Activity) MenuItem(android.view.MenuItem) View(android.view.View) Repo(io.github.mthli.Bitocle.Database.Repo.Repo) LayoutInflater(android.view.LayoutInflater) RAction(io.github.mthli.Bitocle.Database.Repo.RAction)

Aggregations

SQLException (android.database.SQLException)224 ContentValues (android.content.ContentValues)114 Uri (android.net.Uri)60 Cursor (android.database.Cursor)57 SQLiteDatabase (android.database.sqlite.SQLiteDatabase)39 SQLiteException (android.database.sqlite.SQLiteException)18 Intent (android.content.Intent)16 ArrayList (java.util.ArrayList)14 SQLiteStatement (android.database.sqlite.SQLiteStatement)13 HandlerThread (android.os.HandlerThread)10 DatabaseUtils (android.database.DatabaseUtils)8 Gson (com.google.gson.Gson)8 RAction (io.github.mthli.Bitocle.Database.Repo.RAction)7 Repo (io.github.mthli.Bitocle.Database.Repo.Repo)6 SQLiteOpenHelper (android.database.sqlite.SQLiteOpenHelper)5 ContactDetail (com.vodafone360.people.datatypes.ContactDetail)5 IOException (java.io.IOException)5 BAction (io.github.mthli.Bitocle.Database.Bookmark.BAction)4 Test (org.junit.Test)4 Activity (android.app.Activity)3