mirror of
https://github.com/FossifyOrg/Gallery.git
synced 2024-11-26 06:28:00 +01:00
some refactoring, no functionality change
This commit is contained in:
parent
fd9980ba41
commit
9ebdffdda0
15 changed files with 425 additions and 404 deletions
|
@ -5,6 +5,7 @@ import android.util.AttributeSet;
|
||||||
import android.widget.ImageView;
|
import android.widget.ImageView;
|
||||||
|
|
||||||
public class MyImageView extends ImageView {
|
public class MyImageView extends ImageView {
|
||||||
|
|
||||||
public MyImageView(Context context) {
|
public MyImageView(Context context) {
|
||||||
super(context);
|
super(context);
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,14 +21,15 @@ public class AboutActivity extends AppCompatActivity {
|
||||||
@BindView(R.id.about_copyright) TextView copyright;
|
@BindView(R.id.about_copyright) TextView copyright;
|
||||||
@BindView(R.id.about_version) TextView version;
|
@BindView(R.id.about_version) TextView version;
|
||||||
@BindView(R.id.about_email) TextView emailTV;
|
@BindView(R.id.about_email) TextView emailTV;
|
||||||
private Resources res;
|
|
||||||
|
private static Resources mRes;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
setContentView(R.layout.activity_about);
|
setContentView(R.layout.activity_about);
|
||||||
ButterKnife.bind(this);
|
ButterKnife.bind(this);
|
||||||
res = getResources();
|
mRes = getResources();
|
||||||
|
|
||||||
setupEmail();
|
setupEmail();
|
||||||
setupVersion();
|
setupVersion();
|
||||||
|
@ -36,8 +37,8 @@ public class AboutActivity extends AppCompatActivity {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setupEmail() {
|
private void setupEmail() {
|
||||||
final String email = res.getString(R.string.email);
|
final String email = mRes.getString(R.string.email);
|
||||||
final String appName = res.getString(R.string.app_name);
|
final String appName = mRes.getString(R.string.app_name);
|
||||||
final String href = "<a href=\"mailto:" + email + "?subject=" + appName + "\">" + email + "</a>";
|
final String href = "<a href=\"mailto:" + email + "?subject=" + appName + "\">" + email + "</a>";
|
||||||
emailTV.setText(Html.fromHtml(href));
|
emailTV.setText(Html.fromHtml(href));
|
||||||
emailTV.setMovementMethod(LinkMovementMethod.getInstance());
|
emailTV.setMovementMethod(LinkMovementMethod.getInstance());
|
||||||
|
@ -45,13 +46,13 @@ public class AboutActivity extends AppCompatActivity {
|
||||||
|
|
||||||
private void setupVersion() {
|
private void setupVersion() {
|
||||||
final String versionName = BuildConfig.VERSION_NAME;
|
final String versionName = BuildConfig.VERSION_NAME;
|
||||||
final String versionText = String.format(res.getString(R.string.version), versionName);
|
final String versionText = String.format(mRes.getString(R.string.version), versionName);
|
||||||
version.setText(versionText);
|
version.setText(versionText);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setupCopyright() {
|
private void setupCopyright() {
|
||||||
final int year = Calendar.getInstance().get(Calendar.YEAR);
|
final int year = Calendar.getInstance().get(Calendar.YEAR);
|
||||||
final String copyrightText = String.format(res.getString(R.string.copyright), year);
|
final String copyrightText = String.format(mRes.getString(R.string.copyright), year);
|
||||||
copyright.setText(copyrightText);
|
copyright.setText(copyrightText);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -11,6 +11,7 @@ import butterknife.ButterKnife;
|
||||||
import butterknife.OnClick;
|
import butterknife.OnClick;
|
||||||
|
|
||||||
public class LicenseActivity extends AppCompatActivity {
|
public class LicenseActivity extends AppCompatActivity {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
|
|
|
@ -45,33 +45,34 @@ import butterknife.ButterKnife;
|
||||||
|
|
||||||
public class MainActivity extends AppCompatActivity
|
public class MainActivity extends AppCompatActivity
|
||||||
implements AdapterView.OnItemClickListener, GridView.MultiChoiceModeListener, GridView.OnTouchListener {
|
implements AdapterView.OnItemClickListener, GridView.MultiChoiceModeListener, GridView.OnTouchListener {
|
||||||
@BindView(R.id.directories_grid) GridView gridView;
|
@BindView(R.id.directories_grid) GridView mGridView;
|
||||||
|
|
||||||
private static final int STORAGE_PERMISSION = 1;
|
private static final int STORAGE_PERMISSION = 1;
|
||||||
private static final int PICK_MEDIA = 2;
|
private static final int PICK_MEDIA = 2;
|
||||||
private List<Directory> dirs;
|
|
||||||
private int selectedItemsCnt;
|
private static List<Directory> mDirs;
|
||||||
private Snackbar snackbar;
|
private static Snackbar mSnackbar;
|
||||||
private boolean isSnackbarShown;
|
private static List<String> mToBeDeleted;
|
||||||
private List<String> toBeDeleted;
|
private static ActionMode mActionMode;
|
||||||
private ActionMode actionMode;
|
private static Parcelable mState;
|
||||||
private Parcelable state;
|
|
||||||
private boolean isPickImageIntent;
|
private static boolean mIsSnackbarShown;
|
||||||
private boolean isPickVideoIntent;
|
private static boolean mIsPickImageIntent;
|
||||||
|
private static boolean mIsPickVideoIntent;
|
||||||
|
private static int mSelectedItemsCnt;
|
||||||
|
|
||||||
@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);
|
||||||
isPickImageIntent = isPickImageIntent(getIntent());
|
mIsPickImageIntent = isPickImageIntent(getIntent());
|
||||||
isPickVideoIntent = isPickVideoIntent(getIntent());
|
mIsPickVideoIntent = isPickVideoIntent(getIntent());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onCreateOptionsMenu(Menu menu) {
|
public boolean onCreateOptionsMenu(Menu menu) {
|
||||||
MenuInflater inflater = getMenuInflater();
|
getMenuInflater().inflate(R.menu.menu, menu);
|
||||||
inflater.inflate(R.menu.menu, menu);
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -91,16 +92,16 @@ public class MainActivity extends AppCompatActivity
|
||||||
protected void onResume() {
|
protected void onResume() {
|
||||||
super.onResume();
|
super.onResume();
|
||||||
tryloadGallery();
|
tryloadGallery();
|
||||||
if (state != null && gridView != null)
|
if (mState != null && mGridView != null)
|
||||||
gridView.onRestoreInstanceState(state);
|
mGridView.onRestoreInstanceState(mState);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onPause() {
|
protected void onPause() {
|
||||||
super.onPause();
|
super.onPause();
|
||||||
deleteDirs();
|
deleteDirs();
|
||||||
if (gridView != null)
|
if (mGridView != null)
|
||||||
state = gridView.onSaveInstanceState();
|
mState = mGridView.onSaveInstanceState();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void tryloadGallery() {
|
private void tryloadGallery() {
|
||||||
|
@ -126,26 +127,26 @@ public class MainActivity extends AppCompatActivity
|
||||||
}
|
}
|
||||||
|
|
||||||
private void initializeGallery() {
|
private void initializeGallery() {
|
||||||
toBeDeleted = new ArrayList<>();
|
mToBeDeleted = new ArrayList<>();
|
||||||
dirs = getDirectories();
|
mDirs = getDirectories();
|
||||||
final DirectoryAdapter adapter = new DirectoryAdapter(this, dirs);
|
|
||||||
|
|
||||||
gridView.setAdapter(adapter);
|
final DirectoryAdapter adapter = new DirectoryAdapter(this, mDirs);
|
||||||
gridView.setOnItemClickListener(this);
|
mGridView.setAdapter(adapter);
|
||||||
gridView.setMultiChoiceModeListener(this);
|
mGridView.setOnItemClickListener(this);
|
||||||
gridView.setOnTouchListener(this);
|
mGridView.setMultiChoiceModeListener(this);
|
||||||
|
mGridView.setOnTouchListener(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<Directory> getDirectories() {
|
private List<Directory> getDirectories() {
|
||||||
final Map<String, Directory> directories = new LinkedHashMap<>();
|
final Map<String, Directory> directories = new LinkedHashMap<>();
|
||||||
final List<String> invalidFiles = new ArrayList<>();
|
final List<String> invalidFiles = new ArrayList<>();
|
||||||
for (int i = 0; i < 2; i++) {
|
for (int i = 0; i < 2; i++) {
|
||||||
if (isPickVideoIntent && i == 0)
|
if (mIsPickVideoIntent && i == 0)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
Uri uri = MediaStore.Images.Media.EXTERNAL_CONTENT_URI;
|
Uri uri = MediaStore.Images.Media.EXTERNAL_CONTENT_URI;
|
||||||
if (i == 1) {
|
if (i == 1) {
|
||||||
if (isPickImageIntent)
|
if (mIsPickImageIntent)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
uri = MediaStore.Video.Media.EXTERNAL_CONTENT_URI;
|
uri = MediaStore.Video.Media.EXTERNAL_CONTENT_URI;
|
||||||
|
@ -172,7 +173,7 @@ public class MainActivity extends AppCompatActivity
|
||||||
final Directory directory = directories.get(fileDir);
|
final Directory directory = directories.get(fileDir);
|
||||||
final int newImageCnt = directory.getMediaCnt() + 1;
|
final int newImageCnt = directory.getMediaCnt() + 1;
|
||||||
directory.setMediaCnt(newImageCnt);
|
directory.setMediaCnt(newImageCnt);
|
||||||
} else if (!toBeDeleted.contains(fileDir)) {
|
} else if (!mToBeDeleted.contains(fileDir)) {
|
||||||
final String dirName = Utils.getFilename(fileDir);
|
final String dirName = Utils.getFilename(fileDir);
|
||||||
directories.put(fileDir, new Directory(fileDir, path, dirName, 1, timestamp));
|
directories.put(fileDir, new Directory(fileDir, path, dirName, 1, timestamp));
|
||||||
}
|
}
|
||||||
|
@ -192,14 +193,14 @@ public class MainActivity extends AppCompatActivity
|
||||||
|
|
||||||
private void prepareForDeleting() {
|
private void prepareForDeleting() {
|
||||||
Utils.showToast(this, R.string.deleting);
|
Utils.showToast(this, R.string.deleting);
|
||||||
final SparseBooleanArray items = gridView.getCheckedItemPositions();
|
final SparseBooleanArray items = mGridView.getCheckedItemPositions();
|
||||||
int cnt = items.size();
|
final int cnt = items.size();
|
||||||
int deletedCnt = 0;
|
int deletedCnt = 0;
|
||||||
for (int i = 0; i < cnt; i++) {
|
for (int i = 0; i < cnt; i++) {
|
||||||
if (items.valueAt(i)) {
|
if (items.valueAt(i)) {
|
||||||
final int id = items.keyAt(i);
|
final int id = items.keyAt(i);
|
||||||
final String path = dirs.get(id).getPath();
|
final String path = mDirs.get(id).getPath();
|
||||||
toBeDeleted.add(path);
|
mToBeDeleted.add(path);
|
||||||
deletedCnt++;
|
deletedCnt++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -208,31 +209,31 @@ public class MainActivity extends AppCompatActivity
|
||||||
}
|
}
|
||||||
|
|
||||||
private void notifyDeletion(int cnt) {
|
private void notifyDeletion(int cnt) {
|
||||||
dirs = getDirectories();
|
mDirs = getDirectories();
|
||||||
|
|
||||||
final CoordinatorLayout coordinator = (CoordinatorLayout) findViewById(R.id.coordinator_layout);
|
final CoordinatorLayout coordinator = (CoordinatorLayout) findViewById(R.id.coordinator_layout);
|
||||||
final Resources res = getResources();
|
final Resources res = getResources();
|
||||||
final String msg = res.getQuantityString(R.plurals.folders_deleted, cnt, cnt);
|
final String msg = res.getQuantityString(R.plurals.folders_deleted, cnt, cnt);
|
||||||
snackbar = Snackbar.make(coordinator, msg, Snackbar.LENGTH_INDEFINITE);
|
mSnackbar = Snackbar.make(coordinator, msg, Snackbar.LENGTH_INDEFINITE);
|
||||||
snackbar.setAction(res.getString(R.string.undo), undoDeletion);
|
mSnackbar.setAction(res.getString(R.string.undo), undoDeletion);
|
||||||
snackbar.setActionTextColor(Color.WHITE);
|
mSnackbar.setActionTextColor(Color.WHITE);
|
||||||
snackbar.show();
|
mSnackbar.show();
|
||||||
isSnackbarShown = true;
|
mIsSnackbarShown = true;
|
||||||
updateGridView();
|
updateGridView();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void deleteDirs() {
|
private void deleteDirs() {
|
||||||
if (toBeDeleted == null || toBeDeleted.isEmpty())
|
if (mToBeDeleted == null || mToBeDeleted.isEmpty())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (snackbar != null) {
|
if (mSnackbar != null) {
|
||||||
snackbar.dismiss();
|
mSnackbar.dismiss();
|
||||||
}
|
}
|
||||||
|
|
||||||
isSnackbarShown = false;
|
mIsSnackbarShown = false;
|
||||||
|
|
||||||
final List<String> updatedFiles = new ArrayList<>();
|
final List<String> updatedFiles = new ArrayList<>();
|
||||||
for (String delPath : toBeDeleted) {
|
for (String delPath : mToBeDeleted) {
|
||||||
final File dir = new File(delPath);
|
final File dir = new File(delPath);
|
||||||
if (dir.exists()) {
|
if (dir.exists()) {
|
||||||
final File[] files = dir.listFiles();
|
final File[] files = dir.listFiles();
|
||||||
|
@ -247,32 +248,32 @@ public class MainActivity extends AppCompatActivity
|
||||||
|
|
||||||
final String[] deletedPaths = updatedFiles.toArray(new String[updatedFiles.size()]);
|
final String[] deletedPaths = updatedFiles.toArray(new String[updatedFiles.size()]);
|
||||||
MediaScannerConnection.scanFile(this, deletedPaths, null, null);
|
MediaScannerConnection.scanFile(this, deletedPaths, null, null);
|
||||||
toBeDeleted.clear();
|
mToBeDeleted.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
private View.OnClickListener undoDeletion = new View.OnClickListener() {
|
private View.OnClickListener undoDeletion = new View.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
snackbar.dismiss();
|
mSnackbar.dismiss();
|
||||||
isSnackbarShown = false;
|
mIsSnackbarShown = false;
|
||||||
toBeDeleted.clear();
|
mToBeDeleted.clear();
|
||||||
dirs = getDirectories();
|
mDirs = getDirectories();
|
||||||
updateGridView();
|
updateGridView();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
private void updateGridView() {
|
private void updateGridView() {
|
||||||
final DirectoryAdapter adapter = (DirectoryAdapter) gridView.getAdapter();
|
final DirectoryAdapter adapter = (DirectoryAdapter) mGridView.getAdapter();
|
||||||
adapter.updateItems(dirs);
|
adapter.updateItems(mDirs);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void editDirectory() {
|
private void editDirectory() {
|
||||||
final SparseBooleanArray items = gridView.getCheckedItemPositions();
|
final SparseBooleanArray items = mGridView.getCheckedItemPositions();
|
||||||
final int cnt = items.size();
|
final int cnt = items.size();
|
||||||
for (int i = 0; i < cnt; i++) {
|
for (int i = 0; i < cnt; i++) {
|
||||||
if (items.valueAt(i)) {
|
if (items.valueAt(i)) {
|
||||||
final int id = items.keyAt(i);
|
final int id = items.keyAt(i);
|
||||||
final String path = dirs.get(id).getPath();
|
final String path = mDirs.get(id).getPath();
|
||||||
renameDir(path);
|
renameDir(path);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -312,7 +313,7 @@ public class MainActivity extends AppCompatActivity
|
||||||
if (dir.renameTo(newDir)) {
|
if (dir.renameTo(newDir)) {
|
||||||
Utils.showToast(getApplicationContext(), R.string.renaming_folder);
|
Utils.showToast(getApplicationContext(), R.string.renaming_folder);
|
||||||
alertDialog.dismiss();
|
alertDialog.dismiss();
|
||||||
actionMode.finish();
|
mActionMode.finish();
|
||||||
|
|
||||||
final File[] files = newDir.listFiles();
|
final File[] files = newDir.listFiles();
|
||||||
for (File f : files) {
|
for (File f : files) {
|
||||||
|
@ -361,22 +362,22 @@ public class MainActivity 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) {
|
||||||
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, mDirs.get(position).getPath());
|
||||||
intent.putExtra(Constants.PICK_IMAGE_INTENT, isPickImageIntent);
|
intent.putExtra(Constants.PICK_IMAGE_INTENT, mIsPickImageIntent);
|
||||||
intent.putExtra(Constants.PICK_VIDEO_INTENT, isPickVideoIntent);
|
intent.putExtra(Constants.PICK_VIDEO_INTENT, mIsPickVideoIntent);
|
||||||
startActivityForResult(intent, PICK_MEDIA);
|
startActivityForResult(intent, PICK_MEDIA);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onItemCheckedStateChanged(ActionMode mode, int position, long id, boolean checked) {
|
public void onItemCheckedStateChanged(ActionMode mode, int position, long id, boolean checked) {
|
||||||
if (checked) {
|
if (checked) {
|
||||||
selectedItemsCnt++;
|
mSelectedItemsCnt++;
|
||||||
} else {
|
} else {
|
||||||
selectedItemsCnt--;
|
mSelectedItemsCnt--;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (selectedItemsCnt > 0) {
|
if (mSelectedItemsCnt > 0) {
|
||||||
mode.setTitle(String.valueOf(selectedItemsCnt));
|
mode.setTitle(String.valueOf(mSelectedItemsCnt));
|
||||||
}
|
}
|
||||||
|
|
||||||
mode.invalidate();
|
mode.invalidate();
|
||||||
|
@ -386,14 +387,14 @@ public class MainActivity extends AppCompatActivity
|
||||||
public boolean onCreateActionMode(ActionMode mode, Menu menu) {
|
public boolean onCreateActionMode(ActionMode mode, Menu menu) {
|
||||||
final MenuInflater inflater = mode.getMenuInflater();
|
final MenuInflater inflater = mode.getMenuInflater();
|
||||||
inflater.inflate(R.menu.directories_menu, menu);
|
inflater.inflate(R.menu.directories_menu, menu);
|
||||||
actionMode = mode;
|
mActionMode = mode;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onPrepareActionMode(ActionMode mode, Menu menu) {
|
public boolean onPrepareActionMode(ActionMode mode, Menu menu) {
|
||||||
final MenuItem menuItem = menu.findItem(R.id.cab_edit);
|
final MenuItem menuItem = menu.findItem(R.id.cab_edit);
|
||||||
menuItem.setVisible(selectedItemsCnt == 1);
|
menuItem.setVisible(mSelectedItemsCnt == 1);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -414,12 +415,12 @@ public class MainActivity extends AppCompatActivity
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onDestroyActionMode(ActionMode mode) {
|
public void onDestroyActionMode(ActionMode mode) {
|
||||||
selectedItemsCnt = 0;
|
mSelectedItemsCnt = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onTouch(View v, MotionEvent event) {
|
public boolean onTouch(View v, MotionEvent event) {
|
||||||
if (isSnackbarShown) {
|
if (mIsSnackbarShown) {
|
||||||
deleteDirs();
|
deleteDirs();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -429,13 +430,13 @@ public class MainActivity extends AppCompatActivity
|
||||||
private void scanCompleted(final String path) {
|
private void scanCompleted(final String path) {
|
||||||
final File dir = new File(path);
|
final File dir = new File(path);
|
||||||
if (dir.isDirectory()) {
|
if (dir.isDirectory()) {
|
||||||
dirs = getDirectories();
|
mDirs = getDirectories();
|
||||||
|
|
||||||
runOnUiThread(new Runnable() {
|
runOnUiThread(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
updateGridView();
|
updateGridView();
|
||||||
gridView.requestLayout();
|
mGridView.requestLayout();
|
||||||
Utils.showToast(getApplicationContext(), R.string.rename_folder_ok);
|
Utils.showToast(getApplicationContext(), R.string.rename_folder_ok);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -39,41 +39,42 @@ import butterknife.ButterKnife;
|
||||||
|
|
||||||
public class MediaActivity extends AppCompatActivity
|
public class MediaActivity extends AppCompatActivity
|
||||||
implements AdapterView.OnItemClickListener, GridView.MultiChoiceModeListener, GridView.OnTouchListener {
|
implements AdapterView.OnItemClickListener, GridView.MultiChoiceModeListener, GridView.OnTouchListener {
|
||||||
@BindView(R.id.media_grid) GridView gridView;
|
@BindView(R.id.media_grid) GridView mGridView;
|
||||||
|
|
||||||
private List<Medium> media;
|
private static List<Medium> mMedia;
|
||||||
private int selectedItemsCnt;
|
private static String mPath;
|
||||||
private String path;
|
private static Snackbar mSnackbar;
|
||||||
private Snackbar snackbar;
|
private static List<String> mToBeDeleted;
|
||||||
private boolean isSnackbarShown;
|
private static Parcelable mState;
|
||||||
private List<String> toBeDeleted;
|
|
||||||
private Parcelable state;
|
private static boolean mIsSnackbarShown;
|
||||||
private boolean isPickImageIntent;
|
private static boolean mIsPickImageIntent;
|
||||||
private boolean isPickVideoIntent;
|
private static boolean mIsPickVideoIntent;
|
||||||
|
private static int mSelectedItemsCnt;
|
||||||
|
|
||||||
@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);
|
||||||
isPickImageIntent = getIntent().getBooleanExtra(Constants.PICK_IMAGE_INTENT, false);
|
mIsPickImageIntent = getIntent().getBooleanExtra(Constants.PICK_IMAGE_INTENT, false);
|
||||||
isPickVideoIntent = getIntent().getBooleanExtra(Constants.PICK_VIDEO_INTENT, false);
|
mIsPickVideoIntent = getIntent().getBooleanExtra(Constants.PICK_VIDEO_INTENT, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onResume() {
|
protected void onResume() {
|
||||||
super.onResume();
|
super.onResume();
|
||||||
tryloadGallery();
|
tryloadGallery();
|
||||||
if (state != null && gridView != null)
|
if (mState != null && mGridView != null)
|
||||||
gridView.onRestoreInstanceState(state);
|
mGridView.onRestoreInstanceState(mState);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onPause() {
|
protected void onPause() {
|
||||||
super.onPause();
|
super.onPause();
|
||||||
deleteFiles();
|
deleteFiles();
|
||||||
if (gridView != null)
|
if (mGridView != null)
|
||||||
state = gridView.onSaveInstanceState();
|
mState = mGridView.onSaveInstanceState();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void tryloadGallery() {
|
private void tryloadGallery() {
|
||||||
|
@ -85,60 +86,60 @@ public class MediaActivity extends AppCompatActivity
|
||||||
}
|
}
|
||||||
|
|
||||||
private void initializeGallery() {
|
private void initializeGallery() {
|
||||||
toBeDeleted = new ArrayList<>();
|
mToBeDeleted = new ArrayList<>();
|
||||||
path = getIntent().getStringExtra(Constants.DIRECTORY);
|
mPath = getIntent().getStringExtra(Constants.DIRECTORY);
|
||||||
media = getMedia();
|
mMedia = getMedia();
|
||||||
if (isDirEmpty())
|
if (isDirEmpty())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
final MediaAdapter adapter = new MediaAdapter(this, media);
|
final MediaAdapter adapter = new MediaAdapter(this, mMedia);
|
||||||
gridView.setAdapter(adapter);
|
mGridView.setAdapter(adapter);
|
||||||
gridView.setOnItemClickListener(this);
|
mGridView.setOnItemClickListener(this);
|
||||||
gridView.setMultiChoiceModeListener(this);
|
mGridView.setMultiChoiceModeListener(this);
|
||||||
gridView.setOnTouchListener(this);
|
mGridView.setOnTouchListener(this);
|
||||||
isSnackbarShown = false;
|
mIsSnackbarShown = false;
|
||||||
|
|
||||||
final String dirName = Utils.getFilename(path);
|
final String dirName = Utils.getFilename(mPath);
|
||||||
setTitle(dirName);
|
setTitle(dirName);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void deleteDirectoryIfEmpty() {
|
private void deleteDirectoryIfEmpty() {
|
||||||
final File file = new File(path);
|
final File file = new File(mPath);
|
||||||
if (file.isDirectory() && file.listFiles().length == 0) {
|
if (file.isDirectory() && file.listFiles().length == 0) {
|
||||||
file.delete();
|
file.delete();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<Medium> getMedia() {
|
private List<Medium> getMedia() {
|
||||||
final List<Medium> myMedia = new ArrayList<>();
|
final List<Medium> media = new ArrayList<>();
|
||||||
final List<String> invalidFiles = new ArrayList<>();
|
final List<String> invalidFiles = new ArrayList<>();
|
||||||
for (int i = 0; i < 2; i++) {
|
for (int i = 0; i < 2; i++) {
|
||||||
if (isPickVideoIntent && i == 0)
|
if (mIsPickVideoIntent && i == 0)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
Uri uri = MediaStore.Images.Media.EXTERNAL_CONTENT_URI;
|
Uri uri = MediaStore.Images.Media.EXTERNAL_CONTENT_URI;
|
||||||
if (i == 1) {
|
if (i == 1) {
|
||||||
if (isPickImageIntent)
|
if (mIsPickImageIntent)
|
||||||
continue;
|
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 ? ";
|
||||||
final String[] args = new String[]{path + "%"};
|
final String[] args = new String[]{mPath + "%"};
|
||||||
final String[] columns = {MediaStore.Images.Media.DATA, MediaStore.Images.Media.DATE_TAKEN};
|
final String[] columns = {MediaStore.Images.Media.DATA, MediaStore.Images.Media.DATE_TAKEN};
|
||||||
final Cursor cursor = getContentResolver().query(uri, columns, where, args, null);
|
final Cursor cursor = getContentResolver().query(uri, columns, where, args, null);
|
||||||
final String pattern = Pattern.quote(path) + "/[^/]*";
|
final String pattern = Pattern.quote(mPath) + "/[^/]*";
|
||||||
|
|
||||||
if (cursor != null && cursor.moveToFirst()) {
|
if (cursor != null && cursor.moveToFirst()) {
|
||||||
final int pathIndex = cursor.getColumnIndex(MediaStore.Images.Media.DATA);
|
final int pathIndex = cursor.getColumnIndex(MediaStore.Images.Media.DATA);
|
||||||
do {
|
do {
|
||||||
final String curPath = cursor.getString(pathIndex);
|
final String curPath = cursor.getString(pathIndex);
|
||||||
if (curPath.matches(pattern) && !toBeDeleted.contains(curPath)) {
|
if (curPath.matches(pattern) && !mToBeDeleted.contains(curPath)) {
|
||||||
final File file = new File(curPath);
|
final File file = new File(curPath);
|
||||||
if (file.exists()) {
|
if (file.exists()) {
|
||||||
final int dateIndex = cursor.getColumnIndex(MediaStore.Images.Media.DATE_TAKEN);
|
final int dateIndex = cursor.getColumnIndex(MediaStore.Images.Media.DATE_TAKEN);
|
||||||
final long timestamp = cursor.getLong(dateIndex);
|
final long timestamp = cursor.getLong(dateIndex);
|
||||||
myMedia.add(new Medium(curPath, (i == 1), timestamp));
|
media.add(new Medium(curPath, (i == 1), timestamp));
|
||||||
} else {
|
} else {
|
||||||
invalidFiles.add(file.getAbsolutePath());
|
invalidFiles.add(file.getAbsolutePath());
|
||||||
}
|
}
|
||||||
|
@ -148,16 +149,16 @@ public class MediaActivity extends AppCompatActivity
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Collections.sort(myMedia);
|
Collections.sort(media);
|
||||||
|
|
||||||
final String[] invalids = invalidFiles.toArray(new String[invalidFiles.size()]);
|
final String[] invalids = invalidFiles.toArray(new String[invalidFiles.size()]);
|
||||||
MediaScannerConnection.scanFile(getApplicationContext(), invalids, null, null);
|
MediaScannerConnection.scanFile(getApplicationContext(), invalids, null, null);
|
||||||
|
|
||||||
return myMedia;
|
return media;
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean isDirEmpty() {
|
private boolean isDirEmpty() {
|
||||||
if (media.size() <= 0) {
|
if (mMedia.size() <= 0) {
|
||||||
deleteDirectoryIfEmpty();
|
deleteDirectoryIfEmpty();
|
||||||
finish();
|
finish();
|
||||||
return true;
|
return true;
|
||||||
|
@ -167,14 +168,14 @@ public class MediaActivity extends AppCompatActivity
|
||||||
|
|
||||||
private void prepareForDeleting() {
|
private void prepareForDeleting() {
|
||||||
Utils.showToast(this, R.string.deleting);
|
Utils.showToast(this, R.string.deleting);
|
||||||
final SparseBooleanArray items = gridView.getCheckedItemPositions();
|
final SparseBooleanArray items = mGridView.getCheckedItemPositions();
|
||||||
int cnt = items.size();
|
final int cnt = items.size();
|
||||||
int deletedCnt = 0;
|
int deletedCnt = 0;
|
||||||
for (int i = 0; i < cnt; i++) {
|
for (int i = 0; i < cnt; i++) {
|
||||||
if (items.valueAt(i)) {
|
if (items.valueAt(i)) {
|
||||||
final int id = items.keyAt(i);
|
final int id = items.keyAt(i);
|
||||||
final String path = media.get(id).getPath();
|
final String path = mMedia.get(id).getPath();
|
||||||
toBeDeleted.add(path);
|
mToBeDeleted.add(path);
|
||||||
deletedCnt++;
|
deletedCnt++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -183,79 +184,79 @@ public class MediaActivity extends AppCompatActivity
|
||||||
}
|
}
|
||||||
|
|
||||||
private void notifyDeletion(int cnt) {
|
private void notifyDeletion(int cnt) {
|
||||||
media = getMedia();
|
mMedia = getMedia();
|
||||||
|
|
||||||
if (media.isEmpty()) {
|
if (mMedia.isEmpty()) {
|
||||||
deleteFiles();
|
deleteFiles();
|
||||||
} else {
|
} else {
|
||||||
final CoordinatorLayout coordinator = (CoordinatorLayout) findViewById(R.id.coordinator_layout);
|
final CoordinatorLayout coordinator = (CoordinatorLayout) findViewById(R.id.coordinator_layout);
|
||||||
final Resources res = getResources();
|
final Resources res = getResources();
|
||||||
final String msg = res.getQuantityString(R.plurals.files_deleted, cnt, cnt);
|
final String msg = res.getQuantityString(R.plurals.files_deleted, cnt, cnt);
|
||||||
snackbar = Snackbar.make(coordinator, msg, Snackbar.LENGTH_INDEFINITE);
|
mSnackbar = Snackbar.make(coordinator, msg, Snackbar.LENGTH_INDEFINITE);
|
||||||
snackbar.setAction(res.getString(R.string.undo), undoDeletion);
|
mSnackbar.setAction(res.getString(R.string.undo), undoDeletion);
|
||||||
snackbar.setActionTextColor(Color.WHITE);
|
mSnackbar.setActionTextColor(Color.WHITE);
|
||||||
snackbar.show();
|
mSnackbar.show();
|
||||||
isSnackbarShown = true;
|
mIsSnackbarShown = true;
|
||||||
updateGridView();
|
updateGridView();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void deleteFiles() {
|
private void deleteFiles() {
|
||||||
if (toBeDeleted == null || toBeDeleted.isEmpty())
|
if (mToBeDeleted == null || mToBeDeleted.isEmpty())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (snackbar != null) {
|
if (mSnackbar != null) {
|
||||||
snackbar.dismiss();
|
mSnackbar.dismiss();
|
||||||
}
|
}
|
||||||
|
|
||||||
isSnackbarShown = false;
|
mIsSnackbarShown = false;
|
||||||
|
|
||||||
for (String delPath : toBeDeleted) {
|
for (String delPath : mToBeDeleted) {
|
||||||
final File file = new File(delPath);
|
final File file = new File(delPath);
|
||||||
if (file.exists())
|
if (file.exists())
|
||||||
file.delete();
|
file.delete();
|
||||||
}
|
}
|
||||||
|
|
||||||
final String[] deletedPaths = toBeDeleted.toArray(new String[toBeDeleted.size()]);
|
final String[] deletedPaths = mToBeDeleted.toArray(new String[mToBeDeleted.size()]);
|
||||||
MediaScannerConnection.scanFile(this, deletedPaths, null, new MediaScannerConnection.OnScanCompletedListener() {
|
MediaScannerConnection.scanFile(this, deletedPaths, null, new MediaScannerConnection.OnScanCompletedListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onScanCompleted(String path, Uri uri) {
|
public void onScanCompleted(String path, Uri uri) {
|
||||||
if (media != null && media.isEmpty()) {
|
if (mMedia != null && mMedia.isEmpty()) {
|
||||||
finish();
|
finish();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
toBeDeleted.clear();
|
mToBeDeleted.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
private View.OnClickListener undoDeletion = new View.OnClickListener() {
|
private View.OnClickListener undoDeletion = new View.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
snackbar.dismiss();
|
mSnackbar.dismiss();
|
||||||
isSnackbarShown = false;
|
mIsSnackbarShown = false;
|
||||||
toBeDeleted.clear();
|
mToBeDeleted.clear();
|
||||||
media = getMedia();
|
mMedia = getMedia();
|
||||||
updateGridView();
|
updateGridView();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
private void updateGridView() {
|
private void updateGridView() {
|
||||||
if (!isDirEmpty()) {
|
if (!isDirEmpty()) {
|
||||||
final MediaAdapter adapter = (MediaAdapter) gridView.getAdapter();
|
final MediaAdapter adapter = (MediaAdapter) mGridView.getAdapter();
|
||||||
adapter.updateItems(media);
|
adapter.updateItems(mMedia);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@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 (isPickImageIntent || isPickVideoIntent) {
|
if (mIsPickImageIntent || mIsPickVideoIntent) {
|
||||||
final Intent result = new Intent();
|
final Intent result = new Intent();
|
||||||
result.setData(Uri.parse(media.get(position).getPath()));
|
result.setData(Uri.parse(mMedia.get(position).getPath()));
|
||||||
setResult(RESULT_OK, result);
|
setResult(RESULT_OK, result);
|
||||||
finish();
|
finish();
|
||||||
} else {
|
} else {
|
||||||
final Intent intent = new Intent(this, ViewPagerActivity.class);
|
final Intent intent = new Intent(this, ViewPagerActivity.class);
|
||||||
intent.putExtra(Constants.MEDIUM, media.get(position).getPath());
|
intent.putExtra(Constants.MEDIUM, mMedia.get(position).getPath());
|
||||||
startActivity(intent);
|
startActivity(intent);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -263,13 +264,13 @@ public class MediaActivity extends AppCompatActivity
|
||||||
@Override
|
@Override
|
||||||
public void onItemCheckedStateChanged(ActionMode mode, int position, long id, boolean checked) {
|
public void onItemCheckedStateChanged(ActionMode mode, int position, long id, boolean checked) {
|
||||||
if (checked) {
|
if (checked) {
|
||||||
selectedItemsCnt++;
|
mSelectedItemsCnt++;
|
||||||
} else {
|
} else {
|
||||||
selectedItemsCnt--;
|
mSelectedItemsCnt--;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (selectedItemsCnt > 0)
|
if (mSelectedItemsCnt > 0)
|
||||||
mode.setTitle(String.valueOf(selectedItemsCnt));
|
mode.setTitle(String.valueOf(mSelectedItemsCnt));
|
||||||
|
|
||||||
mode.invalidate();
|
mode.invalidate();
|
||||||
}
|
}
|
||||||
|
@ -300,12 +301,12 @@ public class MediaActivity extends AppCompatActivity
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onDestroyActionMode(ActionMode mode) {
|
public void onDestroyActionMode(ActionMode mode) {
|
||||||
selectedItemsCnt = 0;
|
mSelectedItemsCnt = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onTouch(View v, MotionEvent event) {
|
public boolean onTouch(View v, MotionEvent event) {
|
||||||
if (isSnackbarShown) {
|
if (mIsSnackbarShown) {
|
||||||
deleteFiles();
|
deleteFiles();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -16,32 +16,33 @@ import com.simplemobiletools.gallery.fragments.ViewPagerFragment;
|
||||||
import com.simplemobiletools.gallery.models.Medium;
|
import com.simplemobiletools.gallery.models.Medium;
|
||||||
|
|
||||||
public class PhotoActivity extends AppCompatActivity implements ViewPagerFragment.FragmentClickListener {
|
public class PhotoActivity extends AppCompatActivity implements ViewPagerFragment.FragmentClickListener {
|
||||||
private ActionBar actionbar;
|
private static ActionBar mActionbar;
|
||||||
private boolean isFullScreen;
|
private static Uri mUri;
|
||||||
private Uri uri;
|
|
||||||
|
private static boolean mIsFullScreen;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreate(Bundle savedInstanceState) {
|
public void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
setContentView(R.layout.fragment_holder);
|
setContentView(R.layout.fragment_holder);
|
||||||
|
|
||||||
uri = getIntent().getData();
|
mUri = getIntent().getData();
|
||||||
if (uri == null)
|
if (mUri == null)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
actionbar = getSupportActionBar();
|
mActionbar = getSupportActionBar();
|
||||||
isFullScreen = true;
|
mIsFullScreen = true;
|
||||||
hideSystemUI();
|
hideSystemUI();
|
||||||
|
|
||||||
final Bundle bundle = new Bundle();
|
final Bundle bundle = new Bundle();
|
||||||
final Medium medium = new Medium(uri.toString(), false, 0);
|
final Medium medium = new Medium(mUri.toString(), false, 0);
|
||||||
bundle.putSerializable(Constants.MEDIUM, medium);
|
bundle.putSerializable(Constants.MEDIUM, medium);
|
||||||
final ViewPagerFragment fragment = new PhotoFragment();
|
final ViewPagerFragment fragment = new PhotoFragment();
|
||||||
fragment.setListener(this);
|
fragment.setListener(this);
|
||||||
fragment.setArguments(bundle);
|
fragment.setArguments(bundle);
|
||||||
getSupportFragmentManager().beginTransaction().replace(R.id.fragment_holder, fragment).commit();
|
getSupportFragmentManager().beginTransaction().replace(R.id.fragment_holder, fragment).commit();
|
||||||
hideSystemUI();
|
hideSystemUI();
|
||||||
setTitle(Utils.getFilename(uri.toString()));
|
setTitle(Utils.getFilename(mUri.toString()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -65,15 +66,15 @@ public class PhotoActivity extends AppCompatActivity implements ViewPagerFragmen
|
||||||
final String shareTitle = getResources().getString(R.string.share_via);
|
final String shareTitle = getResources().getString(R.string.share_via);
|
||||||
final Intent sendIntent = new Intent();
|
final Intent sendIntent = new Intent();
|
||||||
sendIntent.setAction(Intent.ACTION_SEND);
|
sendIntent.setAction(Intent.ACTION_SEND);
|
||||||
sendIntent.putExtra(Intent.EXTRA_STREAM, uri);
|
sendIntent.putExtra(Intent.EXTRA_STREAM, mUri);
|
||||||
sendIntent.setType("image/*");
|
sendIntent.setType("image/*");
|
||||||
startActivity(Intent.createChooser(sendIntent, shareTitle));
|
startActivity(Intent.createChooser(sendIntent, shareTitle));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void fragmentClicked() {
|
public void fragmentClicked() {
|
||||||
isFullScreen = !isFullScreen;
|
mIsFullScreen = !mIsFullScreen;
|
||||||
if (isFullScreen) {
|
if (mIsFullScreen) {
|
||||||
hideSystemUI();
|
hideSystemUI();
|
||||||
} else {
|
} else {
|
||||||
showSystemUI();
|
showSystemUI();
|
||||||
|
@ -81,10 +82,10 @@ public class PhotoActivity extends AppCompatActivity implements ViewPagerFragmen
|
||||||
}
|
}
|
||||||
|
|
||||||
private void hideSystemUI() {
|
private void hideSystemUI() {
|
||||||
Utils.hideSystemUI(actionbar, getWindow());
|
Utils.hideSystemUI(mActionbar, getWindow());
|
||||||
}
|
}
|
||||||
|
|
||||||
private void showSystemUI() {
|
private void showSystemUI() {
|
||||||
Utils.showSystemUI(actionbar, getWindow());
|
Utils.showSystemUI(mActionbar, getWindow());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,32 +16,33 @@ import com.simplemobiletools.gallery.fragments.ViewPagerFragment;
|
||||||
import com.simplemobiletools.gallery.models.Medium;
|
import com.simplemobiletools.gallery.models.Medium;
|
||||||
|
|
||||||
public class VideoActivity extends AppCompatActivity implements ViewPagerFragment.FragmentClickListener {
|
public class VideoActivity extends AppCompatActivity implements ViewPagerFragment.FragmentClickListener {
|
||||||
private ActionBar actionbar;
|
private static ActionBar mActionbar;
|
||||||
private boolean isFullScreen;
|
private static Uri mUri;
|
||||||
private Uri uri;
|
|
||||||
|
private static boolean mIsFullScreen;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreate(Bundle savedInstanceState) {
|
public void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
setContentView(R.layout.fragment_holder);
|
setContentView(R.layout.fragment_holder);
|
||||||
|
|
||||||
uri = getIntent().getData();
|
mUri = getIntent().getData();
|
||||||
if (uri == null)
|
if (mUri == null)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
actionbar = getSupportActionBar();
|
mActionbar = getSupportActionBar();
|
||||||
isFullScreen = true;
|
mIsFullScreen = true;
|
||||||
hideSystemUI();
|
hideSystemUI();
|
||||||
|
|
||||||
final Bundle bundle = new Bundle();
|
final Bundle bundle = new Bundle();
|
||||||
final Medium medium = new Medium(uri.toString(), true, 0);
|
final Medium medium = new Medium(mUri.toString(), true, 0);
|
||||||
bundle.putSerializable(Constants.MEDIUM, medium);
|
bundle.putSerializable(Constants.MEDIUM, medium);
|
||||||
final ViewPagerFragment fragment = new VideoFragment();
|
final ViewPagerFragment fragment = new VideoFragment();
|
||||||
fragment.setListener(this);
|
fragment.setListener(this);
|
||||||
fragment.setArguments(bundle);
|
fragment.setArguments(bundle);
|
||||||
getSupportFragmentManager().beginTransaction().replace(R.id.fragment_holder, fragment).commit();
|
getSupportFragmentManager().beginTransaction().replace(R.id.fragment_holder, fragment).commit();
|
||||||
hideSystemUI();
|
hideSystemUI();
|
||||||
setTitle(Utils.getFilename(uri.toString()));
|
setTitle(Utils.getFilename(mUri.toString()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -65,15 +66,15 @@ public class VideoActivity extends AppCompatActivity implements ViewPagerFragmen
|
||||||
final String shareTitle = getResources().getString(R.string.share_via);
|
final String shareTitle = getResources().getString(R.string.share_via);
|
||||||
final Intent sendIntent = new Intent();
|
final Intent sendIntent = new Intent();
|
||||||
sendIntent.setAction(Intent.ACTION_SEND);
|
sendIntent.setAction(Intent.ACTION_SEND);
|
||||||
sendIntent.putExtra(Intent.EXTRA_STREAM, uri);
|
sendIntent.putExtra(Intent.EXTRA_STREAM, mUri);
|
||||||
sendIntent.setType("video/*");
|
sendIntent.setType("video/*");
|
||||||
startActivity(Intent.createChooser(sendIntent, shareTitle));
|
startActivity(Intent.createChooser(sendIntent, shareTitle));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void fragmentClicked() {
|
public void fragmentClicked() {
|
||||||
isFullScreen = !isFullScreen;
|
mIsFullScreen = !mIsFullScreen;
|
||||||
if (isFullScreen) {
|
if (mIsFullScreen) {
|
||||||
hideSystemUI();
|
hideSystemUI();
|
||||||
} else {
|
} else {
|
||||||
showSystemUI();
|
showSystemUI();
|
||||||
|
@ -81,10 +82,10 @@ public class VideoActivity extends AppCompatActivity implements ViewPagerFragmen
|
||||||
}
|
}
|
||||||
|
|
||||||
private void hideSystemUI() {
|
private void hideSystemUI() {
|
||||||
Utils.hideSystemUI(actionbar, getWindow());
|
Utils.hideSystemUI(mActionbar, getWindow());
|
||||||
}
|
}
|
||||||
|
|
||||||
private void showSystemUI() {
|
private void showSystemUI() {
|
||||||
Utils.showSystemUI(actionbar, getWindow());
|
Utils.showSystemUI(mActionbar, getWindow());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -40,18 +40,19 @@ import butterknife.OnClick;
|
||||||
public class ViewPagerActivity extends AppCompatActivity
|
public class ViewPagerActivity extends AppCompatActivity
|
||||||
implements ViewPager.OnPageChangeListener, View.OnSystemUiVisibilityChangeListener, ViewPager.OnTouchListener,
|
implements ViewPager.OnPageChangeListener, View.OnSystemUiVisibilityChangeListener, ViewPager.OnTouchListener,
|
||||||
ViewPagerFragment.FragmentClickListener {
|
ViewPagerFragment.FragmentClickListener {
|
||||||
@BindView(R.id.undo_delete) View undoBtn;
|
@BindView(R.id.undo_delete) View mUndoBtn;
|
||||||
@BindView(R.id.view_pager) MyViewPager pager;
|
@BindView(R.id.view_pager) MyViewPager mPager;
|
||||||
|
|
||||||
private int pos;
|
private static ActionBar mActionbar;
|
||||||
private boolean isFullScreen;
|
private static List<Medium> mMedia;
|
||||||
private boolean isUndoShown;
|
private static String mPath;
|
||||||
private ActionBar actionbar;
|
private static String mDirectory;
|
||||||
private List<Medium> media;
|
private static String mToBeDeleted;
|
||||||
private String path;
|
private static String mBeingDeleted;
|
||||||
private String directory;
|
|
||||||
private String toBeDeleted;
|
private static boolean mIsFullScreen;
|
||||||
private String beingDeleted;
|
private static boolean mIsUndoShown;
|
||||||
|
private static int mPos;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
|
@ -64,26 +65,26 @@ public class ViewPagerActivity extends AppCompatActivity
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
pos = 0;
|
mPos = 0;
|
||||||
isFullScreen = true;
|
mIsFullScreen = true;
|
||||||
actionbar = getSupportActionBar();
|
mActionbar = getSupportActionBar();
|
||||||
toBeDeleted = "";
|
mToBeDeleted = "";
|
||||||
beingDeleted = "";
|
mBeingDeleted = "";
|
||||||
hideSystemUI();
|
hideSystemUI();
|
||||||
|
|
||||||
path = getIntent().getStringExtra(Constants.MEDIUM);
|
mPath = getIntent().getStringExtra(Constants.MEDIUM);
|
||||||
MediaScannerConnection.scanFile(this, new String[]{path}, null, null);
|
MediaScannerConnection.scanFile(this, new String[]{mPath}, null, null);
|
||||||
addUndoMargin();
|
addUndoMargin();
|
||||||
directory = new File(path).getParent();
|
mDirectory = new File(mPath).getParent();
|
||||||
media = getMedia();
|
mMedia = getMedia();
|
||||||
if (isDirEmpty())
|
if (isDirEmpty())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
final MyPagerAdapter adapter = new MyPagerAdapter(this, getSupportFragmentManager(), media);
|
final MyPagerAdapter adapter = new MyPagerAdapter(this, getSupportFragmentManager(), mMedia);
|
||||||
pager.setAdapter(adapter);
|
mPager.setAdapter(adapter);
|
||||||
pager.setCurrentItem(pos);
|
mPager.setCurrentItem(mPos);
|
||||||
pager.addOnPageChangeListener(this);
|
mPager.addOnPageChangeListener(this);
|
||||||
pager.setOnTouchListener(this);
|
mPager.setOnTouchListener(this);
|
||||||
|
|
||||||
getWindow().getDecorView().setOnSystemUiVisibilityChangeListener(this);
|
getWindow().getDecorView().setOnSystemUiVisibilityChangeListener(this);
|
||||||
updateActionbarTitle();
|
updateActionbarTitle();
|
||||||
|
@ -99,10 +100,10 @@ public class ViewPagerActivity extends AppCompatActivity
|
||||||
|
|
||||||
@OnClick(R.id.undo_delete)
|
@OnClick(R.id.undo_delete)
|
||||||
public void undoDeletion() {
|
public void undoDeletion() {
|
||||||
isUndoShown = false;
|
mIsUndoShown = false;
|
||||||
toBeDeleted = "";
|
mToBeDeleted = "";
|
||||||
beingDeleted = "";
|
mBeingDeleted = "";
|
||||||
undoBtn.setVisibility(View.GONE);
|
mUndoBtn.setVisibility(View.GONE);
|
||||||
reloadViewPager();
|
reloadViewPager();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -138,37 +139,38 @@ public class ViewPagerActivity extends AppCompatActivity
|
||||||
final Uri uri = Uri.fromFile(file);
|
final Uri uri = Uri.fromFile(file);
|
||||||
sendIntent.setAction(Intent.ACTION_SEND);
|
sendIntent.setAction(Intent.ACTION_SEND);
|
||||||
sendIntent.putExtra(Intent.EXTRA_STREAM, uri);
|
sendIntent.putExtra(Intent.EXTRA_STREAM, uri);
|
||||||
if (medium.getIsVideo())
|
if (medium.getIsVideo()) {
|
||||||
sendIntent.setType("video/*");
|
sendIntent.setType("video/*");
|
||||||
else
|
} else {
|
||||||
sendIntent.setType("image/*");
|
sendIntent.setType("image/*");
|
||||||
|
}
|
||||||
startActivity(Intent.createChooser(sendIntent, shareTitle));
|
startActivity(Intent.createChooser(sendIntent, shareTitle));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void notifyDeletion() {
|
private void notifyDeletion() {
|
||||||
toBeDeleted = getCurrentFile().getAbsolutePath();
|
mToBeDeleted = getCurrentFile().getAbsolutePath();
|
||||||
|
|
||||||
if (media.size() <= 1) {
|
if (mMedia.size() <= 1) {
|
||||||
deleteFile();
|
deleteFile();
|
||||||
} else {
|
} else {
|
||||||
Utils.showToast(this, R.string.file_deleted);
|
Utils.showToast(this, R.string.file_deleted);
|
||||||
undoBtn.setVisibility(View.VISIBLE);
|
mUndoBtn.setVisibility(View.VISIBLE);
|
||||||
isUndoShown = true;
|
mIsUndoShown = true;
|
||||||
reloadViewPager();
|
reloadViewPager();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void deleteFile() {
|
private void deleteFile() {
|
||||||
if (toBeDeleted.isEmpty())
|
if (mToBeDeleted.isEmpty())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
isUndoShown = false;
|
mIsUndoShown = false;
|
||||||
beingDeleted = "";
|
mBeingDeleted = "";
|
||||||
|
|
||||||
final File file = new File(toBeDeleted);
|
final File file = new File(mToBeDeleted);
|
||||||
if (file.delete()) {
|
if (file.delete()) {
|
||||||
beingDeleted = toBeDeleted;
|
mBeingDeleted = mToBeDeleted;
|
||||||
final String[] deletedPath = new String[]{toBeDeleted};
|
final String[] deletedPath = new String[]{mToBeDeleted};
|
||||||
MediaScannerConnection.scanFile(this, deletedPath, null, new MediaScannerConnection.OnScanCompletedListener() {
|
MediaScannerConnection.scanFile(this, deletedPath, null, new MediaScannerConnection.OnScanCompletedListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onScanCompleted(String path, Uri uri) {
|
public void onScanCompleted(String path, Uri uri) {
|
||||||
|
@ -176,12 +178,12 @@ public class ViewPagerActivity extends AppCompatActivity
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
toBeDeleted = "";
|
mToBeDeleted = "";
|
||||||
undoBtn.setVisibility(View.GONE);
|
mUndoBtn.setVisibility(View.GONE);
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean isDirEmpty() {
|
private boolean isDirEmpty() {
|
||||||
if (media.size() <= 0) {
|
if (mMedia.size() <= 0) {
|
||||||
deleteDirectoryIfEmpty();
|
deleteDirectoryIfEmpty();
|
||||||
finish();
|
finish();
|
||||||
return true;
|
return true;
|
||||||
|
@ -229,8 +231,8 @@ public class ViewPagerActivity extends AppCompatActivity
|
||||||
final File newFile = new File(file.getParent(), fileName + "." + extension);
|
final File newFile = new File(file.getParent(), fileName + "." + extension);
|
||||||
|
|
||||||
if (file.renameTo(newFile)) {
|
if (file.renameTo(newFile)) {
|
||||||
final int currItem = pager.getCurrentItem();
|
final int currItem = mPager.getCurrentItem();
|
||||||
media.set(currItem, new Medium(newFile.getAbsolutePath(), media.get(currItem).getIsVideo(), 0));
|
mMedia.set(currItem, new Medium(newFile.getAbsolutePath(), mMedia.get(currItem).getIsVideo(), 0));
|
||||||
|
|
||||||
final String[] changedFiles = {file.getAbsolutePath(), newFile.getAbsolutePath()};
|
final String[] changedFiles = {file.getAbsolutePath(), newFile.getAbsolutePath()};
|
||||||
MediaScannerConnection.scanFile(getApplicationContext(), changedFiles, null, null);
|
MediaScannerConnection.scanFile(getApplicationContext(), changedFiles, null, null);
|
||||||
|
@ -244,75 +246,75 @@ public class ViewPagerActivity extends AppCompatActivity
|
||||||
}
|
}
|
||||||
|
|
||||||
private void reloadViewPager() {
|
private void reloadViewPager() {
|
||||||
final MyPagerAdapter adapter = (MyPagerAdapter) pager.getAdapter();
|
final MyPagerAdapter adapter = (MyPagerAdapter) mPager.getAdapter();
|
||||||
final int curPos = pager.getCurrentItem();
|
final int curPos = mPager.getCurrentItem();
|
||||||
media = getMedia();
|
mMedia = getMedia();
|
||||||
if (isDirEmpty())
|
if (isDirEmpty())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
pager.setAdapter(null);
|
mPager.setAdapter(null);
|
||||||
adapter.updateItems(media);
|
adapter.updateItems(mMedia);
|
||||||
pager.setAdapter(adapter);
|
mPager.setAdapter(adapter);
|
||||||
|
|
||||||
final int newPos = Math.min(curPos, adapter.getCount());
|
final int newPos = Math.min(curPos, adapter.getCount());
|
||||||
pager.setCurrentItem(newPos);
|
mPager.setCurrentItem(newPos);
|
||||||
updateActionbarTitle();
|
updateActionbarTitle();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void deleteDirectoryIfEmpty() {
|
private void deleteDirectoryIfEmpty() {
|
||||||
final File file = new File(directory);
|
final File file = new File(mDirectory);
|
||||||
if (file.isDirectory() && file.listFiles().length == 0) {
|
if (file.isDirectory() && file.listFiles().length == 0) {
|
||||||
file.delete();
|
file.delete();
|
||||||
}
|
}
|
||||||
|
|
||||||
final String[] toBeDeleted = new String[]{directory};
|
final String[] toBeDeleted = new String[]{mDirectory};
|
||||||
MediaScannerConnection.scanFile(getApplicationContext(), toBeDeleted, null, null);
|
MediaScannerConnection.scanFile(getApplicationContext(), toBeDeleted, null, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<Medium> getMedia() {
|
private List<Medium> getMedia() {
|
||||||
final List<Medium> myMedia = new ArrayList<>();
|
final List<Medium> media = new ArrayList<>();
|
||||||
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) {
|
||||||
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 ? ";
|
||||||
final String[] args = new String[]{directory + "%"};
|
final String[] args = new String[]{mDirectory + "%"};
|
||||||
final String[] columns = {MediaStore.Images.Media.DATA, MediaStore.Images.Media.DATE_TAKEN};
|
final String[] columns = {MediaStore.Images.Media.DATA, MediaStore.Images.Media.DATE_TAKEN};
|
||||||
final Cursor cursor = getContentResolver().query(uri, columns, where, args, null);
|
final Cursor cursor = getContentResolver().query(uri, columns, where, args, null);
|
||||||
final String pattern = Pattern.quote(directory) + "/[^/]*";
|
final String pattern = Pattern.quote(mDirectory) + "/[^/]*";
|
||||||
|
|
||||||
if (cursor != null && cursor.moveToFirst()) {
|
if (cursor != null && cursor.moveToFirst()) {
|
||||||
final int pathIndex = cursor.getColumnIndex(MediaStore.Images.Media.DATA);
|
final int pathIndex = cursor.getColumnIndex(MediaStore.Images.Media.DATA);
|
||||||
do {
|
do {
|
||||||
final String curPath = cursor.getString(pathIndex);
|
final String curPath = cursor.getString(pathIndex);
|
||||||
if (curPath.matches(pattern) && !curPath.equals(toBeDeleted) && !curPath.equals(beingDeleted)) {
|
if (curPath.matches(pattern) && !curPath.equals(mToBeDeleted) && !curPath.equals(mBeingDeleted)) {
|
||||||
final int dateIndex = cursor.getColumnIndex(MediaStore.Images.Media.DATE_TAKEN);
|
final int dateIndex = cursor.getColumnIndex(MediaStore.Images.Media.DATE_TAKEN);
|
||||||
final long timestamp = cursor.getLong(dateIndex);
|
final long timestamp = cursor.getLong(dateIndex);
|
||||||
myMedia.add(new Medium(curPath, i == 1, timestamp));
|
media.add(new Medium(curPath, i == 1, timestamp));
|
||||||
}
|
}
|
||||||
} while (cursor.moveToNext());
|
} while (cursor.moveToNext());
|
||||||
cursor.close();
|
cursor.close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Collections.sort(myMedia);
|
Collections.sort(media);
|
||||||
int j = 0;
|
int j = 0;
|
||||||
for (Medium medium : myMedia) {
|
for (Medium medium : media) {
|
||||||
if (medium.getPath().equals(path)) {
|
if (medium.getPath().equals(mPath)) {
|
||||||
pos = j;
|
mPos = j;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
j++;
|
j++;
|
||||||
}
|
}
|
||||||
return myMedia;
|
return media;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void fragmentClicked() {
|
public void fragmentClicked() {
|
||||||
deleteFile();
|
deleteFile();
|
||||||
isFullScreen = !isFullScreen;
|
mIsFullScreen = !mIsFullScreen;
|
||||||
if (isFullScreen) {
|
if (mIsFullScreen) {
|
||||||
hideSystemUI();
|
hideSystemUI();
|
||||||
} else {
|
} else {
|
||||||
showSystemUI();
|
showSystemUI();
|
||||||
|
@ -320,21 +322,21 @@ public class ViewPagerActivity extends AppCompatActivity
|
||||||
}
|
}
|
||||||
|
|
||||||
private void hideSystemUI() {
|
private void hideSystemUI() {
|
||||||
Utils.hideSystemUI(actionbar, getWindow());
|
Utils.hideSystemUI(mActionbar, getWindow());
|
||||||
}
|
}
|
||||||
|
|
||||||
private void showSystemUI() {
|
private void showSystemUI() {
|
||||||
Utils.showSystemUI(actionbar, getWindow());
|
Utils.showSystemUI(mActionbar, getWindow());
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateActionbarTitle() {
|
private void updateActionbarTitle() {
|
||||||
setTitle(Utils.getFilename(media.get(pager.getCurrentItem()).getPath()));
|
setTitle(Utils.getFilename(mMedia.get(mPager.getCurrentItem()).getPath()));
|
||||||
}
|
}
|
||||||
|
|
||||||
private Medium getCurrentMedium() {
|
private Medium getCurrentMedium() {
|
||||||
if (pos >= media.size())
|
if (mPos >= mMedia.size())
|
||||||
pos = media.size() - 1;
|
mPos = mMedia.size() - 1;
|
||||||
return media.get(pos);
|
return mMedia.get(mPos);
|
||||||
}
|
}
|
||||||
|
|
||||||
private File getCurrentFile() {
|
private File getCurrentFile() {
|
||||||
|
@ -343,7 +345,7 @@ public class ViewPagerActivity extends AppCompatActivity
|
||||||
|
|
||||||
private void addUndoMargin() {
|
private void addUndoMargin() {
|
||||||
final Resources res = getResources();
|
final Resources res = getResources();
|
||||||
final RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) undoBtn.getLayoutParams();
|
final RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) mUndoBtn.getLayoutParams();
|
||||||
final int topMargin = Utils.getStatusBarHeight(res) + Utils.getActionBarHeight(getApplicationContext(), res);
|
final int topMargin = Utils.getStatusBarHeight(res) + Utils.getActionBarHeight(getApplicationContext(), res);
|
||||||
int rightMargin = params.rightMargin;
|
int rightMargin = params.rightMargin;
|
||||||
|
|
||||||
|
@ -362,33 +364,33 @@ public class ViewPagerActivity extends AppCompatActivity
|
||||||
@Override
|
@Override
|
||||||
public void onPageSelected(int position) {
|
public void onPageSelected(int position) {
|
||||||
updateActionbarTitle();
|
updateActionbarTitle();
|
||||||
pos = position;
|
mPos = position;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onPageScrollStateChanged(int state) {
|
public void onPageScrollStateChanged(int state) {
|
||||||
if (state == ViewPager.SCROLL_STATE_DRAGGING) {
|
if (state == ViewPager.SCROLL_STATE_DRAGGING) {
|
||||||
final MyPagerAdapter adapter = (MyPagerAdapter) pager.getAdapter();
|
final MyPagerAdapter adapter = (MyPagerAdapter) mPager.getAdapter();
|
||||||
adapter.itemDragged(pos);
|
adapter.itemDragged(mPos);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onSystemUiVisibilityChange(int visibility) {
|
public void onSystemUiVisibilityChange(int visibility) {
|
||||||
if ((visibility & View.SYSTEM_UI_FLAG_FULLSCREEN) == 0) {
|
if ((visibility & View.SYSTEM_UI_FLAG_FULLSCREEN) == 0) {
|
||||||
isFullScreen = false;
|
mIsFullScreen = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
final MyPagerAdapter adapter = (MyPagerAdapter) pager.getAdapter();
|
final MyPagerAdapter adapter = (MyPagerAdapter) mPager.getAdapter();
|
||||||
adapter.updateUiVisibility(isFullScreen, pos);
|
adapter.updateUiVisibility(mIsFullScreen, mPos);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void scanCompleted() {
|
private void scanCompleted() {
|
||||||
beingDeleted = "";
|
mBeingDeleted = "";
|
||||||
runOnUiThread(new Runnable() {
|
runOnUiThread(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
if (media != null && media.size() <= 1) {
|
if (mMedia != null && mMedia.size() <= 1) {
|
||||||
reloadViewPager();
|
reloadViewPager();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -397,7 +399,7 @@ public class ViewPagerActivity extends AppCompatActivity
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onTouch(View v, MotionEvent event) {
|
public boolean onTouch(View v, MotionEvent event) {
|
||||||
if (isUndoShown) {
|
if (mIsUndoShown) {
|
||||||
deleteFile();
|
deleteFile();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -9,8 +9,8 @@ import android.widget.ImageView;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
|
||||||
import com.bumptech.glide.Glide;
|
import com.bumptech.glide.Glide;
|
||||||
import com.simplemobiletools.gallery.models.Directory;
|
|
||||||
import com.simplemobiletools.gallery.R;
|
import com.simplemobiletools.gallery.R;
|
||||||
|
import com.simplemobiletools.gallery.models.Directory;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
@ -18,43 +18,44 @@ import butterknife.BindView;
|
||||||
import butterknife.ButterKnife;
|
import butterknife.ButterKnife;
|
||||||
|
|
||||||
public class DirectoryAdapter extends BaseAdapter {
|
public class DirectoryAdapter extends BaseAdapter {
|
||||||
private final Context context;
|
private final Context mContext;
|
||||||
private final List<Directory> dirs;
|
private final List<Directory> mDirs;
|
||||||
private final LayoutInflater inflater;
|
private final LayoutInflater mInflater;
|
||||||
|
|
||||||
public DirectoryAdapter(Context context, List<Directory> dirs) {
|
public DirectoryAdapter(Context context, List<Directory> dirs) {
|
||||||
this.context = context;
|
this.mContext = context;
|
||||||
this.dirs = dirs;
|
this.mDirs = dirs;
|
||||||
this.inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
this.mInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public View getView(int position, View view, ViewGroup parent) {
|
public View getView(int position, View view, ViewGroup parent) {
|
||||||
ViewHolder holder;
|
ViewHolder holder;
|
||||||
if (view == null) {
|
if (view == null) {
|
||||||
view = inflater.inflate(R.layout.directory_item, parent, false);
|
view = mInflater.inflate(R.layout.directory_item, parent, false);
|
||||||
holder = new ViewHolder(view);
|
holder = new ViewHolder(view);
|
||||||
view.setTag(holder);
|
view.setTag(holder);
|
||||||
} else {
|
} else {
|
||||||
holder = (ViewHolder) view.getTag();
|
holder = (ViewHolder) view.getTag();
|
||||||
}
|
}
|
||||||
|
|
||||||
final Directory dir = dirs.get(position);
|
final Directory dir = mDirs.get(position);
|
||||||
holder.dirName.setText(dir.getName());
|
holder.dirName.setText(dir.getName());
|
||||||
holder.photoCnt.setText(String.valueOf(dir.getMediaCnt()));
|
holder.photoCnt.setText(String.valueOf(dir.getMediaCnt()));
|
||||||
Glide.with(context).load(dir.getThumbnail()).placeholder(R.color.tmb_background).centerCrop().crossFade().into(holder.dirThumbnail);
|
Glide.with(mContext).load(dir.getThumbnail()).placeholder(R.color.tmb_background).centerCrop().crossFade()
|
||||||
|
.into(holder.dirThumbnail);
|
||||||
|
|
||||||
return view;
|
return view;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getCount() {
|
public int getCount() {
|
||||||
return dirs.size();
|
return mDirs.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object getItem(int position) {
|
public Object getItem(int position) {
|
||||||
return dirs.get(position);
|
return mDirs.get(position);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -63,8 +64,8 @@ public class DirectoryAdapter extends BaseAdapter {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void updateItems(List<Directory> newDirs) {
|
public void updateItems(List<Directory> newDirs) {
|
||||||
dirs.clear();
|
mDirs.clear();
|
||||||
dirs.addAll(newDirs);
|
mDirs.addAll(newDirs);
|
||||||
notifyDataSetChanged();
|
notifyDataSetChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -17,22 +17,22 @@ import butterknife.BindView;
|
||||||
import butterknife.ButterKnife;
|
import butterknife.ButterKnife;
|
||||||
|
|
||||||
public class MediaAdapter extends BaseAdapter {
|
public class MediaAdapter extends BaseAdapter {
|
||||||
private final Context context;
|
private final Context mContext;
|
||||||
private final List<Medium> media;
|
private final List<Medium> mMedia;
|
||||||
private final LayoutInflater inflater;
|
private final LayoutInflater mInflater;
|
||||||
|
|
||||||
public MediaAdapter(Context context, List<Medium> media) {
|
public MediaAdapter(Context context, List<Medium> media) {
|
||||||
this.context = context;
|
this.mContext = context;
|
||||||
this.media = media;
|
this.mMedia = media;
|
||||||
this.inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
this.mInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public View getView(int position, View view, ViewGroup parent) {
|
public View getView(int position, View view, ViewGroup parent) {
|
||||||
final Medium medium = media.get(position);
|
final Medium medium = mMedia.get(position);
|
||||||
ViewHolder holder;
|
ViewHolder holder;
|
||||||
if (view == null) {
|
if (view == null) {
|
||||||
view = inflater.inflate(R.layout.video_item, parent, false);
|
view = mInflater.inflate(R.layout.video_item, parent, false);
|
||||||
holder = new ViewHolder(view);
|
holder = new ViewHolder(view);
|
||||||
view.setTag(holder);
|
view.setTag(holder);
|
||||||
} else {
|
} else {
|
||||||
|
@ -46,19 +46,19 @@ public class MediaAdapter extends BaseAdapter {
|
||||||
}
|
}
|
||||||
|
|
||||||
final String path = medium.getPath();
|
final String path = medium.getPath();
|
||||||
Glide.with(context).load(path).placeholder(R.color.tmb_background).centerCrop().crossFade().into(holder.photoThumbnail);
|
Glide.with(mContext).load(path).placeholder(R.color.tmb_background).centerCrop().crossFade().into(holder.photoThumbnail);
|
||||||
|
|
||||||
return view;
|
return view;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getCount() {
|
public int getCount() {
|
||||||
return media.size();
|
return mMedia.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object getItem(int position) {
|
public Object getItem(int position) {
|
||||||
return media.get(position);
|
return mMedia.get(position);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -67,14 +67,14 @@ public class MediaAdapter extends BaseAdapter {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void updateItems(List<Medium> newPhotos) {
|
public void updateItems(List<Medium> newPhotos) {
|
||||||
media.clear();
|
mMedia.clear();
|
||||||
media.addAll(newPhotos);
|
mMedia.addAll(newPhotos);
|
||||||
notifyDataSetChanged();
|
notifyDataSetChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
static class ViewHolder {
|
static class ViewHolder {
|
||||||
@BindView(R.id.medium_thumbnail) ImageView photoThumbnail;
|
@BindView(R.id.medium_thumbnail) ImageView photoThumbnail;
|
||||||
@BindView(R.id.play_outline) ImageView playOutline;
|
@BindView(R.id.play_outline) View playOutline;
|
||||||
|
|
||||||
public ViewHolder(View view) {
|
public ViewHolder(View view) {
|
||||||
ButterKnife.bind(this, view);
|
ButterKnife.bind(this, view);
|
||||||
|
|
|
@ -17,25 +17,25 @@ import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
public class MyPagerAdapter extends FragmentStatePagerAdapter {
|
public class MyPagerAdapter extends FragmentStatePagerAdapter {
|
||||||
private List<Medium> media;
|
private final List<Medium> mMedia;
|
||||||
private Map<Integer, ViewPagerFragment> fragments;
|
private final Map<Integer, ViewPagerFragment> mFragments;
|
||||||
private ViewPagerActivity activity;
|
private final ViewPagerActivity mActivity;
|
||||||
|
|
||||||
public MyPagerAdapter(ViewPagerActivity act, FragmentManager fm, List<Medium> media) {
|
public MyPagerAdapter(ViewPagerActivity act, FragmentManager fm, List<Medium> media) {
|
||||||
super(fm);
|
super(fm);
|
||||||
this.activity = act;
|
this.mActivity = act;
|
||||||
this.media = media;
|
this.mMedia = media;
|
||||||
fragments = new HashMap<>();
|
mFragments = new HashMap<>();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getCount() {
|
public int getCount() {
|
||||||
return media.size();
|
return mMedia.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Fragment getItem(int position) {
|
public Fragment getItem(int position) {
|
||||||
final Medium medium = media.get(position);
|
final Medium medium = mMedia.get(position);
|
||||||
final Bundle bundle = new Bundle();
|
final Bundle bundle = new Bundle();
|
||||||
bundle.putSerializable(Constants.MEDIUM, medium);
|
bundle.putSerializable(Constants.MEDIUM, medium);
|
||||||
ViewPagerFragment fragment;
|
ViewPagerFragment fragment;
|
||||||
|
@ -46,21 +46,21 @@ public class MyPagerAdapter extends FragmentStatePagerAdapter {
|
||||||
fragment = new PhotoFragment();
|
fragment = new PhotoFragment();
|
||||||
}
|
}
|
||||||
|
|
||||||
fragments.put(position, fragment);
|
mFragments.put(position, fragment);
|
||||||
fragment.setArguments(bundle);
|
fragment.setArguments(bundle);
|
||||||
fragment.setListener(activity);
|
fragment.setListener(mActivity);
|
||||||
return fragment;
|
return fragment;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void itemDragged(int pos) {
|
public void itemDragged(int pos) {
|
||||||
if (fragments.get(pos) != null) {
|
if (mFragments.get(pos) != null) {
|
||||||
fragments.get(pos).itemDragged();
|
mFragments.get(pos).itemDragged();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void updateUiVisibility(boolean isFullscreen, int pos) {
|
public void updateUiVisibility(boolean isFullscreen, int pos) {
|
||||||
for (int i = -1; i <= 1; i++) {
|
for (int i = -1; i <= 1; i++) {
|
||||||
ViewPagerFragment fragment = fragments.get(pos + i);
|
final ViewPagerFragment fragment = mFragments.get(pos + i);
|
||||||
if (fragment != null) {
|
if (fragment != null) {
|
||||||
fragment.systemUiVisibilityChanged(isFullscreen);
|
fragment.systemUiVisibilityChanged(isFullscreen);
|
||||||
}
|
}
|
||||||
|
@ -68,8 +68,8 @@ public class MyPagerAdapter extends FragmentStatePagerAdapter {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void updateItems(List<Medium> newPaths) {
|
public void updateItems(List<Medium> newPaths) {
|
||||||
media.clear();
|
mMedia.clear();
|
||||||
media.addAll(newPaths);
|
mMedia.addAll(newPaths);
|
||||||
notifyDataSetChanged();
|
notifyDataSetChanged();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -37,10 +37,10 @@ public class PhotoFragment extends ViewPagerFragment implements View.OnClickList
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
if (listener == null)
|
if (mListener == null)
|
||||||
listener = (FragmentClickListener) getActivity();
|
mListener = (FragmentClickListener) getActivity();
|
||||||
|
|
||||||
listener.fragmentClicked();
|
mListener.fragmentClicked();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -35,33 +35,34 @@ public class VideoFragment extends ViewPagerFragment
|
||||||
SeekBar.OnSeekBarChangeListener, OnPreparedListener {
|
SeekBar.OnSeekBarChangeListener, OnPreparedListener {
|
||||||
private static final String TAG = VideoFragment.class.getSimpleName();
|
private static final String TAG = VideoFragment.class.getSimpleName();
|
||||||
private static final String PROGRESS = "progress";
|
private static final String PROGRESS = "progress";
|
||||||
private MediaPlayer mediaPlayer;
|
|
||||||
private SurfaceView surfaceView;
|
|
||||||
private SurfaceHolder surfaceHolder;
|
|
||||||
|
|
||||||
private ImageView playOutline;
|
private MediaPlayer mMediaPlayer;
|
||||||
private TextView currTimeView;
|
private SurfaceView mSurfaceView;
|
||||||
private TextView durationView;
|
private SurfaceHolder mSurfaceHolder;
|
||||||
private Handler timerHandler;
|
private ImageView mPlayOutline;
|
||||||
private SeekBar seekBar;
|
private TextView mCurrTimeView;
|
||||||
private Medium medium;
|
private TextView mDurationView;
|
||||||
private View timeHolder;
|
private Handler mTimerHandler;
|
||||||
private boolean isPlaying;
|
private SeekBar mSeekBar;
|
||||||
private boolean isDragged;
|
private Medium mMedium;
|
||||||
private boolean isFullscreen;
|
private View mTimeHolder;
|
||||||
private int currTime;
|
|
||||||
private int duration;
|
private boolean mIsPlaying;
|
||||||
|
private boolean mIsDragged;
|
||||||
|
private boolean mIsFullscreen;
|
||||||
|
private int mCurrTime;
|
||||||
|
private int mDuration;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||||
final View view = inflater.inflate(R.layout.pager_video_item, container, false);
|
final View view = inflater.inflate(R.layout.pager_video_item, container, false);
|
||||||
|
|
||||||
medium = (Medium) getArguments().getSerializable(Constants.MEDIUM);
|
mMedium = (Medium) getArguments().getSerializable(Constants.MEDIUM);
|
||||||
if (savedInstanceState != null) {
|
if (savedInstanceState != null) {
|
||||||
currTime = savedInstanceState.getInt(PROGRESS);
|
mCurrTime = savedInstanceState.getInt(PROGRESS);
|
||||||
}
|
}
|
||||||
|
|
||||||
isFullscreen = (getActivity().getWindow().getDecorView().getSystemUiVisibility() & View.SYSTEM_UI_FLAG_FULLSCREEN) ==
|
mIsFullscreen = (getActivity().getWindow().getDecorView().getSystemUiVisibility() & View.SYSTEM_UI_FLAG_FULLSCREEN) ==
|
||||||
View.SYSTEM_UI_FLAG_FULLSCREEN;
|
View.SYSTEM_UI_FLAG_FULLSCREEN;
|
||||||
setupPlayer(view);
|
setupPlayer(view);
|
||||||
view.setOnClickListener(this);
|
view.setOnClickListener(this);
|
||||||
|
@ -73,13 +74,13 @@ public class VideoFragment extends ViewPagerFragment
|
||||||
if (getActivity() == null)
|
if (getActivity() == null)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
playOutline = (ImageView) view.findViewById(R.id.video_play_outline);
|
mPlayOutline = (ImageView) view.findViewById(R.id.video_play_outline);
|
||||||
playOutline.setOnClickListener(this);
|
mPlayOutline.setOnClickListener(this);
|
||||||
|
|
||||||
surfaceView = (SurfaceView) view.findViewById(R.id.video_surface);
|
mSurfaceView = (SurfaceView) view.findViewById(R.id.video_surface);
|
||||||
surfaceView.setOnClickListener(this);
|
mSurfaceView.setOnClickListener(this);
|
||||||
surfaceHolder = surfaceView.getHolder();
|
mSurfaceHolder = mSurfaceView.getHolder();
|
||||||
surfaceHolder.addCallback(this);
|
mSurfaceHolder.addCallback(this);
|
||||||
|
|
||||||
initTimeHolder(view);
|
initTimeHolder(view);
|
||||||
}
|
}
|
||||||
|
@ -90,42 +91,42 @@ public class VideoFragment extends ViewPagerFragment
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void systemUiVisibilityChanged(boolean toFullscreen) {
|
public void systemUiVisibilityChanged(boolean toFullscreen) {
|
||||||
if (isFullscreen != toFullscreen) {
|
if (mIsFullscreen != toFullscreen) {
|
||||||
isFullscreen = toFullscreen;
|
mIsFullscreen = toFullscreen;
|
||||||
checkFullscreen();
|
checkFullscreen();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void initTimeHolder(View view) {
|
private void initTimeHolder(View view) {
|
||||||
timeHolder = view.findViewById(R.id.video_time_holder);
|
mTimeHolder = view.findViewById(R.id.video_time_holder);
|
||||||
final Resources res = getResources();
|
final Resources res = getResources();
|
||||||
final int height = Utils.getNavBarHeight(res);
|
final int height = Utils.getNavBarHeight(res);
|
||||||
final int left = timeHolder.getPaddingLeft();
|
final int left = mTimeHolder.getPaddingLeft();
|
||||||
final int top = timeHolder.getPaddingTop();
|
final int top = mTimeHolder.getPaddingTop();
|
||||||
final int right = timeHolder.getPaddingRight();
|
final int right = mTimeHolder.getPaddingRight();
|
||||||
final int bottom = timeHolder.getPaddingBottom();
|
final int bottom = mTimeHolder.getPaddingBottom();
|
||||||
|
|
||||||
if (Utils.hasNavBar(res)) {
|
if (Utils.hasNavBar(res)) {
|
||||||
if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT) {
|
if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT) {
|
||||||
timeHolder.setPadding(left, top, right, bottom + height);
|
mTimeHolder.setPadding(left, top, right, bottom + height);
|
||||||
} else {
|
} else {
|
||||||
timeHolder.setPadding(left, top, right + height, bottom);
|
mTimeHolder.setPadding(left, top, right + height, bottom);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
currTimeView = (TextView) view.findViewById(R.id.video_curr_time);
|
mCurrTimeView = (TextView) view.findViewById(R.id.video_curr_time);
|
||||||
durationView = (TextView) view.findViewById(R.id.video_duration);
|
mDurationView = (TextView) view.findViewById(R.id.video_duration);
|
||||||
seekBar = (SeekBar) view.findViewById(R.id.video_seekbar);
|
mSeekBar = (SeekBar) view.findViewById(R.id.video_seekbar);
|
||||||
seekBar.setOnSeekBarChangeListener(this);
|
mSeekBar.setOnSeekBarChangeListener(this);
|
||||||
|
|
||||||
if (isFullscreen)
|
if (mIsFullscreen)
|
||||||
timeHolder.setVisibility(View.INVISIBLE);
|
mTimeHolder.setVisibility(View.INVISIBLE);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setupTimeHolder() {
|
private void setupTimeHolder() {
|
||||||
seekBar.setMax(duration);
|
mSeekBar.setMax(mDuration);
|
||||||
durationView.setText(getTimeString(duration));
|
mDurationView.setText(getTimeString(mDuration));
|
||||||
timerHandler = new Handler();
|
mTimerHandler = new Handler();
|
||||||
setupTimer();
|
setupTimer();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -133,13 +134,13 @@ public class VideoFragment extends ViewPagerFragment
|
||||||
getActivity().runOnUiThread(new Runnable() {
|
getActivity().runOnUiThread(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
if (mediaPlayer != null && !isDragged && isPlaying) {
|
if (mMediaPlayer != null && !mIsDragged && mIsPlaying) {
|
||||||
currTime = mediaPlayer.getCurrentPosition() / 1000;
|
mCurrTime = mMediaPlayer.getCurrentPosition() / 1000;
|
||||||
seekBar.setProgress(currTime);
|
mSeekBar.setProgress(mCurrTime);
|
||||||
currTimeView.setText(getTimeString(currTime));
|
mCurrTimeView.setText(getTimeString(mCurrTime));
|
||||||
}
|
}
|
||||||
|
|
||||||
timerHandler.postDelayed(this, 1000);
|
mTimerHandler.postDelayed(this, 1000);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -147,7 +148,7 @@ public class VideoFragment extends ViewPagerFragment
|
||||||
@Override
|
@Override
|
||||||
public void onSaveInstanceState(Bundle outState) {
|
public void onSaveInstanceState(Bundle outState) {
|
||||||
super.onSaveInstanceState(outState);
|
super.onSaveInstanceState(outState);
|
||||||
outState.putInt(PROGRESS, currTime);
|
outState.putInt(PROGRESS, mCurrTime);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -157,31 +158,31 @@ public class VideoFragment extends ViewPagerFragment
|
||||||
togglePlayPause();
|
togglePlayPause();
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
isFullscreen = !isFullscreen;
|
mIsFullscreen = !mIsFullscreen;
|
||||||
checkFullscreen();
|
checkFullscreen();
|
||||||
|
|
||||||
if (listener == null)
|
if (mListener == null)
|
||||||
listener = (FragmentClickListener) getActivity();
|
mListener = (FragmentClickListener) getActivity();
|
||||||
listener.fragmentClicked();
|
mListener.fragmentClicked();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void checkFullscreen() {
|
private void checkFullscreen() {
|
||||||
int anim = R.anim.fade_in;
|
int anim = R.anim.fade_in;
|
||||||
if (isFullscreen) {
|
if (mIsFullscreen) {
|
||||||
anim = R.anim.fade_out;
|
anim = R.anim.fade_out;
|
||||||
seekBar.setOnSeekBarChangeListener(null);
|
mSeekBar.setOnSeekBarChangeListener(null);
|
||||||
} else {
|
} else {
|
||||||
seekBar.setOnSeekBarChangeListener(this);
|
mSeekBar.setOnSeekBarChangeListener(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
final Animation animation = AnimationUtils.loadAnimation(getContext(), anim);
|
final Animation animation = AnimationUtils.loadAnimation(getContext(), anim);
|
||||||
timeHolder.startAnimation(animation);
|
mTimeHolder.startAnimation(animation);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void pauseVideo() {
|
private void pauseVideo() {
|
||||||
if (isPlaying) {
|
if (mIsPlaying) {
|
||||||
togglePlayPause();
|
togglePlayPause();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -190,19 +191,19 @@ public class VideoFragment extends ViewPagerFragment
|
||||||
if (getActivity() == null)
|
if (getActivity() == null)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
isPlaying = !isPlaying;
|
mIsPlaying = !mIsPlaying;
|
||||||
if (isPlaying) {
|
if (mIsPlaying) {
|
||||||
if (mediaPlayer != null) {
|
if (mMediaPlayer != null) {
|
||||||
mediaPlayer.start();
|
mMediaPlayer.start();
|
||||||
}
|
}
|
||||||
|
|
||||||
playOutline.setImageDrawable(null);
|
mPlayOutline.setImageDrawable(null);
|
||||||
} else {
|
} else {
|
||||||
if (mediaPlayer != null) {
|
if (mMediaPlayer != null) {
|
||||||
mediaPlayer.pause();
|
mMediaPlayer.pause();
|
||||||
}
|
}
|
||||||
|
|
||||||
playOutline.setImageDrawable(getResources().getDrawable(R.mipmap.play_outline_big));
|
mPlayOutline.setImageDrawable(getResources().getDrawable(R.mipmap.play_outline_big));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -212,32 +213,32 @@ public class VideoFragment extends ViewPagerFragment
|
||||||
}
|
}
|
||||||
|
|
||||||
private void initMediaPlayer() {
|
private void initMediaPlayer() {
|
||||||
if (mediaPlayer != null)
|
if (mMediaPlayer != null)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
mediaPlayer = new MediaPlayer();
|
mMediaPlayer = new MediaPlayer();
|
||||||
mediaPlayer.setDataSource(getContext(), Uri.parse(medium.getPath()));
|
mMediaPlayer.setDataSource(getContext(), Uri.parse(mMedium.getPath()));
|
||||||
mediaPlayer.setDisplay(surfaceHolder);
|
mMediaPlayer.setDisplay(mSurfaceHolder);
|
||||||
mediaPlayer.setOnCompletionListener(this);
|
mMediaPlayer.setOnCompletionListener(this);
|
||||||
mediaPlayer.setOnVideoSizeChangedListener(this);
|
mMediaPlayer.setOnVideoSizeChangedListener(this);
|
||||||
mediaPlayer.setOnPreparedListener(this);
|
mMediaPlayer.setOnPreparedListener(this);
|
||||||
mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
|
mMediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
|
||||||
mediaPlayer.prepareAsync();
|
mMediaPlayer.prepareAsync();
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
Log.e(TAG, "init media player " + e.getMessage());
|
Log.e(TAG, "init media player " + e.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setProgress(int seconds) {
|
private void setProgress(int seconds) {
|
||||||
mediaPlayer.seekTo(seconds * 1000);
|
mMediaPlayer.seekTo(seconds * 1000);
|
||||||
seekBar.setProgress(seconds);
|
mSeekBar.setProgress(seconds);
|
||||||
currTimeView.setText(getTimeString(seconds));
|
mCurrTimeView.setText(getTimeString(seconds));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void addPreviewImage() {
|
private void addPreviewImage() {
|
||||||
mediaPlayer.start();
|
mMediaPlayer.start();
|
||||||
mediaPlayer.pause();
|
mMediaPlayer.pause();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -257,19 +258,19 @@ public class VideoFragment extends ViewPagerFragment
|
||||||
private void cleanup() {
|
private void cleanup() {
|
||||||
pauseVideo();
|
pauseVideo();
|
||||||
|
|
||||||
if (currTimeView != null)
|
if (mCurrTimeView != null)
|
||||||
currTimeView.setText(getTimeString(0));
|
mCurrTimeView.setText(getTimeString(0));
|
||||||
|
|
||||||
if (mediaPlayer != null) {
|
if (mMediaPlayer != null) {
|
||||||
mediaPlayer.release();
|
mMediaPlayer.release();
|
||||||
mediaPlayer = null;
|
mMediaPlayer = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (seekBar != null)
|
if (mSeekBar != null)
|
||||||
seekBar.setProgress(0);
|
mSeekBar.setProgress(0);
|
||||||
|
|
||||||
if (timerHandler != null)
|
if (mTimerHandler != null)
|
||||||
timerHandler.removeCallbacksAndMessages(null);
|
mTimerHandler.removeCallbacksAndMessages(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -284,8 +285,8 @@ public class VideoFragment extends ViewPagerFragment
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCompletion(MediaPlayer mp) {
|
public void onCompletion(MediaPlayer mp) {
|
||||||
seekBar.setProgress(seekBar.getMax());
|
mSeekBar.setProgress(mSeekBar.getMax());
|
||||||
currTimeView.setText(getTimeString(duration));
|
mCurrTimeView.setText(getTimeString(mDuration));
|
||||||
pauseVideo();
|
pauseVideo();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -315,7 +316,7 @@ public class VideoFragment extends ViewPagerFragment
|
||||||
|
|
||||||
final float screenProportion = (float) screenWidth / (float) screenHeight;
|
final float screenProportion = (float) screenWidth / (float) screenHeight;
|
||||||
|
|
||||||
final android.view.ViewGroup.LayoutParams lp = surfaceView.getLayoutParams();
|
final android.view.ViewGroup.LayoutParams lp = mSurfaceView.getLayoutParams();
|
||||||
if (videoProportion > screenProportion) {
|
if (videoProportion > screenProportion) {
|
||||||
lp.width = screenWidth;
|
lp.width = screenWidth;
|
||||||
lp.height = (int) ((float) screenWidth / videoProportion);
|
lp.height = (int) ((float) screenWidth / videoProportion);
|
||||||
|
@ -323,7 +324,7 @@ public class VideoFragment extends ViewPagerFragment
|
||||||
lp.width = (int) (videoProportion * (float) screenHeight);
|
lp.width = (int) (videoProportion * (float) screenHeight);
|
||||||
lp.height = screenHeight;
|
lp.height = screenHeight;
|
||||||
}
|
}
|
||||||
surfaceView.setLayoutParams(lp);
|
mSurfaceView.setLayoutParams(lp);
|
||||||
}
|
}
|
||||||
|
|
||||||
private String getTimeString(int duration) {
|
private String getTimeString(int duration) {
|
||||||
|
@ -344,36 +345,36 @@ public class VideoFragment extends ViewPagerFragment
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
|
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
|
||||||
if (mediaPlayer != null && fromUser) {
|
if (mMediaPlayer != null && fromUser) {
|
||||||
setProgress(progress);
|
setProgress(progress);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onStartTrackingTouch(SeekBar seekBar) {
|
public void onStartTrackingTouch(SeekBar seekBar) {
|
||||||
if (mediaPlayer == null)
|
if (mMediaPlayer == null)
|
||||||
initMediaPlayer();
|
initMediaPlayer();
|
||||||
|
|
||||||
mediaPlayer.pause();
|
mMediaPlayer.pause();
|
||||||
isDragged = true;
|
mIsDragged = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onStopTrackingTouch(SeekBar seekBar) {
|
public void onStopTrackingTouch(SeekBar seekBar) {
|
||||||
if (!isPlaying) {
|
if (!mIsPlaying) {
|
||||||
togglePlayPause();
|
togglePlayPause();
|
||||||
} else {
|
} else {
|
||||||
mediaPlayer.start();
|
mMediaPlayer.start();
|
||||||
}
|
}
|
||||||
|
|
||||||
isDragged = false;
|
mIsDragged = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onPrepared(MediaPlayer mp) {
|
public void onPrepared(MediaPlayer mp) {
|
||||||
duration = mp.getDuration() / 1000;
|
mDuration = mp.getDuration() / 1000;
|
||||||
addPreviewImage();
|
addPreviewImage();
|
||||||
setupTimeHolder();
|
setupTimeHolder();
|
||||||
setProgress(currTime);
|
setProgress(mCurrTime);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,10 +3,10 @@ package com.simplemobiletools.gallery.fragments;
|
||||||
import android.support.v4.app.Fragment;
|
import android.support.v4.app.Fragment;
|
||||||
|
|
||||||
public abstract class ViewPagerFragment extends Fragment {
|
public abstract class ViewPagerFragment extends Fragment {
|
||||||
protected FragmentClickListener listener;
|
protected FragmentClickListener mListener;
|
||||||
|
|
||||||
public void setListener(FragmentClickListener ln) {
|
public void setListener(FragmentClickListener listener) {
|
||||||
listener = ln;
|
mListener = listener;
|
||||||
}
|
}
|
||||||
|
|
||||||
public abstract void itemDragged();
|
public abstract void itemDragged();
|
||||||
|
|
|
@ -49,4 +49,14 @@ public class Directory implements Comparable {
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "Directory {" +
|
||||||
|
"path=" + getPath() +
|
||||||
|
", thumbnail=" + getThumbnail() +
|
||||||
|
", name=" + getName() +
|
||||||
|
", timestamp=" + getTimestamp() +
|
||||||
|
", mediaCnt=" + getMediaCnt() + "}";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue