Incognito and download switch (#121)
* Offline Mode and incognito Switch * fix * Fix 1 * Update MainActivity.kt * Update MainActivity.kt --------- Co-authored-by: rebel onion <87634197+rebelonion@users.noreply.github.com>
This commit is contained in:
parent
46b84ffc76
commit
84e300482a
14 changed files with 192 additions and 180 deletions
|
@ -234,7 +234,6 @@
|
||||||
<category android:name="android.intent.category.LEANBACK_LAUNCHER" />
|
<category android:name="android.intent.category.LEANBACK_LAUNCHER" />
|
||||||
</intent-filter>
|
</intent-filter>
|
||||||
</activity>
|
</activity>
|
||||||
<activity android:name=".download.DownloadContainerActivity" />
|
|
||||||
<activity
|
<activity
|
||||||
android:name="eu.kanade.tachiyomi.extension.manga.util.MangaExtensionInstallActivity"
|
android:name="eu.kanade.tachiyomi.extension.manga.util.MangaExtensionInstallActivity"
|
||||||
android:exported="false"
|
android:exported="false"
|
||||||
|
|
|
@ -11,14 +11,12 @@ import android.os.Bundle
|
||||||
import android.os.Handler
|
import android.os.Handler
|
||||||
import android.os.Looper
|
import android.os.Looper
|
||||||
import android.provider.Settings
|
import android.provider.Settings
|
||||||
import android.util.Log
|
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
import android.view.animation.AnticipateInterpolator
|
import android.view.animation.AnticipateInterpolator
|
||||||
import android.widget.TextView
|
import android.widget.TextView
|
||||||
import androidx.activity.addCallback
|
import androidx.activity.addCallback
|
||||||
import androidx.activity.viewModels
|
import androidx.activity.viewModels
|
||||||
import androidx.annotation.OptIn
|
|
||||||
import androidx.appcompat.app.AppCompatActivity
|
import androidx.appcompat.app.AppCompatActivity
|
||||||
import androidx.core.animation.doOnEnd
|
import androidx.core.animation.doOnEnd
|
||||||
import androidx.core.content.ContextCompat
|
import androidx.core.content.ContextCompat
|
||||||
|
@ -28,14 +26,12 @@ import androidx.fragment.app.Fragment
|
||||||
import androidx.fragment.app.FragmentManager
|
import androidx.fragment.app.FragmentManager
|
||||||
import androidx.lifecycle.Lifecycle
|
import androidx.lifecycle.Lifecycle
|
||||||
import androidx.lifecycle.lifecycleScope
|
import androidx.lifecycle.lifecycleScope
|
||||||
import androidx.media3.common.util.UnstableApi
|
|
||||||
import androidx.media3.exoplayer.offline.Download
|
|
||||||
import androidx.viewpager2.adapter.FragmentStateAdapter
|
import androidx.viewpager2.adapter.FragmentStateAdapter
|
||||||
|
import ani.dantotsu.App.Companion.context
|
||||||
import ani.dantotsu.connections.anilist.Anilist
|
import ani.dantotsu.connections.anilist.Anilist
|
||||||
import ani.dantotsu.connections.anilist.AnilistHomeViewModel
|
import ani.dantotsu.connections.anilist.AnilistHomeViewModel
|
||||||
import ani.dantotsu.databinding.ActivityMainBinding
|
import ani.dantotsu.databinding.ActivityMainBinding
|
||||||
import ani.dantotsu.databinding.SplashScreenBinding
|
import ani.dantotsu.databinding.SplashScreenBinding
|
||||||
import ani.dantotsu.download.video.Helper
|
|
||||||
import ani.dantotsu.home.AnimeFragment
|
import ani.dantotsu.home.AnimeFragment
|
||||||
import ani.dantotsu.home.HomeFragment
|
import ani.dantotsu.home.HomeFragment
|
||||||
import ani.dantotsu.home.LoginFragment
|
import ani.dantotsu.home.LoginFragment
|
||||||
|
@ -50,7 +46,6 @@ import ani.dantotsu.themes.ThemeManager
|
||||||
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
|
||||||
import kotlinx.coroutines.GlobalScope
|
|
||||||
import kotlinx.coroutines.delay
|
import kotlinx.coroutines.delay
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
import kotlinx.coroutines.withContext
|
import kotlinx.coroutines.withContext
|
||||||
|
@ -66,7 +61,7 @@ class MainActivity : AppCompatActivity() {
|
||||||
private var uiSettings = UserInterfaceSettings()
|
private var uiSettings = UserInterfaceSettings()
|
||||||
|
|
||||||
|
|
||||||
@OptIn(UnstableApi::class) override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
ThemeManager(this).applyTheme()
|
ThemeManager(this).applyTheme()
|
||||||
LangSet.setLocale(this)
|
LangSet.setLocale(this)
|
||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
|
@ -79,10 +74,16 @@ class MainActivity : AppCompatActivity() {
|
||||||
|
|
||||||
val backgroundDrawable = _bottomBar.background as GradientDrawable
|
val backgroundDrawable = _bottomBar.background as GradientDrawable
|
||||||
val currentColor = backgroundDrawable.color?.defaultColor ?: 0
|
val currentColor = backgroundDrawable.color?.defaultColor ?: 0
|
||||||
val semiTransparentColor = (currentColor and 0x00FFFFFF) or 0xF0000000.toInt()
|
val semiTransparentColor = (currentColor and 0x00FFFFFF) or 0xE8000000.toInt()
|
||||||
backgroundDrawable.setColor(semiTransparentColor)
|
backgroundDrawable.setColor(semiTransparentColor)
|
||||||
_bottomBar.background = backgroundDrawable
|
_bottomBar.background = backgroundDrawable
|
||||||
}
|
}
|
||||||
|
val colorOverflow = this.getSharedPreferences("Dantotsu", Context.MODE_PRIVATE)
|
||||||
|
.getBoolean("colorOverflow", false)
|
||||||
|
if (!colorOverflow) {
|
||||||
|
_bottomBar.background = ContextCompat.getDrawable(this, R.drawable.bottom_nav_gray)
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
var doubleBackToExitPressedOnce = false
|
var doubleBackToExitPressedOnce = false
|
||||||
|
@ -147,13 +148,19 @@ class MainActivity : AppCompatActivity() {
|
||||||
bottomMargin = navBarHeight
|
bottomMargin = navBarHeight
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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))
|
||||||
} else {
|
getSharedPreferences("Dantotsu", Context.MODE_PRIVATE)
|
||||||
|
.edit()
|
||||||
|
.putBoolean("offlineMode", true)
|
||||||
|
.apply()} else {
|
||||||
|
getSharedPreferences("Dantotsu", Context.MODE_PRIVATE)
|
||||||
|
.edit()
|
||||||
|
.putBoolean("offlineMode", false)
|
||||||
|
.apply()
|
||||||
val model: AnilistHomeViewModel by viewModels()
|
val model: AnilistHomeViewModel by viewModels()
|
||||||
model.genres.observe(this) {
|
model.genres.observe(this) { it ->
|
||||||
if (it != null) {
|
if (it != null) {
|
||||||
if (it) {
|
if (it) {
|
||||||
val navbar = binding.includedNavbar.navbar
|
val navbar = binding.includedNavbar.navbar
|
||||||
|
@ -236,13 +243,11 @@ class MainActivity : AppCompatActivity() {
|
||||||
.setData(Uri.parse("package:$packageName"))
|
.setData(Uri.parse("package:$packageName"))
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
dismiss()
|
|
||||||
}
|
}
|
||||||
}.show(supportFragmentManager, "dialog")
|
}.show(supportFragmentManager, "dialog")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
GlobalScope.launch(Dispatchers.IO) {
|
GlobalScope.launch(Dispatchers.IO) {
|
||||||
val index = Helper.downloadManager(this@MainActivity).downloadIndex
|
val index = Helper.downloadManager(this@MainActivity).downloadIndex
|
||||||
val downloadCursor = index.getDownloads()
|
val downloadCursor = index.getDownloads()
|
||||||
|
@ -262,6 +267,8 @@ class MainActivity : AppCompatActivity() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,25 +0,0 @@
|
||||||
package ani.dantotsu.download
|
|
||||||
|
|
||||||
import android.os.Bundle
|
|
||||||
import androidx.appcompat.app.AppCompatActivity
|
|
||||||
import androidx.fragment.app.Fragment
|
|
||||||
import ani.dantotsu.R
|
|
||||||
import ani.dantotsu.others.LangSet
|
|
||||||
import ani.dantotsu.themes.ThemeManager
|
|
||||||
|
|
||||||
class DownloadContainerActivity : AppCompatActivity() {
|
|
||||||
|
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
|
||||||
super.onCreate(savedInstanceState)
|
|
||||||
LangSet.setLocale(this)
|
|
||||||
ThemeManager(this).applyTheme()
|
|
||||||
setContentView(R.layout.activity_container)
|
|
||||||
|
|
||||||
val fragmentClassName = intent.getStringExtra("FRAGMENT_CLASS_NAME")
|
|
||||||
val fragment = Class.forName(fragmentClassName).newInstance() as Fragment
|
|
||||||
|
|
||||||
supportFragmentManager.beginTransaction()
|
|
||||||
.replace(R.id.fragment_container, fragment)
|
|
||||||
.commit()
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,7 +1,6 @@
|
||||||
package ani.dantotsu.download.manga
|
package ani.dantotsu.download.manga
|
||||||
|
|
||||||
import android.animation.ObjectAnimator
|
import android.animation.ObjectAnimator
|
||||||
import android.annotation.SuppressLint
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import android.net.Uri
|
import android.net.Uri
|
||||||
|
@ -21,7 +20,6 @@ import android.widget.AbsListView
|
||||||
import android.widget.AutoCompleteTextView
|
import android.widget.AutoCompleteTextView
|
||||||
import android.widget.GridView
|
import android.widget.GridView
|
||||||
import android.widget.ImageView
|
import android.widget.ImageView
|
||||||
import android.widget.TextView
|
|
||||||
import androidx.appcompat.app.AppCompatActivity
|
import androidx.appcompat.app.AppCompatActivity
|
||||||
import androidx.cardview.widget.CardView
|
import androidx.cardview.widget.CardView
|
||||||
import androidx.fragment.app.Fragment
|
import androidx.fragment.app.Fragment
|
||||||
|
@ -59,7 +57,6 @@ class OfflineMangaFragment : Fragment(), OfflineMangaSearchListener {
|
||||||
private lateinit var gridView: GridView
|
private lateinit var gridView: GridView
|
||||||
private lateinit var adapter: OfflineMangaAdapter
|
private lateinit var adapter: OfflineMangaAdapter
|
||||||
|
|
||||||
@SuppressLint("SetTextI18n")
|
|
||||||
override fun onCreateView(
|
override fun onCreateView(
|
||||||
inflater: LayoutInflater,
|
inflater: LayoutInflater,
|
||||||
container: ViewGroup?,
|
container: ViewGroup?,
|
||||||
|
@ -79,14 +76,8 @@ class OfflineMangaFragment : Fragment(), OfflineMangaSearchListener {
|
||||||
|
|
||||||
val animeUserAvatar = view.findViewById<ShapeableImageView>(R.id.offlineMangaUserAvatar)
|
val animeUserAvatar = view.findViewById<ShapeableImageView>(R.id.offlineMangaUserAvatar)
|
||||||
animeUserAvatar.setSafeOnClickListener {
|
animeUserAvatar.setSafeOnClickListener {
|
||||||
animeUserAvatar.setSafeOnClickListener {
|
val dialogFragment = SettingsDialogFragment.newInstance2(SettingsDialogFragment.Companion.PageType2.OfflineMANGA)
|
||||||
val dialogFragment = SettingsDialogFragment.newInstance(SettingsDialogFragment.Companion.PageType.HOME)
|
dialogFragment.show((it.context as AppCompatActivity).supportFragmentManager, "dialog")
|
||||||
dialogFragment.show(
|
|
||||||
(it.context as AppCompatActivity).supportFragmentManager,
|
|
||||||
"dialog"
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
val colorOverflow = currContext()?.getSharedPreferences("Dantotsu", Context.MODE_PRIVATE)
|
val colorOverflow = currContext()?.getSharedPreferences("Dantotsu", Context.MODE_PRIVATE)
|
||||||
|
@ -180,6 +171,7 @@ class OfflineMangaFragment : Fragment(), OfflineMangaSearchListener {
|
||||||
snackString("no media found")
|
snackString("no media found")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
val total = view.findViewById<TextView>(R.id.total)
|
val total = view.findViewById<TextView>(R.id.total)
|
||||||
total.text = if (gridView.count > 0) "Manga and Novels (${gridView.count})" else "Empty List"
|
total.text = if (gridView.count > 0) "Manga and Novels (${gridView.count})" else "Empty List"
|
||||||
gridView.setOnItemLongClickListener { parent, view, position, id ->
|
gridView.setOnItemLongClickListener { parent, view, position, id ->
|
||||||
|
@ -198,7 +190,6 @@ class OfflineMangaFragment : Fragment(), OfflineMangaSearchListener {
|
||||||
downloadManager.removeMedia(item.title, type)
|
downloadManager.removeMedia(item.title, type)
|
||||||
getDownloads()
|
getDownloads()
|
||||||
adapter.setItems(downloads)
|
adapter.setItems(downloads)
|
||||||
|
|
||||||
}
|
}
|
||||||
builder.setNegativeButton("No") { _, _ ->
|
builder.setNegativeButton("No") { _, _ ->
|
||||||
// Do nothing
|
// Do nothing
|
||||||
|
@ -207,6 +198,7 @@ class OfflineMangaFragment : Fragment(), OfflineMangaSearchListener {
|
||||||
dialog.window?.setDimAmount(0.8f)
|
dialog.window?.setDimAmount(0.8f)
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
|
|
||||||
return view
|
return view
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -93,6 +93,7 @@ class AnimePageAdapter : RecyclerView.Adapter<AnimePageAdapter.AnimePageViewHold
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
setIncognito()
|
||||||
binding.animeSearchBar.setEndIconOnClickListener {
|
binding.animeSearchBar.setEndIconOnClickListener {
|
||||||
binding.animeSearchBarText.performClick()
|
binding.animeSearchBarText.performClick()
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,7 +2,6 @@ package ani.dantotsu.home
|
||||||
|
|
||||||
import android.animation.ObjectAnimator
|
import android.animation.ObjectAnimator
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.content.ContextWrapper
|
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import android.graphics.drawable.Animatable
|
import android.graphics.drawable.Animatable
|
||||||
import android.os.Build
|
import android.os.Build
|
||||||
|
@ -10,7 +9,6 @@ import android.os.Bundle
|
||||||
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.WindowManager
|
|
||||||
import android.view.animation.LayoutAnimationController
|
import android.view.animation.LayoutAnimationController
|
||||||
import androidx.core.content.ContextCompat
|
import androidx.core.content.ContextCompat
|
||||||
import androidx.core.view.updateLayoutParams
|
import androidx.core.view.updateLayoutParams
|
||||||
|
@ -22,7 +20,6 @@ import androidx.lifecycle.MutableLiveData
|
||||||
import androidx.lifecycle.lifecycleScope
|
import androidx.lifecycle.lifecycleScope
|
||||||
import androidx.recyclerview.widget.LinearLayoutManager
|
import androidx.recyclerview.widget.LinearLayoutManager
|
||||||
import androidx.recyclerview.widget.RecyclerView
|
import androidx.recyclerview.widget.RecyclerView
|
||||||
import ani.dantotsu.App
|
|
||||||
import ani.dantotsu.R
|
import ani.dantotsu.R
|
||||||
import ani.dantotsu.Refresh
|
import ani.dantotsu.Refresh
|
||||||
import ani.dantotsu.bottomBar
|
import ani.dantotsu.bottomBar
|
||||||
|
@ -75,7 +72,7 @@ class HomeFragment : Fragment() {
|
||||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||||
val scope = lifecycleScope
|
val scope = lifecycleScope
|
||||||
var uiSettings = loadData<UserInterfaceSettings>("ui_settings") ?: UserInterfaceSettings()
|
var uiSettings = loadData<UserInterfaceSettings>("ui_settings") ?: UserInterfaceSettings()
|
||||||
|
setIncognito()
|
||||||
fun load() {
|
fun load() {
|
||||||
if (activity != null && _binding != null) lifecycleScope.launch(Dispatchers.Main) {
|
if (activity != null && _binding != null) lifecycleScope.launch(Dispatchers.Main) {
|
||||||
binding.homeUserName.text = Anilist.username
|
binding.homeUserName.text = Anilist.username
|
||||||
|
@ -361,9 +358,7 @@ class HomeFragment : Fragment() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
private fun setIncognito() {
|
||||||
override fun onResume() {
|
|
||||||
if (!model.loaded) Refresh.activity[1]!!.postValue(true)
|
|
||||||
val incognito = currContext()?.getSharedPreferences("Dantotsu", Context.MODE_PRIVATE)
|
val incognito = currContext()?.getSharedPreferences("Dantotsu", Context.MODE_PRIVATE)
|
||||||
?.getBoolean("incognito", false) ?: false
|
?.getBoolean("incognito", false) ?: false
|
||||||
if(incognito) {
|
if(incognito) {
|
||||||
|
@ -381,6 +376,10 @@ class HomeFragment : Fragment() {
|
||||||
} else {
|
} else {
|
||||||
binding.incognitoTextView.visibility = View.GONE
|
binding.incognitoTextView.visibility = View.GONE
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
override fun onResume() {
|
||||||
|
if (!model.loaded) Refresh.activity[1]!!.postValue(true)
|
||||||
|
setIncognito()
|
||||||
super.onResume()
|
super.onResume()
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -98,6 +98,7 @@ class MangaPageAdapter : RecyclerView.Adapter<MangaPageAdapter.MangaPageViewHold
|
||||||
dialogFragment.show((it.context as AppCompatActivity).supportFragmentManager, "dialog")
|
dialogFragment.show((it.context as AppCompatActivity).supportFragmentManager, "dialog")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
setIncognito()
|
||||||
binding.mangaSearchBar.setEndIconOnClickListener {
|
binding.mangaSearchBar.setEndIconOnClickListener {
|
||||||
binding.mangaSearchBarText.performClick()
|
binding.mangaSearchBarText.performClick()
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
package ani.dantotsu.offline
|
package ani.dantotsu.offline
|
||||||
|
|
||||||
|
import android.content.Context
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.view.LayoutInflater
|
import android.view.LayoutInflater
|
||||||
import android.view.View
|
import android.view.View
|
||||||
|
@ -8,6 +9,8 @@ import androidx.core.view.updateLayoutParams
|
||||||
import androidx.fragment.app.Fragment
|
import androidx.fragment.app.Fragment
|
||||||
import ani.dantotsu.databinding.FragmentOfflineBinding
|
import ani.dantotsu.databinding.FragmentOfflineBinding
|
||||||
import ani.dantotsu.isOnline
|
import ani.dantotsu.isOnline
|
||||||
|
import ani.dantotsu.App
|
||||||
|
import ani.dantotsu.R
|
||||||
import ani.dantotsu.navBarHeight
|
import ani.dantotsu.navBarHeight
|
||||||
import ani.dantotsu.startMainActivity
|
import ani.dantotsu.startMainActivity
|
||||||
import ani.dantotsu.statusBarHeight
|
import ani.dantotsu.statusBarHeight
|
||||||
|
@ -23,8 +26,10 @@ class OfflineFragment : Fragment() {
|
||||||
topMargin = statusBarHeight
|
topMargin = statusBarHeight
|
||||||
bottomMargin = navBarHeight
|
bottomMargin = navBarHeight
|
||||||
}
|
}
|
||||||
|
val offline = App.context?.getSharedPreferences("Dantotsu", Context.MODE_PRIVATE)?.getBoolean("offlineMode", false) ?: false
|
||||||
|
binding.noInternet.text = if (!isOnline(requireContext())) getString(R.string.no_internet) else "OFFLINE MODE"
|
||||||
binding.refreshButton.setOnClickListener {
|
binding.refreshButton.setOnClickListener {
|
||||||
if (isOnline(requireContext())) {
|
if (!isOnline(requireContext()) && offline) {
|
||||||
startMainActivity(requireActivity())
|
startMainActivity(requireActivity())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -463,16 +463,6 @@ class SettingsActivity : AppCompatActivity(), SimpleDialog.OnDialogResultListen
|
||||||
uiTheme(true, it)
|
uiTheme(true, it)
|
||||||
}
|
}
|
||||||
|
|
||||||
binding.settingsIncognito.isChecked =
|
|
||||||
getSharedPreferences("Dantotsu", Context.MODE_PRIVATE).getBoolean(
|
|
||||||
"incognito",
|
|
||||||
false
|
|
||||||
)
|
|
||||||
binding.settingsIncognito.setOnCheckedChangeListener { _, isChecked ->
|
|
||||||
getSharedPreferences("Dantotsu", Context.MODE_PRIVATE).edit()
|
|
||||||
.putBoolean("incognito", isChecked).apply()
|
|
||||||
}
|
|
||||||
|
|
||||||
var previousStart: View = when (uiSettings.defaultStartUpTab) {
|
var previousStart: View = when (uiSettings.defaultStartUpTab) {
|
||||||
0 -> binding.uiSettingsAnime
|
0 -> binding.uiSettingsAnime
|
||||||
1 -> binding.uiSettingsHome
|
1 -> binding.uiSettingsHome
|
||||||
|
|
|
@ -1,40 +1,42 @@
|
||||||
package ani.dantotsu.settings
|
package ani.dantotsu.settings
|
||||||
|
|
||||||
import android.app.DownloadManager
|
|
||||||
import android.content.ActivityNotFoundException
|
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
|
import android.content.Context
|
||||||
import android.graphics.Color
|
import android.graphics.Color
|
||||||
import android.net.Uri
|
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.util.TypedValue
|
import android.util.TypedValue
|
||||||
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 androidx.core.content.ContextCompat
|
|
||||||
import ani.dantotsu.BottomSheetDialogFragment
|
import ani.dantotsu.BottomSheetDialogFragment
|
||||||
import ani.dantotsu.R
|
import ani.dantotsu.R
|
||||||
|
import ani.dantotsu.MainActivity
|
||||||
import ani.dantotsu.connections.anilist.Anilist
|
import ani.dantotsu.connections.anilist.Anilist
|
||||||
import ani.dantotsu.databinding.BottomSheetSettingsBinding
|
import ani.dantotsu.databinding.BottomSheetSettingsBinding
|
||||||
import ani.dantotsu.download.DownloadContainerActivity
|
|
||||||
import ani.dantotsu.download.manga.OfflineMangaFragment
|
import ani.dantotsu.download.manga.OfflineMangaFragment
|
||||||
import ani.dantotsu.loadData
|
|
||||||
import ani.dantotsu.loadImage
|
import ani.dantotsu.loadImage
|
||||||
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.startMainActivity
|
import ani.dantotsu.startMainActivity
|
||||||
import ani.dantotsu.toast
|
import ani.dantotsu.currContext
|
||||||
|
import ani.dantotsu.home.AnimeFragment
|
||||||
|
import ani.dantotsu.home.HomeFragment
|
||||||
|
import ani.dantotsu.home.LoginFragment
|
||||||
|
import ani.dantotsu.home.MangaFragment
|
||||||
|
import ani.dantotsu.home.NoInternet
|
||||||
|
import ani.dantotsu.offline.OfflineFragment
|
||||||
|
|
||||||
class SettingsDialogFragment() : BottomSheetDialogFragment() {
|
class SettingsDialogFragment() : BottomSheetDialogFragment() {
|
||||||
private var _binding: BottomSheetSettingsBinding? = null
|
private var _binding: BottomSheetSettingsBinding? = null
|
||||||
private val binding get() = _binding!!
|
private val binding get() = _binding!!
|
||||||
|
|
||||||
private lateinit var pageType: PageType
|
private lateinit var pageType: PageType
|
||||||
|
private lateinit var pageType2: PageType2
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
pageType = arguments?.getSerializable("pageType") as? PageType ?: PageType.HOME
|
pageType = arguments?.getSerializable("pageType") as? PageType ?: PageType.HOME
|
||||||
|
pageType2 = arguments?.getSerializable("pageType2") as? PageType2 ?: PageType2.OfflineMANGA // changed when offline home page comes
|
||||||
}
|
}
|
||||||
override fun onCreateView(
|
override fun onCreateView(
|
||||||
inflater: LayoutInflater,
|
inflater: LayoutInflater,
|
||||||
|
@ -72,6 +74,16 @@ class SettingsDialogFragment() : BottomSheetDialogFragment() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
binding.settingsIncognito.isChecked =
|
||||||
|
context?.getSharedPreferences("Dantotsu", Context.MODE_PRIVATE)?.getBoolean(
|
||||||
|
"incognito",
|
||||||
|
false
|
||||||
|
) ?: false
|
||||||
|
|
||||||
|
binding.settingsIncognito.setOnCheckedChangeListener { _, isChecked ->
|
||||||
|
context?.getSharedPreferences("Dantotsu", Context.MODE_PRIVATE)?.edit()
|
||||||
|
?.putBoolean("incognito", isChecked)?.apply()
|
||||||
|
}
|
||||||
binding.settingsExtensionSettings.setSafeOnClickListener {
|
binding.settingsExtensionSettings.setSafeOnClickListener {
|
||||||
startActivity(Intent(activity, ExtensionsActivity::class.java))
|
startActivity(Intent(activity, ExtensionsActivity::class.java))
|
||||||
dismiss()
|
dismiss()
|
||||||
|
@ -88,38 +100,51 @@ class SettingsDialogFragment() : BottomSheetDialogFragment() {
|
||||||
startActivity(Intent(activity, ImageSearchActivity::class.java))
|
startActivity(Intent(activity, ImageSearchActivity::class.java))
|
||||||
dismiss()
|
dismiss()
|
||||||
}
|
}
|
||||||
binding.settingsDownloads.setSafeOnClickListener {
|
|
||||||
|
binding.settingsDownloads.isChecked =
|
||||||
|
context?.getSharedPreferences("Dantotsu", Context.MODE_PRIVATE)?.getBoolean("offlineMode", false) ?: false
|
||||||
|
binding.settingsDownloads.setOnCheckedChangeListener { _, isChecked ->
|
||||||
|
|
||||||
|
if (!isChecked) {
|
||||||
|
when (pageType2) {
|
||||||
|
PageType2.OfflineMANGA -> {
|
||||||
|
val intent = Intent(activity, MainActivity::class.java)
|
||||||
|
intent.putExtra("FRAGMENT_CLASS_NAME", MangaFragment::class.java.name)
|
||||||
|
startActivity(intent)
|
||||||
|
}
|
||||||
|
PageType2.OfflineHOME -> { //no offline home for now
|
||||||
|
val intent = Intent(activity, MainActivity::class.java)
|
||||||
|
intent.putExtra("FRAGMENT_CLASS_NAME", if (Anilist.token != null) HomeFragment::class.java.name else LoginFragment::class.java.name)
|
||||||
|
startActivity(intent)
|
||||||
|
}
|
||||||
|
PageType2.OfflineANIME -> { //no offline anime for now
|
||||||
|
val intent = Intent(activity, MainActivity::class.java)
|
||||||
|
intent.putExtra("FRAGMENT_CLASS_NAME", AnimeFragment::class.java.name)
|
||||||
|
startActivity(intent)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
when (pageType) {
|
when (pageType) {
|
||||||
PageType.MANGA -> {
|
PageType.MANGA -> {
|
||||||
val intent = Intent(activity, DownloadContainerActivity::class.java)
|
val intent = Intent(activity, NoInternet::class.java)
|
||||||
intent.putExtra("FRAGMENT_CLASS_NAME", OfflineMangaFragment::class.java.name)
|
intent.putExtra("FRAGMENT_CLASS_NAME", OfflineMangaFragment::class.java.name)
|
||||||
startActivity(intent)
|
startActivity(intent)
|
||||||
}
|
}
|
||||||
|
|
||||||
PageType.ANIME -> {
|
PageType.ANIME -> {
|
||||||
try {
|
val intent = Intent(activity, NoInternet::class.java)
|
||||||
val arrayOfFiles =
|
intent.putExtra("FRAGMENT_CLASS_NAME", OfflineFragment::class.java.name)
|
||||||
ContextCompat.getExternalFilesDirs(requireContext(), null)
|
startActivity(intent)
|
||||||
startActivity(
|
|
||||||
if (loadData<Boolean>("sd_dl") == true && arrayOfFiles.size > 1 && arrayOfFiles[0] != null && arrayOfFiles[1] != null) {
|
|
||||||
val parentDirectory = arrayOfFiles[1].toString()
|
|
||||||
val intent = Intent(Intent.ACTION_VIEW)
|
|
||||||
intent.setDataAndType(Uri.parse(parentDirectory), "resource/folder")
|
|
||||||
} else Intent(DownloadManager.ACTION_VIEW_DOWNLOADS)
|
|
||||||
)
|
|
||||||
} catch (e: ActivityNotFoundException) {
|
|
||||||
toast(getString(R.string.file_manager_not_found))
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
PageType.HOME -> {
|
PageType.HOME -> {
|
||||||
val intent = Intent(activity, DownloadContainerActivity::class.java)
|
val intent = Intent(activity, NoInternet::class.java)
|
||||||
intent.putExtra("FRAGMENT_CLASS_NAME", OfflineMangaFragment::class.java.name)
|
intent.putExtra("FRAGMENT_CLASS_NAME", OfflineFragment::class.java.name)
|
||||||
startActivity(intent)
|
startActivity(intent)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
dismiss()
|
dismiss()
|
||||||
|
context?.getSharedPreferences("Dantotsu", Context.MODE_PRIVATE)?.edit()
|
||||||
|
?.putBoolean("offlineMode", isChecked)?.apply()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -132,7 +157,9 @@ class SettingsDialogFragment() : BottomSheetDialogFragment() {
|
||||||
enum class PageType {
|
enum class PageType {
|
||||||
MANGA, ANIME, HOME
|
MANGA, ANIME, HOME
|
||||||
}
|
}
|
||||||
|
enum class PageType2 {
|
||||||
|
OfflineMANGA, OfflineANIME, OfflineHOME
|
||||||
|
}
|
||||||
fun newInstance(pageType: PageType): SettingsDialogFragment {
|
fun newInstance(pageType: PageType): SettingsDialogFragment {
|
||||||
val fragment = SettingsDialogFragment()
|
val fragment = SettingsDialogFragment()
|
||||||
val args = Bundle()
|
val args = Bundle()
|
||||||
|
@ -140,5 +167,12 @@ class SettingsDialogFragment() : BottomSheetDialogFragment() {
|
||||||
fragment.arguments = args
|
fragment.arguments = args
|
||||||
return fragment
|
return fragment
|
||||||
}
|
}
|
||||||
|
fun newInstance2(pageType: PageType2): SettingsDialogFragment {
|
||||||
|
val fragment = SettingsDialogFragment()
|
||||||
|
val args = Bundle()
|
||||||
|
args.putSerializable("pageType", pageType)
|
||||||
|
fragment.arguments = args
|
||||||
|
return fragment
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -335,25 +335,6 @@
|
||||||
app:drawableEndCompat="@drawable/ic_round_arrow_drop_down_24"
|
app:drawableEndCompat="@drawable/ic_round_arrow_drop_down_24"
|
||||||
tools:ignore="TextContrastCheck" />
|
tools:ignore="TextContrastCheck" />
|
||||||
|
|
||||||
<com.google.android.material.materialswitch.MaterialSwitch
|
|
||||||
android:id="@+id/settingsIncognito"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:layout_marginStart="4dp"
|
|
||||||
android:checked="false"
|
|
||||||
android:drawableStart="@drawable/ic_incognito_24"
|
|
||||||
android:drawablePadding="16dp"
|
|
||||||
android:elegantTextHeight="true"
|
|
||||||
android:fontFamily="@font/poppins_bold"
|
|
||||||
android:minHeight="64dp"
|
|
||||||
android:text="@string/incognito_mode"
|
|
||||||
android:textAlignment="viewStart"
|
|
||||||
android:textColor="?attr/colorOnBackground"
|
|
||||||
app:cornerRadius="0dp"
|
|
||||||
app:drawableTint="?attr/colorPrimary"
|
|
||||||
app:showText="false"
|
|
||||||
app:thumbTint="@color/button_switch_track" />
|
|
||||||
|
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
android:id="@+id/settingsAnilistLoginContainer"
|
android:id="@+id/settingsAnilistLoginContainer"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
|
|
|
@ -72,6 +72,51 @@
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
|
<com.google.android.material.materialswitch.MaterialSwitch
|
||||||
|
android:id="@+id/settingsIncognito"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="64dp"
|
||||||
|
android:checked="false"
|
||||||
|
android:drawableStart="@drawable/ic_incognito_24"
|
||||||
|
android:drawablePadding="16dp"
|
||||||
|
android:insetTop="0dp"
|
||||||
|
android:insetBottom="0dp"
|
||||||
|
android:paddingStart="32dp"
|
||||||
|
android:paddingEnd="32dp"
|
||||||
|
android:elegantTextHeight="true"
|
||||||
|
android:fontFamily="@font/poppins_bold"
|
||||||
|
android:text="@string/incognito_mode"
|
||||||
|
android:textAlignment="viewStart"
|
||||||
|
android:textColor="?attr/colorOnBackground"
|
||||||
|
app:cornerRadius="0dp"
|
||||||
|
android:layout_marginBottom="8dp"
|
||||||
|
app:drawableTint="?attr/colorPrimary"
|
||||||
|
app:showText="false"
|
||||||
|
app:thumbTint="@color/button_switch_track" />
|
||||||
|
|
||||||
|
<com.google.android.material.materialswitch.MaterialSwitch
|
||||||
|
android:id="@+id/settingsDownloads"
|
||||||
|
style="@style/Widget.Material3.Button.TextButton"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="64dp"
|
||||||
|
android:fontFamily="@font/poppins_bold"
|
||||||
|
android:insetTop="0dp"
|
||||||
|
android:insetBottom="0dp"
|
||||||
|
android:paddingStart="32dp"
|
||||||
|
android:paddingEnd="32dp"
|
||||||
|
android:text="@string/offline_mode"
|
||||||
|
android:textAlignment="viewStart"
|
||||||
|
android:textAllCaps="false"
|
||||||
|
android:textColor="?attr/colorOnBackground"
|
||||||
|
app:cornerRadius="0dp"
|
||||||
|
android:drawableStart="@drawable/ic_round_download_24"
|
||||||
|
android:drawablePadding="16dp"
|
||||||
|
android:layout_marginBottom="8dp"
|
||||||
|
app:drawableTint="?attr/colorPrimary"
|
||||||
|
app:showText="false"
|
||||||
|
app:thumbTint="@color/button_switch_track"
|
||||||
|
android:checked="false"/>
|
||||||
|
|
||||||
<Button
|
<Button
|
||||||
android:id="@+id/image_search"
|
android:id="@+id/image_search"
|
||||||
style="@style/Widget.Material3.Button.TextButton"
|
style="@style/Widget.Material3.Button.TextButton"
|
||||||
|
@ -91,25 +136,6 @@
|
||||||
app:iconPadding="16dp"
|
app:iconPadding="16dp"
|
||||||
app:iconSize="24dp" />
|
app:iconSize="24dp" />
|
||||||
|
|
||||||
<Button
|
|
||||||
android:id="@+id/settingsDownloads"
|
|
||||||
style="@style/Widget.Material3.Button.TextButton"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="64dp"
|
|
||||||
android:fontFamily="@font/poppins_bold"
|
|
||||||
android:insetTop="0dp"
|
|
||||||
android:insetBottom="0dp"
|
|
||||||
android:paddingStart="32dp"
|
|
||||||
android:paddingEnd="32dp"
|
|
||||||
android:text="@string/downloads"
|
|
||||||
android:textAlignment="viewStart"
|
|
||||||
android:textAllCaps="false"
|
|
||||||
android:textColor="?attr/colorOnBackground"
|
|
||||||
app:cornerRadius="0dp"
|
|
||||||
app:icon="@drawable/ic_round_download_24"
|
|
||||||
app:iconPadding="16dp"
|
|
||||||
app:iconSize="24dp" />
|
|
||||||
|
|
||||||
<Button
|
<Button
|
||||||
android:id="@+id/settingsAnilistSettings"
|
android:id="@+id/settingsAnilistSettings"
|
||||||
style="@style/Widget.Material3.Button.TextButton"
|
style="@style/Widget.Material3.Button.TextButton"
|
||||||
|
|
|
@ -30,6 +30,7 @@
|
||||||
app:layout_constraintTop_toTopOf="parent" />
|
app:layout_constraintTop_toTopOf="parent" />
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
|
android:id="@+id/no_internet"
|
||||||
android:layout_width="200dp"
|
android:layout_width="200dp"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:text="@string/no_internet"
|
android:text="@string/no_internet"
|
||||||
|
|
|
@ -156,6 +156,7 @@
|
||||||
<string name="anilist_settings">Anilist Settings</string>
|
<string name="anilist_settings">Anilist Settings</string>
|
||||||
<string name="extension_settings">Extensions</string>
|
<string name="extension_settings">Extensions</string>
|
||||||
<string name="downloads">Downloads</string>
|
<string name="downloads">Downloads</string>
|
||||||
|
<string name="offline_mode">Offline Mode</string>
|
||||||
<string name="settings">Settings</string>
|
<string name="settings">Settings</string>
|
||||||
<string name="extensions">Extensions</string>
|
<string name="extensions">Extensions</string>
|
||||||
<string name="player_settings">Player Settings</string>
|
<string name="player_settings">Player Settings</string>
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue