Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into mail-validation-ui
Browse files Browse the repository at this point in the history
# Conflicts:
#	app/src/main/java/com/infomaniak/swisstransfer/ui/screen/newtransfer/ImportFilesViewModel.kt
  • Loading branch information
LunarX committed Dec 18, 2024
2 parents ec33f4e + 82119d5 commit 4a13692
Show file tree
Hide file tree
Showing 20 changed files with 318 additions and 67 deletions.
5 changes: 5 additions & 0 deletions .github/workflows/android.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ jobs:
token: ${{ github.token }}
submodules: recursive

- name: Create test env.properties
run: |
touch env.properties
echo "sentryAuthToken=DummyToken" > env.properties
# Setup Gradle and Run tests
- name: Grant execute permission for gradlew
run: chmod +x gradlew
Expand Down
21 changes: 12 additions & 9 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
*.iml
.gradle
/local.properties
/.idea
.cxx
.DS_Store
build/
/captures
.externalNativeBuild
.cxx
local.properties
*.apk
.gradle
.kotlin/sessions
*.aab
*.apk
*.iml
env.properties
local.properties
build/
/.idea
/app/release/baselineProfiles
/captures
/local.properties
31 changes: 31 additions & 0 deletions Core2/src/main/java/com/infomaniak/core2/UserAgentUtils.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* Infomaniak SwissTransfer - 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.core2

import android.os.Build

fun buildUserAgent(
appId: String,
appVersionCode: Int,
appVersionName: String,
): String {
val androidVersion = "Android ${Build.VERSION.RELEASE}"
val arch = System.getProperty("os.arch")
return "$appId/$appVersionName-$appVersionCode (${Build.MODEL}; $androidVersion; $arch)"
}

32 changes: 32 additions & 0 deletions Core2/src/main/java/com/infomaniak/core2/extensions/BundleExt.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* Infomaniak SwissTransfer - 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.core2.extensions

import android.os.Build
import android.os.Bundle
import android.os.Parcelable

inline fun <reified T : Parcelable> Bundle.parcelableExtra(key: String): T? = when {
Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU -> getParcelable(key, T::class.java)
else -> @Suppress("DEPRECATION") getParcelable(key) as? T
}

inline fun <reified T : Parcelable> Bundle.parcelableArrayListExtra(key: String): List<T>? = when {
Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU -> getParcelableArrayList(key, T::class.java)
else -> @Suppress("DEPRECATION") getParcelableArrayList(key)
}
31 changes: 22 additions & 9 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import org.jetbrains.kotlin.konan.properties.loadProperties

plugins {
alias(libs.plugins.android.application)
alias(libs.plugins.kotlin.android)
Expand All @@ -13,6 +15,10 @@ val sharedCompileSdk: Int by rootProject.extra
val sharedMinSdk: Int by rootProject.extra
val sharedJavaVersion: JavaVersion by rootProject.extra

val envProperties = loadProperties("env.properties")
val sentryAuthToken = envProperties.getProperty("sentryAuthToken").takeIf { it.isNotEmpty() }
?: error("The `sentryAuthToken` property in `env.properties` must be defined and not empty (see `env.example.properties`).")

android {
namespace = "com.infomaniak.swisstransfer"
compileSdk = sharedCompileSdk
Expand All @@ -29,13 +35,22 @@ android {
useSupportLibrary = true
}

//TODO: Remove preprod url when api is in prod
val preprodHost = "swisstransfer.preprod.dev.infomaniak.ch"
val prodHost = "swisstransfer.com"
resValue("string", "preprod_host", preprodHost)
resValue("string", "prod_host", prodHost)
buildConfigField("String", "PREPROD_URL", "\"https://$preprodHost\"")
buildConfigField("String", "PROD_URL", "\"https://$prodHost\"")

buildConfigField("String", "RECAPTCHA_API_SITE_KEY", "\"6LfaxOgpAAAAAI3Sj4rtB2oAFjkRJILiGEt-LUsc\"")
buildConfigField("String", "GITHUB_REPO_URL", "\"https://github.com/Infomaniak/android-SwissTransfer\"")
}

buildTypes {
release {
isMinifyEnabled = false
isMinifyEnabled = true
isShrinkResources = true
proguardFiles(getDefaultProguardFile("proguard-android-optimize.txt"), "proguard-rules.pro")
}
}
Expand Down Expand Up @@ -71,15 +86,13 @@ kapt {
}

sentry {
// Enables or disables the automatic upload of mapping files during a build.
// If you disable this, you'll need to manually upload the mapping files with sentry-cli when you do a release.
// Default is enabled.
autoUploadProguardMapping = true

// Does or doesn't include the source code of native code for Sentry.
// This executes sentry-cli with the --include-sources param. automatically so you don't need to do it manually.
// Default is disabled.
org = "sentry"
projectName = "swisstransfer-android"
authToken = sentryAuthToken
url = "https://sentry-mobile.infomaniak.com"
uploadNativeSymbols = true
includeNativeSources = true
includeSourceContext = true
}

dependencies {
Expand Down
5 changes: 4 additions & 1 deletion app/proguard-rules.pro
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,7 @@

# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile
#-renamesourcefileattribute SourceFile

# The TransferTypeUi class is removed when minifying, we don't want that.
-keep class com.infomaniak.swisstransfer.ui.screen.newtransfer.importfiles.components.TransferTypeUi{*;}
18 changes: 17 additions & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
android:name=".ui.MainApplication"
android:allowBackup="true"
android:dataExtractionRules="@xml/data_extraction_rules"
android:enableOnBackInvokedCallback="true"
android:fullBackupContent="@xml/backup_rules"
android:icon="@mipmap/ic_launcher"
android:label="@string/appName"
Expand Down Expand Up @@ -70,7 +71,22 @@

<activity android:name=".ui.OnboardingActivity" />

<activity android:name=".ui.MainActivity" />
<activity
android:name=".ui.MainActivity"
android:exported="true"
android:launchMode="singleTop">
<intent-filter android:autoVerify="true">
<action android:name="android.intent.action.VIEW" />

<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />

<data android:scheme="https" />
<data android:host="@string/preprod_host" />
<data android:host="@string/prod_host" />
<data android:pathPattern="/d/.*" />
</intent-filter>
</activity>

<activity android:name=".ui.NewTransferActivity" />
</application>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@ package com.infomaniak.swisstransfer.di

import android.app.Application
import com.infomaniak.core2.appintegrity.AppIntegrityManager
import com.infomaniak.core2.buildUserAgent
import com.infomaniak.multiplatform_swisstransfer.SwissTransferInjection
import com.infomaniak.multiplatform_swisstransfer.common.utils.ApiEnvironment
import com.infomaniak.swisstransfer.BuildConfig
import dagger.Module
import dagger.Provides
import dagger.hilt.InstallIn
Expand All @@ -32,7 +35,14 @@ object SwissTransferInjectionModule {

@Provides
@Singleton
fun providesSwissTransferInjection() = SwissTransferInjection(userAgent = "Ktor client") // TODO: Waiting for api support
fun providesSwissTransferInjection(): SwissTransferInjection {
val userAgent = buildUserAgent(
appId = BuildConfig.APPLICATION_ID,
appVersionCode = BuildConfig.VERSION_CODE,
appVersionName = BuildConfig.VERSION_NAME,
)
return SwissTransferInjection(environment = ApiEnvironment.Prod, userAgent = userAgent)
}

@Provides
@Singleton
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,13 @@
package com.infomaniak.swisstransfer.ui.navigation

import android.os.Bundle
import androidx.compose.animation.AnimatedContentScope
import androidx.compose.runtime.Composable
import androidx.navigation.NavBackStackEntry
import androidx.navigation.NavGraphBuilder
import androidx.navigation.compose.composable
import androidx.navigation.navDeepLink
import com.infomaniak.swisstransfer.BuildConfig
import com.infomaniak.swisstransfer.ui.screen.newtransfer.importfiles.components.TransferTypeUi
import kotlinx.serialization.Serializable
import kotlin.reflect.KClass
Expand All @@ -33,8 +39,25 @@ sealed class MainNavigation : NavigationDestination() {

@Serializable
data object SentDestination : MainNavigation()

@Serializable
data object ReceivedDestination : MainNavigation()
data class ReceivedDestination(val transferUuid: String? = null) : MainNavigation() {

companion object {
fun NavGraphBuilder.receivedDestination(
content: @Composable (AnimatedContentScope.(NavBackStackEntry) -> Unit),
) {
val preprodBasePath = "${BuildConfig.PREPROD_URL}/d/{${ReceivedDestination::transferUuid.name}}"
val prodBasePath = "${BuildConfig.PROD_URL}/d/${ReceivedDestination::transferUuid.name}"
val deepLinks = listOf(
navDeepLink<ReceivedDestination>(preprodBasePath),
navDeepLink<ReceivedDestination>(prodBasePath),
)
composable<ReceivedDestination>(deepLinks = deepLinks, content = content)
}
}
}

@Serializable
data class TransferDetailsDestination(val transferUuid: String) : MainNavigation()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,6 @@ enum class NavigationItem(
val destination: MainNavigation,
) {
SENT(R.string.sentTitle, AppIcons.ArrowUpCircle, SentDestination),
RECEIVED(R.string.receivedTitle, AppIcons.ArrowDownCircle, ReceivedDestination),
RECEIVED(R.string.receivedTitle, AppIcons.ArrowDownCircle, ReceivedDestination()),
SETTINGS(R.string.settingsTitle, AppIcons.Settings, SettingsDestination),
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,11 @@ import androidx.compose.runtime.Composable
import androidx.navigation.NavHostController
import androidx.navigation.compose.NavHost
import androidx.navigation.compose.composable
import androidx.navigation.toRoute
import com.infomaniak.multiplatform_swisstransfer.common.models.TransferDirection
import com.infomaniak.swisstransfer.ui.navigation.MainNavigation
import com.infomaniak.swisstransfer.ui.navigation.MainNavigation.*
import com.infomaniak.swisstransfer.ui.navigation.MainNavigation.ReceivedDestination.Companion.receivedDestination
import com.infomaniak.swisstransfer.ui.screen.main.settings.SettingsScreenWrapper
import com.infomaniak.swisstransfer.ui.screen.main.transfers.TransfersScreenWrapper

Expand All @@ -43,7 +45,10 @@ fun MainNavHost(
exitTransition = { if (currentDestination.enableTransition) fadeOut() else ExitTransition.None },
) {
composable<SentDestination> { TransfersScreenWrapper(TransferDirection.SENT) }
composable<ReceivedDestination> { TransfersScreenWrapper(TransferDirection.RECEIVED) }
receivedDestination {
val args = it.toRoute<ReceivedDestination>()
TransfersScreenWrapper(TransferDirection.RECEIVED, transferUuid = args.transferUuid)
}
composable<SettingsDestination> { SettingsScreenWrapper() }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ private fun AppNavigationBar(
NavigationBarItem(
icon = { NavigationIcon(true, navigationItem) },
label = { NavigationLabel(navigationItem) },
selected = currentDestination == navigationItem.destination,
selected = currentDestination::class == navigationItem.destination::class,
onClick = { onClick(navigationItem.destination) },
)
}
Expand All @@ -129,7 +129,7 @@ private fun AppNavigationRail(
NavigationRailItem(
icon = { NavigationIcon(false, navigationItem) },
label = { NavigationLabel(navigationItem) },
selected = currentDestination == navigationItem.destination,
selected = currentDestination::class == navigationItem.destination::class,
onClick = { onClick(navigationItem.destination) },
)
if (index != navigationItems.lastIndex) {
Expand Down
Loading

0 comments on commit 4a13692

Please sign in to comment.