backend preference wrapper
This commit is contained in:
parent
eb5b83564f
commit
8020b32541
66 changed files with 482 additions and 458 deletions
|
@ -1,17 +1,16 @@
|
|||
package ani.dantotsu.download
|
||||
|
||||
import android.content.Context
|
||||
import android.content.SharedPreferences
|
||||
import android.os.Environment
|
||||
import android.widget.Toast
|
||||
import ani.dantotsu.settings.saving.PrefName
|
||||
import ani.dantotsu.settings.saving.PrefWrapper
|
||||
import com.google.gson.Gson
|
||||
import com.google.gson.reflect.TypeToken
|
||||
import java.io.File
|
||||
import java.io.Serializable
|
||||
|
||||
class DownloadsManager(private val context: Context) {
|
||||
private val prefs: SharedPreferences =
|
||||
context.getSharedPreferences("downloads_pref", Context.MODE_PRIVATE)
|
||||
private val gson = Gson()
|
||||
private val downloadsList = loadDownloads().toMutableList()
|
||||
|
||||
|
@ -24,11 +23,11 @@ class DownloadsManager(private val context: Context) {
|
|||
|
||||
private fun saveDownloads() {
|
||||
val jsonString = gson.toJson(downloadsList)
|
||||
prefs.edit().putString("downloads_key", jsonString).apply()
|
||||
PrefWrapper.setVal(PrefName.DownloadsKeys, jsonString)
|
||||
}
|
||||
|
||||
private fun loadDownloads(): List<DownloadedType> {
|
||||
val jsonString = prefs.getString("downloads_key", null)
|
||||
val jsonString = PrefWrapper.getVal(PrefName.DownloadsKeys, null as String?)
|
||||
return if (jsonString != null) {
|
||||
val type = object : TypeToken<List<DownloadedType>>() {}.type
|
||||
gson.fromJson(jsonString, type)
|
||||
|
|
|
@ -32,6 +32,7 @@ import ani.dantotsu.media.SubtitleDownloader
|
|||
import ani.dantotsu.media.anime.AnimeWatchFragment
|
||||
import ani.dantotsu.parsers.Subtitle
|
||||
import ani.dantotsu.parsers.Video
|
||||
import ani.dantotsu.settings.saving.PrefWrapper
|
||||
import ani.dantotsu.snackString
|
||||
import com.google.firebase.crashlytics.FirebaseCrashlytics
|
||||
import com.google.gson.GsonBuilder
|
||||
|
@ -294,10 +295,7 @@ class AnimeDownloaderService : Service() {
|
|||
builder.setContentText("${task.title} - ${task.episode} Download completed")
|
||||
notificationManager.notify(NOTIFICATION_ID, builder.build())
|
||||
snackString("${task.title} - ${task.episode} Download completed")
|
||||
getSharedPreferences(
|
||||
getString(R.string.anime_downloads),
|
||||
Context.MODE_PRIVATE
|
||||
).edit().putString(
|
||||
PrefWrapper.getAnimeDownloadPreferences().edit().putString(
|
||||
task.getTaskName(),
|
||||
task.video.file.url
|
||||
).apply()
|
||||
|
|
|
@ -12,6 +12,8 @@ import android.widget.LinearLayout
|
|||
import android.widget.TextView
|
||||
import androidx.cardview.widget.CardView
|
||||
import ani.dantotsu.R
|
||||
import ani.dantotsu.settings.saving.PrefName
|
||||
import ani.dantotsu.settings.saving.PrefWrapper
|
||||
|
||||
|
||||
class OfflineAnimeAdapter(
|
||||
|
@ -22,8 +24,7 @@ class OfflineAnimeAdapter(
|
|||
private val inflater: LayoutInflater =
|
||||
context.getSystemService(Context.LAYOUT_INFLATER_SERVICE) as LayoutInflater
|
||||
private var originalItems: List<OfflineAnimeModel> = items
|
||||
private var style =
|
||||
context.getSharedPreferences("Dantotsu", Context.MODE_PRIVATE).getInt("offline_view", 0)
|
||||
private var style = PrefWrapper.getVal(PrefName.OfflineView, 0)
|
||||
|
||||
override fun getCount(): Int {
|
||||
return items.size
|
||||
|
@ -105,8 +106,7 @@ class OfflineAnimeAdapter(
|
|||
}
|
||||
|
||||
fun notifyNewGrid() {
|
||||
style =
|
||||
context.getSharedPreferences("Dantotsu", Context.MODE_PRIVATE).getInt("offline_view", 0)
|
||||
style = PrefWrapper.getVal(PrefName.OfflineView, 0)
|
||||
notifyDataSetChanged()
|
||||
}
|
||||
}
|
|
@ -44,6 +44,8 @@ import ani.dantotsu.navBarHeight
|
|||
import ani.dantotsu.setSafeOnClickListener
|
||||
import ani.dantotsu.settings.SettingsDialogFragment
|
||||
import ani.dantotsu.settings.UserInterfaceSettings
|
||||
import ani.dantotsu.settings.saving.PrefName
|
||||
import ani.dantotsu.settings.saving.PrefWrapper
|
||||
import ani.dantotsu.snackString
|
||||
import com.google.android.material.card.MaterialCardView
|
||||
import com.google.android.material.imageview.ShapeableImageView
|
||||
|
@ -98,12 +100,9 @@ class OfflineAnimeFragment : Fragment(), OfflineAnimeSearchListener {
|
|||
if (!uiSettings.immersiveMode) {
|
||||
view.rootView.fitsSystemWindows = true
|
||||
}
|
||||
val colorOverflow = currContext()?.getSharedPreferences("Dantotsu", Context.MODE_PRIVATE)
|
||||
?.getBoolean("colorOverflow", false) ?: false
|
||||
if (!colorOverflow) {
|
||||
textInputLayout.boxBackgroundColor = (color and 0x00FFFFFF) or 0x28000000.toInt()
|
||||
materialCardView.setCardBackgroundColor((color and 0x00FFFFFF) or 0x28000000.toInt())
|
||||
}
|
||||
|
||||
textInputLayout.boxBackgroundColor = (color and 0x00FFFFFF) or 0x28000000.toInt()
|
||||
materialCardView.setCardBackgroundColor((color and 0x00FFFFFF) or 0x28000000.toInt())
|
||||
|
||||
val searchView = view.findViewById<AutoCompleteTextView>(R.id.animeSearchBarText)
|
||||
searchView.addTextChangedListener(object : TextWatcher {
|
||||
|
@ -117,8 +116,7 @@ class OfflineAnimeFragment : Fragment(), OfflineAnimeSearchListener {
|
|||
onSearchQuery(s.toString())
|
||||
}
|
||||
})
|
||||
var style = context?.getSharedPreferences("Dantotsu", Context.MODE_PRIVATE)
|
||||
?.getInt("offline_view", 0)
|
||||
var style = PrefWrapper.getVal(PrefName.OfflineView, 0)
|
||||
val layoutList = view.findViewById<ImageView>(R.id.downloadedList)
|
||||
val layoutcompact = view.findViewById<ImageView>(R.id.downloadedGrid)
|
||||
var selected = when (style) {
|
||||
|
@ -137,8 +135,7 @@ class OfflineAnimeFragment : Fragment(), OfflineAnimeSearchListener {
|
|||
layoutList.setOnClickListener {
|
||||
selected(it as ImageView)
|
||||
style = 0
|
||||
context?.getSharedPreferences("Dantotsu", Context.MODE_PRIVATE)?.edit()
|
||||
?.putInt("offline_view", style!!)?.apply()
|
||||
PrefWrapper.setVal(PrefName.OfflineView, style)
|
||||
gridView.visibility = View.GONE
|
||||
gridView = view.findViewById(R.id.gridView)
|
||||
adapter.notifyNewGrid()
|
||||
|
@ -148,8 +145,7 @@ class OfflineAnimeFragment : Fragment(), OfflineAnimeSearchListener {
|
|||
layoutcompact.setOnClickListener {
|
||||
selected(it as ImageView)
|
||||
style = 1
|
||||
context?.getSharedPreferences("Dantotsu", Context.MODE_PRIVATE)?.edit()
|
||||
?.putInt("offline_view", style!!)?.apply()
|
||||
PrefWrapper.setVal(PrefName.OfflineView, style)
|
||||
gridView.visibility = View.GONE
|
||||
gridView = view.findViewById(R.id.gridView1)
|
||||
adapter.notifyNewGrid()
|
||||
|
@ -216,11 +212,7 @@ class OfflineAnimeFragment : Fragment(), OfflineAnimeSearchListener {
|
|||
builder.setMessage("Are you sure you want to delete ${item.title}?")
|
||||
builder.setPositiveButton("Yes") { _, _ ->
|
||||
downloadManager.removeMedia(item.title, type)
|
||||
val mediaIds = requireContext().getSharedPreferences(
|
||||
getString(R.string.anime_downloads),
|
||||
Context.MODE_PRIVATE
|
||||
)
|
||||
?.all?.filter { it.key.contains(item.title) }?.values ?: emptySet()
|
||||
val mediaIds = PrefWrapper.getAnimeDownloadPreferences().all?.filter { it.key.contains(item.title) }?.values ?: emptySet()
|
||||
if (mediaIds.isEmpty()) {
|
||||
snackString("No media found") // if this happens, terrible things have happened
|
||||
}
|
||||
|
|
|
@ -11,6 +11,8 @@ import android.widget.LinearLayout
|
|||
import android.widget.TextView
|
||||
import androidx.cardview.widget.CardView
|
||||
import ani.dantotsu.R
|
||||
import ani.dantotsu.settings.saving.PrefName
|
||||
import ani.dantotsu.settings.saving.PrefWrapper
|
||||
|
||||
|
||||
class OfflineMangaAdapter(
|
||||
|
@ -21,8 +23,7 @@ class OfflineMangaAdapter(
|
|||
private val inflater: LayoutInflater =
|
||||
context.getSystemService(Context.LAYOUT_INFLATER_SERVICE) as LayoutInflater
|
||||
private var originalItems: List<OfflineMangaModel> = items
|
||||
private var style =
|
||||
context.getSharedPreferences("Dantotsu", Context.MODE_PRIVATE).getInt("offline_view", 0)
|
||||
private var style = PrefWrapper.getVal(PrefName.OfflineView, 0)
|
||||
|
||||
override fun getCount(): Int {
|
||||
return items.size
|
||||
|
@ -104,8 +105,7 @@ class OfflineMangaAdapter(
|
|||
}
|
||||
|
||||
fun notifyNewGrid() {
|
||||
style =
|
||||
context.getSharedPreferences("Dantotsu", Context.MODE_PRIVATE).getInt("offline_view", 0)
|
||||
style = PrefWrapper.getVal(PrefName.OfflineView, 0)
|
||||
notifyDataSetChanged()
|
||||
}
|
||||
}
|
|
@ -41,6 +41,8 @@ import ani.dantotsu.navBarHeight
|
|||
import ani.dantotsu.setSafeOnClickListener
|
||||
import ani.dantotsu.settings.SettingsDialogFragment
|
||||
import ani.dantotsu.settings.UserInterfaceSettings
|
||||
import ani.dantotsu.settings.saving.PrefName
|
||||
import ani.dantotsu.settings.saving.PrefWrapper
|
||||
import ani.dantotsu.snackString
|
||||
import com.google.android.material.card.MaterialCardView
|
||||
import com.google.android.material.imageview.ShapeableImageView
|
||||
|
@ -91,12 +93,9 @@ class OfflineMangaFragment : Fragment(), OfflineMangaSearchListener {
|
|||
if (!uiSettings.immersiveMode) {
|
||||
view.rootView.fitsSystemWindows = true
|
||||
}
|
||||
val colorOverflow = currContext()?.getSharedPreferences("Dantotsu", Context.MODE_PRIVATE)
|
||||
?.getBoolean("colorOverflow", false) ?: false
|
||||
if (!colorOverflow) {
|
||||
textInputLayout.boxBackgroundColor = (color and 0x00FFFFFF) or 0x28000000.toInt()
|
||||
materialCardView.setCardBackgroundColor((color and 0x00FFFFFF) or 0x28000000.toInt())
|
||||
}
|
||||
|
||||
textInputLayout.boxBackgroundColor = (color and 0x00FFFFFF) or 0x28000000.toInt()
|
||||
materialCardView.setCardBackgroundColor((color and 0x00FFFFFF) or 0x28000000.toInt())
|
||||
|
||||
val searchView = view.findViewById<AutoCompleteTextView>(R.id.animeSearchBarText)
|
||||
searchView.addTextChangedListener(object : TextWatcher {
|
||||
|
@ -110,8 +109,7 @@ class OfflineMangaFragment : Fragment(), OfflineMangaSearchListener {
|
|||
onSearchQuery(s.toString())
|
||||
}
|
||||
})
|
||||
var style = context?.getSharedPreferences("Dantotsu", Context.MODE_PRIVATE)
|
||||
?.getInt("offline_view", 0)
|
||||
var style = PrefWrapper.getVal(PrefName.OfflineView, 0)
|
||||
val layoutList = view.findViewById<ImageView>(R.id.downloadedList)
|
||||
val layoutcompact = view.findViewById<ImageView>(R.id.downloadedGrid)
|
||||
var selected = when (style) {
|
||||
|
@ -130,8 +128,7 @@ class OfflineMangaFragment : Fragment(), OfflineMangaSearchListener {
|
|||
layoutList.setOnClickListener {
|
||||
selected(it as ImageView)
|
||||
style = 0
|
||||
requireContext().getSharedPreferences("Dantotsu", Context.MODE_PRIVATE).edit()
|
||||
.putInt("offline_view", style!!).apply()
|
||||
PrefWrapper.setVal(PrefName.OfflineView, style)
|
||||
gridView.visibility = View.GONE
|
||||
gridView = view.findViewById(R.id.gridView)
|
||||
adapter.notifyNewGrid()
|
||||
|
@ -142,8 +139,7 @@ class OfflineMangaFragment : Fragment(), OfflineMangaSearchListener {
|
|||
layoutcompact.setOnClickListener {
|
||||
selected(it as ImageView)
|
||||
style = 1
|
||||
requireContext().getSharedPreferences("Dantotsu", Context.MODE_PRIVATE).edit()
|
||||
.putInt("offline_view", style!!).apply()
|
||||
PrefWrapper.setVal(PrefName.OfflineView, style)
|
||||
gridView.visibility = View.GONE
|
||||
gridView = view.findViewById(R.id.gridView1)
|
||||
adapter.notifyNewGrid()
|
||||
|
|
|
@ -43,6 +43,7 @@ import ani.dantotsu.parsers.Subtitle
|
|||
import ani.dantotsu.parsers.SubtitleType
|
||||
import ani.dantotsu.parsers.Video
|
||||
import ani.dantotsu.parsers.VideoType
|
||||
import ani.dantotsu.settings.saving.PrefWrapper
|
||||
import eu.kanade.tachiyomi.network.NetworkHelper
|
||||
import uy.kohesive.injekt.Injekt
|
||||
import uy.kohesive.injekt.api.get
|
||||
|
@ -229,19 +230,13 @@ object Helper {
|
|||
DownloadService.sendRemoveDownload(
|
||||
context,
|
||||
ExoplayerDownloadService::class.java,
|
||||
context.getSharedPreferences(
|
||||
getString(context, R.string.anime_downloads),
|
||||
Context.MODE_PRIVATE
|
||||
).getString(
|
||||
PrefWrapper.getAnimeDownloadPreferences().getString(
|
||||
animeDownloadTask.getTaskName(),
|
||||
""
|
||||
) ?: "",
|
||||
false
|
||||
)
|
||||
context.getSharedPreferences(
|
||||
getString(context, R.string.anime_downloads),
|
||||
Context.MODE_PRIVATE
|
||||
).edit()
|
||||
PrefWrapper.getAnimeDownloadPreferences().edit()
|
||||
.remove(animeDownloadTask.getTaskName())
|
||||
.apply()
|
||||
downloadsManger.removeDownload(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue