diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml
index 62fe6b3a2..832968e31 100644
--- a/app/src/main/AndroidManifest.xml
+++ b/app/src/main/AndroidManifest.xml
@@ -21,7 +21,7 @@
+ android:name=".activities.MediaActivity"/>
parent, View view, int position, long id) {
- final Intent intent = new Intent(this, PhotosActivity.class);
+ final Intent intent = new Intent(this, MediaActivity.class);
intent.putExtra(Constants.DIRECTORY, dirs.get(position).getPath());
startActivity(intent);
}
diff --git a/app/src/main/java/com/simplemobiletools/gallery/activities/PhotosActivity.java b/app/src/main/java/com/simplemobiletools/gallery/activities/MediaActivity.java
similarity index 77%
rename from app/src/main/java/com/simplemobiletools/gallery/activities/PhotosActivity.java
rename to app/src/main/java/com/simplemobiletools/gallery/activities/MediaActivity.java
index 86ff2b8df..0a0583dd6 100644
--- a/app/src/main/java/com/simplemobiletools/gallery/activities/PhotosActivity.java
+++ b/app/src/main/java/com/simplemobiletools/gallery/activities/MediaActivity.java
@@ -28,9 +28,10 @@ import android.widget.GridView;
import android.widget.Toast;
import com.simplemobiletools.gallery.Constants;
+import com.simplemobiletools.gallery.Media;
import com.simplemobiletools.gallery.R;
import com.simplemobiletools.gallery.Utils;
-import com.simplemobiletools.gallery.adapters.PhotosAdapter;
+import com.simplemobiletools.gallery.adapters.MediaAdapter;
import java.io.File;
import java.util.ArrayList;
@@ -40,13 +41,13 @@ import java.util.regex.Pattern;
import butterknife.BindView;
import butterknife.ButterKnife;
-public class PhotosActivity extends AppCompatActivity
+public class MediaActivity extends AppCompatActivity
implements AdapterView.OnItemClickListener, GridView.MultiChoiceModeListener, MediaScannerConnection.OnScanCompletedListener,
GridView.OnTouchListener {
- @BindView(R.id.photos_grid) GridView gridView;
+ @BindView(R.id.media_grid) GridView gridView;
private static final int STORAGE_PERMISSION = 1;
- private List photos;
+ private List media;
private int selectedItemsCnt;
private String path;
private Snackbar snackbar;
@@ -57,7 +58,7 @@ public class PhotosActivity extends AppCompatActivity
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_photos);
+ setContentView(R.layout.activity_media);
ButterKnife.bind(this);
}
@@ -101,11 +102,11 @@ public class PhotosActivity extends AppCompatActivity
private void initializeGallery() {
toBeDeleted = new ArrayList<>();
path = getIntent().getStringExtra(Constants.DIRECTORY);
- photos = getPhotos();
+ media = getMedia();
if (isDirEmpty())
return;
- final PhotosAdapter adapter = new PhotosAdapter(this, photos);
+ final MediaAdapter adapter = new MediaAdapter(this, media);
gridView.setAdapter(adapter);
gridView.setOnItemClickListener(this);
gridView.setMultiChoiceModeListener(this);
@@ -123,34 +124,39 @@ public class PhotosActivity extends AppCompatActivity
}
}
- private List getPhotos() {
- final List myPhotos = new ArrayList<>();
- final Uri uri = MediaStore.Images.Media.EXTERNAL_CONTENT_URI;
- final String where = MediaStore.Images.Media.DATA + " like ? ";
- final String[] args = new String[]{path + "%"};
- final String[] columns = {MediaStore.Images.Media.DATA};
- final String order = MediaStore.Images.Media.DATE_MODIFIED + " DESC";
- final Cursor cursor = getContentResolver().query(uri, columns, where, args, order);
- final String pattern = Pattern.quote(path) + "/[^/]*";
+ private List getMedia() {
+ final List myMedia = new ArrayList<>();
+ for (int i = 0; i < 2; i++) {
+ Uri uri = MediaStore.Images.Media.EXTERNAL_CONTENT_URI;
+ if (i == 1) {
+ uri = MediaStore.Video.Media.EXTERNAL_CONTENT_URI;
+ }
+ final String where = MediaStore.Images.Media.DATA + " like ? ";
+ final String[] args = new String[]{path + "%"};
+ final String[] columns = {MediaStore.Images.Media.DATA};
+ final String order = MediaStore.Images.Media.DATE_MODIFIED + " DESC";
+ final Cursor cursor = getContentResolver().query(uri, columns, where, args, order);
+ final String pattern = Pattern.quote(path) + "/[^/]*";
- if (cursor != null && cursor.moveToFirst()) {
- final int pathIndex = cursor.getColumnIndex(MediaStore.Images.Media.DATA);
- do {
- final String curPath = cursor.getString(pathIndex);
- if (curPath.matches(pattern) && !toBeDeleted.contains(curPath)) {
- final File file = new File(curPath);
- if (file.exists()) {
- myPhotos.add(cursor.getString(pathIndex));
+ if (cursor != null && cursor.moveToFirst()) {
+ final int pathIndex = cursor.getColumnIndex(MediaStore.Images.Media.DATA);
+ do {
+ final String curPath = cursor.getString(pathIndex);
+ if (curPath.matches(pattern) && !toBeDeleted.contains(curPath)) {
+ final File file = new File(curPath);
+ if (file.exists()) {
+ myMedia.add(new Media(cursor.getString(pathIndex), (i == 1)));
+ }
}
- }
- } while (cursor.moveToNext());
- cursor.close();
+ } while (cursor.moveToNext());
+ cursor.close();
+ }
}
- return myPhotos;
+ return myMedia;
}
private boolean isDirEmpty() {
- if (photos.size() <= 0) {
+ if (media.size() <= 0) {
deleteDirectoryIfEmpty();
finish();
return true;
@@ -166,7 +172,7 @@ public class PhotosActivity extends AppCompatActivity
for (int i = 0; i < cnt; i++) {
if (items.valueAt(i)) {
final int id = items.keyAt(i);
- final String path = photos.get(id);
+ final String path = media.get(id).getPath();
toBeDeleted.add(path);
deletedCnt++;
}
@@ -176,9 +182,9 @@ public class PhotosActivity extends AppCompatActivity
}
private void notifyDeletion(int cnt) {
- photos = getPhotos();
+ media = getMedia();
- if (photos.isEmpty()) {
+ if (media.isEmpty()) {
deleteFiles();
} else {
final CoordinatorLayout coordinator = (CoordinatorLayout) findViewById(R.id.coordinator_layout);
@@ -220,22 +226,22 @@ public class PhotosActivity extends AppCompatActivity
snackbar.dismiss();
isSnackbarShown = false;
toBeDeleted.clear();
- photos = getPhotos();
+ media = getMedia();
updateGridView();
}
};
private void updateGridView() {
if (!isDirEmpty()) {
- final PhotosAdapter adapter = (PhotosAdapter) gridView.getAdapter();
- adapter.updateItems(photos);
+ final MediaAdapter adapter = (MediaAdapter) gridView.getAdapter();
+ adapter.updateItems(media);
}
}
@Override
public void onItemClick(AdapterView> parent, View view, int position, long id) {
final Intent intent = new Intent(this, ViewPagerActivity.class);
- intent.putExtra(Constants.PHOTO, photos.get(position));
+ intent.putExtra(Constants.MEDIUM, media.get(position).getPath());
startActivity(intent);
}
@@ -255,7 +261,7 @@ public class PhotosActivity extends AppCompatActivity
@Override
public boolean onCreateActionMode(ActionMode mode, Menu menu) {
final MenuInflater inflater = mode.getMenuInflater();
- inflater.inflate(R.menu.photos_menu, menu);
+ inflater.inflate(R.menu.media_menu, menu);
return true;
}
@@ -283,7 +289,7 @@ public class PhotosActivity extends AppCompatActivity
@Override
public void onScanCompleted(String path, Uri uri) {
- if (photos.isEmpty()) {
+ if (media.isEmpty()) {
finish();
}
}
diff --git a/app/src/main/java/com/simplemobiletools/gallery/activities/ViewPagerActivity.java b/app/src/main/java/com/simplemobiletools/gallery/activities/ViewPagerActivity.java
index f5ef27770..c4db212ac 100644
--- a/app/src/main/java/com/simplemobiletools/gallery/activities/ViewPagerActivity.java
+++ b/app/src/main/java/com/simplemobiletools/gallery/activities/ViewPagerActivity.java
@@ -21,6 +21,7 @@ import android.widget.EditText;
import android.widget.RelativeLayout;
import com.simplemobiletools.gallery.Constants;
+import com.simplemobiletools.gallery.Media;
import com.simplemobiletools.gallery.MyViewPager;
import com.simplemobiletools.gallery.R;
import com.simplemobiletools.gallery.Utils;
@@ -44,7 +45,7 @@ public class ViewPagerActivity extends AppCompatActivity
private int pos;
private boolean isFullScreen;
private ActionBar actionbar;
- private List photos;
+ private List media;
private String path;
private String directory;
private boolean isUndoShown;
@@ -54,7 +55,7 @@ public class ViewPagerActivity extends AppCompatActivity
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_photo);
+ setContentView(R.layout.activity_medium);
ButterKnife.bind(this);
pos = 0;
@@ -64,15 +65,15 @@ public class ViewPagerActivity extends AppCompatActivity
beingDeleted = "";
hideSystemUI();
- path = getIntent().getStringExtra(Constants.PHOTO);
+ path = getIntent().getStringExtra(Constants.MEDIUM);
MediaScannerConnection.scanFile(this, new String[]{path}, null, null);
addUndoMargin();
directory = new File(path).getParent();
- photos = getPhotos();
+ media = getMedia();
if (isDirEmpty())
return;
- final MyPagerAdapter adapter = new MyPagerAdapter(getSupportFragmentManager(), photos);
+ final MyPagerAdapter adapter = new MyPagerAdapter(getSupportFragmentManager(), media);
pager.setAdapter(adapter);
pager.setCurrentItem(pos);
pager.addOnPageChangeListener(this);
@@ -103,20 +104,20 @@ public class ViewPagerActivity extends AppCompatActivity
deleteFile();
switch (item.getItemId()) {
case R.id.menu_share:
- shareImage();
+ shareMedium();
return true;
case R.id.menu_delete:
notifyDeletion();
return true;
case R.id.menu_edit:
- editImage();
+ editMedium();
return true;
default:
return super.onOptionsItemSelected(item);
}
}
- private void shareImage() {
+ private void shareMedium() {
final String shareTitle = getResources().getString(R.string.share_via);
final Intent sendIntent = new Intent();
final File file = getCurrentFile();
@@ -130,7 +131,7 @@ public class ViewPagerActivity extends AppCompatActivity
private void notifyDeletion() {
toBeDeleted = getCurrentFile().getAbsolutePath();
- if (photos.size() <= 1) {
+ if (media.size() <= 1) {
deleteFile();
} else {
Utils.showToast(this, R.string.file_deleted);
@@ -158,7 +159,7 @@ public class ViewPagerActivity extends AppCompatActivity
}
private boolean isDirEmpty() {
- if (photos.size() <= 0) {
+ if (media.size() <= 0) {
deleteDirectoryIfEmpty();
finish();
return true;
@@ -166,7 +167,7 @@ public class ViewPagerActivity extends AppCompatActivity
return false;
}
- private void editImage() {
+ private void editMedium() {
final File file = getCurrentFile();
final String fullName = file.getName();
final int dotAt = fullName.lastIndexOf(".");
@@ -206,7 +207,8 @@ public class ViewPagerActivity extends AppCompatActivity
final File newFile = new File(file.getParent(), fileName + "." + extension);
if (file.renameTo(newFile)) {
- photos.set(pager.getCurrentItem(), newFile.getAbsolutePath());
+ final int currItem = pager.getCurrentItem();
+ media.set(currItem, new Media(newFile.getAbsolutePath(), media.get(currItem).getIsVideo()));
final String[] changedFiles = {file.getAbsolutePath(), newFile.getAbsolutePath()};
MediaScannerConnection.scanFile(getApplicationContext(), changedFiles, null, null);
@@ -222,12 +224,12 @@ public class ViewPagerActivity extends AppCompatActivity
private void reloadViewPager() {
final MyPagerAdapter adapter = (MyPagerAdapter) pager.getAdapter();
final int curPos = pager.getCurrentItem();
- photos = getPhotos();
+ media = getMedia();
if (isDirEmpty())
return;
pager.setAdapter(null);
- adapter.updateItems(photos);
+ adapter.updateItems(media);
pager.setAdapter(adapter);
final int newPos = Math.min(curPos, adapter.getCount());
@@ -245,34 +247,39 @@ public class ViewPagerActivity extends AppCompatActivity
MediaScannerConnection.scanFile(getApplicationContext(), toBeDeleted, null, null);
}
- private List getPhotos() {
- final List photos = new ArrayList<>();
- final Uri uri = MediaStore.Images.Media.EXTERNAL_CONTENT_URI;
- final String where = MediaStore.Images.Media.DATA + " like ? ";
- final String[] args = new String[]{directory + "%"};
- final String[] columns = {MediaStore.Images.Media.DATA};
- final String order = MediaStore.Images.Media.DATE_MODIFIED + " DESC";
- final Cursor cursor = getContentResolver().query(uri, columns, where, args, order);
- final String pattern = Pattern.quote(directory) + "/[^/]*";
+ private List getMedia() {
+ final List media = new ArrayList<>();
+ for (int i = 0; i < 2; i++) {
+ Uri uri = MediaStore.Images.Media.EXTERNAL_CONTENT_URI;
+ if (i == 1) {
+ uri = MediaStore.Video.Media.EXTERNAL_CONTENT_URI;
+ }
+ final String where = MediaStore.Images.Media.DATA + " like ? ";
+ final String[] args = new String[]{directory + "%"};
+ final String[] columns = {MediaStore.Images.Media.DATA};
+ final String order = MediaStore.Images.Media.DATE_MODIFIED + " DESC";
+ final Cursor cursor = getContentResolver().query(uri, columns, where, args, order);
+ final String pattern = Pattern.quote(directory) + "/[^/]*";
- int i = 0;
- if (cursor != null && cursor.moveToFirst()) {
- final int pathIndex = cursor.getColumnIndex(MediaStore.Images.Media.DATA);
- do {
- final String curPath = cursor.getString(pathIndex);
- if (curPath.matches(pattern) && !curPath.equals(toBeDeleted) && !curPath.equals(beingDeleted)) {
- photos.add(curPath);
+ int j = 0;
+ if (cursor != null && cursor.moveToFirst()) {
+ final int pathIndex = cursor.getColumnIndex(MediaStore.Images.Media.DATA);
+ do {
+ final String curPath = cursor.getString(pathIndex);
+ if (curPath.matches(pattern) && !curPath.equals(toBeDeleted) && !curPath.equals(beingDeleted)) {
+ media.add(new Media(curPath, j == 1));
- if (curPath.equals(path)) {
- pos = i;
+ if (curPath.equals(path)) {
+ pos = j;
+ }
+
+ j++;
}
-
- i++;
- }
- } while (cursor.moveToNext());
- cursor.close();
+ } while (cursor.moveToNext());
+ cursor.close();
+ }
}
- return photos;
+ return media;
}
public void photoClicked() {
@@ -307,11 +314,11 @@ public class ViewPagerActivity extends AppCompatActivity
}
private void updateActionbarTitle() {
- setTitle(Utils.getFilename(photos.get(pager.getCurrentItem())));
+ setTitle(Utils.getFilename(media.get(pager.getCurrentItem()).getPath()));
}
private File getCurrentFile() {
- return new File(photos.get(pos));
+ return new File(media.get(pos).getPath());
}
private void addUndoMargin() {
@@ -364,7 +371,7 @@ public class ViewPagerActivity extends AppCompatActivity
runOnUiThread(new Runnable() {
@Override
public void run() {
- if (photos.size() <= 1)
+ if (media.size() <= 1)
reloadViewPager();
}
});
diff --git a/app/src/main/java/com/simplemobiletools/gallery/adapters/DirectoryAdapter.java b/app/src/main/java/com/simplemobiletools/gallery/adapters/DirectoryAdapter.java
index 834c3a1c4..cd763cddd 100644
--- a/app/src/main/java/com/simplemobiletools/gallery/adapters/DirectoryAdapter.java
+++ b/app/src/main/java/com/simplemobiletools/gallery/adapters/DirectoryAdapter.java
@@ -41,7 +41,7 @@ public class DirectoryAdapter extends BaseAdapter {
final Directory dir = dirs.get(position);
holder.dirName.setText(dir.getName());
- holder.photoCnt.setText(String.valueOf(dir.getPhotoCnt()));
+ holder.photoCnt.setText(String.valueOf(dir.getMediaCnt()));
Glide.with(context).load(dir.getThumbnail()).placeholder(R.color.tmb_background).centerCrop().crossFade().into(holder.dirThumbnail);
return view;
diff --git a/app/src/main/java/com/simplemobiletools/gallery/adapters/PhotosAdapter.java b/app/src/main/java/com/simplemobiletools/gallery/adapters/MediaAdapter.java
similarity index 72%
rename from app/src/main/java/com/simplemobiletools/gallery/adapters/PhotosAdapter.java
rename to app/src/main/java/com/simplemobiletools/gallery/adapters/MediaAdapter.java
index 4ffee791c..6126da209 100644
--- a/app/src/main/java/com/simplemobiletools/gallery/adapters/PhotosAdapter.java
+++ b/app/src/main/java/com/simplemobiletools/gallery/adapters/MediaAdapter.java
@@ -8,18 +8,19 @@ import android.widget.BaseAdapter;
import android.widget.ImageView;
import com.bumptech.glide.Glide;
+import com.simplemobiletools.gallery.Media;
import com.simplemobiletools.gallery.R;
import java.util.List;
-public class PhotosAdapter extends BaseAdapter {
+public class MediaAdapter extends BaseAdapter {
private final Context context;
- private final List photos;
+ private final List media;
private final LayoutInflater inflater;
- public PhotosAdapter(Context context, List photos) {
+ public MediaAdapter(Context context, List media) {
this.context = context;
- this.photos = photos;
+ this.media = media;
this.inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}
@@ -27,14 +28,14 @@ public class PhotosAdapter extends BaseAdapter {
public View getView(int position, View view, ViewGroup parent) {
ViewHolder holder;
if (view == null) {
- view = inflater.inflate(R.layout.photo_item, parent, false);
+ view = inflater.inflate(R.layout.medium_item, parent, false);
holder = new ViewHolder(view);
view.setTag(holder);
} else {
holder = (ViewHolder) view.getTag();
}
- final String path = photos.get(position);
+ final String path = media.get(position).getPath();
Glide.with(context).load(path).placeholder(R.color.tmb_background).centerCrop().crossFade().into(holder.photoThumbnail);
return view;
@@ -42,12 +43,12 @@ public class PhotosAdapter extends BaseAdapter {
@Override
public int getCount() {
- return photos.size();
+ return media.size();
}
@Override
public Object getItem(int position) {
- return photos.get(position);
+ return media.get(position);
}
@Override
@@ -55,9 +56,9 @@ public class PhotosAdapter extends BaseAdapter {
return 0;
}
- public void updateItems(List newPhotos) {
- photos.clear();
- photos.addAll(newPhotos);
+ public void updateItems(List newPhotos) {
+ media.clear();
+ media.addAll(newPhotos);
notifyDataSetChanged();
}
@@ -65,7 +66,7 @@ public class PhotosAdapter extends BaseAdapter {
ImageView photoThumbnail;
public ViewHolder(View view) {
- photoThumbnail = (ImageView) view.findViewById(R.id.photo_thumbnail);
+ photoThumbnail = (ImageView) view.findViewById(R.id.medium_thumbnail);
}
}
}
diff --git a/app/src/main/java/com/simplemobiletools/gallery/adapters/MyPagerAdapter.java b/app/src/main/java/com/simplemobiletools/gallery/adapters/MyPagerAdapter.java
index c56fe564c..ab2f637bf 100644
--- a/app/src/main/java/com/simplemobiletools/gallery/adapters/MyPagerAdapter.java
+++ b/app/src/main/java/com/simplemobiletools/gallery/adapters/MyPagerAdapter.java
@@ -4,14 +4,15 @@ import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentStatePagerAdapter;
+import com.simplemobiletools.gallery.Media;
import com.simplemobiletools.gallery.ViewPagerFragment;
import java.util.List;
public class MyPagerAdapter extends FragmentStatePagerAdapter {
- private List paths;
+ private List paths;
- public MyPagerAdapter(FragmentManager fm, List paths) {
+ public MyPagerAdapter(FragmentManager fm, List paths) {
super(fm);
this.paths = paths;
}
@@ -24,11 +25,11 @@ public class MyPagerAdapter extends FragmentStatePagerAdapter {
@Override
public Fragment getItem(int position) {
final ViewPagerFragment fragment = new ViewPagerFragment();
- fragment.setPath(paths.get(position));
+ fragment.setPath(paths.get(position).getPath());
return fragment;
}
- public void updateItems(List newPaths) {
+ public void updateItems(List newPaths) {
paths.clear();
paths.addAll(newPaths);
notifyDataSetChanged();
diff --git a/app/src/main/res/layout/activity_photos.xml b/app/src/main/res/layout/activity_media.xml
similarity index 88%
rename from app/src/main/res/layout/activity_photos.xml
rename to app/src/main/res/layout/activity_media.xml
index fdf7cc5d8..dc5279a1d 100644
--- a/app/src/main/res/layout/activity_photos.xml
+++ b/app/src/main/res/layout/activity_media.xml
@@ -7,11 +7,11 @@
android:background="@android:color/black">
diff --git a/app/src/main/res/menu/photos_menu.xml b/app/src/main/res/menu/media_menu.xml
similarity index 100%
rename from app/src/main/res/menu/photos_menu.xml
rename to app/src/main/res/menu/media_menu.xml
diff --git a/app/src/main/res/values/dimens.xml b/app/src/main/res/values/dimens.xml
index 34243aa13..58495b016 100644
--- a/app/src/main/res/values/dimens.xml
+++ b/app/src/main/res/values/dimens.xml
@@ -1,6 +1,6 @@
16dp
150dp
- 100dp
+ 100dp
8dp
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index 33f524b3a..8238c491b 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -1,7 +1,7 @@
Simple Gallery
Share via
- Not much to do in a gallery without accessing your photos
+ Not much to do in a gallery without accessing your photos and videos
Delete
Deleting
Edit