refresh launchers after refetching instead of recreating

This commit is contained in:
tibbi 2022-09-19 12:14:03 +02:00
parent cc808d3970
commit 898d74c828
2 changed files with 18 additions and 5 deletions

View File

@ -18,11 +18,12 @@ import com.simplemobiletools.launcher.activities.SimpleActivity
import com.simplemobiletools.launcher.extensions.getColumnCount import com.simplemobiletools.launcher.extensions.getColumnCount
import com.simplemobiletools.launcher.interfaces.AllAppsListener import com.simplemobiletools.launcher.interfaces.AllAppsListener
import com.simplemobiletools.launcher.models.AppLauncher import com.simplemobiletools.launcher.models.AppLauncher
import com.simplemobiletools.launcher.models.HomeScreenGridItem
import kotlinx.android.synthetic.main.item_launcher_label.view.* import kotlinx.android.synthetic.main.item_launcher_label.view.*
class LaunchersAdapter( class LaunchersAdapter(
val activity: SimpleActivity, val activity: SimpleActivity,
val launchers: ArrayList<AppLauncher>, var launchers: ArrayList<AppLauncher>,
val fastScroller: RecyclerViewFastScroller, val fastScroller: RecyclerViewFastScroller,
val allAppsListener: AllAppsListener, val allAppsListener: AllAppsListener,
val itemClick: (Any) -> Unit val itemClick: (Any) -> Unit
@ -58,6 +59,13 @@ class LaunchersAdapter(
iconPadding = (iconWidth * 0.1f).toInt() iconPadding = (iconWidth * 0.1f).toInt()
} }
fun updateItems(newItems: ArrayList<AppLauncher>) {
if (newItems.hashCode() != launchers.hashCode()) {
launchers = newItems
notifyDataSetChanged()
}
}
inner class ViewHolder(view: View) : RecyclerView.ViewHolder(view) { inner class ViewHolder(view: View) : RecyclerView.ViewHolder(view) {
fun bindView(launcher: AppLauncher): View { fun bindView(launcher: AppLauncher): View {
itemView.apply { itemView.apply {

View File

@ -113,10 +113,15 @@ class AllAppsFragment(context: Context, attributeSet: AttributeSet) : MyFragment
val layoutManager = all_apps_grid.layoutManager as MyGridLayoutManager val layoutManager = all_apps_grid.layoutManager as MyGridLayoutManager
layoutManager.spanCount = context.getColumnCount() layoutManager.spanCount = context.getColumnCount()
LaunchersAdapter(activity!!, launchers, all_apps_fastscroller, this) { val currAdapter = all_apps_grid.adapter
activity?.launchApp((it as AppLauncher).packageName) if (currAdapter == null) {
}.apply { LaunchersAdapter(activity!!, launchers, all_apps_fastscroller, this) {
all_apps_grid.adapter = this activity?.launchApp((it as AppLauncher).packageName)
}.apply {
all_apps_grid.adapter = this
}
} else {
(currAdapter as LaunchersAdapter).updateItems(launchers)
} }
} }
} }