mirror of
https://github.com/kiwix/kiwix-android.git
synced 2025-09-12 08:58:51 -04:00
Fixed: Notification not showing when downloading ZIM files in custom apps.
* The issue occurred because the notification permission was not granted. On Android 13 and above, notifications won't appear without explicit permission. * To fix this, we now properly request the notification permission on devices running Android 13 and above.
This commit is contained in:
parent
083e9b6103
commit
d70f30b86e
@ -18,11 +18,13 @@
|
|||||||
|
|
||||||
package org.kiwix.kiwixmobile.custom.download
|
package org.kiwix.kiwixmobile.custom.download
|
||||||
|
|
||||||
|
import android.Manifest.permission.POST_NOTIFICATIONS
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.view.LayoutInflater
|
import android.view.LayoutInflater
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
|
import androidx.core.app.ActivityCompat
|
||||||
import androidx.lifecycle.Observer
|
import androidx.lifecycle.Observer
|
||||||
import androidx.lifecycle.ViewModelProvider
|
import androidx.lifecycle.ViewModelProvider
|
||||||
import io.reactivex.disposables.CompositeDisposable
|
import io.reactivex.disposables.CompositeDisposable
|
||||||
@ -36,6 +38,12 @@ import org.kiwix.kiwixmobile.core.extensions.setDistinctDisplayedChild
|
|||||||
import org.kiwix.kiwixmobile.core.extensions.viewModel
|
import org.kiwix.kiwixmobile.core.extensions.viewModel
|
||||||
import org.kiwix.kiwixmobile.core.main.CoreMainActivity
|
import org.kiwix.kiwixmobile.core.main.CoreMainActivity
|
||||||
import org.kiwix.kiwixmobile.core.R
|
import org.kiwix.kiwixmobile.core.R
|
||||||
|
import org.kiwix.kiwixmobile.core.extensions.ActivityExtensions.hasNotificationPermission
|
||||||
|
import org.kiwix.kiwixmobile.core.extensions.ActivityExtensions.requestNotificationPermission
|
||||||
|
import org.kiwix.kiwixmobile.core.navigateToAppSettings
|
||||||
|
import org.kiwix.kiwixmobile.core.utils.SharedPreferenceUtil
|
||||||
|
import org.kiwix.kiwixmobile.core.utils.dialog.DialogShower
|
||||||
|
import org.kiwix.kiwixmobile.core.utils.dialog.KiwixDialog
|
||||||
import org.kiwix.kiwixmobile.custom.customActivityComponent
|
import org.kiwix.kiwixmobile.custom.customActivityComponent
|
||||||
import org.kiwix.kiwixmobile.custom.databinding.FragmentCustomDownloadBinding
|
import org.kiwix.kiwixmobile.custom.databinding.FragmentCustomDownloadBinding
|
||||||
import org.kiwix.kiwixmobile.custom.download.Action.ClickedDownload
|
import org.kiwix.kiwixmobile.custom.download.Action.ClickedDownload
|
||||||
@ -51,6 +59,14 @@ class CustomDownloadFragment : BaseFragment(), FragmentActivityExtensions {
|
|||||||
viewModel<CustomDownloadViewModel>(viewModelFactory)
|
viewModel<CustomDownloadViewModel>(viewModelFactory)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@JvmField
|
||||||
|
@Inject
|
||||||
|
var alertDialogShower: DialogShower? = null
|
||||||
|
|
||||||
|
@JvmField
|
||||||
|
@Inject
|
||||||
|
var sharedPreferenceUtil: SharedPreferenceUtil? = null
|
||||||
|
|
||||||
@Inject lateinit var viewModelFactory: ViewModelProvider.Factory
|
@Inject lateinit var viewModelFactory: ViewModelProvider.Factory
|
||||||
|
|
||||||
private var fragmentCustomDownloadBinding: FragmentCustomDownloadBinding? = null
|
private var fragmentCustomDownloadBinding: FragmentCustomDownloadBinding? = null
|
||||||
@ -81,18 +97,35 @@ class CustomDownloadFragment : BaseFragment(), FragmentActivityExtensions {
|
|||||||
|
|
||||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||||
super.onViewCreated(view, savedInstanceState)
|
super.onViewCreated(view, savedInstanceState)
|
||||||
fragmentCustomDownloadBinding?.customDownloadRequired
|
fragmentCustomDownloadBinding?.apply {
|
||||||
?.cdDownloadButton
|
customDownloadRequired.cdDownloadButton.setOnClickListener {
|
||||||
?.setOnClickListener {
|
if (requireActivity().hasNotificationPermission(sharedPreferenceUtil)) {
|
||||||
downloadViewModel.actions.offer(
|
downloadViewModel.actions.offer(ClickedDownload)
|
||||||
ClickedDownload
|
} else {
|
||||||
)
|
requestNotificationPermission()
|
||||||
}
|
}
|
||||||
fragmentCustomDownloadBinding?.customDownloadError
|
}
|
||||||
?.cdRetryButton
|
customDownloadError.cdRetryButton.setOnClickListener {
|
||||||
?.setOnClickListener {
|
if (requireActivity().hasNotificationPermission(sharedPreferenceUtil)) {
|
||||||
downloadViewModel.actions.offer(
|
downloadViewModel.actions.offer(ClickedRetry)
|
||||||
ClickedRetry
|
} else {
|
||||||
|
requestNotificationPermission()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun requestNotificationPermission() {
|
||||||
|
if (!ActivityCompat.shouldShowRequestPermissionRationale(
|
||||||
|
requireActivity(),
|
||||||
|
POST_NOTIFICATIONS
|
||||||
|
)
|
||||||
|
) {
|
||||||
|
requireActivity().requestNotificationPermission()
|
||||||
|
} else {
|
||||||
|
alertDialogShower?.show(
|
||||||
|
KiwixDialog.NotificationPermissionDialog,
|
||||||
|
requireActivity()::navigateToAppSettings
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user