mirror of
https://github.com/TeamNewPipe/NewPipe
synced 2024-12-24 00:50:32 +00:00
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.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
import android.webkit.MimeTypeMap;
|
import android.webkit.MimeTypeMap;
|
||||||
|
import android.widget.CheckBox;
|
||||||
import android.widget.ImageView;
|
import android.widget.ImageView;
|
||||||
import android.widget.PopupMenu;
|
import android.widget.PopupMenu;
|
||||||
import android.widget.TextView;
|
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();
|
mDownloadManager.forgetFinishedDownloads();
|
||||||
applyChanges();
|
applyChanges();
|
||||||
}
|
}
|
||||||
|
@ -17,6 +17,7 @@ import android.view.Menu;
|
|||||||
import android.view.MenuItem;
|
import android.view.MenuItem;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
|
import android.widget.CheckBox;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
@ -189,9 +190,14 @@ public class MissionsFragment extends Fragment {
|
|||||||
return true;
|
return true;
|
||||||
case R.id.clear_list:
|
case R.id.clear_list:
|
||||||
AlertDialog.Builder prompt = new AlertDialog.Builder(mContext);
|
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.setTitle(R.string.clear_finished_download);
|
||||||
prompt.setMessage(R.string.confirm_prompt);
|
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.setNegativeButton(R.string.cancel, null);
|
||||||
prompt.create().show();
|
prompt.create().show();
|
||||||
return true;
|
return true;
|
||||||
|
14
app/src/main/res/layout/delete_files_checkbox.xml
Normal file
14
app/src/main/res/layout/delete_files_checkbox.xml
Normal file
@ -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_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="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="choose_instance_prompt">Choose an instance</string>
|
||||||
|
<string name="delete_downloaded_files">Delete downloaded files</string>
|
||||||
</resources>
|
</resources>
|
||||||
|
Loading…
Reference in New Issue
Block a user