mirror of
https://github.com/kvorschk/Magisk.git
synced 2026-12-06 07:20:47 -05:00
Add feature to create launch shortcuts
This commit is contained in:
@@ -8,20 +8,19 @@ import android.view.View
|
||||
import android.view.ViewTreeObserver
|
||||
import android.view.WindowManager
|
||||
import androidx.coordinatorlayout.widget.CoordinatorLayout
|
||||
import androidx.core.content.pm.ShortcutManagerCompat
|
||||
import androidx.core.view.forEach
|
||||
import androidx.core.view.setPadding
|
||||
import androidx.core.view.updateLayoutParams
|
||||
import androidx.navigation.NavDirections
|
||||
import com.google.android.material.card.MaterialCardView
|
||||
import com.topjohnwu.magisk.BuildConfig
|
||||
import com.topjohnwu.magisk.MainDirections
|
||||
import com.topjohnwu.magisk.R
|
||||
import com.topjohnwu.magisk.arch.BaseUIActivity
|
||||
import com.topjohnwu.magisk.arch.BaseViewModel
|
||||
import com.topjohnwu.magisk.arch.ReselectionTarget
|
||||
import com.topjohnwu.magisk.core.Const
|
||||
import com.topjohnwu.magisk.core.Info
|
||||
import com.topjohnwu.magisk.core.SplashActivity
|
||||
import com.topjohnwu.magisk.core.redirect
|
||||
import com.topjohnwu.magisk.core.*
|
||||
import com.topjohnwu.magisk.databinding.ActivityMainMd2Binding
|
||||
import com.topjohnwu.magisk.ktx.startAnimations
|
||||
import com.topjohnwu.magisk.ui.home.HomeFragmentDirections
|
||||
@@ -29,6 +28,7 @@ import com.topjohnwu.magisk.utils.HideBottomViewOnScrollBehavior
|
||||
import com.topjohnwu.magisk.utils.HideTopViewOnScrollBehavior
|
||||
import com.topjohnwu.magisk.utils.HideableBehavior
|
||||
import com.topjohnwu.magisk.view.MagiskDialog
|
||||
import com.topjohnwu.magisk.view.Shortcuts
|
||||
import com.topjohnwu.superuser.Shell
|
||||
import org.koin.androidx.viewmodel.ext.android.viewModel
|
||||
|
||||
@@ -60,14 +60,8 @@ open class MainActivity : BaseUIActivity<MainViewModel, ActivityMainMd2Binding>(
|
||||
return
|
||||
}
|
||||
|
||||
if (Info.env.isUnsupported) {
|
||||
MagiskDialog(this)
|
||||
.applyTitle(R.string.unsupport_magisk_title)
|
||||
.applyMessage(R.string.unsupport_magisk_msg, Const.Version.MIN_VERSION)
|
||||
.applyButton(MagiskDialog.ButtonType.POSITIVE) { titleRes = android.R.string.ok }
|
||||
.cancellable(true)
|
||||
.reveal()
|
||||
}
|
||||
showUnsupportedMessage()
|
||||
askForHomeShortcut()
|
||||
|
||||
window.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE)
|
||||
|
||||
@@ -189,6 +183,40 @@ open class MainActivity : BaseUIActivity<MainViewModel, ActivityMainMd2Binding>(
|
||||
}
|
||||
}
|
||||
|
||||
private fun showUnsupportedMessage() {
|
||||
if (Info.env.isUnsupported) {
|
||||
MagiskDialog(this)
|
||||
.applyTitle(R.string.unsupport_magisk_title)
|
||||
.applyMessage(R.string.unsupport_magisk_msg, Const.Version.MIN_VERSION)
|
||||
.applyButton(MagiskDialog.ButtonType.POSITIVE) { titleRes = android.R.string.ok }
|
||||
.cancellable(true)
|
||||
.reveal()
|
||||
}
|
||||
}
|
||||
|
||||
private fun askForHomeShortcut() {
|
||||
// Don't bother if we are not hidden
|
||||
if (packageName == BuildConfig.APPLICATION_ID)
|
||||
return
|
||||
|
||||
if (!Config.askedHome && ShortcutManagerCompat.isRequestPinShortcutSupported(this)) {
|
||||
// Ask and show dialog
|
||||
Config.askedHome = true
|
||||
MagiskDialog(this)
|
||||
.applyTitle(R.string.add_shortcut_title)
|
||||
.applyMessage(R.string.add_shortcut_msg)
|
||||
.applyButton(MagiskDialog.ButtonType.NEGATIVE) {
|
||||
titleRes = R.string.no
|
||||
}.applyButton(MagiskDialog.ButtonType.POSITIVE) {
|
||||
titleRes = R.string.yes
|
||||
onClick {
|
||||
Shortcuts.addHomeIcon(this@MainActivity)
|
||||
}
|
||||
}.cancellable(true)
|
||||
.reveal()
|
||||
}
|
||||
}
|
||||
|
||||
companion object {
|
||||
private val ACTION_APPLICATION_PREFERENCES get() =
|
||||
if (Build.VERSION.SDK_INT >= 24) Intent.ACTION_APPLICATION_PREFERENCES
|
||||
|
||||
@@ -103,9 +103,10 @@ object Restore : BaseSettingsItem.Blank() {
|
||||
override val description = R.string.settings_restore_manager_summary.asTransitive()
|
||||
}
|
||||
|
||||
@Suppress("FunctionName")
|
||||
fun HideOrRestore() =
|
||||
if (get<Context>().packageName == BuildConfig.APPLICATION_ID) Hide else Restore
|
||||
object AddShortcut : BaseSettingsItem.Blank() {
|
||||
override val title = R.string.add_shortcut_title.asTransitive()
|
||||
override val description = R.string.setting_add_shortcut_summary.asTransitive()
|
||||
}
|
||||
|
||||
object DownloadPath : BaseSettingsItem.Input() {
|
||||
override var value = Config.downloadPath
|
||||
|
||||
@@ -1,10 +1,13 @@
|
||||
package com.topjohnwu.magisk.ui.settings
|
||||
|
||||
import android.content.Context
|
||||
import android.os.Build
|
||||
import android.view.View
|
||||
import android.widget.Toast
|
||||
import androidx.core.content.pm.ShortcutManagerCompat
|
||||
import androidx.lifecycle.viewModelScope
|
||||
import com.topjohnwu.magisk.BR
|
||||
import com.topjohnwu.magisk.BuildConfig
|
||||
import com.topjohnwu.magisk.R
|
||||
import com.topjohnwu.magisk.arch.BaseViewModel
|
||||
import com.topjohnwu.magisk.arch.adapterOf
|
||||
@@ -17,6 +20,7 @@ import com.topjohnwu.magisk.core.download.DownloadService
|
||||
import com.topjohnwu.magisk.core.download.DownloadSubject
|
||||
import com.topjohnwu.magisk.core.utils.PatchAPK
|
||||
import com.topjohnwu.magisk.data.database.RepoDao
|
||||
import com.topjohnwu.magisk.events.AddHomeIconEvent
|
||||
import com.topjohnwu.magisk.events.RecreateEvent
|
||||
import com.topjohnwu.magisk.events.dialog.BiometricDialog
|
||||
import com.topjohnwu.magisk.utils.Utils
|
||||
@@ -39,6 +43,9 @@ class SettingsViewModel(
|
||||
}
|
||||
|
||||
private fun createItems(): List<BaseSettingsItem> {
|
||||
val context = get<Context>()
|
||||
val hidden = context.packageName != BuildConfig.APPLICATION_ID
|
||||
|
||||
// Customization
|
||||
val list = mutableListOf(
|
||||
Customization,
|
||||
@@ -49,6 +56,8 @@ class SettingsViewModel(
|
||||
// making theming a pain in the ass. Just forget about it
|
||||
list.remove(Theme)
|
||||
}
|
||||
if (hidden && ShortcutManagerCompat.isRequestPinShortcutSupported(context))
|
||||
list.add(AddShortcut)
|
||||
|
||||
// Manager
|
||||
list.addAll(listOf(
|
||||
@@ -58,7 +67,7 @@ class SettingsViewModel(
|
||||
if (Info.env.isActive) {
|
||||
list.add(ClearRepoCache)
|
||||
if (Const.USER_ID == 0 && Info.isConnected.get())
|
||||
list.add(HideOrRestore())
|
||||
list.add(if (hidden) Restore else Hide)
|
||||
}
|
||||
|
||||
// Magisk
|
||||
@@ -96,6 +105,7 @@ class SettingsViewModel(
|
||||
is ClearRepoCache -> clearRepoCache()
|
||||
is SystemlessHosts -> createHosts()
|
||||
is Restore -> restoreManager()
|
||||
is AddShortcut -> AddHomeIconEvent().publish()
|
||||
else -> callback()
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user