Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Unverified Commit dd294a4b authored by Ricki Hirner's avatar Ricki Hirner Committed by GitHub
Browse files

Move external URIs from Constants to ExternalUris object (#1574)

* [WIP] Move external URIs from Constants to ExternalUris object

* Update external URIs to use class names or screen name for stat params
parent 0efe6a7b
Loading
Loading
Loading
Loading
+0 −48
Original line number Diff line number Diff line
@@ -3,8 +3,6 @@
 */
package at.bitfire.davdroid

import android.net.Uri
import androidx.core.net.toUri
import at.bitfire.ical4android.ical4jVersion
import ezvcard.Ezvcard
import net.fortuna.ical4j.model.property.ProdId
@@ -16,56 +14,10 @@ object Constants {

    const val DAVDROID_GREEN_RGBA = 0xFF8bc34a.toInt()

    val HOMEPAGE_URL = "https://www.davx5.com".toUri()
    const val HOMEPAGE_PATH_FAQ = "faq"
    const val HOMEPAGE_PATH_FAQ_SYNC_NOT_RUN = "synchronization-is-not-run-as-expected"
    const val HOMEPAGE_PATH_FAQ_LOCATION_PERMISSION = "wifi-ssid-restriction-location-permission"
    const val HOMEPAGE_PATH_OPEN_SOURCE = "donate"
    const val HOMEPAGE_PATH_PRIVACY = "privacy"
    const val HOMEPAGE_PATH_TESTED_SERVICES = "tested-with"

    val MANUAL_URL = "https://manual.davx5.com".toUri()

    const val MANUAL_PATH_ACCOUNTS_COLLECTIONS = "accounts_collections.html"
    const val MANUAL_FRAGMENT_SERVICE_DISCOVERY = "how-does-service-discovery-work"

    const val MANUAL_PATH_INTRODUCTION = "introduction.html"
    const val MANUAL_FRAGMENT_AUTHENTICATION_METHODS = "authentication-methods"

    const val MANUAL_PATH_SETTINGS = "settings.html"
    const val MANUAL_FRAGMENT_APP_SETTINGS = "app-wide-settings"
    const val MANUAL_FRAGMENT_ACCOUNT_SETTINGS = "account-settings"

    const val MANUAL_PATH_WEBDAV_PUSH = "webdav_push.html"
    const val MANUAL_PATH_WEBDAV_MOUNTS = "webdav_mounts.html"

    const val MANAGED_PATH = "organizations"

    val COMMUNITY_URL = "https://github.com/bitfireAT/davx5-ose/discussions".toUri()

    const val FEDIVERSE_HANDLE = "@davx5app@fosstodon.org"
    val FEDIVERSE_URL = "https://fosstodon.org/@davx5app".toUri()


    // product IDs for iCalendar/vCard

    val iCalProdId = ProdId("DAVx5/${BuildConfig.VERSION_NAME} ical4j/$ical4jVersion")
    const val vCardProdId = "+//IDN bitfire.at//DAVx5/${BuildConfig.VERSION_NAME} ez-vcard/${Ezvcard.VERSION}"

    /**
     * Appends query parameters for anonymized usage statistics (app ID, version).
     * Can be used by the called Website to get an idea of which versions etc. are currently used.
     *
     * @param context   optional info about from where the URL was opened (like a specific Activity)
     */
    fun Uri.Builder.withStatParams(context: String? = null): Uri.Builder {
        appendQueryParameter("pk_campaign", BuildConfig.APPLICATION_ID)
        appendQueryParameter("app-version", BuildConfig.VERSION_NAME)

        if (context != null)
            appendQueryParameter("pk_kwd", context)

        return this
    }

}
 No newline at end of file
+3 −4
Original line number Diff line number Diff line
@@ -48,10 +48,9 @@ import androidx.compose.ui.unit.dp
import androidx.lifecycle.ViewModel
import androidx.lifecycle.compose.collectAsStateWithLifecycle
import at.bitfire.davdroid.BuildConfig
import at.bitfire.davdroid.Constants
import at.bitfire.davdroid.Constants.withStatParams
import at.bitfire.davdroid.R
import at.bitfire.davdroid.di.IoDispatcher
import at.bitfire.davdroid.ui.ExternalUris.withStatParams
import at.bitfire.davdroid.ui.composable.PixelBoxes
import com.mikepenz.aboutlibraries.ui.compose.LibraryDefaults
import com.mikepenz.aboutlibraries.ui.compose.m3.LibrariesContainer
@@ -110,9 +109,9 @@ class AboutActivity: AppCompatActivity() {
                            },
                            actions = {
                                IconButton(onClick = {
                                    uriHandler.openUri(Constants.HOMEPAGE_URL
                                    uriHandler.openUri(ExternalUris.Homepage.baseUrl
                                        .buildUpon()
                                        .withStatParams("AboutActivity")
                                        .withStatParams(javaClass.simpleName)
                                        .build().toString())
                                }) {
                                    Icon(
+5 −6
Original line number Diff line number Diff line
@@ -67,7 +67,6 @@ import androidx.compose.ui.unit.dp
import androidx.core.graphics.drawable.toBitmap
import androidx.lifecycle.compose.collectAsStateWithLifecycle
import androidx.lifecycle.viewmodel.compose.viewModel
import at.bitfire.davdroid.Constants
import at.bitfire.davdroid.R
import at.bitfire.davdroid.settings.Settings
import at.bitfire.davdroid.ui.AppSettingsModel.PushDistributorInfo
@@ -186,9 +185,9 @@ fun AppSettingsScreen(
                title = { Text(stringResource(R.string.app_settings)) },
                actions = {
                    IconButton(onClick = {
                        val settingsUri = Constants.MANUAL_URL.buildUpon()
                            .appendPath(Constants.MANUAL_PATH_SETTINGS)
                            .fragment(Constants.MANUAL_FRAGMENT_APP_SETTINGS)
                        val settingsUri = ExternalUris.Manual.baseUrl.buildUpon()
                            .appendPath(ExternalUris.Manual.PATH_SETTINGS)
                            .fragment(ExternalUris.Manual.FRAGMENT_APP_SETTINGS)
                            .build()
                        uriHandler.openUri(settingsUri.toString())
                    }) {
@@ -653,8 +652,8 @@ private fun PushDistributorSelectionDialog(
                            )
                            pushLink(
                                LinkAnnotation.Url(
                                    Constants.MANUAL_URL.buildUpon()
                                        .appendPath(Constants.MANUAL_PATH_WEBDAV_PUSH)
                                    ExternalUris.Manual.baseUrl.buildUpon()
                                        .appendPath(ExternalUris.Manual.PATH_WEBDAV_PUSH)
                                        .build().toString()
                                )
                            )
+95 −0
Original line number Diff line number Diff line
/*
 * Copyright © All Contributors. See LICENSE and AUTHORS in the root directory for details.
 */

package at.bitfire.davdroid.ui

import android.net.Uri
import androidx.core.net.toUri
import at.bitfire.davdroid.BuildConfig

/**
 * Links to to external pages (Web site, manual, social media etc.)
 */
object ExternalUris {

    /**
     * URLs of the DAVx5 homepage
     */
    @Suppress("unused")     // build variants
    object Homepage {

        val baseUrl
            get() = "https://www.davx5.com".toUri()

        const val PATH_FAQ = "faq"
        const val PATH_FAQ_SYNC_NOT_RUN = "synchronization-is-not-run-as-expected"
        const val PATH_FAQ_LOCATION_PERMISSION = "wifi-ssid-restriction-location-permission"
        const val PATH_OPEN_SOURCE = "donate"
        const val PATH_PRIVACY = "privacy"
        const val PATH_TESTED_SERVICES = "tested-with"

        const val PATH_ORGANIZATIONS = "organizations"
        const val PATH_ORGANIZATIONS_MANAGED = "managed-davx5"
        const val PATH_ORGANIZATIONS_TRY_IT = "try-it-for-free"
    }


    /**
     * URLs of the DAVx5 Manual
     */
    object Manual {

        val baseUrl
            get() = "https://manual.davx5.com".toUri()

        const val PATH_ACCOUNTS_COLLECTIONS = "accounts_collections.html"
        const val FRAGMENT_SERVICE_DISCOVERY = "how-does-service-discovery-work"

        const val PATH_INTRODUCTION = "introduction.html"
        const val FRAGMENT_AUTHENTICATION_METHODS = "authentication-methods"

        const val PATH_SETTINGS = "settings.html"
        const val FRAGMENT_APP_SETTINGS = "app-wide-settings"
        const val FRAGMENT_ACCOUNT_SETTINGS = "account-settings"

        const val PATH_WEBDAV_PUSH = "webdav_push.html"
        const val PATH_WEBDAV_MOUNTS = "webdav_mounts.html"

    }


    /**
     * URLs of DAVx5 social sites
     */
    object Social {

        val discussionsUrl
            get() = "https://github.com/bitfireAT/davx5-ose/discussions".toUri()

        const val fediverseHandle = "@davx5app@fosstodon.org"
        val fediverseUrl
            get() = "https://fosstodon.org/@davx5app".toUri()

    }


    // helpers

    /**
     * Appends query parameters for anonymized usage statistics (app ID, version).
     * Can be used by the called Website to get an idea of which versions etc. are currently used.
     *
     * @param context   optional info about from where the URL was opened (like a specific Activity)
     */
    fun Uri.Builder.withStatParams(context: String? = null): Uri.Builder {
        appendQueryParameter("pk_campaign", BuildConfig.APPLICATION_ID)
        appendQueryParameter("app-version", BuildConfig.VERSION_NAME)

        if (context != null)
            appendQueryParameter("pk_kwd", context)

        return this
    }

}
 No newline at end of file
+23 −27
Original line number Diff line number Diff line
@@ -19,20 +19,14 @@ import androidx.compose.ui.platform.LocalUriHandler
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.tooling.preview.Preview
import at.bitfire.davdroid.Constants
import at.bitfire.davdroid.Constants.COMMUNITY_URL
import at.bitfire.davdroid.Constants.FEDIVERSE_URL
import at.bitfire.davdroid.Constants.MANUAL_URL
import at.bitfire.davdroid.Constants.withStatParams
import at.bitfire.davdroid.R
import at.bitfire.davdroid.ui.ExternalUris.Homepage
import at.bitfire.davdroid.ui.ExternalUris.Social
import at.bitfire.davdroid.ui.ExternalUris.withStatParams
import javax.inject.Inject

open class OseAccountsDrawerHandler @Inject constructor(): AccountsDrawerHandler() {

    companion object {
        const val WEB_CONTEXT = "AccountsDrawerHandler"
    }

    @Composable
    override fun MenuEntries(
        snackbarHostState: SnackbarHostState
@@ -46,9 +40,9 @@ open class OseAccountsDrawerHandler @Inject constructor(): AccountsDrawerHandler
        MenuHeading(R.string.navigation_drawer_news_updates)
        MenuEntry(
            icon = painterResource(R.drawable.mastodon),
            title = Constants.FEDIVERSE_HANDLE,
            title = Social.fediverseHandle,
            onClick = {
                uriHandler.openUri(FEDIVERSE_URL.toString())
                uriHandler.openUri(Social.fediverseUrl.toString())
            }
        )

@@ -59,9 +53,9 @@ open class OseAccountsDrawerHandler @Inject constructor(): AccountsDrawerHandler
        MenuHeading(R.string.navigation_drawer_support_project)
        Contribute(onContribute = {
            uriHandler.openUri(
                Constants.HOMEPAGE_URL.buildUpon()
                    .appendPath(Constants.HOMEPAGE_PATH_OPEN_SOURCE)
                    .withStatParams(WEB_CONTEXT)
                Homepage.baseUrl.buildUpon()
                    .appendPath(Homepage.PATH_OPEN_SOURCE)
                    .withStatParams(javaClass.simpleName)
                    .build().toString()
            )
        })
@@ -69,7 +63,7 @@ open class OseAccountsDrawerHandler @Inject constructor(): AccountsDrawerHandler
            icon = Icons.Default.Forum,
            title = stringResource(R.string.navigation_drawer_community),
            onClick = {
                uriHandler.openUri(COMMUNITY_URL.toString())
                uriHandler.openUri(Social.discussionsUrl.toString())
            }
        )

@@ -80,9 +74,10 @@ open class OseAccountsDrawerHandler @Inject constructor(): AccountsDrawerHandler
            icon = Icons.Default.Home,
            title = stringResource(R.string.navigation_drawer_website),
            onClick = {
                uriHandler.openUri(Constants.HOMEPAGE_URL
                uriHandler.openUri(
                    Homepage.baseUrl
                    .buildUpon()
                    .withStatParams(WEB_CONTEXT)
                    .withStatParams(javaClass.simpleName)
                    .build().toString())
            }
        )
@@ -90,7 +85,7 @@ open class OseAccountsDrawerHandler @Inject constructor(): AccountsDrawerHandler
            icon = Icons.Default.Info,
            title = stringResource(R.string.navigation_drawer_manual),
            onClick = {
                uriHandler.openUri(MANUAL_URL.toString())
                uriHandler.openUri(ExternalUris.Manual.baseUrl.toString())
            }
        )
        MenuEntry(
@@ -98,9 +93,9 @@ open class OseAccountsDrawerHandler @Inject constructor(): AccountsDrawerHandler
            title = stringResource(R.string.navigation_drawer_faq),
            onClick = {
                uriHandler.openUri(
                    Constants.HOMEPAGE_URL.buildUpon()
                        .appendPath(Constants.HOMEPAGE_PATH_FAQ)
                        .withStatParams(WEB_CONTEXT)
                    Homepage.baseUrl.buildUpon()
                        .appendPath(Homepage.PATH_FAQ)
                        .withStatParams(javaClass.simpleName)
                        .build().toString()
                )
            }
@@ -110,9 +105,10 @@ open class OseAccountsDrawerHandler @Inject constructor(): AccountsDrawerHandler
            title = stringResource(R.string.navigation_drawer_managed),
            onClick = {
                uriHandler.openUri(
                    Constants.HOMEPAGE_URL.buildUpon()
                        .appendPath(Constants.MANAGED_PATH)
                        .withStatParams(WEB_CONTEXT)
                    Homepage.baseUrl.buildUpon()
                        .appendPath(Homepage.PATH_ORGANIZATIONS)
                        .appendPath(Homepage.PATH_ORGANIZATIONS_MANAGED)
                        .withStatParams(javaClass.simpleName)
                        .build().toString()
                )
            }
@@ -122,9 +118,9 @@ open class OseAccountsDrawerHandler @Inject constructor(): AccountsDrawerHandler
            title = stringResource(R.string.navigation_drawer_privacy_policy),
            onClick = {
                uriHandler.openUri(
                    Constants.HOMEPAGE_URL.buildUpon()
                        .appendPath(Constants.HOMEPAGE_PATH_PRIVACY)
                        .withStatParams(WEB_CONTEXT)
                    Homepage.baseUrl.buildUpon()
                        .appendPath(Homepage.PATH_PRIVACY)
                        .withStatParams(javaClass.simpleName)
                        .build().toString()
                )
            }
Loading