diff --git a/app/src/main/java/io/github/wulkanowy/ui/modules/about/AboutFragment.kt b/app/src/main/java/io/github/wulkanowy/ui/modules/about/AboutFragment.kt index 1c613800..badf78fd 100644 --- a/app/src/main/java/io/github/wulkanowy/ui/modules/about/AboutFragment.kt +++ b/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(R.layout.fragment_about), AboutView, diff --git a/app/src/main/java/io/github/wulkanowy/ui/modules/settings/notifications/NotificationsFragment.kt b/app/src/main/java/io/github/wulkanowy/ui/modules/settings/notifications/NotificationsFragment.kt index a9641d88..96d14a1b 100644 --- a/app/src/main/java/io/github/wulkanowy/ui/modules/settings/notifications/NotificationsFragment.kt +++ b/app/src/main/java/io/github/wulkanowy/ui/modules/settings/notifications/NotificationsFragment.kt @@ -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(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) diff --git a/app/src/main/java/io/github/wulkanowy/ui/modules/settings/notifications/NotificationsPresenter.kt b/app/src/main/java/io/github/wulkanowy/ui/modules/settings/notifications/NotificationsPresenter.kt index 981af17d..8366d309 100644 --- a/app/src/main/java/io/github/wulkanowy/ui/modules/settings/notifications/NotificationsPresenter.kt +++ b/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() + } } diff --git a/app/src/main/java/io/github/wulkanowy/ui/modules/settings/notifications/NotificationsView.kt b/app/src/main/java/io/github/wulkanowy/ui/modules/settings/notifications/NotificationsView.kt index 2618cde1..2ab9b035 100644 --- a/app/src/main/java/io/github/wulkanowy/ui/modules/settings/notifications/NotificationsView.kt +++ b/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) } diff --git a/app/src/main/res/values/preferences_keys.xml b/app/src/main/res/values/preferences_keys.xml index 1d00dcd6..5a758709 100644 --- a/app/src/main/res/values/preferences_keys.xml +++ b/app/src/main/res/values/preferences_keys.xml @@ -14,6 +14,7 @@ services_disable_wifi_only services_force_sync notifications_fix_issues + notifications_system_settings notifications_enable notifications_upcoming_lessons_enable notification_debug diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index c81c2c61..27779e7d 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -385,6 +385,8 @@ Like our facebook fanpage Privacy policy Rules for collecting personal data + System settings + Open system settings Homepage Visit the website and help develop the application Licenses @@ -490,6 +492,7 @@ Notifications Show notifications Show upcoming lesson notifications + Open system notification settings Fix synchronization & notifications issues 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. Go to settings diff --git a/app/src/main/res/xml/scheme_preferences_notifications.xml b/app/src/main/res/xml/scheme_preferences_notifications.xml index 3d435ca8..ac88746c 100644 --- a/app/src/main/res/xml/scheme_preferences_notifications.xml +++ b/app/src/main/res/xml/scheme_preferences_notifications.xml @@ -20,6 +20,10 @@ app:key="@string/pref_key_notification_debug" app:singleLineTitle="false" app:title="@string/pref_notify_debug_switch" /> +