Add option to remove downloaded files when clearing finished downloads
This commit is contained in:
parent
7e17bdf369
commit
707e4f7167
|
@ -19,6 +19,7 @@ import android.view.MenuItem;
|
|||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.webkit.MimeTypeMap;
|
||||
import android.widget.CheckBox;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.PopupMenu;
|
||||
import android.widget.TextView;
|
||||
|
@ -557,7 +558,16 @@ public class MissionAdapter extends Adapter<ViewHolder> implements Handler.Callb
|
|||
);
|
||||
}
|
||||
|
||||
public void clearFinishedDownloads() {
|
||||
public void clearFinishedDownloads(boolean delete) {
|
||||
if (delete && mIterator.hasFinishedMissions()) {
|
||||
for(int i=0; i<mIterator.getOldListSize(); i++) {
|
||||
FinishedMission mission = mIterator.getItem(i).mission instanceof FinishedMission ? (FinishedMission) mIterator.getItem(i).mission : null;
|
||||
if (mission != null) {
|
||||
mDownloadManager.deleteMission(mission);
|
||||
mContext.sendBroadcast(new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, mission.storage.getUri()));
|
||||
}
|
||||
}
|
||||
}
|
||||
mDownloadManager.forgetFinishedDownloads();
|
||||
applyChanges();
|
||||
}
|
||||
|
|
|
@ -17,6 +17,7 @@ import android.view.Menu;
|
|||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.CheckBox;
|
||||
import android.widget.Toast;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
@ -189,9 +190,14 @@ public class MissionsFragment extends Fragment {
|
|||
return true;
|
||||
case R.id.clear_list:
|
||||
AlertDialog.Builder prompt = new AlertDialog.Builder(mContext);
|
||||
View checkBoxView = View.inflate(this.getContext(), R.layout.delete_files_checkbox, null);
|
||||
prompt.setTitle(R.string.clear_finished_download);
|
||||
prompt.setMessage(R.string.confirm_prompt);
|
||||
prompt.setPositiveButton(android.R.string.ok, (dialog, which) -> mAdapter.clearFinishedDownloads());
|
||||
prompt.setView(checkBoxView);
|
||||
prompt.setPositiveButton(android.R.string.ok, (dialog, which) -> {
|
||||
CheckBox checkBox = checkBoxView.findViewById(R.id.delete_files_checkbox);
|
||||
mAdapter.clearFinishedDownloads(checkBox.isChecked());
|
||||
});
|
||||
prompt.setNegativeButton(R.string.cancel, null);
|
||||
prompt.create().show();
|
||||
return true;
|
||||
|
|
|
@ -0,0 +1,14 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<FrameLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:paddingHorizontal="15dp">
|
||||
|
||||
<CheckBox
|
||||
android:id="@+id/delete_files_checkbox"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/delete_downloaded_files"/>
|
||||
|
||||
</FrameLayout>
|
|
@ -587,5 +587,5 @@
|
|||
<string name="downloads_storage_use_saf_title">Use SAF</string>
|
||||
<string name="downloads_storage_use_saf_summary">The Storage Access Framework allows downloads to an external SD card.\nNote: some devices are not compatible</string>
|
||||
<string name="choose_instance_prompt">Choose an instance</string>
|
||||
|
||||
<string name="delete_downloaded_files">Delete downloaded files</string>
|
||||
</resources>
|
||||
|
|
Loading…
Reference in New Issue