make sure always the right items are checked

This commit is contained in:
tibbi 2016-08-14 17:32:22 +02:00
parent 2c14e0b5dc
commit 8c6062180f
3 changed files with 15 additions and 12 deletions

View File

@ -7,7 +7,6 @@ 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.*
@ -35,10 +34,13 @@ class RecyclerAdapter(val cxt: Context, val displayChecks: Boolean, val launcher
itemView.setOnClickListener {
itemClick(this)
if (displayChecks)
handleCheck(itemView.launcher_check)
if (displayChecks) {
launcher.isChecked = !launcher.isChecked
handleCheck(itemView.launcher_check, launcher)
}
}
handleCheck(itemView.launcher_check, launcher)
if (launcher.iconId != 0) {
val icon = context.resources.getDrawable(launcher.iconId)
itemView.launcher_icon.setImageDrawable(icon)
@ -49,11 +51,12 @@ class RecyclerAdapter(val cxt: Context, val displayChecks: Boolean, val launcher
}
}
fun handleCheck(check: View) {
if (check.isVisible)
check.hide()
else
fun handleCheck(check: View, launcher: AppLauncher) {
if (launcher.isChecked) {
check.show()
} else {
check.hide()
}
}
}
}

View File

@ -1,6 +1,6 @@
package com.simplemobiletools.applauncher.models
data class AppLauncher(val name: String, val pkgName: String, val iconId: Int) {
data class AppLauncher(val name: String, val pkgName: String, val iconId: Int, var isChecked: Boolean = false) {
override fun equals(other: Any?): Boolean {
return pkgName.equals((other as AppLauncher).pkgName)
}

View File

@ -26,11 +26,11 @@
<ImageView
android:id="@+id/launcher_check"
android:layout_width="match_parent"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="top|right"
android:scaleType="fitEnd"
android:src="@mipmap/check"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:background="@mipmap/check"
android:visibility="invisible"/>
</RelativeLayout>