mirror of https://github.com/deniscerri/ytdlnis
added chips to downloads fragment (sort, filter by type and website)
parent
e86b44ee51
commit
42deee3f2e
@ -0,0 +1,504 @@
|
|||||||
|
package com.deniscerri.ytdlnis.page;
|
||||||
|
|
||||||
|
import android.app.Activity;
|
||||||
|
import android.content.ClipData;
|
||||||
|
import android.content.ClipboardManager;
|
||||||
|
import android.content.Context;
|
||||||
|
import android.content.Intent;
|
||||||
|
import android.graphics.drawable.Drawable;
|
||||||
|
import android.net.Uri;
|
||||||
|
import android.os.Bundle;
|
||||||
|
import androidx.appcompat.widget.SearchView;
|
||||||
|
import androidx.core.content.ContextCompat;
|
||||||
|
import androidx.core.content.res.ResourcesCompat;
|
||||||
|
import androidx.fragment.app.Fragment;
|
||||||
|
import androidx.recyclerview.widget.RecyclerView;
|
||||||
|
|
||||||
|
import android.os.Handler;
|
||||||
|
import android.os.Looper;
|
||||||
|
import android.text.InputType;
|
||||||
|
import android.util.Log;
|
||||||
|
import android.view.LayoutInflater;
|
||||||
|
import android.view.MenuItem;
|
||||||
|
import android.view.View;
|
||||||
|
import android.view.ViewGroup;
|
||||||
|
import android.view.Window;
|
||||||
|
import android.widget.Button;
|
||||||
|
import android.widget.LinearLayout;
|
||||||
|
import android.widget.RelativeLayout;
|
||||||
|
import android.widget.TextView;
|
||||||
|
import android.widget.Toast;
|
||||||
|
|
||||||
|
import com.deniscerri.ytdlnis.R;
|
||||||
|
import com.deniscerri.ytdlnis.adapter.DownloadsRecyclerViewAdapter;
|
||||||
|
import com.deniscerri.ytdlnis.database.DBManager;
|
||||||
|
import com.deniscerri.ytdlnis.database.Video;
|
||||||
|
import com.deniscerri.ytdlnis.service.DownloadInfo;
|
||||||
|
import com.deniscerri.ytdlnis.service.IDownloaderListener;
|
||||||
|
import com.facebook.shimmer.ShimmerFrameLayout;
|
||||||
|
import com.google.android.material.appbar.AppBarLayout;
|
||||||
|
import com.google.android.material.appbar.MaterialToolbar;
|
||||||
|
import com.google.android.material.bottomsheet.BottomSheetDialog;
|
||||||
|
import com.google.android.material.chip.Chip;
|
||||||
|
import com.google.android.material.chip.ChipGroup;
|
||||||
|
import com.google.android.material.dialog.MaterialAlertDialogBuilder;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A fragment representing a list of Items.
|
||||||
|
*/
|
||||||
|
public class DownloadsFragment extends Fragment implements DownloadsRecyclerViewAdapter.OnItemClickListener, View.OnClickListener{
|
||||||
|
|
||||||
|
private View fragmentView;
|
||||||
|
private DBManager dbManager;
|
||||||
|
Context context;
|
||||||
|
Activity activity;
|
||||||
|
Context fragmentContext;
|
||||||
|
private LayoutInflater layoutinflater;
|
||||||
|
private ShimmerFrameLayout shimmerCards;
|
||||||
|
private MaterialToolbar topAppBar;
|
||||||
|
private RecyclerView recyclerView;
|
||||||
|
private DownloadsRecyclerViewAdapter downloadsRecyclerViewAdapter;
|
||||||
|
private BottomSheetDialog bottomSheet;
|
||||||
|
private BottomSheetDialog sortSheet;
|
||||||
|
private Handler uiHandler;
|
||||||
|
private RelativeLayout no_results;
|
||||||
|
private LinearLayout selectionChips;
|
||||||
|
private ChipGroup websiteGroup;
|
||||||
|
private ArrayList<Video> downloadsObjects;
|
||||||
|
private String format = "";
|
||||||
|
private String website = "";
|
||||||
|
private String sort = "DESC";
|
||||||
|
private String searchQuery = "";
|
||||||
|
|
||||||
|
private static final String TAG = "downloadsFragment";
|
||||||
|
|
||||||
|
|
||||||
|
public IDownloaderListener listener = new IDownloaderListener() {
|
||||||
|
|
||||||
|
public void onDownloadStart(DownloadInfo downloadInfo) {
|
||||||
|
try{
|
||||||
|
|
||||||
|
}catch(Exception ignored){}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void onDownloadProgress(DownloadInfo info) {
|
||||||
|
activity.runOnUiThread(() -> {
|
||||||
|
try{
|
||||||
|
|
||||||
|
}catch(Exception ignored){}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public void onDownloadError(DownloadInfo info){
|
||||||
|
try{
|
||||||
|
|
||||||
|
}catch(Exception ignored){}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void onDownloadEnd(DownloadInfo downloadInfo) {
|
||||||
|
try{
|
||||||
|
|
||||||
|
}catch(Exception ignored){}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onDownloadCancel(DownloadInfo downloadInfo) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public void onDownloadServiceEnd() {}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
public DownloadsFragment() {
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unused")
|
||||||
|
public static DownloadsFragment newInstance() {
|
||||||
|
DownloadsFragment fragment = new DownloadsFragment();
|
||||||
|
Bundle args = new Bundle();
|
||||||
|
return fragment;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onCreate(Bundle savedInstanceState) {
|
||||||
|
super.onCreate(savedInstanceState);
|
||||||
|
setRetainInstance(true);
|
||||||
|
setHasOptionsMenu(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
||||||
|
Bundle savedInstanceState) {
|
||||||
|
|
||||||
|
fragmentView = inflater.inflate(R.layout.fragment_downloads, container, false);
|
||||||
|
context = fragmentView.getContext().getApplicationContext();
|
||||||
|
activity = getActivity();
|
||||||
|
fragmentContext = fragmentView.getContext();
|
||||||
|
layoutinflater = LayoutInflater.from(context);
|
||||||
|
shimmerCards = fragmentView.findViewById(R.id.shimmer_downloads_framelayout);
|
||||||
|
topAppBar = fragmentView.findViewById(R.id.downloads_toolbar);
|
||||||
|
no_results = fragmentView.findViewById(R.id.downloads_no_results);
|
||||||
|
selectionChips = fragmentView.findViewById(R.id.downloads_selection_chips);
|
||||||
|
websiteGroup = fragmentView.findViewById(R.id.website_chip_group);
|
||||||
|
uiHandler = new Handler(Looper.getMainLooper());
|
||||||
|
|
||||||
|
dbManager = new DBManager(context);
|
||||||
|
downloadsObjects = new ArrayList<>();
|
||||||
|
|
||||||
|
recyclerView = fragmentView.findViewById(R.id.recycler_view_downloads);
|
||||||
|
|
||||||
|
downloadsRecyclerViewAdapter = new DownloadsRecyclerViewAdapter(downloadsObjects, this, context);
|
||||||
|
recyclerView.setAdapter(downloadsRecyclerViewAdapter);
|
||||||
|
recyclerView.setNestedScrollingEnabled(false);
|
||||||
|
|
||||||
|
initMenu();
|
||||||
|
initChips();
|
||||||
|
initCards();
|
||||||
|
return fragmentView;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public void initCards(){
|
||||||
|
shimmerCards.startShimmer();
|
||||||
|
shimmerCards.setVisibility(View.VISIBLE);
|
||||||
|
downloadsRecyclerViewAdapter.clear();
|
||||||
|
no_results.setVisibility(View.GONE);
|
||||||
|
selectionChips.setVisibility(View.VISIBLE);
|
||||||
|
try{
|
||||||
|
Thread thread = new Thread(() -> {
|
||||||
|
downloadsObjects = dbManager.getHistory("", format,website,sort);
|
||||||
|
uiHandler.post(() -> {
|
||||||
|
downloadsRecyclerViewAdapter.setVideoList(downloadsObjects);
|
||||||
|
shimmerCards.stopShimmer();
|
||||||
|
shimmerCards.setVisibility(View.GONE);
|
||||||
|
updateWebsiteChips();
|
||||||
|
});
|
||||||
|
|
||||||
|
if(downloadsObjects.size() == 0){
|
||||||
|
uiHandler.post(() -> {
|
||||||
|
no_results.setVisibility(View.VISIBLE);
|
||||||
|
selectionChips.setVisibility(View.GONE);
|
||||||
|
websiteGroup.removeAllViews();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
thread.start();
|
||||||
|
}catch(Exception e){
|
||||||
|
Log.e(TAG, e.toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public void scrollToTop(){
|
||||||
|
recyclerView.scrollToPosition(0);
|
||||||
|
new Handler(Looper.getMainLooper()).post(() -> ((AppBarLayout) topAppBar.getParent()).setExpanded(true, true));
|
||||||
|
}
|
||||||
|
|
||||||
|
private void initMenu(){
|
||||||
|
MenuItem.OnActionExpandListener onActionExpandListener = new MenuItem.OnActionExpandListener() {
|
||||||
|
@Override
|
||||||
|
public boolean onMenuItemActionExpand(MenuItem menuItem) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean onMenuItemActionCollapse(MenuItem menuItem) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
topAppBar.getMenu().findItem(R.id.search_downloads).setOnActionExpandListener(onActionExpandListener);
|
||||||
|
SearchView searchView = (SearchView) topAppBar.getMenu().findItem(R.id.search_downloads).getActionView();
|
||||||
|
searchView.setInputType(InputType.TYPE_CLASS_TEXT);
|
||||||
|
searchView.setQueryHint(getString(R.string.search_history_hint));
|
||||||
|
|
||||||
|
searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
|
||||||
|
@Override
|
||||||
|
public boolean onQueryTextSubmit(String query) {
|
||||||
|
searchQuery = query;
|
||||||
|
topAppBar.getMenu().findItem(R.id.search_downloads).collapseActionView();
|
||||||
|
downloadsObjects = dbManager.getHistory(query, format,website,sort);
|
||||||
|
downloadsRecyclerViewAdapter.clear();
|
||||||
|
downloadsRecyclerViewAdapter.setVideoList(downloadsObjects);
|
||||||
|
|
||||||
|
if(downloadsObjects.size() == 0) {
|
||||||
|
no_results.setVisibility(View.VISIBLE);
|
||||||
|
selectionChips.setVisibility(View.GONE);
|
||||||
|
websiteGroup.removeAllViews();
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean onQueryTextChange(String newText) {
|
||||||
|
searchQuery = newText;
|
||||||
|
downloadsObjects = dbManager.getHistory(newText, format,website,sort);
|
||||||
|
downloadsRecyclerViewAdapter.clear();
|
||||||
|
downloadsRecyclerViewAdapter.setVideoList(downloadsObjects);
|
||||||
|
|
||||||
|
if (downloadsObjects.size() == 0) {
|
||||||
|
no_results.setVisibility(View.VISIBLE);
|
||||||
|
selectionChips.setVisibility(View.GONE);
|
||||||
|
}else{
|
||||||
|
no_results.setVisibility(View.GONE);
|
||||||
|
selectionChips.setVisibility(View.VISIBLE);
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
topAppBar.setOnClickListener(view -> scrollToTop());
|
||||||
|
|
||||||
|
topAppBar.setOnMenuItemClickListener((MenuItem m) -> {
|
||||||
|
int itemID = m.getItemId();
|
||||||
|
if(itemID == R.id.remove_downloads) {
|
||||||
|
if (downloadsObjects.size() == 0) {
|
||||||
|
Toast.makeText(context, R.string.history_is_empty, Toast.LENGTH_SHORT).show();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
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) -> {
|
||||||
|
dialogInterface.cancel();
|
||||||
|
});
|
||||||
|
delete_dialog.setPositiveButton(getString(R.string.ok), (dialogInterface, i) -> {
|
||||||
|
dbManager.clearHistory();
|
||||||
|
downloadsRecyclerViewAdapter.clear();
|
||||||
|
no_results.setVisibility(View.VISIBLE);
|
||||||
|
selectionChips.setVisibility(View.GONE);
|
||||||
|
websiteGroup.removeAllViews();
|
||||||
|
});
|
||||||
|
delete_dialog.show();
|
||||||
|
}else if(itemID == R.id.remove_deleted_downloads){
|
||||||
|
if (downloadsObjects.size() == 0) {
|
||||||
|
Toast.makeText(context, R.string.history_is_empty, Toast.LENGTH_SHORT).show();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
MaterialAlertDialogBuilder delete_dialog = new MaterialAlertDialogBuilder(fragmentContext);
|
||||||
|
delete_dialog.setTitle(getString(R.string.confirm_delete_history));
|
||||||
|
delete_dialog.setMessage(getString(R.string.confirm_delete_history_deleted_desc));
|
||||||
|
delete_dialog.setNegativeButton(getString(R.string.cancel), (dialogInterface, i) -> {
|
||||||
|
dialogInterface.cancel();
|
||||||
|
});
|
||||||
|
delete_dialog.setPositiveButton(getString(R.string.ok), (dialogInterface, i) -> {
|
||||||
|
dbManager.clearDeletedHistory();
|
||||||
|
initCards();
|
||||||
|
});
|
||||||
|
delete_dialog.show();
|
||||||
|
}else if (itemID == R.id.remove_duplicates){
|
||||||
|
if (downloadsObjects.size() == 0) {
|
||||||
|
Toast.makeText(context, R.string.history_is_empty, Toast.LENGTH_SHORT).show();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
MaterialAlertDialogBuilder delete_dialog = new MaterialAlertDialogBuilder(fragmentContext);
|
||||||
|
delete_dialog.setTitle(getString(R.string.confirm_delete_history));
|
||||||
|
delete_dialog.setMessage(getString(R.string.confirm_delete_history_duplicates_desc));
|
||||||
|
delete_dialog.setNegativeButton(getString(R.string.cancel), (dialogInterface, i) -> {
|
||||||
|
dialogInterface.cancel();
|
||||||
|
});
|
||||||
|
delete_dialog.setPositiveButton(getString(R.string.ok), (dialogInterface, i) -> {
|
||||||
|
dbManager.clearDuplicateHistory();
|
||||||
|
initCards();
|
||||||
|
});
|
||||||
|
delete_dialog.show();
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
});
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private void initChips(){
|
||||||
|
//sort
|
||||||
|
Chip sortChip = fragmentView.findViewById(R.id.sort_chip);
|
||||||
|
sortChip.setOnClickListener(view -> {
|
||||||
|
sortSheet = new BottomSheetDialog(fragmentContext);
|
||||||
|
sortSheet.requestWindowFeature(Window.FEATURE_NO_TITLE);
|
||||||
|
sortSheet.setContentView(R.layout.downloads_sort_sheet);
|
||||||
|
|
||||||
|
TextView newest = sortSheet.findViewById(R.id.newest);
|
||||||
|
TextView oldest = sortSheet.findViewById(R.id.oldest);
|
||||||
|
|
||||||
|
newest.setOnClickListener(view1 -> {
|
||||||
|
sort = "DESC";
|
||||||
|
downloadsObjects = dbManager.getHistory(searchQuery, format,website,sort);
|
||||||
|
downloadsRecyclerViewAdapter.clear();
|
||||||
|
downloadsRecyclerViewAdapter.setVideoList(downloadsObjects);
|
||||||
|
sortSheet.cancel();
|
||||||
|
});
|
||||||
|
|
||||||
|
oldest.setOnClickListener(view1 -> {
|
||||||
|
sort = "ASC";
|
||||||
|
downloadsObjects = dbManager.getHistory(searchQuery, format,website,sort);
|
||||||
|
downloadsRecyclerViewAdapter.clear();
|
||||||
|
downloadsRecyclerViewAdapter.setVideoList(downloadsObjects);
|
||||||
|
sortSheet.cancel();
|
||||||
|
});
|
||||||
|
|
||||||
|
TextView cancel = sortSheet.findViewById(R.id.cancel);
|
||||||
|
cancel.setOnClickListener(view1 -> {
|
||||||
|
sortSheet.cancel();
|
||||||
|
});
|
||||||
|
|
||||||
|
sortSheet.show();
|
||||||
|
sortSheet.getWindow().setLayout(ViewGroup.LayoutParams.MATCH_PARENT,ViewGroup.LayoutParams.MATCH_PARENT);
|
||||||
|
});
|
||||||
|
|
||||||
|
//format
|
||||||
|
Chip audio = fragmentView.findViewById(R.id.audio_chip);
|
||||||
|
audio.setOnClickListener(view -> {
|
||||||
|
if (audio.isChecked()) {
|
||||||
|
format = "audio";
|
||||||
|
downloadsObjects = dbManager.getHistory(searchQuery,format,website,sort);
|
||||||
|
audio.setChecked(true);
|
||||||
|
}else {
|
||||||
|
format = "";
|
||||||
|
downloadsObjects = dbManager.getHistory(searchQuery,format,website,sort);
|
||||||
|
audio.setChecked(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
downloadsRecyclerViewAdapter.clear();
|
||||||
|
downloadsRecyclerViewAdapter.setVideoList(downloadsObjects);
|
||||||
|
});
|
||||||
|
|
||||||
|
Chip video = fragmentView.findViewById(R.id.video_chip);
|
||||||
|
video.setOnClickListener(view -> {
|
||||||
|
if (video.isChecked()) {
|
||||||
|
format = "video";
|
||||||
|
downloadsObjects = dbManager.getHistory(searchQuery,format,website,sort);
|
||||||
|
video.setChecked(true);
|
||||||
|
}else {
|
||||||
|
format = "";
|
||||||
|
downloadsObjects = dbManager.getHistory(searchQuery,format,website,sort);
|
||||||
|
video.setChecked(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
downloadsRecyclerViewAdapter.clear();
|
||||||
|
downloadsRecyclerViewAdapter.setVideoList(downloadsObjects);
|
||||||
|
});
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private void updateWebsiteChips(){
|
||||||
|
websiteGroup.removeAllViews();
|
||||||
|
|
||||||
|
ArrayList<String> websites = downloadsRecyclerViewAdapter.getWebsites();
|
||||||
|
for (int i = 0; i < websites.size(); i++){
|
||||||
|
String w = websites.get(i);
|
||||||
|
Chip tmp = (Chip) layoutinflater.inflate(R.layout.filter_chip, websiteGroup, false);
|
||||||
|
tmp.setText(w);
|
||||||
|
tmp.setId(i);
|
||||||
|
tmp.setOnClickListener(view -> {
|
||||||
|
if (tmp.isChecked()){
|
||||||
|
website = (String) tmp.getText();
|
||||||
|
downloadsObjects = dbManager.getHistory(searchQuery,format,website,sort);
|
||||||
|
websiteGroup.check(view.getId());
|
||||||
|
}else{
|
||||||
|
website = "";
|
||||||
|
downloadsObjects = dbManager.getHistory(searchQuery,format,website,sort);
|
||||||
|
websiteGroup.clearCheck();
|
||||||
|
}
|
||||||
|
downloadsRecyclerViewAdapter.clear();
|
||||||
|
downloadsRecyclerViewAdapter.setVideoList(downloadsObjects);
|
||||||
|
});
|
||||||
|
websiteGroup.addView(tmp);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onClick(View v) {
|
||||||
|
int id = v.getId();
|
||||||
|
if(id == R.id.bottomsheet_remove_button){
|
||||||
|
removedownloadsItem((Integer) v.getTag());
|
||||||
|
}else if(id == R.id.bottom_sheet_link){
|
||||||
|
copyLinkToClipBoard((Integer) v.getTag());
|
||||||
|
}else if(id == R.id.bottomsheet_open_link_button){
|
||||||
|
openLinkIntent((Integer) v.getTag());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void removedownloadsItem(int position){
|
||||||
|
if(bottomSheet != null) bottomSheet.hide();
|
||||||
|
|
||||||
|
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.setNegativeButton(getString(R.string.cancel), (dialogInterface, i) -> {
|
||||||
|
dialogInterface.cancel();
|
||||||
|
});
|
||||||
|
delete_dialog.setPositiveButton(getString(R.string.ok), (dialogInterface, i) -> {
|
||||||
|
downloadsObjects.remove(position);
|
||||||
|
downloadsRecyclerViewAdapter.notifyItemRemoved(position);
|
||||||
|
downloadsRecyclerViewAdapter.setWebsiteList();
|
||||||
|
updateWebsiteChips();
|
||||||
|
dbManager.clearHistoryItem(v);
|
||||||
|
|
||||||
|
if(downloadsObjects.size() == 0){
|
||||||
|
uiHandler.post(() -> {
|
||||||
|
no_results.setVisibility(View.VISIBLE);
|
||||||
|
selectionChips.setVisibility(View.GONE);
|
||||||
|
websiteGroup.removeAllViews();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
delete_dialog.show();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void copyLinkToClipBoard(int position){
|
||||||
|
String url = downloadsObjects.get(position).getURL();
|
||||||
|
ClipboardManager clipboard = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE);
|
||||||
|
ClipData clip = ClipData.newPlainText(getString(R.string.url), url);
|
||||||
|
clipboard.setPrimaryClip(clip);
|
||||||
|
if(bottomSheet != null) bottomSheet.hide();
|
||||||
|
Toast.makeText(context, getString(R.string.link_copied_to_clipboard), Toast.LENGTH_SHORT).show();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void openLinkIntent(int position){
|
||||||
|
String url =downloadsObjects.get(position).getURL();
|
||||||
|
Intent i = new Intent(Intent.ACTION_VIEW);
|
||||||
|
i.setData(Uri.parse(url));
|
||||||
|
if(bottomSheet != null) bottomSheet.hide();
|
||||||
|
startActivity(i);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onCardClick(int position) {
|
||||||
|
bottomSheet = new BottomSheetDialog(fragmentContext);
|
||||||
|
bottomSheet.requestWindowFeature(Window.FEATURE_NO_TITLE);
|
||||||
|
bottomSheet.setContentView(R.layout.downloads_bottom_sheet);
|
||||||
|
Video video = downloadsObjects.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);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@ -1,369 +0,0 @@
|
|||||||
package com.deniscerri.ytdlnis.page;
|
|
||||||
|
|
||||||
import android.app.Activity;
|
|
||||||
import android.content.ClipData;
|
|
||||||
import android.content.ClipboardManager;
|
|
||||||
import android.content.Context;
|
|
||||||
import android.content.Intent;
|
|
||||||
import android.media.MediaScannerConnection;
|
|
||||||
import android.net.Uri;
|
|
||||||
import android.os.Bundle;
|
|
||||||
import androidx.appcompat.widget.SearchView;
|
|
||||||
import androidx.core.content.ContextCompat;
|
|
||||||
import androidx.fragment.app.Fragment;
|
|
||||||
import androidx.recyclerview.widget.RecyclerView;
|
|
||||||
|
|
||||||
import android.os.Handler;
|
|
||||||
import android.os.Looper;
|
|
||||||
import android.text.InputType;
|
|
||||||
import android.util.Log;
|
|
||||||
import android.view.LayoutInflater;
|
|
||||||
import android.view.MenuItem;
|
|
||||||
import android.view.View;
|
|
||||||
import android.view.ViewGroup;
|
|
||||||
import android.view.Window;
|
|
||||||
import android.widget.Button;
|
|
||||||
import android.widget.RelativeLayout;
|
|
||||||
import android.widget.TextView;
|
|
||||||
import android.widget.Toast;
|
|
||||||
|
|
||||||
import com.deniscerri.ytdlnis.R;
|
|
||||||
import com.deniscerri.ytdlnis.adapter.HistoryRecyclerViewAdapter;
|
|
||||||
import com.deniscerri.ytdlnis.database.DBManager;
|
|
||||||
import com.deniscerri.ytdlnis.database.Video;
|
|
||||||
import com.deniscerri.ytdlnis.service.DownloadInfo;
|
|
||||||
import com.deniscerri.ytdlnis.service.IDownloaderListener;
|
|
||||||
import com.facebook.shimmer.ShimmerFrameLayout;
|
|
||||||
import com.google.android.material.appbar.AppBarLayout;
|
|
||||||
import com.google.android.material.appbar.MaterialToolbar;
|
|
||||||
import com.google.android.material.bottomsheet.BottomSheetDialog;
|
|
||||||
import com.google.android.material.button.MaterialButton;
|
|
||||||
import com.google.android.material.dialog.MaterialAlertDialogBuilder;
|
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Date;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* A fragment representing a list of Items.
|
|
||||||
*/
|
|
||||||
public class HistoryFragment extends Fragment implements HistoryRecyclerViewAdapter.OnItemClickListener, View.OnClickListener{
|
|
||||||
|
|
||||||
private View fragmentView;
|
|
||||||
private DBManager dbManager;
|
|
||||||
Context context;
|
|
||||||
Activity activity;
|
|
||||||
Context fragmentContext;
|
|
||||||
private LayoutInflater layoutinflater;
|
|
||||||
private ShimmerFrameLayout shimmerCards;
|
|
||||||
private MaterialToolbar topAppBar;
|
|
||||||
private RecyclerView recyclerView;
|
|
||||||
private HistoryRecyclerViewAdapter historyRecyclerViewAdapter;
|
|
||||||
private BottomSheetDialog bottomSheet;
|
|
||||||
private Handler uiHandler;
|
|
||||||
private RelativeLayout no_results;
|
|
||||||
private ArrayList<Video> historyObjects;
|
|
||||||
private static final String TAG = "HistoryFragment";
|
|
||||||
|
|
||||||
|
|
||||||
public IDownloaderListener listener = new IDownloaderListener() {
|
|
||||||
|
|
||||||
public void onDownloadStart(DownloadInfo downloadInfo) {
|
|
||||||
try{
|
|
||||||
|
|
||||||
}catch(Exception ignored){}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void onDownloadProgress(DownloadInfo info) {
|
|
||||||
activity.runOnUiThread(() -> {
|
|
||||||
try{
|
|
||||||
|
|
||||||
}catch(Exception ignored){}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
public void onDownloadError(DownloadInfo info){
|
|
||||||
try{
|
|
||||||
|
|
||||||
}catch(Exception ignored){}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void onDownloadEnd(DownloadInfo downloadInfo) {
|
|
||||||
try{
|
|
||||||
|
|
||||||
}catch(Exception ignored){}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onDownloadCancel(DownloadInfo downloadInfo) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public void onDownloadServiceEnd() {}
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
public HistoryFragment() {
|
|
||||||
}
|
|
||||||
|
|
||||||
@SuppressWarnings("unused")
|
|
||||||
public static HistoryFragment newInstance() {
|
|
||||||
HistoryFragment fragment = new HistoryFragment();
|
|
||||||
Bundle args = new Bundle();
|
|
||||||
return fragment;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onCreate(Bundle savedInstanceState) {
|
|
||||||
super.onCreate(savedInstanceState);
|
|
||||||
setRetainInstance(true);
|
|
||||||
setHasOptionsMenu(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
|
||||||
Bundle savedInstanceState) {
|
|
||||||
|
|
||||||
fragmentView = inflater.inflate(R.layout.fragment_history, container, false);
|
|
||||||
context = fragmentView.getContext().getApplicationContext();
|
|
||||||
activity = getActivity();
|
|
||||||
fragmentContext = fragmentView.getContext();
|
|
||||||
layoutinflater = LayoutInflater.from(context);
|
|
||||||
shimmerCards = fragmentView.findViewById(R.id.shimmer_history_framelayout);
|
|
||||||
topAppBar = fragmentView.findViewById(R.id.history_toolbar);
|
|
||||||
no_results = fragmentView.findViewById(R.id.history_no_results);
|
|
||||||
uiHandler = new Handler(Looper.getMainLooper());
|
|
||||||
|
|
||||||
dbManager = new DBManager(context);
|
|
||||||
historyObjects = new ArrayList<>();
|
|
||||||
|
|
||||||
recyclerView = fragmentView.findViewById(R.id.recycler_view_history);
|
|
||||||
|
|
||||||
historyRecyclerViewAdapter = new HistoryRecyclerViewAdapter(historyObjects, this, context);
|
|
||||||
recyclerView.setAdapter(historyRecyclerViewAdapter);
|
|
||||||
recyclerView.setNestedScrollingEnabled(false);
|
|
||||||
|
|
||||||
initMenu();
|
|
||||||
initCards();
|
|
||||||
return fragmentView;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public void initCards(){
|
|
||||||
shimmerCards.startShimmer();
|
|
||||||
shimmerCards.setVisibility(View.VISIBLE);
|
|
||||||
historyRecyclerViewAdapter.clear();
|
|
||||||
no_results.setVisibility(View.GONE);
|
|
||||||
try{
|
|
||||||
Thread thread = new Thread(() -> {
|
|
||||||
historyObjects = dbManager.getHistory("");
|
|
||||||
uiHandler.post(() -> {
|
|
||||||
historyRecyclerViewAdapter.setVideoList(historyObjects);
|
|
||||||
shimmerCards.stopShimmer();
|
|
||||||
shimmerCards.setVisibility(View.GONE);
|
|
||||||
});
|
|
||||||
|
|
||||||
if(historyObjects.size() == 0){
|
|
||||||
uiHandler.post(() -> no_results.setVisibility(View.VISIBLE));
|
|
||||||
}
|
|
||||||
});
|
|
||||||
thread.start();
|
|
||||||
}catch(Exception e){
|
|
||||||
Log.e(TAG, e.toString());
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public void scrollToTop(){
|
|
||||||
recyclerView.scrollToPosition(0);
|
|
||||||
new Handler(Looper.getMainLooper()).post(() -> ((AppBarLayout) topAppBar.getParent()).setExpanded(true, true));
|
|
||||||
}
|
|
||||||
|
|
||||||
private void initMenu(){
|
|
||||||
MenuItem.OnActionExpandListener onActionExpandListener = new MenuItem.OnActionExpandListener() {
|
|
||||||
@Override
|
|
||||||
public boolean onMenuItemActionExpand(MenuItem menuItem) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean onMenuItemActionCollapse(MenuItem menuItem) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
topAppBar.getMenu().findItem(R.id.search_history).setOnActionExpandListener(onActionExpandListener);
|
|
||||||
SearchView searchView = (SearchView) topAppBar.getMenu().findItem(R.id.search_history).getActionView();
|
|
||||||
searchView.setInputType(InputType.TYPE_CLASS_TEXT);
|
|
||||||
searchView.setQueryHint(getString(R.string.search_history_hint));
|
|
||||||
|
|
||||||
searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
|
|
||||||
@Override
|
|
||||||
public boolean onQueryTextSubmit(String query) {
|
|
||||||
topAppBar.getMenu().findItem(R.id.search_history).collapseActionView();
|
|
||||||
historyObjects = dbManager.getHistory(query);
|
|
||||||
historyRecyclerViewAdapter.clear();
|
|
||||||
historyRecyclerViewAdapter.setVideoList(historyObjects);
|
|
||||||
|
|
||||||
if(historyObjects.size() == 0) no_results.setVisibility(View.VISIBLE);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean onQueryTextChange(String newText) {
|
|
||||||
|
|
||||||
historyObjects = dbManager.getHistory(newText);
|
|
||||||
historyRecyclerViewAdapter.clear();
|
|
||||||
historyRecyclerViewAdapter.setVideoList(historyObjects);
|
|
||||||
|
|
||||||
if (historyObjects.size() == 0) {
|
|
||||||
no_results.setVisibility(View.VISIBLE);
|
|
||||||
}else{
|
|
||||||
no_results.setVisibility(View.GONE);
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
topAppBar.setOnClickListener(view -> scrollToTop());
|
|
||||||
|
|
||||||
topAppBar.setOnMenuItemClickListener((MenuItem m) -> {
|
|
||||||
int itemID = m.getItemId();
|
|
||||||
if(itemID == R.id.delete_history){
|
|
||||||
if(historyObjects.size() == 0){
|
|
||||||
Toast.makeText(context, R.string.history_is_empty, Toast.LENGTH_SHORT).show();
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
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) -> {
|
|
||||||
dialogInterface.cancel();
|
|
||||||
});
|
|
||||||
delete_dialog.setPositiveButton(getString(R.string.ok), (dialogInterface, i) -> {
|
|
||||||
dbManager.clearHistory();
|
|
||||||
historyRecyclerViewAdapter.clear();
|
|
||||||
no_results.setVisibility(View.VISIBLE);
|
|
||||||
});
|
|
||||||
delete_dialog.show();
|
|
||||||
}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;
|
|
||||||
});
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onClick(View v) {
|
|
||||||
int id = v.getId();
|
|
||||||
if(id == R.id.bottomsheet_remove_button){
|
|
||||||
removeHistoryItem((Integer) v.getTag());
|
|
||||||
}else if(id == R.id.bottom_sheet_link){
|
|
||||||
copyLinkToClipBoard((Integer) v.getTag());
|
|
||||||
}else if(id == R.id.bottomsheet_open_link_button){
|
|
||||||
openLinkIntent((Integer) v.getTag());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void removeHistoryItem(int position){
|
|
||||||
if(bottomSheet != null) bottomSheet.hide();
|
|
||||||
|
|
||||||
Video v = historyObjects.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.setNegativeButton(getString(R.string.cancel), (dialogInterface, i) -> {
|
|
||||||
dialogInterface.cancel();
|
|
||||||
});
|
|
||||||
delete_dialog.setPositiveButton(getString(R.string.ok), (dialogInterface, i) -> {
|
|
||||||
historyObjects.remove(position);
|
|
||||||
historyRecyclerViewAdapter.notifyItemRemoved(position);
|
|
||||||
historyRecyclerViewAdapter.notifyItemRangeChanged(position, historyObjects.size());
|
|
||||||
dbManager.clearHistoryItem(v);
|
|
||||||
|
|
||||||
if(historyObjects.size() == 0){
|
|
||||||
uiHandler.post(() -> no_results.setVisibility(View.VISIBLE));
|
|
||||||
}
|
|
||||||
});
|
|
||||||
delete_dialog.show();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void copyLinkToClipBoard(int position){
|
|
||||||
String url = historyObjects.get(position).getURL();
|
|
||||||
ClipboardManager clipboard = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE);
|
|
||||||
ClipData clip = ClipData.newPlainText(getString(R.string.url), url);
|
|
||||||
clipboard.setPrimaryClip(clip);
|
|
||||||
if(bottomSheet != null) bottomSheet.hide();
|
|
||||||
Toast.makeText(context, getString(R.string.link_copied_to_clipboard), Toast.LENGTH_SHORT).show();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void openLinkIntent(int position){
|
|
||||||
String url =historyObjects.get(position).getURL();
|
|
||||||
Intent i = new Intent(Intent.ACTION_VIEW);
|
|
||||||
i.setData(Uri.parse(url));
|
|
||||||
if(bottomSheet != null) bottomSheet.hide();
|
|
||||||
startActivity(i);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onCardClick(int position) {
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
@ -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="?attr/colorAccent" android:pathData="M9,16.17L4.83,12l-1.42,1.41L9,19 21,7l-1.41,-1.41z"/>
|
||||||
|
</vector>
|
||||||
@ -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="M4,12l1.41,1.41L11,7.83V20h2V7.83l5.58,5.59L20,12l-8,-8 -8,8z"/>
|
||||||
|
</vector>
|
||||||
@ -1,5 +1,5 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<FrameLayout android:id="@+id/history_element_bottom_sheet"
|
<FrameLayout android:id="@+id/downloads_element_bottom_sheet"
|
||||||
style="@style/Widget.Material3.BottomSheet"
|
style="@style/Widget.Material3.BottomSheet"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
@ -1,5 +1,5 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<FrameLayout android:id="@+id/history_element_bottom_sheet"
|
<FrameLayout android:id="@+id/downloads_element_bottom_sheet"
|
||||||
style="@style/Widget.Material3.BottomSheet"
|
style="@style/Widget.Material3.BottomSheet"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
@ -1,6 +1,6 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<RelativeLayout
|
<RelativeLayout
|
||||||
android:id="@+id/history_no_results"
|
android:id="@+id/downloads_no_results"
|
||||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
xmlns:tools="http://schemas.android.com/tools"
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
@ -0,0 +1,52 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<FrameLayout android:id="@+id/downloads_element_bottom_sheet"
|
||||||
|
style="@style/Widget.Material3.BottomSheet"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
app:layout_behavior="com.google.android.material.bottomsheet.BottomSheetBehavior"
|
||||||
|
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:app="http://schemas.android.com/apk/res-auto">
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_margin="10dp"
|
||||||
|
android:padding="10dp"
|
||||||
|
android:orientation="vertical">
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/newest"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:textSize="15sp"
|
||||||
|
android:text="@string/newest_first"
|
||||||
|
android:drawablePadding="20dp"
|
||||||
|
android:paddingBottom="20dp"
|
||||||
|
app:drawableLeftCompat="@drawable/ic_up" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/oldest"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:textSize="15sp"
|
||||||
|
android:text="@string/oldest_first"
|
||||||
|
android:drawablePadding="20dp"
|
||||||
|
android:paddingBottom="20dp"
|
||||||
|
app:drawableLeftCompat="@drawable/ic_down" />
|
||||||
|
|
||||||
|
<View style="@style/Divider.Horizontal"/>
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/cancel"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:textSize="15sp"
|
||||||
|
app:icon="@drawable/ic_link"
|
||||||
|
android:text="@string/cancel"
|
||||||
|
android:drawablePadding="20dp"
|
||||||
|
app:drawableLeftCompat="@drawable/ic_cancel" />
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
|
|
||||||
|
</FrameLayout>
|
||||||
@ -1,16 +1,8 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
<com.google.android.material.chip.Chip xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
xmlns:tools="http://schemas.android.com/tools"
|
android:id="@+id/website_chip"
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="match_parent">
|
|
||||||
|
|
||||||
<com.google.android.material.chip.Chip
|
|
||||||
style="@style/Widget.Material3.Chip.Filter"
|
style="@style/Widget.Material3.Chip.Filter"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:textSize="15sp"
|
|
||||||
android:checked="true"
|
|
||||||
android:textColor="?attr/colorOnSurface"
|
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
tools:ignore="MissingConstraints" />
|
android:theme="@style/Theme.Material3.DayNight"
|
||||||
|
/>
|
||||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
|
||||||
|
|||||||
@ -0,0 +1,165 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<androidx.coordinatorlayout.widget.CoordinatorLayout
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||||
|
android:id="@+id/downloadscoordinator"
|
||||||
|
xmlns:android="http://schemas.android.com/apk/res/android">
|
||||||
|
|
||||||
|
<com.google.android.material.appbar.AppBarLayout
|
||||||
|
android:id="@+id/downloads_appbarlayout"
|
||||||
|
app:liftOnScroll="false"
|
||||||
|
android:background="@android:color/transparent"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content">
|
||||||
|
|
||||||
|
<com.google.android.material.appbar.MaterialToolbar
|
||||||
|
android:id="@+id/downloads_toolbar"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="?attr/actionBarSize"
|
||||||
|
app:layout_scrollFlags="scroll|enterAlways|snap"
|
||||||
|
app:title="@string/downloads"
|
||||||
|
app:menu="@menu/downloads_menu"
|
||||||
|
android:theme="@style/Toolbar"
|
||||||
|
/>
|
||||||
|
|
||||||
|
</com.google.android.material.appbar.AppBarLayout>
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:orientation="vertical"
|
||||||
|
android:layout_margin="10dp"
|
||||||
|
app:layout_behavior="com.google.android.material.appbar.AppBarLayout$ScrollingViewBehavior">
|
||||||
|
|
||||||
|
<HorizontalScrollView
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:scrollbars="none"
|
||||||
|
android:layout_height="wrap_content">
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:id="@+id/downloads_selection_chips"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content">
|
||||||
|
|
||||||
|
<com.google.android.material.chip.ChipGroup
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content">
|
||||||
|
|
||||||
|
<com.google.android.material.chip.Chip
|
||||||
|
android:id="@+id/sort_chip"
|
||||||
|
style="@style/Widget.Material3.Chip.Assist"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
app:chipIcon="@drawable/ic_down"
|
||||||
|
android:text="@string/sort_by"/>
|
||||||
|
|
||||||
|
</com.google.android.material.chip.ChipGroup>
|
||||||
|
|
||||||
|
<View style="@style/Divider.Vertical"/>
|
||||||
|
|
||||||
|
<com.google.android.material.chip.ChipGroup
|
||||||
|
android:id="@+id/format_chip_group"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
app:selectionRequired="false"
|
||||||
|
app:singleSelection="true"
|
||||||
|
android:layout_height="wrap_content">
|
||||||
|
|
||||||
|
<com.google.android.material.chip.Chip
|
||||||
|
android:id="@+id/audio_chip"
|
||||||
|
style="@style/Widget.Material3.Chip.Filter"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="@string/audio"/>
|
||||||
|
|
||||||
|
<com.google.android.material.chip.Chip
|
||||||
|
android:id="@+id/video_chip"
|
||||||
|
style="@style/Widget.Material3.Chip.Filter"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="@string/video"/>
|
||||||
|
|
||||||
|
</com.google.android.material.chip.ChipGroup>
|
||||||
|
|
||||||
|
<View style="@style/Divider.Vertical"/>
|
||||||
|
|
||||||
|
<com.google.android.material.chip.ChipGroup
|
||||||
|
android:id="@+id/website_chip_group"
|
||||||
|
app:selectionRequired="false"
|
||||||
|
app:singleSelection="true"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content">
|
||||||
|
|
||||||
|
</com.google.android.material.chip.ChipGroup>
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
|
</HorizontalScrollView>
|
||||||
|
|
||||||
|
<androidx.recyclerview.widget.RecyclerView
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:id="@+id/recycler_view_downloads"
|
||||||
|
android:orientation="vertical"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:scrollbars="vertical"
|
||||||
|
android:nestedScrollingEnabled="false"
|
||||||
|
android:clipToPadding="false"
|
||||||
|
android:paddingBottom="150dp"
|
||||||
|
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
|
||||||
|
>
|
||||||
|
|
||||||
|
</androidx.recyclerview.widget.RecyclerView>
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
|
|
||||||
|
<include layout="@layout/downloads_no_results"
|
||||||
|
android:visibility="gone" />
|
||||||
|
|
||||||
|
<com.facebook.shimmer.ShimmerFrameLayout
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:visibility="gone"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:layout_marginTop="?attr/actionBarSize"
|
||||||
|
android:id="@+id/shimmer_downloads_framelayout"
|
||||||
|
android:orientation="vertical">
|
||||||
|
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:id="@+id/shimmer_downloads_linear_layout"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_margin="10dp"
|
||||||
|
android:orientation="vertical">
|
||||||
|
|
||||||
|
<include layout="@layout/downloads_card_shimmer" />
|
||||||
|
|
||||||
|
<include layout="@layout/downloads_card_shimmer" />
|
||||||
|
|
||||||
|
<include layout="@layout/downloads_card_shimmer" />
|
||||||
|
|
||||||
|
<include layout="@layout/downloads_card_shimmer" />
|
||||||
|
|
||||||
|
<include layout="@layout/downloads_card_shimmer" />
|
||||||
|
|
||||||
|
<include layout="@layout/downloads_card_shimmer" />
|
||||||
|
|
||||||
|
<include layout="@layout/downloads_card_shimmer" />
|
||||||
|
|
||||||
|
<include layout="@layout/downloads_card_shimmer" />
|
||||||
|
|
||||||
|
<include layout="@layout/downloads_card_shimmer" />
|
||||||
|
|
||||||
|
<include layout="@layout/downloads_card_shimmer" />
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
|
</com.facebook.shimmer.ShimmerFrameLayout>
|
||||||
|
|
||||||
|
<include layout="@layout/downloads_bottom_sheet"
|
||||||
|
android:visibility="gone" />
|
||||||
|
|
||||||
|
</androidx.coordinatorlayout.widget.CoordinatorLayout>
|
||||||
@ -1,92 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
|
||||||
<androidx.coordinatorlayout.widget.CoordinatorLayout
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="match_parent"
|
|
||||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
|
||||||
android:id="@+id/historycoordinator"
|
|
||||||
xmlns:android="http://schemas.android.com/apk/res/android">
|
|
||||||
|
|
||||||
<com.google.android.material.appbar.AppBarLayout
|
|
||||||
android:id="@+id/history_appbarlayout"
|
|
||||||
app:liftOnScroll="false"
|
|
||||||
android:background="@android:color/transparent"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="wrap_content">
|
|
||||||
|
|
||||||
<com.google.android.material.appbar.MaterialToolbar
|
|
||||||
android:id="@+id/history_toolbar"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="?attr/actionBarSize"
|
|
||||||
app:layout_scrollFlags="scroll|enterAlways|snap"
|
|
||||||
app:title="@string/downloads"
|
|
||||||
app:menu="@menu/history_menu"
|
|
||||||
android:theme="@style/Toolbar"
|
|
||||||
/>
|
|
||||||
|
|
||||||
</com.google.android.material.appbar.AppBarLayout>
|
|
||||||
|
|
||||||
<androidx.recyclerview.widget.RecyclerView
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:id="@+id/recycler_view_history"
|
|
||||||
android:orientation="vertical"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:scrollbars="vertical"
|
|
||||||
android:nestedScrollingEnabled="false"
|
|
||||||
android:layout_margin="10dp"
|
|
||||||
android:clipToPadding="false"
|
|
||||||
android:paddingBottom="150dp"
|
|
||||||
app:layout_behavior="com.google.android.material.appbar.AppBarLayout$ScrollingViewBehavior"
|
|
||||||
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
|
|
||||||
>
|
|
||||||
|
|
||||||
</androidx.recyclerview.widget.RecyclerView>
|
|
||||||
|
|
||||||
<include layout="@layout/history_no_results"
|
|
||||||
android:visibility="gone" />
|
|
||||||
|
|
||||||
<com.facebook.shimmer.ShimmerFrameLayout
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="match_parent"
|
|
||||||
android:layout_marginTop="?attr/actionBarSize"
|
|
||||||
android:id="@+id/shimmer_history_framelayout"
|
|
||||||
android:orientation="vertical">
|
|
||||||
|
|
||||||
|
|
||||||
<LinearLayout
|
|
||||||
android:id="@+id/shimmer_history_linear_layout"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:layout_margin="10dp"
|
|
||||||
android:orientation="vertical">
|
|
||||||
|
|
||||||
<include layout="@layout/history_card_shimmer" />
|
|
||||||
|
|
||||||
<include layout="@layout/history_card_shimmer" />
|
|
||||||
|
|
||||||
<include layout="@layout/history_card_shimmer" />
|
|
||||||
|
|
||||||
<include layout="@layout/history_card_shimmer" />
|
|
||||||
|
|
||||||
<include layout="@layout/history_card_shimmer" />
|
|
||||||
|
|
||||||
<include layout="@layout/history_card_shimmer" />
|
|
||||||
|
|
||||||
<include layout="@layout/history_card_shimmer" />
|
|
||||||
|
|
||||||
<include layout="@layout/history_card_shimmer" />
|
|
||||||
|
|
||||||
<include layout="@layout/history_card_shimmer" />
|
|
||||||
|
|
||||||
<include layout="@layout/history_card_shimmer" />
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
</LinearLayout>
|
|
||||||
|
|
||||||
</com.facebook.shimmer.ShimmerFrameLayout>
|
|
||||||
|
|
||||||
<include layout="@layout/history_bottom_sheet"
|
|
||||||
android:visibility="gone" />
|
|
||||||
|
|
||||||
</androidx.coordinatorlayout.widget.CoordinatorLayout>
|
|
||||||
@ -0,0 +1,32 @@
|
|||||||
|
<menu xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||||
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
|
tools:context=".MainActivity" >
|
||||||
|
|
||||||
|
<item
|
||||||
|
android:id="@+id/search_downloads"
|
||||||
|
android:title="@string/search"
|
||||||
|
android:icon="@drawable/ic_search"
|
||||||
|
app:showAsAction="collapseActionView|always"
|
||||||
|
app:actionViewClass="androidx.appcompat.widget.SearchView"/>
|
||||||
|
|
||||||
|
<item
|
||||||
|
android:id="@+id/remove_downloads"
|
||||||
|
android:icon="@drawable/ic_delete_all"
|
||||||
|
android:title="@string/remove_all"
|
||||||
|
app:showAsAction="never" />
|
||||||
|
|
||||||
|
<item
|
||||||
|
android:id="@+id/remove_deleted_downloads"
|
||||||
|
android:icon="@drawable/ic_delete_all"
|
||||||
|
android:title="@string/remove_deleted"
|
||||||
|
app:showAsAction="never" />
|
||||||
|
|
||||||
|
<item
|
||||||
|
android:id="@+id/remove_duplicates"
|
||||||
|
android:icon="@drawable/ic_delete_all"
|
||||||
|
android:title="@string/remove_duplicates"
|
||||||
|
app:showAsAction="never" />
|
||||||
|
|
||||||
|
</menu>
|
||||||
|
|
||||||
@ -1,26 +0,0 @@
|
|||||||
<menu xmlns:android="http://schemas.android.com/apk/res/android"
|
|
||||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
|
||||||
xmlns:tools="http://schemas.android.com/tools"
|
|
||||||
tools:context=".MainActivity" >
|
|
||||||
|
|
||||||
<item
|
|
||||||
android:id="@+id/search_history"
|
|
||||||
android:title="@string/search"
|
|
||||||
android:icon="@drawable/ic_search"
|
|
||||||
app:showAsAction="collapseActionView|always"
|
|
||||||
app:actionViewClass="androidx.appcompat.widget.SearchView"/>
|
|
||||||
|
|
||||||
<item
|
|
||||||
android:id="@+id/filter_history"
|
|
||||||
android:icon="@drawable/ic_filter"
|
|
||||||
android:title="@string/filter_history"
|
|
||||||
app:showAsAction="ifRoom" />
|
|
||||||
|
|
||||||
<item
|
|
||||||
android:id="@+id/delete_history"
|
|
||||||
android:icon="@drawable/ic_delete_all"
|
|
||||||
android:title="@string/fshi_historin"
|
|
||||||
app:showAsAction="ifRoom" />
|
|
||||||
|
|
||||||
</menu>
|
|
||||||
|
|
||||||
Loading…
Reference in New Issue