Skip to content
Snippets Groups Projects
Commit 254f4f16 authored by Nicolas Pomepuy's avatar Nicolas Pomepuy Committed by Duncan McNamara
Browse files

Ask for notification on app startup if needed

parent 0b2c0d23
No related branches found
No related tags found
1 merge request!1564Backport 3.5.x: !1537
......@@ -180,6 +180,8 @@ const val WIDGETS_BACKGROUND_LAST_COLORS = "widgets_background_last_colors"
const val WIDGETS_FOREGROUND_LAST_COLORS = "widgets_foreground_last_colors"
const val CUSTOM_POPUP_HEIGHT = "custom_popup_height"
const val NOTIFICATION_PERMISSION_ASKED = "notification_permission_asked"
//files
const val BROWSER_SHOW_HIDDEN_FILES = "browser_show_hidden_files"
......
<?xml version="1.0" encoding="utf-8"?><!--
~ *************************************************************************
~ dialog_widget_migration.xml
~ **************************************************************************
~ Copyright © 2022 VLC authors and VideoLAN
~ Author: Nicolas POMEPUY
~ This program is free software; you can redistribute it and/or modify
~ it under the terms of the GNU General Public License as published by
~ the Free Software Foundation; either version 2 of the License, or
~ (at your option) any later version.
~
~ This program is distributed in the hope that it will be useful,
~ but WITHOUT ANY WARRANTY; without even the implied warranty of
~ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
~ GNU General Public License for more details.
~
~ You should have received a copy of the GNU General Public License
~ along with this program; if not, write to the Free Software
~ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
~ ***************************************************************************
~
~
-->
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<data>
<import type="android.view.View" />
</data>
<androidx.core.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/title"
style="@style/Theme.VLC.BottomSheetTitle"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:paddingLeft="16dp"
android:paddingRight="16dp"
android:text="@string/notification_permission"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="@+id/notfication_permission_text"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="16dp"
android:text="@string/notification_permission_explanation"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/title" />
<Button
android:id="@+id/ok_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="24dp"
android:layout_marginEnd="16dp"
android:layout_marginBottom="16dp"
android:text="@string/ok"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="@+id/notfication_permission_text" />
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.core.widget.NestedScrollView>
</layout>
......@@ -48,6 +48,7 @@ import org.videolan.vlc.gui.audio.AudioBrowserFragment
import org.videolan.vlc.gui.browser.BaseBrowserFragment
import org.videolan.vlc.gui.browser.ExtensionBrowser
import org.videolan.vlc.gui.dialogs.AllAccessPermissionDialog
import org.videolan.vlc.gui.dialogs.NotificationPermissionManager
import org.videolan.vlc.gui.helpers.INavigator
import org.videolan.vlc.gui.helpers.Navigator
import org.videolan.vlc.gui.helpers.UiTools
......@@ -99,6 +100,7 @@ class MainActivity : ContentActivity(),
// VLCBilling.getInstance(application).retrieveSkus()
WidgetMigration.launchIfNeeded(this)
NotificationPermissionManager.launchIfNeeded(this)
}
override fun onResume() {
......
/*
* ************************************************************************
* WidgetMigrationDialog.kt
* *************************************************************************
* Copyright © 2022 VLC authors and VideoLAN
* Author: Nicolas POMEPUY
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
* **************************************************************************
*
*
*/
package org.videolan.vlc.gui.dialogs
import android.content.DialogInterface
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.core.content.edit
import androidx.fragment.app.FragmentActivity
import androidx.lifecycle.lifecycleScope
import com.google.android.material.bottomsheet.BottomSheetBehavior.STATE_EXPANDED
import kotlinx.coroutines.launch
import org.videolan.tools.NOTIFICATION_PERMISSION_ASKED
import org.videolan.tools.Settings
import org.videolan.vlc.databinding.DialogNorificationPermissionBinding
import org.videolan.vlc.gui.helpers.hf.NotificationDelegate.Companion.getNotificationPermission
import org.videolan.vlc.util.Permissions
class NotificationPermissionDialog : VLCBottomSheetDialogFragment() {
override fun getDefaultState(): Int = STATE_EXPANDED
override fun needToManageOrientation(): Boolean = false
private lateinit var binding: DialogNorificationPermissionBinding
override fun initialFocusedView(): View = binding.title
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View {
binding = DialogNorificationPermissionBinding.inflate(layoutInflater, container, false)
binding.okButton.setOnClickListener {
dismiss()
}
return binding.root
}
override fun onDismiss(dialog: DialogInterface) {
Settings.getInstance(requireActivity()).edit {
putBoolean(NOTIFICATION_PERMISSION_ASKED, true)
}
lifecycleScope.launch { requireActivity().getNotificationPermission() }
super.onDismiss(dialog)
}
}
object NotificationPermissionManager {
fun launchIfNeeded(activity: FragmentActivity) {
if(!Permissions.canSendNotifications(activity) && !Settings.getInstance(activity).getBoolean(NOTIFICATION_PERMISSION_ASKED, false)) {
val notificationPermissionDialog = NotificationPermissionDialog()
notificationPermissionDialog.show(activity.supportFragmentManager, "fragment_notification_permission")
}
}
}
......@@ -105,6 +105,9 @@ class OnboardingActivity : AppCompatActivity(), OnboardingFragmentListener {
lifecycleScope.launch {
viewModel.notificationPermissionAlreadyAsked = true
getNotificationPermission()
Settings.getInstance(this@OnboardingActivity).edit {
putBoolean(NOTIFICATION_PERMISSION_ASKED, true)
}
onNext()
}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment