do not display videos if the app is used as an image chooser

This commit is contained in:
tibbi 2016-06-15 15:40:07 +02:00
parent b36e85844d
commit 99a2ea6829
3 changed files with 16 additions and 5 deletions

View file

@ -3,5 +3,5 @@ package com.simplemobiletools.gallery;
public class Constants { public class Constants {
public static final String DIRECTORY = "directory"; public static final String DIRECTORY = "directory";
public static final String MEDIUM = "medium"; 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";
} }

View file

@ -55,12 +55,14 @@ public class MainActivity extends AppCompatActivity
private List<String> toBeDeleted; private List<String> toBeDeleted;
private ActionMode actionMode; private ActionMode actionMode;
private Parcelable state; private Parcelable state;
private boolean isImagePickIntent;
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main); setContentView(R.layout.activity_main);
ButterKnife.bind(this); ButterKnife.bind(this);
isImagePickIntent = isImagePickIntent(getIntent());
} }
@Override @Override
@ -137,6 +139,9 @@ public class MainActivity extends AppCompatActivity
for (int i = 0; i < 2; i++) { for (int i = 0; i < 2; i++) {
Uri uri = MediaStore.Images.Media.EXTERNAL_CONTENT_URI; Uri uri = MediaStore.Images.Media.EXTERNAL_CONTENT_URI;
if (i == 1) { if (i == 1) {
if (isImagePickIntent)
continue;
uri = MediaStore.Video.Media.EXTERNAL_CONTENT_URI; uri = MediaStore.Video.Media.EXTERNAL_CONTENT_URI;
} }
final String[] columns = {MediaStore.Images.Media.DATA}; final String[] columns = {MediaStore.Images.Media.DATA};
@ -319,8 +324,9 @@ public class MainActivity extends AppCompatActivity
}); });
} }
private boolean isPickIntent(Intent intent) { private boolean isImagePickIntent(Intent intent) {
return intent != null && intent.getAction() != null && intent.getAction().equals(Intent.ACTION_PICK); return intent != null && intent.getAction() != null && intent.getAction().equals(Intent.ACTION_PICK) &&
intent.getData().equals(MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
} }
@Override @Override
@ -338,7 +344,7 @@ public class MainActivity extends AppCompatActivity
public void onItemClick(AdapterView<?> parent, View view, int position, long id) { public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
final Intent intent = new Intent(this, MediaActivity.class); final Intent intent = new Intent(this, MediaActivity.class);
intent.putExtra(Constants.DIRECTORY, dirs.get(position).getPath()); 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); startActivityForResult(intent, PICK_IMAGE);
} }

View file

@ -47,12 +47,14 @@ public class MediaActivity extends AppCompatActivity
private boolean isSnackbarShown; private boolean isSnackbarShown;
private List<String> toBeDeleted; private List<String> toBeDeleted;
private Parcelable state; private Parcelable state;
private boolean isImagePickIntent;
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
setContentView(R.layout.activity_media); setContentView(R.layout.activity_media);
ButterKnife.bind(this); ButterKnife.bind(this);
isImagePickIntent = getIntent().getBooleanExtra(Constants.PICK_IMAGE_INTENT, false);
} }
@Override @Override
@ -110,6 +112,9 @@ public class MediaActivity extends AppCompatActivity
for (int i = 0; i < 2; i++) { for (int i = 0; i < 2; i++) {
Uri uri = MediaStore.Images.Media.EXTERNAL_CONTENT_URI; Uri uri = MediaStore.Images.Media.EXTERNAL_CONTENT_URI;
if (i == 1) { if (i == 1) {
if (isImagePickIntent)
continue;
uri = MediaStore.Video.Media.EXTERNAL_CONTENT_URI; uri = MediaStore.Video.Media.EXTERNAL_CONTENT_URI;
} }
final String where = MediaStore.Images.Media.DATA + " like ? "; final String where = MediaStore.Images.Media.DATA + " like ? ";
@ -234,7 +239,7 @@ public class MediaActivity extends AppCompatActivity
@Override @Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) { 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(); final Intent result = new Intent();
result.setData(Uri.parse(media.get(position).getPath())); result.setData(Uri.parse(media.get(position).getPath()));
setResult(RESULT_OK, result); setResult(RESULT_OK, result);