backend preference wrapper

This commit is contained in:
rebelonion 2024-01-30 00:39:12 -06:00
parent eb5b83564f
commit 8020b32541
66 changed files with 482 additions and 458 deletions

View file

@ -14,6 +14,8 @@ import ani.dantotsu.parsers.MangaSources
import ani.dantotsu.parsers.NovelSources import ani.dantotsu.parsers.NovelSources
import ani.dantotsu.parsers.novel.NovelExtensionManager import ani.dantotsu.parsers.novel.NovelExtensionManager
import ani.dantotsu.settings.SettingsActivity import ani.dantotsu.settings.SettingsActivity
import ani.dantotsu.settings.saving.PrefName
import ani.dantotsu.settings.saving.PrefWrapper
import com.google.android.material.color.DynamicColors import com.google.android.material.color.DynamicColors
import com.google.firebase.crashlytics.FirebaseCrashlytics import com.google.firebase.crashlytics.FirebaseCrashlytics
import com.google.firebase.crashlytics.ktx.crashlytics import com.google.firebase.crashlytics.ktx.crashlytics
@ -51,8 +53,10 @@ class App : MultiDexApplication() {
override fun onCreate() { override fun onCreate() {
super.onCreate() super.onCreate()
val sharedPreferences = getSharedPreferences("Dantotsu", Context.MODE_PRIVATE)
val useMaterialYou = sharedPreferences.getBoolean("use_material_you", false) PrefWrapper.init(this)
val useMaterialYou = PrefWrapper.getVal(PrefName.UseMaterialYou, false)
if (useMaterialYou) { if (useMaterialYou) {
DynamicColors.applyToActivitiesIfAvailable(this) DynamicColors.applyToActivitiesIfAvailable(this)
//TODO: HarmonizedColors //TODO: HarmonizedColors
@ -60,19 +64,10 @@ class App : MultiDexApplication() {
registerActivityLifecycleCallbacks(mFTActivityLifecycleCallbacks) registerActivityLifecycleCallbacks(mFTActivityLifecycleCallbacks)
Firebase.crashlytics.setCrashlyticsCollectionEnabled(!DisabledReports) Firebase.crashlytics.setCrashlyticsCollectionEnabled(!DisabledReports)
getSharedPreferences( PrefWrapper.getVal(PrefName.SharedUserID, true).let {
getString(R.string.preference_file_key),
Context.MODE_PRIVATE
).getBoolean("shared_user_id", true).let {
if (!it) return@let if (!it) return@let
val dUsername = getSharedPreferences( val dUsername = PrefWrapper.getVal(PrefName.DiscordUserName, null as String?)
getString(R.string.preference_file_key), val aUsername = PrefWrapper.getVal(PrefName.AnilistUserName, null as String?)
Context.MODE_PRIVATE
).getString("discord_username", null)
val aUsername = getSharedPreferences(
getString(R.string.preference_file_key),
Context.MODE_PRIVATE
).getString("anilist_username", null)
if (dUsername != null || aUsername != null) { if (dUsername != null || aUsername != null) {
Firebase.crashlytics.setUserId("$dUsername - $aUsername") Firebase.crashlytics.setUserId("$dUsername - $aUsername")
} }
@ -104,7 +99,7 @@ class App : MultiDexApplication() {
mangaScope.launch { mangaScope.launch {
mangaExtensionManager.findAvailableExtensions() mangaExtensionManager.findAvailableExtensions()
logger("Manga Extensions: ${mangaExtensionManager.installedExtensionsFlow.first()}") logger("Manga Extensions: ${mangaExtensionManager.installedExtensionsFlow.first()}")
MangaSources.init(mangaExtensionManager.installedExtensionsFlow, this@App) MangaSources.init(mangaExtensionManager.installedExtensionsFlow)
} }
val novelScope = CoroutineScope(Dispatchers.Default) val novelScope = CoroutineScope(Dispatchers.Default)
novelScope.launch { novelScope.launch {

View file

@ -48,6 +48,8 @@ import ani.dantotsu.databinding.ItemCountDownBinding
import ani.dantotsu.media.Media import ani.dantotsu.media.Media
import ani.dantotsu.parsers.ShowResponse import ani.dantotsu.parsers.ShowResponse
import ani.dantotsu.settings.UserInterfaceSettings import ani.dantotsu.settings.UserInterfaceSettings
import ani.dantotsu.settings.saving.PrefName
import ani.dantotsu.settings.saving.PrefWrapper
import ani.dantotsu.subcriptions.NotificationClickReceiver import ani.dantotsu.subcriptions.NotificationClickReceiver
import com.bumptech.glide.Glide import com.bumptech.glide.Glide
import com.bumptech.glide.load.model.GlideUrl import com.bumptech.glide.load.model.GlideUrl
@ -966,8 +968,7 @@ const val INCOGNITO_CHANNEL_ID = 26
fun incognitoNotification(context: Context) { fun incognitoNotification(context: Context) {
val notificationManager = val notificationManager =
context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
val incognito = context.getSharedPreferences("Dantotsu", Context.MODE_PRIVATE) val incognito = PrefWrapper.getVal(PrefName.Incognito, false)
.getBoolean("incognito", false)
if (incognito) { if (incognito) {
val intent = Intent(context, NotificationClickReceiver::class.java) val intent = Intent(context, NotificationClickReceiver::class.java)
val pendingIntent = PendingIntent.getBroadcast( val pendingIntent = PendingIntent.getBroadcast(

View file

@ -2,7 +2,6 @@ package ani.dantotsu
import android.animation.ObjectAnimator import android.animation.ObjectAnimator
import android.annotation.SuppressLint import android.annotation.SuppressLint
import android.content.Context
import android.content.Intent import android.content.Intent
import android.graphics.drawable.Animatable import android.graphics.drawable.Animatable
import android.graphics.drawable.GradientDrawable import android.graphics.drawable.GradientDrawable
@ -45,9 +44,11 @@ import ani.dantotsu.home.MangaFragment
import ani.dantotsu.home.NoInternet import ani.dantotsu.home.NoInternet
import ani.dantotsu.media.MediaDetailsActivity import ani.dantotsu.media.MediaDetailsActivity
import ani.dantotsu.others.CustomBottomDialog import ani.dantotsu.others.CustomBottomDialog
import ani.dantotsu.others.LangSet
import ani.dantotsu.others.SharedPreferenceBooleanLiveData
import ani.dantotsu.settings.UserInterfaceSettings import ani.dantotsu.settings.UserInterfaceSettings
import ani.dantotsu.settings.saving.PrefName
import ani.dantotsu.settings.saving.PrefWrapper
import ani.dantotsu.settings.saving.PrefWrapper.asLiveBool
import ani.dantotsu.settings.saving.SharedPreferenceBooleanLiveData
import ani.dantotsu.subcriptions.Subscription.Companion.startSubscription import ani.dantotsu.subcriptions.Subscription.Companion.startSubscription
import ani.dantotsu.themes.ThemeManager import ani.dantotsu.themes.ThemeManager
import eu.kanade.domain.source.service.SourcePreferences import eu.kanade.domain.source.service.SourcePreferences
@ -77,7 +78,7 @@ class MainActivity : AppCompatActivity() {
@OptIn(UnstableApi::class) @OptIn(UnstableApi::class)
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
ThemeManager(this).applyTheme() ThemeManager(this).applyTheme()
LangSet.setLocale(this)
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
//get FRAGMENT_CLASS_NAME from intent //get FRAGMENT_CLASS_NAME from intent
@ -95,12 +96,8 @@ class MainActivity : AppCompatActivity() {
backgroundDrawable.setColor(semiTransparentColor) backgroundDrawable.setColor(semiTransparentColor)
_bottomBar.background = backgroundDrawable _bottomBar.background = backgroundDrawable
} }
val sharedPreferences = getSharedPreferences("Dantotsu", Context.MODE_PRIVATE) _bottomBar.background = ContextCompat.getDrawable(this, R.drawable.bottom_nav_gray)
val colorOverflow = sharedPreferences.getBoolean("colorOverflow", false)
if (!colorOverflow) {
_bottomBar.background = ContextCompat.getDrawable(this, R.drawable.bottom_nav_gray)
}
val offset = try { val offset = try {
val statusBarHeightId = resources.getIdentifier("status_bar_height", "dimen", "android") val statusBarHeightId = resources.getIdentifier("status_bar_height", "dimen", "android")
@ -111,11 +108,10 @@ class MainActivity : AppCompatActivity() {
val layoutParams = binding.incognito.layoutParams as ViewGroup.MarginLayoutParams val layoutParams = binding.incognito.layoutParams as ViewGroup.MarginLayoutParams
layoutParams.topMargin = 11 * offset / 12 layoutParams.topMargin = 11 * offset / 12
binding.incognito.layoutParams = layoutParams binding.incognito.layoutParams = layoutParams
incognitoLiveData = SharedPreferenceBooleanLiveData( incognitoLiveData = PrefWrapper.getLiveVal(
sharedPreferences, PrefName.Incognito,
"incognito",
false false
) ).asLiveBool()
incognitoLiveData.observe(this) { incognitoLiveData.observe(this) {
if (it) { if (it) {
val slideDownAnim = ObjectAnimator.ofFloat( val slideDownAnim = ObjectAnimator.ofFloat(
@ -228,8 +224,7 @@ class MainActivity : AppCompatActivity() {
} }
} }
val offlineMode = getSharedPreferences("Dantotsu", Context.MODE_PRIVATE) val offlineMode = PrefWrapper.getVal(PrefName.OfflineMode, false)
.getBoolean("offlineMode", false)
if (!isOnline(this)) { if (!isOnline(this)) {
snackString(this@MainActivity.getString(R.string.no_internet_connection)) snackString(this@MainActivity.getString(R.string.no_internet_connection))
startActivity(Intent(this, NoInternet::class.java)) startActivity(Intent(this, NoInternet::class.java))

View file

@ -45,9 +45,6 @@ class AppModule(val app: Application) : InjektModule {
addSingletonFactory<AnimeSourceManager> { AndroidAnimeSourceManager(app, get()) } addSingletonFactory<AnimeSourceManager> { AndroidAnimeSourceManager(app, get()) }
addSingletonFactory<MangaSourceManager> { AndroidMangaSourceManager(app, get()) } addSingletonFactory<MangaSourceManager> { AndroidMangaSourceManager(app, get()) }
val sharedPreferences = app.getSharedPreferences("Dantotsu", Context.MODE_PRIVATE)
addSingleton(sharedPreferences)
addSingletonFactory { addSingletonFactory {
Json { Json {
ignoreUnknownKeys = true ignoreUnknownKeys = true

View file

@ -6,14 +6,15 @@ import ani.dantotsu.connections.anilist.Anilist
import ani.dantotsu.connections.mal.MAL import ani.dantotsu.connections.mal.MAL
import ani.dantotsu.currContext import ani.dantotsu.currContext
import ani.dantotsu.media.Media import ani.dantotsu.media.Media
import ani.dantotsu.settings.saving.PrefName
import ani.dantotsu.settings.saving.PrefWrapper
import ani.dantotsu.toast import ani.dantotsu.toast
import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
fun updateProgress(media: Media, number: String) { fun updateProgress(media: Media, number: String) {
val incognito = currContext()?.getSharedPreferences("Dantotsu", 0) val incognito = PrefWrapper.getVal(PrefName.Incognito, false)
?.getBoolean("incognito", false) ?: false
if (!incognito) { if (!incognito) {
if (Anilist.userid != null) { if (Anilist.userid != null) {
CoroutineScope(Dispatchers.IO).launch { CoroutineScope(Dispatchers.IO).launch {

View file

@ -1,7 +1,6 @@
package ani.dantotsu.connections.anilist package ani.dantotsu.connections.anilist
import android.app.Activity import android.app.Activity
import android.content.Context
import ani.dantotsu.R import ani.dantotsu.R
import ani.dantotsu.checkGenreTime import ani.dantotsu.checkGenreTime
import ani.dantotsu.checkId import ani.dantotsu.checkId
@ -20,6 +19,8 @@ import ani.dantotsu.media.Media
import ani.dantotsu.media.Studio import ani.dantotsu.media.Studio
import ani.dantotsu.others.MalScraper import ani.dantotsu.others.MalScraper
import ani.dantotsu.saveData import ani.dantotsu.saveData
import ani.dantotsu.settings.saving.PrefName
import ani.dantotsu.settings.saving.PrefWrapper
import ani.dantotsu.snackString import ani.dantotsu.snackString
import kotlinx.coroutines.async import kotlinx.coroutines.async
import kotlinx.coroutines.awaitAll import kotlinx.coroutines.awaitAll
@ -35,15 +36,7 @@ class AnilistQueries {
}.also { println("time : $it") } }.also { println("time : $it") }
val user = response?.data?.user ?: return false val user = response?.data?.user ?: return false
currContext()?.let { PrefWrapper.setVal(PrefName.AnilistUserName, user.name)
it.getSharedPreferences(
it.getString(R.string.preference_file_key),
Context.MODE_PRIVATE
)
.edit()
.putString("anilist_username", user.name)
.apply()
}
Anilist.userid = user.id Anilist.userid = user.id
Anilist.username = user.name Anilist.username = user.name
@ -424,9 +417,9 @@ class AnilistQueries {
sorted["Favourites"]?.sortWith(compareBy { it.userFavOrder }) sorted["Favourites"]?.sortWith(compareBy { it.userFavOrder })
sorted["All"] = all sorted["All"] = all
val listsort = currContext()?.getSharedPreferences("Dantotsu", Context.MODE_PRIVATE) val listSort = if (anime) PrefWrapper.getVal(PrefName.AnimeListSortOrder, "score")
?.getString("sort_order", "score") else PrefWrapper.getVal(PrefName.MangaListSortOrder, "score")
val sort = listsort ?: sortOrder ?: options?.rowOrder val sort = listSort ?: sortOrder ?: options?.rowOrder
for (i in sorted.keys) { for (i in sorted.keys) {
when (sort) { when (sort) {
"score" -> sorted[i]?.sortWith { b, a -> "score" -> sorted[i]?.sortWith { b, a ->

View file

@ -11,6 +11,8 @@ import ani.dantotsu.connections.mal.MAL
import ani.dantotsu.loadData import ani.dantotsu.loadData
import ani.dantotsu.media.Media import ani.dantotsu.media.Media
import ani.dantotsu.others.AppUpdater import ani.dantotsu.others.AppUpdater
import ani.dantotsu.settings.saving.PrefName
import ani.dantotsu.settings.saving.PrefWrapper
import ani.dantotsu.snackString import ani.dantotsu.snackString
import ani.dantotsu.tryWithSuspend import ani.dantotsu.tryWithSuspend
import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.CoroutineScope
@ -19,12 +21,8 @@ import kotlinx.coroutines.launch
suspend fun getUserId(context: Context, block: () -> Unit) { suspend fun getUserId(context: Context, block: () -> Unit) {
CoroutineScope(Dispatchers.IO).launch { CoroutineScope(Dispatchers.IO).launch {
val sharedPref = context.getSharedPreferences( val token = PrefWrapper.getVal(PrefName.DiscordToken, null as String?)
context.getString(R.string.preference_file_key), val userid = PrefWrapper.getVal(PrefName.DiscordId, null as String?)
Context.MODE_PRIVATE
)
val token = sharedPref.getString("discord_token", null)
val userid = sharedPref.getString("discord_id", null)
if (userid == null && token != null) { if (userid == null && token != null) {
/*if (!Discord.getUserData()) /*if (!Discord.getUserData())
snackString(context.getString(R.string.error_loading_discord_user_data))*/ snackString(context.getString(R.string.error_loading_discord_user_data))*/

View file

@ -6,14 +6,13 @@ import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity import androidx.appcompat.app.AppCompatActivity
import ani.dantotsu.logError import ani.dantotsu.logError
import ani.dantotsu.logger import ani.dantotsu.logger
import ani.dantotsu.others.LangSet
import ani.dantotsu.startMainActivity import ani.dantotsu.startMainActivity
import ani.dantotsu.themes.ThemeManager import ani.dantotsu.themes.ThemeManager
class Login : AppCompatActivity() { class Login : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
LangSet.setLocale(this)
ThemeManager(this).applyTheme() ThemeManager(this).applyTheme()
val data: Uri? = intent?.data val data: Uri? = intent?.data
logger(data.toString()) logger(data.toString())

View file

@ -5,14 +5,13 @@ import android.net.Uri
import android.os.Bundle import android.os.Bundle
import androidx.core.os.bundleOf import androidx.core.os.bundleOf
import ani.dantotsu.loadMedia import ani.dantotsu.loadMedia
import ani.dantotsu.others.LangSet
import ani.dantotsu.startMainActivity import ani.dantotsu.startMainActivity
import ani.dantotsu.themes.ThemeManager import ani.dantotsu.themes.ThemeManager
class UrlMedia : Activity() { class UrlMedia : Activity() {
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
LangSet.setLocale(this)
ThemeManager(this).applyTheme() ThemeManager(this).applyTheme()
var id: Int? = intent?.extras?.getInt("media", 0) ?: 0 var id: Int? = intent?.extras?.getInt("media", 0) ?: 0
var isMAL = false var isMAL = false

View file

@ -6,6 +6,8 @@ import android.widget.TextView
import androidx.core.content.edit import androidx.core.content.edit
import ani.dantotsu.R import ani.dantotsu.R
import ani.dantotsu.others.CustomBottomDialog import ani.dantotsu.others.CustomBottomDialog
import ani.dantotsu.settings.saving.PrefName
import ani.dantotsu.settings.saving.PrefWrapper
import ani.dantotsu.toast import ani.dantotsu.toast
import ani.dantotsu.tryWith import ani.dantotsu.tryWith
import io.noties.markwon.Markwon import io.noties.markwon.Markwon
@ -18,37 +20,19 @@ object Discord {
var userid: String? = null var userid: String? = null
var avatar: String? = null var avatar: String? = null
const val TOKEN = "discord_token"
fun getSavedToken(context: Context): Boolean { fun getSavedToken(context: Context): Boolean {
val sharedPref = context.getSharedPreferences( token = PrefWrapper.getVal(
context.getString(R.string.preference_file_key), PrefName.DiscordToken, null as String?)
Context.MODE_PRIVATE
)
token = sharedPref.getString(TOKEN, null)
return token != null return token != null
} }
fun saveToken(context: Context, token: String) { fun saveToken(context: Context, token: String) {
val sharedPref = context.getSharedPreferences( PrefWrapper.setVal(PrefName.DiscordToken, token)
context.getString(R.string.preference_file_key),
Context.MODE_PRIVATE
)
sharedPref.edit {
putString(TOKEN, token)
commit()
}
} }
fun removeSavedToken(context: Context) { fun removeSavedToken(context: Context) {
val sharedPref = context.getSharedPreferences( PrefWrapper.removeVal(PrefName.DiscordToken)
context.getString(R.string.preference_file_key),
Context.MODE_PRIVATE
)
sharedPref.edit {
remove(TOKEN)
commit()
}
tryWith(true) { tryWith(true) {
val dir = File(context.filesDir?.parentFile, "app_webview") val dir = File(context.filesDir?.parentFile, "app_webview")

View file

@ -24,6 +24,8 @@ import ani.dantotsu.R
import ani.dantotsu.connections.discord.serializers.Presence import ani.dantotsu.connections.discord.serializers.Presence
import ani.dantotsu.connections.discord.serializers.User import ani.dantotsu.connections.discord.serializers.User
import ani.dantotsu.isOnline import ani.dantotsu.isOnline
import ani.dantotsu.settings.saving.PrefName
import ani.dantotsu.settings.saving.PrefWrapper
import com.google.gson.JsonArray import com.google.gson.JsonArray
import com.google.gson.JsonObject import com.google.gson.JsonObject
import com.google.gson.JsonParser import com.google.gson.JsonParser
@ -149,19 +151,11 @@ class DiscordService : Service() {
} }
fun saveProfile(response: String) { fun saveProfile(response: String) {
val sharedPref = baseContext.getSharedPreferences(
baseContext.getString(R.string.preference_file_key),
Context.MODE_PRIVATE
)
val user = json.decodeFromString<User.Response>(response).d.user val user = json.decodeFromString<User.Response>(response).d.user
log("User data: $user") log("User data: $user")
with(sharedPref.edit()) { PrefWrapper.setVal(PrefName.DiscordUserName, user.username)
putString("discord_username", user.username) PrefWrapper.setVal(PrefName.DiscordId, user.id)
putString("discord_id", user.id) PrefWrapper.setVal(PrefName.DiscordAvatar, user.avatar)
putString("discord_avatar", user.avatar)
apply()
}
} }
override fun onBind(p0: Intent?): IBinder? = null override fun onBind(p0: Intent?): IBinder? = null
@ -318,17 +312,13 @@ class DiscordService : Service() {
} }
fun getToken(context: Context): String { fun getToken(context: Context): String {
val sharedPref = context.getSharedPreferences( val token = PrefWrapper.getVal(PrefName.DiscordToken, null as String?)
context.getString(R.string.preference_file_key), return if (token == null) {
Context.MODE_PRIVATE
)
val token = sharedPref.getString(Discord.TOKEN, null)
if (token == null) {
log("WebSocket: Token not found") log("WebSocket: Token not found")
errorNotification("Could not set the presence", "token not found") errorNotification("Could not set the presence", "token not found")
return "" ""
} else { } else {
return token token
} }
} }

View file

@ -11,7 +11,6 @@ import android.widget.Toast
import androidx.appcompat.app.AppCompatActivity import androidx.appcompat.app.AppCompatActivity
import ani.dantotsu.R import ani.dantotsu.R
import ani.dantotsu.connections.discord.Discord.saveToken import ani.dantotsu.connections.discord.Discord.saveToken
import ani.dantotsu.others.LangSet
import ani.dantotsu.startMainActivity import ani.dantotsu.startMainActivity
import ani.dantotsu.themes.ThemeManager import ani.dantotsu.themes.ThemeManager
@ -20,7 +19,7 @@ class Login : AppCompatActivity() {
@SuppressLint("SetJavaScriptEnabled") @SuppressLint("SetJavaScriptEnabled")
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
LangSet.setLocale(this)
ThemeManager(this).applyTheme() ThemeManager(this).applyTheme()
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
val process = getProcessName() val process = getProcessName()

View file

@ -10,7 +10,6 @@ import ani.dantotsu.connections.mal.MAL.clientId
import ani.dantotsu.connections.mal.MAL.saveResponse import ani.dantotsu.connections.mal.MAL.saveResponse
import ani.dantotsu.loadData import ani.dantotsu.loadData
import ani.dantotsu.logError import ani.dantotsu.logError
import ani.dantotsu.others.LangSet
import ani.dantotsu.snackString import ani.dantotsu.snackString
import ani.dantotsu.startMainActivity import ani.dantotsu.startMainActivity
import ani.dantotsu.themes.ThemeManager import ani.dantotsu.themes.ThemeManager
@ -21,7 +20,7 @@ import kotlinx.coroutines.launch
class Login : AppCompatActivity() { class Login : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
LangSet.setLocale(this)
ThemeManager(this).applyTheme() ThemeManager(this).applyTheme()
try { try {
val data: Uri = intent?.data val data: Uri = intent?.data

View file

@ -1,17 +1,16 @@
package ani.dantotsu.download package ani.dantotsu.download
import android.content.Context import android.content.Context
import android.content.SharedPreferences
import android.os.Environment import android.os.Environment
import android.widget.Toast 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.Gson
import com.google.gson.reflect.TypeToken import com.google.gson.reflect.TypeToken
import java.io.File import java.io.File
import java.io.Serializable import java.io.Serializable
class DownloadsManager(private val context: Context) { class DownloadsManager(private val context: Context) {
private val prefs: SharedPreferences =
context.getSharedPreferences("downloads_pref", Context.MODE_PRIVATE)
private val gson = Gson() private val gson = Gson()
private val downloadsList = loadDownloads().toMutableList() private val downloadsList = loadDownloads().toMutableList()
@ -24,11 +23,11 @@ class DownloadsManager(private val context: Context) {
private fun saveDownloads() { private fun saveDownloads() {
val jsonString = gson.toJson(downloadsList) val jsonString = gson.toJson(downloadsList)
prefs.edit().putString("downloads_key", jsonString).apply() PrefWrapper.setVal(PrefName.DownloadsKeys, jsonString)
} }
private fun loadDownloads(): List<DownloadedType> { 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) { return if (jsonString != null) {
val type = object : TypeToken<List<DownloadedType>>() {}.type val type = object : TypeToken<List<DownloadedType>>() {}.type
gson.fromJson(jsonString, type) gson.fromJson(jsonString, type)

View file

@ -32,6 +32,7 @@ import ani.dantotsu.media.SubtitleDownloader
import ani.dantotsu.media.anime.AnimeWatchFragment import ani.dantotsu.media.anime.AnimeWatchFragment
import ani.dantotsu.parsers.Subtitle import ani.dantotsu.parsers.Subtitle
import ani.dantotsu.parsers.Video import ani.dantotsu.parsers.Video
import ani.dantotsu.settings.saving.PrefWrapper
import ani.dantotsu.snackString import ani.dantotsu.snackString
import com.google.firebase.crashlytics.FirebaseCrashlytics import com.google.firebase.crashlytics.FirebaseCrashlytics
import com.google.gson.GsonBuilder import com.google.gson.GsonBuilder
@ -294,10 +295,7 @@ class AnimeDownloaderService : Service() {
builder.setContentText("${task.title} - ${task.episode} Download completed") builder.setContentText("${task.title} - ${task.episode} Download completed")
notificationManager.notify(NOTIFICATION_ID, builder.build()) notificationManager.notify(NOTIFICATION_ID, builder.build())
snackString("${task.title} - ${task.episode} Download completed") snackString("${task.title} - ${task.episode} Download completed")
getSharedPreferences( PrefWrapper.getAnimeDownloadPreferences().edit().putString(
getString(R.string.anime_downloads),
Context.MODE_PRIVATE
).edit().putString(
task.getTaskName(), task.getTaskName(),
task.video.file.url task.video.file.url
).apply() ).apply()

View file

@ -12,6 +12,8 @@ import android.widget.LinearLayout
import android.widget.TextView import android.widget.TextView
import androidx.cardview.widget.CardView import androidx.cardview.widget.CardView
import ani.dantotsu.R import ani.dantotsu.R
import ani.dantotsu.settings.saving.PrefName
import ani.dantotsu.settings.saving.PrefWrapper
class OfflineAnimeAdapter( class OfflineAnimeAdapter(
@ -22,8 +24,7 @@ class OfflineAnimeAdapter(
private val inflater: LayoutInflater = private val inflater: LayoutInflater =
context.getSystemService(Context.LAYOUT_INFLATER_SERVICE) as LayoutInflater context.getSystemService(Context.LAYOUT_INFLATER_SERVICE) as LayoutInflater
private var originalItems: List<OfflineAnimeModel> = items private var originalItems: List<OfflineAnimeModel> = items
private var style = private var style = PrefWrapper.getVal(PrefName.OfflineView, 0)
context.getSharedPreferences("Dantotsu", Context.MODE_PRIVATE).getInt("offline_view", 0)
override fun getCount(): Int { override fun getCount(): Int {
return items.size return items.size
@ -105,8 +106,7 @@ class OfflineAnimeAdapter(
} }
fun notifyNewGrid() { fun notifyNewGrid() {
style = style = PrefWrapper.getVal(PrefName.OfflineView, 0)
context.getSharedPreferences("Dantotsu", Context.MODE_PRIVATE).getInt("offline_view", 0)
notifyDataSetChanged() notifyDataSetChanged()
} }
} }

View file

@ -44,6 +44,8 @@ import ani.dantotsu.navBarHeight
import ani.dantotsu.setSafeOnClickListener import ani.dantotsu.setSafeOnClickListener
import ani.dantotsu.settings.SettingsDialogFragment import ani.dantotsu.settings.SettingsDialogFragment
import ani.dantotsu.settings.UserInterfaceSettings import ani.dantotsu.settings.UserInterfaceSettings
import ani.dantotsu.settings.saving.PrefName
import ani.dantotsu.settings.saving.PrefWrapper
import ani.dantotsu.snackString import ani.dantotsu.snackString
import com.google.android.material.card.MaterialCardView import com.google.android.material.card.MaterialCardView
import com.google.android.material.imageview.ShapeableImageView import com.google.android.material.imageview.ShapeableImageView
@ -98,12 +100,9 @@ class OfflineAnimeFragment : Fragment(), OfflineAnimeSearchListener {
if (!uiSettings.immersiveMode) { if (!uiSettings.immersiveMode) {
view.rootView.fitsSystemWindows = true view.rootView.fitsSystemWindows = true
} }
val colorOverflow = currContext()?.getSharedPreferences("Dantotsu", Context.MODE_PRIVATE)
?.getBoolean("colorOverflow", false) ?: false textInputLayout.boxBackgroundColor = (color and 0x00FFFFFF) or 0x28000000.toInt()
if (!colorOverflow) { 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) val searchView = view.findViewById<AutoCompleteTextView>(R.id.animeSearchBarText)
searchView.addTextChangedListener(object : TextWatcher { searchView.addTextChangedListener(object : TextWatcher {
@ -117,8 +116,7 @@ class OfflineAnimeFragment : Fragment(), OfflineAnimeSearchListener {
onSearchQuery(s.toString()) onSearchQuery(s.toString())
} }
}) })
var style = context?.getSharedPreferences("Dantotsu", Context.MODE_PRIVATE) var style = PrefWrapper.getVal(PrefName.OfflineView, 0)
?.getInt("offline_view", 0)
val layoutList = view.findViewById<ImageView>(R.id.downloadedList) val layoutList = view.findViewById<ImageView>(R.id.downloadedList)
val layoutcompact = view.findViewById<ImageView>(R.id.downloadedGrid) val layoutcompact = view.findViewById<ImageView>(R.id.downloadedGrid)
var selected = when (style) { var selected = when (style) {
@ -137,8 +135,7 @@ class OfflineAnimeFragment : Fragment(), OfflineAnimeSearchListener {
layoutList.setOnClickListener { layoutList.setOnClickListener {
selected(it as ImageView) selected(it as ImageView)
style = 0 style = 0
context?.getSharedPreferences("Dantotsu", Context.MODE_PRIVATE)?.edit() PrefWrapper.setVal(PrefName.OfflineView, style)
?.putInt("offline_view", style!!)?.apply()
gridView.visibility = View.GONE gridView.visibility = View.GONE
gridView = view.findViewById(R.id.gridView) gridView = view.findViewById(R.id.gridView)
adapter.notifyNewGrid() adapter.notifyNewGrid()
@ -148,8 +145,7 @@ class OfflineAnimeFragment : Fragment(), OfflineAnimeSearchListener {
layoutcompact.setOnClickListener { layoutcompact.setOnClickListener {
selected(it as ImageView) selected(it as ImageView)
style = 1 style = 1
context?.getSharedPreferences("Dantotsu", Context.MODE_PRIVATE)?.edit() PrefWrapper.setVal(PrefName.OfflineView, style)
?.putInt("offline_view", style!!)?.apply()
gridView.visibility = View.GONE gridView.visibility = View.GONE
gridView = view.findViewById(R.id.gridView1) gridView = view.findViewById(R.id.gridView1)
adapter.notifyNewGrid() adapter.notifyNewGrid()
@ -216,11 +212,7 @@ class OfflineAnimeFragment : Fragment(), OfflineAnimeSearchListener {
builder.setMessage("Are you sure you want to delete ${item.title}?") builder.setMessage("Are you sure you want to delete ${item.title}?")
builder.setPositiveButton("Yes") { _, _ -> builder.setPositiveButton("Yes") { _, _ ->
downloadManager.removeMedia(item.title, type) downloadManager.removeMedia(item.title, type)
val mediaIds = requireContext().getSharedPreferences( val mediaIds = PrefWrapper.getAnimeDownloadPreferences().all?.filter { it.key.contains(item.title) }?.values ?: emptySet()
getString(R.string.anime_downloads),
Context.MODE_PRIVATE
)
?.all?.filter { it.key.contains(item.title) }?.values ?: emptySet()
if (mediaIds.isEmpty()) { if (mediaIds.isEmpty()) {
snackString("No media found") // if this happens, terrible things have happened snackString("No media found") // if this happens, terrible things have happened
} }

View file

@ -11,6 +11,8 @@ import android.widget.LinearLayout
import android.widget.TextView import android.widget.TextView
import androidx.cardview.widget.CardView import androidx.cardview.widget.CardView
import ani.dantotsu.R import ani.dantotsu.R
import ani.dantotsu.settings.saving.PrefName
import ani.dantotsu.settings.saving.PrefWrapper
class OfflineMangaAdapter( class OfflineMangaAdapter(
@ -21,8 +23,7 @@ class OfflineMangaAdapter(
private val inflater: LayoutInflater = private val inflater: LayoutInflater =
context.getSystemService(Context.LAYOUT_INFLATER_SERVICE) as LayoutInflater context.getSystemService(Context.LAYOUT_INFLATER_SERVICE) as LayoutInflater
private var originalItems: List<OfflineMangaModel> = items private var originalItems: List<OfflineMangaModel> = items
private var style = private var style = PrefWrapper.getVal(PrefName.OfflineView, 0)
context.getSharedPreferences("Dantotsu", Context.MODE_PRIVATE).getInt("offline_view", 0)
override fun getCount(): Int { override fun getCount(): Int {
return items.size return items.size
@ -104,8 +105,7 @@ class OfflineMangaAdapter(
} }
fun notifyNewGrid() { fun notifyNewGrid() {
style = style = PrefWrapper.getVal(PrefName.OfflineView, 0)
context.getSharedPreferences("Dantotsu", Context.MODE_PRIVATE).getInt("offline_view", 0)
notifyDataSetChanged() notifyDataSetChanged()
} }
} }

View file

@ -41,6 +41,8 @@ import ani.dantotsu.navBarHeight
import ani.dantotsu.setSafeOnClickListener import ani.dantotsu.setSafeOnClickListener
import ani.dantotsu.settings.SettingsDialogFragment import ani.dantotsu.settings.SettingsDialogFragment
import ani.dantotsu.settings.UserInterfaceSettings import ani.dantotsu.settings.UserInterfaceSettings
import ani.dantotsu.settings.saving.PrefName
import ani.dantotsu.settings.saving.PrefWrapper
import ani.dantotsu.snackString import ani.dantotsu.snackString
import com.google.android.material.card.MaterialCardView import com.google.android.material.card.MaterialCardView
import com.google.android.material.imageview.ShapeableImageView import com.google.android.material.imageview.ShapeableImageView
@ -91,12 +93,9 @@ class OfflineMangaFragment : Fragment(), OfflineMangaSearchListener {
if (!uiSettings.immersiveMode) { if (!uiSettings.immersiveMode) {
view.rootView.fitsSystemWindows = true view.rootView.fitsSystemWindows = true
} }
val colorOverflow = currContext()?.getSharedPreferences("Dantotsu", Context.MODE_PRIVATE)
?.getBoolean("colorOverflow", false) ?: false textInputLayout.boxBackgroundColor = (color and 0x00FFFFFF) or 0x28000000.toInt()
if (!colorOverflow) { 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) val searchView = view.findViewById<AutoCompleteTextView>(R.id.animeSearchBarText)
searchView.addTextChangedListener(object : TextWatcher { searchView.addTextChangedListener(object : TextWatcher {
@ -110,8 +109,7 @@ class OfflineMangaFragment : Fragment(), OfflineMangaSearchListener {
onSearchQuery(s.toString()) onSearchQuery(s.toString())
} }
}) })
var style = context?.getSharedPreferences("Dantotsu", Context.MODE_PRIVATE) var style = PrefWrapper.getVal(PrefName.OfflineView, 0)
?.getInt("offline_view", 0)
val layoutList = view.findViewById<ImageView>(R.id.downloadedList) val layoutList = view.findViewById<ImageView>(R.id.downloadedList)
val layoutcompact = view.findViewById<ImageView>(R.id.downloadedGrid) val layoutcompact = view.findViewById<ImageView>(R.id.downloadedGrid)
var selected = when (style) { var selected = when (style) {
@ -130,8 +128,7 @@ class OfflineMangaFragment : Fragment(), OfflineMangaSearchListener {
layoutList.setOnClickListener { layoutList.setOnClickListener {
selected(it as ImageView) selected(it as ImageView)
style = 0 style = 0
requireContext().getSharedPreferences("Dantotsu", Context.MODE_PRIVATE).edit() PrefWrapper.setVal(PrefName.OfflineView, style)
.putInt("offline_view", style!!).apply()
gridView.visibility = View.GONE gridView.visibility = View.GONE
gridView = view.findViewById(R.id.gridView) gridView = view.findViewById(R.id.gridView)
adapter.notifyNewGrid() adapter.notifyNewGrid()
@ -142,8 +139,7 @@ class OfflineMangaFragment : Fragment(), OfflineMangaSearchListener {
layoutcompact.setOnClickListener { layoutcompact.setOnClickListener {
selected(it as ImageView) selected(it as ImageView)
style = 1 style = 1
requireContext().getSharedPreferences("Dantotsu", Context.MODE_PRIVATE).edit() PrefWrapper.setVal(PrefName.OfflineView, style)
.putInt("offline_view", style!!).apply()
gridView.visibility = View.GONE gridView.visibility = View.GONE
gridView = view.findViewById(R.id.gridView1) gridView = view.findViewById(R.id.gridView1)
adapter.notifyNewGrid() adapter.notifyNewGrid()

View file

@ -43,6 +43,7 @@ import ani.dantotsu.parsers.Subtitle
import ani.dantotsu.parsers.SubtitleType import ani.dantotsu.parsers.SubtitleType
import ani.dantotsu.parsers.Video import ani.dantotsu.parsers.Video
import ani.dantotsu.parsers.VideoType import ani.dantotsu.parsers.VideoType
import ani.dantotsu.settings.saving.PrefWrapper
import eu.kanade.tachiyomi.network.NetworkHelper import eu.kanade.tachiyomi.network.NetworkHelper
import uy.kohesive.injekt.Injekt import uy.kohesive.injekt.Injekt
import uy.kohesive.injekt.api.get import uy.kohesive.injekt.api.get
@ -229,19 +230,13 @@ object Helper {
DownloadService.sendRemoveDownload( DownloadService.sendRemoveDownload(
context, context,
ExoplayerDownloadService::class.java, ExoplayerDownloadService::class.java,
context.getSharedPreferences( PrefWrapper.getAnimeDownloadPreferences().getString(
getString(context, R.string.anime_downloads),
Context.MODE_PRIVATE
).getString(
animeDownloadTask.getTaskName(), animeDownloadTask.getTaskName(),
"" ""
) ?: "", ) ?: "",
false false
) )
context.getSharedPreferences( PrefWrapper.getAnimeDownloadPreferences().edit()
getString(context, R.string.anime_downloads),
Context.MODE_PRIVATE
).edit()
.remove(animeDownloadTask.getTaskName()) .remove(animeDownloadTask.getTaskName())
.apply() .apply()
downloadsManger.removeDownload( downloadsManger.removeDownload(

View file

@ -2,9 +2,7 @@ package ani.dantotsu.home
import android.animation.ObjectAnimator import android.animation.ObjectAnimator
import android.annotation.SuppressLint import android.annotation.SuppressLint
import android.content.Context
import android.content.Intent import android.content.Intent
import android.content.SharedPreferences
import android.os.Build import android.os.Build
import android.os.Bundle import android.os.Bundle
import android.view.LayoutInflater import android.view.LayoutInflater
@ -36,6 +34,8 @@ import ani.dantotsu.media.SearchActivity
import ani.dantotsu.navBarHeight import ani.dantotsu.navBarHeight
import ani.dantotsu.px import ani.dantotsu.px
import ani.dantotsu.settings.UserInterfaceSettings import ani.dantotsu.settings.UserInterfaceSettings
import ani.dantotsu.settings.saving.PrefName
import ani.dantotsu.settings.saving.PrefWrapper
import ani.dantotsu.snackString import ani.dantotsu.snackString
import ani.dantotsu.statusBarHeight import ani.dantotsu.statusBarHeight
import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.Dispatchers
@ -271,8 +271,8 @@ class AnimeFragment : Fragment() {
model.loaded = true model.loaded = true
model.loadTrending(1) model.loadTrending(1)
model.loadUpdated() model.loadUpdated()
model.loadPopular("ANIME", sort = Anilist.sortBy[1], onList = Injekt.get<SharedPreferences>() model.loadPopular("ANIME", sort = Anilist.sortBy[1], onList = PrefWrapper.getVal(
.getBoolean("popular_list", false)) PrefName.PopularAnimeList, false))
} }
live.postValue(false) live.postValue(false)
_binding?.animeRefresh?.isRefreshing = false _binding?.animeRefresh?.isRefreshing = false

View file

@ -34,6 +34,8 @@ import ani.dantotsu.setSlideIn
import ani.dantotsu.setSlideUp import ani.dantotsu.setSlideUp
import ani.dantotsu.settings.SettingsDialogFragment import ani.dantotsu.settings.SettingsDialogFragment
import ani.dantotsu.settings.UserInterfaceSettings import ani.dantotsu.settings.UserInterfaceSettings
import ani.dantotsu.settings.saving.PrefName
import ani.dantotsu.settings.saving.PrefWrapper
import ani.dantotsu.statusBarHeight import ani.dantotsu.statusBarHeight
import com.google.android.material.card.MaterialCardView import com.google.android.material.card.MaterialCardView
import com.google.android.material.textfield.TextInputLayout import com.google.android.material.textfield.TextInputLayout
@ -68,13 +70,8 @@ class AnimePageAdapter : RecyclerView.Adapter<AnimePageAdapter.AnimePageViewHold
currContext()?.theme?.resolveAttribute(android.R.attr.windowBackground, typedValue, true) currContext()?.theme?.resolveAttribute(android.R.attr.windowBackground, typedValue, true)
val color = typedValue.data val color = typedValue.data
textInputLayout.boxBackgroundColor = (color and 0x00FFFFFF) or 0x28000000.toInt()
val colorOverflow = currContext()?.getSharedPreferences("Dantotsu", Context.MODE_PRIVATE) materialCardView.setCardBackgroundColor((color and 0x00FFFFFF) or 0x28000000.toInt())
?.getBoolean("colorOverflow", false) ?: false
if (!colorOverflow) {
textInputLayout.boxBackgroundColor = (color and 0x00FFFFFF) or 0x28000000.toInt()
materialCardView.setCardBackgroundColor((color and 0x00FFFFFF) or 0x28000000.toInt())
}
binding.animeTitleContainer.updatePadding(top = statusBarHeight) binding.animeTitleContainer.updatePadding(top = statusBarHeight)
@ -133,15 +130,12 @@ class AnimePageAdapter : RecyclerView.Adapter<AnimePageAdapter.AnimePageViewHold
binding.animeIncludeList.visibility = binding.animeIncludeList.visibility =
if (Anilist.userid != null) View.VISIBLE else View.GONE if (Anilist.userid != null) View.VISIBLE else View.GONE
binding.animeIncludeList.isChecked = binding.animeIncludeList.isChecked = PrefWrapper.getVal(PrefName.PopularAnimeList, true)
currContext()?.getSharedPreferences("Dantotsu", Context.MODE_PRIVATE)
?.getBoolean("popular_list", true) ?: true
binding.animeIncludeList.setOnCheckedChangeListener { _, isChecked -> binding.animeIncludeList.setOnCheckedChangeListener { _, isChecked ->
onIncludeListClick.invoke(isChecked) onIncludeListClick.invoke(isChecked)
currContext()?.getSharedPreferences("Dantotsu", Context.MODE_PRIVATE)?.edit() PrefWrapper.setVal(PrefName.PopularAnimeList, isChecked)
?.putBoolean("popular_list", isChecked)?.apply()
} }
if (ready.value == false) if (ready.value == false)
ready.postValue(true) ready.postValue(true)

View file

@ -2,8 +2,6 @@ package ani.dantotsu.home
import android.animation.ObjectAnimator import android.animation.ObjectAnimator
import android.annotation.SuppressLint import android.annotation.SuppressLint
import android.content.Context
import android.content.SharedPreferences
import android.os.Build import android.os.Build
import android.os.Bundle import android.os.Bundle
import android.view.LayoutInflater import android.view.LayoutInflater
@ -33,6 +31,8 @@ import ani.dantotsu.media.ProgressAdapter
import ani.dantotsu.navBarHeight import ani.dantotsu.navBarHeight
import ani.dantotsu.px import ani.dantotsu.px
import ani.dantotsu.settings.UserInterfaceSettings import ani.dantotsu.settings.UserInterfaceSettings
import ani.dantotsu.settings.saving.PrefName
import ani.dantotsu.settings.saving.PrefWrapper
import ani.dantotsu.snackString import ani.dantotsu.snackString
import ani.dantotsu.statusBarHeight import ani.dantotsu.statusBarHeight
import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.Dispatchers
@ -245,8 +245,9 @@ class MangaFragment : Fragment() {
model.loaded = true model.loaded = true
model.loadTrending() model.loadTrending()
model.loadTrendingNovel() model.loadTrendingNovel()
model.loadPopular("MANGA", sort = Anilist.sortBy[1], onList = Injekt.get<SharedPreferences>() model.loadPopular("MANGA", sort = Anilist.sortBy[1], onList = PrefWrapper.getVal(
.getBoolean("popular_list", false) ) PrefName.PopularMangaList, false
))
} }
live.postValue(false) live.postValue(false)
_binding?.mangaRefresh?.isRefreshing = false _binding?.mangaRefresh?.isRefreshing = false

View file

@ -33,6 +33,8 @@ import ani.dantotsu.setSlideIn
import ani.dantotsu.setSlideUp import ani.dantotsu.setSlideUp
import ani.dantotsu.settings.SettingsDialogFragment import ani.dantotsu.settings.SettingsDialogFragment
import ani.dantotsu.settings.UserInterfaceSettings import ani.dantotsu.settings.UserInterfaceSettings
import ani.dantotsu.settings.saving.PrefName
import ani.dantotsu.settings.saving.PrefWrapper
import ani.dantotsu.statusBarHeight import ani.dantotsu.statusBarHeight
import com.google.android.material.card.MaterialCardView import com.google.android.material.card.MaterialCardView
import com.google.android.material.textfield.TextInputLayout import com.google.android.material.textfield.TextInputLayout
@ -67,13 +69,8 @@ class MangaPageAdapter : RecyclerView.Adapter<MangaPageAdapter.MangaPageViewHold
currContext()?.theme?.resolveAttribute(android.R.attr.windowBackground, typedValue, true) currContext()?.theme?.resolveAttribute(android.R.attr.windowBackground, typedValue, true)
val color = typedValue.data val color = typedValue.data
textInputLayout.boxBackgroundColor = (color and 0x00FFFFFF) or 0x28000000.toInt()
val colorOverflow = currContext()?.getSharedPreferences("Dantotsu", Context.MODE_PRIVATE) materialCardView.setCardBackgroundColor((color and 0x00FFFFFF) or 0x28000000.toInt())
?.getBoolean("colorOverflow", false) ?: false
if (!colorOverflow) {
textInputLayout.boxBackgroundColor = (color and 0x00FFFFFF) or 0x28000000.toInt()
materialCardView.setCardBackgroundColor((color and 0x00FFFFFF) or 0x28000000.toInt())
}
binding.mangaTitleContainer.updatePadding(top = statusBarHeight) binding.mangaTitleContainer.updatePadding(top = statusBarHeight)
@ -126,15 +123,12 @@ class MangaPageAdapter : RecyclerView.Adapter<MangaPageAdapter.MangaPageViewHold
binding.mangaIncludeList.visibility = binding.mangaIncludeList.visibility =
if (Anilist.userid != null) View.VISIBLE else View.GONE if (Anilist.userid != null) View.VISIBLE else View.GONE
binding.mangaIncludeList.isChecked = binding.mangaIncludeList.isChecked = PrefWrapper.getVal(PrefName.PopularMangaList, false)
currContext()?.getSharedPreferences("Dantotsu", Context.MODE_PRIVATE)
?.getBoolean("popular_list", true) ?: true
binding.mangaIncludeList.setOnCheckedChangeListener { _, isChecked -> binding.mangaIncludeList.setOnCheckedChangeListener { _, isChecked ->
onIncludeListClick.invoke(isChecked) onIncludeListClick.invoke(isChecked)
currContext()?.getSharedPreferences("Dantotsu", Context.MODE_PRIVATE)?.edit() PrefWrapper.setVal(PrefName.PopularMangaList, isChecked)
?.putBoolean("popular_list", isChecked)?.apply()
} }
if (ready.value == false) if (ready.value == false)
ready.postValue(true) ready.postValue(true)

View file

@ -1,6 +1,5 @@
package ani.dantotsu.home package ani.dantotsu.home
import android.content.Context
import android.graphics.drawable.GradientDrawable import android.graphics.drawable.GradientDrawable
import android.os.Build import android.os.Build
import android.os.Bundle import android.os.Bundle
@ -26,7 +25,6 @@ import ani.dantotsu.initActivity
import ani.dantotsu.loadData import ani.dantotsu.loadData
import ani.dantotsu.navBarHeight import ani.dantotsu.navBarHeight
import ani.dantotsu.offline.OfflineFragment import ani.dantotsu.offline.OfflineFragment
import ani.dantotsu.others.LangSet
import ani.dantotsu.selectedOption import ani.dantotsu.selectedOption
import ani.dantotsu.settings.UserInterfaceSettings import ani.dantotsu.settings.UserInterfaceSettings
import ani.dantotsu.snackString import ani.dantotsu.snackString
@ -39,7 +37,7 @@ class NoInternet : AppCompatActivity() {
private var uiSettings = UserInterfaceSettings() private var uiSettings = UserInterfaceSettings()
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
LangSet.setLocale(this)
ThemeManager(this).applyTheme() ThemeManager(this).applyTheme()
binding = ActivityNoInternetBinding.inflate(layoutInflater) binding = ActivityNoInternetBinding.inflate(layoutInflater)
@ -54,12 +52,8 @@ class NoInternet : AppCompatActivity() {
backgroundDrawable.setColor(semiTransparentColor) backgroundDrawable.setColor(semiTransparentColor)
_bottomBar.background = backgroundDrawable _bottomBar.background = backgroundDrawable
} }
val colorOverflow = this.getSharedPreferences("Dantotsu", Context.MODE_PRIVATE) _bottomBar.background = ContextCompat.getDrawable(this, R.drawable.bottom_nav_gray)
.getBoolean("colorOverflow", false)
if (!colorOverflow) {
_bottomBar.background = ContextCompat.getDrawable(this, R.drawable.bottom_nav_gray)
}
var doubleBackToExitPressedOnce = false var doubleBackToExitPressedOnce = false
onBackPressedDispatcher.addCallback(this) { onBackPressedDispatcher.addCallback(this) {

View file

@ -18,7 +18,6 @@ import ani.dantotsu.Refresh
import ani.dantotsu.databinding.ActivityAuthorBinding import ani.dantotsu.databinding.ActivityAuthorBinding
import ani.dantotsu.initActivity import ani.dantotsu.initActivity
import ani.dantotsu.navBarHeight import ani.dantotsu.navBarHeight
import ani.dantotsu.others.LangSet
import ani.dantotsu.others.getSerialized import ani.dantotsu.others.getSerialized
import ani.dantotsu.px import ani.dantotsu.px
import ani.dantotsu.statusBarHeight import ani.dantotsu.statusBarHeight
@ -36,7 +35,7 @@ class AuthorActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
LangSet.setLocale(this)
ThemeManager(this).applyTheme() ThemeManager(this).applyTheme()
binding = ActivityAuthorBinding.inflate(layoutInflater) binding = ActivityAuthorBinding.inflate(layoutInflater)
setContentView(binding.root) setContentView(binding.root)

View file

@ -19,7 +19,6 @@ import ani.dantotsu.databinding.ActivityListBinding
import ani.dantotsu.loadData import ani.dantotsu.loadData
import ani.dantotsu.media.user.ListViewPagerAdapter import ani.dantotsu.media.user.ListViewPagerAdapter
import ani.dantotsu.navBarHeight import ani.dantotsu.navBarHeight
import ani.dantotsu.others.LangSet
import ani.dantotsu.settings.UserInterfaceSettings import ani.dantotsu.settings.UserInterfaceSettings
import ani.dantotsu.statusBarHeight import ani.dantotsu.statusBarHeight
import ani.dantotsu.themes.ThemeManager import ani.dantotsu.themes.ThemeManager
@ -38,7 +37,7 @@ class CalendarActivity : AppCompatActivity() {
@SuppressLint("SetTextI18n") @SuppressLint("SetTextI18n")
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
LangSet.setLocale(this)
ThemeManager(this).applyTheme() ThemeManager(this).applyTheme()
binding = ActivityListBinding.inflate(layoutInflater) binding = ActivityListBinding.inflate(layoutInflater)

View file

@ -21,7 +21,6 @@ import ani.dantotsu.loadData
import ani.dantotsu.loadImage import ani.dantotsu.loadImage
import ani.dantotsu.navBarHeight import ani.dantotsu.navBarHeight
import ani.dantotsu.others.ImageViewDialog import ani.dantotsu.others.ImageViewDialog
import ani.dantotsu.others.LangSet
import ani.dantotsu.others.getSerialized import ani.dantotsu.others.getSerialized
import ani.dantotsu.px import ani.dantotsu.px
import ani.dantotsu.settings.UserInterfaceSettings import ani.dantotsu.settings.UserInterfaceSettings
@ -42,7 +41,7 @@ class CharacterDetailsActivity : AppCompatActivity(), AppBarLayout.OnOffsetChang
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
LangSet.setLocale(this)
ThemeManager(this).applyTheme() ThemeManager(this).applyTheme()
binding = ActivityCharacterBinding.inflate(layoutInflater) binding = ActivityCharacterBinding.inflate(layoutInflater)
setContentView(binding.root) setContentView(binding.root)

View file

@ -14,7 +14,6 @@ import ani.dantotsu.databinding.ActivityGenreBinding
import ani.dantotsu.initActivity import ani.dantotsu.initActivity
import ani.dantotsu.loadData import ani.dantotsu.loadData
import ani.dantotsu.navBarHeight import ani.dantotsu.navBarHeight
import ani.dantotsu.others.LangSet
import ani.dantotsu.statusBarHeight import ani.dantotsu.statusBarHeight
import ani.dantotsu.themes.ThemeManager import ani.dantotsu.themes.ThemeManager
import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.Dispatchers
@ -27,7 +26,7 @@ class GenreActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
LangSet.setLocale(this)
ThemeManager(this).applyTheme() ThemeManager(this).applyTheme()
binding = ActivityGenreBinding.inflate(layoutInflater) binding = ActivityGenreBinding.inflate(layoutInflater)
setContentView(binding.root) setContentView(binding.root)

View file

@ -46,6 +46,8 @@ import ani.dantotsu.others.ImageViewDialog
import ani.dantotsu.others.getSerialized import ani.dantotsu.others.getSerialized
import ani.dantotsu.saveData import ani.dantotsu.saveData
import ani.dantotsu.settings.UserInterfaceSettings import ani.dantotsu.settings.UserInterfaceSettings
import ani.dantotsu.settings.saving.PrefName
import ani.dantotsu.settings.saving.PrefWrapper
import ani.dantotsu.snackString import ani.dantotsu.snackString
import ani.dantotsu.statusBarHeight import ani.dantotsu.statusBarHeight
import ani.dantotsu.themes.ThemeManager import ani.dantotsu.themes.ThemeManager
@ -159,9 +161,7 @@ class MediaDetailsActivity : AppCompatActivity(), AppBarLayout.OnOffsetChangedLi
} }
}) })
banner.setOnTouchListener { _, motionEvent -> gestureDetector.onTouchEvent(motionEvent);true } banner.setOnTouchListener { _, motionEvent -> gestureDetector.onTouchEvent(motionEvent);true }
if (this.getSharedPreferences("Dantotsu", Context.MODE_PRIVATE) if (PrefWrapper.getVal(PrefName.Incognito, false)) {
.getBoolean("incognito", false)
) {
binding.mediaTitle.text = " ${media.userPreferredName}" binding.mediaTitle.text = " ${media.userPreferredName}"
binding.incognito.visibility = View.VISIBLE binding.incognito.visibility = View.VISIBLE
} else { } else {

View file

@ -1,7 +1,6 @@
package ani.dantotsu.media package ani.dantotsu.media
import android.app.Activity import android.app.Activity
import android.content.SharedPreferences
import android.os.Handler import android.os.Handler
import android.os.Looper import android.os.Looper
import androidx.fragment.app.FragmentManager import androidx.fragment.app.FragmentManager

View file

@ -26,6 +26,8 @@ import ani.dantotsu.*
import ani.dantotsu.connections.anilist.Anilist import ani.dantotsu.connections.anilist.Anilist
import ani.dantotsu.connections.anilist.GenresViewModel import ani.dantotsu.connections.anilist.GenresViewModel
import ani.dantotsu.databinding.* import ani.dantotsu.databinding.*
import ani.dantotsu.settings.saving.PrefName
import ani.dantotsu.settings.saving.PrefWrapper
import io.noties.markwon.Markwon import io.noties.markwon.Markwon
import io.noties.markwon.SoftBreakAddsNewLinePlugin import io.noties.markwon.SoftBreakAddsNewLinePlugin
import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.Dispatchers
@ -60,8 +62,7 @@ class MediaInfoFragment : Fragment() {
@SuppressLint("SetJavaScriptEnabled") @SuppressLint("SetJavaScriptEnabled")
override fun onViewCreated(view: View, savedInstanceState: Bundle?) { override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
val model: MediaDetailsViewModel by activityViewModels() val model: MediaDetailsViewModel by activityViewModels()
val offline = requireContext().getSharedPreferences("Dantotsu", Context.MODE_PRIVATE) val offline = PrefWrapper.getVal(PrefName.OfflineMode, false)
.getBoolean("offlineMode", false) || !isOnline(requireContext())
binding.mediaInfoProgressBar.visibility = if (!loaded) View.VISIBLE else View.GONE binding.mediaInfoProgressBar.visibility = if (!loaded) View.VISIBLE else View.GONE
binding.mediaInfoContainer.visibility = if (loaded) View.VISIBLE else View.GONE binding.mediaInfoContainer.visibility = if (loaded) View.VISIBLE else View.GONE
binding.mediaInfoContainer.updateLayoutParams<ViewGroup.MarginLayoutParams> { bottomMargin += 128f.px + navBarHeight } binding.mediaInfoContainer.updateLayoutParams<ViewGroup.MarginLayoutParams> { bottomMargin += 128f.px + navBarHeight }

View file

@ -16,7 +16,6 @@ import ani.dantotsu.connections.anilist.Anilist
import ani.dantotsu.connections.anilist.AnilistSearch import ani.dantotsu.connections.anilist.AnilistSearch
import ani.dantotsu.connections.anilist.SearchResults import ani.dantotsu.connections.anilist.SearchResults
import ani.dantotsu.databinding.ActivitySearchBinding import ani.dantotsu.databinding.ActivitySearchBinding
import ani.dantotsu.others.LangSet
import ani.dantotsu.themes.ThemeManager import ani.dantotsu.themes.ThemeManager
import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
@ -40,7 +39,7 @@ class SearchActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
LangSet.setLocale(this)
ThemeManager(this).applyTheme() ThemeManager(this).applyTheme()
binding = ActivitySearchBinding.inflate(layoutInflater) binding = ActivitySearchBinding.inflate(layoutInflater)
setContentView(binding.root) setContentView(binding.root)

View file

@ -1,8 +1,6 @@
package ani.dantotsu.media package ani.dantotsu.media
import android.annotation.SuppressLint import android.annotation.SuppressLint
import android.content.Context
import android.content.SharedPreferences
import android.graphics.drawable.Drawable import android.graphics.drawable.Drawable
import android.text.Editable import android.text.Editable
import android.text.TextWatcher import android.text.TextWatcher
@ -22,19 +20,16 @@ import androidx.recyclerview.widget.RecyclerView.HORIZONTAL
import ani.dantotsu.App.Companion.context import ani.dantotsu.App.Companion.context
import ani.dantotsu.R import ani.dantotsu.R
import ani.dantotsu.connections.anilist.Anilist import ani.dantotsu.connections.anilist.Anilist
import ani.dantotsu.currContext
import ani.dantotsu.databinding.ItemChipBinding import ani.dantotsu.databinding.ItemChipBinding
import ani.dantotsu.databinding.ItemSearchHeaderBinding import ani.dantotsu.databinding.ItemSearchHeaderBinding
import ani.dantotsu.logger
import ani.dantotsu.others.SharedPreferenceStringSetLiveData
import ani.dantotsu.saveData import ani.dantotsu.saveData
import ani.dantotsu.settings.saving.PrefName
import ani.dantotsu.settings.saving.PrefWrapper
import com.google.android.material.checkbox.MaterialCheckBox.* import com.google.android.material.checkbox.MaterialCheckBox.*
import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.delay import kotlinx.coroutines.delay
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
import uy.kohesive.injekt.Injekt
import uy.kohesive.injekt.api.get
class SearchAdapter(private val activity: SearchActivity, private val type: String) : class SearchAdapter(private val activity: SearchActivity, private val type: String) :
@ -78,9 +73,7 @@ class SearchAdapter(private val activity: SearchActivity, private val type: Stri
} }
binding.searchBar.hint = activity.result.type binding.searchBar.hint = activity.result.type
if (currContext()?.getSharedPreferences("Dantotsu", Context.MODE_PRIVATE) if (PrefWrapper.getVal(PrefName.Incognito, false)) {
?.getBoolean("incognito", false) == true
) {
val startIconDrawableRes = R.drawable.ic_incognito_24 val startIconDrawableRes = R.drawable.ic_incognito_24
val startIconDrawable: Drawable? = val startIconDrawable: Drawable? =
context?.let { AppCompatResources.getDrawable(it, startIconDrawableRes) } context?.let { AppCompatResources.getDrawable(it, startIconDrawableRes) }

View file

@ -1,6 +1,5 @@
package ani.dantotsu.media package ani.dantotsu.media
import android.content.SharedPreferences
import android.view.LayoutInflater import android.view.LayoutInflater
import android.view.View import android.view.View
import android.view.ViewGroup import android.view.ViewGroup
@ -9,24 +8,25 @@ import androidx.recyclerview.widget.ListAdapter
import androidx.recyclerview.widget.RecyclerView import androidx.recyclerview.widget.RecyclerView
import ani.dantotsu.R import ani.dantotsu.R
import ani.dantotsu.databinding.ItemSearchHistoryBinding import ani.dantotsu.databinding.ItemSearchHistoryBinding
import ani.dantotsu.others.SharedPreferenceStringSetLiveData import ani.dantotsu.settings.saving.PrefName
import uy.kohesive.injekt.Injekt import ani.dantotsu.settings.saving.PrefWrapper
import uy.kohesive.injekt.api.get import ani.dantotsu.settings.saving.PrefWrapper.asLiveStringSet
import ani.dantotsu.settings.saving.SharedPreferenceStringSetLiveData
import java.util.Locale
class SearchHistoryAdapter(private val type: String, private val searchClicked: (String) -> Unit) : ListAdapter<String, SearchHistoryAdapter.SearchHistoryViewHolder>( class SearchHistoryAdapter(private val type: String, private val searchClicked: (String) -> Unit) : ListAdapter<String, SearchHistoryAdapter.SearchHistoryViewHolder>(
DIFF_CALLBACK_INSTALLED DIFF_CALLBACK_INSTALLED
) { ) {
private var searchHistoryLiveData: SharedPreferenceStringSetLiveData? = null private var searchHistoryLiveData: SharedPreferenceStringSetLiveData? = null
private var searchHistory: MutableSet<String>? = null private var searchHistory: MutableSet<String>? = null
private var sharedPreferences: SharedPreferences? = null private var historyType: PrefName = when (type.lowercase(Locale.ROOT)) {
"anime" -> PrefName.AnimeSearchHistory
"manga" -> PrefName.MangaSearchHistory
else -> throw IllegalArgumentException("Invalid type")
}
init { init {
sharedPreferences = Injekt.get<SharedPreferences>() searchHistoryLiveData = PrefWrapper.getLiveVal(historyType, mutableSetOf<String>()).asLiveStringSet()
searchHistoryLiveData = SharedPreferenceStringSetLiveData(
sharedPreferences!!,
"searchHistory_$type",
mutableSetOf()
)
searchHistoryLiveData?.observeForever { searchHistoryLiveData?.observeForever {
searchHistory = it.toMutableSet() searchHistory = it.toMutableSet()
submitList(searchHistory?.reversed()) submitList(searchHistory?.reversed())
@ -35,14 +35,14 @@ class SearchHistoryAdapter(private val type: String, private val searchClicked:
fun remove(item: String) { fun remove(item: String) {
searchHistory?.remove(item) searchHistory?.remove(item)
sharedPreferences?.edit()?.putStringSet("searchHistory_$type", searchHistory)?.apply() PrefWrapper.setVal(historyType, searchHistory)
} }
fun add(item: String) { fun add(item: String) {
if (searchHistory?.contains(item) == true || item.isBlank()) return if (searchHistory?.contains(item) == true || item.isBlank()) return
if (sharedPreferences?.getBoolean("incognito", false) == true) return if (PrefWrapper.getVal(PrefName.Incognito, false)) return
searchHistory?.add(item) searchHistory?.add(item)
sharedPreferences?.edit()?.putStringSet("searchHistory_$type", searchHistory)?.apply() PrefWrapper.setVal(historyType, searchHistory)
} }
override fun onCreateViewHolder( override fun onCreateViewHolder(

View file

@ -18,7 +18,6 @@ import ani.dantotsu.Refresh
import ani.dantotsu.databinding.ActivityStudioBinding import ani.dantotsu.databinding.ActivityStudioBinding
import ani.dantotsu.initActivity import ani.dantotsu.initActivity
import ani.dantotsu.navBarHeight import ani.dantotsu.navBarHeight
import ani.dantotsu.others.LangSet
import ani.dantotsu.others.getSerialized import ani.dantotsu.others.getSerialized
import ani.dantotsu.px import ani.dantotsu.px
import ani.dantotsu.statusBarHeight import ani.dantotsu.statusBarHeight
@ -36,7 +35,7 @@ class StudioActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
LangSet.setLocale(this)
ThemeManager(this).applyTheme() ThemeManager(this).applyTheme()
binding = ActivityStudioBinding.inflate(layoutInflater) binding = ActivityStudioBinding.inflate(layoutInflater)
setContentView(binding.root) setContentView(binding.root)

View file

@ -27,6 +27,8 @@ import ani.dantotsu.others.webview.CookieCatcher
import ani.dantotsu.parsers.AnimeSources import ani.dantotsu.parsers.AnimeSources
import ani.dantotsu.parsers.DynamicAnimeParser import ani.dantotsu.parsers.DynamicAnimeParser
import ani.dantotsu.parsers.WatchSources import ani.dantotsu.parsers.WatchSources
import ani.dantotsu.settings.saving.PrefName
import ani.dantotsu.settings.saving.PrefWrapper
import ani.dantotsu.subcriptions.Notifications.Companion.openSettings import ani.dantotsu.subcriptions.Notifications.Companion.openSettings
import ani.dantotsu.subcriptions.Subscription.Companion.getChannelId import ani.dantotsu.subcriptions.Subscription.Companion.getChannelId
import com.google.android.material.chip.Chip import com.google.android.material.chip.Chip
@ -90,11 +92,10 @@ class AnimeWatchAdapter(
null null
) )
} }
val offline = if (!isOnline(binding.root.context) || currContext()?.getSharedPreferences( val offline = if (!isOnline(binding.root.context) || PrefWrapper.getVal(
"Dantotsu", PrefName.OfflineMode,
Context.MODE_PRIVATE false
) )
?.getBoolean("offlineMode", false) == true
) View.GONE else View.VISIBLE ) View.GONE else View.VISIBLE
binding.animeSourceNameContainer.visibility = offline binding.animeSourceNameContainer.visibility = offline

View file

@ -43,6 +43,7 @@ import ani.dantotsu.parsers.HAnimeSources
import ani.dantotsu.settings.PlayerSettings import ani.dantotsu.settings.PlayerSettings
import ani.dantotsu.settings.UserInterfaceSettings import ani.dantotsu.settings.UserInterfaceSettings
import ani.dantotsu.settings.extensionprefs.AnimeSourcePreferencesFragment import ani.dantotsu.settings.extensionprefs.AnimeSourcePreferencesFragment
import ani.dantotsu.settings.saving.PrefWrapper
import ani.dantotsu.subcriptions.Notifications import ani.dantotsu.subcriptions.Notifications
import ani.dantotsu.subcriptions.Notifications.Group.ANIME_GROUP import ani.dantotsu.subcriptions.Notifications.Group.ANIME_GROUP
import ani.dantotsu.subcriptions.Subscription.Companion.getChannelId import ani.dantotsu.subcriptions.Subscription.Companion.getChannelId
@ -476,17 +477,11 @@ class AnimeWatchFragment : Fragment() {
) )
) )
val taskName = AnimeDownloaderService.AnimeDownloadTask.getTaskName(media.mainName(), i) val taskName = AnimeDownloaderService.AnimeDownloadTask.getTaskName(media.mainName(), i)
val id = requireContext().getSharedPreferences( val id = PrefWrapper.getAnimeDownloadPreferences().getString(
ContextCompat.getString(requireContext(), R.string.anime_downloads),
Context.MODE_PRIVATE
).getString(
taskName, taskName,
"" ""
) ?: "" ) ?: ""
requireContext().getSharedPreferences( PrefWrapper.getAnimeDownloadPreferences().edit().remove(taskName).apply()
ContextCompat.getString(requireContext(), R.string.anime_downloads),
Context.MODE_PRIVATE
).edit().remove(taskName).apply()
DownloadService.sendRemoveDownload( DownloadService.sendRemoveDownload(
requireContext(), requireContext(),
ExoplayerDownloadService::class.java, ExoplayerDownloadService::class.java,

View file

@ -2,14 +2,12 @@ package ani.dantotsu.media.anime
import android.annotation.SuppressLint import android.annotation.SuppressLint
import android.app.AlertDialog import android.app.AlertDialog
import android.content.Context
import android.view.LayoutInflater import android.view.LayoutInflater
import android.view.View import android.view.View
import android.view.ViewGroup import android.view.ViewGroup
import android.view.animation.LinearInterpolator import android.view.animation.LinearInterpolator
import android.widget.LinearLayout import android.widget.LinearLayout
import androidx.annotation.OptIn import androidx.annotation.OptIn
import androidx.core.content.ContextCompat
import androidx.lifecycle.coroutineScope import androidx.lifecycle.coroutineScope
import androidx.media3.common.util.UnstableApi import androidx.media3.common.util.UnstableApi
import androidx.media3.exoplayer.offline.DownloadIndex import androidx.media3.exoplayer.offline.DownloadIndex
@ -22,6 +20,7 @@ import ani.dantotsu.databinding.ItemEpisodeListBinding
import ani.dantotsu.download.anime.AnimeDownloaderService import ani.dantotsu.download.anime.AnimeDownloaderService
import ani.dantotsu.download.video.Helper import ani.dantotsu.download.video.Helper
import ani.dantotsu.media.Media import ani.dantotsu.media.Media
import ani.dantotsu.settings.saving.PrefWrapper
import com.bumptech.glide.Glide import com.bumptech.glide.Glide
import com.bumptech.glide.load.model.GlideUrl import com.bumptech.glide.load.model.GlideUrl
import kotlinx.coroutines.delay import kotlinx.coroutines.delay
@ -253,10 +252,7 @@ class EpisodeAdapter(
media.mainName(), media.mainName(),
episodeNumber episodeNumber
) )
val id = fragment.requireContext().getSharedPreferences( val id = PrefWrapper.getAnimeDownloadPreferences().getString(
ContextCompat.getString(fragment.requireContext(), R.string.anime_downloads),
Context.MODE_PRIVATE
).getString(
taskName, taskName,
"" ""
) ?: "" ) ?: ""

View file

@ -77,13 +77,14 @@ import ani.dantotsu.media.MediaDetailsViewModel
import ani.dantotsu.media.SubtitleDownloader import ani.dantotsu.media.SubtitleDownloader
import ani.dantotsu.others.AniSkip import ani.dantotsu.others.AniSkip
import ani.dantotsu.others.AniSkip.getType import ani.dantotsu.others.AniSkip.getType
import ani.dantotsu.others.LangSet
import ani.dantotsu.others.ResettableTimer import ani.dantotsu.others.ResettableTimer
import ani.dantotsu.others.getSerialized import ani.dantotsu.others.getSerialized
import ani.dantotsu.parsers.* import ani.dantotsu.parsers.*
import ani.dantotsu.settings.PlayerSettings import ani.dantotsu.settings.PlayerSettings
import ani.dantotsu.settings.PlayerSettingsActivity import ani.dantotsu.settings.PlayerSettingsActivity
import ani.dantotsu.settings.UserInterfaceSettings import ani.dantotsu.settings.UserInterfaceSettings
import ani.dantotsu.settings.saving.PrefName
import ani.dantotsu.settings.saving.PrefWrapper
import ani.dantotsu.themes.ThemeManager import ani.dantotsu.themes.ThemeManager
import com.bumptech.glide.Glide import com.bumptech.glide.Glide
import com.google.android.gms.cast.framework.CastButtonFactory import com.google.android.gms.cast.framework.CastButtonFactory
@ -331,7 +332,7 @@ class ExoplayerView : AppCompatActivity(), Player.Listener, SessionAvailabilityL
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
LangSet.setLocale(this)
ThemeManager(this).applyTheme() ThemeManager(this).applyTheme()
binding = ActivityExoplayerBinding.inflate(layoutInflater) binding = ActivityExoplayerBinding.inflate(layoutInflater)
setContentView(binding.root) setContentView(binding.root)
@ -1013,8 +1014,7 @@ class ExoplayerView : AppCompatActivity(), Player.Listener, SessionAvailabilityL
preloading = false preloading = false
val context = this val context = this
val incognito = baseContext.getSharedPreferences("Dantotsu", MODE_PRIVATE) val incognito = PrefWrapper.getVal(PrefName.Incognito, false)
.getBoolean("incognito", false)
if (isOnline(context) && Discord.token != null && !incognito) { if (isOnline(context) && Discord.token != null && !incognito) {
lifecycleScope.launch { lifecycleScope.launch {
val presence = RPC.createPresence(RPC.Companion.RPCData( val presence = RPC.createPresence(RPC.Companion.RPCData(
@ -1191,8 +1191,7 @@ class ExoplayerView : AppCompatActivity(), Player.Listener, SessionAvailabilityL
} }
preloading = false preloading = false
val incognito = currContext()?.getSharedPreferences("Dantotsu", Context.MODE_PRIVATE) val incognito = PrefWrapper.getVal(PrefName.Incognito, false)
?.getBoolean("incognito", false) ?: false
val showProgressDialog = val showProgressDialog =
if (settings.askIndividual) loadData<Boolean>("${media.id}_progressDialog") if (settings.askIndividual) loadData<Boolean>("${media.id}_progressDialog")
?: true else false ?: true else false
@ -1343,7 +1342,7 @@ class ExoplayerView : AppCompatActivity(), Player.Listener, SessionAvailabilityL
val downloadedMediaItem = if (ext.server.offline) { val downloadedMediaItem = if (ext.server.offline) {
val key = ext.server.name val key = ext.server.name
downloadId = getSharedPreferences(getString(R.string.anime_downloads), MODE_PRIVATE) downloadId = PrefWrapper.getAnimeDownloadPreferences()
.getString(key, null) .getString(key, null)
if (downloadId != null) { if (downloadId != null) {
Helper.downloadManager(this) Helper.downloadManager(this)
@ -1550,7 +1549,6 @@ class ExoplayerView : AppCompatActivity(), Player.Listener, SessionAvailabilityL
override fun onResume() { override fun onResume() {
super.onResume() super.onResume()
LangSet.setLocale(this)
orientationListener?.enable() orientationListener?.enable()
hideSystemBars() hideSystemBars()
if (isInitialized) { if (isInitialized) {
@ -1745,8 +1743,7 @@ class ExoplayerView : AppCompatActivity(), Player.Listener, SessionAvailabilityL
} }
private fun updateAniProgress() { private fun updateAniProgress() {
val incognito = currContext()?.getSharedPreferences("Dantotsu", Context.MODE_PRIVATE) val incognito = PrefWrapper.getVal(PrefName.Incognito, false)
?.getBoolean("incognito", false) ?: false
if (!incognito && exoPlayer.currentPosition / episodeLength > settings.watchPercentage && Anilist.userid != null) if (!incognito && exoPlayer.currentPosition / episodeLength > settings.watchPercentage && Anilist.userid != null)
if (loadData<Boolean>("${media.id}_save_progress") != false && if (media.isAdult) settings.updateForH else true) { if (loadData<Boolean>("${media.id}_save_progress") != false && if (media.isAdult) settings.updateForH else true) {
media.anime!!.selectedEpisode?.apply { media.anime!!.selectedEpisode?.apply {

View file

@ -28,6 +28,8 @@ import ani.dantotsu.others.webview.CookieCatcher
import ani.dantotsu.parsers.DynamicMangaParser import ani.dantotsu.parsers.DynamicMangaParser
import ani.dantotsu.parsers.MangaReadSources import ani.dantotsu.parsers.MangaReadSources
import ani.dantotsu.parsers.MangaSources import ani.dantotsu.parsers.MangaSources
import ani.dantotsu.settings.saving.PrefName
import ani.dantotsu.settings.saving.PrefWrapper
import ani.dantotsu.subcriptions.Notifications.Companion.openSettings import ani.dantotsu.subcriptions.Notifications.Companion.openSettings
import ani.dantotsu.subcriptions.Subscription.Companion.getChannelId import ani.dantotsu.subcriptions.Subscription.Companion.getChannelId
import com.google.android.material.chip.Chip import com.google.android.material.chip.Chip
@ -69,11 +71,7 @@ class MangaReadAdapter(
null null
) )
} }
val offline = if (!isOnline(binding.root.context) || currContext()?.getSharedPreferences( val offline = if (!isOnline(binding.root.context) || PrefWrapper.getVal(PrefName.OfflineMode, false)
"Dantotsu",
Context.MODE_PRIVATE
)
?.getBoolean("offlineMode", false) == true
) View.GONE else View.VISIBLE ) View.GONE else View.VISIBLE
binding.animeSourceNameContainer.visibility = offline binding.animeSourceNameContainer.visibility = offline

View file

@ -3,7 +3,6 @@ package ani.dantotsu.media.manga.mangareader
import android.animation.ObjectAnimator import android.animation.ObjectAnimator
import android.annotation.SuppressLint import android.annotation.SuppressLint
import android.app.AlertDialog import android.app.AlertDialog
import android.content.Context
import android.content.Intent import android.content.Intent
import android.content.res.Configuration import android.content.res.Configuration
import android.content.res.Resources import android.content.res.Resources
@ -41,7 +40,6 @@ import ani.dantotsu.media.manga.MangaCache
import ani.dantotsu.media.manga.MangaChapter import ani.dantotsu.media.manga.MangaChapter
import ani.dantotsu.media.manga.MangaNameAdapter import ani.dantotsu.media.manga.MangaNameAdapter
import ani.dantotsu.others.ImageViewDialog import ani.dantotsu.others.ImageViewDialog
import ani.dantotsu.others.LangSet
import ani.dantotsu.parsers.HMangaSources import ani.dantotsu.parsers.HMangaSources
import ani.dantotsu.parsers.MangaImage import ani.dantotsu.parsers.MangaImage
import ani.dantotsu.parsers.MangaSources import ani.dantotsu.parsers.MangaSources
@ -51,6 +49,8 @@ import ani.dantotsu.settings.CurrentReaderSettings.DualPageModes.*
import ani.dantotsu.settings.CurrentReaderSettings.Layouts.* import ani.dantotsu.settings.CurrentReaderSettings.Layouts.*
import ani.dantotsu.settings.ReaderSettings import ani.dantotsu.settings.ReaderSettings
import ani.dantotsu.settings.UserInterfaceSettings import ani.dantotsu.settings.UserInterfaceSettings
import ani.dantotsu.settings.saving.PrefName
import ani.dantotsu.settings.saving.PrefWrapper
import ani.dantotsu.themes.ThemeManager import ani.dantotsu.themes.ThemeManager
import com.alexvasilkov.gestures.views.GestureFrameLayout import com.alexvasilkov.gestures.views.GestureFrameLayout
import com.bumptech.glide.load.resource.bitmap.BitmapTransformation import com.bumptech.glide.load.resource.bitmap.BitmapTransformation
@ -138,7 +138,7 @@ class MangaReaderActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
LangSet.setLocale(this)
ThemeManager(this).applyTheme() ThemeManager(this).applyTheme()
binding = ActivityMangaReaderBinding.inflate(layoutInflater) binding = ActivityMangaReaderBinding.inflate(layoutInflater)
setContentView(binding.root) setContentView(binding.root)
@ -220,8 +220,7 @@ class MangaReaderActivity : AppCompatActivity() {
val scope = lifecycleScope val scope = lifecycleScope
scope.launch(Dispatchers.IO) { scope.launch(Dispatchers.IO) {
mangaSources.init( mangaSources.init(
Injekt.get<MangaExtensionManager>().installedExtensionsFlow, Injekt.get<MangaExtensionManager>().installedExtensionsFlow
this@MangaReaderActivity
) )
} }
model.mangaReadSources = mangaSources model.mangaReadSources = mangaSources
@ -321,8 +320,7 @@ class MangaReaderActivity : AppCompatActivity() {
chaptersTitleArr.getOrNull(currentChapterIndex - 1) ?: "" chaptersTitleArr.getOrNull(currentChapterIndex - 1) ?: ""
applySettings() applySettings()
val context = this val context = this
val incognito = context.getSharedPreferences("Dantotsu", 0) val incognito = PrefWrapper.getVal(PrefName.Incognito, false)
?.getBoolean("incognito", false) ?: false
if (isOnline(context) && Discord.token != null && !incognito) { if (isOnline(context) && Discord.token != null && !incognito) {
lifecycleScope.launch { lifecycleScope.launch {
val presence = RPC.createPresence( val presence = RPC.createPresence(
@ -855,9 +853,7 @@ class MangaReaderActivity : AppCompatActivity() {
showProgressDialog = showProgressDialog =
if (settings.askIndividual) loadData<Boolean>("${media.id}_progressDialog") if (settings.askIndividual) loadData<Boolean>("${media.id}_progressDialog")
?: true else false ?: true else false
val incognito = val incognito = PrefWrapper.getVal(PrefName.Incognito, false)
currContext()?.getSharedPreferences("Dantotsu", Context.MODE_PRIVATE)
?.getBoolean("incognito", false) ?: false
if (showProgressDialog && !incognito) { if (showProgressDialog && !incognito) {
val dialogView = layoutInflater.inflate(R.layout.item_custom_dialog, null) val dialogView = layoutInflater.inflate(R.layout.item_custom_dialog, null)

View file

@ -32,7 +32,6 @@ import ani.dantotsu.databinding.ActivityNovelReaderBinding
import ani.dantotsu.hideSystemBars import ani.dantotsu.hideSystemBars
import ani.dantotsu.loadData import ani.dantotsu.loadData
import ani.dantotsu.others.ImageViewDialog import ani.dantotsu.others.ImageViewDialog
import ani.dantotsu.others.LangSet
import ani.dantotsu.saveData import ani.dantotsu.saveData
import ani.dantotsu.setSafeOnClickListener import ani.dantotsu.setSafeOnClickListener
import ani.dantotsu.settings.CurrentNovelReaderSettings import ani.dantotsu.settings.CurrentNovelReaderSettings
@ -171,7 +170,7 @@ class NovelReaderActivity : AppCompatActivity(), EbookReaderEventListener {
return return
} }
LangSet.setLocale(this)
ThemeManager(this).applyTheme() ThemeManager(this).applyTheme()
binding = ActivityNovelReaderBinding.inflate(layoutInflater) binding = ActivityNovelReaderBinding.inflate(layoutInflater)
setContentView(binding.root) setContentView(binding.root)

View file

@ -1,7 +1,6 @@
package ani.dantotsu.media.user package ani.dantotsu.media.user
import android.annotation.SuppressLint import android.annotation.SuppressLint
import android.content.Context
import android.os.Bundle import android.os.Bundle
import android.util.TypedValue import android.util.TypedValue
import android.view.View import android.view.View
@ -17,12 +16,12 @@ import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.lifecycleScope import androidx.lifecycle.lifecycleScope
import ani.dantotsu.R import ani.dantotsu.R
import ani.dantotsu.Refresh import ani.dantotsu.Refresh
import ani.dantotsu.currContext
import ani.dantotsu.databinding.ActivityListBinding import ani.dantotsu.databinding.ActivityListBinding
import ani.dantotsu.loadData import ani.dantotsu.loadData
import ani.dantotsu.navBarHeight import ani.dantotsu.navBarHeight
import ani.dantotsu.others.LangSet
import ani.dantotsu.settings.UserInterfaceSettings import ani.dantotsu.settings.UserInterfaceSettings
import ani.dantotsu.settings.saving.PrefName
import ani.dantotsu.settings.saving.PrefWrapper
import ani.dantotsu.statusBarHeight import ani.dantotsu.statusBarHeight
import ani.dantotsu.themes.ThemeManager import ani.dantotsu.themes.ThemeManager
import com.google.android.material.tabs.TabLayout import com.google.android.material.tabs.TabLayout
@ -39,7 +38,7 @@ class ListActivity : AppCompatActivity() {
@SuppressLint("SetTextI18n") @SuppressLint("SetTextI18n")
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
LangSet.setLocale(this)
ThemeManager(this).applyTheme() ThemeManager(this).applyTheme()
binding = ActivityListBinding.inflate(layoutInflater) binding = ActivityListBinding.inflate(layoutInflater)
@ -154,8 +153,10 @@ class ListActivity : AppCompatActivity() {
R.id.release -> "release" R.id.release -> "release"
else -> null else -> null
} }
currContext()?.getSharedPreferences("Dantotsu", Context.MODE_PRIVATE)?.edit() PrefWrapper.setVal(
?.putString("sort_order", sort)?.apply() if (anime) PrefName.AnimeListSortOrder else PrefName.MangaListSortOrder,
sort ?: ""
)
binding.listProgressBar.visibility = View.VISIBLE binding.listProgressBar.visibility = View.VISIBLE
binding.listViewPager.adapter = null binding.listViewPager.adapter = null
scope.launch { scope.launch {

View file

@ -11,6 +11,8 @@ import ani.dantotsu.R
import ani.dantotsu.databinding.FragmentOfflineBinding import ani.dantotsu.databinding.FragmentOfflineBinding
import ani.dantotsu.isOnline import ani.dantotsu.isOnline
import ani.dantotsu.navBarHeight import ani.dantotsu.navBarHeight
import ani.dantotsu.settings.saving.PrefName
import ani.dantotsu.settings.saving.PrefWrapper
import ani.dantotsu.startMainActivity import ani.dantotsu.startMainActivity
import ani.dantotsu.statusBarHeight import ani.dantotsu.statusBarHeight
@ -26,8 +28,7 @@ class OfflineFragment : Fragment() {
topMargin = statusBarHeight topMargin = statusBarHeight
bottomMargin = navBarHeight bottomMargin = navBarHeight
} }
offline = requireContext().getSharedPreferences("Dantotsu", Context.MODE_PRIVATE) offline = PrefWrapper.getVal(PrefName.OfflineMode, false)
?.getBoolean("offlineMode", false) ?: false
binding.noInternet.text = binding.noInternet.text =
if (offline) "Offline Mode" else getString(R.string.no_internet) if (offline) "Offline Mode" else getString(R.string.no_internet)
binding.refreshButton.visibility = if (offline) View.GONE else View.VISIBLE binding.refreshButton.visibility = if (offline) View.GONE else View.VISIBLE
@ -41,7 +42,6 @@ class OfflineFragment : Fragment() {
override fun onResume() { override fun onResume() {
super.onResume() super.onResume()
offline = requireContext().getSharedPreferences("Dantotsu", Context.MODE_PRIVATE) offline = PrefWrapper.getVal(PrefName.OfflineMode, false)
?.getBoolean("offlineMode", false) ?: false
} }
} }

View file

@ -1,22 +0,0 @@
package ani.dantotsu.others
import android.app.Activity
import android.content.res.Configuration
import android.content.res.Resources
import java.util.Locale
class LangSet {
companion object {
fun setLocale(activity: Activity) {
val useCursedLang = activity.getSharedPreferences("Dantotsu", Activity.MODE_PRIVATE)
.getBoolean("use_cursed_lang", false)
val locale = if (useCursedLang) Locale("en", "DW") else Locale("en", "US")
Locale.setDefault(locale)
val resources: Resources = activity.resources
val config: Configuration = resources.configuration
config.setLocale(locale)
resources.updateConfiguration(config, resources.displayMetrics)
}
}
}

View file

@ -19,7 +19,6 @@ import ani.dantotsu.databinding.ActivityImageSearchBinding
import ani.dantotsu.initActivity import ani.dantotsu.initActivity
import ani.dantotsu.media.MediaDetailsActivity import ani.dantotsu.media.MediaDetailsActivity
import ani.dantotsu.navBarHeight import ani.dantotsu.navBarHeight
import ani.dantotsu.others.LangSet
import ani.dantotsu.themes.ThemeManager import ani.dantotsu.themes.ThemeManager
import ani.dantotsu.toast import ani.dantotsu.toast
import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.Dispatchers
@ -52,7 +51,7 @@ class ImageSearchActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
LangSet.setLocale(this)
initActivity(this) initActivity(this)
ThemeManager(this).applyTheme() ThemeManager(this).applyTheme()
binding = ActivityImageSearchBinding.inflate(layoutInflater) binding = ActivityImageSearchBinding.inflate(layoutInflater)

View file

@ -3,6 +3,8 @@ package ani.dantotsu.parsers
import android.content.Context import android.content.Context
import ani.dantotsu.Lazier import ani.dantotsu.Lazier
import ani.dantotsu.lazyList import ani.dantotsu.lazyList
import ani.dantotsu.settings.saving.PrefName
import ani.dantotsu.settings.saving.PrefWrapper
import eu.kanade.tachiyomi.extension.anime.model.AnimeExtension import eu.kanade.tachiyomi.extension.anime.model.AnimeExtension
import kotlinx.coroutines.flow.StateFlow import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.first import kotlinx.coroutines.flow.first
@ -12,9 +14,7 @@ object AnimeSources : WatchSources() {
var pinnedAnimeSources: Set<String> = emptySet() var pinnedAnimeSources: Set<String> = emptySet()
suspend fun init(fromExtensions: StateFlow<List<AnimeExtension.Installed>>, context: Context) { suspend fun init(fromExtensions: StateFlow<List<AnimeExtension.Installed>>, context: Context) {
val sharedPrefs = context.getSharedPreferences("Dantotsu", Context.MODE_PRIVATE) pinnedAnimeSources = PrefWrapper.getVal(PrefName.PinnedAnimeSources, emptySet())
pinnedAnimeSources =
sharedPrefs.getStringSet("pinned_anime_sources", emptySet()) ?: emptySet()
// Initialize with the first value from StateFlow // Initialize with the first value from StateFlow
val initialExtensions = fromExtensions.first() val initialExtensions = fromExtensions.first()

View file

@ -3,6 +3,8 @@ package ani.dantotsu.parsers
import android.content.Context import android.content.Context
import ani.dantotsu.Lazier import ani.dantotsu.Lazier
import ani.dantotsu.lazyList import ani.dantotsu.lazyList
import ani.dantotsu.settings.saving.PrefName
import ani.dantotsu.settings.saving.PrefWrapper
import eu.kanade.tachiyomi.extension.manga.model.MangaExtension import eu.kanade.tachiyomi.extension.manga.model.MangaExtension
import kotlinx.coroutines.flow.StateFlow import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.first import kotlinx.coroutines.flow.first
@ -11,10 +13,8 @@ object MangaSources : MangaReadSources() {
override var list: List<Lazier<BaseParser>> = emptyList() override var list: List<Lazier<BaseParser>> = emptyList()
var pinnedMangaSources: Set<String> = emptySet() var pinnedMangaSources: Set<String> = emptySet()
suspend fun init(fromExtensions: StateFlow<List<MangaExtension.Installed>>, context: Context) { suspend fun init(fromExtensions: StateFlow<List<MangaExtension.Installed>>) {
val sharedPrefs = context.getSharedPreferences("Dantotsu", Context.MODE_PRIVATE) pinnedMangaSources = PrefWrapper.getVal(PrefName.PinnedMangaSources, emptySet())
pinnedMangaSources =
sharedPrefs.getStringSet("pinned_manga_sources", emptySet()) ?: emptySet()
// Initialize with the first value from StateFlow // Initialize with the first value from StateFlow
val initialExtensions = fromExtensions.first() val initialExtensions = fromExtensions.first()

View file

@ -4,6 +4,8 @@ package ani.dantotsu.parsers.novel
import android.content.Context import android.content.Context
import ani.dantotsu.currContext import ani.dantotsu.currContext
import ani.dantotsu.logger import ani.dantotsu.logger
import ani.dantotsu.settings.saving.PrefName
import ani.dantotsu.settings.saving.PrefWrapper
import eu.kanade.tachiyomi.extension.ExtensionUpdateNotifier import eu.kanade.tachiyomi.extension.ExtensionUpdateNotifier
import eu.kanade.tachiyomi.extension.anime.model.AnimeExtension import eu.kanade.tachiyomi.extension.anime.model.AnimeExtension
import eu.kanade.tachiyomi.extension.anime.model.AnimeLoadResult import eu.kanade.tachiyomi.extension.anime.model.AnimeLoadResult
@ -26,9 +28,7 @@ class NovelExtensionGithubApi {
private val novelExtensionManager: NovelExtensionManager by injectLazy() private val novelExtensionManager: NovelExtensionManager by injectLazy()
private val json: Json by injectLazy() private val json: Json by injectLazy()
private val lastExtCheck: Long = private val lastExtCheck: Long = PrefWrapper.getVal(PrefName.NovelLastExtCheck, 0L)
currContext()?.getSharedPreferences("Dantotsu", Context.MODE_PRIVATE)
?.getLong("last_ext_check", 0) ?: 0
private var requiresFallbackSource = false private var requiresFallbackSource = false
@ -86,8 +86,7 @@ class NovelExtensionGithubApi {
novelExtensionManager.availableExtensionsFlow.value novelExtensionManager.availableExtensionsFlow.value
} else { } else {
findExtensions().also { findExtensions().also {
context.getSharedPreferences("Dantotsu", Context.MODE_PRIVATE)?.edit() PrefWrapper.setVal(PrefName.NovelLastExtCheck, Date().time)
?.putLong("last_ext_check", Date().time)?.apply()
} }
} }

View file

@ -16,7 +16,6 @@ import androidx.viewpager2.adapter.FragmentStateAdapter
import androidx.viewpager2.widget.ViewPager2 import androidx.viewpager2.widget.ViewPager2
import ani.dantotsu.* import ani.dantotsu.*
import ani.dantotsu.databinding.ActivityExtensionsBinding import ani.dantotsu.databinding.ActivityExtensionsBinding
import ani.dantotsu.others.LangSet
import ani.dantotsu.themes.ThemeManager import ani.dantotsu.themes.ThemeManager
import com.google.android.material.tabs.TabLayout import com.google.android.material.tabs.TabLayout
import com.google.android.material.tabs.TabLayoutMediator import com.google.android.material.tabs.TabLayoutMediator
@ -27,7 +26,7 @@ class ExtensionsActivity : AppCompatActivity() {
@SuppressLint("SetTextI18n") @SuppressLint("SetTextI18n")
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
LangSet.setLocale(this)
ThemeManager(this).applyTheme() ThemeManager(this).applyTheme()
binding = ActivityExtensionsBinding.inflate(layoutInflater) binding = ActivityExtensionsBinding.inflate(layoutInflater)
setContentView(binding.root) setContentView(binding.root)

View file

@ -7,7 +7,6 @@ import ani.dantotsu.R
import ani.dantotsu.currContext import ani.dantotsu.currContext
import ani.dantotsu.databinding.ActivityFaqBinding import ani.dantotsu.databinding.ActivityFaqBinding
import ani.dantotsu.initActivity import ani.dantotsu.initActivity
import ani.dantotsu.others.LangSet
import ani.dantotsu.themes.ThemeManager import ani.dantotsu.themes.ThemeManager
class FAQActivity : AppCompatActivity() { class FAQActivity : AppCompatActivity() {
@ -101,7 +100,7 @@ class FAQActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
LangSet.setLocale(this)
ThemeManager(this).applyTheme() ThemeManager(this).applyTheme()
binding = ActivityFaqBinding.inflate(layoutInflater) binding = ActivityFaqBinding.inflate(layoutInflater)
setContentView(binding.root) setContentView(binding.root)

View file

@ -17,7 +17,6 @@ import ani.dantotsu.initActivity
import ani.dantotsu.loadData import ani.dantotsu.loadData
import ani.dantotsu.media.Media import ani.dantotsu.media.Media
import ani.dantotsu.navBarHeight import ani.dantotsu.navBarHeight
import ani.dantotsu.others.LangSet
import ani.dantotsu.others.getSerialized import ani.dantotsu.others.getSerialized
import ani.dantotsu.parsers.Subtitle import ani.dantotsu.parsers.Subtitle
import ani.dantotsu.saveData import ani.dantotsu.saveData
@ -39,7 +38,7 @@ class PlayerSettingsActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
LangSet.setLocale(this)
ThemeManager(this).applyTheme() ThemeManager(this).applyTheme()
binding = ActivityPlayerSettingsBinding.inflate(layoutInflater) binding = ActivityPlayerSettingsBinding.inflate(layoutInflater)
setContentView(binding.root) setContentView(binding.root)

View file

@ -9,7 +9,6 @@ import ani.dantotsu.databinding.ActivityReaderSettingsBinding
import ani.dantotsu.initActivity import ani.dantotsu.initActivity
import ani.dantotsu.loadData import ani.dantotsu.loadData
import ani.dantotsu.navBarHeight import ani.dantotsu.navBarHeight
import ani.dantotsu.others.LangSet
import ani.dantotsu.saveData import ani.dantotsu.saveData
import ani.dantotsu.snackString import ani.dantotsu.snackString
import ani.dantotsu.statusBarHeight import ani.dantotsu.statusBarHeight
@ -20,7 +19,7 @@ class ReaderSettingsActivity : AppCompatActivity() {
private val reader = "reader_settings" private val reader = "reader_settings"
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
LangSet.setLocale(this)
ThemeManager(this).applyTheme() ThemeManager(this).applyTheme()
binding = ActivityReaderSettingsBinding.inflate(layoutInflater) binding = ActivityReaderSettingsBinding.inflate(layoutInflater)
setContentView(binding.root) setContentView(binding.root)

View file

@ -32,9 +32,10 @@ import ani.dantotsu.download.DownloadsManager
import ani.dantotsu.download.video.ExoplayerDownloadService import ani.dantotsu.download.video.ExoplayerDownloadService
import ani.dantotsu.others.AppUpdater import ani.dantotsu.others.AppUpdater
import ani.dantotsu.others.CustomBottomDialog import ani.dantotsu.others.CustomBottomDialog
import ani.dantotsu.others.LangSet
import ani.dantotsu.parsers.AnimeSources import ani.dantotsu.parsers.AnimeSources
import ani.dantotsu.parsers.MangaSources import ani.dantotsu.parsers.MangaSources
import ani.dantotsu.settings.saving.PrefName
import ani.dantotsu.settings.saving.PrefWrapper
import ani.dantotsu.subcriptions.Notifications import ani.dantotsu.subcriptions.Notifications
import ani.dantotsu.subcriptions.Notifications.Companion.openSettings import ani.dantotsu.subcriptions.Notifications.Companion.openSettings
import ani.dantotsu.subcriptions.Subscription.Companion.defaultTime import ani.dantotsu.subcriptions.Subscription.Companion.defaultTime
@ -71,7 +72,7 @@ class SettingsActivity : AppCompatActivity(), SimpleDialog.OnDialogResultListene
@SuppressLint("SetTextI18n") @SuppressLint("SetTextI18n")
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
LangSet.setLocale(this)
ThemeManager(this).applyTheme() ThemeManager(this).applyTheme()
binding = ActivitySettingsBinding.inflate(layoutInflater) binding = ActivitySettingsBinding.inflate(layoutInflater)
setContentView(binding.root) setContentView(binding.root)
@ -96,26 +97,16 @@ class SettingsActivity : AppCompatActivity(), SimpleDialog.OnDialogResultListene
onBackPressedDispatcher.onBackPressed() onBackPressedDispatcher.onBackPressed()
} }
binding.settingsUseMaterialYou.isChecked = binding.settingsUseMaterialYou.isChecked = PrefWrapper.getVal(PrefName.UseMaterialYou, false)
getSharedPreferences("Dantotsu", Context.MODE_PRIVATE).getBoolean(
"use_material_you",
false
)
binding.settingsUseMaterialYou.setOnCheckedChangeListener { _, isChecked -> binding.settingsUseMaterialYou.setOnCheckedChangeListener { _, isChecked ->
getSharedPreferences("Dantotsu", Context.MODE_PRIVATE).edit() PrefWrapper.setVal(PrefName.UseMaterialYou, isChecked)
.putBoolean("use_material_you", isChecked).apply()
if (isChecked) binding.settingsUseCustomTheme.isChecked = false if (isChecked) binding.settingsUseCustomTheme.isChecked = false
restartApp() restartApp()
} }
binding.settingsUseCustomTheme.isChecked = binding.settingsUseCustomTheme.isChecked = PrefWrapper.getVal(PrefName.UseCustomTheme, false)
getSharedPreferences("Dantotsu", Context.MODE_PRIVATE).getBoolean(
"use_custom_theme",
false
)
binding.settingsUseCustomTheme.setOnCheckedChangeListener { _, isChecked -> binding.settingsUseCustomTheme.setOnCheckedChangeListener { _, isChecked ->
getSharedPreferences("Dantotsu", Context.MODE_PRIVATE).edit() PrefWrapper.setVal(PrefName.UseCustomTheme, isChecked)
.putBoolean("use_custom_theme", isChecked).apply()
if (isChecked) { if (isChecked) {
binding.settingsUseMaterialYou.isChecked = false binding.settingsUseMaterialYou.isChecked = false
} }
@ -123,26 +114,19 @@ class SettingsActivity : AppCompatActivity(), SimpleDialog.OnDialogResultListene
restartApp() restartApp()
} }
binding.settingsUseSourceTheme.isChecked = binding.settingsUseSourceTheme.isChecked = PrefWrapper.getVal(PrefName.UseSourceTheme, false)
getSharedPreferences("Dantotsu", Context.MODE_PRIVATE).getBoolean(
"use_source_theme",
false
)
binding.settingsUseSourceTheme.setOnCheckedChangeListener { _, isChecked -> binding.settingsUseSourceTheme.setOnCheckedChangeListener { _, isChecked ->
getSharedPreferences("Dantotsu", Context.MODE_PRIVATE).edit() PrefWrapper.setVal(PrefName.UseSourceTheme, isChecked)
.putBoolean("use_source_theme", isChecked).apply()
}
binding.settingsUseOLED.isChecked =
getSharedPreferences("Dantotsu", Context.MODE_PRIVATE).getBoolean("use_oled", false)
binding.settingsUseOLED.setOnCheckedChangeListener { _, isChecked ->
getSharedPreferences("Dantotsu", Context.MODE_PRIVATE).edit()
.putBoolean("use_oled", isChecked).apply()
restartApp() restartApp()
} }
val themeString = binding.settingsUseOLED.isChecked = PrefWrapper.getVal(PrefName.UseOLED, false)
getSharedPreferences("Dantotsu", Context.MODE_PRIVATE).getString("theme", "PURPLE")!! binding.settingsUseOLED.setOnCheckedChangeListener { _, isChecked ->
PrefWrapper.setVal(PrefName.UseOLED, isChecked)
restartApp()
}
val themeString = PrefWrapper.getVal(PrefName.Theme, "PURPLE")
binding.themeSwitcher.setText( binding.themeSwitcher.setText(
themeString.substring(0, 1) + themeString.substring(1).lowercase() themeString.substring(0, 1) + themeString.substring(1).lowercase()
) )
@ -151,13 +135,12 @@ class SettingsActivity : AppCompatActivity(), SimpleDialog.OnDialogResultListene
ArrayAdapter( ArrayAdapter(
this, this,
R.layout.item_dropdown, R.layout.item_dropdown,
ThemeManager.Companion.Theme.values() ThemeManager.Companion.Theme.entries
.map { it.theme.substring(0, 1) + it.theme.substring(1).lowercase() }) .map { it.theme.substring(0, 1) + it.theme.substring(1).lowercase() })
) )
binding.themeSwitcher.setOnItemClickListener { _, _, i, _ -> binding.themeSwitcher.setOnItemClickListener { _, _, i, _ ->
getSharedPreferences("Dantotsu", Context.MODE_PRIVATE).edit() PrefWrapper.setVal(PrefName.Theme, ThemeManager.Companion.Theme.entries[i].theme)
.putString("theme", ThemeManager.Companion.Theme.values()[i].theme).apply()
//ActivityHelper.shouldRefreshMainActivity = true //ActivityHelper.shouldRefreshMainActivity = true
binding.themeSwitcher.clearFocus() binding.themeSwitcher.clearFocus()
restartApp() restartApp()
@ -166,10 +149,7 @@ class SettingsActivity : AppCompatActivity(), SimpleDialog.OnDialogResultListene
binding.customTheme.setOnClickListener { binding.customTheme.setOnClickListener {
val originalColor = getSharedPreferences("Dantotsu", MODE_PRIVATE).getInt( val originalColor = PrefWrapper.getVal(PrefName.CustomThemeInt, Color.parseColor("#6200EE"))
"custom_theme_int",
Color.parseColor("#6200EE")
)
class CustomColorDialog : SimpleColorDialog() { //idk where to put it class CustomColorDialog : SimpleColorDialog() { //idk where to put it
override fun onPositiveButtonClick() { override fun onPositiveButtonClick() {
@ -196,11 +176,8 @@ class SettingsActivity : AppCompatActivity(), SimpleDialog.OnDialogResultListene
val names = animeSourcesWithoutDownloadsSource.map { it.name } val names = animeSourcesWithoutDownloadsSource.map { it.name }
val pinnedSourcesBoolean = val pinnedSourcesBoolean =
animeSourcesWithoutDownloadsSource.map { it.name in AnimeSources.pinnedAnimeSources } animeSourcesWithoutDownloadsSource.map { it.name in AnimeSources.pinnedAnimeSources }
val pinnedSourcesOriginal = getSharedPreferences( val pinnedSourcesOriginal = PrefWrapper.getVal(PrefName.PinnedAnimeSources, setOf<String>())
"Dantotsu", val pinnedSources = pinnedSourcesOriginal.toMutableSet() ?: mutableSetOf()
Context.MODE_PRIVATE
).getStringSet("pinned_anime_sources", null)
val pinnedSources = pinnedSourcesOriginal?.toMutableSet() ?: mutableSetOf()
val alertDialog = AlertDialog.Builder(this, R.style.MyPopup) val alertDialog = AlertDialog.Builder(this, R.style.MyPopup)
.setTitle("Pinned Anime Sources") .setTitle("Pinned Anime Sources")
.setMultiChoiceItems( .setMultiChoiceItems(
@ -214,8 +191,7 @@ class SettingsActivity : AppCompatActivity(), SimpleDialog.OnDialogResultListene
} }
} }
.setPositiveButton("OK") { dialog, _ -> .setPositiveButton("OK") { dialog, _ ->
getSharedPreferences("Dantotsu", Context.MODE_PRIVATE).edit() PrefWrapper.setVal(PrefName.PinnedAnimeSources, pinnedSources)
.putStringSet("pinned_anime_sources", pinnedSources).apply()
AnimeSources.pinnedAnimeSources = pinnedSources AnimeSources.pinnedAnimeSources = pinnedSources
AnimeSources.performReorderAnimeSources() AnimeSources.performReorderAnimeSources()
dialog.dismiss() dialog.dismiss()
@ -395,15 +371,9 @@ class SettingsActivity : AppCompatActivity(), SimpleDialog.OnDialogResultListene
binding.settingsRecentlyListOnly.setOnCheckedChangeListener { _, isChecked -> binding.settingsRecentlyListOnly.setOnCheckedChangeListener { _, isChecked ->
saveData("recently_list_only", isChecked) saveData("recently_list_only", isChecked)
} }
binding.settingsShareUsername.isChecked = getSharedPreferences( binding.settingsShareUsername.isChecked = PrefWrapper.getVal(PrefName.SharedUserID, true)
getString(R.string.preference_file_key),
Context.MODE_PRIVATE
).getBoolean("shared_user_id", true)
binding.settingsShareUsername.setOnCheckedChangeListener { _, isChecked -> binding.settingsShareUsername.setOnCheckedChangeListener { _, isChecked ->
getSharedPreferences( PrefWrapper.setVal(PrefName.SharedUserID, isChecked)
getString(R.string.preference_file_key),
Context.MODE_PRIVATE
).edit().putBoolean("shared_user_id", isChecked).apply()
} }
binding.settingsPreferDub.isChecked = loadData("settings_prefer_dub") ?: false binding.settingsPreferDub.isChecked = loadData("settings_prefer_dub") ?: false
@ -417,11 +387,8 @@ class SettingsActivity : AppCompatActivity(), SimpleDialog.OnDialogResultListene
val names = mangaSourcesWithoutDownloadsSource.map { it.name } val names = mangaSourcesWithoutDownloadsSource.map { it.name }
val pinnedSourcesBoolean = val pinnedSourcesBoolean =
mangaSourcesWithoutDownloadsSource.map { it.name in MangaSources.pinnedMangaSources } mangaSourcesWithoutDownloadsSource.map { it.name in MangaSources.pinnedMangaSources }
val pinnedSourcesOriginal = getSharedPreferences( val pinnedSourcesOriginal = PrefWrapper.getVal(PrefName.PinnedMangaSources, setOf<String>())
"Dantotsu", val pinnedSources = pinnedSourcesOriginal.toMutableSet()
Context.MODE_PRIVATE
).getStringSet("pinned_manga_sources", null)
val pinnedSources = pinnedSourcesOriginal?.toMutableSet() ?: mutableSetOf()
val alertDialog = AlertDialog.Builder(this, R.style.MyPopup) val alertDialog = AlertDialog.Builder(this, R.style.MyPopup)
.setTitle("Pinned Manga Sources") .setTitle("Pinned Manga Sources")
.setMultiChoiceItems( .setMultiChoiceItems(
@ -435,8 +402,7 @@ class SettingsActivity : AppCompatActivity(), SimpleDialog.OnDialogResultListene
} }
} }
.setPositiveButton("OK") { dialog, _ -> .setPositiveButton("OK") { dialog, _ ->
getSharedPreferences("Dantotsu", Context.MODE_PRIVATE).edit() PrefWrapper.setVal(PrefName.PinnedMangaSources, pinnedSources)
.putStringSet("pinned_manga_sources", pinnedSources).apply()
MangaSources.pinnedMangaSources = pinnedSources MangaSources.pinnedMangaSources = pinnedSources
MangaSources.performReorderMangaSources() MangaSources.performReorderMangaSources()
dialog.dismiss() dialog.dismiss()
@ -605,13 +571,7 @@ class SettingsActivity : AppCompatActivity(), SimpleDialog.OnDialogResultListene
Toast.makeText(this, "youwu have been cuwsed :pwayge:", Toast.LENGTH_LONG).show() Toast.makeText(this, "youwu have been cuwsed :pwayge:", Toast.LENGTH_LONG).show()
val url = "https://www.youtube.com/watch?v=dQw4w9WgXcQ" val url = "https://www.youtube.com/watch?v=dQw4w9WgXcQ"
openLinkInBrowser(url) openLinkInBrowser(url)
getSharedPreferences("Dantotsu", Context.MODE_PRIVATE).edit().putBoolean( //PrefWrapper.setVal(PrefName.SomethingSpecial, !PrefWrapper.getVal(PrefName.SomethingSpecial, false))
"use_cursed_lang",
getSharedPreferences(
"Dantotsu",
Context.MODE_PRIVATE
).getBoolean("use_cursed_lang", false).not()
).apply()
} else { } else {
snackString(array[(Math.random() * array.size).toInt()], this) snackString(array[(Math.random() * array.size).toInt()], this)
} }
@ -772,18 +732,9 @@ class SettingsActivity : AppCompatActivity(), SimpleDialog.OnDialogResultListene
} }
if (Discord.token != null) { if (Discord.token != null) {
val id = getSharedPreferences( val id = PrefWrapper.getVal(PrefName.DiscordId, null as String?)
getString(R.string.preference_file_key), val avatar = PrefWrapper.getVal(PrefName.DiscordAvatar, null as String?)
Context.MODE_PRIVATE val username = PrefWrapper.getVal(PrefName.DiscordUserName, null as String?)
).getString("discord_id", null)
val avatar = getSharedPreferences(
getString(R.string.preference_file_key),
Context.MODE_PRIVATE
).getString("discord_avatar", null)
val username = getSharedPreferences(
getString(R.string.preference_file_key),
Context.MODE_PRIVATE
).getString("discord_username", null)
if (id != null && avatar != null) { if (id != null && avatar != null) {
binding.settingsDiscordAvatar.loadImage("https://cdn.discordapp.com/avatars/$id/$avatar.png") binding.settingsDiscordAvatar.loadImage("https://cdn.discordapp.com/avatars/$id/$avatar.png")
} }
@ -838,8 +789,7 @@ class SettingsActivity : AppCompatActivity(), SimpleDialog.OnDialogResultListene
if (which == BUTTON_POSITIVE) { if (which == BUTTON_POSITIVE) {
if (dialogTag == "colorPicker") { if (dialogTag == "colorPicker") {
val color = extras.getInt(SimpleColorDialog.COLOR) val color = extras.getInt(SimpleColorDialog.COLOR)
getSharedPreferences("Dantotsu", Context.MODE_PRIVATE).edit() PrefWrapper.setVal(PrefName.CustomThemeInt, color)
.putInt("custom_theme_int", color).apply()
logger("Custom Theme: $color") logger("Custom Theme: $color")
} }
} }

View file

@ -1,6 +1,5 @@
package ani.dantotsu.settings package ani.dantotsu.settings
import android.content.Context
import android.content.Intent import android.content.Intent
import android.graphics.Color import android.graphics.Color
import android.os.Bundle import android.os.Bundle
@ -26,6 +25,8 @@ import ani.dantotsu.offline.OfflineFragment
import ani.dantotsu.openLinkInBrowser import ani.dantotsu.openLinkInBrowser
import ani.dantotsu.others.imagesearch.ImageSearchActivity import ani.dantotsu.others.imagesearch.ImageSearchActivity
import ani.dantotsu.setSafeOnClickListener import ani.dantotsu.setSafeOnClickListener
import ani.dantotsu.settings.saving.PrefName
import ani.dantotsu.settings.saving.PrefWrapper
import ani.dantotsu.startMainActivity import ani.dantotsu.startMainActivity
class SettingsDialogFragment : BottomSheetDialogFragment() { class SettingsDialogFragment : BottomSheetDialogFragment() {
@ -75,14 +76,10 @@ class SettingsDialogFragment : BottomSheetDialogFragment() {
} }
binding.settingsIncognito.isChecked = binding.settingsIncognito.isChecked =
context?.getSharedPreferences("Dantotsu", Context.MODE_PRIVATE)?.getBoolean( PrefWrapper.getVal(PrefName.Incognito, false)
"incognito",
false
) ?: false
binding.settingsIncognito.setOnCheckedChangeListener { _, isChecked -> binding.settingsIncognito.setOnCheckedChangeListener { _, isChecked ->
context?.getSharedPreferences("Dantotsu", Context.MODE_PRIVATE)?.edit() PrefWrapper.setVal(PrefName.Incognito, isChecked)
?.putBoolean("incognito", isChecked)?.apply()
incognitoNotification(requireContext()) incognitoNotification(requireContext())
} }
binding.settingsExtensionSettings.setSafeOnClickListener { binding.settingsExtensionSettings.setSafeOnClickListener {
@ -102,9 +99,7 @@ class SettingsDialogFragment : BottomSheetDialogFragment() {
dismiss() dismiss()
} }
binding.settingsDownloads.isChecked = binding.settingsDownloads.isChecked = PrefWrapper.getVal(PrefName.OfflineMode, false)
context?.getSharedPreferences("Dantotsu", Context.MODE_PRIVATE)
?.getBoolean("offlineMode", false) ?: false
binding.settingsDownloads.setOnCheckedChangeListener { _, isChecked -> binding.settingsDownloads.setOnCheckedChangeListener { _, isChecked ->
when (pageType) { when (pageType) {
PageType.MANGA -> { PageType.MANGA -> {
@ -154,8 +149,7 @@ class SettingsDialogFragment : BottomSheetDialogFragment() {
} }
dismiss() dismiss()
context?.getSharedPreferences("Dantotsu", Context.MODE_PRIVATE)?.edit() PrefWrapper.setVal(PrefName.OfflineMode, isChecked)
?.putBoolean("offlineMode", isChecked)?.apply()
} }
} }

View file

@ -11,7 +11,6 @@ import ani.dantotsu.databinding.ActivityUserInterfaceSettingsBinding
import ani.dantotsu.initActivity import ani.dantotsu.initActivity
import ani.dantotsu.loadData import ani.dantotsu.loadData
import ani.dantotsu.navBarHeight import ani.dantotsu.navBarHeight
import ani.dantotsu.others.LangSet
import ani.dantotsu.saveData import ani.dantotsu.saveData
import ani.dantotsu.statusBarHeight import ani.dantotsu.statusBarHeight
import ani.dantotsu.themes.ThemeManager import ani.dantotsu.themes.ThemeManager
@ -22,7 +21,7 @@ class UserInterfaceSettingsActivity : AppCompatActivity() {
private val ui = "ui_settings" private val ui = "ui_settings"
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
LangSet.setLocale(this)
ThemeManager(this).applyTheme() ThemeManager(this).applyTheme()
binding = ActivityUserInterfaceSettingsBinding.inflate(layoutInflater) binding = ActivityUserInterfaceSettingsBinding.inflate(layoutInflater)
setContentView(binding.root) setContentView(binding.root)

View file

@ -0,0 +1,171 @@
package ani.dantotsu.settings.saving
import android.content.Context
import android.content.SharedPreferences
import ani.dantotsu.settings.saving.internal.Location
object PrefWrapper {
private var generalPreferences: SharedPreferences? = null
private var animePreferences: SharedPreferences? = null
private var mangaPreferences: SharedPreferences? = null
private var playerPreferences: SharedPreferences? = null
private var readerPreferences: SharedPreferences? = null
private var irrelevantPreferences: SharedPreferences? = null
private var animeDownloadsPreferences: SharedPreferences? = null
private var protectedPreferences: SharedPreferences? = null
fun init(context: Context) {
generalPreferences = context.getSharedPreferences(Location.General.location, Context.MODE_PRIVATE)
animePreferences = context.getSharedPreferences(Location.Anime.location, Context.MODE_PRIVATE)
mangaPreferences = context.getSharedPreferences(Location.Manga.location, Context.MODE_PRIVATE)
playerPreferences = context.getSharedPreferences(Location.Player.location, Context.MODE_PRIVATE)
readerPreferences = context.getSharedPreferences(Location.Reader.location, Context.MODE_PRIVATE)
irrelevantPreferences = context.getSharedPreferences(Location.Irrelevant.location, Context.MODE_PRIVATE)
animeDownloadsPreferences = context.getSharedPreferences(Location.AnimeDownloads.location, Context.MODE_PRIVATE)
protectedPreferences = context.getSharedPreferences(Location.Protected.location, Context.MODE_PRIVATE)
}
@Suppress("UNCHECKED_CAST")
fun <T> setVal(prefName: PrefName, value: T) {
val pref = when (prefName.data.prefLocation) {
Location.General -> generalPreferences
Location.Anime -> animePreferences
Location.Manga -> mangaPreferences
Location.Player -> playerPreferences
Location.Reader -> readerPreferences
Location.Irrelevant -> irrelevantPreferences
Location.AnimeDownloads -> animeDownloadsPreferences
Location.Protected -> protectedPreferences
}
with(pref!!.edit()) {
when (prefName.data.type) {
Boolean::class -> putBoolean(prefName.name, value as Boolean)
Int::class -> putInt(prefName.name, value as Int)
Float::class -> putFloat(prefName.name, value as Float)
Long::class -> putLong(prefName.name, value as Long)
String::class -> putString(prefName.name, value as String)
Set::class -> putStringSet(prefName.name, value as Set<String>)
else -> throw IllegalArgumentException("Type not supported")
}
apply()
}
}
@Suppress("UNCHECKED_CAST")
fun <T> getVal(prefName: PrefName, default: T) : T {
return try {
val pref = when (prefName.data.prefLocation) {
Location.General -> generalPreferences
Location.Anime -> animePreferences
Location.Manga -> mangaPreferences
Location.Player -> playerPreferences
Location.Reader -> readerPreferences
Location.Irrelevant -> irrelevantPreferences
Location.AnimeDownloads -> animeDownloadsPreferences
Location.Protected -> protectedPreferences
}
when (prefName.data.type) {
Boolean::class -> pref!!.getBoolean(prefName.name, default as Boolean) as T
Int::class -> pref!!.getInt(prefName.name, default as Int) as T
Float::class -> pref!!.getFloat(prefName.name, default as Float) as T
Long::class -> pref!!.getLong(prefName.name, default as Long) as T
String::class -> pref!!.getString(prefName.name, default as String) as T
Set::class -> pref!!.getStringSet(prefName.name, default as Set<String>) as T
else -> throw IllegalArgumentException("Type not supported")
}
} catch (e: Exception) {
default
}
}
@Suppress("UNCHECKED_CAST")
fun <T> getLiveVal(prefName: PrefName, default: T) : SharedPreferenceLiveData<T> {
val pref = when (prefName.data.prefLocation) {
Location.General -> generalPreferences
Location.Anime -> animePreferences
Location.Manga -> mangaPreferences
Location.Player -> playerPreferences
Location.Reader -> readerPreferences
Location.Irrelevant -> irrelevantPreferences
Location.AnimeDownloads -> animeDownloadsPreferences
Location.Protected -> protectedPreferences
}
return when (prefName.data.type) {
Boolean::class -> SharedPreferenceBooleanLiveData(
pref!!,
prefName.name,
default as Boolean
) as SharedPreferenceLiveData<T>
Int::class -> SharedPreferenceIntLiveData(
pref!!,
prefName.name,
default as Int
) as SharedPreferenceLiveData<T>
Float::class -> SharedPreferenceFloatLiveData(
pref!!,
prefName.name,
default as Float
) as SharedPreferenceLiveData<T>
Long::class -> SharedPreferenceLongLiveData(
pref!!,
prefName.name,
default as Long
) as SharedPreferenceLiveData<T>
String::class -> SharedPreferenceStringLiveData(
pref!!,
prefName.name,
default as String
) as SharedPreferenceLiveData<T>
Set::class -> SharedPreferenceStringSetLiveData(
pref!!,
prefName.name,
default as Set<String>
) as SharedPreferenceLiveData<T>
else -> throw IllegalArgumentException("Type not supported")
}
}
fun removeVal(prefName: PrefName) {
val pref = when (prefName.data.prefLocation) {
Location.General -> generalPreferences
Location.Anime -> animePreferences
Location.Manga -> mangaPreferences
Location.Player -> playerPreferences
Location.Reader -> readerPreferences
Location.Irrelevant -> irrelevantPreferences
Location.AnimeDownloads -> animeDownloadsPreferences
Location.Protected -> protectedPreferences
}
with(pref!!.edit()) {
remove(prefName.name)
apply()
}
}
fun SharedPreferenceLiveData<*>.asLiveBool(): SharedPreferenceBooleanLiveData =
this as? SharedPreferenceBooleanLiveData
?: throw ClassCastException("Cannot cast to SharedPreferenceLiveData<Boolean>")
fun SharedPreferenceLiveData<*>.asLiveInt(): SharedPreferenceIntLiveData =
this as? SharedPreferenceIntLiveData
?: throw ClassCastException("Cannot cast to SharedPreferenceLiveData<Int>")
fun SharedPreferenceLiveData<*>.asLiveFloat(): SharedPreferenceFloatLiveData =
this as? SharedPreferenceFloatLiveData
?: throw ClassCastException("Cannot cast to SharedPreferenceLiveData<Float>")
fun SharedPreferenceLiveData<*>.asLiveLong(): SharedPreferenceLongLiveData =
this as? SharedPreferenceLongLiveData
?: throw ClassCastException("Cannot cast to SharedPreferenceLiveData<Long>")
fun SharedPreferenceLiveData<*>.asLiveString(): SharedPreferenceStringLiveData =
this as? SharedPreferenceStringLiveData
?: throw ClassCastException("Cannot cast to SharedPreferenceLiveData<String>")
fun SharedPreferenceLiveData<*>.asLiveStringSet(): SharedPreferenceStringSetLiveData =
this as? SharedPreferenceStringSetLiveData
?: throw ClassCastException("Cannot cast to SharedPreferenceLiveData<Set<String>>")
fun getAnimeDownloadPreferences(): SharedPreferences = animeDownloadsPreferences!! //needs to be used externally
}

View file

@ -0,0 +1,43 @@
package ani.dantotsu.settings.saving
import ani.dantotsu.settings.saving.internal.Pref
import ani.dantotsu.settings.saving.internal.Location
enum class PrefName(val data: Pref) {
//General
SharedUserID(Pref(Location.General, Boolean::class)),
OfflineView(Pref(Location.General, Int::class)),
UseOLED(Pref(Location.General, Boolean::class)),
UseCustomTheme(Pref(Location.General, Boolean::class)),
CustomThemeInt(Pref(Location.General, Int::class)),
UseSourceTheme(Pref(Location.General, Boolean::class)),
UseMaterialYou(Pref(Location.General, Boolean::class)),
Theme(Pref(Location.General, String::class)),
//Anime
AnimeListSortOrder(Pref(Location.Anime, String::class)),
PinnedAnimeSources(Pref(Location.Anime, Set::class)),
PopularAnimeList(Pref(Location.Anime, Boolean::class)),
AnimeSearchHistory(Pref(Location.Anime, Set::class)),
//Manga
MangaListSortOrder(Pref(Location.Manga, String::class)),
PinnedMangaSources(Pref(Location.Manga, Set::class)),
PopularMangaList(Pref(Location.Manga, Boolean::class)),
MangaSearchHistory(Pref(Location.Manga, Set::class)),
//Irrelevant
Incognito(Pref(Location.Irrelevant, Boolean::class)),
OfflineMode(Pref(Location.Irrelevant, Boolean::class)),
DownloadsKeys(Pref(Location.Irrelevant, String::class)),
NovelLastExtCheck(Pref(Location.Irrelevant, Long::class)),
SomethingSpecial(Pref(Location.Irrelevant, Boolean::class)),
//Protected
DiscordToken(Pref(Location.Protected, String::class)),
DiscordId(Pref(Location.Protected, String::class)),
DiscordUserName(Pref(Location.Protected, String::class)),
DiscordAvatar(Pref(Location.Protected, String::class)),
AnilistUserName(Pref(Location.Protected, String::class)),
}

View file

@ -1,4 +1,4 @@
package ani.dantotsu.others package ani.dantotsu.settings.saving
import android.content.SharedPreferences import android.content.SharedPreferences
import androidx.lifecycle.LiveData import androidx.lifecycle.LiveData

View file

@ -0,0 +1,19 @@
package ani.dantotsu.settings.saving.internal
import kotlin.reflect.KClass
data class Pref(
val prefLocation: Location,
val type: KClass<*>
)
enum class Location(val location: String) {
General("ani.dantotsu.general"),
Anime("ani.dantotsu.anime"),
Manga("ani.dantotsu.manga"),
Player("ani.dantotsu.player"),
Reader("ani.dantotsu.reader"),
Irrelevant("ani.dantotsu.irrelevant"),
AnimeDownloads("animeDownloads"), //different for legacy reasons
Protected("ani.dantotsu.protected")
}

View file

@ -5,14 +5,14 @@ import android.content.BroadcastReceiver
import android.content.Context import android.content.Context
import android.content.Intent import android.content.Intent
import ani.dantotsu.INCOGNITO_CHANNEL_ID import ani.dantotsu.INCOGNITO_CHANNEL_ID
import ani.dantotsu.settings.saving.PrefName
import ani.dantotsu.settings.saving.PrefWrapper
class NotificationClickReceiver : BroadcastReceiver() { class NotificationClickReceiver : BroadcastReceiver() {
override fun onReceive(context: Context, intent: Intent?) { override fun onReceive(context: Context, intent: Intent?) {
context.getSharedPreferences("Dantotsu", Context.MODE_PRIVATE).edit() PrefWrapper.setVal(PrefName.Incognito, false)
.putBoolean("incognito", false)
.apply()
val notificationManager = val notificationManager =
context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
notificationManager.cancel(INCOGNITO_CHANNEL_ID) notificationManager.cancel(INCOGNITO_CHANNEL_ID)

View file

@ -7,22 +7,19 @@ import android.graphics.Bitmap
import android.view.Window import android.view.Window
import android.view.WindowManager import android.view.WindowManager
import ani.dantotsu.R import ani.dantotsu.R
import ani.dantotsu.settings.saving.PrefName
import ani.dantotsu.settings.saving.PrefWrapper
import com.google.android.material.color.DynamicColors import com.google.android.material.color.DynamicColors
import com.google.android.material.color.DynamicColorsOptions import com.google.android.material.color.DynamicColorsOptions
class ThemeManager(private val context: Activity) { class ThemeManager(private val context: Activity) {
fun applyTheme(fromImage: Bitmap? = null) { fun applyTheme(fromImage: Bitmap? = null) {
val useOLED = context.getSharedPreferences("Dantotsu", Context.MODE_PRIVATE) val useOLED = PrefWrapper.getVal(PrefName.UseOLED, false) && isDarkThemeActive(context)
.getBoolean("use_oled", false) && isDarkThemeActive(context) val useCustomTheme = PrefWrapper.getVal(PrefName.UseCustomTheme, false)
val useCustomTheme = context.getSharedPreferences("Dantotsu", Context.MODE_PRIVATE) val customTheme = PrefWrapper.getVal(PrefName.CustomThemeInt, 16712221)
.getBoolean("use_custom_theme", false) val useSource = PrefWrapper.getVal(PrefName.UseSourceTheme, false)
val customTheme = context.getSharedPreferences("Dantotsu", Context.MODE_PRIVATE) val useMaterial = PrefWrapper.getVal(PrefName.UseMaterialYou, false)
.getInt("custom_theme_int", 16712221)
val useSource = context.getSharedPreferences("Dantotsu", Context.MODE_PRIVATE)
.getBoolean("use_source_theme", false)
val useMaterial = context.getSharedPreferences("Dantotsu", Context.MODE_PRIVATE)
.getBoolean("use_material_you", false)
if (useSource) { if (useSource) {
val returnedEarly = applyDynamicColors( val returnedEarly = applyDynamicColors(
useMaterial, useMaterial,
@ -40,8 +37,7 @@ class ThemeManager(private val context: Activity) {
val returnedEarly = applyDynamicColors(useMaterial, context, useOLED, useCustom = null) val returnedEarly = applyDynamicColors(useMaterial, context, useOLED, useCustom = null)
if (!returnedEarly) return if (!returnedEarly) return
} }
val theme = context.getSharedPreferences("Dantotsu", Context.MODE_PRIVATE) val theme = PrefWrapper.getVal(PrefName.Theme, "PURPLE")
.getString("theme", "PURPLE")!!
val themeToApply = when (theme) { val themeToApply = when (theme) {
"BLUE" -> if (useOLED) R.style.Theme_Dantotsu_BlueOLED else R.style.Theme_Dantotsu_Blue "BLUE" -> if (useOLED) R.style.Theme_Dantotsu_BlueOLED else R.style.Theme_Dantotsu_Blue

View file

@ -9,7 +9,6 @@ import android.view.View
import android.widget.EditText import android.widget.EditText
import ani.dantotsu.R import ani.dantotsu.R
import ani.dantotsu.databinding.CurrentlyAiringWidgetConfigureBinding import ani.dantotsu.databinding.CurrentlyAiringWidgetConfigureBinding
import ani.dantotsu.others.LangSet
import ani.dantotsu.themes.ThemeManager import ani.dantotsu.themes.ThemeManager
/** /**
@ -46,7 +45,7 @@ class CurrentlyAiringWidgetConfigureActivity : Activity() {
private lateinit var binding: CurrentlyAiringWidgetConfigureBinding private lateinit var binding: CurrentlyAiringWidgetConfigureBinding
public override fun onCreate(icicle: Bundle?) { public override fun onCreate(icicle: Bundle?) {
LangSet.setLocale(this)
ThemeManager(this).applyTheme() ThemeManager(this).applyTheme()
super.onCreate(icicle) super.onCreate(icicle)

View file

@ -3,7 +3,6 @@ package eu.kanade.tachiyomi.extension.anime.util
import android.app.Activity import android.app.Activity
import android.content.Intent import android.content.Intent
import android.os.Bundle import android.os.Bundle
import ani.dantotsu.others.LangSet
import ani.dantotsu.themes.ThemeManager import ani.dantotsu.themes.ThemeManager
import eu.kanade.tachiyomi.extension.InstallStep import eu.kanade.tachiyomi.extension.InstallStep
import eu.kanade.tachiyomi.extension.anime.AnimeExtensionManager import eu.kanade.tachiyomi.extension.anime.AnimeExtensionManager
@ -26,7 +25,7 @@ class AnimeExtensionInstallActivity : Activity() {
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
LangSet.setLocale(this)
ThemeManager(this).applyTheme() ThemeManager(this).applyTheme()
val installIntent = Intent(Intent.ACTION_INSTALL_PACKAGE) val installIntent = Intent(Intent.ACTION_INSTALL_PACKAGE)

View file

@ -3,7 +3,6 @@ package eu.kanade.tachiyomi.extension.manga.util
import android.app.Activity import android.app.Activity
import android.content.Intent import android.content.Intent
import android.os.Bundle import android.os.Bundle
import ani.dantotsu.others.LangSet
import ani.dantotsu.themes.ThemeManager import ani.dantotsu.themes.ThemeManager
import eu.kanade.tachiyomi.extension.InstallStep import eu.kanade.tachiyomi.extension.InstallStep
import eu.kanade.tachiyomi.extension.manga.MangaExtensionManager import eu.kanade.tachiyomi.extension.manga.MangaExtensionManager
@ -26,7 +25,7 @@ class MangaExtensionInstallActivity : Activity() {
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
LangSet.setLocale(this)
ThemeManager(this).applyTheme() ThemeManager(this).applyTheme()
val installIntent = Intent(Intent.ACTION_INSTALL_PACKAGE) val installIntent = Intent(Intent.ACTION_INSTALL_PACKAGE)