add ability to delete own files from MediaViewerActivity

This commit is contained in:
Christian Schneppe 2020-02-16 10:48:14 +01:00
parent 827ae43d8b
commit d5f1690724
No known key found for this signature in database
GPG key ID: F30B8D686B44D87E
3 changed files with 70 additions and 27 deletions

View file

@ -37,6 +37,7 @@ import com.google.android.exoplayer2.source.ProgressiveMediaSource;
import com.google.android.exoplayer2.upstream.DataSource;
import com.google.android.exoplayer2.upstream.DefaultDataSourceFactory;
import com.google.android.exoplayer2.util.Util;
import com.leinardi.android.speeddial.SpeedDialActionItem;
import java.io.File;
import java.io.FileNotFoundException;
@ -109,28 +110,7 @@ public class MediaViewerActivity extends XmppActivity implements AudioManager.On
getWindow().setAttributes(layout);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
binding.speedDial.inflate(R.menu.media_viewer);
binding.speedDial.setOnActionSelectedListener(actionItem -> {
switch (actionItem.getId()) {
case R.id.action_share:
share();
break;
case R.id.action_open:
open();
break;
/*
case R.id.action_delete:
if (mFile == null || !mFile.toString().startsWith("/") || mFile.toString().contains(FileBackend.getConversationsDirectory("null"))) {
deleteFile();
}
break;
*/
default:
return false;
}
return false;
});
showFab();
//binding.speedDial.inflate(R.menu.media_viewer);
}
private void share() {
@ -146,7 +126,7 @@ public class MediaViewerActivity extends XmppActivity implements AudioManager.On
}
private void deleteFile() {
AlertDialog.Builder builder = new AlertDialog.Builder(this);
final AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setNegativeButton(R.string.cancel, null);
builder.setTitle(R.string.delete_file_dialog);
builder.setMessage(R.string.delete_file_dialog_msg);
@ -228,6 +208,54 @@ public class MediaViewerActivity extends XmppActivity implements AudioManager.On
}
}
}
if (isDeletableFile(mFile)) {
binding.speedDial.addActionItem(new SpeedDialActionItem.Builder(R.id.action_delete, R.drawable.ic_delete_white_24dp)
.setLabel(R.string.action_delete)
.create()
);
}
binding.speedDial.addActionItem(new SpeedDialActionItem.Builder(R.id.action_open, R.drawable.ic_open_in_new_white_24dp)
.setLabel(R.string.open_with)
.create()
);
binding.speedDial.addActionItem(new SpeedDialActionItem.Builder(R.id.action_share, R.drawable.ic_share_white_24dp)
.setLabel(R.string.share)
.create()
);
if (isDeletableFile(mFile)) {
binding.speedDial.setOnActionSelectedListener(actionItem -> {
switch (actionItem.getId()) {
case R.id.action_share:
share();
break;
case R.id.action_open:
open();
break;
case R.id.action_delete:
deleteFile();
break;
default:
return false;
}
return false;
});
} else {
binding.speedDial.setOnActionSelectedListener(actionItem -> {
switch (actionItem.getId()) {
case R.id.action_share:
share();
break;
case R.id.action_open:
open();
break;
default:
return false;
}
return false;
});
}
showFab();
}
private void DisplayImage(final File file, final Uri uri) {
@ -309,14 +337,18 @@ public class MediaViewerActivity extends XmppActivity implements AudioManager.On
private void releaseAudiFocus() {
AudioManager am = (AudioManager) this.getSystemService(Context.AUDIO_SERVICE);
am.abandonAudioFocus(this);
if (am != null) {
am.abandonAudioFocus(this);
}
}
private void requestAudioFocus() {
AudioManager am = (AudioManager) this.getSystemService(Context.AUDIO_SERVICE);
am.requestAudioFocus(this,
AudioManager.STREAM_MUSIC,
AudioManager.AUDIOFOCUS_GAIN_TRANSIENT);
if (am != null) {
am.requestAudioFocus(this,
AudioManager.STREAM_MUSIC,
AudioManager.AUDIOFOCUS_GAIN_TRANSIENT);
}
}
private int getRotation(Uri image) {
@ -462,4 +494,8 @@ public class MediaViewerActivity extends XmppActivity implements AudioManager.On
Log.i(Config.LOGTAG, "Audio focus failed.");
}
}
private boolean isDeletableFile(File file) {
return (file == null || !file.toString().startsWith("/") || file.toString().contains(FileBackend.getConversationsDirectory("null")));
}
}

View file

@ -10,4 +10,10 @@
android:icon="@drawable/ic_open_in_new_white_24dp"
android:orderInCategory="20"
android:title="@string/action_open" />
<item
android:id="@+id/action_delete"
android:icon="@drawable/ic_delete_white_24dp"
android:orderInCategory="20"
android:title="@string/action_delete"
android:visible="false" />
</menu>

View file

@ -1004,4 +1004,5 @@
<string name="pref_use_colored_muc_names">Colorize nicknames</string>
<string name="show_videos_images_only">Only images/videos</string>
<string name="show_avatar">Show avatar</string>
<string name="action_delete">Delete</string>
</resources>