fixed downloads delete dialogs not showing

also fixed certain files not getting recognized in the filesystem and giving a false negative on downloads tab, making them grey
made grey downloads' buttons grey too
switched the button to materialbutton like home
replaced basic progressbar to linearprogress. Now progress is buttery smooth
This commit is contained in:
Denis Çerri 2022-10-02 01:19:18 +02:00
parent 3936e83578
commit b5119e8b4e
No known key found for this signature in database
GPG key ID: 3F50F14A8E7F7A13
13 changed files with 90 additions and 45 deletions

View file

@ -320,7 +320,7 @@
<PersistentState>
<option name="values">
<map>
<entry key="url" value="file:/$USER_HOME$/AppData/Local/Android/Sdk/icons/material/materialiconsoutlined/cloud_download/outline_cloud_download_24.xml" />
<entry key="url" value="file:/$USER_HOME$/AppData/Local/Android/Sdk/icons/material/materialicons/filter_list/baseline_filter_list_24.xml" />
</map>
</option>
</PersistentState>
@ -331,7 +331,7 @@
<option name="values">
<map>
<entry key="color" value="00a6ff" />
<entry key="outputName" value="ic_outline_cloud_download_24" />
<entry key="outputName" value="ic_filter" />
<entry key="sourceFile" value="C:\Users\denis\Desktop\adaptiveproduct_youtube_foreground_color_108 (1).svg" />
</map>
</option>

View file

@ -47,6 +47,7 @@
<entry key="..\:/Users/denis/Documents/GitHub/ytdlnis/app/src/main/res/drawable/ic_down.xml" value="0.109" />
<entry key="..\:/Users/denis/Documents/GitHub/ytdlnis/app/src/main/res/drawable/ic_download.xml" value="0.1275" />
<entry key="..\:/Users/denis/Documents/GitHub/ytdlnis/app/src/main/res/drawable/ic_downloads.xml" value="0.2395" />
<entry key="..\:/Users/denis/Documents/GitHub/ytdlnis/app/src/main/res/drawable/ic_filter.xml" value="0.1965" />
<entry key="..\:/Users/denis/Documents/GitHub/ytdlnis/app/src/main/res/drawable/ic_go_up.xml" value="0.1275" />
<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" />
@ -85,6 +86,7 @@
<entry key="..\:/Users/denis/Documents/GitHub/ytdlnis/app/src/main/res/layout/history_bottom_sheet.xml" value="0.16875" />
<entry key="..\:/Users/denis/Documents/GitHub/ytdlnis/app/src/main/res/layout/history_card.xml" value="0.33" />
<entry key="..\:/Users/denis/Documents/GitHub/ytdlnis/app/src/main/res/layout/history_card_shimmer.xml" value="0.33" />
<entry key="..\:/Users/denis/Documents/GitHub/ytdlnis/app/src/main/res/layout/history_filter_sheet.xml" value="0.33" />
<entry key="..\:/Users/denis/Documents/GitHub/ytdlnis/app/src/main/res/layout/history_no_results.xml" value="0.21" />
<entry key="..\:/Users/denis/Documents/GitHub/ytdlnis/app/src/main/res/layout/home_download_all_bottom_sheet.xml" value="0.33" />
<entry key="..\:/Users/denis/Documents/GitHub/ytdlnis/app/src/main/res/layout/home_video_bottom_sheet.xml" value="0.1703125" />

View file

