Search in sources :

Example 6 with Repo

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