From 66fc4d61daff509a8492c1e29b299b0c8cb01f43 Mon Sep 17 00:00:00 2001 From: abdrasulov Date: Thu, 2 Jan 2025 12:20:18 +0600 Subject: [PATCH] Add dev implementation of subscriptions --- app/build.gradle | 6 ++- settings.gradle | 1 + subscriptions-dev/.gitignore | 1 + subscriptions-dev/build.gradle | 42 +++++++++++++++++++ subscriptions-dev/consumer-rules.pro | 0 subscriptions-dev/proguard-rules.pro | 21 ++++++++++ .../dev/ExampleInstrumentedTest.kt | 22 ++++++++++ .../src/main/AndroidManifest.xml | 13 ++++++ .../dev/SubscriptionServiceDev.kt | 26 ++++++++++++ .../dev/SubscriptionServiceInitializer.kt | 17 ++++++++ .../subscriptions/dev/ExampleUnitTest.kt | 16 +++++++ 11 files changed, 164 insertions(+), 1 deletion(-) create mode 100644 subscriptions-dev/.gitignore create mode 100644 subscriptions-dev/build.gradle create mode 100644 subscriptions-dev/consumer-rules.pro create mode 100644 subscriptions-dev/proguard-rules.pro create mode 100644 subscriptions-dev/src/androidTest/java/io/horizontalsystems/subscriptions/dev/ExampleInstrumentedTest.kt create mode 100644 subscriptions-dev/src/main/AndroidManifest.xml create mode 100644 subscriptions-dev/src/main/java/io/horizontalsystems/subscriptions/dev/SubscriptionServiceDev.kt create mode 100644 subscriptions-dev/src/main/java/io/horizontalsystems/subscriptions/dev/SubscriptionServiceInitializer.kt create mode 100644 subscriptions-dev/src/test/java/io/horizontalsystems/subscriptions/dev/ExampleUnitTest.kt diff --git a/app/build.gradle b/app/build.gradle index 963df1dba4..36763628c3 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -319,7 +319,11 @@ dependencies { implementation project(':components:chartview') implementation project(':subscriptions-core') - implementation project(':subscriptions-google-play') + + releaseImplementation project(':subscriptions-google-play') + debugImplementation project(':subscriptions-dev') + appcenterdebugImplementation project(':subscriptions-dev') + appcenterreleaseImplementation project(':subscriptions-dev') // Integration with activities implementation 'androidx.activity:activity-compose:1.9.3' diff --git a/settings.gradle b/settings.gradle index c889f3d22c..5304504069 100644 --- a/settings.gradle +++ b/settings.gradle @@ -5,3 +5,4 @@ include ':components:icons' include ':components:chartview' include ':subscriptions-core' include ':subscriptions-google-play' +include ':subscriptions-dev' diff --git a/subscriptions-dev/.gitignore b/subscriptions-dev/.gitignore new file mode 100644 index 0000000000..42afabfd2a --- /dev/null +++ b/subscriptions-dev/.gitignore @@ -0,0 +1 @@ +/build \ No newline at end of file diff --git a/subscriptions-dev/build.gradle b/subscriptions-dev/build.gradle new file mode 100644 index 0000000000..03621311fe --- /dev/null +++ b/subscriptions-dev/build.gradle @@ -0,0 +1,42 @@ +plugins { + id 'com.android.library' + id 'org.jetbrains.kotlin.android' +} + +android { + namespace 'io.horizontalsystems.subscriptions.dev' + compileSdk 34 + + defaultConfig { + minSdk 27 + + testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" + consumerProguardFiles "consumer-rules.pro" + } + + buildTypes { + release { + minifyEnabled false + proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' + } + } + compileOptions { + sourceCompatibility JavaVersion.VERSION_11 + targetCompatibility JavaVersion.VERSION_11 + } + kotlinOptions { + jvmTarget = '11' + } +} + +dependencies { + implementation project(':subscriptions-core') + implementation "androidx.startup:startup-runtime:1.2.0" + + implementation 'androidx.core:core-ktx:1.15.0' + implementation 'androidx.appcompat:appcompat:1.7.0' + implementation 'com.google.android.material:material:1.12.0' + testImplementation 'junit:junit:4.13.2' + androidTestImplementation 'androidx.test.ext:junit:1.2.1' + androidTestImplementation 'androidx.test.espresso:espresso-core:3.6.1' +} \ No newline at end of file diff --git a/subscriptions-dev/consumer-rules.pro b/subscriptions-dev/consumer-rules.pro new file mode 100644 index 0000000000..e69de29bb2 diff --git a/subscriptions-dev/proguard-rules.pro b/subscriptions-dev/proguard-rules.pro new file mode 100644 index 0000000000..481bb43481 --- /dev/null +++ b/subscriptions-dev/proguard-rules.pro @@ -0,0 +1,21 @@ +# Add project specific ProGuard rules here. +# You can control the set of applied configuration files using the +# proguardFiles setting in build.gradle. +# +# For more details, see +# http://developer.android.com/guide/developing/tools/proguard.html + +# If your project uses WebView with JS, uncomment the following +# and specify the fully qualified class name to the JavaScript interface +# class: +#-keepclassmembers class fqcn.of.javascript.interface.for.webview { +# public *; +#} + +# Uncomment this to preserve the line number information for +# debugging stack traces. +#-keepattributes SourceFile,LineNumberTable + +# If you keep the line number information, uncomment this to +# hide the original source file name. +#-renamesourcefileattribute SourceFile \ No newline at end of file diff --git a/subscriptions-dev/src/androidTest/java/io/horizontalsystems/subscriptions/dev/ExampleInstrumentedTest.kt b/subscriptions-dev/src/androidTest/java/io/horizontalsystems/subscriptions/dev/ExampleInstrumentedTest.kt new file mode 100644 index 0000000000..f46e7aa048 --- /dev/null +++ b/subscriptions-dev/src/androidTest/java/io/horizontalsystems/subscriptions/dev/ExampleInstrumentedTest.kt @@ -0,0 +1,22 @@ +package io.horizontalsystems.subscriptions.dev + +import androidx.test.ext.junit.runners.AndroidJUnit4 +import androidx.test.platform.app.InstrumentationRegistry +import org.junit.Assert.assertEquals +import org.junit.Test +import org.junit.runner.RunWith + +/** + * Instrumented test, which will execute on an Android device. + * + * See [testing documentation](http://d.android.com/tools/testing). + */ +@RunWith(AndroidJUnit4::class) +class ExampleInstrumentedTest { + @Test + fun useAppContext() { + // Context of the app under test. + val appContext = InstrumentationRegistry.getInstrumentation().targetContext + assertEquals("io.horizontalsystems.subscriptions.dev.test", appContext.packageName) + } +} \ No newline at end of file diff --git a/subscriptions-dev/src/main/AndroidManifest.xml b/subscriptions-dev/src/main/AndroidManifest.xml new file mode 100644 index 0000000000..863b94e71e --- /dev/null +++ b/subscriptions-dev/src/main/AndroidManifest.xml @@ -0,0 +1,13 @@ + + + + + + + + \ No newline at end of file diff --git a/subscriptions-dev/src/main/java/io/horizontalsystems/subscriptions/dev/SubscriptionServiceDev.kt b/subscriptions-dev/src/main/java/io/horizontalsystems/subscriptions/dev/SubscriptionServiceDev.kt new file mode 100644 index 0000000000..59e2cd1dce --- /dev/null +++ b/subscriptions-dev/src/main/java/io/horizontalsystems/subscriptions/dev/SubscriptionServiceDev.kt @@ -0,0 +1,26 @@ +package io.horizontalsystems.subscriptions.dev + +import android.app.Activity +import io.horizontalsystems.subscriptions.core.BasePlan +import io.horizontalsystems.subscriptions.core.IPaidAction +import io.horizontalsystems.subscriptions.core.Subscription +import io.horizontalsystems.subscriptions.core.SubscriptionService + +class SubscriptionServiceDev : SubscriptionService { + + override var predefinedSubscriptions: List = listOf() + + override suspend fun onResume() = Unit + + override fun isActionAllowed(paidAction: IPaidAction) = true + + override fun getBasePlans(subscriptionId: String): List = listOf() + + override suspend fun getSubscriptions(): List = listOf() + + override suspend fun launchPurchaseFlow( + subscriptionId: String, + planId: String, + activity: Activity, + ) = null +} diff --git a/subscriptions-dev/src/main/java/io/horizontalsystems/subscriptions/dev/SubscriptionServiceInitializer.kt b/subscriptions-dev/src/main/java/io/horizontalsystems/subscriptions/dev/SubscriptionServiceInitializer.kt new file mode 100644 index 0000000000..e3f24022bb --- /dev/null +++ b/subscriptions-dev/src/main/java/io/horizontalsystems/subscriptions/dev/SubscriptionServiceInitializer.kt @@ -0,0 +1,17 @@ +package io.horizontalsystems.subscriptions.dev + +import android.content.Context +import androidx.startup.Initializer +import io.horizontalsystems.subscriptions.core.UserSubscriptionManager + +class SubscriptionServiceInitializer : Initializer { + override fun create(context: Context): SubscriptionServiceDev { + val service = SubscriptionServiceDev() + UserSubscriptionManager.registerService(service) + return service + } + + override fun dependencies(): List>> { + return emptyList() + } +} diff --git a/subscriptions-dev/src/test/java/io/horizontalsystems/subscriptions/dev/ExampleUnitTest.kt b/subscriptions-dev/src/test/java/io/horizontalsystems/subscriptions/dev/ExampleUnitTest.kt new file mode 100644 index 0000000000..a3eb5937d7 --- /dev/null +++ b/subscriptions-dev/src/test/java/io/horizontalsystems/subscriptions/dev/ExampleUnitTest.kt @@ -0,0 +1,16 @@ +package io.horizontalsystems.subscriptions.dev + +import org.junit.Assert.assertEquals +import org.junit.Test + +/** + * Example local unit test, which will execute on the development machine (host). + * + * See [testing documentation](http://d.android.com/tools/testing). + */ +class ExampleUnitTest { + @Test + fun addition_isCorrect() { + assertEquals(4, 2 + 2) + } +} \ No newline at end of file