mirror of https://github.com/deniscerri/ytdlnis
implemented format inside objects instead of a separate table
parent
ff58bd2dbf
commit
9e5f0e5fab
@ -0,0 +1,29 @@
|
||||
package com.deniscerri.ytdlnis.database
|
||||
|
||||
import androidx.room.TypeConverter
|
||||
import com.deniscerri.ytdlnis.database.models.Format
|
||||
import com.google.gson.Gson
|
||||
import com.google.gson.reflect.TypeToken
|
||||
import java.lang.reflect.Type
|
||||
|
||||
|
||||
class Converters {
|
||||
@TypeConverter
|
||||
fun stringToListOfFormats(value: String?): ArrayList<Format> {
|
||||
val listType: Type = object : TypeToken<ArrayList<Format?>?>() {}.type
|
||||
return Gson().fromJson(value, listType)
|
||||
}
|
||||
|
||||
@TypeConverter
|
||||
fun listOfFormatsToString(list: ArrayList<Format?>?): String {
|
||||
val gson = Gson()
|
||||
return gson.toJson(list)
|
||||
}
|
||||
|
||||
@TypeConverter
|
||||
fun formatToString(format: Format): String = Gson().toJson(format)
|
||||
|
||||
@TypeConverter
|
||||
fun stringToFormat(string: String): Format = Gson().fromJson(string, Format::class.java)
|
||||
|
||||
}
|
||||
@ -1,25 +0,0 @@
|
||||
package com.deniscerri.ytdlnis.database.dao
|
||||
|
||||
import androidx.lifecycle.LiveData
|
||||
import androidx.room.*
|
||||
import com.deniscerri.ytdlnis.database.models.Format
|
||||
import com.deniscerri.ytdlnis.database.models.ResultItem
|
||||
|
||||
@Dao
|
||||
interface FormatDao {
|
||||
@Query("SELECT * FROM formats WHERE itemId=:itemId")
|
||||
fun getFormatsByItemId(itemId: Long) : List<Format>
|
||||
|
||||
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
||||
suspend fun insert(item: Format)
|
||||
|
||||
@Update(onConflict = OnConflictStrategy.REPLACE)
|
||||
suspend fun update(item: Format)
|
||||
|
||||
@Query("DELETE FROM formats")
|
||||
suspend fun deleteAll()
|
||||
|
||||
@Query("DELETE FROM formats WHERE itemId=:itemId")
|
||||
suspend fun deleteFromatsByItemId(itemId: Long)
|
||||
|
||||
}
|
||||
@ -1,20 +1,14 @@
|
||||
package com.deniscerri.ytdlnis.database.models
|
||||
|
||||
import androidx.room.Entity
|
||||
import androidx.room.PrimaryKey
|
||||
import com.google.gson.annotations.SerializedName
|
||||
|
||||
@Entity(tableName = "formats")
|
||||
data class Format(
|
||||
@PrimaryKey(autoGenerate = true)
|
||||
var id: Long = -1,
|
||||
var itemId: Long = 0,
|
||||
@SerializedName(value = "format_id", alternate = ["itag"])
|
||||
val format_id: String = "",
|
||||
var format_id: String = "",
|
||||
@SerializedName(value = "ext", alternate = ["container"])
|
||||
val container: String = "",
|
||||
@SerializedName(value = "filesize", alternate = ["clen", "filesize_approx"])
|
||||
val filesize: Long = 0,
|
||||
@SerializedName(value = "format_note", alternate = ["resolution", "audioQuality"])
|
||||
val format_note: String = ""
|
||||
var format_note: String = ""
|
||||
)
|
||||
@ -1,6 +0,0 @@
|
||||
package com.deniscerri.ytdlnis.database.models
|
||||
|
||||
data class ResultItemWithFormats(
|
||||
val resultItem: ResultItem,
|
||||
var formats: ArrayList<Format>
|
||||
)
|
||||
@ -0,0 +1,36 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
Sample data extraction rules file; uncomment and customize as necessary.
|
||||
See https://developer.android.com/about/versions/12/backup-restore#xml-changes
|
||||
for details.
|
||||
-->
|
||||
<data-extraction-rules>
|
||||
<cloud-backup>
|
||||
<!--
|
||||
TODO: Use <include> and <exclude> to control what is backed up.
|
||||
The domain can be file, database, sharedpref, external or root.
|
||||
Examples:
|
||||
|
||||
<include domain="file" path="file_to_include"/>
|
||||
<exclude domain="file" path="file_to_exclude"/>
|
||||
<include domain="file" path="include_folder"/>
|
||||
<exclude domain="file" path="include_folder/file_to_exclude"/>
|
||||
<exclude domain="file" path="exclude_folder"/>
|
||||
<include domain="file" path="exclude_folder/file_to_include"/>
|
||||
|
||||
<include domain="sharedpref" path="include_shared_pref1.xml"/>
|
||||
<include domain="database" path="db_name/file_to_include"/>
|
||||
<exclude domain="database" path="db_name/include_folder/file_to_exclude"/>
|
||||
<include domain="external" path="file_to_include"/>
|
||||
<exclude domain="external" path="file_to_exclude"/>
|
||||
<include domain="root" path="file_to_include"/>
|
||||
<exclude domain="root" path="file_to_exclude"/>
|
||||
-->
|
||||
</cloud-backup>
|
||||
<!--
|
||||
<device-transfer>
|
||||
<include .../>
|
||||
<exclude .../>
|
||||
</device-transfer>
|
||||
-->
|
||||
</data-extraction-rules>
|
||||
Loading…
Reference in New Issue