@ -1,6 +1,7 @@
package com.deniscerri.ytdlnis.adapter;
import android.content.Context;
import android.content.res.ColorStateList;
import android.graphics.Color;
import android.graphics.ColorMatrix;
import android.graphics.ColorMatrixColorFilter;
@ -21,6 +22,7 @@ import androidx.recyclerview.widget.RecyclerView;
import com.deniscerri.ytdlnis.R;
import com.deniscerri.ytdlnis.database.Video;
import com.google.android.material.button.MaterialButton;
import com.squareup.picasso.Picasso;
import java.io.File;
@ -91,21 +93,33 @@ public class HistoryRecyclerViewAdapter extends RecyclerView.Adapter<HistoryRecy
String downloadedTime = video.getDownloadedTime();
datetime.setText(downloadedTime);
// BUTTON ----------------------------------
LinearLayout buttonLayout = card.findViewById(R.id.history_download_button_layout);
Button btn = buttonLayout.findViewById(R.id.history_download_button_type);
if(video.getDownloadedType().equals("audio") || video.getDownloadedType().equals("mp3")){
btn.setBackground(ContextCompat.getDrawable(context, R.drawable.ic_music));
}else{
btn.setBackground(ContextCompat.getDrawable(context, R.drawable.ic_video));
}
File file = new File(video.getDownloadPath());
if(!file.exists()){
//IS IN THE FILE SYSTEM?
String path = video.getDownloadPath();
File file = new File(path);
boolean filePresent = true;
if(!file.exists() && !path.isEmpty()){
filePresent = false;
thumbnail.setColorFilter(new ColorMatrixColorFilter(new ColorMatrix(){{setSaturation(0f);}}));
thumbnail.setAlpha(0.7f);
}
// BUTTON ----------------------------------
LinearLayout buttonLayout = card.findViewById(R.id.history_download_button_layout);
MaterialButton btn = buttonLayout.findViewById(R.id.history_download_button_type);
if(video.getDownloadedType().equals("audio")){
if (filePresent) btn.setIcon(ContextCompat.getDrawable(context, R.drawable.ic_music_downloaded));
else {
btn.setIcon(ContextCompat.getDrawable(context, R.drawable.ic_music));
btn.setBackgroundTintList(ColorStateList.valueOf(Color.parseColor("#707a7e")));
}
}else{
if (filePresent) btn.setIcon(ContextCompat.getDrawable(context, R.drawable.ic_video_downloaded));
else {
btn.setIcon(ContextCompat.getDrawable(context, R.drawable.ic_video));
btn.setBackgroundTintList(ColorStateList.valueOf(Color.parseColor("#707a7e")));
}
}
card.setOnClickListener(view -> onItemClickListener.onCardClick(position));
}

View file

@ -10,17 +10,15 @@ import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ProgressBar;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.core.content.ContextCompat;
import androidx.recyclerview.widget.RecyclerView;
import com.deniscerri.ytdlnis.R;
import com.deniscerri.ytdlnis.database.Video;
import com.google.android.material.button.MaterialButton;
import com.google.android.material.card.MaterialCardView;
import com.google.android.material.progressindicator.LinearProgressIndicator;
import com.squareup.picasso.Picasso;
import java.util.ArrayList;
@ -105,7 +103,7 @@ public class HomeRecyclerViewAdapter extends RecyclerView.Adapter<HomeRecyclerVi
// PROGRESS BAR ----------------------------------------------------
ProgressBar progressBar = card.findViewById(R.id.download_progress);
LinearProgressIndicator progressBar = card.findViewById(R.id.download_progress);
progressBar.setVisibility(View.GONE);
progressBar.setTag(videoID + "##progress");

View file

