feat: search on home + setting

This commit is contained in:
rebel onion 2025-01-04 05:06:06 -06:00
parent 986d0fa4a8
commit d422a1586f
7 changed files with 75 additions and 8 deletions

View file

@ -20,6 +20,7 @@ import androidx.viewpager2.widget.ViewPager2
import ani.dantotsu.MediaPageTransformer
import ani.dantotsu.R
import ani.dantotsu.connections.anilist.Anilist
import ani.dantotsu.connections.anilist.AnilistSearch.SearchType.Companion.toAnilistString
import ani.dantotsu.databinding.ItemAnimePageBinding
import ani.dantotsu.databinding.LayoutTrendingBinding
import ani.dantotsu.getAppString
@ -30,6 +31,7 @@ import ani.dantotsu.media.GenreActivity
import ani.dantotsu.media.Media
import ani.dantotsu.media.MediaAdaptor
import ani.dantotsu.media.MediaListViewActivity
import ani.dantotsu.media.SearchActivity
import ani.dantotsu.profile.ProfileActivity
import ani.dantotsu.px
import ani.dantotsu.setSafeOnClickListener
@ -82,11 +84,20 @@ class AnimePageAdapter : RecyclerView.Adapter<AnimePageAdapter.AnimePageViewHold
trendingBinding.searchBar.hint = binding.root.context.getString(R.string.search)
trendingBinding.searchBarText.setOnClickListener {
val context = binding.root.context
if (PrefManager.getVal(PrefName.AniMangaSearchDirect) && Anilist.token != null) {
ContextCompat.startActivity(
context,
Intent(context, SearchActivity::class.java).putExtra("type", "ANIME"),
null
)
} else {
SearchBottomSheet.newInstance().show(
(binding.root.context as AppCompatActivity).supportFragmentManager,
(context as AppCompatActivity).supportFragmentManager,
"search"
)
}
}
trendingBinding.userAvatar.setSafeOnClickListener {
val dialogFragment =

View file

@ -133,6 +133,12 @@ class HomeFragment : Fragment() {
"dialog"
)
}
binding.searchImageContainer.setSafeOnClickListener {
SearchBottomSheet.newInstance().show(
(it.context as androidx.appcompat.app.AppCompatActivity).supportFragmentManager,
"search"
)
}
binding.homeUserAvatarContainer.setOnLongClickListener {
it.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS)
ContextCompat.startActivity(

View file

@ -84,11 +84,20 @@ class MangaPageAdapter : RecyclerView.Adapter<MangaPageAdapter.MangaPageViewHold
trendingBinding.notificationCount.text = Anilist.unreadNotificationCount.toString()
trendingBinding.searchBar.hint = binding.root.context.getString(R.string.search)
trendingBinding.searchBarText.setOnClickListener {
val context = binding.root.context
if (PrefManager.getVal(PrefName.AniMangaSearchDirect) && Anilist.token != null) {
ContextCompat.startActivity(
context,
Intent(context, SearchActivity::class.java).putExtra("type", "MANGA"),
null
)
} else {
SearchBottomSheet.newInstance().show(
(binding.root.context as AppCompatActivity).supportFragmentManager,
(context as AppCompatActivity).supportFragmentManager,
"search"
)
}
}
trendingBinding.userAvatar.setSafeOnClickListener {
val dialogFragment =

View file

@ -155,6 +155,16 @@ class SettingsCommonActivity : AppCompatActivity() {
},
isActivity = true
),
Settings(
type = 2,
name = getString(R.string.open_animanga_directly),
desc = getString(R.string.open_animanga_directly_info),
icon = R.drawable.ic_round_search_24,
isChecked = PrefManager.getVal(PrefName.AniMangaSearchDirect),
switch = { isChecked, _ ->
PrefManager.setVal(PrefName.AniMangaSearchDirect, isChecked)
}
),
Settings(
type = 1,
name = getString(R.string.download_manager_select),

View file

@ -55,6 +55,7 @@ enum class PrefName(val data: Pref) {
CommentsEnabled(Pref(Location.General, Int::class, 0)),
EnableSocks5Proxy(Pref(Location.General, Boolean::class, false)),
ProxyAuthEnabled(Pref(Location.General, Boolean::class, false)),
AniMangaSearchDirect(Pref(Location.General, Boolean::class, true)),
//User Interface
UseOLED(Pref(Location.UI, Boolean::class, false)),

View file

@ -146,6 +146,34 @@
</FrameLayout>
<FrameLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="10dp">
<com.google.android.material.card.MaterialCardView
android:id="@+id/searchImageContainer"
android:layout_width="52dp"
android:layout_height="52dp"
android:layout_marginTop="4dp"
android:backgroundTint="@color/nav_bg_inv"
app:cardCornerRadius="26dp">
<com.google.android.material.imageview.ShapeableImageView
android:id="@+id/searchImage"
android:layout_width="52dp"
android:layout_height="52dp"
android:scaleType="center"
android:scaleX="1.2"
android:scaleY="1.2"
android:tint="@color/bg_black"
app:srcCompat="@drawable/ic_round_search_24"
tools:ignore="ContentDescription,ImageContrastCheck" />
</com.google.android.material.card.MaterialCardView>
</FrameLayout>
<FrameLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">

View file

@ -395,6 +395,8 @@
<string name="planned_manga">Planned Manga</string>
<string name="image_long_clicking">Open image by Long Clicking</string>
<string name="always_continue_content">Always continue previous items</string>
<string name="open_animanga_directly">Open Anime/Manga search directly</string>
<string name="open_animanga_directly_info">Open Anime/Manga search on their respective pages directly</string>
<string name="search_source_list">Search next available source</string>
<string name="timestamp_proxy_desc">Useful if you are getting Handshake Fails</string>
<string name="timestamp_proxy">Use Proxy for Timestamps</string>