random stuff
This commit is contained in:
parent
b330a5ba08
commit
d91b6dc217
13 changed files with 751 additions and 392 deletions
|
|
@ -134,7 +134,6 @@ dependencies {
|
|||
|
||||
implementation "com.squareup.retrofit2:retrofit:$retrofitVer"
|
||||
implementation "com.squareup.retrofit2:converter-gson:$retrofitVer"
|
||||
|
||||
implementation "org.kodein.di:kodein-di-generic-jvm:6.4.0"
|
||||
implementation "org.kodein.di:kodein-di-framework-android-x:$kodeinVer"
|
||||
implementation "com.squareup.okhttp3:okhttp:5.0.0-alpha.10"
|
||||
implementation "com.squareup.okhttp3:logging-interceptor:4.7.2"
|
||||
}
|
||||
218
app/schemas/com.deniscerri.ytdlnis.database.DBManager/1.json
Normal file
218
app/schemas/com.deniscerri.ytdlnis.database.DBManager/1.json
Normal file
|
|
@ -0,0 +1,218 @@
|
|||
{
|
||||
"formatVersion": 1,
|
||||
"database": {
|
||||
"version": 1,
|
||||
"identityHash": "12ee531d801d7e6e3fd888f4907adc81",
|
||||
"entities": [
|
||||
{
|
||||
"tableName": "results",
|
||||
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `url` TEXT NOT NULL, `title` TEXT NOT NULL, `author` TEXT NOT NULL, `duration` TEXT NOT NULL, `thumb` TEXT NOT NULL, `website` TEXT NOT NULL, `playlistTitle` TEXT NOT NULL)",
|
||||
"fields": [
|
||||
{
|
||||
"fieldPath": "id",
|
||||
"columnName": "id",
|
||||
"affinity": "INTEGER",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "url",
|
||||
"columnName": "url",
|
||||
"affinity": "TEXT",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "title",
|
||||
"columnName": "title",
|
||||
"affinity": "TEXT",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "author",
|
||||
"columnName": "author",
|
||||
"affinity": "TEXT",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "duration",
|
||||
"columnName": "duration",
|
||||
"affinity": "TEXT",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "thumb",
|
||||
"columnName": "thumb",
|
||||
"affinity": "TEXT",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "website",
|
||||
"columnName": "website",
|
||||
"affinity": "TEXT",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "playlistTitle",
|
||||
"columnName": "playlistTitle",
|
||||
"affinity": "TEXT",
|
||||
"notNull": true
|
||||
}
|
||||
],
|
||||
"primaryKey": {
|
||||
"columnNames": [
|
||||
"id"
|
||||
],
|
||||
"autoGenerate": true
|
||||
},
|
||||
"indices": [],
|
||||
"foreignKeys": []
|
||||
},
|
||||
{
|
||||
"tableName": "history",
|
||||
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `url` TEXT NOT NULL, `title` TEXT NOT NULL, `author` TEXT NOT NULL, `duration` TEXT NOT NULL, `thumb` TEXT NOT NULL, `type` TEXT NOT NULL, `time` TEXT NOT NULL, `downloadPath` TEXT NOT NULL, `website` TEXT NOT NULL)",
|
||||
"fields": [
|
||||
{
|
||||
"fieldPath": "id",
|
||||
"columnName": "id",
|
||||
"affinity": "INTEGER",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "url",
|
||||
"columnName": "url",
|
||||
"affinity": "TEXT",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "title",
|
||||
"columnName": "title",
|
||||
"affinity": "TEXT",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "author",
|
||||
"columnName": "author",
|
||||
"affinity": "TEXT",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "duration",
|
||||
"columnName": "duration",
|
||||
"affinity": "TEXT",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "thumb",
|
||||
"columnName": "thumb",
|
||||
"affinity": "TEXT",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "type",
|
||||
"columnName": "type",
|
||||
"affinity": "TEXT",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "time",
|
||||
"columnName": "time",
|
||||
"affinity": "TEXT",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "downloadPath",
|
||||
"columnName": "downloadPath",
|
||||
"affinity": "TEXT",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "website",
|
||||
"columnName": "website",
|
||||
"affinity": "TEXT",
|
||||
"notNull": true
|
||||
}
|
||||
],
|
||||
"primaryKey": {
|
||||
"columnNames": [
|
||||
"id"
|
||||
],
|
||||
"autoGenerate": true
|
||||
},
|
||||
"indices": [],
|
||||
"foreignKeys": []
|
||||
},
|
||||
{
|
||||
"tableName": "downloads",
|
||||
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `url` TEXT NOT NULL, `title` TEXT NOT NULL, `author` TEXT NOT NULL, `duration` TEXT NOT NULL, `thumb` TEXT NOT NULL, `type` TEXT NOT NULL, `downloadPath` TEXT NOT NULL, `website` TEXT NOT NULL)",
|
||||
"fields": [
|
||||
{
|
||||
"fieldPath": "id",
|
||||
"columnName": "id",
|
||||
"affinity": "INTEGER",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "url",
|
||||
"columnName": "url",
|
||||
"affinity": "TEXT",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "title",
|
||||
"columnName": "title",
|
||||
"affinity": "TEXT",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "author",
|
||||
"columnName": "author",
|
||||
"affinity": "TEXT",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "duration",
|
||||
"columnName": "duration",
|
||||
"affinity": "TEXT",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "thumb",
|
||||
"columnName": "thumb",
|
||||
"affinity": "TEXT",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "type",
|
||||
"columnName": "type",
|
||||
"affinity": "TEXT",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "downloadPath",
|
||||
"columnName": "downloadPath",
|
||||
"affinity": "TEXT",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "website",
|
||||
"columnName": "website",
|
||||
"affinity": "TEXT",
|
||||
"notNull": true
|
||||
}
|
||||
],
|
||||
"primaryKey": {
|
||||
"columnNames": [
|
||||
"id"
|
||||
],
|
||||
"autoGenerate": true
|
||||
},
|
||||
"indices": [],
|
||||
"foreignKeys": []
|
||||
}
|
||||
],
|
||||
"views": [],
|
||||
"setupQueries": [
|
||||
"CREATE TABLE IF NOT EXISTS room_master_table (id INTEGER PRIMARY KEY,identity_hash TEXT)",
|
||||
"INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, '12ee531d801d7e6e3fd888f4907adc81')"
|
||||
]
|
||||
}
|
||||
}
|
||||
|
|
@ -194,7 +194,6 @@ class MainActivity : AppCompatActivity() {
|
|||
lastFragment = homeFragment
|
||||
listeners = ArrayList()
|
||||
listeners.add(homeFragment.listener)
|
||||
listeners.add(downloadsFragment.listener)
|
||||
}
|
||||
|
||||
private fun replaceFragment(f: Fragment) {
|
||||
|
|
@ -229,8 +228,7 @@ class MainActivity : AppCompatActivity() {
|
|||
databaseManager.addToHistory(v)
|
||||
}
|
||||
databaseManager.close()
|
||||
downloadsFragment.setDownloading(true)
|
||||
downloadsFragment.initCards()
|
||||
//downloadsFragment.initCards()
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
e.printStackTrace()
|
||||
|
|
|
|||
|
|
@ -23,6 +23,7 @@ import androidx.recyclerview.widget.RecyclerView;
|
|||
|
||||
import com.deniscerri.ytdlnis.R;
|
||||
import com.deniscerri.ytdlnis.database.Video;
|
||||
import com.deniscerri.ytdlnis.database.models.HistoryItem;
|
||||
import com.google.android.material.button.MaterialButton;
|
||||
import com.google.android.material.card.MaterialCardView;
|
||||
import com.google.android.material.progressindicator.LinearProgressIndicator;
|
||||
|
|
@ -30,16 +31,17 @@ import com.squareup.picasso.Picasso;
|
|||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class DownloadsRecyclerViewAdapter extends RecyclerView.Adapter<DownloadsRecyclerViewAdapter.ViewHolder> {
|
||||
private ArrayList<Video> videoList;
|
||||
private List<HistoryItem> videoList;
|
||||
private ArrayList<Integer> checkedVideos;
|
||||
private ArrayList<String> websites;
|
||||
private final OnItemClickListener onItemClickListener;
|
||||
private Activity activity;
|
||||
|
||||
public DownloadsRecyclerViewAdapter(ArrayList<Video> videos, OnItemClickListener onItemClickListener, Activity activity){
|
||||
this.videoList = videos;
|
||||
public DownloadsRecyclerViewAdapter(OnItemClickListener onItemClickListener, Activity activity){
|
||||
this.videoList = new ArrayList<>();
|
||||
this.websites = new ArrayList<>();
|
||||
this.checkedVideos = new ArrayList<>();
|
||||
this.onItemClickListener = onItemClickListener;
|
||||
|
|
@ -71,7 +73,8 @@ public class DownloadsRecyclerViewAdapter extends RecyclerView.Adapter<Downloads
|
|||
|
||||
@Override
|
||||
public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
|
||||
Video video = videoList.get(position);
|
||||
HistoryItem video = videoList.get(position);
|
||||
Log.e("AAA", video.toString());
|
||||
MaterialCardView card = holder.cardView;
|
||||
// THUMBNAIL ----------------------------------
|
||||
ImageView thumbnail = card.findViewById(R.id.downloads_image_view);
|
||||
|
|
@ -107,51 +110,37 @@ public class DownloadsRecyclerViewAdapter extends RecyclerView.Adapter<Downloads
|
|||
|
||||
// TIME DOWNLOADED ----------------------------------
|
||||
TextView datetime = card.findViewById(R.id.downloads_info_time);
|
||||
String downloadedTime = video.getDownloadedTime();
|
||||
if (downloadedTime == null) downloadedTime = activity.getString(R.string.currently_downloading) + " " + video.getDownloadedType();
|
||||
String downloadedTime = video.getTime();
|
||||
if (downloadedTime.isEmpty()) downloadedTime = activity.getString(R.string.currently_downloading) + " " + video.getType();
|
||||
datetime.setText(downloadedTime);
|
||||
|
||||
// BUTTON ----------------------------------
|
||||
LinearLayout buttonLayout = card.findViewById(R.id.downloads_download_button_layout);
|
||||
MaterialButton btn = buttonLayout.findViewById(R.id.downloads_download_button_type);
|
||||
|
||||
// PROGRESS BAR ----------------------------------------------------
|
||||
LinearProgressIndicator progressBar = card.findViewById(R.id.download_progress);
|
||||
progressBar.setTag(video.getURL()+video.getDownloadedType()+"##progress");
|
||||
|
||||
boolean filePresent = true;
|
||||
|
||||
if (video.isQueuedDownload()){
|
||||
progressBar.setVisibility(View.VISIBLE);
|
||||
btn.setOnClickListener(view -> onItemClickListener.onButtonClick(position));
|
||||
btn.setIcon(ContextCompat.getDrawable(activity, R.drawable.ic_cancel));
|
||||
}else {
|
||||
progressBar.setVisibility(View.GONE);
|
||||
progressBar.setIndeterminate(true);
|
||||
|
||||
//IS IN THE FILE SYSTEM?
|
||||
String path = video.getDownloadPath();
|
||||
File file = new File(path);
|
||||
if(!file.exists() && !path.isEmpty()){
|
||||
filePresent = false;
|
||||
thumbnail.setColorFilter(new ColorMatrixColorFilter(new ColorMatrix(){{setSaturation(0f);}}));
|
||||
thumbnail.setAlpha(0.7f);
|
||||
}
|
||||
|
||||
if(video.getDownloadedType() != null){
|
||||
if(video.getDownloadedType().equals("audio")){
|
||||
if (filePresent) btn.setIcon(ContextCompat.getDrawable(activity, R.drawable.ic_music_downloaded));
|
||||
else btn.setIcon(ContextCompat.getDrawable(activity, R.drawable.ic_music));
|
||||
}else{
|
||||
if (filePresent) btn.setIcon(ContextCompat.getDrawable(activity, R.drawable.ic_video_downloaded));
|
||||
else btn.setIcon(ContextCompat.getDrawable(activity, R.drawable.ic_video));
|
||||
}
|
||||
}
|
||||
|
||||
if (btn.hasOnClickListeners()) btn.setOnClickListener(null);
|
||||
|
||||
//IS IN THE FILE SYSTEM?
|
||||
String path = video.getDownloadPath();
|
||||
File file = new File(path);
|
||||
if(!file.exists() && !path.isEmpty()){
|
||||
filePresent = false;
|
||||
thumbnail.setColorFilter(new ColorMatrixColorFilter(new ColorMatrix(){{setSaturation(0f);}}));
|
||||
thumbnail.setAlpha(0.7f);
|
||||
}
|
||||
|
||||
if(!video.getType().isEmpty()){
|
||||
if(video.getType().equals("audio")){
|
||||
if (filePresent) btn.setIcon(ContextCompat.getDrawable(activity, R.drawable.ic_music_downloaded));
|
||||
else btn.setIcon(ContextCompat.getDrawable(activity, R.drawable.ic_music));
|
||||
}else{
|
||||
if (filePresent) btn.setIcon(ContextCompat.getDrawable(activity, R.drawable.ic_video_downloaded));
|
||||
else btn.setIcon(ContextCompat.getDrawable(activity, R.drawable.ic_video));
|
||||
}
|
||||
}
|
||||
|
||||
if (btn.hasOnClickListeners()) btn.setOnClickListener(null);
|
||||
|
||||
if(checkedVideos.contains(position)){
|
||||
card.setChecked(true);
|
||||
card.setStrokeWidth(5);
|
||||
|
|
@ -174,6 +163,12 @@ public class DownloadsRecyclerViewAdapter extends RecyclerView.Adapter<Downloads
|
|||
});
|
||||
}
|
||||
|
||||
public void setVideoList(List<HistoryItem> list){
|
||||
videoList.clear();
|
||||
videoList.addAll(list);
|
||||
notifyDataSetChanged();
|
||||
}
|
||||
|
||||
private void checkCard(MaterialCardView card, int position){
|
||||
if(card.isChecked()){
|
||||
card.setStrokeWidth(0);
|
||||
|
|
@ -203,7 +198,7 @@ public class DownloadsRecyclerViewAdapter extends RecyclerView.Adapter<Downloads
|
|||
|
||||
public void updateWebsiteList(){
|
||||
websites = new ArrayList<>();
|
||||
for (Video video : videoList){
|
||||
for (HistoryItem video : videoList){
|
||||
if (!websites.contains(video.getWebsite())) websites.add(video.getWebsite());
|
||||
}
|
||||
}
|
||||
|
|
@ -224,7 +219,7 @@ public class DownloadsRecyclerViewAdapter extends RecyclerView.Adapter<Downloads
|
|||
checkedVideos.clear();
|
||||
}
|
||||
|
||||
public void add(ArrayList<Video> vids){
|
||||
public void add(ArrayList<HistoryItem> vids){
|
||||
int position = videoList.size() + 1;
|
||||
videoList.addAll(vids);
|
||||
notifyItemRangeInserted(position, vids.size());
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ interface HistoryDao {
|
|||
"CASE WHEN :sort = 'ASC' THEN id END ASC," +
|
||||
"CASE WHEN :sort = 'DESC' THEN id END DESC," +
|
||||
"CASE WHEN :sort = '' THEN id END DESC ")
|
||||
suspend fun getHistory(query : String, format : String, site : String, sort : String) : LiveData<List<HistoryItem>>
|
||||
fun getHistory(query : String, format : String, site : String, sort : String) : LiveData<List<HistoryItem>>
|
||||
|
||||
@Query("SELECT * FROM history")
|
||||
fun getAllHistory() : LiveData<List<HistoryItem>>
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ package com.deniscerri.ytdlnis.database.models
|
|||
|
||||
import androidx.room.Entity
|
||||
import androidx.room.PrimaryKey
|
||||
import com.google.gson.annotations.SerializedName
|
||||
|
||||
@Entity(tableName = "results")
|
||||
data class ResultItem(
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@ import kotlinx.coroutines.launch
|
|||
|
||||
class HistoryViewModel(application: Application) : AndroidViewModel(application) {
|
||||
private val repository : HistoryRepository
|
||||
private val allHistory : LiveData<List<HistoryItem>>
|
||||
val allHistory : LiveData<List<HistoryItem>>
|
||||
|
||||
init {
|
||||
val dao = DBManager.getInstance(application).historyDao
|
||||
|
|
|
|||
|
|
@ -0,0 +1,49 @@
|
|||
package com.deniscerri.ytdlnis.service
|
||||
|
||||
import androidx.room.Room
|
||||
import com.deniscerri.ytdlnis.database.DBManager
|
||||
import com.deniscerri.ytdlnis.database.models.ResultItem
|
||||
import com.google.gson.JsonArray
|
||||
import com.google.gson.JsonObject
|
||||
import retrofit2.Call
|
||||
import retrofit2.Response
|
||||
import retrofit2.Retrofit
|
||||
import retrofit2.converter.gson.GsonConverterFactory
|
||||
import retrofit2.http.GET
|
||||
import retrofit2.http.Path
|
||||
|
||||
interface InvidiousService {
|
||||
@GET("video/{id}")
|
||||
suspend fun getVideo(
|
||||
@Path("id") id : String
|
||||
) : Call<ResultItem>
|
||||
|
||||
@GET("playlist/{id}")
|
||||
suspend fun getPlaylist(
|
||||
@Path("id") id: String
|
||||
) : Response<JsonObject>
|
||||
|
||||
@GET("trending?type=music®ion={regionCode}")
|
||||
suspend fun getTrending(
|
||||
@Path("regionCode") regionCode: String
|
||||
) : Response<JsonArray>
|
||||
|
||||
@GET("search/suggestions?q={query}")
|
||||
suspend fun getSearchSuggestions(
|
||||
@Path("query") query: String
|
||||
) : Response<JsonObject>
|
||||
|
||||
companion object {
|
||||
var invidiousService : InvidiousService? = null
|
||||
fun getInstance() : InvidiousService {
|
||||
return invidiousService ?: run {
|
||||
val retrofit = Retrofit.Builder()
|
||||
.baseUrl("https://invidious.baczek.me/api/v1/")
|
||||
.addConverterFactory(GsonConverterFactory.create())
|
||||
.build()
|
||||
invidiousService = retrofit.create(InvidiousService::class.java)
|
||||
invidiousService!!
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,71 @@
|
|||
package com.deniscerri.ytdlnis.service
|
||||
|
||||
import androidx.room.Query
|
||||
import androidx.room.Room
|
||||
import com.deniscerri.ytdlnis.database.DBManager
|
||||
import com.deniscerri.ytdlnis.database.models.ResultItem
|
||||
import com.deniscerri.ytdlnis.util.InfoUtil
|
||||
import com.google.gson.JsonArray
|
||||
import com.google.gson.JsonObject
|
||||
import retrofit2.Response
|
||||
import retrofit2.Retrofit
|
||||
import retrofit2.converter.gson.GsonConverterFactory
|
||||
import retrofit2.http.GET
|
||||
import retrofit2.http.Path
|
||||
|
||||
interface YoutubeAPIService {
|
||||
@GET("videos?part=snippet,contentDetails&id={id}&key={apiKey}")
|
||||
suspend fun getVideo(
|
||||
@Path("id") id: String?
|
||||
) : Response<JsonObject>
|
||||
|
||||
@GET("playlistItems?part=snippet&pageToken={nextPageToken}&maxResults=50®ionCode={regionCode}&playlistId={playlistId}&key={apiKey}")
|
||||
suspend fun getPlaylist(
|
||||
@Path("nextPageToken") nextPageToken: String,
|
||||
@Path("playlistId") playlistId : String,
|
||||
@Path("apiKey") apiKey : String
|
||||
) : Response<JsonObject>
|
||||
|
||||
@GET("videos?part=snippet&chart=mostPopular&videoCategoryId=10®ionCode={regionCode}&maxResults=25&key={apiKey}")
|
||||
suspend fun getTrending(
|
||||
@Path("regionCode") regionCode: String,
|
||||
@Path("apiKey") apiKey : String
|
||||
) : Response<JsonArray>
|
||||
|
||||
@GET("videos?part=contentDetails&chart=mostPopular&videoCategoryId=10®ionCode={regionCode}&maxResults=25&key={apiKey}")
|
||||
suspend fun getTrendingExtra(
|
||||
@Path("regionCode") regionCode: String,
|
||||
@Path("apiKey") apiKey : String
|
||||
) : Response<JsonArray>
|
||||
|
||||
@GET("search?part=snippet&q={query}&maxResults=25®ionCode={regionCode}&key={apiKey}")
|
||||
suspend fun search(
|
||||
@Path("query") query: String,
|
||||
@Path("regionCode") regionCode: String,
|
||||
@Path("apiKey") apiKey: String
|
||||
) : Response<JsonObject>
|
||||
|
||||
@GET("videos?id={ids}&part=contentDetails®ionCode={regionCode}&key={apiKey}")
|
||||
suspend fun getExtraData(
|
||||
@Path("ids") ids: String,
|
||||
@Path("regionCode") regionCode: String,
|
||||
@Path("apiKey") apiKey: String
|
||||
) : Response<JsonObject>
|
||||
|
||||
companion object {
|
||||
var invidiousService : YoutubeAPIService? = null
|
||||
lateinit var apiKey : String
|
||||
lateinit var regionCode: String
|
||||
fun getInstance(key: String, regionCode: String) : YoutubeAPIService {
|
||||
apiKey = key
|
||||
return invidiousService ?: run {
|
||||
val retrofit = Retrofit.Builder()
|
||||
.baseUrl("https://www.googleapis.com/youtube/v3/")
|
||||
.addConverterFactory(GsonConverterFactory.create())
|
||||
.build()
|
||||
invidiousService = retrofit.create(YoutubeAPIService::class.java)
|
||||
invidiousService!!
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -3,27 +3,33 @@ package com.deniscerri.ytdlnis.ui
|
|||
import android.app.Activity
|
||||
import android.content.*
|
||||
import android.net.Uri
|
||||
import android.os.Binder
|
||||
import android.os.Bundle
|
||||
import android.os.Handler
|
||||
import android.os.Looper
|
||||
import android.text.InputType
|
||||
import android.util.Log
|
||||
import android.view.*
|
||||
import android.view.View.OnLongClickListener
|
||||
import android.view.View.*
|
||||
import android.widget.*
|
||||
import androidx.appcompat.widget.SearchView
|
||||
import androidx.core.content.FileProvider
|
||||
import androidx.fragment.app.Fragment
|
||||
import androidx.lifecycle.Observer
|
||||
import androidx.lifecycle.ViewModel
|
||||
import androidx.lifecycle.ViewModelProvider
|
||||
import androidx.recyclerview.widget.LinearLayoutManager
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import com.deniscerri.ytdlnis.MainActivity
|
||||
import com.deniscerri.ytdlnis.R
|
||||
import com.deniscerri.ytdlnis.adapter.DownloadsRecyclerViewAdapter
|
||||
import com.deniscerri.ytdlnis.database.DatabaseManager
|
||||
import com.deniscerri.ytdlnis.database.Video
|
||||
import com.deniscerri.ytdlnis.database.models.HistoryItem
|
||||
import com.deniscerri.ytdlnis.database.viewmodel.DownloadViewModel
|
||||
import com.deniscerri.ytdlnis.database.viewmodel.HistoryViewModel
|
||||
import com.deniscerri.ytdlnis.databinding.FragmentDownloadsBinding
|
||||
import com.deniscerri.ytdlnis.databinding.FragmentHomeBinding
|
||||
import com.deniscerri.ytdlnis.service.DownloadInfo
|
||||
import com.deniscerri.ytdlnis.util.FileUtil
|
||||
import com.facebook.shimmer.ShimmerFrameLayout
|
||||
|
|
@ -61,7 +67,7 @@ class DownloadsFragment : Fragment(), DownloadsRecyclerViewAdapter.OnItemClickLi
|
|||
private var no_results: RelativeLayout? = null
|
||||
private var selectionChips: LinearLayout? = null
|
||||
private var websiteGroup: ChipGroup? = null
|
||||
private var downloadsObjects: ArrayList<Video?>? = null
|
||||
private var downloadsObjects: List<HistoryItem?>? = null
|
||||
var selectedObjects: ArrayList<Video?>? = null
|
||||
private var progressBar: LinearProgressIndicator? = null
|
||||
private var deleteFab: ExtendedFloatingActionButton? = null
|
||||
|
|
@ -71,6 +77,8 @@ class DownloadsFragment : Fragment(), DownloadsRecyclerViewAdapter.OnItemClickLi
|
|||
private var sort = "DESC"
|
||||
private var searchQuery = ""
|
||||
|
||||
private var _binding : FragmentDownloadsBinding? = null
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
setHasOptionsMenu(true)
|
||||
|
|
@ -80,21 +88,24 @@ class DownloadsFragment : Fragment(), DownloadsRecyclerViewAdapter.OnItemClickLi
|
|||
inflater: LayoutInflater, container: ViewGroup?,
|
||||
savedInstanceState: Bundle?
|
||||
): View? {
|
||||
_binding = FragmentDownloadsBinding.inflate(inflater, container, false)
|
||||
fragmentView = inflater.inflate(R.layout.fragment_downloads, container, false)
|
||||
activity = getActivity()
|
||||
mainActivity = activity as MainActivity?
|
||||
fragmentContext = context?.applicationContext
|
||||
layoutinflater = LayoutInflater.from(context)
|
||||
|
||||
historyViewModel = ViewModelProvider(this)[HistoryViewModel::class.java]
|
||||
return fragmentView
|
||||
}
|
||||
|
||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||
super.onViewCreated(view, savedInstanceState)
|
||||
|
||||
shimmerCards = this.view?.findViewById(R.id.shimmer_downloads_framelayout)
|
||||
topAppBar = this.view?.findViewById(R.id.downloads_toolbar)
|
||||
no_results = this.view?.findViewById(R.id.downloads_no_results)
|
||||
selectionChips = this.view?.findViewById(R.id.downloads_selection_chips)
|
||||
websiteGroup = this.view?.findViewById(R.id.website_chip_group)
|
||||
deleteFab = this.view?.findViewById(R.id.delete_selected_fab)
|
||||
fragmentContext = context
|
||||
shimmerCards = view.findViewById(R.id.shimmer_downloads_framelayout)
|
||||
topAppBar = view.findViewById(R.id.downloads_toolbar)
|
||||
no_results = view.findViewById(R.id.downloads_no_results)
|
||||
selectionChips = view.findViewById(R.id.downloads_selection_chips)
|
||||
websiteGroup = view.findViewById(R.id.website_chip_group)
|
||||
deleteFab = view.findViewById(R.id.delete_selected_fab)
|
||||
fileUtil = FileUtil()
|
||||
deleteFab?.tag = "deleteSelected"
|
||||
deleteFab?.setOnClickListener(this)
|
||||
|
|
@ -102,57 +113,74 @@ class DownloadsFragment : Fragment(), DownloadsRecyclerViewAdapter.OnItemClickLi
|
|||
downloadsObjects = ArrayList()
|
||||
selectedObjects = ArrayList()
|
||||
downloading = mainActivity!!.isDownloadServiceRunning()
|
||||
recyclerView = this.view?.findViewById(R.id.recycler_view_downloads)
|
||||
|
||||
|
||||
downloadsObjects = mutableListOf()
|
||||
|
||||
downloadsRecyclerViewAdapter =
|
||||
DownloadsRecyclerViewAdapter(downloadsObjects, this, activity)
|
||||
DownloadsRecyclerViewAdapter(this, activity)
|
||||
recyclerView = view.findViewById(R.id.recyclerviewdownloadss)
|
||||
recyclerView?.layoutManager = LinearLayoutManager(context)
|
||||
recyclerView?.adapter = downloadsRecyclerViewAdapter
|
||||
recyclerView?.isNestedScrollingEnabled = false
|
||||
initMenu()
|
||||
initChips()
|
||||
initCards()
|
||||
return fragmentView
|
||||
}
|
||||
|
||||
fun initCards() {
|
||||
shimmerCards!!.startShimmer()
|
||||
shimmerCards!!.visibility = View.VISIBLE
|
||||
downloadsRecyclerViewAdapter!!.clear()
|
||||
no_results!!.visibility = View.GONE
|
||||
selectionChips!!.visibility = View.VISIBLE
|
||||
databaseManager = DatabaseManager(context)
|
||||
try {
|
||||
val thread = Thread {
|
||||
if (!downloading) databaseManager!!.clearDownloadingHistory()
|
||||
downloadsObjects = databaseManager!!.getHistory("", format, website, sort)
|
||||
uiHandler!!.post {
|
||||
downloadsRecyclerViewAdapter!!.add(downloadsObjects)
|
||||
shimmerCards!!.stopShimmer()
|
||||
shimmerCards!!.visibility = View.GONE
|
||||
updateWebsiteChips()
|
||||
}
|
||||
if ((downloadsObjects as ArrayList<Video>?)?.size == 0) {
|
||||
uiHandler!!.post {
|
||||
no_results!!.visibility = View.VISIBLE
|
||||
selectionChips!!.visibility = View.GONE
|
||||
websiteGroup!!.removeAllViews()
|
||||
}
|
||||
}
|
||||
databaseManager!!.close()
|
||||
}
|
||||
thread.start()
|
||||
} catch (e: Exception) {
|
||||
Log.e(TAG, e.toString())
|
||||
no_results?.visibility = GONE
|
||||
selectionChips?.visibility = VISIBLE
|
||||
shimmerCards?.visibility = GONE
|
||||
|
||||
|
||||
historyViewModel = ViewModelProvider(this)[HistoryViewModel::class.java]
|
||||
historyViewModel.allHistory.observe(viewLifecycleOwner) {
|
||||
downloadsRecyclerViewAdapter!!.setVideoList(it);
|
||||
Toast.makeText(context, "CHANGED", Toast.LENGTH_SHORT).show()
|
||||
}
|
||||
|
||||
|
||||
initMenu()
|
||||
//initChips()
|
||||
// initCards()
|
||||
}
|
||||
|
||||
// fun initCards() {
|
||||
// shimmerCards!!.startShimmer()
|
||||
// shimmerCards!!.visibility = View.VISIBLE
|
||||
// downloadsRecyclerViewAdapter!!.clear()
|
||||
// no_results!!.visibility = View.GONE
|
||||
// selectionChips!!.visibility = View.VISIBLE
|
||||
// databaseManager = DatabaseManager(context)
|
||||
// try {
|
||||
// val thread = Thread {
|
||||
// if (!downloading) databaseManager!!.clearDownloadingHistory()
|
||||
// downloadsObjects = databaseManager!!.getHistory("", format, website, sort)
|
||||
// uiHandler!!.post {
|
||||
// downloadsRecyclerViewAdapter!!.add(downloadsObjects)
|
||||
// shimmerCards!!.stopShimmer()
|
||||
// shimmerCards!!.visibility = View.GONE
|
||||
// updateWebsiteChips()
|
||||
// }
|
||||
// if ((downloadsObjects as ArrayList<Video>?)?.size == 0) {
|
||||
// uiHandler!!.post {
|
||||
// no_results!!.visibility = View.VISIBLE
|
||||
// selectionChips!!.visibility = View.GONE
|
||||
// websiteGroup!!.removeAllViews()
|
||||
// }
|
||||
// }
|
||||
// databaseManager!!.close()
|
||||
// }
|
||||
// thread.start()
|
||||
// } catch (e: Exception) {
|
||||
// Log.e(TAG, e.toString())
|
||||
// }
|
||||
// }
|
||||
//
|
||||
fun scrollToTop() {
|
||||
recyclerView!!.scrollToPosition(0)
|
||||
Handler(Looper.getMainLooper()).post {
|
||||
(topAppBar!!.parent as AppBarLayout).setExpanded(
|
||||
true,
|
||||
true
|
||||
)
|
||||
}
|
||||
// recyclerView!!.scrollToPosition(0)
|
||||
// Handler(Looper.getMainLooper()).post {
|
||||
// (topAppBar!!.parent as AppBarLayout).setExpanded(
|
||||
// true,
|
||||
// true
|
||||
// )
|
||||
// }
|
||||
}
|
||||
|
||||
private fun initMenu() {
|
||||
|
|
@ -175,31 +203,31 @@ class DownloadsFragment : Fragment(), DownloadsRecyclerViewAdapter.OnItemClickLi
|
|||
databaseManager = DatabaseManager(context)
|
||||
searchView.setOnQueryTextListener(object : SearchView.OnQueryTextListener {
|
||||
override fun onQueryTextSubmit(query: String): Boolean {
|
||||
searchQuery = query
|
||||
topAppBar!!.menu.findItem(R.id.search_downloads).collapseActionView()
|
||||
downloadsObjects = databaseManager!!.getHistory(query, format, website, sort)
|
||||
downloadsRecyclerViewAdapter!!.clear()
|
||||
downloadsRecyclerViewAdapter!!.add(downloadsObjects)
|
||||
if ((downloadsObjects as ArrayList<Video>?)?.size == 0) {
|
||||
no_results!!.visibility = View.VISIBLE
|
||||
selectionChips!!.visibility = View.GONE
|
||||
websiteGroup!!.removeAllViews()
|
||||
}
|
||||
// searchQuery = query
|
||||
// topAppBar!!.menu.findItem(R.id.search_downloads).collapseActionView()
|
||||
// downloadsObjects = databaseManager!!.getHistory(query, format, website, sort)
|
||||
// downloadsRecyclerViewAdapter!!.clear()
|
||||
// downloadsRecyclerViewAdapter!!.add(downloadsObjects)
|
||||
// if ((downloadsObjects as ArrayList<Video>?)?.size == 0) {
|
||||
// no_results!!.visibility = View.VISIBLE
|
||||
// selectionChips!!.visibility = View.GONE
|
||||
// websiteGroup!!.removeAllViews()
|
||||
// }
|
||||
return true
|
||||
}
|
||||
|
||||
override fun onQueryTextChange(newText: String): Boolean {
|
||||
searchQuery = newText
|
||||
downloadsObjects = databaseManager!!.getHistory(newText, format, website, sort)
|
||||
downloadsRecyclerViewAdapter!!.clear()
|
||||
downloadsRecyclerViewAdapter!!.add(downloadsObjects)
|
||||
if ((downloadsObjects as ArrayList<Video>?)?.size == 0) {
|
||||
no_results!!.visibility = View.VISIBLE
|
||||
selectionChips!!.visibility = View.GONE
|
||||
} else {
|
||||
no_results!!.visibility = View.GONE
|
||||
selectionChips!!.visibility = View.VISIBLE
|
||||
}
|
||||
// searchQuery = newText
|
||||
// downloadsObjects = databaseManager!!.getHistory(newText, format, website, sort)
|
||||
// downloadsRecyclerViewAdapter!!.clear()
|
||||
// downloadsRecyclerViewAdapter!!.add(downloadsObjects)
|
||||
// if ((downloadsObjects as ArrayList<Video>?)?.size == 0) {
|
||||
// no_results!!.visibility = View.VISIBLE
|
||||
// selectionChips!!.visibility = View.GONE
|
||||
// } else {
|
||||
// no_results!!.visibility = View.GONE
|
||||
// selectionChips!!.visibility = View.VISIBLE
|
||||
// }
|
||||
return true
|
||||
}
|
||||
})
|
||||
|
|
@ -207,266 +235,266 @@ class DownloadsFragment : Fragment(), DownloadsRecyclerViewAdapter.OnItemClickLi
|
|||
topAppBar!!.setOnMenuItemClickListener { m: MenuItem ->
|
||||
val itemID = m.itemId
|
||||
if (itemID == R.id.remove_downloads) {
|
||||
if (downloadsObjects!!.size == 0) {
|
||||
Toast.makeText(context, R.string.history_is_empty, Toast.LENGTH_SHORT).show()
|
||||
return@setOnMenuItemClickListener true
|
||||
}
|
||||
val delete_dialog = 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: DialogInterface, i: Int -> dialogInterface.cancel() }
|
||||
delete_dialog.setPositiveButton(getString(R.string.ok)) { dialogInterface: DialogInterface?, i: Int ->
|
||||
databaseManager!!.clearHistory()
|
||||
downloadsRecyclerViewAdapter!!.clear()
|
||||
downloadsObjects!!.clear()
|
||||
no_results!!.visibility = View.VISIBLE
|
||||
selectionChips!!.visibility = View.GONE
|
||||
websiteGroup!!.removeAllViews()
|
||||
}
|
||||
delete_dialog.show()
|
||||
// if (downloadsObjects!!.size == 0) {
|
||||
// Toast.makeText(context, R.string.history_is_empty, Toast.LENGTH_SHORT).show()
|
||||
// return@setOnMenuItemClickListener true
|
||||
// }
|
||||
// val delete_dialog = 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: DialogInterface, i: Int -> dialogInterface.cancel() }
|
||||
// delete_dialog.setPositiveButton(getString(R.string.ok)) { dialogInterface: DialogInterface?, i: Int ->
|
||||
// databaseManager!!.clearHistory()
|
||||
// downloadsRecyclerViewAdapter!!.clear()
|
||||
// downloadsObjects!!.clear()
|
||||
// no_results!!.visibility = View.VISIBLE
|
||||
// selectionChips!!.visibility = 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@setOnMenuItemClickListener true
|
||||
}
|
||||
val delete_dialog = 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: DialogInterface, i: Int -> dialogInterface.cancel() }
|
||||
delete_dialog.setPositiveButton(getString(R.string.ok)) { dialogInterface: DialogInterface?, i: Int ->
|
||||
databaseManager!!.clearDeletedHistory()
|
||||
initCards()
|
||||
}
|
||||
delete_dialog.show()
|
||||
// if (downloadsObjects!!.size == 0) {
|
||||
// Toast.makeText(context, R.string.history_is_empty, Toast.LENGTH_SHORT).show()
|
||||
// return@setOnMenuItemClickListener true
|
||||
// }
|
||||
// val delete_dialog = 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: DialogInterface, i: Int -> dialogInterface.cancel() }
|
||||
// delete_dialog.setPositiveButton(getString(R.string.ok)) { dialogInterface: DialogInterface?, i: Int ->
|
||||
// databaseManager!!.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@setOnMenuItemClickListener true
|
||||
}
|
||||
val delete_dialog = 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: DialogInterface, i: Int -> dialogInterface.cancel() }
|
||||
delete_dialog.setPositiveButton(getString(R.string.ok)) { dialogInterface: DialogInterface?, i: Int ->
|
||||
databaseManager!!.clearDuplicateHistory()
|
||||
initCards()
|
||||
}
|
||||
delete_dialog.show()
|
||||
// if (downloadsObjects!!.size == 0) {
|
||||
// Toast.makeText(context, R.string.history_is_empty, Toast.LENGTH_SHORT).show()
|
||||
// return@setOnMenuItemClickListener true
|
||||
// }
|
||||
// val delete_dialog = 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: DialogInterface, i: Int -> dialogInterface.cancel() }
|
||||
// delete_dialog.setPositiveButton(getString(R.string.ok)) { dialogInterface: DialogInterface?, i: Int ->
|
||||
// databaseManager!!.clearDuplicateHistory()
|
||||
// initCards()
|
||||
// }
|
||||
// delete_dialog.show()
|
||||
} else if (itemID == R.id.remove_downloading) {
|
||||
if (downloadsObjects!!.size == 0) {
|
||||
Toast.makeText(context, R.string.history_is_empty, Toast.LENGTH_SHORT).show()
|
||||
return@setOnMenuItemClickListener true
|
||||
}
|
||||
val delete_dialog = MaterialAlertDialogBuilder(fragmentContext!!)
|
||||
delete_dialog.setTitle(getString(R.string.confirm_delete_history))
|
||||
delete_dialog.setMessage(getString(R.string.confirm_delete_downloading_desc))
|
||||
delete_dialog.setNegativeButton(getString(R.string.cancel)) { dialogInterface: DialogInterface, i: Int -> dialogInterface.cancel() }
|
||||
delete_dialog.setPositiveButton(getString(R.string.ok)) { dialogInterface: DialogInterface?, i: Int ->
|
||||
databaseManager!!.clearDownloadingHistory()
|
||||
mainActivity!!.cancelDownloadService()
|
||||
initCards()
|
||||
}
|
||||
delete_dialog.show()
|
||||
// if (downloadsObjects!!.size == 0) {
|
||||
// Toast.makeText(context, R.string.history_is_empty, Toast.LENGTH_SHORT).show()
|
||||
// return@setOnMenuItemClickListener true
|
||||
// }
|
||||
// val delete_dialog = MaterialAlertDialogBuilder(fragmentContext!!)
|
||||
// delete_dialog.setTitle(getString(R.string.confirm_delete_history))
|
||||
// delete_dialog.setMessage(getString(R.string.confirm_delete_downloading_desc))
|
||||
// delete_dialog.setNegativeButton(getString(R.string.cancel)) { dialogInterface: DialogInterface, i: Int -> dialogInterface.cancel() }
|
||||
// delete_dialog.setPositiveButton(getString(R.string.ok)) { dialogInterface: DialogInterface?, i: Int ->
|
||||
// databaseManager!!.clearDownloadingHistory()
|
||||
// mainActivity!!.cancelDownloadService()
|
||||
// initCards()
|
||||
// }
|
||||
// delete_dialog.show()
|
||||
}
|
||||
true
|
||||
}
|
||||
}
|
||||
|
||||
private fun initChips() {
|
||||
//sort and history/downloading switch
|
||||
val sortChip = fragmentView!!.findViewById<Chip>(R.id.sort_chip)
|
||||
sortChip.setOnClickListener { view: View? ->
|
||||
sortSheet = BottomSheetDialog(fragmentContext!!)
|
||||
sortSheet!!.requestWindowFeature(Window.FEATURE_NO_TITLE)
|
||||
sortSheet!!.setContentView(R.layout.downloads_sort_sheet)
|
||||
val newest = sortSheet!!.findViewById<TextView>(R.id.newest)
|
||||
val oldest = sortSheet!!.findViewById<TextView>(R.id.oldest)
|
||||
newest!!.setOnClickListener { view1: View? ->
|
||||
sort = "DESC"
|
||||
downloadsObjects = databaseManager!!.getHistory(searchQuery, format, website, sort)
|
||||
downloadsRecyclerViewAdapter!!.clear()
|
||||
downloadsRecyclerViewAdapter!!.add(downloadsObjects)
|
||||
sortSheet!!.cancel()
|
||||
}
|
||||
oldest!!.setOnClickListener { view1: View? ->
|
||||
sort = "ASC"
|
||||
downloadsObjects = databaseManager!!.getHistory(searchQuery, format, website, sort)
|
||||
downloadsRecyclerViewAdapter!!.clear()
|
||||
downloadsRecyclerViewAdapter!!.add(downloadsObjects)
|
||||
sortSheet!!.cancel()
|
||||
}
|
||||
val cancel = sortSheet!!.findViewById<TextView>(R.id.cancel)
|
||||
cancel!!.setOnClickListener { view1: View? -> sortSheet!!.cancel() }
|
||||
sortSheet!!.show()
|
||||
sortSheet!!.window!!.setLayout(
|
||||
ViewGroup.LayoutParams.MATCH_PARENT,
|
||||
ViewGroup.LayoutParams.MATCH_PARENT
|
||||
)
|
||||
}
|
||||
|
||||
//format
|
||||
val audio = fragmentView!!.findViewById<Chip>(R.id.audio_chip)
|
||||
audio.setOnClickListener { view: View? ->
|
||||
if (audio.isChecked) {
|
||||
format = "audio"
|
||||
if (recyclerView!!.visibility == View.GONE) {
|
||||
}
|
||||
downloadsObjects = databaseManager!!.getHistory(searchQuery, format, website, sort)
|
||||
audio.isChecked = true
|
||||
} else {
|
||||
format = ""
|
||||
downloadsObjects = databaseManager!!.getHistory(searchQuery, format, website, sort)
|
||||
audio.isChecked = false
|
||||
}
|
||||
downloadsRecyclerViewAdapter!!.clear()
|
||||
downloadsRecyclerViewAdapter!!.add(downloadsObjects)
|
||||
}
|
||||
val video = fragmentView!!.findViewById<Chip>(R.id.video_chip)
|
||||
video.setOnClickListener { view: View? ->
|
||||
if (video.isChecked) {
|
||||
format = "video"
|
||||
downloadsObjects = databaseManager!!.getHistory(searchQuery, format, website, sort)
|
||||
video.isChecked = true
|
||||
} else {
|
||||
format = ""
|
||||
downloadsObjects = databaseManager!!.getHistory(searchQuery, format, website, sort)
|
||||
video.isChecked = false
|
||||
}
|
||||
downloadsRecyclerViewAdapter!!.clear()
|
||||
downloadsRecyclerViewAdapter!!.add(downloadsObjects)
|
||||
}
|
||||
}
|
||||
|
||||
private fun updateWebsiteChips() {
|
||||
websiteGroup!!.removeAllViews()
|
||||
val websites = downloadsRecyclerViewAdapter!!.websites
|
||||
for (i in websites.indices) {
|
||||
val w = websites[i]
|
||||
val tmp = layoutinflater!!.inflate(R.layout.filter_chip, websiteGroup, false) as Chip
|
||||
tmp.text = w
|
||||
tmp.id = i
|
||||
tmp.setOnClickListener { view: View ->
|
||||
if (tmp.isChecked) {
|
||||
website = tmp.text as String
|
||||
downloadsObjects =
|
||||
databaseManager!!.getHistory(searchQuery, format, website, sort)
|
||||
websiteGroup!!.check(view.id)
|
||||
} else {
|
||||
website = ""
|
||||
downloadsObjects =
|
||||
databaseManager!!.getHistory(searchQuery, format, website, sort)
|
||||
websiteGroup!!.clearCheck()
|
||||
}
|
||||
downloadsRecyclerViewAdapter!!.clear()
|
||||
downloadsRecyclerViewAdapter!!.add(downloadsObjects)
|
||||
}
|
||||
websiteGroup!!.addView(tmp)
|
||||
}
|
||||
}
|
||||
// private fun initChips() {
|
||||
// //sort and history/downloading switch
|
||||
// val sortChip = fragmentView!!.findViewById<Chip>(R.id.sort_chip)
|
||||
// sortChip.setOnClickListener { view: View? ->
|
||||
// sortSheet = BottomSheetDialog(fragmentContext!!)
|
||||
// sortSheet!!.requestWindowFeature(Window.FEATURE_NO_TITLE)
|
||||
// sortSheet!!.setContentView(R.layout.downloads_sort_sheet)
|
||||
// val newest = sortSheet!!.findViewById<TextView>(R.id.newest)
|
||||
// val oldest = sortSheet!!.findViewById<TextView>(R.id.oldest)
|
||||
// newest!!.setOnClickListener { view1: View? ->
|
||||
// sort = "DESC"
|
||||
// downloadsObjects = databaseManager!!.getHistory(searchQuery, format, website, sort)
|
||||
// downloadsRecyclerViewAdapter!!.clear()
|
||||
// downloadsRecyclerViewAdapter!!.add(downloadsObjects)
|
||||
// sortSheet!!.cancel()
|
||||
// }
|
||||
// oldest!!.setOnClickListener { view1: View? ->
|
||||
// sort = "ASC"
|
||||
// downloadsObjects = databaseManager!!.getHistory(searchQuery, format, website, sort)
|
||||
// downloadsRecyclerViewAdapter!!.clear()
|
||||
// downloadsRecyclerViewAdapter!!.add(downloadsObjects)
|
||||
// sortSheet!!.cancel()
|
||||
// }
|
||||
// val cancel = sortSheet!!.findViewById<TextView>(R.id.cancel)
|
||||
// cancel!!.setOnClickListener { view1: View? -> sortSheet!!.cancel() }
|
||||
// sortSheet!!.show()
|
||||
// sortSheet!!.window!!.setLayout(
|
||||
// ViewGroup.LayoutParams.MATCH_PARENT,
|
||||
// ViewGroup.LayoutParams.MATCH_PARENT
|
||||
// )
|
||||
// }
|
||||
//
|
||||
// //format
|
||||
// val audio = fragmentView!!.findViewById<Chip>(R.id.audio_chip)
|
||||
// audio.setOnClickListener { view: View? ->
|
||||
// if (audio.isChecked) {
|
||||
// format = "audio"
|
||||
// if (recyclerView!!.visibility == View.GONE) {
|
||||
// }
|
||||
// downloadsObjects = databaseManager!!.getHistory(searchQuery, format, website, sort)
|
||||
// audio.isChecked = true
|
||||
// } else {
|
||||
// format = ""
|
||||
// downloadsObjects = databaseManager!!.getHistory(searchQuery, format, website, sort)
|
||||
// audio.isChecked = false
|
||||
// }
|
||||
// downloadsRecyclerViewAdapter!!.clear()
|
||||
// downloadsRecyclerViewAdapter!!.add(downloadsObjects)
|
||||
// }
|
||||
// val video = fragmentView!!.findViewById<Chip>(R.id.video_chip)
|
||||
// video.setOnClickListener { view: View? ->
|
||||
// if (video.isChecked) {
|
||||
// format = "video"
|
||||
// downloadsObjects = databaseManager!!.getHistory(searchQuery, format, website, sort)
|
||||
// video.isChecked = true
|
||||
// } else {
|
||||
// format = ""
|
||||
// downloadsObjects = databaseManager!!.getHistory(searchQuery, format, website, sort)
|
||||
// video.isChecked = false
|
||||
// }
|
||||
// downloadsRecyclerViewAdapter!!.clear()
|
||||
// downloadsRecyclerViewAdapter!!.add(downloadsObjects)
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// private fun updateWebsiteChips() {
|
||||
// websiteGroup!!.removeAllViews()
|
||||
// val websites = downloadsRecyclerViewAdapter!!.websites
|
||||
// for (i in websites.indices) {
|
||||
// val w = websites[i]
|
||||
// val tmp = layoutinflater!!.inflate(R.layout.filter_chip, websiteGroup, false) as Chip
|
||||
// tmp.text = w
|
||||
// tmp.id = i
|
||||
// tmp.setOnClickListener { view: View ->
|
||||
// if (tmp.isChecked) {
|
||||
// website = tmp.text as String
|
||||
// downloadsObjects =
|
||||
// databaseManager!!.getHistory(searchQuery, format, website, sort)
|
||||
// websiteGroup!!.check(view.id)
|
||||
// } else {
|
||||
// website = ""
|
||||
// downloadsObjects =
|
||||
// databaseManager!!.getHistory(searchQuery, format, website, sort)
|
||||
// websiteGroup!!.clearCheck()
|
||||
// }
|
||||
// downloadsRecyclerViewAdapter!!.clear()
|
||||
// downloadsRecyclerViewAdapter!!.add(downloadsObjects)
|
||||
// }
|
||||
// websiteGroup!!.addView(tmp)
|
||||
// }
|
||||
// }
|
||||
|
||||
override fun onClick(v: View) {
|
||||
val id = v.id
|
||||
if (id == R.id.bottomsheet_remove_button) {
|
||||
removedownloadsItem(v.tag as Int)
|
||||
} else if (id == R.id.bottom_sheet_link) {
|
||||
openLinkIntent(v.tag as Int)
|
||||
} else if (id == R.id.bottomsheet_open_file_button) {
|
||||
openFileIntent(v.tag as Int)
|
||||
} else if (id == R.id.delete_selected_fab) {
|
||||
removeSelectedItems()
|
||||
}
|
||||
// val id = v.id
|
||||
// if (id == R.id.bottomsheet_remove_button) {
|
||||
// removedownloadsItem(v.tag as Int)
|
||||
// } else if (id == R.id.bottom_sheet_link) {
|
||||
// openLinkIntent(v.tag as Int)
|
||||
// } else if (id == R.id.bottomsheet_open_file_button) {
|
||||
// openFileIntent(v.tag as Int)
|
||||
// } else if (id == R.id.delete_selected_fab) {
|
||||
// removeSelectedItems()
|
||||
// }
|
||||
}
|
||||
|
||||
override fun onLongClick(v: View): Boolean {
|
||||
val id = v.id
|
||||
if (id == R.id.bottom_sheet_link) {
|
||||
copyLinkToClipBoard(v.tag as Int)
|
||||
return true
|
||||
}
|
||||
// val id = v.id
|
||||
// if (id == R.id.bottom_sheet_link) {
|
||||
// copyLinkToClipBoard(v.tag as Int)
|
||||
// return true
|
||||
// }
|
||||
return false
|
||||
}
|
||||
|
||||
private fun removeSelectedItems() {
|
||||
if (bottomSheet != null) bottomSheet!!.hide()
|
||||
val delete_file = booleanArrayOf(false)
|
||||
databaseManager = DatabaseManager(context)
|
||||
val delete_dialog = MaterialAlertDialogBuilder(fragmentContext!!)
|
||||
delete_dialog.setTitle(getString(R.string.you_are_going_to_delete_multiple_items))
|
||||
delete_dialog.setMultiChoiceItems(
|
||||
arrayOf(getString(R.string.delete_files_too)),
|
||||
booleanArrayOf(false)
|
||||
) { dialogInterface: DialogInterface?, i: Int, b: Boolean -> delete_file[0] = b }
|
||||
delete_dialog.setNegativeButton(getString(R.string.cancel)) { dialogInterface: DialogInterface, i: Int -> dialogInterface.cancel() }
|
||||
delete_dialog.setPositiveButton(getString(R.string.ok)) { dialogInterface: DialogInterface?, i: Int ->
|
||||
for (j in selectedObjects!!.indices) {
|
||||
val v = selectedObjects!![j]
|
||||
val position = downloadsObjects!!.indexOf(v)
|
||||
downloadsObjects!!.remove(v)
|
||||
downloadsRecyclerViewAdapter!!.remove(position)
|
||||
databaseManager!!.clearHistoryItem(v, delete_file[0])
|
||||
}
|
||||
updateWebsiteChips()
|
||||
databaseManager!!.close()
|
||||
selectedObjects = ArrayList()
|
||||
downloadsRecyclerViewAdapter!!.clearCheckedVideos()
|
||||
deleteFab!!.visibility = View.GONE
|
||||
if (downloadsObjects!!.size == 0) {
|
||||
uiHandler!!.post {
|
||||
no_results!!.visibility = View.VISIBLE
|
||||
selectionChips!!.visibility = View.GONE
|
||||
websiteGroup!!.removeAllViews()
|
||||
}
|
||||
}
|
||||
}
|
||||
delete_dialog.show()
|
||||
}
|
||||
|
||||
private fun removedownloadsItem(position: Int) {
|
||||
if (bottomSheet != null) bottomSheet!!.hide()
|
||||
val delete_file = booleanArrayOf(false)
|
||||
databaseManager = DatabaseManager(context)
|
||||
val v = downloadsObjects!![position]
|
||||
val delete_dialog = MaterialAlertDialogBuilder(fragmentContext!!)
|
||||
delete_dialog.setTitle(getString(R.string.you_are_going_to_delete) + " \"" + v!!.title + "\"!")
|
||||
delete_dialog.setMultiChoiceItems(
|
||||
arrayOf(getString(R.string.delete_file_too)),
|
||||
booleanArrayOf(false)
|
||||
) { dialogInterface: DialogInterface?, i: Int, b: Boolean -> delete_file[0] = b }
|
||||
delete_dialog.setNegativeButton(getString(R.string.cancel)) { dialogInterface: DialogInterface, i: Int -> dialogInterface.cancel() }
|
||||
delete_dialog.setPositiveButton(getString(R.string.ok)) { dialogInterface: DialogInterface?, i: Int ->
|
||||
downloadsObjects!!.removeAt(position)
|
||||
downloadsRecyclerViewAdapter!!.remove(position)
|
||||
updateWebsiteChips()
|
||||
databaseManager!!.clearHistoryItem(v, delete_file[0])
|
||||
databaseManager!!.close()
|
||||
if (downloadsObjects!!.size == 0) {
|
||||
uiHandler!!.post {
|
||||
no_results!!.visibility = View.VISIBLE
|
||||
selectionChips!!.visibility = View.GONE
|
||||
websiteGroup!!.removeAllViews()
|
||||
}
|
||||
}
|
||||
}
|
||||
delete_dialog.show()
|
||||
}
|
||||
|
||||
private fun copyLinkToClipBoard(position: Int) {
|
||||
val url = downloadsObjects!![position]!!.getURL()
|
||||
val clipboard = context?.getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager
|
||||
val 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 fun openLinkIntent(position: Int) {
|
||||
val url = downloadsObjects!![position]!!.getURL()
|
||||
val i = Intent(Intent.ACTION_VIEW)
|
||||
i.data = Uri.parse(url)
|
||||
if (bottomSheet != null) bottomSheet!!.hide()
|
||||
startActivity(i)
|
||||
}
|
||||
// private fun removeSelectedItems() {
|
||||
// if (bottomSheet != null) bottomSheet!!.hide()
|
||||
// val delete_file = booleanArrayOf(false)
|
||||
// databaseManager = DatabaseManager(context)
|
||||
// val delete_dialog = MaterialAlertDialogBuilder(fragmentContext!!)
|
||||
// delete_dialog.setTitle(getString(R.string.you_are_going_to_delete_multiple_items))
|
||||
// delete_dialog.setMultiChoiceItems(
|
||||
// arrayOf(getString(R.string.delete_files_too)),
|
||||
// booleanArrayOf(false)
|
||||
// ) { dialogInterface: DialogInterface?, i: Int, b: Boolean -> delete_file[0] = b }
|
||||
// delete_dialog.setNegativeButton(getString(R.string.cancel)) { dialogInterface: DialogInterface, i: Int -> dialogInterface.cancel() }
|
||||
// delete_dialog.setPositiveButton(getString(R.string.ok)) { dialogInterface: DialogInterface?, i: Int ->
|
||||
// for (j in selectedObjects!!.indices) {
|
||||
// val v = selectedObjects!![j]
|
||||
// val position = downloadsObjects!!.indexOf(v)
|
||||
// downloadsObjects!!.remove(v)
|
||||
// downloadsRecyclerViewAdapter!!.remove(position)
|
||||
// databaseManager!!.clearHistoryItem(v, delete_file[0])
|
||||
// }
|
||||
// updateWebsiteChips()
|
||||
// databaseManager!!.close()
|
||||
// selectedObjects = ArrayList()
|
||||
// downloadsRecyclerViewAdapter!!.clearCheckedVideos()
|
||||
// deleteFab!!.visibility = View.GONE
|
||||
// if (downloadsObjects!!.size == 0) {
|
||||
// uiHandler!!.post {
|
||||
// no_results!!.visibility = View.VISIBLE
|
||||
// selectionChips!!.visibility = View.GONE
|
||||
// websiteGroup!!.removeAllViews()
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// delete_dialog.show()
|
||||
// }
|
||||
//
|
||||
// private fun removedownloadsItem(position: Int) {
|
||||
// if (bottomSheet != null) bottomSheet!!.hide()
|
||||
// val delete_file = booleanArrayOf(false)
|
||||
// databaseManager = DatabaseManager(context)
|
||||
// val v = downloadsObjects!![position]
|
||||
// val delete_dialog = MaterialAlertDialogBuilder(fragmentContext!!)
|
||||
// delete_dialog.setTitle(getString(R.string.you_are_going_to_delete) + " \"" + v!!.title + "\"!")
|
||||
// delete_dialog.setMultiChoiceItems(
|
||||
// arrayOf(getString(R.string.delete_file_too)),
|
||||
// booleanArrayOf(false)
|
||||
// ) { dialogInterface: DialogInterface?, i: Int, b: Boolean -> delete_file[0] = b }
|
||||
// delete_dialog.setNegativeButton(getString(R.string.cancel)) { dialogInterface: DialogInterface, i: Int -> dialogInterface.cancel() }
|
||||
// delete_dialog.setPositiveButton(getString(R.string.ok)) { dialogInterface: DialogInterface?, i: Int ->
|
||||
// downloadsObjects!!.removeAt(position)
|
||||
// downloadsRecyclerViewAdapter!!.remove(position)
|
||||
// updateWebsiteChips()
|
||||
// databaseManager!!.clearHistoryItem(v, delete_file[0])
|
||||
// databaseManager!!.close()
|
||||
// if (downloadsObjects!!.size == 0) {
|
||||
// uiHandler!!.post {
|
||||
// no_results!!.visibility = View.VISIBLE
|
||||
// selectionChips!!.visibility = View.GONE
|
||||
// websiteGroup!!.removeAllViews()
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// delete_dialog.show()
|
||||
// }
|
||||
//
|
||||
// private fun copyLinkToClipBoard(position: Int) {
|
||||
// val url = downloadsObjects!![position]!!.getURL()
|
||||
// val clipboard = context?.getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager
|
||||
// val 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 fun openLinkIntent(position: Int) {
|
||||
// val url = downloadsObjects!![position]!!.getURL()
|
||||
// val i = Intent(Intent.ACTION_VIEW)
|
||||
// i.data = Uri.parse(url)
|
||||
// if (bottomSheet != null) bottomSheet!!.hide()
|
||||
// startActivity(i)
|
||||
// }
|
||||
|
||||
private fun openFileIntent(position: Int) {
|
||||
val downloadPath = downloadsObjects!![position]!!.downloadPath
|
||||
|
|
@ -493,7 +521,7 @@ class DownloadsFragment : Fragment(), DownloadsRecyclerViewAdapter.OnItemClickLi
|
|||
val author = bottomSheet!!.findViewById<TextView>(R.id.bottom_sheet_author)
|
||||
author!!.text = video.author
|
||||
val link = bottomSheet!!.findViewById<Button>(R.id.bottom_sheet_link)
|
||||
val url = video.getURL()
|
||||
val url = video.url
|
||||
link!!.text = url
|
||||
link.tag = position
|
||||
link.setOnClickListener(this)
|
||||
|
|
@ -504,7 +532,7 @@ class DownloadsFragment : Fragment(), DownloadsRecyclerViewAdapter.OnItemClickLi
|
|||
val openFile = bottomSheet!!.findViewById<Button>(R.id.bottomsheet_open_file_button)
|
||||
openFile!!.tag = position
|
||||
openFile.setOnClickListener(this)
|
||||
if (!isFilePresent) openFile.visibility = View.GONE
|
||||
if (!isFilePresent) openFile.visibility = GONE
|
||||
bottomSheet!!.show()
|
||||
bottomSheet!!.window!!.setLayout(
|
||||
ViewGroup.LayoutParams.MATCH_PARENT,
|
||||
|
|
@ -513,30 +541,30 @@ class DownloadsFragment : Fragment(), DownloadsRecyclerViewAdapter.OnItemClickLi
|
|||
}
|
||||
|
||||
override fun onCardSelect(position: Int, add: Boolean) {
|
||||
val video = downloadsObjects!![position]
|
||||
if (add) selectedObjects!!.add(video) else selectedObjects!!.remove(video)
|
||||
if (selectedObjects!!.size > 1) {
|
||||
deleteFab!!.visibility = View.VISIBLE
|
||||
} else {
|
||||
deleteFab!!.visibility = View.GONE
|
||||
}
|
||||
// val video = downloadsObjects!![position]
|
||||
// if (add) selectedObjects!!.add(video) else selectedObjects!!.remove(video)
|
||||
// if (selectedObjects!!.size > 1) {
|
||||
// deleteFab!!.visibility = View.VISIBLE
|
||||
// } else {
|
||||
// deleteFab!!.visibility = View.GONE
|
||||
// }
|
||||
}
|
||||
|
||||
//
|
||||
override fun onButtonClick(position: Int) {
|
||||
val vid = downloadsObjects!![position]
|
||||
try {
|
||||
mainActivity!!.removeItemFromDownloadQueue(vid, vid!!.downloadedType)
|
||||
} catch (e: Exception) {
|
||||
val info = DownloadInfo()
|
||||
info.video = vid
|
||||
info.downloadType = vid!!.downloadedType
|
||||
}
|
||||
// val vid = downloadsObjects!![position]
|
||||
// try {
|
||||
// mainActivity!!.removeItemFromDownloadQueue(vid, vid!!.downloadedType)
|
||||
// } catch (e: Exception) {
|
||||
// val info = DownloadInfo()
|
||||
// info.video = vid
|
||||
// info.downloadType = vid!!.downloadedType
|
||||
// }
|
||||
}
|
||||
|
||||
fun findVideo(url: String, type: String): Video? {
|
||||
//
|
||||
fun findVideo(url: String, type: String): HistoryItem? {
|
||||
for (i in downloadsObjects!!.indices) {
|
||||
val v = downloadsObjects!![i]
|
||||
if (v!!.getURL() == url && v.downloadedType == type && v.isQueuedDownload) {
|
||||
if (v!!.url == url && v.type == type) {
|
||||
return v
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -100,7 +100,7 @@
|
|||
</HorizontalScrollView>
|
||||
|
||||
<androidx.recyclerview.widget.RecyclerView
|
||||
android:id="@+id/recycler_view_downloads"
|
||||
android:id="@+id/recyclerviewdownloadss"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_below="@+id/chips_recycler_horizontalscrollview"
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ buildscript {
|
|||
|
||||
def versionMajor = 1
|
||||
def versionMinor = 4
|
||||
def versionPatch = 8
|
||||
def versionPatch = 9
|
||||
def versionBuild = 0 // bump for dogfood builds, public betas, etc.
|
||||
|
||||
ext {
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@
|
|||
# The setting is particularly useful for tweaking memory settings.
|
||||
android.enableJetifier=true
|
||||
android.useAndroidX=true
|
||||
org.gradle.jvmargs=-Xmx1536m
|
||||
org.gradle.jvmargs=-Xmx2048m -Dfile.encoding=UTF-8
|
||||
# When configured, Gradle will run in incubating parallel mode.
|
||||
# This option should only be used with decoupled projects. More details, visit
|
||||
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
|
||||
|
|
|
|||
Loading…
Reference in a new issue