From 7d4803bac4c1ccd23af4bde7584f3a1b85793139 Mon Sep 17 00:00:00 2001 From: isdl03 Date: Mon, 21 Dec 2020 20:36:54 +0530 Subject: [PATCH] Set limit on maximum number of images that can be uploaded at a time to 5. --- .../nrw/commons/upload/UploadActivity.java | 71 ++++++++++--------- app/src/main/res/values/strings.xml | 3 +- 2 files changed, 41 insertions(+), 33 deletions(-) diff --git a/app/src/main/java/fr/free/nrw/commons/upload/UploadActivity.java b/app/src/main/java/fr/free/nrw/commons/upload/UploadActivity.java index 16e4371543..a9013b4cbd 100644 --- a/app/src/main/java/fr/free/nrw/commons/upload/UploadActivity.java +++ b/app/src/main/java/fr/free/nrw/commons/upload/UploadActivity.java @@ -14,6 +14,7 @@ import android.widget.LinearLayout; import android.widget.RelativeLayout; import android.widget.TextView; +import android.widget.Toast; import androidx.appcompat.app.AlertDialog; import androidx.cardview.widget.CardView; import androidx.fragment.app.Fragment; @@ -115,10 +116,10 @@ protected void onCreate(Bundle savedInstanceState) { init(); PermissionUtils.checkPermissionsAndPerformAction(this, - Manifest.permission.WRITE_EXTERNAL_STORAGE, - this::receiveSharedItems, - R.string.storage_permission_title, - R.string.write_storage_permission_rationale_for_image_share); + Manifest.permission.WRITE_EXTERNAL_STORAGE, + this::receiveSharedItems, + R.string.storage_permission_title, + R.string.write_storage_permission_rationale_for_image_share); } private void init() { @@ -135,7 +136,7 @@ private void initProgressDialog() { private void initThumbnailsRecyclerView() { rvThumbnails.setLayoutManager(new LinearLayoutManager(this, - LinearLayoutManager.HORIZONTAL, false)); + LinearLayoutManager.HORIZONTAL, false)); thumbnailsAdapter = new ThumbnailsAdapter(() -> currentSelectedPosition); rvThumbnails.setAdapter(thumbnailsAdapter); @@ -147,7 +148,7 @@ private void initViewPager() { vpUpload.addOnPageChangeListener(new ViewPager.OnPageChangeListener() { @Override public void onPageScrolled(int position, float positionOffset, - int positionOffsetPixels) { + int positionOffsetPixels) { } @@ -192,22 +193,22 @@ protected void onResume() { */ protected void checkBlockStatus() { compositeDisposable.add(userClient.isUserBlockedFromCommons() - .subscribeOn(Schedulers.io()) - .observeOn(AndroidSchedulers.mainThread()) - .filter(result -> result) - .subscribe(result -> showInfoAlert(R.string.block_notification_title, - R.string.block_notification, UploadActivity.this::finish) - )); + .subscribeOn(Schedulers.io()) + .observeOn(AndroidSchedulers.mainThread()) + .filter(result -> result) + .subscribe(result -> showInfoAlert(R.string.block_notification_title, + R.string.block_notification, UploadActivity.this::finish) + )); } private void checkStoragePermissions() { PermissionUtils.checkPermissionsAndPerformAction(this, - Manifest.permission.WRITE_EXTERNAL_STORAGE, - () -> { - //TODO handle this - }, - R.string.storage_permission_title, - R.string.write_storage_permission_rationale_for_image_share); + Manifest.permission.WRITE_EXTERNAL_STORAGE, + () -> { + //TODO handle this + }, + R.string.storage_permission_title, + R.string.write_storage_permission_rationale_for_image_share); } @@ -268,7 +269,7 @@ public void onUploadMediaDeleted(int index) { @Override public void updateTopCardTitle() { tvTopCardTitle.setText(getResources() - .getQuantityString(R.plurals.upload_count_title, uploadableFiles.size(), uploadableFiles.size())); + .getQuantityString(R.plurals.upload_count_title, uploadableFiles.size(), uploadableFiles.size())); } @Override @@ -297,19 +298,21 @@ private void receiveSharedItems() { } else if (ACTION_INTERNAL_UPLOADS.equals(action)) { receiveInternalSharedItems(); } - - if (uploadableFiles == null || uploadableFiles.isEmpty()) { + if (uploadableFiles.size() > 5) { + handleLargeMedia(); + } + else if (uploadableFiles == null || uploadableFiles.isEmpty()) { handleNullMedia(); } else { //Show thumbnails if (uploadableFiles.size() - > 1) {//If there is only file, no need to show the image thumbnails + > 1) {//If there is only file, no need to show the image thumbnails thumbnailsAdapter.setUploadableFiles(uploadableFiles); } else { llContainerTopCard.setVisibility(View.GONE); } tvTopCardTitle.setText(getResources() - .getQuantityString(R.plurals.upload_count_title, uploadableFiles.size(), uploadableFiles.size())); + .getQuantityString(R.plurals.upload_count_title, uploadableFiles.size(), uploadableFiles.size())); fragments = new ArrayList<>(); for (UploadableFile uploadableFile : uploadableFiles) { @@ -395,18 +398,22 @@ private void handleNullMedia() { ViewUtil.showLongToast(this, R.string.error_processing_image); finish(); } + private void handleLargeMedia() { + ViewUtil.showLongToast(this, R.string.HandleLargeMedia); + finish(); + } private void showInfoAlert(int titleStringID, int messageStringId, Runnable positive, String... formatArgs) { new AlertDialog.Builder(this) - .setTitle(titleStringID) - .setMessage(getString(messageStringId, (Object[]) formatArgs)) - .setCancelable(true) - .setPositiveButton(android.R.string.ok, (dialog, id) -> { - positive.run(); - dialog.cancel(); - }) - .create() - .show(); + .setTitle(titleStringID) + .setMessage(getString(messageStringId, (Object[]) formatArgs)) + .setCancelable(true) + .setPositiveButton(android.R.string.ok, (dialog, id) -> { + positive.run(); + dialog.cancel(); + }) + .create() + .show(); } @Override diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index a612f3251a..d7877d5322 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -428,7 +428,7 @@ Notifications Notifications (read) Display nearby notification - Tap here to see the nearest place that needs pictures + Show in-app notification for the nearest place that needs pictures No nearby places found close to you List @@ -699,4 +699,5 @@ Upload your first media by tapping on the add button. Limited Connection Quality Images Quality images are diagrams or photographs that meet certain quality standards (which are mostly technical in nature) and are valuable for Wikimedia projects + Please upload atmost 5 images at a time!