From 99a2ea6829a961a3236fffa22744facfff09b456 Mon Sep 17 00:00:00 2001 From: tibbi Date: Wed, 15 Jun 2016 15:40:07 +0200 Subject: [PATCH] do not display videos if the app is used as an image chooser --- .../com/simplemobiletools/gallery/Constants.java | 2 +- .../gallery/activities/MainActivity.java | 12 +++++++++--- .../gallery/activities/MediaActivity.java | 7 ++++++- 3 files changed, 16 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/com/simplemobiletools/gallery/Constants.java b/app/src/main/java/com/simplemobiletools/gallery/Constants.java index 345479f6a..c18012513 100644 --- a/app/src/main/java/com/simplemobiletools/gallery/Constants.java +++ b/app/src/main/java/com/simplemobiletools/gallery/Constants.java @@ -3,5 +3,5 @@ package com.simplemobiletools.gallery; public class Constants { public static final String DIRECTORY = "directory"; public static final String MEDIUM = "medium"; - public static final String PICK_INTENT = "is_pick_intent"; + public static final String PICK_IMAGE_INTENT = "is_image_pick_intent"; } diff --git a/app/src/main/java/com/simplemobiletools/gallery/activities/MainActivity.java b/app/src/main/java/com/simplemobiletools/gallery/activities/MainActivity.java index 80f7ec92a..692663a72 100644 --- a/app/src/main/java/com/simplemobiletools/gallery/activities/MainActivity.java +++ b/app/src/main/java/com/simplemobiletools/gallery/activities/MainActivity.java @@ -55,12 +55,14 @@ public class MainActivity extends AppCompatActivity private List toBeDeleted; private ActionMode actionMode; private Parcelable state; + private boolean isImagePickIntent; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); ButterKnife.bind(this); + isImagePickIntent = isImagePickIntent(getIntent()); } @Override @@ -137,6 +139,9 @@ public class MainActivity extends AppCompatActivity for (int i = 0; i < 2; i++) { Uri uri = MediaStore.Images.Media.EXTERNAL_CONTENT_URI; if (i == 1) { + if (isImagePickIntent) + continue; + uri = MediaStore.Video.Media.EXTERNAL_CONTENT_URI; } final String[] columns = {MediaStore.Images.Media.DATA}; @@ -319,8 +324,9 @@ public class MainActivity extends AppCompatActivity }); } - private boolean isPickIntent(Intent intent) { - return intent != null && intent.getAction() != null && intent.getAction().equals(Intent.ACTION_PICK); + private boolean isImagePickIntent(Intent intent) { + return intent != null && intent.getAction() != null && intent.getAction().equals(Intent.ACTION_PICK) && + intent.getData().equals(MediaStore.Images.Media.EXTERNAL_CONTENT_URI); } @Override @@ -338,7 +344,7 @@ public class MainActivity extends AppCompatActivity public void onItemClick(AdapterView parent, View view, int position, long id) { final Intent intent = new Intent(this, MediaActivity.class); intent.putExtra(Constants.DIRECTORY, dirs.get(position).getPath()); - intent.putExtra(Constants.PICK_INTENT, isPickIntent(getIntent())); + intent.putExtra(Constants.PICK_IMAGE_INTENT, isImagePickIntent); startActivityForResult(intent, PICK_IMAGE); } diff --git a/app/src/main/java/com/simplemobiletools/gallery/activities/MediaActivity.java b/app/src/main/java/com/simplemobiletools/gallery/activities/MediaActivity.java index c68411d15..e30301361 100644 --- a/app/src/main/java/com/simplemobiletools/gallery/activities/MediaActivity.java +++ b/app/src/main/java/com/simplemobiletools/gallery/activities/MediaActivity.java @@ -47,12 +47,14 @@ public class MediaActivity extends AppCompatActivity private boolean isSnackbarShown; private List toBeDeleted; private Parcelable state; + private boolean isImagePickIntent; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_media); ButterKnife.bind(this); + isImagePickIntent = getIntent().getBooleanExtra(Constants.PICK_IMAGE_INTENT, false); } @Override @@ -110,6 +112,9 @@ public class MediaActivity extends AppCompatActivity for (int i = 0; i < 2; i++) { Uri uri = MediaStore.Images.Media.EXTERNAL_CONTENT_URI; if (i == 1) { + if (isImagePickIntent) + continue; + uri = MediaStore.Video.Media.EXTERNAL_CONTENT_URI; } final String where = MediaStore.Images.Media.DATA + " like ? "; @@ -234,7 +239,7 @@ public class MediaActivity extends AppCompatActivity @Override public void onItemClick(AdapterView parent, View view, int position, long id) { - if (getIntent().getBooleanExtra(Constants.PICK_INTENT, false)) { + if (isImagePickIntent) { final Intent result = new Intent(); result.setData(Uri.parse(media.get(position).getPath())); setResult(RESULT_OK, result);