Swap data instead of create new adapter in dapps and profile recycler views
This commit is contained in:
parent
e02c8b2714
commit
9aa9a865d0
|
@ -93,6 +93,7 @@ public abstract class BaseActivity extends AppCompatActivity implements
|
|||
}
|
||||
};
|
||||
private ImageView mHeaderImageView;
|
||||
private DAppDrawerAdapter mDAppsDrawerAdapter;
|
||||
|
||||
protected abstract void onDAppClick(Dapp dapp);
|
||||
|
||||
|
@ -138,15 +139,19 @@ public abstract class BaseActivity extends AppCompatActivity implements
|
|||
mFrontView = findViewById(R.id.ll_front_view);
|
||||
mBackView = findViewById(R.id.ll_back_view);
|
||||
|
||||
mProfilesRecyclerView = (RecyclerView) findViewById(R.id.accounts_drawer_recycler_view);
|
||||
mProfilesRecyclerView = (RecyclerView) findViewById(R.id.profile_drawer_recycler_view);
|
||||
RecyclerView.LayoutManager layoutManager2 = new LinearLayoutManager(this);
|
||||
mProfilesRecyclerView.setLayoutManager(layoutManager2);
|
||||
mProfileDrawerAdapter = new ProfileDrawerAdapter(this, new ArrayList<Profile>(), this);
|
||||
mProfilesRecyclerView.setAdapter(mProfileDrawerAdapter);
|
||||
populateProfiles();
|
||||
|
||||
mDAppsRecyclerView = (RecyclerView) findViewById(R.id.dapd_drawer_recycler_view);
|
||||
mDAppsRecyclerView = (RecyclerView) findViewById(R.id.dapp_drawer_recycler_view);
|
||||
mDAppsRecyclerView.setHasFixedSize(true);
|
||||
RecyclerView.LayoutManager layoutManager1 = new LinearLayoutManager(this);
|
||||
mDAppsRecyclerView.setLayoutManager(layoutManager1);
|
||||
mDAppsDrawerAdapter = new DAppDrawerAdapter(new ArrayList<Dapp>(), this);
|
||||
mDAppsRecyclerView.setAdapter(mDAppsDrawerAdapter);
|
||||
populateDApps();
|
||||
|
||||
mHeaderImageView = (ImageView) findViewById(R.id.iv_header);
|
||||
|
@ -157,8 +162,7 @@ public abstract class BaseActivity extends AppCompatActivity implements
|
|||
}
|
||||
|
||||
private void populateProfiles() {
|
||||
mProfileDrawerAdapter = new ProfileDrawerAdapter(this, ProfileManager.getProfiles(), this);
|
||||
mProfilesRecyclerView.setAdapter(mProfileDrawerAdapter);
|
||||
mProfileDrawerAdapter.swapData(ProfileManager.getProfiles());
|
||||
updateCurrentProfileName();
|
||||
}
|
||||
|
||||
|
@ -249,8 +253,7 @@ public abstract class BaseActivity extends AppCompatActivity implements
|
|||
dapps.add(item);
|
||||
}
|
||||
}
|
||||
DAppDrawerAdapter mDAppsDrawerAdapter = new DAppDrawerAdapter(dapps, this);
|
||||
mDAppsRecyclerView.setAdapter(mDAppsDrawerAdapter);
|
||||
mDAppsDrawerAdapter.swapData(dapps);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -99,7 +99,6 @@ public class DAppDrawerAdapter extends RecyclerView.Adapter<RecyclerView.ViewHol
|
|||
}
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -137,6 +136,12 @@ public class DAppDrawerAdapter extends RecyclerView.Adapter<RecyclerView.ViewHol
|
|||
notifyDataSetChanged();
|
||||
}
|
||||
|
||||
public void swapData(List<Dapp> items) {
|
||||
mDataSet.clear();
|
||||
mDataSet.addAll(items);
|
||||
notifyDataSetChanged();
|
||||
}
|
||||
|
||||
static class SimpleViewHolder extends RecyclerView.ViewHolder {
|
||||
|
||||
private TextView nameTextView;
|
||||
|
@ -171,4 +176,5 @@ public class DAppDrawerAdapter extends RecyclerView.Adapter<RecyclerView.ViewHol
|
|||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -8,7 +8,7 @@
|
|||
|
||||
|
||||
<android.support.v7.widget.RecyclerView
|
||||
android:id="@+id/accounts_drawer_recycler_view"
|
||||
android:id="@+id/profile_drawer_recycler_view"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="0dp"
|
||||
android:layout_weight="1"
|
||||
|
|
|
@ -45,7 +45,7 @@
|
|||
</RelativeLayout>
|
||||
|
||||
<android.support.v7.widget.RecyclerView
|
||||
android:id="@+id/dapd_drawer_recycler_view"
|
||||
android:id="@+id/dapp_drawer_recycler_view"
|
||||
tools:listitem="@layout/simple_list_item"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
|
|
Loading…
Reference in New Issue