removed unimplemented components
This commit is contained in:
parent
94bb83cbe7
commit
6c644b9d7e
6 changed files with 0 additions and 233 deletions
|
|
@ -1,43 +0,0 @@
|
||||||
package com.deniscerri.ytdlnis.database
|
|
||||||
|
|
||||||
import android.content.Context
|
|
||||||
import androidx.room.Database
|
|
||||||
import androidx.room.Room
|
|
||||||
import androidx.room.RoomDatabase
|
|
||||||
import com.deniscerri.ytdlnis.database.dao.HistoryDao
|
|
||||||
import com.deniscerri.ytdlnis.database.dao.ResultDao
|
|
||||||
import com.deniscerri.ytdlnis.database.models.HistoryItem
|
|
||||||
import com.deniscerri.ytdlnis.database.models.ResultItem
|
|
||||||
|
|
||||||
@Database(
|
|
||||||
entities = [ResultItem::class, HistoryItem::class],
|
|
||||||
version = 7,
|
|
||||||
autoMigrations = []
|
|
||||||
)
|
|
||||||
abstract class DBManager : RoomDatabase(){
|
|
||||||
abstract val resultDao : ResultDao
|
|
||||||
abstract val historyDao : HistoryDao
|
|
||||||
|
|
||||||
companion object {
|
|
||||||
@Volatile
|
|
||||||
private var instance : DBManager? = null
|
|
||||||
|
|
||||||
fun getInstance(context: Context) : DBManager {
|
|
||||||
if (instance == null){
|
|
||||||
synchronized(this){
|
|
||||||
instance = buildDatabase(context)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return instance!!
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun buildDatabase(context: Context) : DBManager {
|
|
||||||
return Room.databaseBuilder(
|
|
||||||
context.applicationContext,
|
|
||||||
DBManager::class.java, "ytdlnis_db"
|
|
||||||
)
|
|
||||||
.build();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -1,90 +0,0 @@
|
||||||
package com.deniscerri.ytdlnis.database.dao
|
|
||||||
|
|
||||||
import androidx.room.*
|
|
||||||
import com.deniscerri.ytdlnis.database.models.HistoryItem
|
|
||||||
import com.deniscerri.ytdlnis.util.FileUtil
|
|
||||||
|
|
||||||
@Dao
|
|
||||||
interface HistoryDao {
|
|
||||||
|
|
||||||
@Query("SELECT * FROM history WHERE title LIKE '%'||:query||'%' AND type LIKE '%'||:format||'%' AND website LIKE '%'||:site||'%' ORDER BY " +
|
|
||||||
"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) : List<HistoryItem>
|
|
||||||
|
|
||||||
@Query("SELECT * FROM history WHERE url=:url AND type=:type LIMIT 1")
|
|
||||||
suspend fun getHistoryItemByURLAndType(url: String, type: String) : HistoryItem
|
|
||||||
|
|
||||||
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
|
||||||
suspend fun addToHistory(results: ArrayList<HistoryItem>)
|
|
||||||
|
|
||||||
@Query("DELETE FROM history")
|
|
||||||
suspend fun clearHistory()
|
|
||||||
|
|
||||||
@Query("DELETE FROM history where id=:id")
|
|
||||||
suspend fun deleteItem(id: Int)
|
|
||||||
|
|
||||||
@Transaction
|
|
||||||
suspend fun clearDeletedHistory(){
|
|
||||||
val fileUtil = FileUtil()
|
|
||||||
val items : List<HistoryItem> = getHistory("","","","")
|
|
||||||
items.forEach { item ->
|
|
||||||
if (!fileUtil.exists(item.downloadPath)){
|
|
||||||
clearHistoryItem(item, false)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Transaction
|
|
||||||
suspend fun clearDownloadingHistory(){
|
|
||||||
val items : List<HistoryItem> = getHistory("","","","")
|
|
||||||
items.forEach { item ->
|
|
||||||
if (item.isQueuedDownload == 1){
|
|
||||||
clearHistoryItem(item, false)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Query("DELETE FROM history WHERE id > (SELECT MIN(h.id) FROM history h WHERE h.url = history.url AND h.type = history.type)")
|
|
||||||
suspend fun clearDuplicates()
|
|
||||||
|
|
||||||
@Query("UPDATE results SET downloadedAudio=0, downloadedVideo=0 WHERE downloadedAudio=1 OR downloadedVideo=1")
|
|
||||||
suspend fun removeAllDownloadStatusesFromResults()
|
|
||||||
|
|
||||||
@Query("UPDATE results SET downloadedAudio=0 WHERE downloadedAudio=1 AND url=:url")
|
|
||||||
suspend fun removeAudioDownloadStatusFromOneResult(url: String)
|
|
||||||
|
|
||||||
@Query("UPDATE results SET downloadedVideo=0 WHERE downloadedVideo=1 AND url=:url")
|
|
||||||
suspend fun removeVideoDownloadStatusFromOneResult(url: String)
|
|
||||||
|
|
||||||
@Transaction
|
|
||||||
suspend fun clearDuplicateHistory(){
|
|
||||||
clearDuplicates()
|
|
||||||
removeAllDownloadStatusesFromResults()
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@Transaction
|
|
||||||
suspend fun clearHistoryItem(video: HistoryItem, delete_file : Boolean){
|
|
||||||
if (delete_file){
|
|
||||||
val fileUtil = FileUtil()
|
|
||||||
fileUtil.deleteFile(video.downloadPath)
|
|
||||||
}
|
|
||||||
deleteItem(video.id)
|
|
||||||
when(video.type){
|
|
||||||
"audio" -> removeAudioDownloadStatusFromOneResult(video.url)
|
|
||||||
"video" -> removeVideoDownloadStatusFromOneResult(video.url)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Update
|
|
||||||
suspend fun updateHistoryItem(item: HistoryItem)
|
|
||||||
|
|
||||||
@Transaction
|
|
||||||
suspend fun checkDownloaded(url: String, type: String) : Boolean {
|
|
||||||
val historyItem = getHistoryItemByURLAndType(url, type)
|
|
||||||
val fileUtil = FileUtil()
|
|
||||||
return fileUtil.exists(historyItem.downloadPath)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,21 +0,0 @@
|
||||||
package com.deniscerri.ytdlnis.database.dao
|
|
||||||
|
|
||||||
import androidx.room.*
|
|
||||||
import com.deniscerri.ytdlnis.database.models.ResultItem
|
|
||||||
import com.deniscerri.ytdlnis.util.FileUtil
|
|
||||||
|
|
||||||
@Dao
|
|
||||||
interface ResultDao {
|
|
||||||
|
|
||||||
@Query("SELECT * FROM results")
|
|
||||||
suspend fun getResults() : List<ResultItem>
|
|
||||||
|
|
||||||
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
|
||||||
suspend fun addToResults(results: ArrayList<ResultItem>)
|
|
||||||
|
|
||||||
@Update(onConflict = OnConflictStrategy.REPLACE)
|
|
||||||
suspend fun updateResult(item: ResultItem)
|
|
||||||
|
|
||||||
@Query("DELETE FROM results")
|
|
||||||
suspend fun clearResults()
|
|
||||||
}
|
|
||||||
|
|
@ -1,20 +0,0 @@
|
||||||
package com.deniscerri.ytdlnis.database.models
|
|
||||||
|
|
||||||
import androidx.room.Entity
|
|
||||||
import androidx.room.PrimaryKey
|
|
||||||
|
|
||||||
@Entity(tableName = "history")
|
|
||||||
data class HistoryItem(
|
|
||||||
@PrimaryKey(autoGenerate = true)
|
|
||||||
val id: Int,
|
|
||||||
val url: String,
|
|
||||||
val title: String,
|
|
||||||
val author: String,
|
|
||||||
val duration: String,
|
|
||||||
val thumb: String,
|
|
||||||
val type: String,
|
|
||||||
val time: String,
|
|
||||||
val downloadPath: String,
|
|
||||||
val website: String,
|
|
||||||
val isQueuedDownload: Int
|
|
||||||
)
|
|
||||||
|
|
@ -1,23 +0,0 @@
|
||||||
package com.deniscerri.ytdlnis.database.models
|
|
||||||
|
|
||||||
import androidx.room.Entity
|
|
||||||
import androidx.room.PrimaryKey
|
|
||||||
|
|
||||||
@Entity(tableName = "results")
|
|
||||||
data class ResultItem(
|
|
||||||
@PrimaryKey(autoGenerate = true)
|
|
||||||
val id: Int,
|
|
||||||
val videoId: String,
|
|
||||||
val url: String,
|
|
||||||
val title: String,
|
|
||||||
val author: String,
|
|
||||||
val duration: String,
|
|
||||||
val thumb: String,
|
|
||||||
val downloadedAudio: Int,
|
|
||||||
val downloadedVideo: Int,
|
|
||||||
val isPlaylistItem: Int,
|
|
||||||
val website: String,
|
|
||||||
val downloadingAudio: Int,
|
|
||||||
val downloadingVideo: Int,
|
|
||||||
val playlistTitle: String
|
|
||||||
)
|
|
||||||
|
|
@ -1,36 +0,0 @@
|
||||||
package com.deniscerri.ytdlnis.util;
|
|
||||||
|
|
||||||
import android.app.PendingIntent;
|
|
||||||
import android.content.Context;
|
|
||||||
import android.content.Intent;
|
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
|
||||||
import androidx.work.ForegroundInfo;
|
|
||||||
import androidx.work.Worker;
|
|
||||||
import androidx.work.WorkerParameters;
|
|
||||||
|
|
||||||
import com.deniscerri.ytdlnis.MainActivity;
|
|
||||||
import com.deniscerri.ytdlnis.database.Video;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
|
|
||||||
import kotlin.random.Random;
|
|
||||||
|
|
||||||
public class DownloadWorker extends Worker {
|
|
||||||
private Context context;
|
|
||||||
private WorkerParameters workerParams;
|
|
||||||
public DownloadWorker(
|
|
||||||
@NonNull Context appContext,
|
|
||||||
@NonNull WorkerParameters workerParams) {
|
|
||||||
super(appContext, workerParams);
|
|
||||||
this.context = appContext;
|
|
||||||
this.workerParams = workerParams;
|
|
||||||
}
|
|
||||||
|
|
||||||
@NonNull
|
|
||||||
@Override
|
|
||||||
public Result doWork() {
|
|
||||||
//TODO
|
|
||||||
return Result.success();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Loading…
Reference in a new issue