mirror of
https://github.com/SimpleMobileTools/Simple-Launcher.git
synced 2025-01-27 06:05:00 +01:00
refresh launchers after refetching instead of recreating
This commit is contained in:
parent
cc808d3970
commit
898d74c828
@ -18,11 +18,12 @@ import com.simplemobiletools.launcher.activities.SimpleActivity
|
||||
import com.simplemobiletools.launcher.extensions.getColumnCount
|
||||
import com.simplemobiletools.launcher.interfaces.AllAppsListener
|
||||
import com.simplemobiletools.launcher.models.AppLauncher
|
||||
import com.simplemobiletools.launcher.models.HomeScreenGridItem
|
||||
import kotlinx.android.synthetic.main.item_launcher_label.view.*
|
||||
|
||||
class LaunchersAdapter(
|
||||
val activity: SimpleActivity,
|
||||
val launchers: ArrayList<AppLauncher>,
|
||||
var launchers: ArrayList<AppLauncher>,
|
||||
val fastScroller: RecyclerViewFastScroller,
|
||||
val allAppsListener: AllAppsListener,
|
||||
val itemClick: (Any) -> Unit
|
||||
@ -58,6 +59,13 @@ class LaunchersAdapter(
|
||||
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) {
|
||||
fun bindView(launcher: AppLauncher): View {
|
||||
itemView.apply {
|
||||
|
@ -113,10 +113,15 @@ class AllAppsFragment(context: Context, attributeSet: AttributeSet) : MyFragment
|
||||
val layoutManager = all_apps_grid.layoutManager as MyGridLayoutManager
|
||||
layoutManager.spanCount = context.getColumnCount()
|
||||
|
||||
LaunchersAdapter(activity!!, launchers, all_apps_fastscroller, this) {
|
||||
activity?.launchApp((it as AppLauncher).packageName)
|
||||
}.apply {
|
||||
all_apps_grid.adapter = this
|
||||
val currAdapter = all_apps_grid.adapter
|
||||
if (currAdapter == null) {
|
||||
LaunchersAdapter(activity!!, launchers, all_apps_fastscroller, this) {
|
||||
activity?.launchApp((it as AppLauncher).packageName)
|
||||
}.apply {
|
||||
all_apps_grid.adapter = this
|
||||
}
|
||||
} else {
|
||||
(currAdapter as LaunchersAdapter).updateItems(launchers)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user