mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-27 21:03:54 +01:00
Removed butterknife from contributions list fragment (#5396)
* Removed butterknife from contributions list fragment and overhauled its test * Suggested fix from stack overflow to remove duplicate class error during build
This commit is contained in:
parent
8b054926fe
commit
3d525d4eb3
5 changed files with 126 additions and 184 deletions
|
|
@ -24,6 +24,7 @@ import androidx.activity.result.ActivityResultLauncher;
|
|||
import androidx.activity.result.contract.ActivityResultContracts;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.annotation.VisibleForTesting;
|
||||
import androidx.appcompat.widget.AppCompatTextView;
|
||||
import androidx.fragment.app.FragmentManager;
|
||||
import androidx.recyclerview.widget.GridLayoutManager;
|
||||
|
|
@ -32,15 +33,13 @@ import androidx.recyclerview.widget.RecyclerView.AdapterDataObserver;
|
|||
import androidx.recyclerview.widget.RecyclerView.ItemAnimator;
|
||||
import androidx.recyclerview.widget.RecyclerView.OnItemTouchListener;
|
||||
import androidx.recyclerview.widget.SimpleItemAnimator;
|
||||
import butterknife.BindView;
|
||||
import butterknife.ButterKnife;
|
||||
import butterknife.OnClick;
|
||||
import com.google.android.material.floatingactionbutton.FloatingActionButton;
|
||||
import fr.free.nrw.commons.CommonsApplication;
|
||||
import fr.free.nrw.commons.Media;
|
||||
import fr.free.nrw.commons.R;
|
||||
import fr.free.nrw.commons.Utils;
|
||||
import fr.free.nrw.commons.auth.SessionManager;
|
||||
import fr.free.nrw.commons.databinding.FragmentContributionsListBinding;
|
||||
import fr.free.nrw.commons.di.CommonsDaggerSupportFragment;
|
||||
import fr.free.nrw.commons.media.MediaClient;
|
||||
import fr.free.nrw.commons.profile.ProfileActivity;
|
||||
|
|
@ -66,61 +65,43 @@ public class ContributionsListFragment extends CommonsDaggerSupportFragment impl
|
|||
|
||||
private static final String RV_STATE = "rv_scroll_state";
|
||||
|
||||
@BindView(R.id.contributionsList)
|
||||
RecyclerView rvContributionsList;
|
||||
@BindView(R.id.loadingContributionsProgressBar)
|
||||
ProgressBar progressBar;
|
||||
@BindView(R.id.fab_plus)
|
||||
FloatingActionButton fabPlus;
|
||||
@BindView(R.id.fab_camera)
|
||||
FloatingActionButton fabCamera;
|
||||
@BindView(R.id.fab_gallery)
|
||||
FloatingActionButton fabGallery;
|
||||
@BindView(R.id.noContributionsYet)
|
||||
TextView noContributionsYet;
|
||||
@BindView(R.id.fab_layout)
|
||||
LinearLayout fab_layout;
|
||||
@BindView(R.id.fab_custom_gallery)
|
||||
FloatingActionButton fabCustomGallery;
|
||||
|
||||
@Inject
|
||||
SystemThemeUtils systemThemeUtils;
|
||||
@BindView(R.id.tv_contributions_of_user)
|
||||
AppCompatTextView tvContributionsOfUser;
|
||||
|
||||
@Inject
|
||||
ContributionController controller;
|
||||
@Inject
|
||||
MediaClient mediaClient;
|
||||
|
||||
@Named(NAMED_LANGUAGE_WIKI_PEDIA_WIKI_SITE)
|
||||
@Inject
|
||||
WikiSite languageWikipediaSite;
|
||||
|
||||
@Inject
|
||||
ContributionsListPresenter contributionsListPresenter;
|
||||
|
||||
@Inject
|
||||
SessionManager sessionManager;
|
||||
|
||||
private FragmentContributionsListBinding binding;
|
||||
private Animation fab_close;
|
||||
private Animation fab_open;
|
||||
private Animation rotate_forward;
|
||||
private Animation rotate_backward;
|
||||
|
||||
|
||||
private boolean isFabOpen;
|
||||
|
||||
private ContributionsListAdapter adapter;
|
||||
@VisibleForTesting
|
||||
protected RecyclerView rvContributionsList;
|
||||
|
||||
@VisibleForTesting
|
||||
protected ContributionsListAdapter adapter;
|
||||
|
||||
@Nullable
|
||||
private Callback callback;
|
||||
@VisibleForTesting
|
||||
protected Callback callback;
|
||||
|
||||
private final int SPAN_COUNT_LANDSCAPE = 3;
|
||||
private final int SPAN_COUNT_PORTRAIT = 1;
|
||||
|
||||
private int contributionsSize;
|
||||
String userName;
|
||||
private String userName;
|
||||
|
||||
private ActivityResultLauncher<String[]> inAppCameraLocationPermissionLauncher = registerForActivityResult(new ActivityResultContracts.RequestMultiplePermissions(), new ActivityResultCallback<Map<String, Boolean>>() {
|
||||
@Override
|
||||
public void onActivityResult(Map<String, Boolean> result) {
|
||||
|
|
@ -162,21 +143,32 @@ public class ContributionsListFragment extends CommonsDaggerSupportFragment impl
|
|||
public View onCreateView(
|
||||
final LayoutInflater inflater, @Nullable final ViewGroup container,
|
||||
@Nullable final Bundle savedInstanceState) {
|
||||
final View view = inflater.inflate(R.layout.fragment_contributions_list, container, false);
|
||||
ButterKnife.bind(this, view);
|
||||
binding = FragmentContributionsListBinding.inflate(
|
||||
inflater, container, false
|
||||
);
|
||||
rvContributionsList = binding.contributionsList;
|
||||
|
||||
contributionsListPresenter.onAttachView(this);
|
||||
binding.fabCustomGallery.setOnClickListener(v -> launchCustomSelector());
|
||||
|
||||
if (Objects.equals(sessionManager.getUserName(), userName)) {
|
||||
tvContributionsOfUser.setVisibility(GONE);
|
||||
fab_layout.setVisibility(VISIBLE);
|
||||
binding.tvContributionsOfUser.setVisibility(GONE);
|
||||
binding.fabLayout.setVisibility(VISIBLE);
|
||||
} else {
|
||||
tvContributionsOfUser.setVisibility(VISIBLE);
|
||||
tvContributionsOfUser.setText(getString(R.string.contributions_of_user, userName));
|
||||
fab_layout.setVisibility(GONE);
|
||||
binding.tvContributionsOfUser.setVisibility(VISIBLE);
|
||||
binding.tvContributionsOfUser.setText(getString(R.string.contributions_of_user, userName));
|
||||
binding.fabLayout.setVisibility(GONE);
|
||||
}
|
||||
|
||||
initAdapter();
|
||||
return view;
|
||||
|
||||
return binding.getRoot();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroyView() {
|
||||
binding = null;
|
||||
super.onDestroyView();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -309,7 +301,7 @@ public class ContributionsListFragment extends CommonsDaggerSupportFragment impl
|
|||
public void onConfigurationChanged(final Configuration newConfig) {
|
||||
super.onConfigurationChanged(newConfig);
|
||||
// check orientation
|
||||
fab_layout.setOrientation(newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE ?
|
||||
binding.fabLayout.setOrientation(newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE ?
|
||||
LinearLayout.HORIZONTAL : LinearLayout.VERTICAL);
|
||||
rvContributionsList
|
||||
.setLayoutManager(
|
||||
|
|
@ -324,12 +316,12 @@ public class ContributionsListFragment extends CommonsDaggerSupportFragment impl
|
|||
}
|
||||
|
||||
private void setListeners() {
|
||||
fabPlus.setOnClickListener(view -> animateFAB(isFabOpen));
|
||||
fabCamera.setOnClickListener(view -> {
|
||||
binding.fabPlus.setOnClickListener(view -> animateFAB(isFabOpen));
|
||||
binding.fabCamera.setOnClickListener(view -> {
|
||||
controller.initiateCameraPick(getActivity(), inAppCameraLocationPermissionLauncher);
|
||||
animateFAB(isFabOpen);
|
||||
});
|
||||
fabGallery.setOnClickListener(view -> {
|
||||
binding.fabGallery.setOnClickListener(view -> {
|
||||
controller.initiateGalleryPick(getActivity(), true);
|
||||
animateFAB(isFabOpen);
|
||||
});
|
||||
|
|
@ -338,8 +330,7 @@ public class ContributionsListFragment extends CommonsDaggerSupportFragment impl
|
|||
/**
|
||||
* Launch Custom Selector.
|
||||
*/
|
||||
@OnClick(R.id.fab_custom_gallery)
|
||||
void launchCustomSelector() {
|
||||
protected void launchCustomSelector() {
|
||||
controller.initiateCustomGalleryPickWithPermission(getActivity());
|
||||
animateFAB(isFabOpen);
|
||||
}
|
||||
|
|
@ -350,23 +341,23 @@ public class ContributionsListFragment extends CommonsDaggerSupportFragment impl
|
|||
|
||||
private void animateFAB(final boolean isFabOpen) {
|
||||
this.isFabOpen = !isFabOpen;
|
||||
if (fabPlus.isShown()) {
|
||||
if (binding.fabPlus.isShown()) {
|
||||
if (isFabOpen) {
|
||||
fabPlus.startAnimation(rotate_backward);
|
||||
fabCamera.startAnimation(fab_close);
|
||||
fabGallery.startAnimation(fab_close);
|
||||
fabCustomGallery.startAnimation(fab_close);
|
||||
fabCamera.hide();
|
||||
fabGallery.hide();
|
||||
fabCustomGallery.hide();
|
||||
binding.fabPlus.startAnimation(rotate_backward);
|
||||
binding.fabCamera.startAnimation(fab_close);
|
||||
binding.fabGallery.startAnimation(fab_close);
|
||||
binding.fabCustomGallery.startAnimation(fab_close);
|
||||
binding.fabCamera.hide();
|
||||
binding.fabGallery.hide();
|
||||
binding.fabCustomGallery.hide();
|
||||
} else {
|
||||
fabPlus.startAnimation(rotate_forward);
|
||||
fabCamera.startAnimation(fab_open);
|
||||
fabGallery.startAnimation(fab_open);
|
||||
fabCustomGallery.startAnimation(fab_open);
|
||||
fabCamera.show();
|
||||
fabGallery.show();
|
||||
fabCustomGallery.show();
|
||||
binding.fabPlus.startAnimation(rotate_forward);
|
||||
binding.fabCamera.startAnimation(fab_open);
|
||||
binding.fabGallery.startAnimation(fab_open);
|
||||
binding.fabCustomGallery.startAnimation(fab_open);
|
||||
binding.fabCamera.show();
|
||||
binding.fabGallery.show();
|
||||
binding.fabCustomGallery.show();
|
||||
}
|
||||
this.isFabOpen = !isFabOpen;
|
||||
}
|
||||
|
|
@ -377,7 +368,7 @@ public class ContributionsListFragment extends CommonsDaggerSupportFragment impl
|
|||
*/
|
||||
@Override
|
||||
public void showWelcomeTip(final boolean shouldShow) {
|
||||
noContributionsYet.setVisibility(shouldShow ? VISIBLE : GONE);
|
||||
binding.noContributionsYet.setVisibility(shouldShow ? VISIBLE : GONE);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -387,12 +378,12 @@ public class ContributionsListFragment extends CommonsDaggerSupportFragment impl
|
|||
*/
|
||||
@Override
|
||||
public void showProgress(final boolean shouldShow) {
|
||||
progressBar.setVisibility(shouldShow ? VISIBLE : GONE);
|
||||
binding.loadingContributionsProgressBar.setVisibility(shouldShow ? VISIBLE : GONE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void showNoContributionsUI(final boolean shouldShow) {
|
||||
noContributionsYet.setVisibility(shouldShow ? VISIBLE : GONE);
|
||||
binding.noContributionsYet.setVisibility(shouldShow ? VISIBLE : GONE);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue