From 953a81b2992a338199c873e1e85fc81ba150e37d Mon Sep 17 00:00:00 2001 From: tonymanou Date: Mon, 9 Jan 2017 20:34:17 +0100 Subject: [PATCH] Extract getItem() method from onBindViewHolder() --- .../magisk/adapters/ReposAdapter.java | 28 +++++++++++-------- 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/app/src/main/java/com/topjohnwu/magisk/adapters/ReposAdapter.java b/app/src/main/java/com/topjohnwu/magisk/adapters/ReposAdapter.java index 6bd4a668e..d05e26f65 100644 --- a/app/src/main/java/com/topjohnwu/magisk/adapters/ReposAdapter.java +++ b/app/src/main/java/com/topjohnwu/magisk/adapters/ReposAdapter.java @@ -49,18 +49,8 @@ public class ReposAdapter extends RecyclerView.Adapter @Override public void onBindViewHolder(final ViewHolder holder, int position) { Context context = holder.itemView.getContext(); - final Repo repo; - if (position >= mUpdateRepos.size()) { - position -= mUpdateRepos.size(); - if (position >= mInstalledRepos.size()) { - position -= mInstalledRepos.size(); - repo = mOthersRepos.get(position); - } else { - repo = mInstalledRepos.get(position); - } - } else { - repo = mUpdateRepos.get(position); - } + Repo repo = getItem(position); + holder.title.setText(repo.getName()); String author = repo.getAuthor(); String versionName = repo.getVersion(); @@ -122,6 +112,20 @@ public class ReposAdapter extends RecyclerView.Adapter return mUpdateRepos.size() + mInstalledRepos.size() + mOthersRepos.size(); } + private Repo getItem(int position) { + if (position >= mUpdateRepos.size()) { + position -= mUpdateRepos.size(); + if (position >= mInstalledRepos.size()) { + position -= mInstalledRepos.size(); + return mOthersRepos.get(position); + } else { + return mInstalledRepos.get(position); + } + } else { + return mUpdateRepos.get(position); + } + } + static class ViewHolder extends RecyclerView.ViewHolder { @BindView(R.id.title) TextView title;