mirror of
https://github.com/android10/Android-CleanArchitecture.git
synced 2026-03-13 10:13:41 +08:00
Inject UserListAdapter. Minor refactor and clean up.
This commit is contained in:
@@ -15,7 +15,9 @@ import butterknife.ButterKnife;
|
||||
import com.fernandocejas.android10.sample.presentation.R;
|
||||
import com.fernandocejas.android10.sample.presentation.model.UserModel;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import javax.inject.Inject;
|
||||
|
||||
/**
|
||||
* Adaptar that manages a collection of {@link UserModel}.
|
||||
@@ -31,11 +33,11 @@ public class UsersAdapter extends RecyclerView.Adapter<UsersAdapter.UserViewHold
|
||||
|
||||
private OnItemClickListener onItemClickListener;
|
||||
|
||||
public UsersAdapter(Context context, Collection<UserModel> usersCollection) {
|
||||
this.validateUsersCollection(usersCollection);
|
||||
@Inject
|
||||
public UsersAdapter(Context context) {
|
||||
this.layoutInflater =
|
||||
(LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
||||
this.usersCollection = (List<UserModel>) usersCollection;
|
||||
this.usersCollection = Collections.emptyList();
|
||||
}
|
||||
|
||||
@Override public int getItemCount() {
|
||||
@@ -43,10 +45,8 @@ public class UsersAdapter extends RecyclerView.Adapter<UsersAdapter.UserViewHold
|
||||
}
|
||||
|
||||
@Override public UserViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
|
||||
View view = this.layoutInflater.inflate(R.layout.row_user, parent, false);
|
||||
UserViewHolder userViewHolder = new UserViewHolder(view);
|
||||
|
||||
return userViewHolder;
|
||||
final View view = this.layoutInflater.inflate(R.layout.row_user, parent, false);
|
||||
return new UserViewHolder(view);
|
||||
}
|
||||
|
||||
@Override public void onBindViewHolder(UserViewHolder holder, final int position) {
|
||||
|
||||
@@ -30,8 +30,6 @@ public class UserDetailsFragment extends BaseFragment implements UserDetailsView
|
||||
|
||||
private static final String ARGUMENT_KEY_USER_ID = "org.android10.ARGUMENT_USER_ID";
|
||||
|
||||
private int userId;
|
||||
|
||||
@Inject UserDetailsPresenter userDetailsPresenter;
|
||||
|
||||
@Bind(R.id.iv_cover) AutoLoadImageView iv_cover;
|
||||
@@ -70,7 +68,6 @@ public class UserDetailsFragment extends BaseFragment implements UserDetailsView
|
||||
@Override public void onViewCreated(View view, Bundle savedInstanceState) {
|
||||
super.onViewCreated(view, savedInstanceState);
|
||||
this.userDetailsPresenter.setView(this);
|
||||
this.userId = getArguments().getInt(ARGUMENT_KEY_USER_ID);
|
||||
this.userDetailsPresenter.initialize();
|
||||
}
|
||||
|
||||
|
||||
@@ -24,7 +24,6 @@ import com.fernandocejas.android10.sample.presentation.presenter.UserListPresent
|
||||
import com.fernandocejas.android10.sample.presentation.view.UserListView;
|
||||
import com.fernandocejas.android10.sample.presentation.view.adapter.UsersAdapter;
|
||||
import com.fernandocejas.android10.sample.presentation.view.adapter.UsersLayoutManager;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import javax.inject.Inject;
|
||||
|
||||
@@ -41,15 +40,13 @@ public class UserListFragment extends BaseFragment implements UserListView {
|
||||
}
|
||||
|
||||
@Inject UserListPresenter userListPresenter;
|
||||
@Inject UsersAdapter usersAdapter;
|
||||
|
||||
@Bind(R.id.rv_users) RecyclerView rv_users;
|
||||
@Bind(R.id.rl_progress) RelativeLayout rl_progress;
|
||||
@Bind(R.id.rl_retry) RelativeLayout rl_retry;
|
||||
@Bind(R.id.bt_retry) Button bt_retry;
|
||||
|
||||
private UsersAdapter usersAdapter;
|
||||
private UsersLayoutManager usersLayoutManager;
|
||||
|
||||
private UserListListener userListListener;
|
||||
|
||||
public UserListFragment() {
|
||||
@@ -72,7 +69,7 @@ public class UserListFragment extends BaseFragment implements UserListView {
|
||||
Bundle savedInstanceState) {
|
||||
final View fragmentView = inflater.inflate(R.layout.fragment_user_list, container, false);
|
||||
ButterKnife.bind(this, fragmentView);
|
||||
setupUI();
|
||||
setupRecyclerView();
|
||||
return fragmentView;
|
||||
}
|
||||
|
||||
@@ -92,23 +89,15 @@ public class UserListFragment extends BaseFragment implements UserListView {
|
||||
this.userListPresenter.pause();
|
||||
}
|
||||
|
||||
@Override public void onDestroy() {
|
||||
super.onDestroy();
|
||||
this.userListPresenter.destroy();
|
||||
}
|
||||
|
||||
@Override public void onDestroyView() {
|
||||
super.onDestroyView();
|
||||
rv_users.setAdapter(null);
|
||||
ButterKnife.unbind(this);
|
||||
}
|
||||
|
||||
private void setupUI() {
|
||||
this.usersLayoutManager = new UsersLayoutManager(getActivity());
|
||||
this.rv_users.setLayoutManager(usersLayoutManager);
|
||||
|
||||
this.usersAdapter = new UsersAdapter(getActivity(), new ArrayList<UserModel>());
|
||||
this.usersAdapter.setOnItemClickListener(onItemClickListener);
|
||||
this.rv_users.setAdapter(usersAdapter);
|
||||
@Override public void onDestroy() {
|
||||
super.onDestroy();
|
||||
this.userListPresenter.destroy();
|
||||
}
|
||||
|
||||
@Override public void showLoading() {
|
||||
@@ -149,6 +138,12 @@ public class UserListFragment extends BaseFragment implements UserListView {
|
||||
return this.getActivity().getApplicationContext();
|
||||
}
|
||||
|
||||
private void setupRecyclerView() {
|
||||
this.usersAdapter.setOnItemClickListener(onItemClickListener);
|
||||
this.rv_users.setLayoutManager(new UsersLayoutManager(context()));
|
||||
this.rv_users.setAdapter(usersAdapter);
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads all users.
|
||||
*/
|
||||
|
||||
@@ -24,6 +24,7 @@
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:textSize="@dimen/lv_row_text_size"
|
||||
android:textColor="@android:color/black"
|
||||
android:gravity="center_vertical"
|
||||
android:singleLine="true"
|
||||
android:ellipsize="end"
|
||||
|
||||
Reference in New Issue
Block a user