From be4cd3a2c4ce628a114e4db38605d0476e960f25 Mon Sep 17 00:00:00 2001 From: PhotonQyv Date: Wed, 23 Aug 2017 00:09:49 +0100 Subject: [PATCH] Updated the code so that only a maximum of four (4) shared images are attached to a toot, the rest are quietly discarded. --- .../mastodon/activities/TootActivity.java | 42 +++++++++++-------- 1 file changed, 25 insertions(+), 17 deletions(-) diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/activities/TootActivity.java b/app/src/main/java/fr/gouv/etalab/mastodon/activities/TootActivity.java index 6a81aeb7d..f8b97df9e 100644 --- a/app/src/main/java/fr/gouv/etalab/mastodon/activities/TootActivity.java +++ b/app/src/main/java/fr/gouv/etalab/mastodon/activities/TootActivity.java @@ -524,26 +524,34 @@ public class TootActivity extends AppCompatActivity implements OnRetrieveSearcAc public void uploadSharedImage(ArrayList uri) { if (!uri.isEmpty()) { - for(Uri fileUri: uri) { - if (fileUri != null) { - picture_scrollview.setVisibility(View.VISIBLE); - - try { - InputStream inputStream = getContentResolver().openInputStream(fileUri); - loading_picture.setVisibility(View.VISIBLE); - toot_picture.setEnabled(false); - new UploadActionAsyncTask(getApplicationContext(), inputStream, TootActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); - } catch (FileNotFoundException e) { - Toast.makeText(getApplicationContext(), R.string.toot_select_image_error, Toast.LENGTH_LONG).show(); - loading_picture.setVisibility(View.GONE); - toot_picture.setEnabled(true); - e.printStackTrace(); - } - } else { - Toast.makeText(getApplicationContext(), R.string.toot_select_image_error, Toast.LENGTH_LONG).show(); + int count = 0; + for(Uri fileUri: uri) { + if (fileUri != null) { + if (count == 4) + { + break; } + + picture_scrollview.setVisibility(View.VISIBLE); + + try { + InputStream inputStream = getContentResolver().openInputStream(fileUri); + loading_picture.setVisibility(View.VISIBLE); + toot_picture.setEnabled(false); + new UploadActionAsyncTask(getApplicationContext(), inputStream, TootActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); + count++; + + } catch (FileNotFoundException e) { + Toast.makeText(getApplicationContext(), R.string.toot_select_image_error, Toast.LENGTH_LONG).show(); + loading_picture.setVisibility(View.GONE); + toot_picture.setEnabled(true); + e.printStackTrace(); + } + } else { + Toast.makeText(getApplicationContext(), R.string.toot_select_image_error, Toast.LENGTH_LONG).show(); } } + } } @Override