Skip to content

Commit

Permalink
Merge pull request #852 from Infomaniak/removeGeniusScanForFdroid
Browse files Browse the repository at this point in the history
Remove genius scan for fdroid
  • Loading branch information
sirambd authored Jul 25, 2022
2 parents f0f2663 + 1c91754 commit f933d97
Show file tree
Hide file tree
Showing 17 changed files with 247 additions and 146 deletions.
12 changes: 7 additions & 5 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,13 @@ android {
standard {
dimension 'distribution'
apply plugin: 'com.google.gms.google-services'

dependencies {
def geniusscansdk_version = '4.5.2'
implementation "com.geniusscansdk:gssdk-core:$geniusscansdk_version"
implementation "com.geniusscansdk:gssdk-ocr:$geniusscansdk_version"
implementation "com.geniusscansdk:gssdk-scanflow:$geniusscansdk_version"
}
}
fdroid { dimension 'distribution' }
preprod {
Expand Down Expand Up @@ -128,11 +135,6 @@ dependencies {
implementation 'com.tbuonomo:dotsindicator:4.2'
implementation 'com.wdullaer:materialdatetimepicker:4.2.3'

def geniusscansdk_version = '4.5.2'
implementation "com.geniusscansdk:gssdk-core:$geniusscansdk_version"
implementation "com.geniusscansdk:gssdk-ocr:$geniusscansdk_version"
implementation "com.geniusscansdk:gssdk-scanflow:$geniusscansdk_version"

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

standardImplementation 'com.google.android.play:core:1.10.3'
Expand Down
42 changes: 42 additions & 0 deletions app/src/fdroid/java/com/infomaniak/drive/GeniusScanUtils.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* Infomaniak kDrive - Android
* Copyright (C) 2022 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.drive

import android.app.Activity
import android.content.Context
import android.content.DialogInterface
import android.content.Intent
import com.google.android.material.dialog.MaterialAlertDialogBuilder
import com.infomaniak.drive.ui.MainActivity

object GeniusScanUtils {

const val SCAN_REQUEST = -1

fun Context.initGeniusScanSdk() = true

fun Activity.startScanFlow() {
MaterialAlertDialogBuilder(this, R.style.DialogStyle)
.setTitle(R.string.allErrorFeatureNotAvailableInFdroid)
.setPositiveButton("Ok") { _: DialogInterface?, _: Int -> }
.show()
}

fun MainActivity.scanResultProcessing(intent: Intent?) = Unit

}
3 changes: 1 addition & 2 deletions app/src/fdroid/java/com/infomaniak/drive/Gplay.kt
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,4 @@ fun Context.checkUpdateIsAvailable(onResult: (updateIsAvailable: Boolean) -> Uni
onResult(false)
}

fun Activity.launchInAppReview() {
}
fun Activity.launchInAppReview() = Unit
15 changes: 2 additions & 13 deletions app/src/main/java/com/infomaniak/drive/ApplicationMain.kt
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import android.content.Intent
import android.os.Build
import android.os.StrictMode
import android.os.StrictMode.VmPolicy
import android.util.Log
import androidx.appcompat.app.AppCompatDelegate
import androidx.core.app.NotificationManagerCompat
import coil.ImageLoader
Expand All @@ -34,9 +33,8 @@ import coil.disk.DiskCache
import coil.memory.MemoryCache
import com.facebook.stetho.Stetho
import com.facebook.stetho.okhttp3.StethoInterceptor
import com.geniusscansdk.core.GeniusScanSDK
import com.geniusscansdk.core.LicenseException
import com.infomaniak.drive.BuildConfig.DRIVE_API
import com.infomaniak.drive.GeniusScanUtils.initGeniusScanSdk
import com.infomaniak.drive.data.documentprovider.CloudStorageProvider.Companion.initRealm
import com.infomaniak.drive.data.models.UiSettings
import com.infomaniak.drive.data.services.MqttClientWrapper
Expand All @@ -57,7 +55,6 @@ import com.infomaniak.lib.core.networking.HttpClient
import com.infomaniak.lib.core.networking.HttpUtils
import com.infomaniak.lib.core.utils.clearStack
import com.infomaniak.lib.login.ApiToken
import io.sentry.Sentry
import io.sentry.SentryEvent
import io.sentry.SentryOptions
import io.sentry.android.core.SentryAndroid
Expand Down Expand Up @@ -108,15 +105,7 @@ class ApplicationMain : Application(), ImageLoaderFactory {

runBlocking { initRealm() }

geniusScanIsReady = try {
GeniusScanSDK.init(this, BuildConfig.GENIUS_SCAN_KEY)
true
} catch (licenseException: LicenseException) {
licenseException.printStackTrace()
Log.e("GeniusScanSDK", "The license is expired or invalid")
Sentry.captureException(licenseException)
false
}
geniusScanIsReady = initGeniusScanSdk()

AccountUtils.reloadApp = { bundle ->
val intent = Intent(this, LaunchActivity::class.java)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import com.infomaniak.drive.utils.AccountUtils
import com.infomaniak.drive.utils.KDriveHttpClient
import com.infomaniak.drive.utils.RealmModules
import com.infomaniak.drive.utils.Utils
import com.infomaniak.drive.utils.Utils.ROOT_ID
import com.infomaniak.lib.core.models.ApiResponse
import com.infomaniak.lib.core.networking.HttpClient
import io.realm.*
Expand All @@ -50,7 +51,6 @@ object FileController {
// Example: We did it when we added Categories & Colored folders, to automatically display them when updating the app.
private const val MIN_VERSION_CODE = 4_02_000_08

const val ROOT_ID = Utils.ROOT_ID
const val FAVORITES_FILE_ID = -1
const val MY_SHARES_FILE_ID = -2
const val RECENT_CHANGES_FILE_ID = -4
Expand Down
47 changes: 6 additions & 41 deletions app/src/main/java/com/infomaniak/drive/ui/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ import androidx.activity.result.IntentSenderRequest
import androidx.activity.result.contract.ActivityResultContracts.StartIntentSenderForResult
import androidx.activity.viewModels
import androidx.core.content.ContextCompat
import androidx.core.content.FileProvider
import androidx.core.graphics.drawable.toBitmap
import androidx.core.view.get
import androidx.core.view.isVisible
Expand All @@ -52,20 +51,17 @@ import androidx.navigation.fragment.NavHostFragment
import coil.ImageLoader
import coil.request.ImageRequest
import coil.transform.CircleCropTransformation
import com.geniusscansdk.scanflow.ScanFlow
import com.google.android.material.bottomnavigation.BottomNavigationMenuView
import com.google.android.material.navigation.NavigationBarItemView
import com.infomaniak.drive.BuildConfig
import com.infomaniak.drive.R
import com.infomaniak.drive.checkUpdateIsAvailable
import com.infomaniak.drive.*
import com.infomaniak.drive.GeniusScanUtils.scanResultProcessing
import com.infomaniak.drive.data.models.AppSettings
import com.infomaniak.drive.data.models.File
import com.infomaniak.drive.data.models.UiSettings
import com.infomaniak.drive.data.models.UploadFile
import com.infomaniak.drive.data.services.DownloadReceiver
import com.infomaniak.drive.data.services.UploadWorker
import com.infomaniak.drive.data.sync.UploadNotifications
import com.infomaniak.drive.launchInAppReview
import com.infomaniak.drive.ui.fileList.FileListFragment
import com.infomaniak.drive.ui.fileList.FileListFragmentArgs
import com.infomaniak.drive.utils.*
Expand All @@ -74,12 +70,9 @@ import com.infomaniak.drive.utils.NavigationUiUtils.setupWithNavControllerCustom
import com.infomaniak.drive.utils.SyncUtils.launchAllUpload
import com.infomaniak.drive.utils.SyncUtils.startContentObserverService
import com.infomaniak.drive.utils.Utils.getRootName
import com.infomaniak.lib.core.utils.FORMAT_NEW_FILE
import com.infomaniak.lib.core.utils.LiveDataNetworkStatus
import com.infomaniak.lib.core.utils.SnackbarUtils.showSnackbar
import com.infomaniak.lib.core.utils.UtilsUi.generateInitialsAvatarDrawable
import com.infomaniak.lib.core.utils.UtilsUi.getBackgroundColorBasedOnId
import com.infomaniak.lib.core.utils.format
import io.sentry.Breadcrumb
import io.sentry.Sentry
import io.sentry.SentryLevel
Expand Down Expand Up @@ -237,40 +230,12 @@ class MainActivity : BaseActivity() {
}
}

override fun onActivityResult(requestCode: Int, resultCode: Int, intent: Intent?) {
if (requestCode == ScanFlow.SCAN_REQUEST && resultCode == RESULT_OK) scanResultProcessing(intent)
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
super.onActivityResult(requestCode, resultCode, data)
if (requestCode == GeniusScanUtils.SCAN_REQUEST && resultCode == RESULT_OK) scanResultProcessing(data)
}

private fun scanResultProcessing(intent: Intent?) {
try {
val geniusScanFile = ScanFlow.getScanResultFromActivityResult(intent).multiPageDocument!!
val newName = "scan_${Date().format(FORMAT_NEW_FILE)}.${geniusScanFile.extension}"
val scanFile = java.io.File(geniusScanFile.parent, newName)
geniusScanFile.renameTo(scanFile)

val uri = FileProvider.getUriForFile(this@MainActivity, getString(R.string.FILE_AUTHORITY), scanFile)

val fileListFragment = getNavHostFragment().childFragmentManager.fragments.getOrNull(0) as? FileListFragment

Intent(this, SaveExternalFilesActivity::class.java).apply {
action = Intent.ACTION_SEND
putExtra(Intent.EXTRA_STREAM, uri)
putExtras(
SaveExternalFilesActivityArgs(
userId = AccountUtils.currentUserId,
userDriveId = AccountUtils.currentDriveId,
folderId = fileListFragment?.folderId ?: -1
).toBundle()
)
type = "/pdf"
startActivity(this)
}
} catch (exception: Exception) {
exception.printStackTrace()
Sentry.captureException(exception)
showSnackbar(R.string.anErrorHasOccurred)
}
}
fun getFileListFragment() = getNavHostFragment().childFragmentManager.fragments.getOrNull(0) as? FileListFragment

override fun onResume() {
super.onResume()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,9 @@ class SaveExternalFilesActivity : BaseActivity() {
private fun fetchFolder() = with(selectDriveViewModel) {
saveExternalFilesViewModel.folderId.observe(this@SaveExternalFilesActivity) { folderId ->

val folder = if (selectedUserId.value == null || selectedDrive.value?.id == null || folderId == null) {
val folder = if (selectedUserId.value == null || selectedDrive.value?.id == null
|| folderId == null || folderId < 1
) {
null
} else {
val userDrive = UserDrive(userId = selectedUserId.value!!, driveId = selectedDrive.value!!.id)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,9 @@ import androidx.documentfile.provider.DocumentFile
import androidx.fragment.app.activityViewModels
import androidx.lifecycle.lifecycleScope
import androidx.navigation.fragment.findNavController
import com.geniusscansdk.scanflow.ScanConfiguration
import com.geniusscansdk.scanflow.ScanFlow
import com.google.android.material.bottomsheet.BottomSheetDialogFragment
import com.infomaniak.drive.ApplicationMain
import com.infomaniak.drive.GeniusScanUtils.startScanFlow
import com.infomaniak.drive.R
import com.infomaniak.drive.data.api.UploadTask
import com.infomaniak.drive.data.models.CreateFile
Expand All @@ -46,8 +45,6 @@ import com.infomaniak.drive.data.models.UserDrive
import com.infomaniak.drive.ui.MainViewModel
import com.infomaniak.drive.utils.*
import com.infomaniak.drive.utils.AccountUtils.currentUserId
import com.infomaniak.drive.utils.GeniusScanUtils.getOcrConfiguration
import com.infomaniak.drive.utils.GeniusScanUtils.removeOldScanFiles
import com.infomaniak.drive.utils.MatomoUtils.trackNewElementEvent
import com.infomaniak.drive.utils.SyncUtils.syncImmediately
import com.infomaniak.lib.core.utils.FORMAT_NEW_FILE
Expand Down Expand Up @@ -159,16 +156,7 @@ class AddFileBottomSheetDialog : BottomSheetDialogFragment() {

private fun scanDocuments() {
trackNewElement("scan")
context?.removeOldScanFiles()
val scanConfiguration = ScanConfiguration().apply {
context?.let {
backgroundColor = ContextCompat.getColor(it, R.color.previewBackground)
foregroundColor = ContextCompat.getColor(it, R.color.white)
highlightColor = ContextCompat.getColor(it, R.color.accent)
ocrConfiguration = it.getOcrConfiguration()
}
}
ScanFlow.scanWithConfiguration(activity, scanConfiguration)
activity?.startScanFlow()
dismiss()
}

Expand Down
67 changes: 0 additions & 67 deletions app/src/main/java/com/infomaniak/drive/utils/GeniusScanUtils.kt

This file was deleted.

1 change: 1 addition & 0 deletions app/src/main/res/values-de/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
<string name="allDisabled">Deaktiviert</string>
<string name="allDuplicateFileName">%1$s - Kopie%2$s</string>
<string name="allEmptyInputError">Dieses Feld darf nicht leer sein</string>
<string name="allErrorFeatureNotAvailableInFdroid">Funktion nicht verfügbar seit F-Droid</string>
<string name="allFileAddFavoris">%s zu Favoriten hinzugefügt</string>
<string name="allFileAddRightError">Sie haben nicht die Berechtigungen, um diesem Ordner Dateien hinzuzufügen.</string>
<string name="allFileDeleteFavoris">%s von den Favoriten gelöscht</string>
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values-es/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
<string name="allDisabled">Desactivado</string>
<string name="allDuplicateFileName">%1$s - Copiado%2$s</string>
<string name="allEmptyInputError">Este campo no puede estar vacío</string>
<string name="allErrorFeatureNotAvailableInFdroid">Función no disponible desde F-Droid</string>
<string name="allFileAddFavoris">%s añadido a favoritos</string>
<string name="allFileAddRightError">No tienes los derechos para acceder a los archivos en esta carpeta.</string>
<string name="allFileDeleteFavoris">%s eliminado de favoritos</string>
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values-fr/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
<string name="allDisabled">Désactivé</string>
<string name="allDuplicateFileName">%1$s - Copie%2$s</string>
<string name="allEmptyInputError">Ce champ ne peut pas être vide</string>
<string name="allErrorFeatureNotAvailableInFdroid">Fonctionnalité indisponible depuis F-Droid</string>
<string name="allFileAddFavoris">%s ajouté aux favoris</string>
<string name="allFileAddRightError">Vous n’avez pas les droits d’ajouter des fichiers dans ce dossier.</string>
<string name="allFileDeleteFavoris">%s supprimé des favoris</string>
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values-it/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
<string name="allDisabled">Disattivato</string>
<string name="allDuplicateFileName">%1$s - Copia%2$s</string>
<string name="allEmptyInputError">Il campo deve essere compilato</string>
<string name="allErrorFeatureNotAvailableInFdroid">Funzione non disponibile da F-Droid</string>
<string name="allFileAddFavoris">%s aggiunto ai preferiti</string>
<string name="allFileAddRightError">Non si dispone dei diritti necessari per aggiungere file a questa cartella.</string>
<string name="allFileDeleteFavoris">%s eliminato dai preferiti</string>
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
<string name="allDisabled">Disabled</string>
<string name="allDuplicateFileName">%1$s - Copy%2$s</string>
<string name="allEmptyInputError">This field cannot be empty</string>
<string name="allErrorFeatureNotAvailableInFdroid">Feature not available since F-Droid</string>
<string name="allFileAddFavoris">%s added to favorites</string>
<string name="allFileAddRightError">You’re not authorised to add files to this folder.</string>
<string name="allFileDeleteFavoris">%s deleted from favorites</string>
Expand Down
Loading

0 comments on commit f933d97

Please sign in to comment.