added incognito mode, ability to delete file when deleting history item
also fixed cancel all downloads button from the top app bar not disappearing when i cancel the single download from the card
This commit is contained in:
parent
83055c0a42
commit
8910d19815
10 changed files with 78 additions and 48 deletions
|
|
@ -320,7 +320,7 @@
|
|||
<PersistentState>
|
||||
<option name="values">
|
||||
<map>
|
||||
<entry key="url" value="file:/$USER_HOME$/AppData/Local/Android/Sdk/icons/material/materialicons/history/baseline_history_24.xml" />
|
||||
<entry key="url" value="file:/$USER_HOME$/AppData/Local/Android/Sdk/icons/material/materialicons/bedtime/baseline_bedtime_24.xml" />
|
||||
</map>
|
||||
</option>
|
||||
</PersistentState>
|
||||
|
|
@ -331,7 +331,7 @@
|
|||
<option name="values">
|
||||
<map>
|
||||
<entry key="color" value="00a6ff" />
|
||||
<entry key="outputName" value="ic_history" />
|
||||
<entry key="outputName" value="ic_incognito" />
|
||||
<entry key="sourceFile" value="C:\Users\denis\Desktop\adaptiveproduct_youtube_foreground_color_108 (1).svg" />
|
||||
</map>
|
||||
</option>
|
||||
|
|
|
|||
|
|
@ -54,6 +54,7 @@
|
|||
<entry key="..\:/Users/denis/Documents/GitHub/ytdlnis/app/src/main/res/drawable/ic_history.xml" value="0.1965" />
|
||||
<entry key="..\:/Users/denis/Documents/GitHub/ytdlnis/app/src/main/res/drawable/ic_home.xml" value="0.1275" />
|
||||
<entry key="..\:/Users/denis/Documents/GitHub/ytdlnis/app/src/main/res/drawable/ic_image.xml" value="0.109" />
|
||||
<entry key="..\:/Users/denis/Documents/GitHub/ytdlnis/app/src/main/res/drawable/ic_incognito.xml" value="0.198" />
|
||||
<entry key="..\:/Users/denis/Documents/GitHub/ytdlnis/app/src/main/res/drawable/ic_info.xml" value="0.109" />
|
||||
<entry key="..\:/Users/denis/Documents/GitHub/ytdlnis/app/src/main/res/drawable/ic_key.xml" value="0.1965" />
|
||||
<entry key="..\:/Users/denis/Documents/GitHub/ytdlnis/app/src/main/res/drawable/ic_launcher_background.xml" value="0.2395" />
|
||||
|
|
|
|||
|
|
@ -186,14 +186,17 @@ public class MainActivity extends AppCompatActivity{
|
|||
|
||||
public void addQueueToDownloads(ArrayList<Video> downloadQueue) {
|
||||
try {
|
||||
DBManager dbManager = new DBManager(context);
|
||||
for (int i = downloadQueue.size() - 1; i >= 0; i--){
|
||||
Video v = downloadQueue.get(i);
|
||||
v.setQueuedDownload(true);
|
||||
dbManager.addToHistory(v);
|
||||
SharedPreferences sharedPreferences = context.getSharedPreferences("root_preferences", Activity.MODE_PRIVATE);
|
||||
if (!sharedPreferences.getBoolean("incognito", false)) {
|
||||
DBManager dbManager = new DBManager(context);
|
||||
for (int i = downloadQueue.size() - 1; i >= 0; i--){
|
||||
Video v = downloadQueue.get(i);
|
||||
v.setQueuedDownload(true);
|
||||
dbManager.addToHistory(v);
|
||||
}
|
||||
dbManager.close();
|
||||
downloadsFragment.initCards();
|
||||
}
|
||||
dbManager.close();
|
||||
downloadsFragment.initCards();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@ import android.database.sqlite.SQLiteOpenHelper;
|
|||
import android.graphics.ColorMatrix;
|
||||
import android.graphics.ColorMatrixColorFilter;
|
||||
import android.util.Log;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.deniscerri.ytdlnis.R;
|
||||
|
||||
|
|
@ -16,6 +17,7 @@ import java.io.File;
|
|||
import java.util.ArrayList;
|
||||
|
||||
public class DBManager extends SQLiteOpenHelper {
|
||||
Context context;
|
||||
|
||||
public static final String db_name = "ytdlnis_db";
|
||||
public static final int db_version = 7;
|
||||
|
|
@ -42,6 +44,7 @@ public class DBManager extends SQLiteOpenHelper {
|
|||
|
||||
public DBManager(Context context){
|
||||
super(context, db_name, null, db_version);
|
||||
this.context = context;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -89,8 +92,28 @@ public class DBManager extends SQLiteOpenHelper {
|
|||
" WHERE downloadedAudio=1 OR downloadedVideo=1");
|
||||
}
|
||||
|
||||
public void clearHistoryItem(Video video){
|
||||
@SuppressLint("Range")
|
||||
public void clearHistoryItem(Video video, boolean delete_file){
|
||||
SQLiteDatabase db = this.getWritableDatabase();
|
||||
|
||||
if (delete_file){
|
||||
try{
|
||||
Cursor cursor = db.rawQuery("SELECT * FROM " + history_table_name + " WHERE url='" +
|
||||
video.getURL() + "' AND type='"+video.getDownloadedType() + "' LIMIT 1", null);
|
||||
|
||||
if(cursor.moveToFirst()){
|
||||
String path = cursor.getString(cursor.getColumnIndex(downloadPath));
|
||||
File file = new File(path);
|
||||
if(file.exists()){
|
||||
file.delete();
|
||||
}
|
||||
}
|
||||
}catch (Exception e){
|
||||
Toast.makeText(context, R.string.error_deleting_file, Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
db.execSQL("DELETE FROM " + history_table_name + " WHERE id=" + video.getId());
|
||||
|
||||
String where = "";
|
||||
|
|
@ -114,7 +137,7 @@ public class DBManager extends SQLiteOpenHelper {
|
|||
String path = video.getDownloadPath();
|
||||
File file = new File(path);
|
||||
if(!file.exists() && !path.isEmpty()){
|
||||
clearHistoryItem(video);
|
||||
clearHistoryItem(video, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -124,7 +147,7 @@ public class DBManager extends SQLiteOpenHelper {
|
|||
for (int i = 0; i < videos.size(); i++){
|
||||
Video video = videos.get(i);
|
||||
if(video.isQueuedDownload()){
|
||||
clearHistoryItem(video);
|
||||
clearHistoryItem(video, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -310,13 +333,14 @@ public class DBManager extends SQLiteOpenHelper {
|
|||
db.update(results_table_name, values, "videoId = ?", new String[]{id});
|
||||
}
|
||||
|
||||
@SuppressLint("Range")
|
||||
public int checkDownloaded(String url, String downloadType){
|
||||
SQLiteDatabase db = this.getWritableDatabase();
|
||||
Cursor cursor = db.rawQuery("SELECT * FROM " + history_table_name + " WHERE url='" +
|
||||
url + "' AND type='"+downloadType + "' LIMIT 1", null);
|
||||
|
||||
if(cursor.moveToFirst()){
|
||||
String path = cursor.getString(8);
|
||||
String path = cursor.getString(cursor.getColumnIndex(downloadPath));
|
||||
File file = new File(path);
|
||||
if(!file.exists() && !path.isEmpty()){
|
||||
return 0;
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ import android.app.Activity;
|
|||
import android.content.ClipData;
|
||||
import android.content.ClipboardManager;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.media.MediaScannerConnection;
|
||||
import android.net.Uri;
|
||||
|
|
@ -113,7 +114,7 @@ public class DownloadsFragment extends Fragment implements DownloadsRecyclerView
|
|||
int position = downloadsObjects.indexOf(info.getVideo());
|
||||
Video v = downloadsObjects.get(position);
|
||||
dbManager = new DBManager(context);
|
||||
dbManager.clearHistoryItem(v);
|
||||
dbManager.clearHistoryItem(v, false);
|
||||
downloadsRecyclerViewAdapter.notifyItemRemoved(position);
|
||||
}catch(Exception ignored){}
|
||||
}
|
||||
|
|
@ -180,7 +181,7 @@ public class DownloadsFragment extends Fragment implements DownloadsRecyclerView
|
|||
try {
|
||||
downloadsObjects.remove(v);
|
||||
dbManager = new DBManager(context);
|
||||
dbManager.clearHistoryItem(v);
|
||||
dbManager.clearHistoryItem(v,false);
|
||||
downloadsRecyclerViewAdapter.setVideoList(downloadsObjects);
|
||||
}catch (Exception ignored){}
|
||||
}
|
||||
|
|
@ -532,11 +533,12 @@ public class DownloadsFragment extends Fragment implements DownloadsRecyclerView
|
|||
|
||||
private void removedownloadsItem(int position){
|
||||
if(bottomSheet != null) bottomSheet.hide();
|
||||
final boolean[] delete_file = {false};
|
||||
|
||||
Video v = downloadsObjects.get(position);
|
||||
MaterialAlertDialogBuilder delete_dialog = new MaterialAlertDialogBuilder(fragmentContext);
|
||||
delete_dialog.setTitle(getString(R.string.confirm_delete_history));
|
||||
delete_dialog.setMessage(getString(R.string.you_are_going_to_delete) + " \""+v.getTitle()+"\"!");
|
||||
delete_dialog.setTitle(getString(R.string.you_are_going_to_delete) + " \""+v.getTitle()+"\"!");
|
||||
delete_dialog.setMultiChoiceItems(new String[]{getString(R.string.delete_file_too)}, new boolean[]{false}, (dialogInterface, i, b) -> delete_file[0] = b);
|
||||
delete_dialog.setNegativeButton(getString(R.string.cancel), (dialogInterface, i) -> {
|
||||
dialogInterface.cancel();
|
||||
});
|
||||
|
|
@ -546,7 +548,7 @@ public class DownloadsFragment extends Fragment implements DownloadsRecyclerView
|
|||
downloadsRecyclerViewAdapter.setVideoList(downloadsObjects);
|
||||
downloadsRecyclerViewAdapter.setWebsiteList();
|
||||
updateWebsiteChips();
|
||||
dbManager.clearHistoryItem(v);
|
||||
dbManager.clearHistoryItem(v, delete_file[0]);
|
||||
|
||||
if(downloadsObjects.size() == 0){
|
||||
uiHandler.post(() -> {
|
||||
|
|
|
|||
|
|
@ -154,6 +154,11 @@ public class HomeFragment extends Fragment implements HomeRecyclerViewAdapter.On
|
|||
Video video = findVideo(info.getVideo().getURL());
|
||||
String type = info.getDownloadType();
|
||||
updateDownloadingStatusOnResult(video, type, false);
|
||||
|
||||
if (info.getDownloadQueue().size() == 1){
|
||||
downloading = false;
|
||||
topAppBar.getMenu().findItem(R.id.cancel_download).setVisible(false);
|
||||
}
|
||||
}catch (Exception e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
|
@ -618,36 +623,6 @@ public class HomeFragment extends Fragment implements HomeRecyclerViewAdapter.On
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
public void addToHistory(Video video, Date date, String[] paths) {
|
||||
Calendar cal = Calendar.getInstance();
|
||||
cal.setTime(date);
|
||||
int day = cal.get(Calendar.DAY_OF_MONTH);
|
||||
String month = cal.getDisplayName(Calendar.MONTH, Calendar.LONG, Locale.getDefault());
|
||||
int year = cal.get(Calendar.YEAR);
|
||||
|
||||
DateFormat formatter = new SimpleDateFormat("HH:mm", Locale.getDefault());
|
||||
String time = formatter.format(date);
|
||||
String downloadedTime = day + " " + month + " " + year + " " + time;
|
||||
|
||||
String path = "";
|
||||
try{
|
||||
path = paths[0];
|
||||
}catch(Exception e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
if (video != null) {
|
||||
dbManager = new DBManager(context);
|
||||
try {
|
||||
video.setDownloadedTime(downloadedTime);
|
||||
video.setDownloadPath(path);
|
||||
dbManager.addToHistory(video);
|
||||
dbManager.close();
|
||||
} catch (Exception ignored) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void updateDownloadStatusOnResult(Video v, String type, boolean downloaded) {
|
||||
if (v != null) {
|
||||
dbManager = new DBManager(context);
|
||||
|
|
|
|||
|
|
@ -29,6 +29,7 @@ public class SettingsFragment extends PreferenceFragmentCompat {
|
|||
Preference videoPath;
|
||||
Preference commandPath;
|
||||
|
||||
SwitchPreferenceCompat incognito;
|
||||
EditTextPreference apiKey;
|
||||
SeekBarPreference concurrentFragments;
|
||||
EditTextPreference limitRate;
|
||||
|
|
@ -72,6 +73,7 @@ public class SettingsFragment extends PreferenceFragmentCompat {
|
|||
videoPath = findPreference("video_path");
|
||||
commandPath = findPreference("command_path");
|
||||
|
||||
incognito = findPreference("incognito");
|
||||
apiKey = findPreference("api_key");
|
||||
concurrentFragments = findPreference("concurrent_fragments");
|
||||
limitRate = findPreference("limit_rate");
|
||||
|
|
@ -101,6 +103,7 @@ public class SettingsFragment extends PreferenceFragmentCompat {
|
|||
editor.putString("command_path", getString(R.string.command_path));
|
||||
}
|
||||
|
||||
editor.putBoolean("incognito", incognito.isChecked());
|
||||
editor.putString("api_key", apiKey.getText());
|
||||
editor.putInt("concurrent_fragments", concurrentFragments.getValue());
|
||||
editor.putString("limit_rate", limitRate.getText());
|
||||
|
|
@ -143,6 +146,13 @@ public class SettingsFragment extends PreferenceFragmentCompat {
|
|||
return true;
|
||||
});
|
||||
|
||||
incognito.setOnPreferenceChangeListener((preference, newValue) -> {
|
||||
boolean enable = (Boolean) newValue;
|
||||
editor.putBoolean("incognito", enable);
|
||||
editor.apply();
|
||||
return true;
|
||||
});
|
||||
|
||||
apiKey.setOnPreferenceChangeListener((preference, newValue) -> {
|
||||
editor.putString("api_key", String.valueOf(newValue));
|
||||
editor.apply();
|
||||
|
|
|
|||
5
app/src/main/res/drawable/ic_incognito.xml
Normal file
5
app/src/main/res/drawable/ic_incognito.xml
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
<vector android:height="24dp"
|
||||
android:viewportHeight="24" android:viewportWidth="24"
|
||||
android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<path android:fillColor="?android:colorAccent" android:pathData="M12.34,2.02C6.59,1.82 2,6.42 2,12c0,5.52 4.48,10 10,10c3.71,0 6.93,-2.02 8.66,-5.02C13.15,16.73 8.57,8.55 12.34,2.02z"/>
|
||||
</vector>
|
||||
|
|
@ -113,4 +113,7 @@
|
|||
<string name="currently_downloading">Downloading</string>
|
||||
<string name="remove_downloading">Remove Downloading</string>
|
||||
<string name="confirm_delete_downloading_desc">You are going to remove all items that have a downloading state and then cancel the download service!</string>
|
||||
<string name="error_deleting_file">Error on deleting file! :(</string>
|
||||
<string name="delete_file_too">Delete the file from the system</string>
|
||||
<string name="incognito_summary">Download privately without a download history</string>
|
||||
</resources>
|
||||
|
|
|
|||
|
|
@ -23,6 +23,13 @@
|
|||
</PreferenceCategory>
|
||||
|
||||
<PreferenceCategory app:title="@string/downloading">
|
||||
<SwitchPreferenceCompat
|
||||
app:defaultValue="false"
|
||||
android:icon="@drawable/ic_incognito"
|
||||
android:key="incognito"
|
||||
app:summary="@string/incognito_summary"
|
||||
app:title="Incognito" />
|
||||
|
||||
<EditTextPreference
|
||||
android:icon="@drawable/ic_key"
|
||||
app:key="api_key"
|
||||
|
|
|
|||
Loading…
Reference in a new issue