Added in-app settings shortcut from system settings

This commit is contained in:
Viktor De Pasquale 2019-10-06 12:20:05 +02:00
parent 8024089bde
commit 8999a57f06
5 changed files with 34 additions and 4 deletions

View File

@ -36,6 +36,16 @@
<category android:name="android.intent.category.LAUNCHER" /> <category android:name="android.intent.category.LAUNCHER" />
</intent-filter> </intent-filter>
</activity> </activity>
<activity-alias
android:name="a.s"
android:targetActivity="a.c">
<intent-filter>
<action android:name="android.intent.action.APPLICATION_PREFERENCES" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity-alias>
<activity <activity
android:name="a.f" android:name="a.f"
android:configChanges="keyboardHidden|orientation|screenSize" android:configChanges="keyboardHidden|orientation|screenSize"

View File

@ -59,6 +59,7 @@ object Const {
const val ETAG_KEY = "ETag" const val ETAG_KEY = "ETag"
// intents // intents
const val OPEN_SECTION = "section" const val OPEN_SECTION = "section"
const val OPEN_SETTINGS = "settings"
const val INTENT_SET_APP = "app_json" const val INTENT_SET_APP = "app_json"
const val FLASH_ACTION = "action" const val FLASH_ACTION = "action"
const val FLASH_DATA = "additional_data" const val FLASH_DATA = "additional_data"

View File

@ -2,6 +2,7 @@ package com.topjohnwu.magisk.model.navigation
import android.content.Context import android.content.Context
import android.content.Intent import android.content.Intent
import android.os.Build
import com.topjohnwu.magisk.ClassMap import com.topjohnwu.magisk.ClassMap
import com.topjohnwu.magisk.Config import com.topjohnwu.magisk.Config
import com.topjohnwu.magisk.Const import com.topjohnwu.magisk.Const
@ -74,12 +75,23 @@ object Navigation {
Config.redesign -> RedesignActivity::class.java Config.redesign -> RedesignActivity::class.java
else -> MainActivity::class.java else -> MainActivity::class.java
} }
val intent = Intent(context, ClassMap[destination]) Intent(context, ClassMap[destination])
intent.putExtra(Const.Key.OPEN_SECTION, launchIntent.getStringExtra(Const.Key.OPEN_SECTION)) .putExtra(Const.Key.OPEN_SECTION, launchIntent.getStringExtra(Const.Key.OPEN_SECTION))
context.startActivity(intent) .putExtra(
Const.Key.OPEN_SETTINGS,
launchIntent.action == ACTION_APPLICATION_PREFERENCES
)
.also { context.startActivity(it) }
} }
object Main { object Main {
const val OPEN_NAV = 1 const val OPEN_NAV = 1
} }
private val ACTION_APPLICATION_PREFERENCES
get() = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
Intent.ACTION_APPLICATION_PREFERENCES
} else {
"cannot be null, cannot be empty"
}
} }

View File

@ -4,6 +4,7 @@ import android.graphics.Insets
import android.os.Bundle import android.os.Bundle
import androidx.fragment.app.Fragment import androidx.fragment.app.Fragment
import com.ncapdevi.fragnav.FragNavController import com.ncapdevi.fragnav.FragNavController
import com.topjohnwu.magisk.Const
import com.topjohnwu.magisk.R import com.topjohnwu.magisk.R
import com.topjohnwu.magisk.databinding.ActivityMainMd2Binding import com.topjohnwu.magisk.databinding.ActivityMainMd2Binding
import com.topjohnwu.magisk.model.navigation.Navigation import com.topjohnwu.magisk.model.navigation.Navigation
@ -44,9 +45,13 @@ open class MainActivity : CompatActivity<MainViewModel, ActivityMainMd2Binding>(
R.id.logFragment -> Navigation.log() R.id.logFragment -> Navigation.log()
R.id.settingsFragment -> Navigation.settings() R.id.settingsFragment -> Navigation.settings()
else -> throw NotImplementedError("Id ${it.itemId} is not defined as selectable") else -> throw NotImplementedError("Id ${it.itemId} is not defined as selectable")
}.also { onEventDispatched(it) } }.dispatchOnSelf()
true true
} }
if (intent.getBooleanExtra(Const.Key.OPEN_SETTINGS, false)) {
binding.mainNavigation.selectedItemId = R.id.settingsFragment
}
} }
override fun onTabTransaction(fragment: Fragment?, index: Int) { override fun onTabTransaction(fragment: Fragment?, index: Int) {

View File

@ -31,4 +31,6 @@ abstract class CompatActivity<ViewModel : CompatViewModel, Binding : ViewDataBin
delegate.onEventExecute(event, this) delegate.onEventExecute(event, this)
} }
protected fun ViewEvent.dispatchOnSelf() = onEventDispatched(this)
} }