feat: 优化代码

pull/103/head
kunfei 5 years ago
parent a6891c89f5
commit b794d09005
  1. 4
      app/src/main/AndroidManifest.xml
  2. 54
      app/src/main/java/io/legado/app/help/LauncherIconHelp.kt
  3. 4
      app/src/main/java/io/legado/app/ui/config/ThemeConfigFragment.kt
  4. 2
      app/src/main/java/io/legado/app/ui/welcome/WelcomeActivity.kt
  5. 0
      app/src/main/res/mipmap-anydpi-v26/launcher1.xml
  6. 2
      app/src/main/res/values/arrays.xml

@ -38,8 +38,8 @@
</activity>
<!--图标1-->
<activity
android:name=".ui.welcome.Icon1Activity"
android:icon="@mipmap/ic_launcher_1"
android:name=".ui.welcome.Launcher1"
android:icon="@mipmap/launcher1"
android:enabled="false">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

@ -0,0 +1,54 @@
package io.legado.app.help
import android.content.ComponentName
import android.content.pm.PackageManager
import android.os.Build
import io.legado.app.App
import io.legado.app.ui.welcome.Launcher1
import io.legado.app.ui.welcome.WelcomeActivity
import org.jetbrains.anko.toast
/**
* Created by GKF on 2018/2/27.
* 更换图标
*/
object LauncherIconHelp {
private val packageManager: PackageManager = App.INSTANCE.packageManager
private val componentNames = arrayListOf(
ComponentName(App.INSTANCE, Launcher1::class.java.name)
)
fun changeIcon(icon: String?) {
if (icon.isNullOrEmpty()) return
if (Build.VERSION.SDK_INT < 26) {
App.INSTANCE.toast("图标为矢量图标,Android8.0一下不支持")
return
}
var hasEnabled = false
componentNames.forEach {
if (it.className.equals(icon, true)) {
hasEnabled = true
//启用
packageManager.setComponentEnabledSetting(
it,
PackageManager.COMPONENT_ENABLED_STATE_ENABLED,
PackageManager.DONT_KILL_APP
)
} else {
//禁用
packageManager.setComponentEnabledSetting(
it,
PackageManager.COMPONENT_ENABLED_STATE_DISABLED,
PackageManager.DONT_KILL_APP
)
}
}
if (!hasEnabled) {
packageManager.setComponentEnabledSetting(
ComponentName(App.INSTANCE, WelcomeActivity::class.java.name),
PackageManager.COMPONENT_ENABLED_STATE_ENABLED,
PackageManager.DONT_KILL_APP
)
}
}
}

@ -11,6 +11,7 @@ import io.legado.app.App
import io.legado.app.R
import io.legado.app.constant.EventBus
import io.legado.app.help.AppConfig
import io.legado.app.help.LauncherIconHelp
import io.legado.app.lib.dialogs.alert
import io.legado.app.lib.dialogs.noButton
import io.legado.app.lib.dialogs.yesButton
@ -26,7 +27,7 @@ class ThemeConfigFragment : PreferenceFragmentCompat(), SharedPreferences.OnShar
override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) {
addPreferencesFromResource(R.xml.pref_config_theme)
findPreference<Preference>("defaultTheme")?.summary = "${items[getPrefInt("default_theme", 0)]}"
findPreference<Preference>("defaultTheme")?.summary = items[getPrefInt("default_theme", 0)]
}
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
@ -47,6 +48,7 @@ class ThemeConfigFragment : PreferenceFragmentCompat(), SharedPreferences.OnShar
override fun onSharedPreferenceChanged(sharedPreferences: SharedPreferences?, key: String?) {
sharedPreferences ?: return
when (key) {
"launcherIcon" -> LauncherIconHelp.changeIcon(getPrefString(key))
"transparentStatusBar" -> {
recreateActivities()
}

@ -48,4 +48,4 @@ open class WelcomeActivity : BaseActivity(R.layout.activity_welcome) {
}
class Icon1Activity : WelcomeActivity()
class Launcher1 : WelcomeActivity()

@ -139,7 +139,7 @@
<string-array name="icons">
<item>ic_launcher</item>
<item>ic_launcher_1</item>
<item>launcher1</item>
</string-array>
<string-array name="chinese_mode">

Loading…
Cancel
Save