mirror of
https://github.com/SimpleMobileTools/Simple-App-Launcher.git
synced 2025-02-01 09:56:47 +01:00
display checks at selected items
This commit is contained in:
parent
bb409e6080
commit
2ca2cec35b
@ -24,7 +24,7 @@ class MainActivity : SimpleActivity() {
|
||||
setContentView(R.layout.activity_main)
|
||||
dbHelper = DbHelper(applicationContext)
|
||||
launchers = dbHelper.getLaunchers()
|
||||
launchers_holder.adapter = RecyclerAdapter(applicationContext, launchers) {
|
||||
launchers_holder.adapter = RecyclerAdapter(applicationContext, false, launchers) {
|
||||
val launchIntent = packageManager.getLaunchIntentForPackage(it.pkgName)
|
||||
if (launchIntent != null) {
|
||||
startActivity(launchIntent)
|
||||
|
@ -6,15 +6,18 @@ import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import com.simplemobiletools.applauncher.R
|
||||
import com.simplemobiletools.applauncher.extensions.hide
|
||||
import com.simplemobiletools.applauncher.extensions.isVisible
|
||||
import com.simplemobiletools.applauncher.extensions.show
|
||||
import com.simplemobiletools.applauncher.models.AppLauncher
|
||||
import kotlinx.android.synthetic.main.app_launcher_dialog_item.view.*
|
||||
|
||||
|
||||
class RecyclerAdapter(val cxt: Context, val launchers: List<AppLauncher>, val itemClick: (AppLauncher) -> Unit) :
|
||||
class RecyclerAdapter(val cxt: Context, val displayChecks: Boolean, val launchers: List<AppLauncher>, val itemClick: (AppLauncher) -> Unit) :
|
||||
RecyclerView.Adapter<RecyclerAdapter.ViewHolder>() {
|
||||
|
||||
override fun onBindViewHolder(holder: ViewHolder, position: Int) {
|
||||
holder.bindView(cxt, launchers[position])
|
||||
holder.bindView(cxt, displayChecks, launchers[position])
|
||||
}
|
||||
|
||||
override fun onCreateViewHolder(parent: ViewGroup?, viewType: Int): ViewHolder {
|
||||
@ -26,11 +29,16 @@ class RecyclerAdapter(val cxt: Context, val launchers: List<AppLauncher>, val it
|
||||
return launchers.count()
|
||||
}
|
||||
|
||||
class ViewHolder(view: View, val itemClick: (AppLauncher) -> Unit) : RecyclerView.ViewHolder(view) {
|
||||
fun bindView(context: Context, launcher: AppLauncher) {
|
||||
class ViewHolder(view: View, val itemClick: (AppLauncher) -> (Unit)) : RecyclerView.ViewHolder(view) {
|
||||
fun bindView(context: Context, displayChecks: Boolean, launcher: AppLauncher) {
|
||||
with(launcher) {
|
||||
itemView.launcher_label.text = launcher.name
|
||||
itemView.setOnClickListener { itemClick(this) }
|
||||
itemView.setOnClickListener {
|
||||
itemClick(this)
|
||||
|
||||
if (displayChecks)
|
||||
handleCheck(itemView.launcher_check)
|
||||
}
|
||||
|
||||
if (launcher.iconId != 0) {
|
||||
val icon = context.resources.getDrawable(launcher.iconId)
|
||||
@ -41,5 +49,12 @@ class RecyclerAdapter(val cxt: Context, val launchers: List<AppLauncher>, val it
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun handleCheck(check: View) {
|
||||
if (check.isVisible)
|
||||
check.hide()
|
||||
else
|
||||
check.show()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -46,7 +46,7 @@ class AddAppDialog() : DialogFragment() {
|
||||
|
||||
val sorted = apps.sortedWith(compareBy { it.name.toLowerCase() })
|
||||
val unique = sorted.distinctBy { it.pkgName }
|
||||
recyclerView.launchers_holder.adapter = RecyclerAdapter(activity, unique) {
|
||||
recyclerView.launchers_holder.adapter = RecyclerAdapter(activity, true, unique) {
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,13 @@
|
||||
package com.simplemobiletools.applauncher.extensions
|
||||
|
||||
import android.view.View
|
||||
|
||||
val View.isVisible: Boolean get() = visibility == View.VISIBLE
|
||||
|
||||
fun View.hide() {
|
||||
visibility = View.GONE
|
||||
}
|
||||
|
||||
fun View.show() {
|
||||
visibility = View.VISIBLE
|
||||
}
|
@ -25,6 +25,7 @@
|
||||
android:textSize="@dimen/font_size_smaller"/>
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/launcher_check"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:gravity="top|right"
|
||||
|
Loading…
x
Reference in New Issue
Block a user