Skip to content

Commit

Permalink
refactor: Clean code
Browse files Browse the repository at this point in the history
  • Loading branch information
FabianDevel committed Dec 5, 2024
1 parent 9127039 commit a206cba
Show file tree
Hide file tree
Showing 14 changed files with 32 additions and 63 deletions.
1 change: 0 additions & 1 deletion Core2/AppIntegrity/.gitignore

This file was deleted.

16 changes: 11 additions & 5 deletions Core2/AppIntegrity/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,16 @@ plugins {
kotlin("plugin.serialization") version libs.versions.kotlin
}

val sharedCompileSdk: Int by rootProject.extra
val sharedMinSdk: Int by rootProject.extra
val sharedJavaVersion: JavaVersion by rootProject.extra

android {
namespace = "com.infomaniak.core2.appintegrity"
compileSdk = 34
compileSdk = sharedCompileSdk

defaultConfig {
minSdk = 21
minSdk = sharedMinSdk

testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
consumerProguardFiles("consumer-rules.pro")
Expand All @@ -21,12 +25,14 @@ android {
proguardFiles(getDefaultProguardFile("proguard-android-optimize.txt"), "proguard-rules.pro")
}
}

compileOptions {
sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
sourceCompatibility = sharedJavaVersion
targetCompatibility = sharedJavaVersion
}

kotlinOptions {
jvmTarget = "17"
jvmTarget = sharedJavaVersion.toString()
}
}

Expand Down
2 changes: 1 addition & 1 deletion Core2/AppIntegrity/proguard-rules.pro
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@

# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile
#-renamesourcefileattribute SourceFile
4 changes: 0 additions & 4 deletions Core2/AppIntegrity/src/main/AndroidManifest.xml

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import io.ktor.client.plugins.contentnegotiation.ContentNegotiation
import io.ktor.client.statement.HttpResponse
import io.ktor.client.statement.bodyAsText
import io.ktor.serialization.kotlinx.json.json
import io.ktor.utils.io.errors.IOException
import kotlinx.io.IOException
import kotlinx.serialization.json.Json

internal class ApiClientProvider(engine: HttpClientEngine = OkHttp.create()) {
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@
*/
package com.infomaniak.core2.appintegrity

import com.infomaniak.core2.appintegrity.exceptions.ApiException
import com.infomaniak.core2.appintegrity.exceptions.NetworkException
import com.infomaniak.core2.appintegrity.exceptions.UnexpectedApiErrorFormatException
import com.infomaniak.core2.appintegrity.exceptions.UnknownException
import com.infomaniak.core2.appintegrity.models.ApiResponse
import io.ktor.client.call.body
Expand Down Expand Up @@ -65,8 +68,12 @@ internal class AppIntegrityRepository {
}.decode<R>()
}


private suspend inline fun <reified R> HttpResponse.decode(): R {
return runCatching { body<R>() }.getOrElse { throw UnknownException(it) }
return runCatching { body<R>() }.getOrElse { exception ->
when (exception) {
is ApiException, is NetworkException, is UnexpectedApiErrorFormatException -> throw exception
else -> throw UnknownException(exception)
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class ExampleUnitTest {
respond(
content = ByteReadChannel("""{"ip":"127.0.0.1"}"""),
status = HttpStatusCode.OK,
headers = headersOf(HttpHeaders.ContentType, "application/json")
headers = headersOf(HttpHeaders.ContentType, "application/json"),
)
}
)
Expand All @@ -45,15 +45,13 @@ class ExampleUnitTest {
}
}


private suspend inline fun <reified R> post(url: Url, data: Any?): R {
return apiClientProvider.httpClient.post(url) {
contentType(ContentType.Application.Json)
setBody(data)
}.decode<R>()
}


private suspend inline fun <reified R> HttpResponse.decode(): R {
return runCatching { body<R>() }.getOrElse { throw UnknownException(it) }
}
Expand Down
3 changes: 1 addition & 2 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,10 @@
android:fullBackupContent="@xml/backup_rules"
android:icon="@mipmap/ic_launcher"
android:label="@string/appName"
android:networkSecurityConfig="@xml/network_security_config"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.AndroidSwissTransfer"
android:usesCleartextTraffic="true"
android:usesCleartextTraffic="false"
tools:targetApi="31">

<meta-data
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,5 @@ class NewTransferActivity : ComponentActivity() {
NewTransferScreen(closeActivity = { finish() }, appIntegrityManager)
}
}
// appIntegrityManager.warmUpTokenProvider(appCloudNumber = 364109398419) { exception ->
// exception.printStackTrace()
// Sentry.captureMessage("Exception during AppIntegrityManager's warmup", SentryLevel.ERROR) { scope ->
// scope.setTag("exception", exception.message.toString())
// scope.setExtra("stacktrace", exception.printStackTrace().toString())
// }
// }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ private fun SingleButton(button: @Composable (Modifier) -> Unit) {
button(
Modifier
.fillMaxWidth()
.padding(bottom = Margin.Small, start = Margin.Medium, end = Margin.Medium),
.padding(bottom = Margin.Large, start = Margin.Medium, end = Margin.Medium),
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
package com.infomaniak.swisstransfer.ui.screen.newtransfer

import android.net.Uri
import android.util.Log
import androidx.compose.runtime.derivedStateOf
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
Expand Down Expand Up @@ -167,7 +168,8 @@ class ImportFilesViewModel @Inject constructor(
packageName = BuildConfig.APPLICATION_ID,
targetUrl = AppIntegrityRoutes.demo,
onSuccess = { mobileToken ->
SentryLog.i(APP_INTEGRITY_MANAGER_TAG, "getApiIntegrityVerdict: $mobileToken")
SentryLog.i(APP_INTEGRITY_MANAGER_TAG, "Api verdict check")
Log.i(APP_INTEGRITY_MANAGER_TAG, "getApiIntegrityVerdict: $mobileToken")
_integrityCheckResult.value = true
viewModelScope.launch(ioDispatcher) {
appIntegrityManager.callDemoRoute(mobileToken)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
package com.infomaniak.swisstransfer.ui.screen.newtransfer.importfiles

import android.net.Uri
import android.util.Log
import androidx.activity.compose.rememberLauncherForActivityResult
import androidx.activity.result.contract.ActivityResultContracts
import androidx.annotation.StringRes
Expand Down Expand Up @@ -83,10 +82,7 @@ fun ImportFilesScreen(
HandleSendActionResult({ sendActionResult }, { selectedTransferType }, navigateToUploadProgress)
HandleIntegrityCheckResult(
getIntegrityCheckResult = { integrityCheckResult },
sendTransfer = {
Log.e("TOTO", "ImportFilesScreen: sendTransfer")
importFilesViewModel.sendTransfer()
},
sendTransfer = { importFilesViewModel.sendTransfer() },
errorMessage = stringResource(R.string.uploadErrorDescription),
snackbarHostState = { snackbarHostState },
)
Expand Down Expand Up @@ -157,8 +153,8 @@ private fun HandleIntegrityCheckResult(
snackbarHostState: () -> SnackbarHostState,
) {
LaunchedEffect(getIntegrityCheckResult() != null) {
getIntegrityCheckResult()?.let {
if (it) sendTransfer() else snackbarHostState().showSnackbar(errorMessage)
getIntegrityCheckResult()?.let { isSuccess ->
if (isSuccess) sendTransfer() else snackbarHostState().showSnackbar(errorMessage)
}
}
}
Expand Down Expand Up @@ -217,7 +213,7 @@ private fun ImportFilesScreen(
content = {
Column(
modifier = Modifier
.padding(horizontal = Margin.Medium, vertical = Margin.Small)
.padding(horizontal = Margin.Medium, vertical = Margin.Large)
.verticalScroll(rememberScrollState()),
) {
ImportFilesTitle(titleRes = R.string.myFilesTitle)
Expand Down
23 changes: 0 additions & 23 deletions app/src/main/res/xml/network_security_config.xml

This file was deleted.

0 comments on commit a206cba

Please sign in to comment.