@ -188,7 +188,7 @@ public class HistoryFragment extends Fragment implements HistoryRecyclerViewAdap
return true;
}
MaterialAlertDialogBuilder delete_dialog = new MaterialAlertDialogBuilder(context);
MaterialAlertDialogBuilder delete_dialog = new MaterialAlertDialogBuilder(fragmentContext);
delete_dialog.setTitle(getString(R.string.confirm_delete_history));
delete_dialog.setMessage(getString(R.string.confirm_delete_history_desc));
delete_dialog.setNegativeButton(getString(R.string.cancel), (dialogInterface, i) -> {
@ -200,8 +200,34 @@ public class HistoryFragment extends Fragment implements HistoryRecyclerViewAdap
no_results.setVisibility(View.VISIBLE);
});
delete_dialog.show();
}else if(itemID == R.id.refresh_history){
initCards();
}else if(itemID == R.id.filter_history){
// bottomSheet = new BottomSheetDialog(fragmentContext);
// bottomSheet.requestWindowFeature(Window.FEATURE_NO_TITLE);
// bottomSheet.setContentView(R.layout.history_bottom_sheet);
// Video video = historyObjects.get(position);
//
// TextView title = bottomSheet.findViewById(R.id.bottom_sheet_title);
// title.setText(video.getTitle());
//
// TextView author = bottomSheet.findViewById(R.id.bottom_sheet_author);
// author.setText(video.getAuthor());
//
// Button link = bottomSheet.findViewById(R.id.bottom_sheet_link);
// String url = video.getURL();
// link.setText(url);
// link.setTag(position);
// link.setOnClickListener(this);
//
// Button remove = bottomSheet.findViewById(R.id.bottomsheet_remove_button);
// remove.setTag(position);
// remove.setOnClickListener(this);
//
// Button openLink = bottomSheet.findViewById(R.id.bottomsheet_open_link_button);
// openLink.setTag(position);
// openLink.setOnClickListener(this);
//
// bottomSheet.show();
// bottomSheet.getWindow().setLayout(ViewGroup.LayoutParams.MATCH_PARENT,ViewGroup.LayoutParams.MATCH_PARENT);
}
return true;
});
@ -224,7 +250,7 @@ public class HistoryFragment extends Fragment implements HistoryRecyclerViewAdap
if(bottomSheet != null) bottomSheet.hide();
Video v = historyObjects.get(position);
MaterialAlertDialogBuilder delete_dialog = new MaterialAlertDialogBuilder(context);
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.setNegativeButton(getString(R.string.cancel), (dialogInterface, i) -> {

View file

@ -40,6 +40,7 @@ import com.google.android.material.bottomsheet.BottomSheetDialog;
import com.google.android.material.button.MaterialButton;
import com.google.android.material.floatingactionbutton.ExtendedFloatingActionButton;
import com.google.android.material.floatingactionbutton.FloatingActionButton;
import com.google.android.material.progressindicator.LinearProgressIndicator;
import com.google.android.material.textfield.TextInputLayout;
import java.io.File;
@ -56,7 +57,7 @@ import java.util.regex.Pattern;
public class HomeFragment extends Fragment implements HomeRecyclerViewAdapter.OnItemClickListener, View.OnClickListener {
private boolean downloading = false;
private View fragmentView;
private ProgressBar progressBar;
private LinearProgressIndicator progressBar;
private String inputQuery;
private RecyclerView recyclerView;
private HomeRecyclerViewAdapter homeRecyclerViewAdapter;
@ -91,8 +92,6 @@ public class HomeFragment extends Fragment implements HomeRecyclerViewAdapter.On
MaterialButton clickedButton = recyclerView.findViewWithTag(id + "##"+type);
progressBar = recyclerView.findViewWithTag(id + "##progress");
progressBar.setVisibility(View.VISIBLE);
progressBar.setIndeterminate(true);
progressBar.setProgress(0);
downloading = true;
topAppBar.getMenu().findItem(R.id.cancel_download).setVisible(true);
@ -111,12 +110,12 @@ public class HomeFragment extends Fragment implements HomeRecyclerViewAdapter.On
activity.runOnUiThread(() -> {
try{
int progress = info.getProgress();
progressBar = fragmentView.findViewWithTag(info.getVideo().getVideoId()+"##progress");
progressBar.setVisibility(View.VISIBLE);
if (progress > 1){
progressBar.setIndeterminate(false);
progressBar.setProgress(info.getProgress());
if (progress > 0) {
progressBar = fragmentView.findViewWithTag(info.getVideo().getVideoId()+"##progress");
progressBar.setVisibility(View.VISIBLE);
progressBar.setProgressCompat(progress, true);
}
}catch(Exception ignored){}
});
}
@ -154,16 +153,20 @@ public class HomeFragment extends Fragment implements HomeRecyclerViewAdapter.On
// MEDIA SCAN
ArrayList<File> files = new ArrayList<>();
String title = downloadInfo.getVideo().getTitle();
String title = downloadInfo.getVideo().getTitle().replaceAll("[^a-zA-Z0-9]","");
String pathTmp = "";
File path = new File(downloadInfo.getDownloadPath());
for( File file : path.listFiles() ){
if(file.isFile() && file.getAbsolutePath().contains(title)) files.add(file);
if(file.isFile()){
pathTmp = file.getAbsolutePath().replaceAll("[^a-zA-Z0-9]","");
if (pathTmp.contains(title)){
files.add(file);
}
}
}
String[] paths = new String[files.size()];
for (int i = 0; i < files.size(); i++) paths[i] = files.get(i).getAbsolutePath();
MediaScannerConnection.scanFile(context, paths, null, null);
addToHistory(item, new Date(), paths);
updateDownloadStatusOnResult(item, type);

View file

@ -1,5 +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:textColorPrimary" android:pathData="M15,16h4v2h-4zM15,8h7v2h-7zM15,12h6v2h-6zM3,18c0,1.1 0.9,2 2,2h6c1.1,0 2,-0.9 2,-2L13,8L3,8v10zM14,5h-3l-1,-1L6,4L5,5L2,5v2h12z"/>
<path android:fillColor="?android:textColorPrimary" android:pathData="M15,16h4v2h-4zM15,8h7v2h-7zM15,12h6v2h-6zM3,18c0,1.1 0.9,2 2,2h6c1.1,0 2,-0.9 2,-2L13,8L3,8v10zM5,10h6v8L5,18v-8zM10,4L6,4L5,5L2,5v2h12L14,5h-3z"/>
</vector>

View 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:textColorPrimary" android:pathData="M10,18h4v-2h-4v2zM3,6v2h18L21,6L3,6zM6,13h12v-2L6,11v2z"/>
</vector>

View file

@ -18,7 +18,7 @@
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:layout_scrollFlags="scroll|enterAlways|snap"
app:title="@string/history"
app:title="@string/downloads"
app:menu="@menu/history_menu"
android:theme="@style/Toolbar"
/>

View file

@ -36,15 +36,13 @@
android:layout_width="match_parent"
android:layout_height="match_parent" />
<ProgressBar
<com.google.android.material.progressindicator.LinearProgressIndicator
android:id="@+id/download_progress"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="bottom"
android:backgroundTintMode="src_in"
android:progress="0"
android:indeterminate="true"
android:alpha="0.7"
style="@style/Widget.AppCompat.ProgressBar.Horizontal"
android:scaleY="100" />
<TextView

View file

@ -10,11 +10,10 @@
app:showAsAction="collapseActionView|always"
app:actionViewClass="androidx.appcompat.widget.SearchView"/>
<item
android:id="@+id/refresh_history"
android:icon="@drawable/ic_refresh"
android:title="@string/refresh_history"
android:id="@+id/filter_history"
android:icon="@drawable/ic_filter"
android:title="@string/filter_history"
app:showAsAction="ifRoom" />
<item

View file

@ -6,7 +6,6 @@
<string name="fshi_historin">Pastro Historinë</string>
<string name="end_of_results"><b>Arrite fundin e rezultateve</b></string>
<string name="download_all">Shkarko të gjitha</string>
<string name="history">Historia</string>
<string name="settings">Cilësime</string>
<string name="home">Kryesore</string>
<string name="directories">Direktoritë</string>
@ -97,4 +96,5 @@
<string name="api_key_summary">Përdor një çelës api për të marrë rezultate më të shpejta nga YouTube</string>
<string name="update_app_summary">Njoftohu kur një përditësim është i vlefshëm</string>
<string name="downloads">Shkarkimet</string>
<string name="filter_history">Filtro Historinë</string>
</resources>

View file

@ -6,7 +6,6 @@
<string name="Trending"><b>Trending</b></string>
<string name="end_of_results"><b>You reached the end of results</b></string>
<string name="download_all">Download All</string>
<string name="history">History</string>
<string name="settings">Settings</string>
<string name="home">Home</string>
<string name="directories">Directories</string>
@ -100,4 +99,5 @@
<string name="api_key_summary">Use an api key to get faster results from YouTube</string>
<string name="update_app_summary">Let you know when updates are available right when you open the application</string>
<string name="downloads">Downloads</string>
<string name="filter_history">Filter History</string>
</resources>