mirror of
				https://github.com/SimpleMobileTools/Simple-App-Launcher.git
				synced 2025-06-05 21:49:21 +02:00 
			
		
		
		
	launch the apps on click
This commit is contained in:
		| @@ -29,11 +29,16 @@ class MainActivity : SimpleActivity() { | |||||||
|         val list = pm.queryIntentActivities(intent, PackageManager.PERMISSION_GRANTED) |         val list = pm.queryIntentActivities(intent, PackageManager.PERMISSION_GRANTED) | ||||||
|         for (info in list) { |         for (info in list) { | ||||||
|             val componentInfo = info.activityInfo.applicationInfo |             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 } |         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 { |     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 kotlinx.android.synthetic.main.app_launcher_item.view.* | ||||||
| import java.util.* | 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) { |     override fun onBindViewHolder(holder: ViewHolder, position: Int) { | ||||||
|         holder.bindView(launchers[position]) |         holder.bindView(launchers[position]) | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     override fun onCreateViewHolder(parent: ViewGroup?, viewType: Int): ViewHolder { |     override fun onCreateViewHolder(parent: ViewGroup?, viewType: Int): ViewHolder { | ||||||
|         val view = LayoutInflater.from(parent?.context).inflate(R.layout.app_launcher_item, parent, false) |         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 { |     override fun getItemCount(): Int { | ||||||
|         return launchers.count() |         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) { |         fun bindView(launcher: AppLauncher) { | ||||||
|             with(launcher) { |             with(launcher) { | ||||||
|                 itemView.launcher_label.text = launcher.name |                 itemView.launcher_label.text = launcher.name | ||||||
|                 itemView.launcher_icon.setImageDrawable(launcher.icon) |                 itemView.launcher_icon.setImageDrawable(launcher.icon) | ||||||
|  |                 itemView.setOnClickListener { itemClick(this) } | ||||||
|             } |             } | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
|   | |||||||
| @@ -2,4 +2,4 @@ package com.simplemobiletools.applauncher.models | |||||||
|  |  | ||||||
| import android.graphics.drawable.Drawable | 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) {} | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user