-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1674 from Infomaniak/OnBoarding-notif
Permissions On boarding
- Loading branch information
Showing
29 changed files
with
2,453 additions
and
156 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
97 changes: 97 additions & 0 deletions
97
app/src/main/java/com/infomaniak/mail/ui/main/onboarding/PermissionsOnboardingFragment.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
/* | ||
* Infomaniak Mail - Android | ||
* Copyright (C) 2024 Infomaniak Network SA | ||
* | ||
* 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 3 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, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
package com.infomaniak.mail.ui.main.onboarding | ||
|
||
import android.content.res.ColorStateList | ||
import android.os.Bundle | ||
import android.view.LayoutInflater | ||
import android.view.View | ||
import android.view.ViewGroup | ||
import androidx.annotation.DrawableRes | ||
import androidx.annotation.StringRes | ||
import androidx.fragment.app.Fragment | ||
import androidx.navigation.fragment.navArgs | ||
import com.infomaniak.lib.core.utils.safeBinding | ||
import com.infomaniak.mail.R | ||
import com.infomaniak.mail.data.LocalSettings | ||
import com.infomaniak.mail.data.LocalSettings.* | ||
import com.infomaniak.mail.databinding.FragmentPermissionsOnboardingBinding | ||
import dagger.hilt.android.AndroidEntryPoint | ||
import javax.inject.Inject | ||
|
||
@AndroidEntryPoint | ||
class PermissionsOnboardingFragment : Fragment() { | ||
|
||
private var binding: FragmentPermissionsOnboardingBinding by safeBinding() | ||
private val navigationArgs: PermissionsOnboardingFragmentArgs by navArgs() | ||
|
||
@Inject | ||
lateinit var localSettings: LocalSettings | ||
|
||
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View { | ||
return FragmentPermissionsOnboardingBinding.inflate(inflater, container, false).also { binding = it }.root | ||
} | ||
|
||
override fun onViewCreated(view: View, savedInstanceState: Bundle?): Unit = with(binding) { | ||
super.onViewCreated(view, savedInstanceState) | ||
setPermissionUi() | ||
} | ||
|
||
private fun setPermissionUi() = with(binding) { | ||
val permission = if (navigationArgs.position == 0) PermissionType.CONTACTS else PermissionType.NOTIFICATIONS | ||
iconLayout.setImageResource(getIconResWithAccentColor(permission)) | ||
title.setText(permission.titleRes) | ||
description.setText(permission.descritionRes) | ||
waveBackground.apply { | ||
setImageResource(permission.waveRes) | ||
imageTintList = ColorStateList.valueOf(localSettings.accentColor.getOnboardingSecondaryBackground(context)) | ||
} | ||
} | ||
|
||
private fun getIconResWithAccentColor(permission: PermissionType) = when (localSettings.accentColor) { | ||
AccentColor.PINK -> permission.pinkIconRes | ||
AccentColor.BLUE -> permission.blueIconRes | ||
AccentColor.SYSTEM -> permission.systemIconRes | ||
} | ||
|
||
enum class PermissionType( | ||
@DrawableRes val pinkIconRes: Int, | ||
@DrawableRes val blueIconRes: Int, | ||
@DrawableRes val systemIconRes: Int, | ||
@StringRes val titleRes: Int, | ||
@StringRes val descritionRes: Int, | ||
@DrawableRes val waveRes: Int, | ||
) { | ||
CONTACTS( | ||
pinkIconRes = R.drawable.illustration_onboarding_contacts, | ||
blueIconRes = R.drawable.illustration_onboarding_contacts_blue, | ||
systemIconRes = R.drawable.illustration_onboarding_contacts_material, | ||
titleRes = R.string.onBoardingContactsTitle, | ||
descritionRes = R.string.onBoardingContactsDescription, | ||
waveRes = R.drawable.ic_back_wave_1, | ||
), | ||
NOTIFICATIONS( | ||
pinkIconRes = R.drawable.illustration_onboarding_notifications, | ||
blueIconRes = R.drawable.illustration_onboarding_notifications_blue, | ||
systemIconRes = R.drawable.illustration_onboarding_notifications_material, | ||
titleRes = R.string.onBoardingNotificationsTitle, | ||
descritionRes = R.string.onBoardingNotificationsDescription, | ||
waveRes = R.drawable.ic_back_wave_2, | ||
), | ||
} | ||
} |
106 changes: 106 additions & 0 deletions
106
...rc/main/java/com/infomaniak/mail/ui/main/onboarding/PermissionsOnboardingPagerFragment.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
/* | ||
* Infomaniak Mail - Android | ||
* Copyright (C) 2024 Infomaniak Network SA | ||
* | ||
* 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 3 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, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
package com.infomaniak.mail.ui.main.onboarding | ||
|
||
import android.os.Bundle | ||
import android.view.LayoutInflater | ||
import android.view.View | ||
import android.view.ViewGroup | ||
import androidx.fragment.app.Fragment | ||
import androidx.fragment.app.activityViewModels | ||
import androidx.viewpager2.widget.ViewPager2 | ||
import com.infomaniak.lib.core.utils.context | ||
import com.infomaniak.lib.core.utils.safeBinding | ||
import com.infomaniak.lib.core.utils.safeNavigate | ||
import com.infomaniak.mail.R | ||
import com.infomaniak.mail.data.LocalSettings | ||
import com.infomaniak.mail.databinding.FragmentPermissionsOnboardingPagerBinding | ||
import com.infomaniak.mail.ui.MainViewModel | ||
import com.infomaniak.mail.utils.PermissionUtils | ||
import com.infomaniak.mail.utils.removeOverScrollForApiBelow31 | ||
import dagger.hilt.android.AndroidEntryPoint | ||
import javax.inject.Inject | ||
|
||
@AndroidEntryPoint | ||
class PermissionsOnboardingPagerFragment : Fragment() { | ||
|
||
private var binding: FragmentPermissionsOnboardingPagerBinding by safeBinding() | ||
private val mainViewModel: MainViewModel by activityViewModels() | ||
private var currentPosition = 0 | ||
|
||
@Inject | ||
lateinit var localSettings: LocalSettings | ||
|
||
@Inject | ||
lateinit var permissionUtils: PermissionUtils | ||
|
||
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View { | ||
return FragmentPermissionsOnboardingPagerBinding.inflate(inflater, container, false).also { binding = it }.root | ||
} | ||
|
||
override fun onViewCreated(view: View, savedInstanceState: Bundle?): Unit = with(binding) { | ||
super.onViewCreated(view, savedInstanceState) | ||
|
||
requireActivity().window.statusBarColor = localSettings.accentColor.getOnboardingSecondaryBackground(context) | ||
|
||
permissionUtils.apply { | ||
registerReadContactsPermission(fragment = this@PermissionsOnboardingPagerFragment) | ||
registerNotificationsPermissionIfNeeded(fragment = this@PermissionsOnboardingPagerFragment) | ||
} | ||
|
||
permissionsViewpager.apply { | ||
adapter = PermissionsPagerAdapter(childFragmentManager, viewLifecycleOwner.lifecycle) | ||
isUserInputEnabled = false | ||
savedInstanceState?.getInt(VIEW_PAGER_POSITION_KEY)?.let { setCurrentItem(it, false) } | ||
removeOverScrollForApiBelow31() | ||
} | ||
|
||
continueButton.setOnClickListener { | ||
when (permissionsViewpager.currentItem) { | ||
0 -> { | ||
permissionUtils.requestReadContactsPermission { hasPermission -> | ||
if (hasPermission) mainViewModel.updateUserInfo() | ||
if (permissionsViewpager.isLastPage()) { | ||
leaveOnboarding() | ||
} else { | ||
currentPosition += 1 | ||
permissionsViewpager.currentItem += 1 | ||
} | ||
} | ||
} | ||
1 -> permissionUtils.requestNotificationsPermissionIfNeeded { leaveOnboarding() } | ||
} | ||
} | ||
} | ||
|
||
override fun onSaveInstanceState(outState: Bundle) { | ||
outState.putInt(VIEW_PAGER_POSITION_KEY, currentPosition) | ||
super.onSaveInstanceState(outState) | ||
} | ||
|
||
private fun ViewPager2.isLastPage() = adapter?.let { currentItem == it.itemCount - 1 } ?: true | ||
|
||
fun leaveOnboarding() { | ||
localSettings.showPermissionsOnboarding = false | ||
safeNavigate(R.id.threadListFragment) | ||
} | ||
|
||
companion object { | ||
private const val VIEW_PAGER_POSITION_KEY = "viewPagerPositionKey" | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
app/src/main/java/com/infomaniak/mail/ui/main/onboarding/PermissionsPagerAdapter.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/* | ||
* Infomaniak Mail - Android | ||
* Copyright (C) 2024 Infomaniak Network SA | ||
* | ||
* 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 3 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, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
package com.infomaniak.mail.ui.main.onboarding | ||
|
||
import androidx.fragment.app.FragmentManager | ||
import androidx.lifecycle.Lifecycle | ||
import androidx.viewpager2.adapter.FragmentStateAdapter | ||
import com.infomaniak.mail.utils.PermissionUtils | ||
|
||
class PermissionsPagerAdapter(manager: FragmentManager, lifecycle: Lifecycle) : FragmentStateAdapter(manager, lifecycle) { | ||
|
||
override fun getItemCount() = PermissionUtils.getMainPermissions(mustRequireNotification = true).count() | ||
|
||
override fun createFragment(position: Int) = PermissionsOnboardingFragment().apply { | ||
arguments = PermissionsOnboardingFragmentArgs(position).toBundle() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.