Skip to content

Commit

Permalink
Add code to do forward to age verification.
Browse files Browse the repository at this point in the history
  • Loading branch information
mopsalarm committed Oct 1, 2021
1 parent 39e8ac2 commit 1590c4c
Show file tree
Hide file tree
Showing 6 changed files with 70 additions and 19 deletions.
53 changes: 39 additions & 14 deletions app/src/main/java/com/pr0gramm/app/services/NavigationProvider.kt
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import com.pr0gramm.app.model.config.Config
import com.pr0gramm.app.model.user.LoginState
import com.pr0gramm.app.orm.asFeedFilter
import com.pr0gramm.app.services.config.ConfigService
import com.pr0gramm.app.util.getColorCompat
import com.squareup.picasso.Picasso
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.flow.*
Expand Down Expand Up @@ -44,6 +45,7 @@ class NavigationProvider(
private val iconFeedTypeRandom by drawable(R.drawable.ic_action_random)
private val iconInbox by drawable(R.drawable.ic_action_email)
private val iconUpload by drawable(R.drawable.ic_action_upload)
private val iconAgeVerify by drawable(R.drawable.ic_action_verify)

private val iconSettings by drawable(R.drawable.ic_action_settings)
private val iconContact by drawable(R.drawable.ic_action_feedback)
Expand All @@ -57,7 +59,7 @@ class NavigationProvider(
private val refreshAfterNavItemWasDeletedStateFlow = MutableStateFlow(false)

private fun drawable(@DrawableRes id: Int): Lazy<Drawable> {
return lazy {
return lazy(LazyThreadSafetyMode.PUBLICATION) {
AppCompatResources.getDrawable(context, id)!!
}
}
Expand All @@ -69,6 +71,8 @@ class NavigationProvider(
val rawSources = listOf(
remoteConfigItems(loginState, upper = true),

ageVerificationItem(loginState),

currentSelection.map { selection ->
categoryNavigationItems(selection, loginState.name)
},
Expand Down Expand Up @@ -101,6 +105,16 @@ class NavigationProvider(
return refreshAfterNavItemWasDeletedStateFlow.flatMapLatest { items }.distinctUntilChanged()
}

private fun ageVerificationItem(loginState: LoginState): Flow<List<NavigationItem>> {
val items = if (loginState.authorized && !loginState.verified) {
listOf(staticItemAgeVerification)
} else {
listOf()
}

return flowOf(items)
}

private fun footerItems(loginState: LoginState): List<NavigationItem> {
val items = mutableListOf<NavigationItem>()

Expand Down Expand Up @@ -251,7 +265,7 @@ class NavigationProvider(
/**
* Returns the menu item that takes the user to the upload activity.
*/
private val uploadNavigationItem: NavigationItem by lazy {
private val uploadNavigationItem: NavigationItem by lazy(LazyThreadSafetyMode.PUBLICATION) {
NavigationItem(
action = ActionType.UPLOAD,
title = getString(R.string.action_upload),
Expand All @@ -261,40 +275,50 @@ class NavigationProvider(
/**
* Divider to divide item groups
*/
private val staticItemDivider: NavigationItem by lazy {
private val staticItemDivider: NavigationItem by lazy(LazyThreadSafetyMode.PUBLICATION) {
NavigationItem(ActionType.DIVIDER,
layout = R.layout.left_drawer_nav_item_divider)
}

private fun staticItem(action: ActionType, icon: Drawable, title: String): NavigationItem {
return NavigationItem(action, title = title, icon = icon, colorOverride = 0x80808080.toInt())
private fun staticItem(action: ActionType, icon: Drawable, title: String, colorOverride: Int = 0x80808080.toInt()): NavigationItem {
return NavigationItem(action, title = title, icon = icon, colorOverride = colorOverride)
}

private val staticItemFAQ: NavigationItem by lazy {
private val staticItemFAQ: NavigationItem by lazy(LazyThreadSafetyMode.PUBLICATION) {
staticItem(ActionType.FAQ, iconFAQ, getString(R.string.action_faq))
}

private val staticItemSettings: NavigationItem by lazy {
private val staticItemSettings: NavigationItem by lazy(LazyThreadSafetyMode.PUBLICATION) {
staticItem(ActionType.SETTINGS, iconSettings, getString(R.string.action_settings))
}

private val staticItemInvites: NavigationItem by lazy {
private val staticItemInvites: NavigationItem by lazy(LazyThreadSafetyMode.PUBLICATION) {
staticItem(ActionType.INVITES, iconInvite, getString(R.string.action_invite))
}

private val staticItemContact: NavigationItem by lazy {
private val staticItemContact: NavigationItem by lazy(LazyThreadSafetyMode.PUBLICATION) {
staticItem(ActionType.CONTACT, iconContact, getString(R.string.action_contact))
}

private val staticItemPremium: NavigationItem by lazy {
private val staticItemPremium: NavigationItem by lazy(LazyThreadSafetyMode.PUBLICATION) {
staticItem(ActionType.PREMIUM, iconPremium, getString(R.string.action_premium))
}

private val staticItemLogin: NavigationItem by lazy {
private val staticItemAgeVerification: NavigationItem by lazy(LazyThreadSafetyMode.PUBLICATION) {
// we want some alarm color
val color = context.getColorCompat(R.color.red_700)
staticItem(
ActionType.AGE_VERIFICATION, iconAgeVerify,
getString(R.string.action_age_verification),
colorOverride = color,
)
}

private val staticItemLogin: NavigationItem by lazy(LazyThreadSafetyMode.PUBLICATION) {
staticItem(ActionType.LOGIN, iconLogin, getString(R.string.action_login))
}

private val staticItemLogout: NavigationItem by lazy {
private val staticItemLogout: NavigationItem by lazy(LazyThreadSafetyMode.PUBLICATION) {
staticItem(ActionType.LOGOUT, iconLogout, getString(R.string.action_logout))
}

Expand Down Expand Up @@ -365,7 +389,7 @@ class NavigationProvider(
val isSelected: Boolean = false,
val colorOverride: Int? = null) {

private val hashCode by lazy {
private val hashCode by lazy(LazyThreadSafetyMode.PUBLICATION) {
listOf(action, title, layout, filter, bookmark, unreadCount, uri, isSelected).hashCode()
}

Expand All @@ -387,6 +411,7 @@ class NavigationProvider(
enum class ActionType {
HINT, FILTER, BOOKMARK, MESSAGES, UPLOAD, COLLECTIONS, URI,
DIVIDER,
SETTINGS, CONTACT, INVITES, FAQ, PREMIUM, LOGIN, LOGOUT
SETTINGS, CONTACT, INVITES, FAQ, PREMIUM, LOGIN, LOGOUT,
AGE_VERIFICATION,
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,12 @@ private class NavigationDelegateAdapter(
BrowserHelper.openCustomTab(activity, uri)
}

NavigationProvider.ActionType.AGE_VERIFICATION -> {
val uri = Uri.parse("https://pr0gramm.com/verify")
BrowserHelper.openCustomTab(activity, uri, handover = true)
}


NavigationProvider.ActionType.LOGIN ->
activity.startActivity<LoginActivity>()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -834,7 +834,13 @@ class FeedFragment : BaseFragment("FeedFragment", R.layout.fragment_feed), Filte
private fun hintUserIsNotVerified() {
showDialog(this) {
content(R.string.user_is_not_verified)
positive()

positive(R.string.action_verify) {
val uri = Uri.parse("https://pr0gramm.com/verify")
BrowserHelper.openCustomTab(requireContext(), uri, handover = true)
}

negative(R.string.action_not_now)
}
}

Expand Down
10 changes: 10 additions & 0 deletions app/src/main/res/drawable/ic_action_verify.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:fillColor="#000"
android:pathData="M10,17L6,13L7.41,11.59L10,14.17L16.59,7.58L18,9M12,1L3,5V11C3,16.55 6.84,21.74 12,23C17.16,21.74 21,16.55 21,11V5L12,1Z" />
</vector>
7 changes: 4 additions & 3 deletions app/src/main/res/values-de/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -562,7 +562,8 @@
<string name="action_scroll_seen">Nächster gesehener Hochlad</string>
<string name="error_max_scroll_reached">Maximale Scrollweite erreicht. Probiere es einfach nochmal.</string>
<string name="changelog">Changelog</string>
<string name="user_is_not_verified">Deine Altersverifikation ist noch nicht abgeschlossen.</string>


<string name="user_is_not_verified">Dein Altersnachweis ist noch nicht abgeschlossen. Um nicht jugendfreie Inhalte anzusehen, musst Du dein Alter bestätigen.</string>
<string name="action_age_verification">Altersnachweis</string>
<string name="action_verify">Verifizieren</string>
<string name="action_not_now">Nicht jetzt</string>
</resources>
5 changes: 4 additions & 1 deletion app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -581,6 +581,9 @@
<string name="action_scroll_seen">Scroll next seen</string>
<string name="error_max_scroll_reached">Max scroll distance reached. Please try again.</string>
<string name="changelog">Changelog</string>
<string name="user_is_not_verified">You are not age verified.</string>
<string name="user_is_not_verified">Your age was not verified. To be able to access adult content, you need to verify your age.</string>
<string name="action_verify">Verify</string>
<string name="action_not_now">Not now</string>
<string name="action_age_verification">Age verification</string>
</resources>

0 comments on commit 1590c4c

Please sign in to comment.