Add system settings shortcut
MODIFY
app/src/main/java/io/github/wulkanowy/ui/modules/about/AboutFragment.kt
app/src/main/java/io/github/wulkanowy/ui/modules/about/AboutFragment.kt
@@ -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,

MODIFY
app/src/main/java/io/github/wulkanowy/ui/modules/settings/notifications/NotificationsFragment.kt
app/src/main/java/io/github/wulkanowy/ui/modules/settings/notifications/NotificationsFragment.kt
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)

MODIFY
app/src/main/java/io/github/wulkanowy/ui/modules/settings/notifications/NotificationsPresenter.kt
app/src/main/java/io/github/wulkanowy/ui/modules/settings/notifications/NotificationsPresenter.kt
@@ -55,4 +55,8 @@ class NotificationsPresenter @Inject constructor(
fun onFixSyncIssuesClicked() {
view?.showFixSyncDialog()
}
+
+ fun onOpenSystemSettingsClicked() {
+ view?.openSystemSettings()
+ }
}

MODIFY
app/src/main/java/io/github/wulkanowy/ui/modules/settings/notifications/NotificationsView.kt
app/src/main/java/io/github/wulkanowy/ui/modules/settings/notifications/NotificationsView.kt
@@ -8,5 +8,7 @@ interface NotificationsView : BaseView {
fun showFixSyncDialog()
+ fun openSystemSettings()
+
fun enableNotification(notificationKey: String, enable: Boolean)
}

MODIFY
app/src/main/res/values/preferences_keys.xml
app/src/main/res/values/preferences_keys.xml
<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>

MODIFY
app/src/main/res/values/strings.xml
app/src/main/res/values/strings.xml
<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>
<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 &amp; 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>

MODIFY
app/src/main/res/xml/scheme_preferences_notifications.xml
app/src/main/res/xml/scheme_preferences_notifications.xml
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"

Add system settings shortcut (#1271)