mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-29 22:03:55 +01:00
Fix - No Precise Error Message After Error Due to Password Change (#5643)
* initial commit * Fix No Precise Message After Clicking Review Buttons * Fix For ThanksClient * Fix For Depictions * Fix For Categories * Fix For Description & Coordinates * Fix For Description & Coordinates * Fix For Description & Coordinates * Fix For Mark as Read notifications * resolve conflicts * fix merge conflicts
This commit is contained in:
parent
e56de2c343
commit
3d1efecb55
18 changed files with 361 additions and 110 deletions
|
|
@ -9,6 +9,8 @@ import androidx.annotation.NonNull;
|
|||
import androidx.annotation.Nullable;
|
||||
import androidx.core.app.NotificationCompat;
|
||||
|
||||
import fr.free.nrw.commons.auth.SessionManager;
|
||||
import fr.free.nrw.commons.auth.csrf.InvalidLoginTokenException;
|
||||
import fr.free.nrw.commons.wikidata.mwapi.MwQueryPage;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
|
@ -39,6 +41,9 @@ public class ReviewController {
|
|||
protected static ArrayList<String> categories;
|
||||
@Inject
|
||||
ThanksClient thanksClient;
|
||||
|
||||
@Inject
|
||||
SessionManager sessionManager;
|
||||
private final DeleteHelper deleteHelper;
|
||||
@Nullable
|
||||
MwQueryPage.Revision firstRevision; // TODO: maybe we can expand this class to include fileName
|
||||
|
|
@ -155,9 +160,23 @@ public class ReviewController {
|
|||
Observable.defer((Callable<ObservableSource<Boolean>>) () -> thanksClient.thank(firstRevision.getRevisionId()))
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe((result) -> {
|
||||
displayThanksToast(context,result);
|
||||
}, Timber::e);
|
||||
.subscribe(result -> {
|
||||
displayThanksToast(context, result);
|
||||
}, throwable -> {
|
||||
if (throwable instanceof InvalidLoginTokenException) {
|
||||
final String username = sessionManager.getUserName();
|
||||
final CommonsApplication.BaseLogoutListener logoutListener = new CommonsApplication.BaseLogoutListener(
|
||||
activity,
|
||||
activity.getString(R.string.invalid_login_message),
|
||||
username
|
||||
);
|
||||
|
||||
CommonsApplication.getInstance().clearApplicationData(
|
||||
activity, logoutListener);
|
||||
} else {
|
||||
Timber.e(throwable);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@SuppressLint("StringFormatInvalid")
|
||||
|
|
@ -192,6 +211,8 @@ public class ReviewController {
|
|||
|
||||
void onFailure();
|
||||
|
||||
void onTokenException(Exception e);
|
||||
|
||||
void disableButtons();
|
||||
|
||||
void enableButtons();
|
||||
|
|
|
|||
|
|
@ -7,15 +7,17 @@ import android.text.TextUtils;
|
|||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import fr.free.nrw.commons.CommonsApplication;
|
||||
import fr.free.nrw.commons.Media;
|
||||
import fr.free.nrw.commons.R;
|
||||
import fr.free.nrw.commons.auth.SessionManager;
|
||||
import fr.free.nrw.commons.auth.csrf.InvalidLoginTokenException;
|
||||
import fr.free.nrw.commons.databinding.FragmentReviewImageBinding;
|
||||
import fr.free.nrw.commons.di.CommonsDaggerSupportFragment;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import javax.inject.Inject;
|
||||
|
||||
public class ReviewImageFragment extends CommonsDaggerSupportFragment {
|
||||
|
||||
|
|
@ -28,7 +30,8 @@ public class ReviewImageFragment extends CommonsDaggerSupportFragment {
|
|||
|
||||
private FragmentReviewImageBinding binding;
|
||||
|
||||
|
||||
@Inject
|
||||
SessionManager sessionManager;
|
||||
|
||||
|
||||
// Constant variable used to store user's key name for onSaveInstanceState method
|
||||
|
|
@ -37,20 +40,20 @@ public class ReviewImageFragment extends CommonsDaggerSupportFragment {
|
|||
// Variable that stores the value of user
|
||||
private String user;
|
||||
|
||||
public void update(int position) {
|
||||
public void update(final int position) {
|
||||
this.position = position;
|
||||
}
|
||||
|
||||
private String updateCategoriesQuestion() {
|
||||
Media media = getReviewActivity().getMedia();
|
||||
final Media media = getReviewActivity().getMedia();
|
||||
if (media != null && media.getCategoriesHiddenStatus() != null && isAdded()) {
|
||||
// Filter category name attribute from all categories
|
||||
List<String> categories = new ArrayList<>();
|
||||
for(String key : media.getCategoriesHiddenStatus().keySet()) {
|
||||
final List<String> categories = new ArrayList<>();
|
||||
for(final String key : media.getCategoriesHiddenStatus().keySet()) {
|
||||
String value = String.valueOf(key);
|
||||
// Each category returned has a format like "Category:<some-category-name>"
|
||||
// so remove the prefix "Category:"
|
||||
int index = key.indexOf("Category:");
|
||||
final int index = key.indexOf("Category:");
|
||||
if(index == 0) {
|
||||
value = key.substring(9);
|
||||
}
|
||||
|
|
@ -59,7 +62,7 @@ public class ReviewImageFragment extends CommonsDaggerSupportFragment {
|
|||
String catString = TextUtils.join(", ", categories);
|
||||
if (catString != null && !catString.equals("") && binding.tvReviewQuestionContext != null) {
|
||||
catString = "<b>" + catString + "</b>";
|
||||
String stringToConvertHtml = String.format(getResources().getString(R.string.review_category_explanation), catString);
|
||||
final String stringToConvertHtml = String.format(getResources().getString(R.string.review_category_explanation), catString);
|
||||
return Html.fromHtml(stringToConvertHtml).toString();
|
||||
}
|
||||
}
|
||||
|
|
@ -67,17 +70,20 @@ public class ReviewImageFragment extends CommonsDaggerSupportFragment {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
public void onCreate(final Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
}
|
||||
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
||||
Bundle savedInstanceState) {
|
||||
public View onCreateView(final LayoutInflater inflater, final ViewGroup container,
|
||||
final Bundle savedInstanceState) {
|
||||
position = getArguments().getInt("position");
|
||||
binding = FragmentReviewImageBinding.inflate(inflater, container, false);
|
||||
|
||||
String question, explanation=null, yesButtonText, noButtonText;
|
||||
final String question;
|
||||
String explanation=null;
|
||||
String yesButtonText;
|
||||
final String noButtonText;
|
||||
|
||||
binding.buttonYes.setOnClickListener(view -> onYesButtonClicked());
|
||||
|
||||
|
|
@ -182,6 +188,22 @@ public class ReviewImageFragment extends CommonsDaggerSupportFragment {
|
|||
//do nothing
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTokenException(final Exception e) {
|
||||
if (e instanceof InvalidLoginTokenException){
|
||||
final String username = sessionManager.getUserName();
|
||||
final CommonsApplication.BaseLogoutListener logoutListener = new CommonsApplication.BaseLogoutListener(
|
||||
getActivity(),
|
||||
requireActivity().getString(R.string.invalid_login_message),
|
||||
username
|
||||
);
|
||||
|
||||
CommonsApplication.getInstance().clearApplicationData(
|
||||
requireActivity(), logoutListener);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This function is called when an image is being loaded
|
||||
* to disable the review buttons
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue