From 63bd57bd966bbff1968ec0270f500f7b9c20ba5c Mon Sep 17 00:00:00 2001 From: tibbi Date: Wed, 26 Oct 2022 10:03:09 +0200 Subject: [PATCH] list hidden icons at the proper activity --- .../activities/HiddenIconsActivity.kt | 21 +++++ .../launcher/adapters/HiddenIconsAdapter.kt | 81 +++++++++++++++++++ .../launcher/interfaces/AppLaunchersDao.kt | 3 + .../main/res/layout/activity_hidden_icons.xml | 2 +- app/src/main/res/layout/item_hidden_icon.xml | 30 +++++++ 5 files changed, 136 insertions(+), 1 deletion(-) create mode 100644 app/src/main/kotlin/com/simplemobiletools/launcher/adapters/HiddenIconsAdapter.kt create mode 100644 app/src/main/res/layout/item_hidden_icon.xml diff --git a/app/src/main/kotlin/com/simplemobiletools/launcher/activities/HiddenIconsActivity.kt b/app/src/main/kotlin/com/simplemobiletools/launcher/activities/HiddenIconsActivity.kt index 40938ff..7652433 100644 --- a/app/src/main/kotlin/com/simplemobiletools/launcher/activities/HiddenIconsActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/launcher/activities/HiddenIconsActivity.kt @@ -2,17 +2,38 @@ package com.simplemobiletools.launcher.activities import android.os.Bundle import com.simplemobiletools.commons.helpers.NavigationIcon +import com.simplemobiletools.commons.helpers.ensureBackgroundThread +import com.simplemobiletools.commons.views.MyGridLayoutManager import com.simplemobiletools.launcher.R +import com.simplemobiletools.launcher.adapters.HiddenIconsAdapter +import com.simplemobiletools.launcher.extensions.getColumnCount +import com.simplemobiletools.launcher.extensions.hiddenIconsDB +import com.simplemobiletools.launcher.models.HiddenIcon import kotlinx.android.synthetic.main.activity_hidden_icons.* class HiddenIconsActivity : SimpleActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_hidden_icons) + updateIcons() + + val layoutManager = manage_hidden_icons_list.layoutManager as MyGridLayoutManager + layoutManager.spanCount = getColumnCount() } override fun onResume() { super.onResume() setupToolbar(manage_hidden_icons_toolbar, NavigationIcon.Arrow) } + + private fun updateIcons() { + ensureBackgroundThread { + val hiddenIcons = hiddenIconsDB.getHiddenIcons().toMutableList() as ArrayList + HiddenIconsAdapter(this, hiddenIcons) { + + }.apply { + manage_hidden_icons_list.adapter = this + } + } + } } diff --git a/app/src/main/kotlin/com/simplemobiletools/launcher/adapters/HiddenIconsAdapter.kt b/app/src/main/kotlin/com/simplemobiletools/launcher/adapters/HiddenIconsAdapter.kt new file mode 100644 index 0000000..72c140a --- /dev/null +++ b/app/src/main/kotlin/com/simplemobiletools/launcher/adapters/HiddenIconsAdapter.kt @@ -0,0 +1,81 @@ +package com.simplemobiletools.launcher.adapters + +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import androidx.recyclerview.widget.RecyclerView +import com.bumptech.glide.Glide +import com.bumptech.glide.load.engine.DiskCacheStrategy +import com.bumptech.glide.load.resource.drawable.DrawableTransitionOptions +import com.bumptech.glide.request.transition.DrawableCrossFadeFactory +import com.simplemobiletools.commons.extensions.getProperTextColor +import com.simplemobiletools.commons.extensions.portrait +import com.simplemobiletools.commons.extensions.realScreenSize +import com.simplemobiletools.commons.helpers.mydebug +import com.simplemobiletools.launcher.R +import com.simplemobiletools.launcher.activities.SimpleActivity +import com.simplemobiletools.launcher.models.HiddenIcon +import kotlinx.android.synthetic.main.item_hidden_icon.view.* + +class HiddenIconsAdapter( + val activity: SimpleActivity, + var hiddenIcons: ArrayList, + val itemClick: (Any) -> Unit +) : RecyclerView.Adapter() { + + private var textColor = activity.getProperTextColor() + private var iconPadding = 0 + + init { + calculateIconWidth() + } + + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder { + val view = LayoutInflater.from(parent.context).inflate(R.layout.item_hidden_icon, parent, false) + return ViewHolder(view) + } + + override fun onBindViewHolder(holder: ViewHolder, position: Int) { + holder.bindView(hiddenIcons[position]) + } + + override fun getItemCount() = hiddenIcons.size + + private fun calculateIconWidth() { + val currentColumnCount = activity.resources.getInteger( + if (activity.portrait) { + R.integer.portrait_column_count + } else { + R.integer.landscape_column_count + } + ) + + mydebug("size ${activity.realScreenSize.x}") + val iconWidth = activity.realScreenSize.x / currentColumnCount + iconPadding = (iconWidth * 0.1f).toInt() + } + + inner class ViewHolder(view: View) : RecyclerView.ViewHolder(view) { + fun bindView(icon: HiddenIcon): View { + itemView.apply { + hidden_icon_label.text = icon.title + hidden_icon_label.setTextColor(textColor) + hidden_icon.setPadding(iconPadding, iconPadding, iconPadding, 0) + + val factory = DrawableCrossFadeFactory.Builder(150).setCrossFadeEnabled(true).build() + + Glide.with(activity) + .load(icon.drawable) + .diskCacheStrategy(DiskCacheStrategy.RESOURCE) + .transition(DrawableTransitionOptions.withCrossFade(factory)) + .into(hidden_icon) + + setOnClickListener { + itemClick(icon) + } + } + + return itemView + } + } +} diff --git a/app/src/main/kotlin/com/simplemobiletools/launcher/interfaces/AppLaunchersDao.kt b/app/src/main/kotlin/com/simplemobiletools/launcher/interfaces/AppLaunchersDao.kt index d2b7b6c..333b266 100644 --- a/app/src/main/kotlin/com/simplemobiletools/launcher/interfaces/AppLaunchersDao.kt +++ b/app/src/main/kotlin/com/simplemobiletools/launcher/interfaces/AppLaunchersDao.kt @@ -16,4 +16,7 @@ interface AppLaunchersDao { @Query("DELETE FROM apps WHERE package_name = :packageName") fun deleteApp(packageName: String) + + @Query("DELETE FROM apps WHERE id = :id") + fun deleteById(id: Long) } diff --git a/app/src/main/res/layout/activity_hidden_icons.xml b/app/src/main/res/layout/activity_hidden_icons.xml index bc049ce..ce0ee54 100644 --- a/app/src/main/res/layout/activity_hidden_icons.xml +++ b/app/src/main/res/layout/activity_hidden_icons.xml @@ -32,7 +32,7 @@ android:layout_height="match_parent" android:clipToPadding="false" android:scrollbars="vertical" - app:layoutManager="com.simplemobiletools.commons.views.MyLinearLayoutManager" /> + app:layoutManager="com.simplemobiletools.commons.views.MyGridLayoutManager" /> + + + + + + +