mirror of
				https://github.com/SimpleMobileTools/Simple-App-Launcher.git
				synced 2025-06-05 21:49:21 +02:00 
			
		
		
		
	use different adapters for the main activity and dialog grid
This commit is contained in:
		| @@ -54,7 +54,7 @@ class MainActivity : SimpleActivity(), AddAppDialog.AddLaunchersInterface { | ||||
|  | ||||
|     private fun setupLaunchers() { | ||||
|         launchers = dbHelper.getLaunchers() | ||||
|         launchers_holder.adapter = RecyclerAdapter(applicationContext, false, launchers) { | ||||
|         launchers_holder.adapter = RecyclerAdapter(applicationContext, launchers) { | ||||
|             val launchIntent = packageManager.getLaunchIntentForPackage(it.pkgName) | ||||
|             if (launchIntent != null) { | ||||
|                 startActivity(launchIntent) | ||||
|   | ||||
| @@ -6,16 +6,14 @@ import android.view.LayoutInflater | ||||
| import android.view.View | ||||
| import android.view.ViewGroup | ||||
| import com.simplemobiletools.applauncher.R | ||||
| import com.simplemobiletools.applauncher.extensions.hide | ||||
| import com.simplemobiletools.applauncher.extensions.show | ||||
| import com.simplemobiletools.applauncher.models.AppLauncher | ||||
| import kotlinx.android.synthetic.main.app_launcher_dialog_item.view.* | ||||
|  | ||||
| class RecyclerAdapter(val cxt: Context, val displayChecks: Boolean, val launchers: List<AppLauncher>, val itemClick: (AppLauncher) -> Unit) : | ||||
| class RecyclerAdapter(val cxt: Context, val launchers: List<AppLauncher>, val itemClick: (AppLauncher) -> Unit) : | ||||
|         RecyclerView.Adapter<RecyclerAdapter.ViewHolder>() { | ||||
|  | ||||
|     override fun onBindViewHolder(holder: ViewHolder, position: Int) { | ||||
|         holder.bindView(cxt, displayChecks, launchers[position]) | ||||
|         holder.bindView(cxt, launchers[position]) | ||||
|     } | ||||
|  | ||||
|     override fun onCreateViewHolder(parent: ViewGroup?, viewType: Int): ViewHolder { | ||||
| @@ -28,19 +26,13 @@ class RecyclerAdapter(val cxt: Context, val displayChecks: Boolean, val launcher | ||||
|     } | ||||
|  | ||||
|     class ViewHolder(view: View, val itemClick: (AppLauncher) -> (Unit)) : RecyclerView.ViewHolder(view) { | ||||
|         fun bindView(context: Context, displayChecks: Boolean, launcher: AppLauncher) { | ||||
|         fun bindView(context: Context, launcher: AppLauncher) { | ||||
|             with(launcher) { | ||||
|                 itemView.launcher_label.text = launcher.name | ||||
|                 itemView.setOnClickListener { | ||||
|                     itemClick(this) | ||||
|  | ||||
|                     if (displayChecks) { | ||||
|                         launcher.isChecked = !launcher.isChecked | ||||
|                         handleCheck(itemView.launcher_check, launcher) | ||||
|                     } | ||||
|                 } | ||||
|  | ||||
|                 handleCheck(itemView.launcher_check, launcher) | ||||
|                 if (launcher.iconId != 0) { | ||||
|                     val icon = context.resources.getDrawable(launcher.iconId) | ||||
|                     itemView.launcher_icon.setImageDrawable(icon) | ||||
| @@ -50,13 +42,5 @@ class RecyclerAdapter(val cxt: Context, val displayChecks: Boolean, val launcher | ||||
|                 } | ||||
|             } | ||||
|         } | ||||
|  | ||||
|         fun handleCheck(check: View, launcher: AppLauncher) { | ||||
|             if (launcher.isChecked) { | ||||
|                 check.show() | ||||
|             } else { | ||||
|                 check.hide() | ||||
|             } | ||||
|         } | ||||
|     } | ||||
| } | ||||
|   | ||||
| @@ -0,0 +1,57 @@ | ||||
| package com.simplemobiletools.applauncher.adapters | ||||
|  | ||||
| import android.content.Context | ||||
| import android.support.v7.widget.RecyclerView | ||||
| import android.view.LayoutInflater | ||||
| import android.view.View | ||||
| import android.view.ViewGroup | ||||
| import com.simplemobiletools.applauncher.R | ||||
| import com.simplemobiletools.applauncher.extensions.hide | ||||
| import com.simplemobiletools.applauncher.extensions.show | ||||
| import com.simplemobiletools.applauncher.models.AppLauncher | ||||
| import kotlinx.android.synthetic.main.app_launcher_dialog_item.view.* | ||||
|  | ||||
| class RecyclerDialogAdapter(val cxt: Context, val launchers: List<AppLauncher>) : RecyclerView.Adapter<RecyclerDialogAdapter.ViewHolder>() { | ||||
|  | ||||
|     override fun onBindViewHolder(holder: ViewHolder, position: Int) { | ||||
|         holder.bindView(cxt, launchers[position]) | ||||
|     } | ||||
|  | ||||
|     override fun onCreateViewHolder(parent: ViewGroup?, viewType: Int): ViewHolder { | ||||
|         val view = LayoutInflater.from(parent?.context).inflate(R.layout.app_launcher_dialog_item, parent, false) | ||||
|         return ViewHolder(view) | ||||
|     } | ||||
|  | ||||
|     override fun getItemCount(): Int { | ||||
|         return 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) | ||||
|                 } | ||||
|  | ||||
|                 handleCheck(itemView.launcher_check, launcher) | ||||
|                 if (launcher.iconId != 0) { | ||||
|                     val icon = context.resources.getDrawable(launcher.iconId) | ||||
|                     itemView.launcher_icon.setImageDrawable(icon) | ||||
|                 } else { | ||||
|                     val icon = context.packageManager.getApplicationIcon(launcher.pkgName) | ||||
|                     itemView.launcher_icon.setImageDrawable(icon) | ||||
|                 } | ||||
|             } | ||||
|         } | ||||
|  | ||||
|         fun handleCheck(check: View, launcher: AppLauncher) { | ||||
|             if (launcher.isChecked) { | ||||
|                 check.show() | ||||
|             } else { | ||||
|                 check.hide() | ||||
|             } | ||||
|         } | ||||
|     } | ||||
| } | ||||
| @@ -6,7 +6,7 @@ import android.os.Bundle | ||||
| import android.support.v7.app.AlertDialog | ||||
| import android.view.View | ||||
| import com.simplemobiletools.applauncher.R | ||||
| import com.simplemobiletools.applauncher.adapters.RecyclerAdapter | ||||
| import com.simplemobiletools.applauncher.adapters.RecyclerDialogAdapter | ||||
| import com.simplemobiletools.applauncher.models.AppLauncher | ||||
| import kotlinx.android.synthetic.main.launcher_picker.view.* | ||||
| import java.util.* | ||||
| @@ -28,7 +28,7 @@ class AddAppDialog() : DialogFragment() { | ||||
|         builder.setTitle(R.string.add_apps) | ||||
|  | ||||
|         val recyclerView = View.inflate(activity, R.layout.launcher_picker, null) | ||||
|         recyclerView.launchers_holder.adapter = RecyclerAdapter(activity, true, launchers) { } | ||||
|         recyclerView.launchers_holder.adapter = RecyclerDialogAdapter(activity, launchers) | ||||
|         builder.setView(recyclerView) | ||||
|  | ||||
|         builder.setPositiveButton(android.R.string.ok, { dialogInterface, i -> | ||||
|   | ||||
		Reference in New Issue
	
	Block a user