feat: add tags dialog
This commit is contained in:
@@ -10,6 +10,7 @@ open class Post(
|
||||
open val fileUrl:String,
|
||||
open val sampleHeight: Int,
|
||||
open val sampleWidth: Int,
|
||||
open val tags:String?
|
||||
): Parcelable {
|
||||
constructor(parcel: Parcel) : this(
|
||||
parcel.readString()!!,
|
||||
@@ -17,7 +18,8 @@ open class Post(
|
||||
parcel.readString()!!,
|
||||
parcel.readString()!!,
|
||||
parcel.readInt(),
|
||||
parcel.readInt()
|
||||
parcel.readInt(),
|
||||
parcel.readString()!!
|
||||
)
|
||||
|
||||
override fun describeContents(): Int {
|
||||
@@ -31,6 +33,7 @@ open class Post(
|
||||
dest.writeString(fileUrl)
|
||||
dest.writeInt(sampleHeight)
|
||||
dest.writeInt(sampleWidth)
|
||||
dest.writeString(tags)
|
||||
}
|
||||
|
||||
companion object {
|
||||
|
||||
@@ -7,8 +7,7 @@ class YandPost(
|
||||
@SerializedName("sample_url") override val sampleUrl: String,
|
||||
@SerializedName("sample_height") override val sampleHeight : Int,
|
||||
@SerializedName("sample_width") override val sampleWidth: Int,
|
||||
@SerializedName("file_ext") val fileExt: String,
|
||||
@SerializedName("file_size") val fileSize: String,
|
||||
@SerializedName("id") override val postId: String,
|
||||
rating: String
|
||||
):Post(postId, rating, sampleUrl,fileUrl,sampleHeight,sampleWidth)
|
||||
rating: String,
|
||||
tags:String?
|
||||
):Post(postId, rating, sampleUrl,fileUrl,sampleHeight,sampleWidth,tags)
|
||||
@@ -16,8 +16,9 @@ data class Collect(
|
||||
@ColumnInfo(name = "file_url")override val fileUrl:String,
|
||||
@ColumnInfo(name = "sampleHeight") override val sampleHeight:Int,
|
||||
@ColumnInfo(name = "sampleWeight") override val sampleWidth:Int,
|
||||
@ColumnInfo(name = "type")val type:String
|
||||
):Post(postId,rating,sampleUrl,fileUrl,sampleHeight,sampleWidth){
|
||||
@ColumnInfo(name = "type")val type:String,
|
||||
@ColumnInfo(name = "tags") override val tags:String?
|
||||
):Post(postId,rating,sampleUrl,fileUrl,sampleHeight,sampleWidth,tags){
|
||||
constructor(
|
||||
postId: String,
|
||||
sampleUrl:String,
|
||||
@@ -25,10 +26,11 @@ data class Collect(
|
||||
fileUrl:String,
|
||||
sampleHeight:Int,
|
||||
sampleWeight:Int,
|
||||
tags:String?
|
||||
): this(0, postId, sampleUrl, rating, fileUrl, sampleHeight, sampleWeight,
|
||||
YandViewApplication.context?.getSharedPreferences("com.lsp.view_preferences",Context.MODE_PRIVATE)?.getString("source_name", "yande.re")!!)
|
||||
YandViewApplication.context?.getSharedPreferences("com.lsp.view_preferences",Context.MODE_PRIVATE)?.getString("source_name", "yande.re")!!,tags)
|
||||
companion object{
|
||||
fun Post.toCollect():Collect = Collect(this.postId,this.sampleUrl,this.rating,this.fileUrl,this.sampleHeight,this.sampleWidth )
|
||||
fun Post.toCollect():Collect = Collect(this.postId,this.sampleUrl,this.rating,this.fileUrl,this.sampleHeight,this.sampleWidth ,this.tags)
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -52,6 +52,9 @@ class MainViewModel(private val repository: PostRepository, context: Context):Vi
|
||||
}
|
||||
|
||||
@Volatile private var isProcessing = false
|
||||
private val _tagsList = MutableLiveData<ArrayList<String>>()
|
||||
val tagsList get() = _tagsList as LiveData<ArrayList<String>>
|
||||
|
||||
|
||||
companion object {
|
||||
fun provideFactory(
|
||||
|
||||
@@ -56,14 +56,7 @@ class CollectFragment : Fragment() {
|
||||
|
||||
collectAdapter.setOnListItemClick(object : PostAdapter.OnListItemClick {
|
||||
override fun setOnListItemClick(post: Post) {
|
||||
val bundle = Bundle()
|
||||
bundle.putParcelable("post",post)
|
||||
Navigation.findNavController(view).navigate(R.id.action_collectFragment_to_imageFragment,bundle)
|
||||
val slideOutAnimation = AnimationUtils.loadAnimation(context,
|
||||
R.anim.slide_out_bottom
|
||||
)
|
||||
activityContext.bottomNav.startAnimation(slideOutAnimation)
|
||||
activityContext.bottomNav.visibility = View.GONE
|
||||
ImageFragment.navigationToImageFragment(activityContext,post,view,R.id.action_collectFragment_to_imageFragment)
|
||||
}
|
||||
|
||||
})
|
||||
|
||||
@@ -13,9 +13,11 @@ import android.view.LayoutInflater
|
||||
import android.view.MenuItem
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.view.animation.AnimationUtils
|
||||
import android.widget.ImageView
|
||||
import androidx.core.content.FileProvider
|
||||
import androidx.lifecycle.lifecycleScope
|
||||
import androidx.navigation.Navigation
|
||||
import com.bumptech.glide.Glide
|
||||
import com.bumptech.glide.load.model.GlideUrl
|
||||
import com.bumptech.glide.load.model.LazyHeaders
|
||||
@@ -74,6 +76,12 @@ class ImageFragment : Fragment() {
|
||||
}
|
||||
true
|
||||
}
|
||||
R.id.tags_menu_btn -> {
|
||||
val tagBottomSheet = TagBottomSheet(post?.tags)
|
||||
tagBottomSheet.show(activityContext.supportFragmentManager,TagBottomSheet.TAG)
|
||||
|
||||
true
|
||||
}
|
||||
|
||||
else -> {false}
|
||||
}
|
||||
@@ -114,6 +122,7 @@ class ImageFragment : Fragment() {
|
||||
|
||||
}
|
||||
|
||||
|
||||
private fun collectIt(collect: Collect){
|
||||
activityContext.viewModel.addCollect(collect)
|
||||
collectBtn.setIcon(R.drawable.ic_baseline_favorite_24)
|
||||
@@ -201,6 +210,26 @@ class ImageFragment : Fragment() {
|
||||
|
||||
}
|
||||
|
||||
companion object{
|
||||
fun navigationToImageFragment(context:MainActivity ,post:Post,view:View,fragmentId:Int){
|
||||
val bundle = Bundle()
|
||||
bundle.putParcelable("post",post)
|
||||
val tags = post.tags?.split(",")?.toList()
|
||||
|
||||
context.viewModel.tagsList.value?.apply {
|
||||
clear()
|
||||
tags?.let { addAll(it) }
|
||||
}
|
||||
|
||||
Navigation.findNavController(view).navigate(fragmentId,bundle)
|
||||
val slideOutAnimation = AnimationUtils.loadAnimation(context,
|
||||
R.anim.slide_out_bottom
|
||||
)
|
||||
context.bottomNav.startAnimation(slideOutAnimation)
|
||||
context.bottomNav.visibility = View.GONE
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -87,14 +87,7 @@ class PostListFragment:Fragment() {
|
||||
|
||||
viewModel.adapter.setOnListItemClick(object : PostAdapter.OnListItemClick {
|
||||
override fun setOnListItemClick(post: Post) {
|
||||
val bundle = Bundle()
|
||||
bundle.putParcelable("post",post)
|
||||
Navigation.findNavController(view).navigate(R.id.action_postListFragment_to_imageFragment,bundle)
|
||||
val slideOutAnimation = AnimationUtils.loadAnimation(context,
|
||||
R.anim.slide_out_bottom
|
||||
)
|
||||
activityContext.bottomNav.startAnimation(slideOutAnimation)
|
||||
activityContext.bottomNav.visibility = View.GONE
|
||||
ImageFragment.navigationToImageFragment(activityContext,post,view,R.id.action_postListFragment_to_imageFragment)
|
||||
}
|
||||
|
||||
})
|
||||
|
||||
@@ -0,0 +1,49 @@
|
||||
package com.lsp.view.ui.fragment
|
||||
|
||||
import android.os.Bundle
|
||||
import android.util.Log
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import com.google.android.flexbox.FlexDirection
|
||||
import com.google.android.flexbox.FlexWrap
|
||||
import com.google.android.flexbox.FlexboxLayoutManager
|
||||
import com.google.android.material.bottomsheet.BottomSheetDialogFragment
|
||||
import com.lsp.view.R
|
||||
import com.lsp.view.ui.activity.MainActivity
|
||||
import com.lsp.view.ui.fragment.adapter.TagsAdapter
|
||||
|
||||
class TagBottomSheet(val tags:String?): BottomSheetDialogFragment() {
|
||||
private val activityContext : MainActivity by lazy {
|
||||
requireActivity() as MainActivity
|
||||
}
|
||||
override fun onCreateView(
|
||||
inflater: LayoutInflater,
|
||||
container: ViewGroup?,
|
||||
savedInstanceState: Bundle?
|
||||
): View? {
|
||||
return inflater.inflate(R.layout.fragment_bottom_sheet, container, false)
|
||||
}
|
||||
|
||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||
super.onViewCreated(view, savedInstanceState)
|
||||
val tagList = view.findViewById<RecyclerView>(R.id.tag_list)
|
||||
// val layoutManager = LinearLayoutManager(activityContext)
|
||||
val flManager = FlexboxLayoutManager(activityContext)
|
||||
flManager.flexWrap = FlexWrap.WRAP
|
||||
flManager.flexDirection = FlexDirection.ROW
|
||||
|
||||
Log.e(TAG,tags.toString())
|
||||
val split = tags?.split(" ")?.toList()
|
||||
if (split!=null){
|
||||
val adapter = TagsAdapter(split)
|
||||
tagList.layoutManager = flManager
|
||||
tagList.adapter = adapter
|
||||
}
|
||||
|
||||
}
|
||||
companion object {
|
||||
const val TAG = "TagBottomSheet"
|
||||
}
|
||||
}
|
||||
@@ -18,7 +18,6 @@ class PostAdapter(val context: Context,private val postList: ArrayList<Post> = A
|
||||
RecyclerView.Adapter<PostAdapter.ViewHolder>() {
|
||||
val TAG = this::class.java.simpleName
|
||||
private var inBottom:Boolean = false//当前列表是否在底部
|
||||
@Volatile private var isProcess:Boolean = false
|
||||
|
||||
inner class ViewHolder(view: View) : RecyclerView.ViewHolder(view) {
|
||||
val picImage: ImageView = view.findViewById(R.id.image)
|
||||
@@ -26,24 +25,20 @@ class PostAdapter(val context: Context,private val postList: ArrayList<Post> = A
|
||||
}
|
||||
|
||||
fun pushNewData(list: List<Post>) {
|
||||
if (!isProcess) {
|
||||
isProcess = true
|
||||
if (inBottom) {
|
||||
//在底部,则追加数据
|
||||
val pos = postList.size
|
||||
postList.addAll(list)
|
||||
notifyItemRangeInserted(pos - 1, list.size)
|
||||
} else {
|
||||
//不在则刷新数据
|
||||
val oldSize = postList.size
|
||||
postList.clear()
|
||||
notifyItemRangeRemoved(0, oldSize)
|
||||
postList.addAll(list)
|
||||
notifyItemRangeInserted(0, list.size)
|
||||
}
|
||||
if (inBottom) {
|
||||
//在底部,则追加数据
|
||||
val pos = postList.size
|
||||
postList.addAll(list)
|
||||
notifyItemRangeInserted(pos - 1, list.size)
|
||||
} else {
|
||||
//不在则刷新数据
|
||||
val oldSize = postList.size
|
||||
postList.clear()
|
||||
notifyItemRangeRemoved(0, oldSize)
|
||||
postList.addAll(list)
|
||||
notifyItemRangeInserted(0, list.size)
|
||||
}
|
||||
|
||||
isProcess = false
|
||||
inBottom = false//加入新数据后不在底部,若仍在底部说明无更多数据,也不必处理
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
package com.lsp.view.ui.fragment.adapter
|
||||
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.widget.TextView
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import com.lsp.view.R
|
||||
|
||||
class TagsAdapter(private val tagList:List<String>):RecyclerView.Adapter<TagsAdapter.ViewHolder>() {
|
||||
inner class ViewHolder(view:View):RecyclerView.ViewHolder(view) {
|
||||
val tagItem = view.findViewById<TextView>(R.id.tag)
|
||||
}
|
||||
|
||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
|
||||
val view =
|
||||
LayoutInflater.from(parent.context).inflate(R.layout.tags_item_layout, parent, false)
|
||||
val viewHolder = ViewHolder(view)
|
||||
|
||||
return viewHolder
|
||||
}
|
||||
|
||||
override fun getItemCount() = tagList.size
|
||||
|
||||
override fun onBindViewHolder(holder: ViewHolder, position: Int) {
|
||||
holder.tagItem.text = tagList[position]
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
<vector android:autoMirrored="true" android:height="24dp"
|
||||
android:tint="?attr/colorControlNormal"
|
||||
android:viewportHeight="24"
|
||||
android:viewportWidth="24" android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<path android:fillColor="@android:color/white" android:pathData="M17.63,5.84C17.27,5.33 16.67,5 16,5L5,5.01C3.9,5.01 3,5.9 3,7v10c0,1.1 0.9,1.99 2,1.99L16,19c0.67,0 1.27,-0.33 1.63,-0.84L22,12l-4.37,-6.16z"/>
|
||||
</vector>
|
||||
@@ -0,0 +1,19 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto">
|
||||
<FrameLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:id="@+id/standard_bottom_sheet"
|
||||
app:layout_behavior="com.google.android.material.bottomsheet.BottomSheetBehavior">
|
||||
<androidx.recyclerview.widget.RecyclerView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:id="@+id/tag_list"/>
|
||||
|
||||
</FrameLayout>
|
||||
|
||||
|
||||
</androidx.coordinatorlayout.widget.CoordinatorLayout>
|
||||
@@ -14,8 +14,6 @@
|
||||
android:id="@+id/image_content"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"/>
|
||||
|
||||
|
||||
<com.google.android.material.bottomappbar.BottomAppBar
|
||||
android:id="@+id/bottomAppBar"
|
||||
style="@style/Widget.Material3.BottomAppBar"
|
||||
@@ -32,6 +30,7 @@
|
||||
app:srcCompat="@drawable/baseline_file_download_24"
|
||||
android:contentDescription="@string/description_download" />
|
||||
|
||||
|
||||
</androidx.coordinatorlayout.widget.CoordinatorLayout>
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<com.google.android.material.card.MaterialCardView xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content">
|
||||
<TextView
|
||||
android:layout_margin="10dp"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:id="@+id/tag"/>
|
||||
|
||||
</com.google.android.material.card.MaterialCardView>
|
||||
@@ -10,5 +10,10 @@
|
||||
android:title="@string/title_collect"
|
||||
android:icon="@drawable/ic_baseline_favorite_24"
|
||||
app:showAsAction="ifRoom"/>
|
||||
<item android:id="@+id/tags_menu_btn"
|
||||
android:title="@string/tags"
|
||||
android:icon="@drawable/ic_baseline_label_24"
|
||||
app:showAsAction="ifRoom"/>
|
||||
|
||||
|
||||
</menu>
|
||||
@@ -28,4 +28,5 @@
|
||||
<string name="toast_download_start">Start download</string>
|
||||
<string name="title_share">Share</string>
|
||||
<string name="title_collect">Collect</string>
|
||||
<string name="tags">Tags</string>
|
||||
</resources>
|
||||
Reference in New Issue
Block a user