From ecb6122e7f62772512f81474ced37359aa84942a Mon Sep 17 00:00:00 2001 From: lunaticbum <> Date: Fri, 8 Nov 2024 13:33:56 +0900 Subject: [PATCH] ... --- .../behavior/behaviorimpl/BehaviorRecT.kt | 83 +++++++++++++++++++ .../lunatic/launcher/home/LauncherHome.kt | 11 ++- .../launcher/home/adapters/RssItemAdapter.kt | 17 ++-- .../launcher/model/RssDataInterface.kt | 1 - app/src/main/res/layout/behavior.xml | 22 +++-- 5 files changed, 114 insertions(+), 20 deletions(-) create mode 100644 app/src/main/kotlin/bums/lunatic/launcher/behavior/behaviorimpl/BehaviorRecT.kt diff --git a/app/src/main/kotlin/bums/lunatic/launcher/behavior/behaviorimpl/BehaviorRecT.kt b/app/src/main/kotlin/bums/lunatic/launcher/behavior/behaviorimpl/BehaviorRecT.kt new file mode 100644 index 00000000..9dfd8187 --- /dev/null +++ b/app/src/main/kotlin/bums/lunatic/launcher/behavior/behaviorimpl/BehaviorRecT.kt @@ -0,0 +1,83 @@ +package bums.lunatic.launcher.behavior.behaviorimpl + +import android.content.Context +import android.util.AttributeSet +import android.util.DisplayMetrics +import android.util.TypedValue +import android.view.View +import android.widget.TextView +import androidx.annotation.NonNull +import androidx.coordinatorlayout.widget.CoordinatorLayout +import androidx.recyclerview.widget.RecyclerView +import bums.lunatic.launcher.R +import com.google.android.material.appbar.AppBarLayout +import kotlin.math.abs + + +class BehaviorRecT(context: Context, attrs: AttributeSet?) : + CoordinatorLayout.Behavior(context, attrs) { + private val mContext: Context = context + + private val marginTop: Float + private val marginTopAfter: Float + + private val getYMax: Float = + context.getResources().getDimension(R.dimen.appbar_height) - context.getResources() + .getDimension(R.dimen.toolbar_height) + + init { + marginTop = dpToPx(getYMax / 4) + marginTopAfter = dpToPx(getYMax / 8) + } + + override fun layoutDependsOn( + @NonNull parent: CoordinatorLayout, + @NonNull child: RecyclerView, + @NonNull dependency: View + ): Boolean { + return dependency is AppBarLayout + } + + /** + * dependency 의 View 의 변화가 있을때 이벤트가 들어옵니다. + */ + override fun onDependentViewChanged( + @NonNull parent: CoordinatorLayout, + @NonNull child: RecyclerView, + @NonNull dependency: View + ): Boolean { + child.alpha = getRatioValue( + 1f, 0f, + abs(dependency.y.toDouble()).toFloat(), getYMax + ) + child.alpha = getRatioValue( + 1f, 0f, + abs(dependency.y.toDouble()).toFloat(), getYMax + ) + + child.x = (dependency.width / 2 - (child.width / 2)).toFloat() + + child.y = getRatioValue( + marginTop, marginTopAfter, + abs(dependency.y.toDouble()).toFloat(), getYMax + ) + + return false + } + + private fun dpToPx(dp: Float): Float { + val dm: DisplayMetrics = mContext.getResources().getDisplayMetrics() + return TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dp, dm).toInt() + .toFloat() + } + + private fun getRatioValue( + firstValue: Float, + lastValue: Float, + getY: Float, + getYMax: Float + ): Float { + val temp = -(firstValue - lastValue) * getY / getYMax + return firstValue + temp + } +} \ No newline at end of file diff --git a/app/src/main/kotlin/bums/lunatic/launcher/home/LauncherHome.kt b/app/src/main/kotlin/bums/lunatic/launcher/home/LauncherHome.kt index e71ad3b3..80c087a3 100644 --- a/app/src/main/kotlin/bums/lunatic/launcher/home/LauncherHome.kt +++ b/app/src/main/kotlin/bums/lunatic/launcher/home/LauncherHome.kt @@ -521,12 +521,15 @@ internal class LauncherHome : Fragment() { mRssDataResult?.asFlow()?.collect { changes: ResultsChange -> commandHandler.removeCallbacks(hideListView) commandHandler.removeCallbacks(infoUpdate) + BLog.LOGE("enableSwipeToDeleteAndUndo in changes") when (changes) { is InitialResults,is UpdatedResults -> { WorkersDb.getRealm().apply { lasted = copyFromRealm(changes.list) + BLog.LOGE("enableSwipeToDeleteAndUndo in new querys") } commandHandler.postDelayed(infoUpdate, UPDATE_DELAY) + BLog.LOGE("enableSwipeToDeleteAndUndo postDelayed") } else -> { } @@ -557,7 +560,7 @@ internal class LauncherHome : Fragment() { fun queryInfos(keyword : String, category : ArrayList = arrayListOf(), noLimit : Boolean = false) { beforeQuery() - var rQ = WorkersDb.getRealm().query().query("read < $0", nomoreShowCount) + var rQ = WorkersDb.getRealm().query() if (!noLimit)rQ.query("pubDate > $0", beforeDay(Date(),3)) if(keyword.length > 0) { // BLog.LOGE("queryInfos it >>> ${keyword}") @@ -593,6 +596,9 @@ internal class LauncherHome : Fragment() { rQ = rQ.query(queryString) } + if(keyword.length == 0 && category.size == 0){ + rQ = rQ.query("read < $0", 3).query("vote != $0", true) + } updateQuery(rQ) rssStateVote = false } @@ -851,13 +857,16 @@ internal class LauncherHome : Fragment() { (viewHolder.itemView.getTag() as? RssData)?.let { rss -> WorkersDb.getRealm().apply { writeBlocking { + BLog.LOGE("enableSwipeToDeleteAndUndo in ") if (rssStateVote && rss.vote) { rss.vote = false rss.read = 0 } else { rss.read += nomoreShowCount } + BLog.LOGE("enableSwipeToDeleteAndUndo in before updated ${rss.read}") copyToRealm(rss, UpdatePolicy.ALL) + BLog.LOGE("enableSwipeToDeleteAndUndo in updated") } } } diff --git a/app/src/main/kotlin/bums/lunatic/launcher/home/adapters/RssItemAdapter.kt b/app/src/main/kotlin/bums/lunatic/launcher/home/adapters/RssItemAdapter.kt index e22a6ae6..0f790d88 100644 --- a/app/src/main/kotlin/bums/lunatic/launcher/home/adapters/RssItemAdapter.kt +++ b/app/src/main/kotlin/bums/lunatic/launcher/home/adapters/RssItemAdapter.kt @@ -38,7 +38,6 @@ import bums.lunatic.launcher.openNews import bums.lunatic.launcher.openOpera import bums.lunatic.launcher.openReddit import bums.lunatic.launcher.openYouTube -import bums.lunatic.launcher.utils.BLog import bums.lunatic.launcher.workers.WorkersDb import com.google.android.material.imageview.ShapeableImageView import com.squareup.picasso.Picasso @@ -48,7 +47,7 @@ import java.util.Date internal class RssItemAdapter ( - private val context: Context) : RecyclerView.Adapter() { + private val context: Context) : RecyclerView.Adapter() { companion object { @SuppressLint("SimpleDateFormat") val dateFormat = SimpleDateFormat("a HH:mm / yy - MM - dd") @@ -86,7 +85,7 @@ internal class RssItemAdapter ( } } } - private var rssDataItemLis: ArrayList = arrayListOf() + private var rssDataItemLis: ArrayList = arrayListOf() val mLongClickListener = View.OnLongClickListener { v -> (v?.tag as? RssData)?.let { rss -> WorkersDb.getRealm().apply { @@ -103,9 +102,9 @@ internal class RssItemAdapter ( - override fun onCreateViewHolder(viewGroup: ViewGroup, i: Int): RssTag { + override fun onCreateViewHolder(viewGroup: ViewGroup, i: Int): RssHolder { val binding = ListItemWithBinding.inflate(LayoutInflater.from(viewGroup.context), viewGroup, false) - return RssTag(binding) + return RssHolder(binding) } override fun getItemCount(): Int { @@ -115,7 +114,7 @@ internal class RssItemAdapter ( @SuppressLint("SetTextI18n") - override fun onBindViewHolder(holder: RssTag, position: Int) { + override fun onBindViewHolder(holder: RssHolder, position: Int) { val rssData = rssDataItemLis[position] if (rssData.pubDate() > 1000L) { holder.view.date.text = dateFormat.format(Date(rssData.pubDate())) @@ -123,7 +122,7 @@ internal class RssItemAdapter ( holder.view.date.text = emptyDate } - holder.view.title.text = rssData.title() + holder.view.title.text = "".plus(if(rssData.vote) " * " else "").plus(rssData.title().plus("[R:${rssData.read}]")) holder.view.desc.text = rssData.description() var param = holder.view.circlePreview.layoutParams @@ -156,7 +155,7 @@ internal class RssItemAdapter ( this.recyclerView = recyclerView } - fun updateData(newList: List) { + fun updateData(newList: List) { try { DiffUtil.calculateDiff(RssItemDiffUtil(rssDataItemLis, newList)).apply { @@ -177,7 +176,7 @@ internal class RssItemAdapter ( } } -internal class RssTag(var view: ListItemWithBinding) : RecyclerView.ViewHolder(view.root) {} +internal class RssHolder(var view: ListItemWithBinding) : RecyclerView.ViewHolder(view.root) {} internal class RssItemDiffUtil( var oldList: List, var newList: List ) : DiffUtil.Callback() { diff --git a/app/src/main/kotlin/bums/lunatic/launcher/model/RssDataInterface.kt b/app/src/main/kotlin/bums/lunatic/launcher/model/RssDataInterface.kt index e010dbef..ab74a9c3 100644 --- a/app/src/main/kotlin/bums/lunatic/launcher/model/RssDataInterface.kt +++ b/app/src/main/kotlin/bums/lunatic/launcher/model/RssDataInterface.kt @@ -59,5 +59,4 @@ interface RssDataInterface { fun pubDate() : Long fun category() : RssDataType fun getCho() : String? - } \ No newline at end of file diff --git a/app/src/main/res/layout/behavior.xml b/app/src/main/res/layout/behavior.xml index b7e818b5..76b462a9 100644 --- a/app/src/main/res/layout/behavior.xml +++ b/app/src/main/res/layout/behavior.xml @@ -62,18 +62,21 @@ - + + + \ No newline at end of file