diff --git a/app/src/main/java/eu/ottop/yamlauncher/AppMenuActivity.kt b/app/src/main/java/eu/ottop/yamlauncher/AppMenuActivity.kt index dda4c4d..a3340d7 100644 --- a/app/src/main/java/eu/ottop/yamlauncher/AppMenuActivity.kt +++ b/app/src/main/java/eu/ottop/yamlauncher/AppMenuActivity.kt @@ -65,6 +65,11 @@ class AppMenuActivity : AppCompatActivity(), AppMenuAdapter.OnItemClickListener, binding = ActivityAppMenuBinding.inflate(layoutInflater) setContentView(binding.root) setSupportActionBar(null) + + if (menuMode == "shortcut") { + binding.menutitle.visibility = View.VISIBLE + } + launcherApps = getSystemService(Context.LAUNCHER_APPS_SERVICE) as LauncherApps searchView = findViewById(R.id.searchView) diff --git a/app/src/main/java/eu/ottop/yamlauncher/AppMenuAdapter.kt b/app/src/main/java/eu/ottop/yamlauncher/AppMenuAdapter.kt index 256d03c..11484ab 100644 --- a/app/src/main/java/eu/ottop/yamlauncher/AppMenuAdapter.kt +++ b/app/src/main/java/eu/ottop/yamlauncher/AppMenuAdapter.kt @@ -2,6 +2,7 @@ package eu.ottop.yamlauncher import android.content.Context import android.content.pm.LauncherActivityInfo +import android.content.res.Resources import android.os.UserHandle import android.view.LayoutInflater import android.view.View @@ -12,6 +13,7 @@ import android.widget.FrameLayout import android.widget.LinearLayout import android.widget.TextView import androidx.appcompat.widget.AppCompatButton +import androidx.core.content.res.ResourcesCompat import androidx.recyclerview.widget.RecyclerView class AppMenuAdapter( @@ -55,22 +57,20 @@ class AppMenuAdapter( actionMenuLayout.visibility = View.INVISIBLE editView.visibility = View.INVISIBLE - itemView.setOnClickListener { - val position = bindingAdapterPosition - if (position != RecyclerView.NO_POSITION) { + textView.setOnClickListener { + val position = bindingAdapterPosition val app = apps[position].first if (menuMode == "shortcut") { - shortcutListener.onShortcut(app, apps[position].second.first, textView, apps[position].second.second ) + shortcutListener.onShortcut(app, apps[position].second.first, textView, apps[position].second.second) } else if (menuMode == "app") { itemClickListener.onItemClick(app, apps[position].second.first) } - } } if (menuMode == "app") { - itemView.setOnLongClickListener { - val position = bindingAdapterPosition - if (position != RecyclerView.NO_POSITION) { + textView.setOnLongClickListener { + val position = bindingAdapterPosition + val app = apps[position].first itemLongClickListener.onItemLongClick( app, @@ -82,8 +82,8 @@ class AppMenuAdapter( ) return@setOnLongClickListener true } - false - } + + } } } @@ -96,6 +96,17 @@ class AppMenuAdapter( override fun onBindViewHolder(holder: AppViewHolder, position: Int) { val app = apps[position] + + holder.textView.setCompoundDrawablesWithIntrinsicBounds(null, null, null, null) + + if (app.second.second != 0) { + holder.textView.setCompoundDrawablesWithIntrinsicBounds(ResourcesCompat.getDrawable(activity.resources, R.drawable.ic_work_app, null),null,null,null) + } + else { + holder.textView.setCompoundDrawablesWithIntrinsicBounds(ResourcesCompat.getDrawable(activity.resources, R.drawable.ic_empty, null),null,null,null) + } + holder.textView.compoundDrawablePadding = 0 + val appInfo = app.first.activityInfo.applicationInfo holder.textView.text = sharedPreferenceManager.getAppName(activity, app.first.applicationInfo.packageName,app.second.second, appInfo.loadLabel(holder.itemView.context.packageManager)) holder.editView.findViewById(R.id.app_name_edit).setText(holder.textView.text) diff --git a/app/src/main/java/eu/ottop/yamlauncher/MainActivity.kt b/app/src/main/java/eu/ottop/yamlauncher/MainActivity.kt index af58172..bec15c4 100644 --- a/app/src/main/java/eu/ottop/yamlauncher/MainActivity.kt +++ b/app/src/main/java/eu/ottop/yamlauncher/MainActivity.kt @@ -15,6 +15,7 @@ import android.widget.Toast import androidx.activity.result.ActivityResultLauncher import androidx.activity.result.contract.ActivityResultContracts import androidx.appcompat.app.AppCompatActivity +import androidx.core.content.res.ResourcesCompat import androidx.core.view.children import eu.ottop.yamlauncher.databinding.ActivityMainBinding import kotlin.math.abs @@ -40,12 +41,27 @@ class MainActivity : AppCompatActivity() { val savedView = sharedPreferenceManager.getShortcut(this, textView) + textView.setCompoundDrawablesWithIntrinsicBounds(ResourcesCompat.getDrawable(resources, R.drawable.ic_empty, null),null,null,null) + + textView.compoundDrawablePadding = 0 + + i.setOnClickListener { + Toast.makeText(this, "Long click to select an app", Toast.LENGTH_SHORT).show() + } + if (savedView?.get(1) != "e") { + + if (savedView?.get(1) != "0") { + textView.setCompoundDrawablesWithIntrinsicBounds(ResourcesCompat.getDrawable(resources, R.drawable.ic_work_app, null),null,null,null) + } + else { + textView.setCompoundDrawablesWithIntrinsicBounds(ResourcesCompat.getDrawable(resources, R.drawable.ic_empty, null),null,null,null) + } textView.text = savedView?.get(2) textView.setOnClickListener { val mainActivity = launcherApps.getActivityList(savedView?.get(0).toString(), launcherApps.profiles[savedView?.get(1)!!.toInt()]).firstOrNull() if (mainActivity != null) { - launcherApps.startMainActivity(mainActivity.componentName, launcherApps.profiles[savedView[1]!!.toInt()], null, null) + launcherApps.startMainActivity(mainActivity.componentName, launcherApps.profiles[savedView[1].toInt()], null, null) } else { Toast.makeText(this, "Cannot launch app", Toast.LENGTH_SHORT).show() } @@ -54,6 +70,13 @@ class MainActivity : AppCompatActivity() { i.setOnLongClickListener { AppMenuActivity.start(this@MainActivity, "shortcut") { newText -> + + if (newText.first.second != 0) { + textView.setCompoundDrawablesWithIntrinsicBounds(ResourcesCompat.getDrawable(resources, R.drawable.ic_work_app, null),null,null,null) + } + else { + textView.setCompoundDrawablesWithIntrinsicBounds(ResourcesCompat.getDrawable(resources, R.drawable.ic_empty, null),null,null,null) + } textView.text = newText.first.first i.setOnClickListener { val mainActivity = launcherApps.getActivityList(newText.second.first.applicationInfo.packageName, newText.second.second).firstOrNull() diff --git a/app/src/main/res/drawable/ic_empty.xml b/app/src/main/res/drawable/ic_empty.xml new file mode 100644 index 0000000..5a83206 --- /dev/null +++ b/app/src/main/res/drawable/ic_empty.xml @@ -0,0 +1,10 @@ + + + + + diff --git a/app/src/main/res/drawable/ic_work_app.xml b/app/src/main/res/drawable/ic_work_app.xml new file mode 100644 index 0000000..cb421b0 --- /dev/null +++ b/app/src/main/res/drawable/ic_work_app.xml @@ -0,0 +1,17 @@ + + + + + diff --git a/app/src/main/res/layout/activity_app_menu.xml b/app/src/main/res/layout/activity_app_menu.xml index 58a9e42..f5b2339 100644 --- a/app/src/main/res/layout/activity_app_menu.xml +++ b/app/src/main/res/layout/activity_app_menu.xml @@ -6,11 +6,30 @@ android:gravity="bottom" android:orientation="vertical"> + + + + + android:textSize="70sp" /> + + + + + + + android:textAppearance="@android:style/TextAppearance.DeviceDefault" + android:textSize="28sp" /> + android:textAppearance="@android:style/TextAppearance.DeviceDefault" + android:textColor="#F3F3F3" /> + android:visibility="visible" + app:drawableLeftCompat="@drawable/ic_work_app" /> + app:drawableTopCompat="@android:drawable/ic_menu_info_details" /> + app:drawableTopCompat="@android:drawable/ic_menu_delete" /> + app:drawableTopCompat="@android:drawable/ic_menu_edit" /> + app:drawableTopCompat="@android:drawable/ic_menu_view" /> + app:drawableTopCompat="@android:drawable/ic_menu_close_clear_cancel" />