mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-28 05:13:53 +01:00
* Add showAlertDialog option for UploadPresenter to use * Move location reminder logic from UploadActivity to UploadPresenter * Add test cases for dialog alert with handleSubmit * Change threshold variable name to be more descriptive * Fix broken reference to renamed constant in tests
This commit is contained in:
parent
9bf5cf7441
commit
1a8a068552
4 changed files with 93 additions and 15 deletions
|
|
@ -470,6 +470,16 @@ public class UploadActivity extends BaseActivity implements UploadContract.View,
|
|||
.show();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void showAlertDialog(int messageResourceId, Runnable onPositiveClick) {
|
||||
DialogUtil.showAlertDialog(this,
|
||||
"",
|
||||
getString(messageResourceId),
|
||||
getString(R.string.ok),
|
||||
onPositiveClick,
|
||||
false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNextButtonClicked(int index) {
|
||||
if (index < fragments.size() - 1) {
|
||||
|
|
@ -478,18 +488,7 @@ public class UploadActivity extends BaseActivity implements UploadContract.View,
|
|||
((LinearLayoutManager) rvThumbnails.getLayoutManager())
|
||||
.scrollToPositionWithOffset((index > 0) ? index-1 : 0, 0);
|
||||
} else {
|
||||
if(defaultKvStore.getInt(COUNTER_OF_CONSECUTIVE_UPLOADS_WITHOUT_COORDINATES, 0) >= 10){
|
||||
DialogUtil.showAlertDialog(this,
|
||||
"",
|
||||
getString(R.string.location_message),
|
||||
getString(R.string.ok),
|
||||
() -> {
|
||||
defaultKvStore.putInt(COUNTER_OF_CONSECUTIVE_UPLOADS_WITHOUT_COORDINATES, 0);
|
||||
presenter.handleSubmit();
|
||||
}, false);
|
||||
} else {
|
||||
presenter.handleSubmit();
|
||||
}
|
||||
presenter.handleSubmit();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -24,6 +24,12 @@ public interface UploadContract {
|
|||
|
||||
void showMessage(int messageResourceId);
|
||||
|
||||
/**
|
||||
* Displays an alert with message given by {@code messageResourceId}.
|
||||
* {@code onPositiveClick} is run after acknowledgement.
|
||||
*/
|
||||
void showAlertDialog(int messageResourceId, Runnable onPositiveClick);
|
||||
|
||||
List<UploadableFile> getUploadableFiles();
|
||||
|
||||
void showHideTopCard(boolean shouldShow);
|
||||
|
|
|
|||
|
|
@ -35,6 +35,8 @@ public class UploadPresenter implements UploadContract.UserActionListener {
|
|||
public static final String COUNTER_OF_CONSECUTIVE_UPLOADS_WITHOUT_COORDINATES
|
||||
= "number_of_consecutive_uploads_without_coordinates";
|
||||
|
||||
public static final int CONSECUTIVE_UPLOADS_WITHOUT_COORDINATES_REMINDER_THRESHOLD = 10;
|
||||
|
||||
|
||||
@Inject
|
||||
UploadPresenter(UploadRepository uploadRepository,
|
||||
|
|
@ -51,6 +53,31 @@ public class UploadPresenter implements UploadContract.UserActionListener {
|
|||
@SuppressLint("CheckResult")
|
||||
@Override
|
||||
public void handleSubmit() {
|
||||
boolean hasLocationProvidedForNewUploads = false;
|
||||
for (UploadItem item : repository.getUploads()) {
|
||||
if (item.getGpsCoords().getImageCoordsExists()) {
|
||||
hasLocationProvidedForNewUploads = true;
|
||||
}
|
||||
}
|
||||
boolean hasManyConsecutiveUploadsWithoutLocation = defaultKvStore.getInt(
|
||||
COUNTER_OF_CONSECUTIVE_UPLOADS_WITHOUT_COORDINATES, 0) >=
|
||||
CONSECUTIVE_UPLOADS_WITHOUT_COORDINATES_REMINDER_THRESHOLD;
|
||||
|
||||
if (hasManyConsecutiveUploadsWithoutLocation && !hasLocationProvidedForNewUploads) {
|
||||
defaultKvStore.putInt(COUNTER_OF_CONSECUTIVE_UPLOADS_WITHOUT_COORDINATES, 0);
|
||||
view.showAlertDialog(
|
||||
R.string.location_message,
|
||||
() -> {defaultKvStore.putInt(
|
||||
COUNTER_OF_CONSECUTIVE_UPLOADS_WITHOUT_COORDINATES,
|
||||
0);
|
||||
processContributionsForSubmission();
|
||||
});
|
||||
} else {
|
||||
processContributionsForSubmission();
|
||||
}
|
||||
}
|
||||
|
||||
private void processContributionsForSubmission() {
|
||||
if (view.isLoggedIn()) {
|
||||
view.showProgress(true);
|
||||
repository.buildContributions()
|
||||
|
|
@ -72,9 +99,8 @@ public class UploadPresenter implements UploadContract.UserActionListener {
|
|||
|
||||
@Override
|
||||
public void onNext(Contribution contribution) {
|
||||
if(contribution.getDecimalCoords() == null){
|
||||
final int recentCount
|
||||
= defaultKvStore.getInt(
|
||||
if (contribution.getDecimalCoords() == null) {
|
||||
final int recentCount = defaultKvStore.getInt(
|
||||
COUNTER_OF_CONSECUTIVE_UPLOADS_WITHOUT_COORDINATES, 0);
|
||||
defaultKvStore.putInt(
|
||||
COUNTER_OF_CONSECUTIVE_UPLOADS_WITHOUT_COORDINATES, recentCount + 1);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue