Skip to content

Commit

Permalink
Move optional appscan feature to a separate module to avoid duplicati…
Browse files Browse the repository at this point in the history
…ng code between variants

This now uses a AppScanOptionalFeature injected interface that is satisfied by each module,
reducing the duplicated code to a minimum

Signed-off-by: Álvaro Brey <alvaro.brey@nextcloud.com>
  • Loading branch information
AlvaroBrey committed Jan 27, 2023
1 parent 9478fb1 commit 1917198
Show file tree
Hide file tree
Showing 29 changed files with 417 additions and 379 deletions.
8 changes: 4 additions & 4 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ dependencies {
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
implementation 'com.google.android.material:material:1.8.0'
implementation 'com.jakewharton:disklrucache:2.0.2'
implementation 'androidx.appcompat:appcompat:1.6.0'
implementation "androidx.appcompat:appcompat:$appCompatVersion"
implementation 'androidx.webkit:webkit:1.5.0'
implementation 'androidx.cardview:cardview:1.0.0'
implementation 'androidx.exifinterface:exifinterface:1.3.5'
Expand Down Expand Up @@ -276,9 +276,9 @@ dependencies {
implementation "com.github.nextcloud-deps.hwsecurity:hwsecurity-fido2:$fidoVersion"

// document scanner not available on FDroid (generic) due to OpenCV binaries
gplayImplementation "com.github.zynkware:Document-Scanning-Android-SDK:$documentScannerVersion"
huaweiImplementation "com.github.zynkware:Document-Scanning-Android-SDK:$documentScannerVersion"
qaImplementation "com.github.zynkware:Document-Scanning-Android-SDK:$documentScannerVersion"
gplayImplementation project(':appscan')
huaweiImplementation project(':appscan')
qaImplementation project(':appscan')

spotbugsPlugins 'com.h3xstream.findsecbugs:findsecbugs-plugin:1.12.0'
spotbugsPlugins 'com.mebigfatguy.fb-contrib:fb-contrib:7.4.7'
Expand Down
34 changes: 34 additions & 0 deletions app/src/generic/java/com/nextcloud/client/di/VariantModule.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
* Nextcloud Android client application
*
* @author Chris Narkiewicz
* Copyright (C) 2919 Chris Narkiewicz <hello@ezaquarii.com>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
* License as published by the Free Software Foundation; either
* version 3 of the License, or 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 AFFERO GENERAL PUBLIC LICENSE for more details.
*
* You should have received a copy of the GNU Affero General Public
* License along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.nextcloud.client.di

import com.nextcloud.client.documentscan.AppScanOptionalFeature
import dagger.Module
import dagger.Provides
import dagger.Reusable

@Module
internal class VariantModule {
@Provides
@Reusable
fun scanOptionalFeature(): AppScanOptionalFeature {
return AppScanOptionalFeature.Stub
}
}

This file was deleted.

37 changes: 37 additions & 0 deletions app/src/gplay/java/com/nextcloud/client/di/VariantModule.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* Nextcloud Android client application
*
* @author Chris Narkiewicz
* Copyright (C) 2919 Chris Narkiewicz <hello@ezaquarii.com>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
* License as published by the Free Software Foundation; either
* version 3 of the License, or 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 AFFERO GENERAL PUBLIC LICENSE for more details.
*
* You should have received a copy of the GNU Affero General Public
* License along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.nextcloud.client.di

import com.nextcloud.appscan.ScanPageContract
import com.nextcloud.client.documentscan.AppScanOptionalFeature
import dagger.Module
import dagger.Provides
import dagger.Reusable

@Module
internal class VariantModule {
@Provides
@Reusable
fun scanOptionalFeature(): AppScanOptionalFeature {
return object : AppScanOptionalFeature() {
override fun getScanContract() = ScanPageContract()
}
}
}

This file was deleted.

37 changes: 37 additions & 0 deletions app/src/huawei/java/com/nextcloud/client/di/VariantModule.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* Nextcloud Android client application
*
* @author Chris Narkiewicz
* Copyright (C) 2919 Chris Narkiewicz <hello@ezaquarii.com>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
* License as published by the Free Software Foundation; either
* version 3 of the License, or 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 AFFERO GENERAL PUBLIC LICENSE for more details.
*
* You should have received a copy of the GNU Affero General Public
* License along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.nextcloud.client.di

import com.nextcloud.appscan.ScanPageContract
import com.nextcloud.client.documentscan.AppScanOptionalFeature
import dagger.Module
import dagger.Provides
import dagger.Reusable

@Module
internal class VariantModule {
@Provides
@Reusable
fun scanOptionalFeature(): AppScanOptionalFeature {
return object : AppScanOptionalFeature() {
override fun getScanContract() = ScanPageContract()
}
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
ThemeModule.class,
DatabaseModule.class,
DispatcherModule.class,
VariantModule.class
})
@Singleton
public interface AppComponent {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
* Nextcloud Android client application
*
* @author Álvaro Brey
* Copyright (C) 2023 Álvaro Brey
* Copyright (C) 2023 Nextcloud GmbH
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
* License as published by the Free Software Foundation; either
* version 3 of the License, or 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 AFFERO GENERAL PUBLIC LICENSE for more details.
*
* You should have received a copy of the GNU Affero General Public
* License along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/

package com.nextcloud.client.documentscan

import androidx.activity.result.contract.ActivityResultContract

abstract class AppScanOptionalFeature {
/**
* Check [isAvailable] before calling this method.
*/
abstract fun getScanContract(): ActivityResultContract<Unit, String?>
open val isAvailable: Boolean = true

/**
* Use this in variants where the feature is not available
*/
@Suppress("unused") // used only in some variants
object Stub : AppScanOptionalFeature() {
override fun getScanContract(): ActivityResultContract<Unit, String?> {
throw UnsupportedOperationException("Document scan is not available")
}

override val isAvailable = false
}
}
Loading

0 comments on commit 1917198

Please sign in to comment.