list hidden icons at the proper activity

This commit is contained in:
tibbi 2022-10-26 10:03:09 +02:00
parent 645dee47bc
commit 63bd57bd96
5 changed files with 136 additions and 1 deletions

View File

@ -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<HiddenIcon>
HiddenIconsAdapter(this, hiddenIcons) {
}.apply {
manage_hidden_icons_list.adapter = this
}
}
}
}

View File

@ -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<HiddenIcon>,
val itemClick: (Any) -> Unit
) : RecyclerView.Adapter<HiddenIconsAdapter.ViewHolder>() {
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
}
}
}

View File

@ -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)
}

View File

@ -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" />
<com.simplemobiletools.commons.views.MyTextView
android:id="@+id/manage_hidden_icons_placeholder"

View File

@ -0,0 +1,30 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/hidden_icon_holder"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="?attr/selectableItemBackground"
android:clickable="true"
android:focusable="true"
android:paddingStart="@dimen/small_margin"
android:paddingTop="@dimen/medium_margin"
android:paddingEnd="@dimen/small_margin"
android:paddingBottom="@dimen/small_margin">
<com.simplemobiletools.commons.views.MySquareImageView
android:id="@+id/hidden_icon"
android:layout_width="match_parent"
android:layout_height="@dimen/launcher_icon_size"
android:layout_gravity="center_horizontal|bottom" />
<TextView
android:id="@+id/hidden_icon_label"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/hidden_icon"
android:ellipsize="end"
android:gravity="center_horizontal|top"
android:maxLines="2"
android:textSize="@dimen/smaller_text_size" />
</RelativeLayout>