-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Replaced Butterknife with Viewbinding in MoreBottomSheetFragment.java #5379
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
nicolas-raoul
merged 1 commit into
commons-app:main
from
psh:psh/remove-some-butterknife
Nov 10, 2023
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,9 +15,6 @@ | |
import androidx.annotation.NonNull; | ||
import androidx.annotation.Nullable; | ||
import androidx.appcompat.app.AlertDialog; | ||
import butterknife.BindView; | ||
import butterknife.ButterKnife; | ||
import butterknife.OnClick; | ||
import com.google.android.material.bottomsheet.BottomSheetDialogFragment; | ||
import fr.free.nrw.commons.AboutActivity; | ||
import fr.free.nrw.commons.BuildConfig; | ||
|
@@ -26,11 +23,11 @@ | |
import fr.free.nrw.commons.WelcomeActivity; | ||
import fr.free.nrw.commons.actions.PageEditClient; | ||
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.feedback.FeedbackContentCreator; | ||
import fr.free.nrw.commons.feedback.model.Feedback; | ||
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.logging.CommonsLogSender; | ||
import fr.free.nrw.commons.profile.ProfileActivity; | ||
|
@@ -49,10 +46,8 @@ public class MoreBottomSheetFragment extends BottomSheetDialogFragment { | |
|
||
@Inject | ||
CommonsLogSender commonsLogSender; | ||
@BindView(R.id.more_profile) | ||
TextView moreProfile; | ||
|
||
@BindView((R.id.more_peer_review)) TextView morePeerReview; | ||
private TextView moreProfile; | ||
|
||
@Inject @Named("default_preferences") | ||
JsonKvStore store; | ||
|
@@ -66,20 +61,31 @@ public class MoreBottomSheetFragment extends BottomSheetDialogFragment { | |
public View onCreateView(@NonNull final LayoutInflater inflater, | ||
@Nullable final ViewGroup container, @Nullable final Bundle savedInstanceState) { | ||
super.onCreateView(inflater, container, savedInstanceState); | ||
final View view = inflater.inflate(R.layout.fragment_more_bottom_sheet, container, false); | ||
ButterKnife.bind(this, view); | ||
final @NonNull FragmentMoreBottomSheetBinding binding = | ||
FragmentMoreBottomSheetBinding.inflate(inflater, container, false); | ||
moreProfile = binding.moreProfile; | ||
|
||
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(); | ||
return view; | ||
return binding.getRoot(); | ||
} | ||
|
||
@Override | ||
public void onAttach(@NonNull final Context context) { | ||
super.onAttach(context); | ||
ApplicationlessInjection | ||
.getInstance(getActivity().getApplicationContext()) | ||
.getInstance(requireActivity().getApplicationContext()) | ||
.getCommonsApplicationComponent() | ||
.inject(this); | ||
} | ||
|
@@ -102,42 +108,35 @@ private String getUserName(){ | |
} | ||
|
||
|
||
@OnClick(R.id.more_logout) | ||
public void onLogoutClicked() { | ||
new AlertDialog.Builder(getActivity()) | ||
protected void onLogoutClicked() { | ||
new AlertDialog.Builder(requireActivity()) | ||
.setMessage(R.string.logout_verification) | ||
.setCancelable(false) | ||
.setPositiveButton(R.string.yes, (dialog, which) -> { | ||
BaseLogoutListener logoutListener = new BaseLogoutListener(); | ||
CommonsApplication app = (CommonsApplication) getContext().getApplicationContext(); | ||
app.clearApplicationData(getContext(), logoutListener); | ||
final CommonsApplication app = (CommonsApplication) | ||
requireContext().getApplicationContext(); | ||
app.clearApplicationData(requireContext(), new BaseLogoutListener()); | ||
}) | ||
.setNegativeButton(R.string.no, (dialog, which) -> dialog.cancel()) | ||
.show(); | ||
} | ||
|
||
@OnClick(R.id.more_feedback) | ||
public void onFeedbackClicked() { | ||
protected void onFeedbackClicked() { | ||
showFeedbackDialog(); | ||
} | ||
|
||
/** | ||
* Creates and shows a dialog asking feedback from users | ||
*/ | ||
private void showFeedbackDialog() { | ||
new FeedbackDialog(getContext(), new OnFeedbackSubmitCallback() { | ||
@Override | ||
public void onFeedbackSubmit(Feedback feedback) { | ||
uploadFeedback(feedback); | ||
} | ||
}).show(); | ||
new FeedbackDialog(getContext(), this::uploadFeedback).show(); | ||
} | ||
|
||
/** | ||
* uploads feedback data on the server | ||
*/ | ||
void uploadFeedback(Feedback feedback) { | ||
FeedbackContentCreator feedbackContentCreator = new FeedbackContentCreator(getContext(), feedback); | ||
void uploadFeedback(final Feedback feedback) { | ||
final FeedbackContentCreator feedbackContentCreator = new FeedbackContentCreator(getContext(), feedback); | ||
|
||
Single<Boolean> single = | ||
pageEditClient.prependEdit("Commons:Mobile_app/Feedback", feedbackContentCreator.toString(), "Summary") | ||
|
@@ -162,12 +161,10 @@ void uploadFeedback(Feedback feedback) { | |
* This method shows the alert dialog when a user wants to send feedback about the app. | ||
*/ | ||
private void showAlertDialog() { | ||
new AlertDialog.Builder(getActivity()) | ||
new AlertDialog.Builder(requireActivity()) | ||
.setMessage(R.string.feedback_sharing_data_alert) | ||
.setCancelable(false) | ||
.setPositiveButton(R.string.ok, (dialog, which) -> { | ||
sendFeedback(); | ||
}) | ||
.setPositiveButton(R.string.ok, (dialog, which) -> sendFeedback()) | ||
.show(); | ||
} | ||
|
||
|
@@ -194,32 +191,27 @@ private void sendFeedback() { | |
} | ||
} | ||
|
||
@OnClick(R.id.more_about) | ||
public void onAboutClicked() { | ||
protected void onAboutClicked() { | ||
final Intent intent = new Intent(getActivity(), AboutActivity.class); | ||
intent.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT | Intent.FLAG_ACTIVITY_SINGLE_TOP); | ||
getActivity().startActivity(intent); | ||
requireActivity().startActivity(intent); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Several different instances - the call to |
||
} | ||
|
||
@OnClick(R.id.more_tutorial) | ||
public void onTutorialClicked() { | ||
protected void onTutorialClicked() { | ||
WelcomeActivity.startYourself(getActivity()); | ||
} | ||
|
||
@OnClick(R.id.more_settings) | ||
public void onSettingsClicked() { | ||
protected void onSettingsClicked() { | ||
final Intent intent = new Intent(getActivity(), SettingsActivity.class); | ||
intent.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT | Intent.FLAG_ACTIVITY_SINGLE_TOP); | ||
getActivity().startActivity(intent); | ||
requireActivity().startActivity(intent); | ||
} | ||
|
||
@OnClick(R.id.more_profile) | ||
public void onProfileClicked() { | ||
protected void onProfileClicked() { | ||
ProfileActivity.startYourself(getActivity(), getUserName(), false); | ||
} | ||
|
||
@OnClick(R.id.more_peer_review) | ||
public void onPeerReviewClicked() { | ||
protected void onPeerReviewClicked() { | ||
ReviewActivity.startYourself(getActivity(), getString(R.string.title_activity_review)); | ||
} | ||
|
||
|
@@ -233,7 +225,7 @@ public void onLogoutComplete() { | |
nearbyIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK); | ||
nearbyIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); | ||
startActivity(nearbyIntent); | ||
getActivity().finish(); | ||
requireActivity().finish(); | ||
} | ||
} | ||
} | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Replace anonymous inner class with method reference, suggested by the IDE