Skip to content

Commit

Permalink
navbar fix (#135)
Browse files Browse the repository at this point in the history
* navbar fix

* fixed can uninstall after changing grid view

* removes server selector in offline mode shows amount of Scanlator present
  • Loading branch information
aayush2622 authored Jan 16, 2024
1 parent 6115006 commit aa972c9
Show file tree
Hide file tree
Showing 9 changed files with 107 additions and 59 deletions.
5 changes: 5 additions & 0 deletions app/src/main/java/ani/dantotsu/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,11 @@ class MainActivity : AppCompatActivity() {
initActivity(this)
uiSettings = loadData("ui_settings") ?: uiSettings
selectedOption = uiSettings.defaultStartUpTab
if (!uiSettings.immersiveMode) {
binding.includedNavbar.navbarContainer.updateLayoutParams<ViewGroup.MarginLayoutParams> {
bottomMargin = navBarHeight
}
}
}
val offline = getSharedPreferences("Dantotsu", Context.MODE_PRIVATE)
.getBoolean("offlineMode", false)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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?
Expand Down Expand Up @@ -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<TextView>(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
Expand Down Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,8 +171,28 @@ class OfflineMangaFragment : Fragment(), OfflineMangaSearchListener {
gridView.scheduleLayoutAnimation()
grid()
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"

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
Expand All @@ -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)
Expand All @@ -243,7 +244,7 @@ class OfflineMangaFragment : Fragment(), OfflineMangaSearchListener {
}
val scrollTop = view.findViewById<CardView>(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
Expand Down
8 changes: 8 additions & 0 deletions app/src/main/java/ani/dantotsu/home/NoInternet.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -75,6 +78,11 @@ class NoInternet : AppCompatActivity() {
initActivity(this)
uiSettings = loadData("ui_settings") ?: uiSettings
selectedOption = uiSettings.defaultStartUpTab
if (!uiSettings.immersiveMode) {
binding.includedNavbar.navbarContainer.updateLayoutParams<ViewGroup.MarginLayoutParams> {
bottomMargin = navBarHeight
}
}
}
val navbar = binding.includedNavbar.navbar
ani.dantotsu.bottomBar = navbar
Expand Down
11 changes: 9 additions & 2 deletions app/src/main/java/ani/dantotsu/media/anime/AnimeWatchAdapter.kt
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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 =
Expand Down Expand Up @@ -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)

}
Expand Down
15 changes: 11 additions & 4 deletions app/src/main/java/ani/dantotsu/media/manga/MangaReadAdapter.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 }
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)

Expand Down
11 changes: 10 additions & 1 deletion app/src/main/res/layout/custom_dialog_layout.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,16 @@
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="16dp">

<TextView
android:layout_width="265dp"
android:layout_height="48dp"
android:fontFamily="@font/poppins_bold"
android:gravity="center|start"
android:textSize="16sp"
android:singleLine="true"
android:textColor="?attr/colorOnBackground"
android:ellipsize="end"
android:text="Scanlators" />
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content">
Expand Down
24 changes: 19 additions & 5 deletions app/src/main/res/layout/dialog_layout.xml
Original file line number Diff line number Diff line change
Expand Up @@ -198,13 +198,27 @@
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:id="@+id/animeScanlatorContainer">
<TextView
<LinearLayout
android:layout_width="265dp"
android:layout_height="match_parent"
android:fontFamily="@font/poppins_bold"
android:alpha="0.58"
android:text="Scanlator"
android:gravity="center_vertical"/>
android:orientation="vertical">

<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fontFamily="@font/poppins_bold"
android:alpha="0.58"
android:text="Scanlator" />

<TextView
android:id="@+id/scanlatorNo"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fontFamily="@font/poppins_bold"
android:textColor="?attr/colorSecondary"
tools:ignore="TextContrastCheck"
tools:text="number" />
</LinearLayout>
<androidx.cardview.widget.CardView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/layout/item_anime_watch.xml
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@

<com.google.android.material.textfield.TextInputLayout
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox.ExposedDropdownMenu"
android:id="@+id/animeSourceNameContainer"
android:layout_width="0dp"

android:layout_height="56dp"
android:layout_weight="1"
android:hint="@string/source"
Expand Down

0 comments on commit aa972c9

Please sign in to comment.