Skip to content

Commit 7d4803b

Browse files
committed
Set limit on maximum number of images that can be uploaded at a time to 5.
1 parent 9d99c25 commit 7d4803b

File tree

2 files changed

+41
-33
lines changed

2 files changed

+41
-33
lines changed

app/src/main/java/fr/free/nrw/commons/upload/UploadActivity.java

Lines changed: 39 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import android.widget.LinearLayout;
1515
import android.widget.RelativeLayout;
1616
import android.widget.TextView;
17+
import android.widget.Toast;
1718
import androidx.appcompat.app.AlertDialog;
1819
import androidx.cardview.widget.CardView;
1920
import androidx.fragment.app.Fragment;
@@ -115,10 +116,10 @@ protected void onCreate(Bundle savedInstanceState) {
115116
init();
116117

117118
PermissionUtils.checkPermissionsAndPerformAction(this,
118-
Manifest.permission.WRITE_EXTERNAL_STORAGE,
119-
this::receiveSharedItems,
120-
R.string.storage_permission_title,
121-
R.string.write_storage_permission_rationale_for_image_share);
119+
Manifest.permission.WRITE_EXTERNAL_STORAGE,
120+
this::receiveSharedItems,
121+
R.string.storage_permission_title,
122+
R.string.write_storage_permission_rationale_for_image_share);
122123
}
123124

124125
private void init() {
@@ -135,7 +136,7 @@ private void initProgressDialog() {
135136

136137
private void initThumbnailsRecyclerView() {
137138
rvThumbnails.setLayoutManager(new LinearLayoutManager(this,
138-
LinearLayoutManager.HORIZONTAL, false));
139+
LinearLayoutManager.HORIZONTAL, false));
139140
thumbnailsAdapter = new ThumbnailsAdapter(() -> currentSelectedPosition);
140141
rvThumbnails.setAdapter(thumbnailsAdapter);
141142

@@ -147,7 +148,7 @@ private void initViewPager() {
147148
vpUpload.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
148149
@Override
149150
public void onPageScrolled(int position, float positionOffset,
150-
int positionOffsetPixels) {
151+
int positionOffsetPixels) {
151152

152153
}
153154

@@ -192,22 +193,22 @@ protected void onResume() {
192193
*/
193194
protected void checkBlockStatus() {
194195
compositeDisposable.add(userClient.isUserBlockedFromCommons()
195-
.subscribeOn(Schedulers.io())
196-
.observeOn(AndroidSchedulers.mainThread())
197-
.filter(result -> result)
198-
.subscribe(result -> showInfoAlert(R.string.block_notification_title,
199-
R.string.block_notification, UploadActivity.this::finish)
200-
));
196+
.subscribeOn(Schedulers.io())
197+
.observeOn(AndroidSchedulers.mainThread())
198+
.filter(result -> result)
199+
.subscribe(result -> showInfoAlert(R.string.block_notification_title,
200+
R.string.block_notification, UploadActivity.this::finish)
201+
));
201202
}
202203

203204
private void checkStoragePermissions() {
204205
PermissionUtils.checkPermissionsAndPerformAction(this,
205-
Manifest.permission.WRITE_EXTERNAL_STORAGE,
206-
() -> {
207-
//TODO handle this
208-
},
209-
R.string.storage_permission_title,
210-
R.string.write_storage_permission_rationale_for_image_share);
206+
Manifest.permission.WRITE_EXTERNAL_STORAGE,
207+
() -> {
208+
//TODO handle this
209+
},
210+
R.string.storage_permission_title,
211+
R.string.write_storage_permission_rationale_for_image_share);
211212
}
212213

213214

@@ -268,7 +269,7 @@ public void onUploadMediaDeleted(int index) {
268269
@Override
269270
public void updateTopCardTitle() {
270271
tvTopCardTitle.setText(getResources()
271-
.getQuantityString(R.plurals.upload_count_title, uploadableFiles.size(), uploadableFiles.size()));
272+
.getQuantityString(R.plurals.upload_count_title, uploadableFiles.size(), uploadableFiles.size()));
272273
}
273274

274275
@Override
@@ -297,19 +298,21 @@ private void receiveSharedItems() {
297298
} else if (ACTION_INTERNAL_UPLOADS.equals(action)) {
298299
receiveInternalSharedItems();
299300
}
300-
301-
if (uploadableFiles == null || uploadableFiles.isEmpty()) {
301+
if (uploadableFiles.size() > 5) {
302+
handleLargeMedia();
303+
}
304+
else if (uploadableFiles == null || uploadableFiles.isEmpty()) {
302305
handleNullMedia();
303306
} else {
304307
//Show thumbnails
305308
if (uploadableFiles.size()
306-
> 1) {//If there is only file, no need to show the image thumbnails
309+
> 1) {//If there is only file, no need to show the image thumbnails
307310
thumbnailsAdapter.setUploadableFiles(uploadableFiles);
308311
} else {
309312
llContainerTopCard.setVisibility(View.GONE);
310313
}
311314
tvTopCardTitle.setText(getResources()
312-
.getQuantityString(R.plurals.upload_count_title, uploadableFiles.size(), uploadableFiles.size()));
315+
.getQuantityString(R.plurals.upload_count_title, uploadableFiles.size(), uploadableFiles.size()));
313316

314317
fragments = new ArrayList<>();
315318
for (UploadableFile uploadableFile : uploadableFiles) {
@@ -395,18 +398,22 @@ private void handleNullMedia() {
395398
ViewUtil.showLongToast(this, R.string.error_processing_image);
396399
finish();
397400
}
401+
private void handleLargeMedia() {
402+
ViewUtil.showLongToast(this, R.string.HandleLargeMedia);
403+
finish();
404+
}
398405

399406
private void showInfoAlert(int titleStringID, int messageStringId, Runnable positive, String... formatArgs) {
400407
new AlertDialog.Builder(this)
401-
.setTitle(titleStringID)
402-
.setMessage(getString(messageStringId, (Object[]) formatArgs))
403-
.setCancelable(true)
404-
.setPositiveButton(android.R.string.ok, (dialog, id) -> {
405-
positive.run();
406-
dialog.cancel();
407-
})
408-
.create()
409-
.show();
408+
.setTitle(titleStringID)
409+
.setMessage(getString(messageStringId, (Object[]) formatArgs))
410+
.setCancelable(true)
411+
.setPositiveButton(android.R.string.ok, (dialog, id) -> {
412+
positive.run();
413+
dialog.cancel();
414+
})
415+
.create()
416+
.show();
410417
}
411418

412419
@Override

app/src/main/res/values/strings.xml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -428,7 +428,7 @@
428428
<string name="notifications">Notifications</string>
429429
<string name="read_notifications">Notifications (read)</string>
430430
<string name="display_nearby_notification">Display nearby notification</string>
431-
<string name="display_nearby_notification_summary">Tap here to see the nearest place that needs pictures</string>
431+
<string name="display_nearby_notification_summary">Show in-app notification for the nearest place that needs pictures</string>
432432

433433
<string name="no_close_nearby">No nearby places found close to you</string>
434434
<string name="list_sheet">List</string>
@@ -699,4 +699,5 @@ Upload your first media by tapping on the add button.</string>
699699
<string name="limited_connection">Limited Connection</string>
700700
<string name="statistics_quality">Quality Images</string>
701701
<string name="quality_images_info">Quality images are diagrams or photographs that meet certain quality standards (which are mostly technical in nature) and are valuable for Wikimedia projects</string>
702+
<string name="HandleLargeMedia">Please upload atmost 5 images at a time!</string>
702703
</resources>

0 commit comments

Comments
 (0)