forked from github/wulkanowy-mirror
Add system settings shortcut (#1271)
This commit is contained in:
parent
bd2d26418a
commit
f131edf857
@ -21,6 +21,10 @@ import io.github.wulkanowy.utils.openInternetBrowser
|
||||
import io.github.wulkanowy.utils.toFormattedString
|
||||
import io.github.wulkanowy.utils.toLocalDateTime
|
||||
import javax.inject.Inject
|
||||
import android.content.Intent
|
||||
import android.net.Uri
|
||||
import android.provider.Settings
|
||||
import android.util.Log
|
||||
|
||||
@AndroidEntryPoint
|
||||
class AboutFragment : BaseFragment<FragmentAboutBinding>(R.layout.fragment_about), AboutView,
|
||||
|
@ -1,7 +1,12 @@
|
||||
package io.github.wulkanowy.ui.modules.settings.notifications
|
||||
|
||||
import android.annotation.SuppressLint
|
||||
import android.content.Intent
|
||||
import android.content.SharedPreferences
|
||||
import android.net.Uri
|
||||
import android.os.Build
|
||||
import android.os.Bundle
|
||||
import android.provider.Settings
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
@ -16,7 +21,9 @@ import io.github.wulkanowy.R
|
||||
import io.github.wulkanowy.ui.base.BaseActivity
|
||||
import io.github.wulkanowy.ui.base.ErrorDialog
|
||||
import io.github.wulkanowy.ui.modules.main.MainView
|
||||
import io.github.wulkanowy.utils.AppInfo
|
||||
import io.github.wulkanowy.utils.openInternetBrowser
|
||||
import timber.log.Timber
|
||||
import javax.inject.Inject
|
||||
|
||||
@AndroidEntryPoint
|
||||
@ -27,6 +34,9 @@ class NotificationsFragment : PreferenceFragmentCompat(),
|
||||
@Inject
|
||||
lateinit var presenter: NotificationsPresenter
|
||||
|
||||
@Inject
|
||||
lateinit var appInfo: AppInfo
|
||||
|
||||
companion object {
|
||||
fun newInstance() = NotificationsFragment()
|
||||
}
|
||||
@ -46,6 +56,13 @@ class NotificationsFragment : PreferenceFragmentCompat(),
|
||||
true
|
||||
}
|
||||
}
|
||||
|
||||
findPreference<Preference>(getString(R.string.pref_key_notifications_system_settings))?.run {
|
||||
setOnPreferenceClickListener {
|
||||
presenter.onOpenSystemSettingsClicked()
|
||||
true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun onCreateRecyclerView(
|
||||
@ -118,6 +135,24 @@ class NotificationsFragment : PreferenceFragmentCompat(),
|
||||
.show()
|
||||
}
|
||||
|
||||
@SuppressLint("InlinedApi")
|
||||
override fun openSystemSettings() {
|
||||
val intent = if (appInfo.systemVersion >= Build.VERSION_CODES.O) {
|
||||
Intent(Settings.ACTION_APP_NOTIFICATION_SETTINGS).apply {
|
||||
putExtra("android.provider.extra.APP_PACKAGE", requireActivity().packageName)
|
||||
}
|
||||
} else {
|
||||
Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS).apply {
|
||||
data = Uri.fromParts("package", requireActivity().packageName, null)
|
||||
}
|
||||
}
|
||||
try {
|
||||
requireActivity().startActivity(intent)
|
||||
} catch (e: Exception) {
|
||||
Timber.e(e)
|
||||
}
|
||||
}
|
||||
|
||||
override fun onResume() {
|
||||
super.onResume()
|
||||
preferenceScreen.sharedPreferences.registerOnSharedPreferenceChangeListener(this)
|
||||
|
@ -55,4 +55,8 @@ class NotificationsPresenter @Inject constructor(
|
||||
fun onFixSyncIssuesClicked() {
|
||||
view?.showFixSyncDialog()
|
||||
}
|
||||
|
||||
fun onOpenSystemSettingsClicked() {
|
||||
view?.openSystemSettings()
|
||||
}
|
||||
}
|
||||
|
@ -8,5 +8,7 @@ interface NotificationsView : BaseView {
|
||||
|
||||
fun showFixSyncDialog()
|
||||
|
||||
fun openSystemSettings()
|
||||
|
||||
fun enableNotification(notificationKey: String, enable: Boolean)
|
||||
}
|
||||
|
@ -14,6 +14,7 @@
|
||||
<string name="pref_key_services_wifi_only">services_disable_wifi_only</string>
|
||||
<string name="pref_key_services_force_sync">services_force_sync</string>
|
||||
<string name="pref_key_notifications_fix_issues">notifications_fix_issues</string>
|
||||
<string name="pref_key_notifications_system_settings">notifications_system_settings</string>
|
||||
<string name="pref_key_notifications_enable">notifications_enable</string>
|
||||
<string name="pref_key_notifications_upcoming_lessons_enable">notifications_upcoming_lessons_enable</string>
|
||||
<string name="pref_key_notification_debug">notification_debug</string>
|
||||
|
@ -385,6 +385,8 @@
|
||||
<string name="about_facebook_summary">Like our facebook fanpage</string>
|
||||
<string name="about_privacy">Privacy policy</string>
|
||||
<string name="about_privacy_summary">Rules for collecting personal data</string>
|
||||
<string name="about_system">System settings</string>
|
||||
<string name="about_system_summary">Open system settings</string>
|
||||
<string name="about_homepage">Homepage</string>
|
||||
<string name="about_homepage_summary">Visit the website and help develop the application</string>
|
||||
<string name="about_licenses">Licenses</string>
|
||||
@ -490,6 +492,7 @@
|
||||
<string name="pref_notify_header">Notifications</string>
|
||||
<string name="pref_notify_switch">Show notifications</string>
|
||||
<string name="pref_notify_upcoming_lessons_switch">Show upcoming lesson notifications</string>
|
||||
<string name="pref_notify_open_system_settings">Open system notification settings</string>
|
||||
<string name="pref_notify_fix_sync_issues">Fix synchronization & notifications issues</string>
|
||||
<string name="pref_notify_fix_sync_issues_message">Your device may have data synchronization issues and with notifications.\n\nTo fix them, you need to add Wulkanowy to the autostart and turn off battery optimization/saving in the phone settings.</string>
|
||||
<string name="pref_notify_fix_sync_issues_settings_button">Go to settings</string>
|
||||
|
@ -20,6 +20,10 @@
|
||||
app:key="@string/pref_key_notification_debug"
|
||||
app:singleLineTitle="false"
|
||||
app:title="@string/pref_notify_debug_switch" />
|
||||
<Preference
|
||||
app:iconSpaceReserved="false"
|
||||
app:key="@string/pref_key_notifications_system_settings"
|
||||
app:title="@string/pref_notify_open_system_settings" />
|
||||
<Preference
|
||||
app:iconSpaceReserved="false"
|
||||
app:isPreferenceVisible="false"
|
||||
|
Loading…
x
Reference in New Issue
Block a user