From 9483a09220ab8ac0b69b182615c6c0a853e2e904 Mon Sep 17 00:00:00 2001 From: Narinder Rana Date: Tue, 17 May 2022 16:41:24 +0530 Subject: [PATCH 1/6] search list smoothScrollToPosition 0 for show update result --- .../e/apps/search/SearchFragment.kt | 20 ++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/foundation/e/apps/search/SearchFragment.kt b/app/src/main/java/foundation/e/apps/search/SearchFragment.kt index 3791b0db0..a7a96e414 100644 --- a/app/src/main/java/foundation/e/apps/search/SearchFragment.kt +++ b/app/src/main/java/foundation/e/apps/search/SearchFragment.kt @@ -22,6 +22,7 @@ import android.app.Activity import android.database.MatrixCursor import android.os.Bundle import android.provider.BaseColumns +import android.util.Log import android.view.View import android.view.inputmethod.InputMethodManager import android.widget.ImageView @@ -39,11 +40,7 @@ import androidx.recyclerview.widget.RecyclerView import com.aurora.gplayapi.SearchSuggestEntry import com.facebook.shimmer.ShimmerFrameLayout import dagger.hilt.android.AndroidEntryPoint -import foundation.e.apps.AppInfoFetchViewModel -import foundation.e.apps.AppProgressViewModel -import foundation.e.apps.MainActivityViewModel -import foundation.e.apps.PrivacyInfoViewModel -import foundation.e.apps.R +import foundation.e.apps.* import foundation.e.apps.api.fused.FusedAPIInterface import foundation.e.apps.api.fused.data.FusedApp import foundation.e.apps.application.subFrags.ApplicationDialogFragment @@ -172,6 +169,7 @@ class SearchFragment : } mainActivityViewModel.downloadList.observe(viewLifecycleOwner) { list -> + val searchList = searchViewModel.searchResult.value?.toMutableList() searchList?.let { mainActivityViewModel.updateStatusOfFusedApps(searchList, list) @@ -180,17 +178,26 @@ class SearchFragment : } searchViewModel.searchResult.observe(viewLifecycleOwner) { + + Log.e("TAG", "........................................16") if (it.isNullOrEmpty()) { noAppsFoundLayout?.visibility = View.VISIBLE } else { + listAdapter?.setData(it) shimmerLayout?.visibility = View.GONE recyclerView?.visibility = View.VISIBLE noAppsFoundLayout?.visibility = View.GONE + + + } + recyclerView!!.post { // Call smooth scroll + recyclerView!!.smoothScrollToPosition(0) } } } + override fun onResume() { super.onResume() binding.shimmerLayout.startShimmer() @@ -202,6 +209,7 @@ class SearchFragment : } override fun onQueryTextSubmit(query: String?): Boolean { + query?.let { text -> hideKeyboard(activity as Activity) view?.requestFocus() @@ -228,7 +236,9 @@ class SearchFragment : } override fun onSuggestionClick(position: Int): Boolean { + searchViewModel.searchSuggest.value?.let { + searchView?.setQuery(it[position].suggestedQuery, true) } return true -- GitLab From ed4334d4ff48f57933e7ab37e375798bfbfb5b57 Mon Sep 17 00:00:00 2001 From: Narinder Rana Date: Tue, 17 May 2022 16:52:08 +0530 Subject: [PATCH 2/6] update recyclerview.post to postDelayed for bind recyclerview --- app/src/main/java/foundation/e/apps/search/SearchFragment.kt | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/app/src/main/java/foundation/e/apps/search/SearchFragment.kt b/app/src/main/java/foundation/e/apps/search/SearchFragment.kt index a7a96e414..01f6a4a27 100644 --- a/app/src/main/java/foundation/e/apps/search/SearchFragment.kt +++ b/app/src/main/java/foundation/e/apps/search/SearchFragment.kt @@ -191,9 +191,7 @@ class SearchFragment : } - recyclerView!!.post { // Call smooth scroll - recyclerView!!.smoothScrollToPosition(0) - } + recyclerView!!.postDelayed(Runnable { kotlin.run { recyclerView!!.scrollToPosition(0) } }, 1000) } } -- GitLab From a8c80f4dad23918f50d7e6d2a6a07d6e69a583a8 Mon Sep 17 00:00:00 2001 From: Narinder Rana Date: Tue, 17 May 2022 17:16:50 +0530 Subject: [PATCH 3/6] gradlew lintRelease and refine code --- app/src/main/java/foundation/e/apps/search/SearchFragment.kt | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/app/src/main/java/foundation/e/apps/search/SearchFragment.kt b/app/src/main/java/foundation/e/apps/search/SearchFragment.kt index 01f6a4a27..1bd03173f 100644 --- a/app/src/main/java/foundation/e/apps/search/SearchFragment.kt +++ b/app/src/main/java/foundation/e/apps/search/SearchFragment.kt @@ -179,7 +179,7 @@ class SearchFragment : searchViewModel.searchResult.observe(viewLifecycleOwner) { - Log.e("TAG", "........................................16") + if (it.isNullOrEmpty()) { noAppsFoundLayout?.visibility = View.VISIBLE } else { @@ -188,14 +188,11 @@ class SearchFragment : shimmerLayout?.visibility = View.GONE recyclerView?.visibility = View.VISIBLE noAppsFoundLayout?.visibility = View.GONE - - } recyclerView!!.postDelayed(Runnable { kotlin.run { recyclerView!!.scrollToPosition(0) } }, 1000) } } - override fun onResume() { super.onResume() binding.shimmerLayout.startShimmer() -- GitLab From e50bf24ca79b7c8315616c5a999ca3abb7d0712f Mon Sep 17 00:00:00 2001 From: Narinder Rana Date: Tue, 17 May 2022 19:41:09 +0530 Subject: [PATCH 4/6] update import classes and refine code --- .../main/java/foundation/e/apps/search/SearchFragment.kt | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/foundation/e/apps/search/SearchFragment.kt b/app/src/main/java/foundation/e/apps/search/SearchFragment.kt index 1bd03173f..8e6b11d37 100644 --- a/app/src/main/java/foundation/e/apps/search/SearchFragment.kt +++ b/app/src/main/java/foundation/e/apps/search/SearchFragment.kt @@ -40,7 +40,11 @@ import androidx.recyclerview.widget.RecyclerView import com.aurora.gplayapi.SearchSuggestEntry import com.facebook.shimmer.ShimmerFrameLayout import dagger.hilt.android.AndroidEntryPoint -import foundation.e.apps.* +import foundation.e.apps.AppInfoFetchViewModel +import foundation.e.apps.AppProgressViewModel +import foundation.e.apps.MainActivityViewModel +import foundation.e.apps.PrivacyInfoViewModel +import foundation.e.apps.R import foundation.e.apps.api.fused.FusedAPIInterface import foundation.e.apps.api.fused.data.FusedApp import foundation.e.apps.application.subFrags.ApplicationDialogFragment -- GitLab From 340e49cac7551cf67f4850699cc217e1d27068c2 Mon Sep 17 00:00:00 2001 From: Narinder Rana Date: Wed, 18 May 2022 07:42:12 +0530 Subject: [PATCH 5/6] search recycler scrollToPosition after DataObserver --- .../main/java/foundation/e/apps/search/SearchFragment.kt | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/foundation/e/apps/search/SearchFragment.kt b/app/src/main/java/foundation/e/apps/search/SearchFragment.kt index 8e6b11d37..1be72bca7 100644 --- a/app/src/main/java/foundation/e/apps/search/SearchFragment.kt +++ b/app/src/main/java/foundation/e/apps/search/SearchFragment.kt @@ -193,7 +193,11 @@ class SearchFragment : recyclerView?.visibility = View.VISIBLE noAppsFoundLayout?.visibility = View.GONE } - recyclerView!!.postDelayed(Runnable { kotlin.run { recyclerView!!.scrollToPosition(0) } }, 1000) + listAdapter?.registerAdapterDataObserver(object: RecyclerView.AdapterDataObserver() { + override fun onItemRangeInserted(positionStart: Int, itemCount: Int) { + recyclerView!!.scrollToPosition(0) + } + }) } } -- GitLab From 2bc87c10544baef1d64dda595564838a14a3c1a5 Mon Sep 17 00:00:00 2001 From: Narinder Rana Date: Wed, 18 May 2022 07:53:49 +0530 Subject: [PATCH 6/6] code refine ktlintFormat --- app/src/main/java/foundation/e/apps/search/SearchFragment.kt | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/app/src/main/java/foundation/e/apps/search/SearchFragment.kt b/app/src/main/java/foundation/e/apps/search/SearchFragment.kt index 1be72bca7..7cf486ab4 100644 --- a/app/src/main/java/foundation/e/apps/search/SearchFragment.kt +++ b/app/src/main/java/foundation/e/apps/search/SearchFragment.kt @@ -22,7 +22,6 @@ import android.app.Activity import android.database.MatrixCursor import android.os.Bundle import android.provider.BaseColumns -import android.util.Log import android.view.View import android.view.inputmethod.InputMethodManager import android.widget.ImageView @@ -183,7 +182,6 @@ class SearchFragment : searchViewModel.searchResult.observe(viewLifecycleOwner) { - if (it.isNullOrEmpty()) { noAppsFoundLayout?.visibility = View.VISIBLE } else { @@ -193,7 +191,7 @@ class SearchFragment : recyclerView?.visibility = View.VISIBLE noAppsFoundLayout?.visibility = View.GONE } - listAdapter?.registerAdapterDataObserver(object: RecyclerView.AdapterDataObserver() { + listAdapter?.registerAdapterDataObserver(object : RecyclerView.AdapterDataObserver() { override fun onItemRangeInserted(positionStart: Int, itemCount: Int) { recyclerView!!.scrollToPosition(0) } -- GitLab