updating Commons, kotlin, gradle, min Android OS version to 5

This commit is contained in:
tibbi 2018-10-14 22:29:17 +02:00
parent c20673a94e
commit e67423b9f7
13 changed files with 103 additions and 114 deletions

View File

@ -3,13 +3,13 @@ apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
android {
compileSdkVersion 27
buildToolsVersion "27.0.3"
compileSdkVersion 28
buildToolsVersion "28.0.3"
defaultConfig {
applicationId "com.simplemobiletools.applauncher"
minSdkVersion 16
targetSdkVersion 27
minSdkVersion 21
targetSdkVersion 28
versionCode 15
versionName "4.1.1"
multiDexEnabled true
@ -42,9 +42,9 @@ android {
}
dependencies {
implementation 'com.simplemobiletools:commons:4.6.7'
implementation 'com.simplemobiletools:commons:5.0.18'
implementation 'com.facebook.stetho:stetho:1.5.0'
implementation 'com.android.support:multidex:1.0.3'
implementation 'androidx.multidex:multidex:2.0.0'
}
Properties props = new Properties()

View File

@ -1,6 +1,6 @@
package com.simplemobiletools.applauncher
import android.support.multidex.MultiDexApplication
import androidx.multidex.MultiDexApplication
import com.facebook.stetho.Stetho
import com.simplemobiletools.commons.extensions.checkUseEnglish

View File

@ -17,7 +17,6 @@ import com.simplemobiletools.applauncher.models.AppLauncher
import com.simplemobiletools.commons.extensions.appLaunched
import com.simplemobiletools.commons.extensions.checkWhatsNew
import com.simplemobiletools.commons.extensions.updateTextColors
import com.simplemobiletools.commons.helpers.LICENSE_MULTISELECT
import com.simplemobiletools.commons.helpers.LICENSE_STETHO
import com.simplemobiletools.commons.interfaces.RefreshRecyclerViewListener
import com.simplemobiletools.commons.models.FAQItem
@ -94,7 +93,7 @@ class MainActivity : SimpleActivity(), RefreshRecyclerViewListener {
}
private fun launchAbout() {
val licenses = LICENSE_MULTISELECT or LICENSE_STETHO
val licenses = LICENSE_STETHO
val faqItems = arrayListOf(
FAQItem(R.string.faq_2_title_commons, R.string.faq_2_text_commons)

View File

@ -17,7 +17,6 @@ import com.simplemobiletools.commons.interfaces.RefreshRecyclerViewListener
import com.simplemobiletools.commons.views.FastScroller
import com.simplemobiletools.commons.views.MyRecyclerView
import kotlinx.android.synthetic.main.item_app_launcher.view.*
import java.util.*
class LaunchersAdapter(activity: SimpleActivity, val launchers: MutableList<AppLauncher>, val listener: RefreshRecyclerViewListener?,
recyclerView: MyRecyclerView, fastScroller: FastScroller, itemClick: (Any) -> Unit) :
@ -29,26 +28,6 @@ class LaunchersAdapter(activity: SimpleActivity, val launchers: MutableList<AppL
override fun getActionMenuId() = R.menu.cab
override fun prepareItemSelection(viewHolder: ViewHolder) {
viewHolder.itemView?.launcher_check?.background?.applyColorFilter(primaryColor)
}
override fun markViewHolderSelection(select: Boolean, viewHolder: ViewHolder?) {
viewHolder?.itemView?.launcher_check?.beInvisibleIf(!select)
}
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int) = createViewHolder(R.layout.item_app_launcher, parent)
override fun onBindViewHolder(holder: MyRecyclerViewAdapter.ViewHolder, position: Int) {
val launcher = launchers[position]
val view = holder.bindView(launcher, true, true) { itemView, adapterPosition ->
setupView(itemView, launcher)
}
bindViewHolder(holder, position, view)
}
override fun getItemCount() = launchers.size
override fun prepareActionMode(menu: Menu) {
menu.apply {
findItem(R.id.cab_edit).isVisible = isOneItemSelected()
@ -56,18 +35,40 @@ class LaunchersAdapter(activity: SimpleActivity, val launchers: MutableList<AppL
}
override fun actionItemPressed(id: Int) {
if (selectedKeys.isEmpty()) {
return
}
when (id) {
R.id.cab_edit -> showEditDialog()
R.id.cab_remove -> tryRemoveLauncher()
}
}
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int) = createViewHolder(R.layout.item_app_launcher, parent)
override fun onBindViewHolder(holder: MyRecyclerViewAdapter.ViewHolder, position: Int) {
val launcher = launchers[position]
holder.bindView(launcher, true, true) { itemView, adapterPosition ->
setupView(itemView, launcher, isKeySelected(launcher.packageName.hashCode()))
}
bindViewHolder(holder)
}
override fun getItemCount() = launchers.size
private fun getItemWithKey(key: Int): AppLauncher? = launchers.firstOrNull { it.packageName.hashCode() == key }
override fun getSelectableItemCount() = launchers.size
override fun getIsItemSelectable(position: Int) = true
override fun getItemSelectionKey(position: Int) = launchers.getOrNull(position)?.packageName?.hashCode()
override fun getItemKeyPosition(key: Int) = launchers.indexOfFirst { it.packageName.hashCode() == key }
private fun showEditDialog() {
EditDialog(activity, launchers[selectedPositions.first()]) {
EditDialog(activity, getItemWithKey(selectedKeys.first())!!) {
finishActMode()
listener?.refreshItems()
}
@ -89,24 +90,38 @@ class LaunchersAdapter(activity: SimpleActivity, val launchers: MutableList<AppL
}
private fun removeItems() {
val removeIds = ArrayList<String>(selectedPositions.size)
val removeLaunchers = ArrayList<AppLauncher>(selectedPositions.size)
selectedPositions.sortedDescending().forEach {
val launcher = launchers[it]
val removeIds = ArrayList<String>(selectedKeys.size)
val removeLaunchers = ArrayList<AppLauncher>(selectedKeys.size)
val positions = ArrayList<Int>(selectedKeys.size)
for (key in selectedKeys) {
val launcher = getItemWithKey(key) ?: continue
removeIds.add(launcher.id.toString())
removeLaunchers.add(launcher)
val position = launchers.indexOfFirst { it.packageName.hashCode() == key }
if (position != -1) {
positions.add(position)
}
}
launchers.removeAll(removeLaunchers)
activity.dbHelper.deleteLaunchers(removeIds)
removeSelectedItems()
positions.sortDescending()
removeSelectedItems(positions)
}
private fun setupView(view: View, launcher: AppLauncher) {
private fun setupView(view: View, launcher: AppLauncher, isSelected: Boolean) {
view.apply {
// setup check icon
launcher_check?.beInvisibleIf(!isSelected)
launcher_label.text = launcher.name
launcher_label.setTextColor(textColor)
launcher_icon.setImageDrawable(launcher.drawable!!)
if (isSelected) {
launcher_check?.background?.applyColorFilter(primaryColor)
}
}
}
}

View File

@ -1,87 +1,74 @@
package com.simplemobiletools.applauncher.adapters
import android.app.Activity
import android.support.v7.widget.RecyclerView
import android.util.SparseArray
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
import com.simplemobiletools.applauncher.R
import com.simplemobiletools.applauncher.extensions.config
import com.simplemobiletools.applauncher.models.AppLauncher
import com.simplemobiletools.commons.extensions.applyColorFilter
import com.simplemobiletools.commons.extensions.beInvisibleIf
import com.simplemobiletools.commons.interfaces.MyAdapterListener
import kotlinx.android.synthetic.main.item_app_launcher.view.*
import java.util.*
class LaunchersDialogAdapter(activity: Activity, val launchers: ArrayList<AppLauncher>) : RecyclerView.Adapter<LaunchersDialogAdapter.ViewHolder>() {
private val config = activity.config
private var primaryColor = config.primaryColor
private var itemViews = SparseArray<View>()
private val selectedPositions = HashSet<Int>()
private var textColor = config.textColor
private var selectedKeys = HashSet<Int>()
fun toggleItemSelection(select: Boolean, pos: Int) {
val itemKey = launchers.getOrNull(pos)?.packageName?.hashCode() ?: return
if (select) {
if (itemViews[pos] != null) {
itemViews[pos].launcher_check?.background?.applyColorFilter(primaryColor)
selectedPositions.add(pos)
}
selectedKeys.add(itemKey)
} else {
selectedPositions.remove(pos)
selectedKeys.remove(itemKey)
}
itemViews[pos]?.launcher_check?.beInvisibleIf(!select)
notifyItemChanged(pos)
}
fun getSelectedLaunchers(): ArrayList<AppLauncher> {
val selectedLaunchers = ArrayList<AppLauncher>()
selectedPositions.forEach {
selectedLaunchers.add(launchers[it])
}
return selectedLaunchers
}
private val adapterListener = object : MyAdapterListener {
override fun itemLongClicked(position: Int) {
}
override fun toggleItemSelectionAdapter(select: Boolean, position: Int) {
toggleItemSelection(select, position)
}
override fun getSelectedPositions(): HashSet<Int> = selectedPositions
}
fun getSelectedLaunchers() = launchers.filter { selectedKeys.contains(it.packageName.hashCode()) } as ArrayList<AppLauncher>
override fun onBindViewHolder(holder: ViewHolder, position: Int) {
itemViews.put(position, holder.bindView(launchers[position], textColor))
toggleItemSelection(selectedPositions.contains(position), position)
holder.bindView(launchers[position])
}
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
val view = LayoutInflater.from(parent.context).inflate(R.layout.item_app_launcher, parent, false)
return ViewHolder(view, adapterListener)
return ViewHolder(view)
}
override fun getItemCount() = launchers.size
class ViewHolder(view: View, val adapterListener: MyAdapterListener) : RecyclerView.ViewHolder(view) {
fun bindView(launcher: AppLauncher, textColor: Int): View {
private fun isKeySelected(key: Int) = selectedKeys.contains(key)
inner class ViewHolder(view: View) : RecyclerView.ViewHolder(view) {
fun bindView(launcher: AppLauncher): View {
val isSelected = isKeySelected(launcher.packageName.hashCode())
itemView.apply {
launcher_check?.beInvisibleIf(!isSelected)
launcher_label.text = launcher.name
launcher_label.setTextColor(textColor)
launcher_icon.setImageDrawable(launcher.drawable!!)
setOnClickListener { viewClicked() }
setOnLongClickListener { viewClicked(); true }
if (isSelected) {
launcher_check?.background?.applyColorFilter(primaryColor)
}
setOnClickListener { viewClicked(launcher) }
setOnLongClickListener { viewClicked(launcher); true }
}
return itemView
}
private fun viewClicked() {
val isSelected = adapterListener.getSelectedPositions().contains(adapterPosition)
adapterListener.toggleItemSelectionAdapter(!isSelected, adapterPosition)
private fun viewClicked(launcher: AppLauncher) {
val isSelected = selectedKeys.contains(launcher.packageName.hashCode())
toggleItemSelection(!isSelected, adapterPosition)
}
}
}

View File

@ -1,8 +1,8 @@
package com.simplemobiletools.applauncher.dialogs
import android.app.Activity
import android.support.v7.app.AlertDialog
import android.view.ViewGroup
import androidx.appcompat.app.AlertDialog
import com.simplemobiletools.applauncher.R
import com.simplemobiletools.applauncher.adapters.LaunchersDialogAdapter
import com.simplemobiletools.applauncher.extensions.dbHelper
@ -16,7 +16,7 @@ class AddAppLauncherDialog(val activity: Activity, val notDisplayedLaunchers: Ar
init {
AlertDialog.Builder(activity)
.setPositiveButton(R.string.ok, { dialogInterface, i -> confirmSelection() })
.setPositiveButton(R.string.ok) { dialogInterface, i -> confirmSelection() }
.setNegativeButton(R.string.cancel, null)
.create().apply {
activity.setupDialogStuff(view, this) {

View File

@ -1,8 +1,8 @@
package com.simplemobiletools.applauncher.dialogs
import android.app.Activity
import android.support.v7.app.AlertDialog
import android.view.ViewGroup
import androidx.appcompat.app.AlertDialog
import com.simplemobiletools.applauncher.R
import com.simplemobiletools.applauncher.extensions.dbHelper
import com.simplemobiletools.applauncher.models.AppLauncher

View File

@ -1,22 +1,18 @@
package com.simplemobiletools.applauncher.extensions
import android.annotation.TargetApi
import android.content.Context
import android.content.Intent
import android.content.pm.LauncherApps
import android.content.pm.PackageManager
import android.graphics.drawable.Drawable
import android.os.Build
import com.simplemobiletools.applauncher.helpers.Config
import com.simplemobiletools.applauncher.helpers.DBHelper
import com.simplemobiletools.applauncher.models.AppLauncher
import com.simplemobiletools.commons.helpers.isLollipopPlus
val Context.config: Config get() = Config.newInstance(applicationContext)
val Context.dbHelper: DBHelper get() = DBHelper.newInstance(applicationContext)
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
fun Context.getNotDisplayedLaunchers(displayedLaunchers: ArrayList<AppLauncher>): ArrayList<AppLauncher> {
val allApps = ArrayList<AppLauncher>()
val intent = Intent(Intent.ACTION_MAIN, null)
@ -28,14 +24,12 @@ fun Context.getNotDisplayedLaunchers(displayedLaunchers: ArrayList<AppLauncher>)
val packageName = componentInfo.packageName
var drawable: Drawable? = null
if (isLollipopPlus()) {
try {
// try getting the properly colored launcher icons
val launcher = getSystemService(Context.LAUNCHER_APPS_SERVICE) as LauncherApps
val activityList = launcher.getActivityList(packageName, android.os.Process.myUserHandle())[0]
drawable = activityList.getBadgedIcon(0)
} catch (e: Exception) {
}
try {
// try getting the properly colored launcher icons
val launcher = getSystemService(Context.LAUNCHER_APPS_SERVICE) as LauncherApps
val activityList = launcher.getActivityList(packageName, android.os.Process.myUserHandle())[0]
drawable = activityList.getBadgedIcon(0)
} catch (e: Exception) {
}
if (drawable == null) {

View File

@ -1,6 +1,5 @@
package com.simplemobiletools.applauncher.helpers
import android.annotation.TargetApi
import android.content.ContentValues
import android.content.Context
import android.content.pm.LauncherApps
@ -8,7 +7,6 @@ import android.content.pm.PackageManager
import android.database.sqlite.SQLiteDatabase
import android.database.sqlite.SQLiteOpenHelper
import android.graphics.drawable.Drawable
import android.os.Build
import android.text.TextUtils
import com.simplemobiletools.applauncher.R
import com.simplemobiletools.applauncher.extensions.getLauncherDrawable
@ -16,7 +14,6 @@ import com.simplemobiletools.applauncher.extensions.isAPredefinedApp
import com.simplemobiletools.applauncher.models.AppLauncher
import com.simplemobiletools.commons.extensions.getIntValue
import com.simplemobiletools.commons.extensions.getStringValue
import com.simplemobiletools.commons.helpers.isLollipopPlus
import java.util.*
class DBHelper private constructor(val context: Context) : SQLiteOpenHelper(context, DB_NAME, null, DB_VERSION) {
@ -123,7 +120,6 @@ class DBHelper private constructor(val context: Context) : SQLiteOpenHelper(cont
return mDb.update(MAIN_TABLE_NAME, values, selection, selectionArgs) == 1
}
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
fun getLaunchers(): ArrayList<AppLauncher> {
val resources = context.resources
val packageManager = context.packageManager
@ -139,18 +135,16 @@ class DBHelper private constructor(val context: Context) : SQLiteOpenHelper(cont
val wasRenamed = cursor.getIntValue(COL_WAS_RENAMED) == 1
var drawable: Drawable? = null
if (isLollipopPlus()) {
try {
// try getting the properly colored launcher icons
val launcher = context.getSystemService(Context.LAUNCHER_APPS_SERVICE) as LauncherApps
val activityList = launcher.getActivityList(packageName, android.os.Process.myUserHandle())[0]
drawable = activityList.getBadgedIcon(0)
try {
// try getting the properly colored launcher icons
val launcher = context.getSystemService(Context.LAUNCHER_APPS_SERVICE) as LauncherApps
val activityList = launcher.getActivityList(packageName, android.os.Process.myUserHandle())[0]
drawable = activityList.getBadgedIcon(0)
if (!wasRenamed) {
name = activityList.label.toString()
}
} catch (e: Exception) {
if (!wasRenamed) {
name = activityList.label.toString()
}
} catch (e: Exception) {
}
if (drawable == null) {

View File

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
<androidx.coordinatorlayout.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/coordinator_layout"
@ -45,4 +45,4 @@
android:layout_margin="@dimen/activity_margin"
android:src="@drawable/ic_plus"/>
</android.support.design.widget.CoordinatorLayout>
</androidx.coordinatorlayout.widget.CoordinatorLayout>

View File

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.RecyclerView
<com.simplemobiletools.commons.views.MyRecyclerView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/pick_launchers_holder"

View File

@ -1,15 +1,15 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
ext.kotlin_version = '1.2.60'
ext.kotlin_version = '1.2.71'
repositories {
jcenter()
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.1.4'
classpath 'com.android.tools.build:gradle:3.2.1'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
// NOTE: Do not place your application dependencies here; they belong
@ -19,8 +19,8 @@ buildscript {
allprojects {
repositories {
jcenter()
google()
jcenter()
maven { url "https://jitpack.io" }
}
}

View File

@ -1,6 +1,6 @@
#Fri Nov 10 21:55:37 CET 2017
#Fri Oct 12 23:02:59 CEST 2018
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.4.1-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-4.6-all.zip