diff --git a/app/src/main/java/ani/dantotsu/download/anime/OfflineAnimeAdapter.kt b/app/src/main/java/ani/dantotsu/download/anime/OfflineAnimeAdapter.kt index f1ce28f111..4cd57f050f 100644 --- a/app/src/main/java/ani/dantotsu/download/anime/OfflineAnimeAdapter.kt +++ b/app/src/main/java/ani/dantotsu/download/anime/OfflineAnimeAdapter.kt @@ -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(R.id.itemCompactScore) val itemScoreBG = view.findViewById(R.id.itemCompactScoreBG) val ongoing = view.findViewById(R.id.itemCompactOngoing) - val totalchapter = view.findViewById(R.id.itemCompactTotal) + val totalepisodes = view.findViewById(R.id.itemCompactTotal) val typeimage = view.findViewById(R.id.itemCompactTypeImage) val type = view.findViewById(R.id.itemCompactRelation) val typeView = view.findViewById(R.id.itemCompactType) if (style == 0) { val bannerView = view.findViewById(R.id.itemCompactBanner) // for large view - val chapters = view.findViewById(R.id.itemTotal) - chapters.text = " Chapters" + val episodes = view.findViewById(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(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 diff --git a/app/src/main/java/ani/dantotsu/download/anime/OfflineAnimeFragment.kt b/app/src/main/java/ani/dantotsu/download/anime/OfflineAnimeFragment.kt index b59928b264..58914b280d 100644 --- a/app/src/main/java/ani/dantotsu/download/anime/OfflineAnimeFragment.kt +++ b/app/src/main/java/ani/dantotsu/download/anime/OfflineAnimeFragment.kt @@ -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 = 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(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(R.id.animeTitleContainer) - animeTitleContainer.updatePadding(top = statusBarHeight) - val animeUserAvatar = view.findViewById(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(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(R.id.mangaRefresh) - mangaRefresh.updatePaddingRelative(bottom = navBarHeight + 160f.px) val scrollTop = view.findViewById(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, diff --git a/app/src/main/java/ani/dantotsu/download/anime/OfflineAnimeModel.kt b/app/src/main/java/ani/dantotsu/download/anime/OfflineAnimeModel.kt index a3fe79058c..b5047b97a1 100644 --- a/app/src/main/java/ani/dantotsu/download/anime/OfflineAnimeModel.kt +++ b/app/src/main/java/ani/dantotsu/download/anime/OfflineAnimeModel.kt @@ -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, diff --git a/app/src/main/java/ani/dantotsu/download/manga/OfflineMangaFragment.kt b/app/src/main/java/ani/dantotsu/download/manga/OfflineMangaFragment.kt index 6b39f21a4c..3f202a2ed6 100644 --- a/app/src/main/java/ani/dantotsu/download/manga/OfflineMangaFragment.kt +++ b/app/src/main/java/ani/dantotsu/download/manga/OfflineMangaFragment.kt @@ -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 = 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(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(R.id.animeTitleContainer) - animeTitleContainer.updatePadding(top = statusBarHeight) - val animeUserAvatar = view.findViewById(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(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(R.id.mangaRefresh) - mangaRefresh.updatePaddingRelative(bottom = navBarHeight + 160f.px) val scrollTop = view.findViewById(R.id.mangaPageScrollTop) + scrollTop.translationY = -(navBarHeight + bottomBar.height + bottomBar.marginBottom).toFloat() var visible = false fun animate() { diff --git a/app/src/main/res/layout/fragment_manga_offline.xml b/app/src/main/res/layout/fragment_offline_page.xml similarity index 97% rename from app/src/main/res/layout/fragment_manga_offline.xml rename to app/src/main/res/layout/fragment_offline_page.xml index bcd97c8622..68cc7150c3 100644 --- a/app/src/main/res/layout/fragment_manga_offline.xml +++ b/app/src/main/res/layout/fragment_offline_page.xml @@ -7,7 +7,6 @@ tools:context=".home.MangaFragment">