"Include list" switch changed (#153)

* "Include list" switch change

* remember the toggle state of "Include list"
This commit is contained in:
aayush262 2024-01-23 00:10:29 +05:30 committed by GitHub
parent 627bed2407
commit 563e4f2cbe
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 28 additions and 7 deletions

View file

@ -2,6 +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.os.Build import android.os.Build
import android.os.Bundle import android.os.Bundle
@ -267,7 +268,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]) model.loadPopular("ANIME", sort = Anilist.sortBy[1], onList = requireContext().getSharedPreferences("Dantotsu", Context.MODE_PRIVATE)
.getBoolean("popular_list", false))
} }
live.postValue(false) live.postValue(false)
_binding?.animeRefresh?.isRefreshing = false _binding?.animeRefresh?.isRefreshing = false

View file

@ -132,8 +132,15 @@ 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 = 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()
?.putBoolean("popular_list", isChecked)?.apply()
} }
if (ready.value == false) if (ready.value == false)
ready.postValue(true) ready.postValue(true)

View file

@ -2,6 +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.os.Build import android.os.Build
import android.os.Bundle import android.os.Bundle
import android.view.LayoutInflater import android.view.LayoutInflater
@ -241,7 +242,8 @@ class MangaFragment : Fragment() {
model.loaded = true model.loaded = true
model.loadTrending() model.loadTrending()
model.loadTrendingNovel() model.loadTrendingNovel()
model.loadPopular("MANGA", sort = Anilist.sortBy[1]) model.loadPopular("MANGA", sort = Anilist.sortBy[1], onList = requireContext().getSharedPreferences("Dantotsu", Context.MODE_PRIVATE)
.getBoolean("popular_list", false) )
} }
live.postValue(false) live.postValue(false)
_binding?.mangaRefresh?.isRefreshing = false _binding?.mangaRefresh?.isRefreshing = false

View file

@ -125,10 +125,16 @@ 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 = 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()
?.putBoolean("popular_list", isChecked)?.apply()
}
if (ready.value == false) if (ready.value == false)
ready.postValue(true) ready.postValue(true)
} }

View file

@ -308,11 +308,13 @@
android:text="@string/popular_anime" android:text="@string/popular_anime"
android:textSize="16sp" /> android:textSize="16sp" />
<androidx.appcompat.widget.SwitchCompat <com.google.android.material.materialswitch.MaterialSwitch
android:id="@+id/animeIncludeList" android:id="@+id/animeIncludeList"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:checked="true" android:checked="true"
android:textSize="12sp"
android:fontFamily="@font/poppins_bold"
android:text="@string/include_media_in_list" /> android:text="@string/include_media_in_list" />
</LinearLayout> </LinearLayout>

View file

@ -264,12 +264,14 @@
android:text="@string/popular_manga" android:text="@string/popular_manga"
android:textSize="16sp" /> android:textSize="16sp" />
<androidx.appcompat.widget.SwitchCompat <com.google.android.material.materialswitch.MaterialSwitch
android:id="@+id/mangaIncludeList" android:id="@+id/mangaIncludeList"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:text="@string/include_media_in_list" android:checked="true"
android:checked="true"/> android:textSize="12sp"
android:fontFamily="@font/poppins_bold"
android:text="@string/include_media_in_list" />
</LinearLayout> </LinearLayout>