mirror of
https://github.com/SimpleMobileTools/Simple-App-Launcher.git
synced 2025-02-07 15:28:43 +01:00
launch the apps on click
This commit is contained in:
parent
7b999702bf
commit
cf9d543255
@ -29,11 +29,16 @@ class MainActivity : SimpleActivity() {
|
||||
val list = pm.queryIntentActivities(intent, PackageManager.PERMISSION_GRANTED)
|
||||
for (info in list) {
|
||||
val componentInfo = info.activityInfo.applicationInfo
|
||||
apps.add(AppLauncher(componentInfo.loadLabel(pm).toString(), componentInfo.loadIcon(pm)))
|
||||
apps.add(AppLauncher(componentInfo.loadLabel(pm).toString(), componentInfo.loadIcon(pm), componentInfo.packageName))
|
||||
}
|
||||
|
||||
apps.sortBy { it.name }
|
||||
launchers_holder.adapter = LaunchersAdapter(apps)
|
||||
launchers_holder.adapter = LaunchersAdapter(apps) {
|
||||
val launchIntent = packageManager.getLaunchIntentForPackage(it.pkgName)
|
||||
if (launchIntent != null) {
|
||||
startActivity(launchIntent)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun onCreateOptionsMenu(menu: Menu?): Boolean {
|
||||
|
@ -9,25 +9,27 @@ import com.simplemobiletools.applauncher.models.AppLauncher
|
||||
import kotlinx.android.synthetic.main.app_launcher_item.view.*
|
||||
import java.util.*
|
||||
|
||||
class LaunchersAdapter(val launchers: ArrayList<AppLauncher>) : RecyclerView.Adapter<LaunchersAdapter.ViewHolder>() {
|
||||
class LaunchersAdapter(val launchers: ArrayList<AppLauncher>, val itemClick: (AppLauncher) -> Unit) :
|
||||
RecyclerView.Adapter<LaunchersAdapter.ViewHolder>() {
|
||||
override fun onBindViewHolder(holder: ViewHolder, position: Int) {
|
||||
holder.bindView(launchers[position])
|
||||
}
|
||||
|
||||
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, itemClick)
|
||||
}
|
||||
|
||||
override fun getItemCount(): Int {
|
||||
return launchers.count()
|
||||
}
|
||||
|
||||
class ViewHolder(view: View) : RecyclerView.ViewHolder(view) {
|
||||
class ViewHolder(view: View, val itemClick: (AppLauncher) -> Unit) : RecyclerView.ViewHolder(view) {
|
||||
fun bindView(launcher: AppLauncher) {
|
||||
with(launcher) {
|
||||
itemView.launcher_label.text = launcher.name
|
||||
itemView.launcher_icon.setImageDrawable(launcher.icon)
|
||||
itemView.setOnClickListener { itemClick(this) }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -2,4 +2,4 @@ package com.simplemobiletools.applauncher.models
|
||||
|
||||
import android.graphics.drawable.Drawable
|
||||
|
||||
data class AppLauncher(val name: String, val icon: Drawable) { }
|
||||
data class AppLauncher(val name: String, val icon: Drawable, val pkgName: String) {}
|
||||
|
Loading…
x
Reference in New Issue
Block a user