Skip to content

Commit

Permalink
Fix pending issues in upload flow
Browse files Browse the repository at this point in the history
  • Loading branch information
maskara committed Nov 6, 2018
1 parent 225c2a7 commit 6ff0684
Show file tree
Hide file tree
Showing 6 changed files with 75 additions and 116 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ public void startSingleGalleryPick() {
Timber.d("Fragment is not added, startActivityForResult cannot be called");
return;
}
Timber.d("startGalleryPick() called with pickImageIntent");
Timber.d("startSingleGalleryPick() called with pickImageIntent");

fragment.startActivityForResult(pickImageIntent, SELECT_FROM_GALLERY);
}
Expand All @@ -114,7 +114,7 @@ public void startMultipleGalleryPick() {
Timber.d("Fragment is not added, startActivityForResult cannot be called");
return;
}
Timber.d("startGalleryPick() called with pickImageIntent");
Timber.d("startMultipleGalleryPick() called with pickImageIntent");

fragment.startActivityForResult(pickImageIntent, PICK_IMAGE_MULTIPLE);
}
Expand Down
83 changes: 26 additions & 57 deletions app/src/main/java/fr/free/nrw/commons/upload/UploadActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import android.Manifest;
import android.animation.LayoutTransition;
import android.annotation.SuppressLint;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.net.Uri;
Expand Down Expand Up @@ -54,6 +53,7 @@
import fr.free.nrw.commons.category.CategoryItem;
import fr.free.nrw.commons.contributions.Contribution;
import fr.free.nrw.commons.mwapi.MediaWikiApi;
import fr.free.nrw.commons.utils.DialogUtil;
import fr.free.nrw.commons.utils.ImageUtils;
import fr.free.nrw.commons.utils.ViewUtil;
import io.reactivex.Observable;
Expand Down Expand Up @@ -139,7 +139,7 @@ protected void onCreate(Bundle savedInstanceState) {
configureCategories();
configureLicenses();

presenter.initFromSavedState(savedInstanceState);
presenter.init();

dexterPermissionObtainer = new DexterPermissionObtainer(this,
Manifest.permission.WRITE_EXTERNAL_STORAGE,
Expand Down Expand Up @@ -329,12 +329,11 @@ public void setBackground(Uri mediaUri) {

@Override
public void dismissKeyboard() {
// inputMethodManager.hideSoftInputFromWindow(imageTitle.getWindowToken(), 0);

}

@Override
public void showBadPicturePopup(@ImageUtils.Result int result) {
String errorTitle = getString(R.string.warning);
String errorMessage;
if (result == ImageUtils.IMAGE_DARK)
errorMessage = getString(R.string.upload_image_problem_dark);
Expand All @@ -350,52 +349,36 @@ else if (result == (ImageUtils.IMAGE_BLURRY|ImageUtils.IMAGE_DUPLICATE))
errorMessage = getString(R.string.upload_image_problem_blurry_duplicate);
else if (result == (ImageUtils.IMAGE_DARK|ImageUtils.IMAGE_BLURRY|ImageUtils.IMAGE_DUPLICATE))
errorMessage = getString(R.string.upload_image_problem_dark_blurry_duplicate);
else if (result == ImageUtils.FILE_NAME_EXISTS)
errorMessage = String.format(getString(R.string.upload_title_duplicate), presenter.getCurrentImageFileName());
else
return;

AlertDialog.Builder errorDialogBuilder = new AlertDialog.Builder(this);
errorDialogBuilder.setMessage(errorMessage);
errorDialogBuilder.setTitle(errorTitle);
//user does not wish to upload the picture, delete it
errorDialogBuilder.setPositiveButton(R.string.no, (dialogInterface, i) -> {
presenter.deletePicture();
dialogInterface.dismiss();
});
//user wishes to go ahead with the upload of this picture, just dismiss this dialog
errorDialogBuilder.setNegativeButton(R.string.yes, (DialogInterface dialogInterface, int i) -> {
presenter.keepPicture();
dialogInterface.dismiss();
if(result == ImageUtils.FILE_NAME_EXISTS) {
presenter.handleNext(categoriesModel, false);
}
});
DialogUtil.showAlertDialog(this,
getString(R.string.warning),
errorMessage,
() -> presenter.deletePicture(),
() -> presenter.keepPicture());
}

AlertDialog errorDialog = errorDialogBuilder.create();
if (!isFinishing()) {
errorDialog.show();
}
@Override
public void showDuplicatePicturePopup() {
DialogUtil.showAlertDialog(this,
getString(R.string.warning),
String.format(getString(R.string.upload_title_duplicate), presenter.getCurrentImageFileName()),
null,
() -> {
presenter.keepPicture();
presenter.handleNext(categoriesModel, false);
});
}

public void showNoCategorySelectedWarning() {
AlertDialog.Builder errorDialogBuilder = new AlertDialog.Builder(this);
errorDialogBuilder.setMessage(R.string.no_categories_selected_warning_desc);
errorDialogBuilder.setTitle(R.string.no_categories_selected);
//user does not wish to upload the picture, delete it
errorDialogBuilder.setPositiveButton(R.string.no_go_back, (dialogInterface, i) -> {
dialogInterface.dismiss();
});
//user wishes to go ahead with the upload of this picture, just dismiss this dialog
errorDialogBuilder.setNegativeButton(R.string.yes_submit, (DialogInterface dialogInterface, int i) -> {
presenter.handleNext(categoriesModel, true);
dialogInterface.dismiss();
});

AlertDialog errorDialog = errorDialogBuilder.create();
if (!isFinishing()) {
errorDialog.show();
}
DialogUtil.showAlertDialog(this,
getString(R.string.no_categories_selected),
getString(R.string.no_categories_selected_warning_desc),
getString(R.string.no_go_back),
getString(R.string.yes_submit),
null,
() -> presenter.handleNext(categoriesModel, true));
}

@Override
Expand All @@ -413,20 +396,6 @@ public void initDefaultCategories() {
updateCategoryList("");
}

@Override
protected void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
Bundle state = presenter.getSavedState();
outState.putAll(state);
int itemCount = categoriesAdapter.getItemCount();
ArrayList<CategoryItem> items = new ArrayList<>(itemCount);
for (int i = 0; i < itemCount; i++) {
items.add(categoriesAdapter.getItem(i));
}
outState.putParcelableArrayList("currentCategories", items);
outState.putSerializable("categoriesCache", categoriesModel.getCategoriesCache());
}

@Override
protected void onAuthCookieAcquired(String authCookie) {
mwApi.setAuthCookie(authCookie);
Expand Down
39 changes: 0 additions & 39 deletions app/src/main/java/fr/free/nrw/commons/upload/UploadController.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import java.util.Date;
import java.util.concurrent.Executors;

import fr.free.nrw.commons.CommonsApplication;
import fr.free.nrw.commons.HandlerService;
import fr.free.nrw.commons.R;
import fr.free.nrw.commons.auth.SessionManager;
Expand Down Expand Up @@ -85,44 +84,6 @@ public void cleanup() {
}
}

/**
* Starts a new upload task.
*
* @param title the title of the contribution
* @param mediaUri the media URI of the contribution
* @param description the description of the contribution
* @param mimeType the MIME type of the contribution
* @param source the source of the contribution
* @param decimalCoords the coordinates in decimal. (e.g. "37.51136|-77.602615")
* @param wikiDataEntityId
* @param onComplete the progress tracker
*/
public void startUpload(String title, Uri contentProviderUri, Uri mediaUri, String description, String mimeType, String source, String decimalCoords, String wikiDataEntityId, ContributionUploadProgress onComplete) {
Contribution contribution;

Timber.d("Wikidata entity ID received from Share activity is %s", wikiDataEntityId);
//TODO: Modify this to include coords
Account currentAccount = sessionManager.getCurrentAccount();
if (currentAccount == null) {
Timber.d("Current account is null");
ViewUtil.showLongToast(context, context.getString(R.string.user_not_logged_in));
sessionManager.forceLogin(context);
return;
}
contribution = new Contribution(mediaUri, null, title, description, -1,
null, null, currentAccount.name,
CommonsApplication.DEFAULT_EDIT_SUMMARY, decimalCoords);


contribution.setTag("mimeType", mimeType);
contribution.setSource(source);
contribution.setWikiDataEntityId(wikiDataEntityId);
contribution.setContentProviderUri(contentProviderUri);

//Calls the next overloaded method
startUpload(contribution, onComplete);
}

/**
* Starts a new upload task.
*
Expand Down
20 changes: 2 additions & 18 deletions app/src/main/java/fr/free/nrw/commons/upload/UploadPresenter.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import android.annotation.SuppressLint;
import android.net.Uri;
import android.os.Bundle;

import java.lang.reflect.Proxy;
import java.util.ArrayList;
Expand All @@ -20,7 +19,6 @@
import io.reactivex.Completable;
import io.reactivex.Observable;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.disposables.CompositeDisposable;
import io.reactivex.schedulers.Schedulers;
import timber.log.Timber;

Expand All @@ -35,8 +33,6 @@
*/
@Singleton
public class UploadPresenter {
private static final String TOP_CARD_STATE = "fr.free.nrw.commons.upload.top_card_state";
private static final String BOTTOM_CARD_STATE = "fr.free.nrw.commons.upload.bottom_card_state";

private final UploadModel uploadModel;
private final UploadController uploadController;
Expand Down Expand Up @@ -149,7 +145,7 @@ private void handleImage(Integer errorCode) {
if(getCurrentItem().imageQuality.getValue().equals(IMAGE_KEEP)) {
nextUploadedItem();
} else {
view.showBadPicturePopup(FILE_NAME_EXISTS);
view.showDuplicatePicturePopup();
}
break;
case IMAGE_OK:
Expand Down Expand Up @@ -310,26 +306,14 @@ public void closeAllCards() {
//endregion

//region View / Lifecycle management
public void initFromSavedState(Bundle state) {
if (state != null) {
Timber.i("Saved state is not null.");
uploadModel.setTopCardState(state.getBoolean(TOP_CARD_STATE, true));
uploadModel.setBottomCardState(state.getBoolean(BOTTOM_CARD_STATE, true));
}
public void init() {
uploadController.prepareService();
}

public void cleanup() {
uploadController.cleanup();
}

public Bundle getSavedState() {
Bundle bundle = new Bundle();
bundle.putBoolean(TOP_CARD_STATE, uploadModel.isTopCardState());
bundle.putBoolean(BOTTOM_CARD_STATE, uploadModel.isBottomCardState());
return bundle;
}

public void removeView() {
this.view = DUMMY;
}
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/java/fr/free/nrw/commons/upload/UploadView.java
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ public interface UploadView {

void showBadPicturePopup(@ImageUtils.Result int errorMessage);

void showDuplicatePicturePopup();

void finish();

void launchMapActivity(String decCoords);
Expand Down
43 changes: 43 additions & 0 deletions app/src/main/java/fr/free/nrw/commons/utils/DialogUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import android.app.AlertDialog.Builder;
import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
import android.os.Build;
import android.support.annotation.Nullable;
import android.support.v4.app.DialogFragment;
Expand Down Expand Up @@ -114,7 +115,49 @@ public static AlertDialog getAlertDialogWithPositiveAndNegativeCallbacks(
.setIcon(iconResourceId).create();

return alertDialog;
}

public static void showAlertDialog(Activity activity,
String title,
String message,
final Runnable onPositiveBtnClick,
final Runnable onNegativeBtnClick) {
showAlertDialog(activity,
title,
message,
activity.getString(R.string.no),
activity.getString(R.string.yes),
onPositiveBtnClick,
onNegativeBtnClick);
}

public static void showAlertDialog(Activity activity,
String title,
String message,
String positiveButtonText,
String negativeButtonText,
final Runnable onPositiveBtnClick,
final Runnable onNegativeBtnClick) {
AlertDialog.Builder builder = new AlertDialog.Builder(activity);
builder.setTitle(title);
builder.setMessage(message);

builder.setPositiveButton(positiveButtonText, (dialogInterface, i) -> {
dialogInterface.dismiss();
if (onPositiveBtnClick != null) {
onPositiveBtnClick.run();
}
});

builder.setNegativeButton(negativeButtonText, (DialogInterface dialogInterface, int i) -> {
dialogInterface.dismiss();
if (onNegativeBtnClick != null) {
onNegativeBtnClick.run();
}
});

AlertDialog dialog = builder.create();
showSafely(activity, dialog);
}

public interface Callback {
Expand Down

0 comments on commit 6ff0684

Please sign in to comment.