From aa972c916a3e207d2b1795249f66f497d67dafce Mon Sep 17 00:00:00 2001 From: aayush262 <99584765+aayush2622@users.noreply.github.com> Date: Wed, 17 Jan 2024 02:24:07 +0530 Subject: [PATCH] navbar fix (#135) * navbar fix * fixed can uninstall after changing grid view * removes server selector in offline mode shows amount of Scanlator present --- .../main/java/ani/dantotsu/MainActivity.kt | 5 +++ .../download/anime/OfflineAnimeFragment.kt | 45 +++++++++---------- .../download/manga/OfflineMangaFragment.kt | 45 ++++++++++--------- .../main/java/ani/dantotsu/home/NoInternet.kt | 8 ++++ .../dantotsu/media/anime/AnimeWatchAdapter.kt | 11 ++++- .../dantotsu/media/manga/MangaReadAdapter.kt | 15 +++++-- .../main/res/layout/custom_dialog_layout.xml | 11 ++++- app/src/main/res/layout/dialog_layout.xml | 24 +++++++--- app/src/main/res/layout/item_anime_watch.xml | 2 +- 9 files changed, 107 insertions(+), 59 deletions(-) diff --git a/app/src/main/java/ani/dantotsu/MainActivity.kt b/app/src/main/java/ani/dantotsu/MainActivity.kt index 5f2173cad4..5fa21e504e 100644 --- a/app/src/main/java/ani/dantotsu/MainActivity.kt +++ b/app/src/main/java/ani/dantotsu/MainActivity.kt @@ -152,6 +152,11 @@ class MainActivity : AppCompatActivity() { initActivity(this) uiSettings = loadData("ui_settings") ?: uiSettings selectedOption = uiSettings.defaultStartUpTab + if (!uiSettings.immersiveMode) { + binding.includedNavbar.navbarContainer.updateLayoutParams { + bottomMargin = navBarHeight + } + } } val offline = getSharedPreferences("Dantotsu", Context.MODE_PRIVATE) .getBoolean("offlineMode", false) 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 58914b280d..398a575c78 100644 --- a/app/src/main/java/ani/dantotsu/download/anime/OfflineAnimeFragment.kt +++ b/app/src/main/java/ani/dantotsu/download/anime/OfflineAnimeFragment.kt @@ -72,7 +72,7 @@ class OfflineAnimeFragment : Fragment(), OfflineAnimeSearchListener { private var uiSettings: UserInterfaceSettings = loadData("ui_settings") ?: UserInterfaceSettings() - @OptIn(UnstableApi::class) override fun onCreateView( + override fun onCreateView( inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle? @@ -167,19 +167,35 @@ class OfflineAnimeFragment : Fragment(), OfflineAnimeSearchListener { if (style == 0) view.findViewById(R.id.gridView) else view.findViewById(R.id.gridView1) gridView.visibility = View.VISIBLE getDownloads() - val fadeIn = AlphaAnimation(0f, 1f) fadeIn.duration = 200 // animations pog val animation = LayoutAnimationController(fadeIn) - gridView.layoutAnimation = animation adapter = OfflineAnimeAdapter(requireContext(), downloads, this) gridView.adapter = adapter gridView.scheduleLayoutAnimation() grid() val total = view.findViewById(R.id.total) - total.text = - if (gridView.count > 0) "Anime (${gridView.count})" else "Empty List" + total.text = if (gridView.count > 0) "Anime (${gridView.count})" else "Empty List" + + return view + } + @OptIn(UnstableApi::class) 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") + } + } gridView.setOnItemLongClickListener { parent, view, position, id -> // Get the OfflineAnimeModel that was clicked val item = adapter.getItem(position) as OfflineAnimeModel @@ -209,25 +225,6 @@ class OfflineAnimeFragment : Fragment(), OfflineAnimeSearchListener { dialog.window?.setDimAmount(0.8f) 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) 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 3f202a2ed6..099c3e587e 100644 --- a/app/src/main/java/ani/dantotsu/download/manga/OfflineMangaFragment.kt +++ b/app/src/main/java/ani/dantotsu/download/manga/OfflineMangaFragment.kt @@ -171,8 +171,28 @@ class OfflineMangaFragment : Fragment(), OfflineMangaSearchListener { gridView.scheduleLayoutAnimation() grid() val total = view.findViewById(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" + + 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") + } + } + gridView.setOnItemLongClickListener { parent, view, position, id -> // Get the OfflineMangaModel that was clicked val item = adapter.getItem(position) as OfflineMangaModel @@ -199,25 +219,6 @@ class OfflineMangaFragment : Fragment(), OfflineMangaSearchListener { dialog.window?.setDimAmount(0.8f) 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) @@ -243,7 +244,7 @@ class OfflineMangaFragment : Fragment(), OfflineMangaSearchListener { } val scrollTop = view.findViewById(R.id.mangaPageScrollTop) scrollTop.translationY = -(navBarHeight + bottomBar.height + bottomBar.marginBottom).toFloat() - var visible = false + val visible = false fun animate() { val start = if (visible) 0f else 1f diff --git a/app/src/main/java/ani/dantotsu/home/NoInternet.kt b/app/src/main/java/ani/dantotsu/home/NoInternet.kt index 2ff26c77b1..7b6aba262e 100644 --- a/app/src/main/java/ani/dantotsu/home/NoInternet.kt +++ b/app/src/main/java/ani/dantotsu/home/NoInternet.kt @@ -7,10 +7,12 @@ import android.os.Bundle import android.os.Handler import android.os.Looper import android.view.View +import android.view.ViewGroup import androidx.activity.addCallback import androidx.appcompat.app.AppCompatActivity import androidx.core.content.ContextCompat import androidx.core.view.doOnAttach +import androidx.core.view.updateLayoutParams import androidx.fragment.app.Fragment import androidx.fragment.app.FragmentManager import androidx.lifecycle.Lifecycle @@ -22,6 +24,7 @@ import ani.dantotsu.download.anime.OfflineAnimeFragment import ani.dantotsu.download.manga.OfflineMangaFragment import ani.dantotsu.initActivity import ani.dantotsu.loadData +import ani.dantotsu.navBarHeight import ani.dantotsu.offline.OfflineFragment import ani.dantotsu.others.LangSet import ani.dantotsu.selectedOption @@ -75,6 +78,11 @@ class NoInternet : AppCompatActivity() { initActivity(this) uiSettings = loadData("ui_settings") ?: uiSettings selectedOption = uiSettings.defaultStartUpTab + if (!uiSettings.immersiveMode) { + binding.includedNavbar.navbarContainer.updateLayoutParams { + bottomMargin = navBarHeight + } + } } val navbar = binding.includedNavbar.navbar ani.dantotsu.bottomBar = navbar diff --git a/app/src/main/java/ani/dantotsu/media/anime/AnimeWatchAdapter.kt b/app/src/main/java/ani/dantotsu/media/anime/AnimeWatchAdapter.kt index cdf7eb3ef4..cf605c4ecd 100644 --- a/app/src/main/java/ani/dantotsu/media/anime/AnimeWatchAdapter.kt +++ b/app/src/main/java/ani/dantotsu/media/anime/AnimeWatchAdapter.kt @@ -1,6 +1,7 @@ package ani.dantotsu.media.anime import android.annotation.SuppressLint +import android.content.Context import android.content.Intent import android.net.Uri import android.view.LayoutInflater @@ -85,6 +86,13 @@ class AnimeWatchAdapter( null ) } + val offline = if (!isOnline(binding.root.context) || currContext()?.getSharedPreferences("Dantotsu", Context.MODE_PRIVATE) + ?.getBoolean("offlineMode", false) == true) View.GONE else View.VISIBLE + + binding.animeSourceNameContainer.visibility = offline + binding.animeSourceSettings.visibility = offline + binding.animeSourceSearch.visibility = offline + binding.animeSourceTitle.visibility = offline //Source Selection var source = @@ -401,9 +409,8 @@ class AnimeWatchAdapter( parser.extension.sources.map { LanguageMapper.mapLanguageCodeToName(it.lang) } ) val items = adapter.count - if (items > 1) binding?.animeSourceLanguageContainer?.visibility = - View.VISIBLE else binding?.animeSourceLanguageContainer?.visibility = View.GONE + binding?.animeSourceLanguageContainer?.visibility = if (items > 1) View.VISIBLE else View.GONE binding?.animeSourceLanguage?.setAdapter(adapter) } diff --git a/app/src/main/java/ani/dantotsu/media/manga/MangaReadAdapter.kt b/app/src/main/java/ani/dantotsu/media/manga/MangaReadAdapter.kt index 940914e2d8..290491ec0d 100644 --- a/app/src/main/java/ani/dantotsu/media/manga/MangaReadAdapter.kt +++ b/app/src/main/java/ani/dantotsu/media/manga/MangaReadAdapter.kt @@ -2,6 +2,7 @@ package ani.dantotsu.media.manga import android.annotation.SuppressLint import android.app.AlertDialog +import android.content.Context import android.view.LayoutInflater import android.view.View import android.view.ViewGroup @@ -64,7 +65,13 @@ class MangaReadAdapter( null ) } + val offline = if (!isOnline(binding.root.context) || currContext()?.getSharedPreferences("Dantotsu", Context.MODE_PRIVATE) + ?.getBoolean("offlineMode", false) == true) View.GONE else View.VISIBLE + binding.animeSourceNameContainer.visibility = offline + binding.animeSourceSettings.visibility = offline + binding.animeSourceSearch.visibility = offline + binding.animeSourceTitle.visibility = offline //Source Selection var source = media.selected!!.sourceIndex.let { if (it >= mangaReadSources.names.size) 0 else it } @@ -142,8 +149,7 @@ class MangaReadAdapter( binding.animeNestedButton.setOnClickListener { - val dialogView = - LayoutInflater.from(fragment.requireContext()).inflate(R.layout.dialog_layout, null) + val dialogView = LayoutInflater.from(fragment.requireContext()).inflate(R.layout.dialog_layout, null) val dialogBinding = DialogLayoutBinding.bind(dialogView) var run = false @@ -210,6 +216,8 @@ class MangaReadAdapter( } //Scanlator + dialogBinding.animeScanlatorContainer.visibility = if (options.count() > 1) View.VISIBLE else View.GONE + dialogBinding.scanlatorNo.text = "${options.count()}" dialogBinding.animeScanlatorTop.setOnClickListener { val dialogView2 = LayoutInflater.from(currContext()).inflate(R.layout.custom_dialog_layout, null) @@ -429,8 +437,7 @@ class MangaReadAdapter( parser.extension.sources.map { LanguageMapper.mapLanguageCodeToName(it.lang) } ) val items = adapter.count - if (items > 1) binding?.animeSourceLanguageContainer?.visibility = - View.VISIBLE else binding?.animeSourceLanguageContainer?.visibility = View.GONE + binding?.animeSourceLanguageContainer?.visibility = if (items > 1) View.VISIBLE else View.GONE binding?.animeSourceLanguage?.setAdapter(adapter) diff --git a/app/src/main/res/layout/custom_dialog_layout.xml b/app/src/main/res/layout/custom_dialog_layout.xml index 1cd9e7dead..a77bc4f0c3 100644 --- a/app/src/main/res/layout/custom_dialog_layout.xml +++ b/app/src/main/res/layout/custom_dialog_layout.xml @@ -4,7 +4,16 @@ android:layout_height="wrap_content" android:orientation="vertical" android:padding="16dp"> - + diff --git a/app/src/main/res/layout/dialog_layout.xml b/app/src/main/res/layout/dialog_layout.xml index b0d24a41fd..aa1d661fa5 100644 --- a/app/src/main/res/layout/dialog_layout.xml +++ b/app/src/main/res/layout/dialog_layout.xml @@ -198,13 +198,27 @@ android:layout_height="wrap_content" android:layout_gravity="center_vertical" android:id="@+id/animeScanlatorContainer"> - + android:orientation="vertical"> + + + + +