mirror of
https://github.com/jrpie/Launcher.git
synced 2025-02-23 14:31:30 +01:00
Preloads Apps to speed up ListActivity
The AppInfos are asyncronously loaded Closes #59
This commit is contained in:
parent
4f5974d997
commit
02685ddf37
3 changed files with 37 additions and 22 deletions
|
@ -22,6 +22,7 @@ import android.widget.ImageView
|
||||||
import android.widget.Switch
|
import android.widget.Switch
|
||||||
import android.widget.Toast
|
import android.widget.Toast
|
||||||
import com.finnmglas.launcher.list.ListActivity
|
import com.finnmglas.launcher.list.ListActivity
|
||||||
|
import com.finnmglas.launcher.list.apps.AppInfo
|
||||||
import com.finnmglas.launcher.list.apps.AppsRecyclerAdapter
|
import com.finnmglas.launcher.list.apps.AppsRecyclerAdapter
|
||||||
import com.finnmglas.launcher.settings.SettingsActivity
|
import com.finnmglas.launcher.settings.SettingsActivity
|
||||||
import com.finnmglas.launcher.settings.intendedSettingsPause
|
import com.finnmglas.launcher.settings.intendedSettingsPause
|
||||||
|
@ -61,7 +62,7 @@ const val PREF_STARTED_TIME = "firstStartup"
|
||||||
const val PREF_VERSION = "version"
|
const val PREF_VERSION = "version"
|
||||||
|
|
||||||
/* Objects used by multiple activities */
|
/* Objects used by multiple activities */
|
||||||
lateinit var appListViewAdapter: AppsRecyclerAdapter
|
val appsList: MutableList<AppInfo> = ArrayList()
|
||||||
|
|
||||||
/* Variables containing settings */
|
/* Variables containing settings */
|
||||||
val displayMetrics = DisplayMetrics()
|
val displayMetrics = DisplayMetrics()
|
||||||
|
@ -301,6 +302,29 @@ fun openAppsList(activity: Activity){
|
||||||
activity.startActivity(intent)
|
activity.startActivity(intent)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* [loadApps] is used to speed up the [AppsRecyclerAdapter] loading time,
|
||||||
|
* as it caches all the apps and allows for fast access to the data.
|
||||||
|
*/
|
||||||
|
fun loadApps(packageManager: PackageManager) {
|
||||||
|
val loadList = mutableListOf<AppInfo>()
|
||||||
|
|
||||||
|
val i = Intent(Intent.ACTION_MAIN, null)
|
||||||
|
i.addCategory(Intent.CATEGORY_LAUNCHER)
|
||||||
|
val allApps = packageManager.queryIntentActivities(i, 0)
|
||||||
|
for (ri in allApps) {
|
||||||
|
val app = AppInfo()
|
||||||
|
app.label = ri.loadLabel(packageManager)
|
||||||
|
app.packageName = ri.activityInfo.packageName
|
||||||
|
app.icon = ri.activityInfo.loadIcon(packageManager)
|
||||||
|
loadList.add(app)
|
||||||
|
}
|
||||||
|
loadList.sortBy { it.label.toString() }
|
||||||
|
|
||||||
|
appsList.clear()
|
||||||
|
appsList.addAll(loadList)
|
||||||
|
}
|
||||||
|
|
||||||
fun loadSettings() {
|
fun loadSettings() {
|
||||||
upApp = launcherPreferences.getString(ACTION_UP, "")!!
|
upApp = launcherPreferences.getString(ACTION_UP, "")!!
|
||||||
downApp = launcherPreferences.getString(ACTION_DOWN, "")!!
|
downApp = launcherPreferences.getString(ACTION_DOWN, "")!!
|
||||||
|
|
|
@ -52,11 +52,6 @@ class HomeActivity: UIObject, AppCompatActivity(),
|
||||||
|
|
||||||
loadSettings()
|
loadSettings()
|
||||||
|
|
||||||
// Preload list of apps (speed up loading time)
|
|
||||||
AsyncTask.execute {
|
|
||||||
appListViewAdapter = AppsRecyclerAdapter(this)
|
|
||||||
}
|
|
||||||
|
|
||||||
// First time opening the app: show Tutorial, else: check versions
|
// First time opening the app: show Tutorial, else: check versions
|
||||||
if (!launcherPreferences.getBoolean(PREF_STARTED, false))
|
if (!launcherPreferences.getBoolean(PREF_STARTED, false))
|
||||||
startActivity(Intent(this, TutorialActivity::class.java))
|
startActivity(Intent(this, TutorialActivity::class.java))
|
||||||
|
@ -86,6 +81,9 @@ class HomeActivity: UIObject, AppCompatActivity(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Preload apps to speed up the Apps Recycler
|
||||||
|
AsyncTask.execute { loadApps(packageManager) }
|
||||||
|
|
||||||
// Initialise layout
|
// Initialise layout
|
||||||
setContentView(R.layout.home)
|
setContentView(R.layout.home)
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,6 +5,7 @@ import android.content.Context
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import android.content.pm.PackageManager
|
import android.content.pm.PackageManager
|
||||||
import android.net.Uri
|
import android.net.Uri
|
||||||
|
import android.os.AsyncTask
|
||||||
import android.view.LayoutInflater
|
import android.view.LayoutInflater
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
|
@ -32,7 +33,6 @@ class AppsRecyclerAdapter(val activity: Activity,
|
||||||
val forApp: String? = ""):
|
val forApp: String? = ""):
|
||||||
RecyclerView.Adapter<AppsRecyclerAdapter.ViewHolder>() {
|
RecyclerView.Adapter<AppsRecyclerAdapter.ViewHolder>() {
|
||||||
|
|
||||||
private val appsList: MutableList<AppInfo>
|
|
||||||
private val appsListDisplayed: MutableList<AppInfo>
|
private val appsListDisplayed: MutableList<AppInfo>
|
||||||
|
|
||||||
inner class ViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView),
|
inner class ViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView),
|
||||||
|
@ -140,22 +140,15 @@ class AppsRecyclerAdapter(val activity: Activity,
|
||||||
}
|
}
|
||||||
|
|
||||||
init {
|
init {
|
||||||
appsList = ArrayList()
|
// Load the apps
|
||||||
appsListDisplayed = ArrayList()
|
if (appsList.size == 0)
|
||||||
|
loadApps(activity.packageManager)
|
||||||
val pm: PackageManager = activity.packageManager
|
else {
|
||||||
|
AsyncTask.execute { loadApps(activity.packageManager) }
|
||||||
val i = Intent(Intent.ACTION_MAIN, null)
|
notifyDataSetChanged()
|
||||||
i.addCategory(Intent.CATEGORY_LAUNCHER)
|
|
||||||
val allApps = pm.queryIntentActivities(i, 0)
|
|
||||||
for (ri in allApps) {
|
|
||||||
val app = AppInfo()
|
|
||||||
app.label = ri.loadLabel(pm)
|
|
||||||
app.packageName = ri.activityInfo.packageName
|
|
||||||
app.icon = ri.activityInfo.loadIcon(pm)
|
|
||||||
appsList.add(app)
|
|
||||||
}
|
}
|
||||||
appsList.sortBy { it.label.toString() }
|
|
||||||
|
appsListDisplayed = ArrayList()
|
||||||
appsListDisplayed.addAll(appsList)
|
appsListDisplayed.addAll(appsList)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue