Skip to content

Commit

Permalink
Merge branch 'android-ui-tests' into fix-searchTimeout
Browse files Browse the repository at this point in the history
# Conflicts:
#	.github/workflows/android.yml
#	app/src/androidTest/java/com/infomaniak/drive/ApiRepositoryTest.kt
  • Loading branch information
FabianDevel committed Feb 22, 2022
2 parents d5505a5 + d962c8e commit e443f00
Show file tree
Hide file tree
Showing 43 changed files with 1,097 additions and 777 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/android.yml
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ jobs:
arch: x86_64
avd-name: kdrive-test
force-avd-creation: false
emulator-options: -no-snapshot-save -noaudio -no-boot-anim -camera-back none -skin 540x1110
emulator-options: -no-snapshot-save -no-window -gpu swiftshader_indirect -noaudio -no-boot-anim -camera-back none -skin 540x1110
script: echo "Generated AVD snapshot for caching."

# - name: set up JDK 11
Expand Down Expand Up @@ -96,7 +96,7 @@ jobs:
arch: x86_64
avd-name: kdrive-test
force-avd-creation: false
emulator-options: -no-snapshot-save -noaudio -no-boot-anim -camera-back none -skin 540x1110
# emulator-options: -no-snapshot-save -no-window -gpu swiftshader_indirect -noaudio -no-boot-anim -camera-back none -skin 1080x2220
# emulator-options: -no-snapshot-save -noaudio -no-boot-anim -camera-back none -skin 540x1110
emulator-options: -no-snapshot-save -no-window -gpu swiftshader_indirect -noaudio -no-boot-anim -camera-back none -skin 540x1110
script: ./gradlew app:connectedStandardDebugAndroidTest --stacktrace

2 changes: 1 addition & 1 deletion Core
29 changes: 12 additions & 17 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,15 @@ apply plugin: 'realm-android'
apply plugin: 'de.mannodermaus.android-junit5'

android {

compileSdkVersion 31

defaultConfig {
applicationId "com.infomaniak.drive"
applicationId 'com.infomaniak.drive'
minSdkVersion 21
targetSdkVersion 31
versionCode 4_01_000_06
versionName "4.1.0"
versionName '4.1.0'

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
testInstrumentationRunnerArgument "runnerBuilder", "de.mannodermaus.junit5.AndroidJUnit5Builder"
Expand All @@ -39,9 +40,7 @@ android {
targetCompatibility rootProject.ext.java_version
}

kotlinOptions {
jvmTarget = rootProject.ext.java_version
}
kotlinOptions { jvmTarget = rootProject.ext.java_version }

buildTypes {
release {
Expand All @@ -50,25 +49,23 @@ android {
}
}

flavorDimensions "distribution"
flavorDimensions 'distribution'
productFlavors {
standard {
dimension "distribution"
dimension 'distribution'
apply plugin: 'com.google.gms.google-services'
}
fdroid {
dimension "distribution"
}
fdroid { dimension 'distribution' }
preprod {
dimension "distribution"
dimension 'distribution'
buildConfigField 'String', 'DRIVE_API', '"https://drive.preprod.dev.infomaniak.ch/drive/"'
buildConfigField 'String', 'DRIVE_API_V2', '"https://drive.preprod.dev.infomaniak.ch/2/drive/"'
}
}

gradle.buildFinished { BuildResult buildResult ->
try {
"say \"Ok\"".execute()
'say \"Ok\"'.execute()
} catch (Throwable ignored) {
}
}
Expand Down Expand Up @@ -101,7 +98,7 @@ sentry {
}

dependencies {
implementation fileTree(dir: "libs", include: ["*.jar"])
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation project(path: ':Core')

def work_version = '2.7.1'
Expand Down Expand Up @@ -131,13 +128,11 @@ dependencies {
implementation "io.coil-kt:coil-gif:$coil_version"

def glide_version = '4.12.0'
implementation("com.github.bumptech.glide:glide:$glide_version") {
exclude group: "com.android.support"
}
implementation("com.github.bumptech.glide:glide:$glide_version") { exclude group: 'com.android.support' }
implementation "com.github.bumptech.glide:okhttp3-integration:$glide_version"
kapt "com.github.bumptech.glide:compiler:$glide_version"

implementation "io.realm:android-adapters:4.0.0"
implementation 'io.realm:android-adapters:4.0.0'

standardImplementation 'com.google.android.play:core:1.10.3'
standardImplementation 'com.google.firebase:firebase-messaging-ktx:23.0.0'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ import com.infomaniak.drive.data.api.ApiRepository.putFileShareLink
import com.infomaniak.drive.data.api.ApiRepository.removeCategory
import com.infomaniak.drive.data.api.ApiRepository.updateDropBox
import com.infomaniak.drive.data.api.ApiRoutes.postFileShare
import com.infomaniak.drive.data.api.ErrorCode.Companion.translateError
import com.infomaniak.drive.data.models.File
import com.infomaniak.drive.utils.ApiTestUtils.assertApiResponseData
import com.infomaniak.drive.utils.ApiTestUtils.createDropBoxForTest
Expand Down Expand Up @@ -278,8 +279,11 @@ class ApiRepositoryTest : KDriveTest() {
fun getFileActivities() {
val okHttpClientWithTimeout = runBlocking { KDriveHttpClient.getHttpClient(user.id, 30) }
with(getFileActivities(okHttpClientWithTimeout, testFile, 1)) {
Log.e("getFileActivityTest", "api response error : ${context.getString(translatedError)}")
assertApiResponseData(this)
if (isSuccess()) {
assertApiResponseData(this)
} else {
Log.e("getFileActivityTest", "api response error : ${context.getString(translatedError)}")
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ object ApiRepository {
return callApi(
ApiRoutes.createTeamFolder(driveId),
POST,
mapOf("name" to name, "for_all_users" to forAllUsers),
mapOf("name" to name, "for_all_user" to forAllUsers),
okHttpClient = okHttpClient
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ class UploadTask(

val url = uploadUrl(
chunkNumber = chunkNumber,
conflictOption = if (uploadFile.isSync() || uploadFile.isCloudStorage()) ConflictOption.REPLACE else ConflictOption.RENAME,
conflictOption = if (uploadFile.replaceOnConflict()) ConflictOption.REPLACE else ConflictOption.RENAME,
currentChunkSize = count,
totalChunks = totalChunks
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,10 @@ enum class BulkOperationType(@StringRes val title: Int, @PluralsRes val successM
COPY(R.string.fileListCopyInProgressSnackbar, R.plurals.fileListDuplicationConfirmationSnackbar),
COLOR_FOLDER(0, R.plurals.fileListColorFolderConfirmationSnackbar),

SET_OFFLINE(0, successMessage = R.plurals.fileListAddOfflineConfirmationSnackbar),
ADD_FAVORITES(0, successMessage = R.plurals.fileListAddFavorisConfirmationSnackbar);
ADD_OFFLINE(0, successMessage = R.plurals.fileListAddOfflineConfirmationSnackbar),
REMOVE_OFFLINE(0, successMessage = R.plurals.fileListRemoveOfflineConfirmationSnackbar),
ADD_FAVORITES(0, successMessage = R.plurals.fileListAddFavoritesConfirmationSnackbar),
REMOVE_FAVORITES(0, successMessage = R.plurals.fileListRemoveFavoritesConfirmationSnackbar);

fun getNotificationBuilder(context: Context): NotificationCompat.Builder {
return when (this) {
Expand Down
29 changes: 26 additions & 3 deletions app/src/main/java/com/infomaniak/drive/data/models/File.kt
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import android.content.Context
import android.net.Uri
import android.os.Parcelable
import android.webkit.MimeTypeMap
import androidx.core.content.FileProvider
import androidx.core.net.toUri
import androidx.work.WorkInfo
import androidx.work.WorkManager
import com.google.gson.annotations.SerializedName
Expand All @@ -36,6 +36,7 @@ import com.infomaniak.drive.utils.RealmListParceler.FileRealmListParceler
import com.infomaniak.drive.utils.RealmListParceler.IntRealmListParceler
import com.infomaniak.drive.utils.Utils.INDETERMINATE_PROGRESS
import com.infomaniak.drive.utils.Utils.ROOT_ID
import com.infomaniak.drive.utils.contains
import com.infomaniak.lib.core.BuildConfig
import io.realm.RealmList
import io.realm.RealmObject
Expand Down Expand Up @@ -158,7 +159,7 @@ open class File(
fun onlyOfficeUrl() = "${BuildConfig.AUTOLOG_URL}?url=" + ApiRoutes.showOffice(this)

fun getFileType(): ConvertedType {
return when (convertedType) {
return if (isFromUploads) getFileTypeFromExtension() else when (convertedType) {
ConvertedType.ARCHIVE.value -> ConvertedType.ARCHIVE
ConvertedType.AUDIO.value -> ConvertedType.AUDIO
ConvertedType.CODE.value -> if (isBookmark()) ConvertedType.URL else ConvertedType.CODE
Expand Down Expand Up @@ -437,7 +438,8 @@ open class File(
val offlineFile = getOfflineFile(context, userDrive.userId)

return cloudUri to if (isOffline && offlineFile != null) {
FileProvider.getUriForFile(context, context.getString(R.string.FILE_AUTHORITY), offlineFile)
// We use the uri with scheme file because some apps don't support modifications from a content uri
offlineFile.toUri()
} else cloudUri
}

Expand All @@ -451,5 +453,26 @@ open class File(
val mediaFolder = context.externalMediaDirs?.firstOrNull() ?: context.filesDir
return java.io.File(mediaFolder, context.getString(R.string.EXPOSED_OFFLINE_DIR))
}

/**
* This method is here, and not directly a class method in the File class, because of a supposed Realm bug.
* When we try to put it in the File class, the app doesn't build anymore, because of a "broken method".
* This is not the only method in this case, search this comment in the project, and you'll see.
* Realm's Github issue: https://github.com/realm/realm-java/issues/7637
*/
fun File.getFileTypeFromExtension(): ConvertedType {
return when (getMimeType()) {
in Regex("application/(zip|rar|x-tar|.*compressed|.*archive)") -> ConvertedType.ARCHIVE
in Regex("audio/") -> ConvertedType.AUDIO
in Regex("image/") -> ConvertedType.IMAGE
in Regex("/pdf") -> ConvertedType.PDF
in Regex("presentation") -> ConvertedType.PRESENTATION
in Regex("spreadsheet|excel|comma-separated-values") -> ConvertedType.SPREADSHEET
in Regex("document|text/plain|msword") -> ConvertedType.TEXT
in Regex("video/") -> ConvertedType.VIDEO
in Regex("text/|application/") -> ConvertedType.CODE
else -> ConvertedType.UNKNOWN
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,9 @@ open class UploadFile(

fun isSyncOffline() = type == Type.SYNC_OFFLINE.name

fun isCloudStorage() = type == Type.CLOUD_STORAGE.name
private fun isCloudStorage() = type == Type.CLOUD_STORAGE.name

fun replaceOnConflict() = isSync() || isSyncOffline() || isCloudStorage()

fun refreshIdentifier() {
getRealmInstance().use { realm ->
Expand Down
Loading

0 comments on commit e443f00

Please sign in to comment.