Merge pull request #1879 from jludden/play_one_click

downloaded files can now be opened with one click
This commit is contained in:
Christian Schabesberger 2018-11-13 13:43:28 +01:00 committed by GitHub
commit 0cd7ac05aa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 26 additions and 32 deletions

View File

@ -96,12 +96,12 @@ public class MissionAdapter extends RecyclerView.Adapter<MissionAdapter.ViewHold
} }
}); });
/*h.itemView.setOnClickListener(new View.OnClickListener() { h.itemView.setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
showDetail(h); if(h.mission.finished) viewFile(h);
} }
});*/ });
return h; return h;
} }
@ -200,14 +200,12 @@ public class MissionAdapter extends RecyclerView.Adapter<MissionAdapter.ViewHold
Menu menu = popup.getMenu(); Menu menu = popup.getMenu();
MenuItem start = menu.findItem(R.id.start); MenuItem start = menu.findItem(R.id.start);
MenuItem pause = menu.findItem(R.id.pause); MenuItem pause = menu.findItem(R.id.pause);
MenuItem view = menu.findItem(R.id.view);
MenuItem delete = menu.findItem(R.id.delete); MenuItem delete = menu.findItem(R.id.delete);
MenuItem checksum = menu.findItem(R.id.checksum); MenuItem checksum = menu.findItem(R.id.checksum);
// Set to false first // Set to false first
start.setVisible(false); start.setVisible(false);
pause.setVisible(false); pause.setVisible(false);
view.setVisible(false);
delete.setVisible(false); delete.setVisible(false);
checksum.setVisible(false); checksum.setVisible(false);
@ -222,7 +220,6 @@ public class MissionAdapter extends RecyclerView.Adapter<MissionAdapter.ViewHold
pause.setVisible(true); pause.setVisible(true);
} }
} else { } else {
view.setVisible(true);
delete.setVisible(true); delete.setVisible(true);
checksum.setVisible(true); checksum.setVisible(true);
} }
@ -241,27 +238,6 @@ public class MissionAdapter extends RecyclerView.Adapter<MissionAdapter.ViewHold
mBinder.onMissionRemoved(mItemList.get(h.position)); mBinder.onMissionRemoved(mItemList.get(h.position));
h.lastTimeStamp = -1; h.lastTimeStamp = -1;
h.lastDone = -1; h.lastDone = -1;
return true;
case R.id.view:
File f = new File(h.mission.location, h.mission.name);
String ext = Utility.getFileExt(h.mission.name);
Log.d(TAG, "Viewing file: " + f.getAbsolutePath() + " ext: " + ext);
if (ext == null) {
Log.w(TAG, "Can't view file because it has no extension: " +
h.mission.name);
return false;
}
String mime = MimeTypeMap.getSingleton().getMimeTypeFromExtension(ext.substring(1));
Log.v(TAG, "Mime: " + mime + " package: " + mContext.getApplicationContext().getPackageName() + ".provider");
if (f.exists()) {
viewFileWithFileProvider(f, mime);
} else {
Log.w(TAG, "File doesn't exist");
}
return true; return true;
case R.id.delete: case R.id.delete:
mDeleteDownloadManager.add(h.mission); mDeleteDownloadManager.add(h.mission);
@ -282,6 +258,28 @@ public class MissionAdapter extends RecyclerView.Adapter<MissionAdapter.ViewHold
popup.show(); popup.show();
} }
private boolean viewFile(ViewHolder h) {
File f = new File(h.mission.location, h.mission.name);
String ext = Utility.getFileExt(h.mission.name);
Log.d(TAG, "Viewing file: " + f.getAbsolutePath() + " ext: " + ext);
if (ext == null) {
Log.w(TAG, "Can't view file because it has no extension: " +
h.mission.name);
return true;
}
String mime = MimeTypeMap.getSingleton().getMimeTypeFromExtension(ext.substring(1));
Log.v(TAG, "Mime: " + mime + " package: " + mContext.getApplicationContext().getPackageName() + ".provider");
if (f.exists()) {
viewFileWithFileProvider(f, mime);
} else {
Log.w(TAG, "File doesn't exist");
}
return false;
}
private void viewFileWithFileProvider(File file, String mimetype) { private void viewFileWithFileProvider(File file, String mimetype) {
String ourPackage = mContext.getApplicationContext().getPackageName(); String ourPackage = mContext.getApplicationContext().getPackageName();
Uri uri = FileProvider.getUriForFile(mContext, ourPackage + ".provider", file); Uri uri = FileProvider.getUriForFile(mContext, ourPackage + ".provider", file);

View File

@ -8,10 +8,6 @@
android:id="@+id/pause" android:id="@+id/pause"
android:title="@string/pause"/> android:title="@string/pause"/>
<item
android:id="@+id/view"
android:title="@string/view"/>
<item <item
android:id="@+id/delete" android:id="@+id/delete"
android:title="@string/delete"/> android:title="@string/delete"/>