diff --git a/app/build.gradle b/app/build.gradle index 6dced41..71c173a 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -39,7 +39,7 @@ android { } dependencies { - compile 'com.simplemobiletools:commons:2.38.6' + compile 'com.simplemobiletools:commons:2.38.8' compile 'com.android.support:multidex:1.0.2' compile 'com.bignerdranch.android:recyclerview-multiselect:0.2' compile 'com.facebook.stetho:stetho:1.5.0' diff --git a/app/src/main/kotlin/com/simplemobiletools/applauncher/adapters/RecyclerAdapter.kt b/app/src/main/kotlin/com/simplemobiletools/applauncher/adapters/RecyclerAdapter.kt index 8358d2d..a2d4a95 100644 --- a/app/src/main/kotlin/com/simplemobiletools/applauncher/adapters/RecyclerAdapter.kt +++ b/app/src/main/kotlin/com/simplemobiletools/applauncher/adapters/RecyclerAdapter.kt @@ -2,7 +2,7 @@ package com.simplemobiletools.applauncher.adapters import android.app.AlertDialog import android.content.pm.PackageManager -import android.graphics.PorterDuff +import android.content.res.Resources import android.support.v7.view.ActionMode import android.support.v7.widget.RecyclerView import android.util.SparseArray @@ -15,9 +15,11 @@ import com.simplemobiletools.applauncher.activities.SimpleActivity import com.simplemobiletools.applauncher.extensions.config import com.simplemobiletools.applauncher.extensions.dbHelper import com.simplemobiletools.applauncher.models.AppLauncher +import com.simplemobiletools.commons.extensions.applyColorFilter import com.simplemobiletools.commons.extensions.beGone import com.simplemobiletools.commons.extensions.beVisibleIf import com.simplemobiletools.commons.extensions.toast +import com.simplemobiletools.commons.interfaces.MyAdapterListener import kotlinx.android.synthetic.main.app_launcher_item.view.* import kotlinx.android.synthetic.main.dialog_edit_launcher.view.* import java.util.* @@ -26,18 +28,20 @@ class RecyclerAdapter(val activity: SimpleActivity, val launchers: List() { private val config = activity.config - var actMode: ActionMode? = null - var primaryColor = config.primaryColor + private var actMode: ActionMode? = null + private var primaryColor = config.primaryColor private val multiSelector = MultiSelector() private var itemViews = SparseArray() private val selectedPositions = HashSet() private var textColor = config.textColor + private var resources = activity.resources + private var packageManager = activity.packageManager fun toggleItemSelection(select: Boolean, pos: Int) { if (select) { if (itemViews[pos] != null) { - itemViews[pos].launcher_check?.background?.setColorFilter(primaryColor, PorterDuff.Mode.SRC_IN) + itemViews[pos].launcher_check?.background?.applyColorFilter(primaryColor) selectedPositions.add(pos) } } else { @@ -100,7 +104,7 @@ class RecyclerAdapter(val activity: SimpleActivity, val launchers: List(positions.size) @@ -153,11 +153,13 @@ class RecyclerAdapter(val activity: SimpleActivity, val launchers: List (Unit)) : SwappingHolder(view, MultiSelector()) { - fun bindView(launcher: AppLauncher, textColor: Int): View { + fun bindView(launcher: AppLauncher, textColor: Int, resources: Resources, packageManager: PackageManager): View { itemView.apply { launcher_label.text = launcher.name launcher_label.setTextColor(textColor) @@ -180,13 +182,12 @@ class RecyclerAdapter(val activity: SimpleActivity, val launchers: List - } - interface AppLaunchersListener { fun refreshLaunchers() } diff --git a/app/src/main/kotlin/com/simplemobiletools/applauncher/adapters/RecyclerDialogAdapter.kt b/app/src/main/kotlin/com/simplemobiletools/applauncher/adapters/RecyclerDialogAdapter.kt index aedda43..b889780 100644 --- a/app/src/main/kotlin/com/simplemobiletools/applauncher/adapters/RecyclerDialogAdapter.kt +++ b/app/src/main/kotlin/com/simplemobiletools/applauncher/adapters/RecyclerDialogAdapter.kt @@ -1,50 +1,85 @@ package com.simplemobiletools.applauncher.adapters -import android.content.Context +import android.app.Activity +import android.content.pm.PackageManager +import android.content.res.Resources import android.support.v7.widget.RecyclerView +import android.util.SparseArray import android.view.LayoutInflater import android.view.View import android.view.ViewGroup import com.simplemobiletools.applauncher.R +import com.simplemobiletools.applauncher.extensions.config import com.simplemobiletools.applauncher.models.AppLauncher -import com.simplemobiletools.commons.extensions.beInvisibleIf +import com.simplemobiletools.commons.extensions.applyColorFilter +import com.simplemobiletools.commons.extensions.beVisibleIf +import com.simplemobiletools.commons.interfaces.MyAdapterListener import kotlinx.android.synthetic.main.app_launcher_item.view.* +import java.util.* -class RecyclerDialogAdapter(val cxt: Context, val launchers: List) : RecyclerView.Adapter() { +class RecyclerDialogAdapter(activity: Activity, val launchers: List) : RecyclerView.Adapter() { + private val config = activity.config + private var primaryColor = config.primaryColor + private var itemViews = SparseArray() + private val selectedPositions = HashSet() + private var textColor = config.textColor + private var resources = activity.resources + private var packageManager = activity.packageManager + + fun toggleItemSelection(select: Boolean, pos: Int) { + if (select) { + if (itemViews[pos] != null) { + itemViews[pos].launcher_check?.background?.applyColorFilter(primaryColor) + selectedPositions.add(pos) + } + } else { + selectedPositions.remove(pos) + } + + itemViews[pos]?.launcher_check?.beVisibleIf(select) + } + + private val adapterListener = object : MyAdapterListener { + override fun toggleItemSelectionAdapter(select: Boolean, position: Int) { + toggleItemSelection(select, position) + } + + override fun getSelectedPositions(): HashSet = selectedPositions + } override fun onBindViewHolder(holder: ViewHolder, position: Int) { - holder.bindView(cxt, launchers[position]) + itemViews.put(position, holder.bindView(launchers[position], textColor, resources, packageManager)) } override fun onCreateViewHolder(parent: ViewGroup?, viewType: Int): ViewHolder { val view = LayoutInflater.from(parent?.context).inflate(R.layout.app_launcher_item, parent, false) - return ViewHolder(view) + return ViewHolder(view, adapterListener) } override fun getItemCount() = launchers.count() - class ViewHolder(view: View) : RecyclerView.ViewHolder(view) { - fun bindView(context: Context, launcher: AppLauncher) { - with(launcher) { - itemView.launcher_label.text = launcher.name - itemView.setOnClickListener { - launcher.isChecked = !launcher.isChecked - handleCheck(itemView.launcher_check, launcher) - } + class ViewHolder(view: View, val adapterListener: MyAdapterListener) : RecyclerView.ViewHolder(view) { + fun bindView(launcher: AppLauncher, textColor: Int, resources: Resources, packageManager: PackageManager): View { + itemView.apply { + launcher_label.text = launcher.name + launcher_label.setTextColor(textColor) - handleCheck(itemView.launcher_check, launcher) - if (launcher.iconId != 0) { - val icon = context.resources.getDrawable(launcher.iconId) - itemView.launcher_icon.setImageDrawable(icon) + setOnClickListener { viewClicked() } + setOnLongClickListener { viewClicked(); true } + + val drawable = if (launcher.iconId != 0) { + resources.getDrawable(launcher.iconId) } else { - val icon = context.packageManager.getApplicationIcon(launcher.pkgName) - itemView.launcher_icon.setImageDrawable(icon) + packageManager.getApplicationIcon(launcher.pkgName) } + launcher_icon.setImageDrawable(drawable) } + return itemView } - fun handleCheck(check: View, launcher: AppLauncher) { - check.beInvisibleIf(!launcher.isChecked) + private fun viewClicked() { + val isSelected = adapterListener.getSelectedPositions().contains(adapterPosition) + adapterListener.toggleItemSelectionAdapter(!isSelected, adapterPosition) } } } diff --git a/app/src/main/kotlin/com/simplemobiletools/applauncher/helpers/DBHelper.kt b/app/src/main/kotlin/com/simplemobiletools/applauncher/helpers/DBHelper.kt index f441079..f3e15bb 100644 --- a/app/src/main/kotlin/com/simplemobiletools/applauncher/helpers/DBHelper.kt +++ b/app/src/main/kotlin/com/simplemobiletools/applauncher/helpers/DBHelper.kt @@ -72,15 +72,15 @@ class DBHelper private constructor(val context: Context) : SQLiteOpenHelper(cont ) val icons = arrayListOf( - R.drawable.ic_calculator, - R.drawable.ic_calendar, - R.drawable.ic_camera, - R.drawable.ic_draw, - R.drawable.ic_filemanager, - R.drawable.ic_flashlight, - R.drawable.ic_gallery, - R.drawable.ic_musicplayer, - R.drawable.ic_notes + R.drawable.ic_launcher_calculator, + R.drawable.ic_launcher_calendar, + R.drawable.ic_launcher_camera, + R.drawable.ic_launcher_draw, + R.drawable.ic_launcher_filemanager, + R.drawable.ic_launcher_flashlight, + R.drawable.ic_launcher_gallery, + R.drawable.ic_launcher_musicplayer, + R.drawable.ic_launcher_notes ) val cnt = titles.size diff --git a/app/src/main/kotlin/com/simplemobiletools/applauncher/models/AppLauncher.kt b/app/src/main/kotlin/com/simplemobiletools/applauncher/models/AppLauncher.kt index 87f72b1..465af21 100644 --- a/app/src/main/kotlin/com/simplemobiletools/applauncher/models/AppLauncher.kt +++ b/app/src/main/kotlin/com/simplemobiletools/applauncher/models/AppLauncher.kt @@ -1,6 +1,6 @@ package com.simplemobiletools.applauncher.models -data class AppLauncher(val id: Int, var name: String, val pkgName: String, val iconId: Int, var isChecked: Boolean = false) { +data class AppLauncher(val id: Int, var name: String, val pkgName: String, val iconId: Int) { override fun equals(other: Any?): Boolean { return pkgName.equals((other as AppLauncher).pkgName, true) } diff --git a/app/src/main/res/drawable-hdpi/ic_calculator.png b/app/src/main/res/drawable-hdpi/ic_launcher_calculator.png similarity index 100% rename from app/src/main/res/drawable-hdpi/ic_calculator.png rename to app/src/main/res/drawable-hdpi/ic_launcher_calculator.png diff --git a/app/src/main/res/drawable-hdpi/ic_calendar.png b/app/src/main/res/drawable-hdpi/ic_launcher_calendar.png similarity index 100% rename from app/src/main/res/drawable-hdpi/ic_calendar.png rename to app/src/main/res/drawable-hdpi/ic_launcher_calendar.png diff --git a/app/src/main/res/drawable-hdpi/ic_camera.png b/app/src/main/res/drawable-hdpi/ic_launcher_camera.png similarity index 100% rename from app/src/main/res/drawable-hdpi/ic_camera.png rename to app/src/main/res/drawable-hdpi/ic_launcher_camera.png diff --git a/app/src/main/res/drawable-hdpi/ic_draw.png b/app/src/main/res/drawable-hdpi/ic_launcher_draw.png similarity index 100% rename from app/src/main/res/drawable-hdpi/ic_draw.png rename to app/src/main/res/drawable-hdpi/ic_launcher_draw.png diff --git a/app/src/main/res/drawable-hdpi/ic_filemanager.png b/app/src/main/res/drawable-hdpi/ic_launcher_filemanager.png similarity index 100% rename from app/src/main/res/drawable-hdpi/ic_filemanager.png rename to app/src/main/res/drawable-hdpi/ic_launcher_filemanager.png diff --git a/app/src/main/res/drawable-hdpi/ic_flashlight.png b/app/src/main/res/drawable-hdpi/ic_launcher_flashlight.png similarity index 100% rename from app/src/main/res/drawable-hdpi/ic_flashlight.png rename to app/src/main/res/drawable-hdpi/ic_launcher_flashlight.png diff --git a/app/src/main/res/drawable-hdpi/ic_gallery.png b/app/src/main/res/drawable-hdpi/ic_launcher_gallery.png similarity index 100% rename from app/src/main/res/drawable-hdpi/ic_gallery.png rename to app/src/main/res/drawable-hdpi/ic_launcher_gallery.png diff --git a/app/src/main/res/drawable-hdpi/ic_musicplayer.png b/app/src/main/res/drawable-hdpi/ic_launcher_musicplayer.png similarity index 100% rename from app/src/main/res/drawable-hdpi/ic_musicplayer.png rename to app/src/main/res/drawable-hdpi/ic_launcher_musicplayer.png diff --git a/app/src/main/res/drawable-hdpi/ic_notes.png b/app/src/main/res/drawable-hdpi/ic_launcher_notes.png similarity index 100% rename from app/src/main/res/drawable-hdpi/ic_notes.png rename to app/src/main/res/drawable-hdpi/ic_launcher_notes.png diff --git a/app/src/main/res/drawable-xhdpi/ic_calculator.png b/app/src/main/res/drawable-xhdpi/ic_launcher_calculator.png similarity index 100% rename from app/src/main/res/drawable-xhdpi/ic_calculator.png rename to app/src/main/res/drawable-xhdpi/ic_launcher_calculator.png diff --git a/app/src/main/res/drawable-xhdpi/ic_calendar.png b/app/src/main/res/drawable-xhdpi/ic_launcher_calendar.png similarity index 100% rename from app/src/main/res/drawable-xhdpi/ic_calendar.png rename to app/src/main/res/drawable-xhdpi/ic_launcher_calendar.png diff --git a/app/src/main/res/drawable-xhdpi/ic_camera.png b/app/src/main/res/drawable-xhdpi/ic_launcher_camera.png similarity index 100% rename from app/src/main/res/drawable-xhdpi/ic_camera.png rename to app/src/main/res/drawable-xhdpi/ic_launcher_camera.png diff --git a/app/src/main/res/drawable-xhdpi/ic_draw.png b/app/src/main/res/drawable-xhdpi/ic_launcher_draw.png similarity index 100% rename from app/src/main/res/drawable-xhdpi/ic_draw.png rename to app/src/main/res/drawable-xhdpi/ic_launcher_draw.png diff --git a/app/src/main/res/drawable-xhdpi/ic_filemanager.png b/app/src/main/res/drawable-xhdpi/ic_launcher_filemanager.png similarity index 100% rename from app/src/main/res/drawable-xhdpi/ic_filemanager.png rename to app/src/main/res/drawable-xhdpi/ic_launcher_filemanager.png diff --git a/app/src/main/res/drawable-xhdpi/ic_flashlight.png b/app/src/main/res/drawable-xhdpi/ic_launcher_flashlight.png similarity index 100% rename from app/src/main/res/drawable-xhdpi/ic_flashlight.png rename to app/src/main/res/drawable-xhdpi/ic_launcher_flashlight.png diff --git a/app/src/main/res/drawable-xhdpi/ic_gallery.png b/app/src/main/res/drawable-xhdpi/ic_launcher_gallery.png similarity index 100% rename from app/src/main/res/drawable-xhdpi/ic_gallery.png rename to app/src/main/res/drawable-xhdpi/ic_launcher_gallery.png diff --git a/app/src/main/res/drawable-xhdpi/ic_musicplayer.png b/app/src/main/res/drawable-xhdpi/ic_launcher_musicplayer.png similarity index 100% rename from app/src/main/res/drawable-xhdpi/ic_musicplayer.png rename to app/src/main/res/drawable-xhdpi/ic_launcher_musicplayer.png diff --git a/app/src/main/res/drawable-xhdpi/ic_notes.png b/app/src/main/res/drawable-xhdpi/ic_launcher_notes.png similarity index 100% rename from app/src/main/res/drawable-xhdpi/ic_notes.png rename to app/src/main/res/drawable-xhdpi/ic_launcher_notes.png diff --git a/app/src/main/res/drawable-xxhdpi/ic_calculator.png b/app/src/main/res/drawable-xxhdpi/ic_launcher_calculator.png similarity index 100% rename from app/src/main/res/drawable-xxhdpi/ic_calculator.png rename to app/src/main/res/drawable-xxhdpi/ic_launcher_calculator.png diff --git a/app/src/main/res/drawable-xxhdpi/ic_calendar.png b/app/src/main/res/drawable-xxhdpi/ic_launcher_calendar.png similarity index 100% rename from app/src/main/res/drawable-xxhdpi/ic_calendar.png rename to app/src/main/res/drawable-xxhdpi/ic_launcher_calendar.png diff --git a/app/src/main/res/drawable-xxhdpi/ic_camera.png b/app/src/main/res/drawable-xxhdpi/ic_launcher_camera.png similarity index 100% rename from app/src/main/res/drawable-xxhdpi/ic_camera.png rename to app/src/main/res/drawable-xxhdpi/ic_launcher_camera.png diff --git a/app/src/main/res/drawable-xxhdpi/ic_draw.png b/app/src/main/res/drawable-xxhdpi/ic_launcher_draw.png similarity index 100% rename from app/src/main/res/drawable-xxhdpi/ic_draw.png rename to app/src/main/res/drawable-xxhdpi/ic_launcher_draw.png diff --git a/app/src/main/res/drawable-xxhdpi/ic_filemanager.png b/app/src/main/res/drawable-xxhdpi/ic_launcher_filemanager.png similarity index 100% rename from app/src/main/res/drawable-xxhdpi/ic_filemanager.png rename to app/src/main/res/drawable-xxhdpi/ic_launcher_filemanager.png diff --git a/app/src/main/res/drawable-xxhdpi/ic_flashlight.png b/app/src/main/res/drawable-xxhdpi/ic_launcher_flashlight.png similarity index 100% rename from app/src/main/res/drawable-xxhdpi/ic_flashlight.png rename to app/src/main/res/drawable-xxhdpi/ic_launcher_flashlight.png diff --git a/app/src/main/res/drawable-xxhdpi/ic_gallery.png b/app/src/main/res/drawable-xxhdpi/ic_launcher_gallery.png similarity index 100% rename from app/src/main/res/drawable-xxhdpi/ic_gallery.png rename to app/src/main/res/drawable-xxhdpi/ic_launcher_gallery.png diff --git a/app/src/main/res/drawable-xxhdpi/ic_musicplayer.png b/app/src/main/res/drawable-xxhdpi/ic_launcher_musicplayer.png similarity index 100% rename from app/src/main/res/drawable-xxhdpi/ic_musicplayer.png rename to app/src/main/res/drawable-xxhdpi/ic_launcher_musicplayer.png diff --git a/app/src/main/res/drawable-xxhdpi/ic_notes.png b/app/src/main/res/drawable-xxhdpi/ic_launcher_notes.png similarity index 100% rename from app/src/main/res/drawable-xxhdpi/ic_notes.png rename to app/src/main/res/drawable-xxhdpi/ic_launcher_notes.png diff --git a/app/src/main/res/drawable-xxxhdpi/ic_calculator.png b/app/src/main/res/drawable-xxxhdpi/ic_launcher_calculator.png similarity index 100% rename from app/src/main/res/drawable-xxxhdpi/ic_calculator.png rename to app/src/main/res/drawable-xxxhdpi/ic_launcher_calculator.png diff --git a/app/src/main/res/drawable-xxxhdpi/ic_calendar.png b/app/src/main/res/drawable-xxxhdpi/ic_launcher_calendar.png similarity index 100% rename from app/src/main/res/drawable-xxxhdpi/ic_calendar.png rename to app/src/main/res/drawable-xxxhdpi/ic_launcher_calendar.png diff --git a/app/src/main/res/drawable-xxxhdpi/ic_camera.png b/app/src/main/res/drawable-xxxhdpi/ic_launcher_camera.png similarity index 100% rename from app/src/main/res/drawable-xxxhdpi/ic_camera.png rename to app/src/main/res/drawable-xxxhdpi/ic_launcher_camera.png diff --git a/app/src/main/res/drawable-xxxhdpi/ic_draw.png b/app/src/main/res/drawable-xxxhdpi/ic_launcher_draw.png similarity index 100% rename from app/src/main/res/drawable-xxxhdpi/ic_draw.png rename to app/src/main/res/drawable-xxxhdpi/ic_launcher_draw.png diff --git a/app/src/main/res/drawable-xxxhdpi/ic_filemanager.png b/app/src/main/res/drawable-xxxhdpi/ic_launcher_filemanager.png similarity index 100% rename from app/src/main/res/drawable-xxxhdpi/ic_filemanager.png rename to app/src/main/res/drawable-xxxhdpi/ic_launcher_filemanager.png diff --git a/app/src/main/res/drawable-xxxhdpi/ic_flashlight.png b/app/src/main/res/drawable-xxxhdpi/ic_launcher_flashlight.png similarity index 100% rename from app/src/main/res/drawable-xxxhdpi/ic_flashlight.png rename to app/src/main/res/drawable-xxxhdpi/ic_launcher_flashlight.png diff --git a/app/src/main/res/drawable-xxxhdpi/ic_gallery.png b/app/src/main/res/drawable-xxxhdpi/ic_launcher_gallery.png similarity index 100% rename from app/src/main/res/drawable-xxxhdpi/ic_gallery.png rename to app/src/main/res/drawable-xxxhdpi/ic_launcher_gallery.png diff --git a/app/src/main/res/drawable-xxxhdpi/ic_musicplayer.png b/app/src/main/res/drawable-xxxhdpi/ic_launcher_musicplayer.png similarity index 100% rename from app/src/main/res/drawable-xxxhdpi/ic_musicplayer.png rename to app/src/main/res/drawable-xxxhdpi/ic_launcher_musicplayer.png diff --git a/app/src/main/res/drawable-xxxhdpi/ic_notes.png b/app/src/main/res/drawable-xxxhdpi/ic_launcher_notes.png similarity index 100% rename from app/src/main/res/drawable-xxxhdpi/ic_notes.png rename to app/src/main/res/drawable-xxxhdpi/ic_launcher_notes.png diff --git a/app/src/main/res/layout/app_launcher_item.xml b/app/src/main/res/layout/app_launcher_item.xml index 4da362f..75f5a5d 100644 --- a/app/src/main/res/layout/app_launcher_item.xml +++ b/app/src/main/res/layout/app_launcher_item.xml @@ -27,11 +27,15 @@ + android:layout_margin="@dimen/small_margin" + android:background="@drawable/circle_background" + android:padding="@dimen/tiny_margin" + android:src="@drawable/ic_check" + android:visibility="gone"/>