downloaded anime page bug fixes (#132)

* after changing grid style items are not accessible fixed

* added total ep released no

* padding fix

* fixed scroll to top coinciding with navbar

* small change
This commit is contained in:
aayush262 2024-01-15 21:31:41 +05:30 committed by GitHub
parent 98cb11e841
commit bd6197031a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 80 additions and 82 deletions

View file

@ -12,8 +12,6 @@ import android.widget.LinearLayout
import android.widget.TextView
import androidx.cardview.widget.CardView
import ani.dantotsu.R
import ani.dantotsu.download.anime.OfflineAnimeModel
import ani.dantotsu.download.anime.OfflineAnimeSearchListener
class OfflineAnimeAdapter(
@ -54,22 +52,22 @@ class OfflineAnimeAdapter(
val itemScore = view.findViewById<TextView>(R.id.itemCompactScore)
val itemScoreBG = view.findViewById<View>(R.id.itemCompactScoreBG)
val ongoing = view.findViewById<CardView>(R.id.itemCompactOngoing)
val totalchapter = view.findViewById<TextView>(R.id.itemCompactTotal)
val totalepisodes = view.findViewById<TextView>(R.id.itemCompactTotal)
val typeimage = view.findViewById<ImageView>(R.id.itemCompactTypeImage)
val type = view.findViewById<TextView>(R.id.itemCompactRelation)
val typeView = view.findViewById<LinearLayout>(R.id.itemCompactType)
if (style == 0) {
val bannerView = view.findViewById<ImageView>(R.id.itemCompactBanner) // for large view
val chapters = view.findViewById<TextView>(R.id.itemTotal)
chapters.text = " Chapters"
val episodes = view.findViewById<TextView>(R.id.itemTotal)
episodes.text = " Episodes"
bannerView.setImageURI(item.banner)
totalchapter.text = item.totalEpisode
totalepisodes.text = item.totalEpisodeList
} else if (style == 1) {
val readchapter =
val watchedEpisodes =
view.findViewById<TextView>(R.id.itemCompactUserProgress) // for compact view
readchapter.text = item.watchedEpisode
totalchapter.text = " | " + item.totalEpisode
watchedEpisodes.text = item.watchedEpisode
totalepisodes.text = " | " + item.totalEpisode
}
// Bind item data to the views

View file

@ -19,32 +19,30 @@ import android.view.animation.LayoutAnimationController
import android.view.animation.OvershootInterpolator
import android.widget.AbsListView
import android.widget.AutoCompleteTextView
import android.widget.FrameLayout
import android.widget.GridView
import android.widget.ImageView
import android.widget.LinearLayout
import android.widget.TextView
import androidx.annotation.OptIn
import androidx.appcompat.app.AppCompatActivity
import androidx.appcompat.widget.ThemedSpinnerAdapter.Helper
import androidx.cardview.widget.CardView
import androidx.core.view.updatePadding
import androidx.core.view.updatePaddingRelative
import androidx.core.view.marginBottom
import androidx.fragment.app.Fragment
import androidx.media3.common.util.UnstableApi
import ani.dantotsu.R
import ani.dantotsu.bottomBar
import ani.dantotsu.currActivity
import ani.dantotsu.currContext
import ani.dantotsu.download.DownloadedType
import ani.dantotsu.download.DownloadsManager
import ani.dantotsu.initActivity
import ani.dantotsu.loadData
import ani.dantotsu.logger
import ani.dantotsu.media.Media
import ani.dantotsu.media.MediaDetailsActivity
import ani.dantotsu.navBarHeight
import ani.dantotsu.px
import ani.dantotsu.setSafeOnClickListener
import ani.dantotsu.settings.SettingsDialogFragment
import ani.dantotsu.settings.UserInterfaceSettings
import ani.dantotsu.snackString
import ani.dantotsu.statusBarHeight
import com.google.android.material.card.MaterialCardView
@ -71,13 +69,15 @@ class OfflineAnimeFragment : Fragment(), OfflineAnimeSearchListener {
private var downloads: List<OfflineAnimeModel> = listOf()
private lateinit var gridView: GridView
private lateinit var adapter: OfflineAnimeAdapter
private var uiSettings: UserInterfaceSettings =
loadData("ui_settings") ?: UserInterfaceSettings()
@OptIn(UnstableApi::class) override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
val view = inflater.inflate(R.layout.fragment_manga_offline, container, false)
val view = inflater.inflate(R.layout.fragment_offline_page, container, false)
val textInputLayout = view.findViewById<TextInputLayout>(R.id.offlineMangaSearchBar)
textInputLayout.hint = "Anime"
@ -90,16 +90,15 @@ class OfflineAnimeFragment : Fragment(), OfflineAnimeSearchListener {
requireContext().theme?.resolveAttribute(android.R.attr.windowBackground, typedValue, true)
val color = typedValue.data
val animeTitleContainer = view.findViewById<LinearLayout>(R.id.animeTitleContainer)
animeTitleContainer.updatePadding(top = statusBarHeight)
val animeUserAvatar = view.findViewById<ShapeableImageView>(R.id.offlineMangaUserAvatar)
animeUserAvatar.setSafeOnClickListener {
val dialogFragment =
SettingsDialogFragment.newInstance2(SettingsDialogFragment.Companion.PageType2.OfflineANIME)
dialogFragment.show((it.context as AppCompatActivity).supportFragmentManager, "dialog")
}
if (!uiSettings.immersiveMode) {
view.rootView.fitsSystemWindows = true
}
val colorOverflow = currContext()?.getSharedPreferences("Dantotsu", Context.MODE_PRIVATE)
?.getBoolean("colorOverflow", false) ?: false
if (!colorOverflow) {
@ -147,7 +146,7 @@ class OfflineAnimeFragment : Fragment(), OfflineAnimeSearchListener {
gridView.scheduleLayoutAnimation()
gridView.visibility = View.VISIBLE
adapter.notifyNewGrid()
grid()
}
layoutcompact.setOnClickListener {
@ -161,6 +160,7 @@ class OfflineAnimeFragment : Fragment(), OfflineAnimeSearchListener {
gridView.scheduleLayoutAnimation()
gridView.visibility = View.VISIBLE
adapter.notifyNewGrid()
grid()
}
gridView =
@ -176,22 +176,7 @@ class OfflineAnimeFragment : Fragment(), OfflineAnimeSearchListener {
adapter = OfflineAnimeAdapter(requireContext(), downloads, this)
gridView.adapter = adapter
gridView.scheduleLayoutAnimation()
gridView.setOnItemClickListener { parent, view, position, id ->
// Get the OfflineAnimeModel that was clicked
val item = adapter.getItem(position) as OfflineAnimeModel
val media =
downloadManager.animeDownloadedTypes.firstOrNull { it.title == item.title }
media?.let {
startActivity(
Intent(requireContext(), MediaDetailsActivity::class.java)
.putExtra("media", getMedia(it))
.putExtra("download", true)
)
} ?: run {
snackString("no media found")
}
}
grid()
val total = view.findViewById<TextView>(R.id.total)
total.text =
if (gridView.count > 0) "Anime (${gridView.count})" else "Empty List"
@ -224,11 +209,26 @@ class OfflineAnimeFragment : Fragment(), OfflineAnimeSearchListener {
dialog.window?.setDimAmount(0.8f)
true
}
view.rootView.fitsSystemWindows = true
return view
}
private fun grid(){
gridView.setOnItemClickListener { parent, view, position, id ->
// Get the OfflineAnimeModel that was clicked
val item = adapter.getItem(position) as OfflineAnimeModel
val media =
downloadManager.animeDownloadedTypes.firstOrNull { it.title == item.title }
media?.let {
startActivity(
Intent(requireContext(), MediaDetailsActivity::class.java)
.putExtra("media", getMedia(it))
.putExtra("download", true)
)
} ?: run {
snackString("no media found")
}
}
}
override fun onSearchQuery(query: String) {
adapter.onSearchQuery(query)
}
@ -251,9 +251,8 @@ class OfflineAnimeFragment : Fragment(), OfflineAnimeSearchListener {
}
}
}
val mangaRefresh = view.findViewById<FrameLayout>(R.id.mangaRefresh)
mangaRefresh.updatePaddingRelative(bottom = navBarHeight + 160f.px)
val scrollTop = view.findViewById<CardView>(R.id.mangaPageScrollTop)
scrollTop.translationY = -(navBarHeight + bottomBar.height + bottomBar.marginBottom).toFloat()
val visible = false
fun animate() {
@ -399,14 +398,16 @@ class OfflineAnimeFragment : Fragment(), OfflineAnimeSearchListener {
val isOngoing =
mediaModel.status == currActivity()!!.getString(R.string.status_releasing)
val isUserScored = mediaModel.userScore != 0
val readEpisode = (mediaModel.userProgress ?: "~").toString()
val totalEpisode = "${mediaModel.anime?.totalEpisodes ?: "??"}"
val watchedEpisodes = (mediaModel.userProgress ?: "~").toString()
val totalEpisode = if (mediaModel.anime?.nextAiringEpisode != null) (mediaModel.anime.nextAiringEpisode.toString() + " | " + (mediaModel.anime.totalEpisodes ?: "~").toString()) else (mediaModel.anime?.totalEpisodes ?: "~").toString()
val chapters = " Chapters"
val totalEpisodesList = if (mediaModel.anime?.nextAiringEpisode != null) (mediaModel.anime.nextAiringEpisode.toString()) else (mediaModel.anime?.totalEpisodes ?: "~").toString()
return OfflineAnimeModel(
title,
score,
totalEpisode,
readEpisode,
totalEpisodesList,
watchedEpisodes,
type,
chapters,
isOngoing,
@ -423,6 +424,7 @@ class OfflineAnimeFragment : Fragment(), OfflineAnimeSearchListener {
"0",
"??",
"??",
"??",
"movie",
"hmm",
false,

View file

@ -5,6 +5,7 @@ data class OfflineAnimeModel (
val title: String,
val score: String,
val totalEpisode: String,
val totalEpisodeList: String,
val watchedEpisode: String,
val type: String,
val episodes: String,

View file

@ -18,29 +18,28 @@ import android.view.animation.LayoutAnimationController
import android.view.animation.OvershootInterpolator
import android.widget.AbsListView
import android.widget.AutoCompleteTextView
import android.widget.FrameLayout
import android.widget.GridView
import android.widget.ImageView
import android.widget.LinearLayout
import android.widget.TextView
import androidx.appcompat.app.AppCompatActivity
import androidx.cardview.widget.CardView
import androidx.core.view.updatePadding
import androidx.core.view.updatePaddingRelative
import androidx.core.view.marginBottom
import androidx.fragment.app.Fragment
import ani.dantotsu.R
import ani.dantotsu.bottomBar
import ani.dantotsu.currActivity
import ani.dantotsu.currContext
import ani.dantotsu.download.DownloadedType
import ani.dantotsu.download.DownloadsManager
import ani.dantotsu.initActivity
import ani.dantotsu.loadData
import ani.dantotsu.logger
import ani.dantotsu.media.Media
import ani.dantotsu.media.MediaDetailsActivity
import ani.dantotsu.navBarHeight
import ani.dantotsu.px
import ani.dantotsu.setSafeOnClickListener
import ani.dantotsu.settings.SettingsDialogFragment
import ani.dantotsu.settings.UserInterfaceSettings
import ani.dantotsu.snackString
import ani.dantotsu.statusBarHeight
import com.google.android.material.card.MaterialCardView
@ -63,15 +62,18 @@ class OfflineMangaFragment : Fragment(), OfflineMangaSearchListener {
private var downloads: List<OfflineMangaModel> = listOf()
private lateinit var gridView: GridView
private lateinit var adapter: OfflineMangaAdapter
private var uiSettings: UserInterfaceSettings =
loadData("ui_settings") ?: UserInterfaceSettings()
override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
val view = inflater.inflate(R.layout.fragment_manga_offline, container, false)
val view = inflater.inflate(R.layout.fragment_offline_page, container, false)
val textInputLayout = view.findViewById<TextInputLayout>(R.id.offlineMangaSearchBar)
textInputLayout.hint = "Manga"
val currentColor = textInputLayout.boxBackgroundColor
val semiTransparentColor = (currentColor and 0x00FFFFFF) or 0xA8000000.toInt()
textInputLayout.boxBackgroundColor = semiTransparentColor
@ -81,16 +83,15 @@ class OfflineMangaFragment : Fragment(), OfflineMangaSearchListener {
requireContext().theme?.resolveAttribute(android.R.attr.windowBackground, typedValue, true)
val color = typedValue.data
val animeTitleContainer = view.findViewById<LinearLayout>(R.id.animeTitleContainer)
animeTitleContainer.updatePadding(top = statusBarHeight)
val animeUserAvatar = view.findViewById<ShapeableImageView>(R.id.offlineMangaUserAvatar)
animeUserAvatar.setSafeOnClickListener {
val dialogFragment =
SettingsDialogFragment.newInstance2(SettingsDialogFragment.Companion.PageType2.OfflineMANGA)
dialogFragment.show((it.context as AppCompatActivity).supportFragmentManager, "dialog")
}
if (!uiSettings.immersiveMode) {
view.rootView.fitsSystemWindows = true
}
val colorOverflow = currContext()?.getSharedPreferences("Dantotsu", Context.MODE_PRIVATE)
?.getBoolean("colorOverflow", false) ?: false
if (!colorOverflow) {
@ -138,6 +139,7 @@ class OfflineMangaFragment : Fragment(), OfflineMangaSearchListener {
gridView.scheduleLayoutAnimation()
gridView.visibility = View.VISIBLE
adapter.notifyNewGrid()
grid()
}
@ -152,8 +154,8 @@ class OfflineMangaFragment : Fragment(), OfflineMangaSearchListener {
gridView.scheduleLayoutAnimation()
gridView.visibility = View.VISIBLE
adapter.notifyNewGrid()
grid()
}
gridView =
if (style == 0) view.findViewById(R.id.gridView) else view.findViewById(R.id.gridView1)
gridView.visibility = View.VISIBLE
@ -167,23 +169,7 @@ class OfflineMangaFragment : Fragment(), OfflineMangaSearchListener {
adapter = OfflineMangaAdapter(requireContext(), downloads, this)
gridView.adapter = adapter
gridView.scheduleLayoutAnimation()
gridView.setOnItemClickListener { parent, view, position, id ->
// Get the OfflineMangaModel that was clicked
val item = adapter.getItem(position) as OfflineMangaModel
val media =
downloadManager.mangaDownloadedTypes.firstOrNull { it.title == item.title }
?: downloadManager.novelDownloadedTypes.firstOrNull { it.title == item.title }
media?.let {
startActivity(
Intent(requireContext(), MediaDetailsActivity::class.java)
.putExtra("media", getMedia(it))
.putExtra("download", true)
)
} ?: run {
snackString("no media found")
}
}
grid()
val total = view.findViewById<TextView>(R.id.total)
total.text =
if (gridView.count > 0) "Manga and Novels (${gridView.count})" else "Empty List"
@ -213,11 +199,26 @@ class OfflineMangaFragment : Fragment(), OfflineMangaSearchListener {
dialog.window?.setDimAmount(0.8f)
true
}
view.rootView.fitsSystemWindows = true
return view
}
private fun grid(){
gridView.setOnItemClickListener { parent, view, position, id ->
// Get the OfflineMangaModel that was clicked
val item = adapter.getItem(position) as OfflineMangaModel
val media =
downloadManager.mangaDownloadedTypes.firstOrNull { it.title == item.title }
?: downloadManager.novelDownloadedTypes.firstOrNull { it.title == item.title }
media?.let {
startActivity(
Intent(requireContext(), MediaDetailsActivity::class.java)
.putExtra("media", getMedia(it))
.putExtra("download", true)
)
} ?: run {
snackString("no media found")
}
}
}
override fun onSearchQuery(query: String) {
adapter.onSearchQuery(query)
}
@ -240,9 +241,8 @@ class OfflineMangaFragment : Fragment(), OfflineMangaSearchListener {
}
}
}
val mangaRefresh = view.findViewById<FrameLayout>(R.id.mangaRefresh)
mangaRefresh.updatePaddingRelative(bottom = navBarHeight + 160f.px)
val scrollTop = view.findViewById<CardView>(R.id.mangaPageScrollTop)
scrollTop.translationY = -(navBarHeight + bottomBar.height + bottomBar.marginBottom).toFloat()
var visible = false
fun animate() {