mirror of
https://github.com/He4eT/yamf_launcher.git
synced 2026-05-05 01:47:24 +00:00
Shortcut modifications are now saved.
This commit is contained in:
parent
288c7921f6
commit
597540b1c6
5 changed files with 53 additions and 10 deletions
|
|
@ -44,10 +44,10 @@ class AppMenuActivity : AppCompatActivity(), AppMenuAdapter.OnItemClickListener,
|
|||
private lateinit var menuMode: String
|
||||
|
||||
companion object {
|
||||
private lateinit var callback: (Pair<String, Pair<LauncherActivityInfo, UserHandle>>) -> Unit
|
||||
private lateinit var callback: (Pair<Pair<String, Int>, Pair<LauncherActivityInfo, UserHandle>>) -> Unit
|
||||
private const val MENU_MODE = "abcd"
|
||||
|
||||
fun start(context: Context, param1: String = "app", callback: (Pair<String, Pair<LauncherActivityInfo, UserHandle>>) -> Unit) {
|
||||
fun start(context: Context, param1: String = "app", callback: (Pair<Pair<String, Int>, Pair<LauncherActivityInfo, UserHandle>>) -> Unit) {
|
||||
val intent = Intent(context, AppMenuActivity::class.java).apply {
|
||||
putExtra(MENU_MODE, param1)
|
||||
}
|
||||
|
|
@ -88,8 +88,8 @@ class AppMenuActivity : AppCompatActivity(), AppMenuAdapter.OnItemClickListener,
|
|||
}
|
||||
}
|
||||
|
||||
override fun onShortcut(appInfo: LauncherActivityInfo, userHandle: UserHandle, textView: TextView) {
|
||||
callback.invoke(Pair(textView.text.toString(), Pair(appInfo, userHandle,)))
|
||||
override fun onShortcut(appInfo: LauncherActivityInfo, userHandle: UserHandle, textView: TextView, userProfile: Int) {
|
||||
callback.invoke(Pair(Pair(textView.text.toString(), userProfile), Pair(appInfo, userHandle,)))
|
||||
finish()
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -31,7 +31,7 @@ class AppMenuAdapter(
|
|||
}
|
||||
|
||||
interface OnShortcutListener {
|
||||
fun onShortcut(appInfo: LauncherActivityInfo, userHandle: UserHandle, textView: TextView)
|
||||
fun onShortcut(appInfo: LauncherActivityInfo, userHandle: UserHandle, textView: TextView, userProfile: Int)
|
||||
}
|
||||
|
||||
interface OnItemLongClickListener {
|
||||
|
|
@ -60,7 +60,7 @@ class AppMenuAdapter(
|
|||
if (position != RecyclerView.NO_POSITION) {
|
||||
val app = apps[position].first
|
||||
if (menuMode == "shortcut") {
|
||||
shortcutListener.onShortcut(app, apps[position].second.first, textView)
|
||||
shortcutListener.onShortcut(app, apps[position].second.first, textView, apps[position].second.second )
|
||||
}
|
||||
else if (menuMode == "app") {
|
||||
itemClickListener.onItemClick(app, apps[position].second.first)
|
||||
|
|
|
|||
|
|
@ -24,6 +24,7 @@ class MainActivity : AppCompatActivity() {
|
|||
private lateinit var binding: ActivityMainBinding
|
||||
private lateinit var gestureDetector: GestureDetector
|
||||
private lateinit var launcherApps: LauncherApps
|
||||
private val sharedPreferenceManager = SharedPreferenceManager()
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
|
|
@ -35,15 +36,25 @@ class MainActivity : AppCompatActivity() {
|
|||
|
||||
for (i in findViewById<LinearLayout>(R.id.shortcuts).children) {
|
||||
|
||||
var textView = i as TextView
|
||||
val textView = i as TextView
|
||||
|
||||
i.setOnClickListener {
|
||||
Log.d("hHJKJFAF", "Click done")
|
||||
val savedView = sharedPreferenceManager.getShortcut(this, textView)
|
||||
|
||||
if (savedView?.get(1) != "e") {
|
||||
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)
|
||||
} else {
|
||||
Toast.makeText(this, "Cannot launch app", Toast.LENGTH_SHORT).show()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
i.setOnLongClickListener {
|
||||
AppMenuActivity.start(this@MainActivity, "shortcut") { newText ->
|
||||
textView.text = newText.first
|
||||
textView.text = newText.first.first
|
||||
i.setOnClickListener {
|
||||
val mainActivity = launcherApps.getActivityList(newText.second.first.applicationInfo.packageName, newText.second.second).firstOrNull()
|
||||
if (mainActivity != null) {
|
||||
|
|
@ -52,6 +63,7 @@ class MainActivity : AppCompatActivity() {
|
|||
Toast.makeText(this, "Cannot launch app", Toast.LENGTH_SHORT).show()
|
||||
}
|
||||
}
|
||||
sharedPreferenceManager.setShortcut(this, textView, newText.second.first.applicationInfo.packageName, newText.first.second)
|
||||
}
|
||||
|
||||
return@setOnLongClickListener true
|
||||
|
|
|
|||
|
|
@ -1,10 +1,25 @@
|
|||
package eu.ottop.yamlauncher
|
||||
|
||||
import android.content.Context
|
||||
import android.widget.TextView
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
|
||||
class SharedPreferenceManager {
|
||||
|
||||
fun setShortcut(cont: Context, textView: TextView, packageName: String, profile: Int) {
|
||||
val editor = cont.getSharedPreferences("shortcuts", AppCompatActivity.MODE_PRIVATE).edit()
|
||||
val key = textView.id.toString()
|
||||
editor.putString(key, "$packageName-$profile-${textView.text}")
|
||||
editor.apply()
|
||||
}
|
||||
|
||||
fun getShortcut(cont: Context, textView: TextView): List<String>? {
|
||||
val sharedPref = cont.getSharedPreferences("shortcuts", AppCompatActivity.MODE_PRIVATE)
|
||||
val key = textView.id.toString()
|
||||
val value = sharedPref.getString(key, "e-e")
|
||||
return value?.split("-")
|
||||
}
|
||||
|
||||
fun setAppHidden(cont: Context, packageName: String, profile: Int, hidden: Boolean) {
|
||||
val editor = cont.getSharedPreferences("hidden_apps", AppCompatActivity.MODE_PRIVATE).edit()
|
||||
val key = "$packageName-$profile"
|
||||
|
|
|
|||
|
|
@ -93,6 +93,22 @@
|
|||
android:textColor="#F3F3F3"
|
||||
android:textSize="28sp"
|
||||
android:visibility="visible" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/app5"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:clickable="false"
|
||||
android:gravity="start"
|
||||
android:paddingLeft="40dp"
|
||||
android:paddingTop="20dp"
|
||||
android:paddingRight="40dp"
|
||||
android:paddingBottom="20dp"
|
||||
android:text="App"
|
||||
android:textAppearance="@android:style/TextAppearance.DeviceDefault"
|
||||
android:textColor="#F3F3F3"
|
||||
android:textSize="28sp"
|
||||
android:visibility="visible" />
|
||||
</LinearLayout>
|
||||
|
||||
<Space
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue