Browse Source

Ask for notification on app startup if needed

merge-requests/1614/head
Nicolas Pomepuy 4 years ago
committed by Duncan McNamara
parent
commit
94449a6b5a
  1. 2
      application/tools/src/main/java/org/videolan/tools/Settings.kt
  2. 81
      application/vlc-android/res/layout/dialog_norification_permission.xml
  3. 2
      application/vlc-android/src/org/videolan/vlc/gui/MainActivity.kt
  4. 79
      application/vlc-android/src/org/videolan/vlc/gui/dialogs/NotificationPermissionDialog.kt
  5. 3
      application/vlc-android/src/org/videolan/vlc/gui/onboarding/OnboardingActivity.kt

2
application/tools/src/main/java/org/videolan/tools/Settings.kt

@ -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"

81
application/vlc-android/res/layout/dialog_norification_permission.xml

@ -0,0 +1,81 @@
<?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>

2
application/vlc-android/src/org/videolan/vlc/gui/MainActivity.kt

@ -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() {

79
application/vlc-android/src/org/videolan/vlc/gui/dialogs/NotificationPermissionDialog.kt

@ -0,0 +1,79 @@
/*
* ************************************************************************
* 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")
}
}
}

3
application/vlc-android/src/org/videolan/vlc/gui/onboarding/OnboardingActivity.kt

@ -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()
}
}

Loading…
Cancel
Save