mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-26 12:23:58 +01:00
Replaced Butterknife with Viewbinding, and dealt the a whole bunch of code quality warnings (#5379)
This commit is contained in:
parent
b113f3c986
commit
9620f6eee0
2 changed files with 37 additions and 49 deletions
|
|
@ -15,9 +15,6 @@ import android.widget.Toast;
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
import androidx.appcompat.app.AlertDialog;
|
import androidx.appcompat.app.AlertDialog;
|
||||||
import butterknife.BindView;
|
|
||||||
import butterknife.ButterKnife;
|
|
||||||
import butterknife.OnClick;
|
|
||||||
import com.google.android.material.bottomsheet.BottomSheetDialogFragment;
|
import com.google.android.material.bottomsheet.BottomSheetDialogFragment;
|
||||||
import fr.free.nrw.commons.AboutActivity;
|
import fr.free.nrw.commons.AboutActivity;
|
||||||
import fr.free.nrw.commons.BuildConfig;
|
import fr.free.nrw.commons.BuildConfig;
|
||||||
|
|
@ -26,11 +23,11 @@ import fr.free.nrw.commons.R;
|
||||||
import fr.free.nrw.commons.WelcomeActivity;
|
import fr.free.nrw.commons.WelcomeActivity;
|
||||||
import fr.free.nrw.commons.actions.PageEditClient;
|
import fr.free.nrw.commons.actions.PageEditClient;
|
||||||
import fr.free.nrw.commons.auth.LoginActivity;
|
import fr.free.nrw.commons.auth.LoginActivity;
|
||||||
|
import fr.free.nrw.commons.databinding.FragmentMoreBottomSheetBinding;
|
||||||
import fr.free.nrw.commons.di.ApplicationlessInjection;
|
import fr.free.nrw.commons.di.ApplicationlessInjection;
|
||||||
import fr.free.nrw.commons.feedback.FeedbackContentCreator;
|
import fr.free.nrw.commons.feedback.FeedbackContentCreator;
|
||||||
import fr.free.nrw.commons.feedback.model.Feedback;
|
import fr.free.nrw.commons.feedback.model.Feedback;
|
||||||
import fr.free.nrw.commons.feedback.FeedbackDialog;
|
import fr.free.nrw.commons.feedback.FeedbackDialog;
|
||||||
import fr.free.nrw.commons.feedback.OnFeedbackSubmitCallback;
|
|
||||||
import fr.free.nrw.commons.kvstore.JsonKvStore;
|
import fr.free.nrw.commons.kvstore.JsonKvStore;
|
||||||
import fr.free.nrw.commons.logging.CommonsLogSender;
|
import fr.free.nrw.commons.logging.CommonsLogSender;
|
||||||
import fr.free.nrw.commons.profile.ProfileActivity;
|
import fr.free.nrw.commons.profile.ProfileActivity;
|
||||||
|
|
@ -49,10 +46,8 @@ public class MoreBottomSheetFragment extends BottomSheetDialogFragment {
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
CommonsLogSender commonsLogSender;
|
CommonsLogSender commonsLogSender;
|
||||||
@BindView(R.id.more_profile)
|
|
||||||
TextView moreProfile;
|
|
||||||
|
|
||||||
@BindView((R.id.more_peer_review)) TextView morePeerReview;
|
private TextView moreProfile;
|
||||||
|
|
||||||
@Inject @Named("default_preferences")
|
@Inject @Named("default_preferences")
|
||||||
JsonKvStore store;
|
JsonKvStore store;
|
||||||
|
|
@ -66,20 +61,31 @@ public class MoreBottomSheetFragment extends BottomSheetDialogFragment {
|
||||||
public View onCreateView(@NonNull final LayoutInflater inflater,
|
public View onCreateView(@NonNull final LayoutInflater inflater,
|
||||||
@Nullable final ViewGroup container, @Nullable final Bundle savedInstanceState) {
|
@Nullable final ViewGroup container, @Nullable final Bundle savedInstanceState) {
|
||||||
super.onCreateView(inflater, container, savedInstanceState);
|
super.onCreateView(inflater, container, savedInstanceState);
|
||||||
final View view = inflater.inflate(R.layout.fragment_more_bottom_sheet, container, false);
|
final @NonNull FragmentMoreBottomSheetBinding binding =
|
||||||
ButterKnife.bind(this, view);
|
FragmentMoreBottomSheetBinding.inflate(inflater, container, false);
|
||||||
|
moreProfile = binding.moreProfile;
|
||||||
|
|
||||||
if(store.getBoolean(CommonsApplication.IS_LIMITED_CONNECTION_MODE_ENABLED)){
|
if(store.getBoolean(CommonsApplication.IS_LIMITED_CONNECTION_MODE_ENABLED)){
|
||||||
morePeerReview.setVisibility(View.GONE);
|
binding.morePeerReview.setVisibility(View.GONE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
binding.moreLogout.setOnClickListener(v -> onLogoutClicked());
|
||||||
|
binding.moreFeedback.setOnClickListener(v -> onFeedbackClicked());
|
||||||
|
binding.moreAbout.setOnClickListener(v -> onAboutClicked());
|
||||||
|
binding.moreTutorial.setOnClickListener(v -> onTutorialClicked());
|
||||||
|
binding.moreSettings.setOnClickListener(v -> onSettingsClicked());
|
||||||
|
binding.moreProfile.setOnClickListener(v -> onProfileClicked());
|
||||||
|
binding.morePeerReview.setOnClickListener(v -> onPeerReviewClicked());
|
||||||
|
|
||||||
setUserName();
|
setUserName();
|
||||||
return view;
|
return binding.getRoot();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onAttach(@NonNull final Context context) {
|
public void onAttach(@NonNull final Context context) {
|
||||||
super.onAttach(context);
|
super.onAttach(context);
|
||||||
ApplicationlessInjection
|
ApplicationlessInjection
|
||||||
.getInstance(getActivity().getApplicationContext())
|
.getInstance(requireActivity().getApplicationContext())
|
||||||
.getCommonsApplicationComponent()
|
.getCommonsApplicationComponent()
|
||||||
.inject(this);
|
.inject(this);
|
||||||
}
|
}
|
||||||
|
|
@ -102,22 +108,20 @@ public class MoreBottomSheetFragment extends BottomSheetDialogFragment {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@OnClick(R.id.more_logout)
|
protected void onLogoutClicked() {
|
||||||
public void onLogoutClicked() {
|
new AlertDialog.Builder(requireActivity())
|
||||||
new AlertDialog.Builder(getActivity())
|
|
||||||
.setMessage(R.string.logout_verification)
|
.setMessage(R.string.logout_verification)
|
||||||
.setCancelable(false)
|
.setCancelable(false)
|
||||||
.setPositiveButton(R.string.yes, (dialog, which) -> {
|
.setPositiveButton(R.string.yes, (dialog, which) -> {
|
||||||
BaseLogoutListener logoutListener = new BaseLogoutListener();
|
final CommonsApplication app = (CommonsApplication)
|
||||||
CommonsApplication app = (CommonsApplication) getContext().getApplicationContext();
|
requireContext().getApplicationContext();
|
||||||
app.clearApplicationData(getContext(), logoutListener);
|
app.clearApplicationData(requireContext(), new BaseLogoutListener());
|
||||||
})
|
})
|
||||||
.setNegativeButton(R.string.no, (dialog, which) -> dialog.cancel())
|
.setNegativeButton(R.string.no, (dialog, which) -> dialog.cancel())
|
||||||
.show();
|
.show();
|
||||||
}
|
}
|
||||||
|
|
||||||
@OnClick(R.id.more_feedback)
|
protected void onFeedbackClicked() {
|
||||||
public void onFeedbackClicked() {
|
|
||||||
showFeedbackDialog();
|
showFeedbackDialog();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -125,19 +129,14 @@ public class MoreBottomSheetFragment extends BottomSheetDialogFragment {
|
||||||
* Creates and shows a dialog asking feedback from users
|
* Creates and shows a dialog asking feedback from users
|
||||||
*/
|
*/
|
||||||
private void showFeedbackDialog() {
|
private void showFeedbackDialog() {
|
||||||
new FeedbackDialog(getContext(), new OnFeedbackSubmitCallback() {
|
new FeedbackDialog(getContext(), this::uploadFeedback).show();
|
||||||
@Override
|
|
||||||
public void onFeedbackSubmit(Feedback feedback) {
|
|
||||||
uploadFeedback(feedback);
|
|
||||||
}
|
|
||||||
}).show();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* uploads feedback data on the server
|
* uploads feedback data on the server
|
||||||
*/
|
*/
|
||||||
void uploadFeedback(Feedback feedback) {
|
void uploadFeedback(final Feedback feedback) {
|
||||||
FeedbackContentCreator feedbackContentCreator = new FeedbackContentCreator(getContext(), feedback);
|
final FeedbackContentCreator feedbackContentCreator = new FeedbackContentCreator(getContext(), feedback);
|
||||||
|
|
||||||
Single<Boolean> single =
|
Single<Boolean> single =
|
||||||
pageEditClient.prependEdit("Commons:Mobile_app/Feedback", feedbackContentCreator.toString(), "Summary")
|
pageEditClient.prependEdit("Commons:Mobile_app/Feedback", feedbackContentCreator.toString(), "Summary")
|
||||||
|
|
@ -162,12 +161,10 @@ public class MoreBottomSheetFragment extends BottomSheetDialogFragment {
|
||||||
* This method shows the alert dialog when a user wants to send feedback about the app.
|
* This method shows the alert dialog when a user wants to send feedback about the app.
|
||||||
*/
|
*/
|
||||||
private void showAlertDialog() {
|
private void showAlertDialog() {
|
||||||
new AlertDialog.Builder(getActivity())
|
new AlertDialog.Builder(requireActivity())
|
||||||
.setMessage(R.string.feedback_sharing_data_alert)
|
.setMessage(R.string.feedback_sharing_data_alert)
|
||||||
.setCancelable(false)
|
.setCancelable(false)
|
||||||
.setPositiveButton(R.string.ok, (dialog, which) -> {
|
.setPositiveButton(R.string.ok, (dialog, which) -> sendFeedback())
|
||||||
sendFeedback();
|
|
||||||
})
|
|
||||||
.show();
|
.show();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -194,32 +191,27 @@ public class MoreBottomSheetFragment extends BottomSheetDialogFragment {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@OnClick(R.id.more_about)
|
protected void onAboutClicked() {
|
||||||
public void onAboutClicked() {
|
|
||||||
final Intent intent = new Intent(getActivity(), AboutActivity.class);
|
final Intent intent = new Intent(getActivity(), AboutActivity.class);
|
||||||
intent.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT | Intent.FLAG_ACTIVITY_SINGLE_TOP);
|
intent.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT | Intent.FLAG_ACTIVITY_SINGLE_TOP);
|
||||||
getActivity().startActivity(intent);
|
requireActivity().startActivity(intent);
|
||||||
}
|
}
|
||||||
|
|
||||||
@OnClick(R.id.more_tutorial)
|
protected void onTutorialClicked() {
|
||||||
public void onTutorialClicked() {
|
|
||||||
WelcomeActivity.startYourself(getActivity());
|
WelcomeActivity.startYourself(getActivity());
|
||||||
}
|
}
|
||||||
|
|
||||||
@OnClick(R.id.more_settings)
|
protected void onSettingsClicked() {
|
||||||
public void onSettingsClicked() {
|
|
||||||
final Intent intent = new Intent(getActivity(), SettingsActivity.class);
|
final Intent intent = new Intent(getActivity(), SettingsActivity.class);
|
||||||
intent.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT | Intent.FLAG_ACTIVITY_SINGLE_TOP);
|
intent.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT | Intent.FLAG_ACTIVITY_SINGLE_TOP);
|
||||||
getActivity().startActivity(intent);
|
requireActivity().startActivity(intent);
|
||||||
}
|
}
|
||||||
|
|
||||||
@OnClick(R.id.more_profile)
|
protected void onProfileClicked() {
|
||||||
public void onProfileClicked() {
|
|
||||||
ProfileActivity.startYourself(getActivity(), getUserName(), false);
|
ProfileActivity.startYourself(getActivity(), getUserName(), false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@OnClick(R.id.more_peer_review)
|
protected void onPeerReviewClicked() {
|
||||||
public void onPeerReviewClicked() {
|
|
||||||
ReviewActivity.startYourself(getActivity(), getString(R.string.title_activity_review));
|
ReviewActivity.startYourself(getActivity(), getString(R.string.title_activity_review));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -233,7 +225,7 @@ public class MoreBottomSheetFragment extends BottomSheetDialogFragment {
|
||||||
nearbyIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
|
nearbyIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
|
||||||
nearbyIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
nearbyIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||||
startActivity(nearbyIntent);
|
startActivity(nearbyIntent);
|
||||||
getActivity().finish();
|
requireActivity().finish();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -56,9 +56,6 @@ class MoreBottomSheetFragmentUnitTests {
|
||||||
@Mock
|
@Mock
|
||||||
private lateinit var store: JsonKvStore
|
private lateinit var store: JsonKvStore
|
||||||
|
|
||||||
@Mock
|
|
||||||
private lateinit var morePeerReview: TextView
|
|
||||||
|
|
||||||
@Mock
|
@Mock
|
||||||
private lateinit var pageEditClient: PageEditClient
|
private lateinit var pageEditClient: PageEditClient
|
||||||
|
|
||||||
|
|
@ -76,7 +73,6 @@ class MoreBottomSheetFragmentUnitTests {
|
||||||
fragmentTransaction.commitNowAllowingStateLoss()
|
fragmentTransaction.commitNowAllowingStateLoss()
|
||||||
|
|
||||||
Whitebox.setInternalState(fragment, "store", store)
|
Whitebox.setInternalState(fragment, "store", store)
|
||||||
Whitebox.setInternalState(fragment, "morePeerReview", morePeerReview)
|
|
||||||
Whitebox.setInternalState(fragment, "pageEditClient", pageEditClient)
|
Whitebox.setInternalState(fragment, "pageEditClient", pageEditClient)
|
||||||
|
|
||||||
`when`(store.getBoolean(CommonsApplication.IS_LIMITED_CONNECTION_MODE_ENABLED)).thenReturn(
|
`when`(store.getBoolean(CommonsApplication.IS_LIMITED_CONNECTION_MODE_ENABLED)).thenReturn(
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue