From cf11988327e486c3e62d58f5131c6aeb0dc63c2f Mon Sep 17 00:00:00 2001
From: Taras Smakula <tarassmakula@gmail.com>
Date: Fri, 9 Jun 2023 20:12:17 +0300
Subject: [PATCH] Remove flavors from auth module

---
 app/build.gradle                               |  3 +++
 .../java/org/futo/circles/di/FlavorModule.kt   | 18 +++++++++++++++++-
 .../java/org/futo/circles/di/FlavorModule.kt   | 16 +++++++++++++++-
 .../google/GoogleSubscriptionsManager.kt       |  4 ++--
 .../google/ProductDetailsMapping.kt            |  2 +-
 {auth => app}/src/gplay/res/values/strings.xml |  1 +
 app/src/main/res/values/strings.xml            |  6 ------
 auth/build.gradle                              | 14 --------------
 .../SubscriptionManagerProvider.kt             | 13 -------------
 auth/src/fdroid/res/values/strings.xml         | 11 -----------
 .../SubscriptionManagerProvider.kt             | 12 ------------
 .../sign_up_type/SelectSignUpTypeFragment.kt   |  8 ++++++--
 .../SubscriptionStageFragment.kt               |  8 ++++++--
 auth/src/main/res/values/strings.xml           |  3 +--
 core/src/fdroid/AndroidManifest.xml            | 16 ----------------
 core/src/fdroid/res/values/strings.xml         | 11 -----------
 core/src/gplay/AndroidManifest.xml             | 15 ---------------
 17 files changed, 52 insertions(+), 109 deletions(-)
 rename {auth/src/gplay/java/org/futo/circles/auth => app/src/gplay/java/org/futo/circles}/subscriptions/google/GoogleSubscriptionsManager.kt (99%)
 rename {auth/src/gplay/java/org/futo/circles/auth => app/src/gplay/java/org/futo/circles}/subscriptions/google/ProductDetailsMapping.kt (95%)
 rename {auth => app}/src/gplay/res/values/strings.xml (84%)
 delete mode 100644 auth/src/fdroid/java/org/futo/circles/auth/subscriptions/SubscriptionManagerProvider.kt
 delete mode 100644 auth/src/fdroid/res/values/strings.xml
 delete mode 100644 auth/src/gplay/java/org/futo/circles/auth/subscriptions/SubscriptionManagerProvider.kt
 delete mode 100644 core/src/fdroid/AndroidManifest.xml
 delete mode 100644 core/src/fdroid/res/values/strings.xml
 delete mode 100644 core/src/gplay/AndroidManifest.xml

diff --git a/app/build.gradle b/app/build.gradle
index 4f5eabd93..46a7d49ec 100644
--- a/app/build.gradle
+++ b/app/build.gradle
@@ -67,6 +67,9 @@ dependencies {
     gplayImplementation 'com.google.firebase:firebase-analytics-ktx'
     gplayImplementation 'com.google.firebase:firebase-messaging-ktx'
 
+    //Subscriptions
+    gplayImplementation 'com.android.billingclient:billing-ktx:6.0.0'
+
     // UnifiedPush
     implementation 'com.github.UnifiedPush:android-connector:2.1.1'
 
diff --git a/app/src/fdroid/java/org/futo/circles/di/FlavorModule.kt b/app/src/fdroid/java/org/futo/circles/di/FlavorModule.kt
index df52ee758..057a6e24f 100644
--- a/app/src/fdroid/java/org/futo/circles/di/FlavorModule.kt
+++ b/app/src/fdroid/java/org/futo/circles/di/FlavorModule.kt
@@ -1,11 +1,17 @@
 package org.futo.circles.di
 
 import android.content.Context
+import androidx.fragment.app.Fragment
 import dagger.Binds
 import dagger.Module
 import dagger.Provides
 import dagger.hilt.InstallIn
+import dagger.hilt.android.qualifiers.ApplicationContext
 import dagger.hilt.components.SingletonComponent
+import org.futo.circles.R
+import org.futo.circles.auth.subscriptions.ItemPurchasedListener
+import org.futo.circles.auth.subscriptions.SubscriptionManager
+import org.futo.circles.auth.subscriptions.SubscriptionProvider
 import org.futo.circles.core.provider.PreferencesProvider
 import org.futo.circles.feature.notifications.FcmHelper
 import org.futo.circles.feature.notifications.GuardServiceStarter
@@ -22,9 +28,19 @@ abstract class FlavorModule {
         @Provides
         fun provideGuardServiceStarter(
             preferences: PreferencesProvider,
-            appContext: Context
+            @ApplicationContext appContext: Context
         ): GuardServiceStarter = FdroidGuardServiceStarter(appContext, preferences)
 
+        @Provides
+        fun provideSubscriptionProvider(): SubscriptionProvider {
+            return object : SubscriptionProvider {
+                override fun getManager(
+                    fragment: Fragment,
+                    itemPurchaseListener: ItemPurchasedListener?
+                ): SubscriptionManager =
+                    throw IllegalStateException(fragment.getString(R.string.flavour_does_not_support_subscriptions))
+            }
+        }
     }
 
     @Binds
diff --git a/app/src/gplay/java/org/futo/circles/di/FlavorModule.kt b/app/src/gplay/java/org/futo/circles/di/FlavorModule.kt
index 7c584eb5c..aebf40b62 100644
--- a/app/src/gplay/java/org/futo/circles/di/FlavorModule.kt
+++ b/app/src/gplay/java/org/futo/circles/di/FlavorModule.kt
@@ -1,16 +1,20 @@
 package org.futo.circles.di
 
+import androidx.fragment.app.Fragment
 import dagger.Binds
 import dagger.Module
 import dagger.Provides
 import dagger.hilt.InstallIn
 import dagger.hilt.components.SingletonComponent
+import org.futo.circles.auth.subscriptions.ItemPurchasedListener
+import org.futo.circles.auth.subscriptions.SubscriptionManager
+import org.futo.circles.auth.subscriptions.SubscriptionProvider
 import org.futo.circles.feature.notifications.FcmHelper
 import org.futo.circles.feature.notifications.GuardServiceStarter
 import org.futo.circles.feature.notifications.test.task.NotificationTestsProvider
 import org.futo.circles.notifications.GoogleFcmHelper
 import org.futo.circles.notifications.test.GoogleNotificationTestProvider
-import javax.inject.Singleton
+import org.futo.circles.subscriptions.google.GoogleSubscriptionsManager
 
 @Module
 @InstallIn(SingletonComponent::class)
@@ -21,6 +25,16 @@ abstract class FlavorModule {
         fun provideGuardServiceStarter(): GuardServiceStarter {
             return object : GuardServiceStarter {}
         }
+
+        @Provides
+        fun provideSubscriptionProvider(): SubscriptionProvider {
+            return object : SubscriptionProvider {
+                override fun getManager(
+                    fragment: Fragment,
+                    itemPurchaseListener: ItemPurchasedListener?
+                ): SubscriptionManager = GoogleSubscriptionsManager(fragment, itemPurchaseListener)
+            }
+        }
     }
 
     @Binds
diff --git a/auth/src/gplay/java/org/futo/circles/auth/subscriptions/google/GoogleSubscriptionsManager.kt b/app/src/gplay/java/org/futo/circles/subscriptions/google/GoogleSubscriptionsManager.kt
similarity index 99%
rename from auth/src/gplay/java/org/futo/circles/auth/subscriptions/google/GoogleSubscriptionsManager.kt
rename to app/src/gplay/java/org/futo/circles/subscriptions/google/GoogleSubscriptionsManager.kt
index 7494f7f57..b5031d137 100644
--- a/auth/src/gplay/java/org/futo/circles/auth/subscriptions/google/GoogleSubscriptionsManager.kt
+++ b/app/src/gplay/java/org/futo/circles/subscriptions/google/GoogleSubscriptionsManager.kt
@@ -1,4 +1,4 @@
-package org.futo.circles.auth.subscriptions.google
+package org.futo.circles.subscriptions.google
 
 import androidx.fragment.app.Fragment
 import androidx.lifecycle.DefaultLifecycleObserver
@@ -6,7 +6,7 @@ import androidx.lifecycle.LifecycleOwner
 import com.android.billingclient.api.*
 import com.android.billingclient.api.BillingClient.BillingResponseCode.*
 import kotlinx.coroutines.suspendCancellableCoroutine
-import org.futo.circles.auth.R
+import org.futo.circles.R
 import org.futo.circles.auth.model.SubscriptionListItem
 import org.futo.circles.auth.model.SubscriptionReceiptData
 import org.futo.circles.auth.subscriptions.ItemPurchasedListener
diff --git a/auth/src/gplay/java/org/futo/circles/auth/subscriptions/google/ProductDetailsMapping.kt b/app/src/gplay/java/org/futo/circles/subscriptions/google/ProductDetailsMapping.kt
similarity index 95%
rename from auth/src/gplay/java/org/futo/circles/auth/subscriptions/google/ProductDetailsMapping.kt
rename to app/src/gplay/java/org/futo/circles/subscriptions/google/ProductDetailsMapping.kt
index 75aa8e3c8..77f49a705 100644
--- a/auth/src/gplay/java/org/futo/circles/auth/subscriptions/google/ProductDetailsMapping.kt
+++ b/app/src/gplay/java/org/futo/circles/subscriptions/google/ProductDetailsMapping.kt
@@ -1,4 +1,4 @@
-package org.futo.circles.auth.subscriptions.google
+package org.futo.circles.subscriptions.google
 
 import android.content.Context
 import com.android.billingclient.api.ProductDetails
diff --git a/auth/src/gplay/res/values/strings.xml b/app/src/gplay/res/values/strings.xml
similarity index 84%
rename from auth/src/gplay/res/values/strings.xml
rename to app/src/gplay/res/values/strings.xml
index de369a42a..a722a40f2 100644
--- a/auth/src/gplay/res/values/strings.xml
+++ b/app/src/gplay/res/values/strings.xml
@@ -6,4 +6,5 @@
     <string name="user_canceled">User canceled</string>
     <string name="item_not_owned">Item is not owned</string>
     <string name="developer_error">Developer error</string>
+    <string name="purchase_failed_format">Purchase failed with code %d</string>
 </resources>
\ No newline at end of file
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index 26db88f31..771da2934 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -164,12 +164,6 @@
     <string name="confirm">Confirm</string>
     <string name="reset_keys">Reset keys</string>
     <string name="reset_keys_message">Confirm auth to reset keys and enable cross signing</string>
-    <string name="feature_not_supported">Feature is not supported</string>
-    <string name="service_unavailable">Service unavailable</string>
-    <string name="item_unavailable">Item is unavailable</string>
-    <string name="user_canceled">User canceled</string>
-    <string name="item_not_owned">Item is not owned</string>
-    <string name="developer_error">Developer error</string>
     <string name="upload_to_gallery">Upload to gallery</string>
     <string name="share_with_group">Share with a group</string>
     <string name="share_with_circle">Share with a circle</string>
diff --git a/auth/build.gradle b/auth/build.gradle
index 8c03432bb..bd42a29d9 100644
--- a/auth/build.gradle
+++ b/auth/build.gradle
@@ -40,17 +40,6 @@ android {
         }
     }
 
-    def flavor_dimension_name = "store"
-    flavorDimensions flavor_dimension_name
-    productFlavors {
-        gplay {
-            dimension flavor_dimension_name
-        }
-        fdroid {
-            dimension flavor_dimension_name
-        }
-    }
-
     compileOptions {
         sourceCompatibility JavaVersion.VERSION_17
         targetCompatibility JavaVersion.VERSION_17
@@ -75,9 +64,6 @@ dependencies {
     //Password strength
     implementation 'com.nulab-inc:zxcvbn:1.7.0'
 
-    //Subscriptions
-    gplayImplementation 'com.android.billingclient:billing-ktx:6.0.0'
-
     //Hilt
     def hilt = '2.46.1'
     implementation "com.google.dagger:hilt-android:$hilt"
diff --git a/auth/src/fdroid/java/org/futo/circles/auth/subscriptions/SubscriptionManagerProvider.kt b/auth/src/fdroid/java/org/futo/circles/auth/subscriptions/SubscriptionManagerProvider.kt
deleted file mode 100644
index e38c0ef55..000000000
--- a/auth/src/fdroid/java/org/futo/circles/auth/subscriptions/SubscriptionManagerProvider.kt
+++ /dev/null
@@ -1,13 +0,0 @@
-package org.futo.circles.auth.subscriptions
-
-import androidx.fragment.app.Fragment
-import org.futo.circles.auth.R
-
-object SubscriptionManagerProvider : SubscriptionProvider {
-
-    override fun getManager(
-        fragment: Fragment,
-        itemPurchaseListener: ItemPurchasedListener?
-    ): SubscriptionManager =
-        throw IllegalStateException(fragment.getString(R.string.flavour_does_not_support_subscriptions))
-}
\ No newline at end of file
diff --git a/auth/src/fdroid/res/values/strings.xml b/auth/src/fdroid/res/values/strings.xml
deleted file mode 100644
index b62816a2a..000000000
--- a/auth/src/fdroid/res/values/strings.xml
+++ /dev/null
@@ -1,11 +0,0 @@
-<resources>
-
-    <string name="flavour_does_not_support_subscriptions">This flavour does not support subscriptions</string>
-    <string name="settings_troubleshoot_test_battery_title">Battery Optimization</string>
-    <string name="settings_troubleshoot_test_battery_success">Circles is not affected by Battery Optimization.</string>
-    <string name="settings_troubleshoot_test_battery_failed">If a user leaves a device unplugged and stationary for a period of time, with the screen off, the device enters Doze mode. This prevents apps from accessing the network and defers their jobs, syncs, and standard alarms. </string>
-    <string name="settings_troubleshoot_test_bg_restricted_title">Check background restrictions</string>
-    <string name="settings_troubleshoot_test_bg_restricted_success">Background restrictions are disabled for Circles. This test should be run using mobile data (no WIFI).\n%1$s</string>
-    <string name="settings_troubleshoot_test_bg_restricted_failed">Background restrictions are enabled for Circles.\nWork that the app tries to do will be aggressively restricted while it is in the background, and this could affect notifications.\n%1$s</string>
-
-</resources>
\ No newline at end of file
diff --git a/auth/src/gplay/java/org/futo/circles/auth/subscriptions/SubscriptionManagerProvider.kt b/auth/src/gplay/java/org/futo/circles/auth/subscriptions/SubscriptionManagerProvider.kt
deleted file mode 100644
index 64dab4842..000000000
--- a/auth/src/gplay/java/org/futo/circles/auth/subscriptions/SubscriptionManagerProvider.kt
+++ /dev/null
@@ -1,12 +0,0 @@
-package org.futo.circles.auth.subscriptions
-
-import androidx.fragment.app.Fragment
-import org.futo.circles.auth.subscriptions.google.GoogleSubscriptionsManager
-
-object SubscriptionManagerProvider : SubscriptionProvider {
-
-    override fun getManager(
-        fragment: Fragment,
-        itemPurchaseListener: ItemPurchasedListener?
-    ): SubscriptionManager = GoogleSubscriptionsManager(fragment, itemPurchaseListener)
-}
\ No newline at end of file
diff --git a/auth/src/main/java/org/futo/circles/auth/feature/sign_up/sign_up_type/SelectSignUpTypeFragment.kt b/auth/src/main/java/org/futo/circles/auth/feature/sign_up/sign_up_type/SelectSignUpTypeFragment.kt
index f1ddc44ca..dc9219fae 100644
--- a/auth/src/main/java/org/futo/circles/auth/feature/sign_up/sign_up_type/SelectSignUpTypeFragment.kt
+++ b/auth/src/main/java/org/futo/circles/auth/feature/sign_up/sign_up_type/SelectSignUpTypeFragment.kt
@@ -9,12 +9,13 @@ import by.kirich1409.viewbindingdelegate.viewBinding
 import dagger.hilt.android.AndroidEntryPoint
 import org.futo.circles.auth.R
 import org.futo.circles.auth.databinding.FragmentSelectSignUpTypeBinding
-import org.futo.circles.auth.subscriptions.SubscriptionManagerProvider
+import org.futo.circles.auth.subscriptions.SubscriptionProvider
 import org.futo.circles.core.CirclesAppConfig
 import org.futo.circles.core.extensions.observeData
 import org.futo.circles.core.extensions.observeResponse
 import org.futo.circles.core.extensions.setIsVisible
 import org.futo.circles.core.fragment.HasLoadingState
+import javax.inject.Inject
 
 @AndroidEntryPoint
 class SelectSignUpTypeFragment : Fragment(R.layout.fragment_select_sign_up_type),
@@ -25,8 +26,11 @@ class SelectSignUpTypeFragment : Fragment(R.layout.fragment_select_sign_up_type)
     private val binding by viewBinding(FragmentSelectSignUpTypeBinding::bind)
     private val viewModel by viewModels<SelectSignUpTypeViewModel>()
 
+    @Inject
+    lateinit var subscriptionProvider: SubscriptionProvider
+
     private val subscriptionManager by lazy {
-        SubscriptionManagerProvider.getManager(this, null)
+        subscriptionProvider.getManager(this, null)
     }
 
     override fun onCreate(savedInstanceState: Bundle?) {
diff --git a/auth/src/main/java/org/futo/circles/auth/feature/sign_up/subscription_stage/SubscriptionStageFragment.kt b/auth/src/main/java/org/futo/circles/auth/feature/sign_up/subscription_stage/SubscriptionStageFragment.kt
index 0d7323dcb..c26a30a2d 100644
--- a/auth/src/main/java/org/futo/circles/auth/feature/sign_up/subscription_stage/SubscriptionStageFragment.kt
+++ b/auth/src/main/java/org/futo/circles/auth/feature/sign_up/subscription_stage/SubscriptionStageFragment.kt
@@ -10,10 +10,11 @@ import org.futo.circles.auth.databinding.FragmentSubscriptionStageBinding
 import org.futo.circles.auth.feature.sign_up.subscription_stage.list.SubscriptionsAdapter
 import org.futo.circles.auth.model.SubscriptionReceiptData
 import org.futo.circles.auth.subscriptions.ItemPurchasedListener
-import org.futo.circles.auth.subscriptions.SubscriptionManagerProvider
+import org.futo.circles.auth.subscriptions.SubscriptionProvider
 import org.futo.circles.core.extensions.observeResponse
 import org.futo.circles.core.extensions.showError
 import org.futo.circles.core.fragment.ParentBackPressOwnerFragment
+import javax.inject.Inject
 
 @AndroidEntryPoint
 class SubscriptionStageFragment :
@@ -22,8 +23,11 @@ class SubscriptionStageFragment :
     private val binding by viewBinding(FragmentSubscriptionStageBinding::bind)
     private val viewModel by viewModels<SubscriptionStageViewModel>()
 
+    @Inject
+    lateinit var subscriptionProvider: SubscriptionProvider
+
     private val subscriptionManager by lazy {
-        SubscriptionManagerProvider.getManager(
+        subscriptionProvider.getManager(
             this, object : ItemPurchasedListener {
                 override fun onItemPurchased(subscriptionReceiptData: SubscriptionReceiptData) {
                     viewModel.validateSubscription(subscriptionReceiptData)
diff --git a/auth/src/main/res/values/strings.xml b/auth/src/main/res/values/strings.xml
index 44004ebcf..163b48848 100644
--- a/auth/src/main/res/values/strings.xml
+++ b/auth/src/main/res/values/strings.xml
@@ -18,7 +18,6 @@
     <string name="choose_a_subscription">Choose a subscription</string>
     <string name="create_a_subscription">Create a subscription</string>
     <string name="sign_up">Sign Up</string>
-    <string name="purchase_failed_format">Purchase failed with code %d</string>
     <string name="not_supported_stage_format">Not supported stage %s</string>
     <string name="sign_up_stage_subtitle_format">Stage %1$d of %2$d</string>
     <string name="no_backup_message">Keys backup not found</string>
@@ -93,7 +92,7 @@
     <string name="remove_user_message">Are you sure you want to remove this user?</string>
     <string name="remove">Remove</string>
     <string name="not_supported_navigation_event">Not supported navigation event</string>
-
+    <string name="purchase_failed_format">Purchase failed with code %d</string>
 
     <plurals name="days">
         <item quantity="one">%1$d day</item>
diff --git a/core/src/fdroid/AndroidManifest.xml b/core/src/fdroid/AndroidManifest.xml
deleted file mode 100644
index 9f6b0aec0..000000000
--- a/core/src/fdroid/AndroidManifest.xml
+++ /dev/null
@@ -1,16 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<manifest xmlns:android="http://schemas.android.com/apk/res/android"
-    xmlns:tools="http://schemas.android.com/tools">
-
-    <uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
-
-    <application>
-
-        <service
-            android:name=".notifications.GuardAndroidService"
-            android:exported="false"
-            tools:ignore="Instantiatable" />
-
-    </application>
-
-</manifest>
diff --git a/core/src/fdroid/res/values/strings.xml b/core/src/fdroid/res/values/strings.xml
deleted file mode 100644
index b62816a2a..000000000
--- a/core/src/fdroid/res/values/strings.xml
+++ /dev/null
@@ -1,11 +0,0 @@
-<resources>
-
-    <string name="flavour_does_not_support_subscriptions">This flavour does not support subscriptions</string>
-    <string name="settings_troubleshoot_test_battery_title">Battery Optimization</string>
-    <string name="settings_troubleshoot_test_battery_success">Circles is not affected by Battery Optimization.</string>
-    <string name="settings_troubleshoot_test_battery_failed">If a user leaves a device unplugged and stationary for a period of time, with the screen off, the device enters Doze mode. This prevents apps from accessing the network and defers their jobs, syncs, and standard alarms. </string>
-    <string name="settings_troubleshoot_test_bg_restricted_title">Check background restrictions</string>
-    <string name="settings_troubleshoot_test_bg_restricted_success">Background restrictions are disabled for Circles. This test should be run using mobile data (no WIFI).\n%1$s</string>
-    <string name="settings_troubleshoot_test_bg_restricted_failed">Background restrictions are enabled for Circles.\nWork that the app tries to do will be aggressively restricted while it is in the background, and this could affect notifications.\n%1$s</string>
-
-</resources>
\ No newline at end of file
diff --git a/core/src/gplay/AndroidManifest.xml b/core/src/gplay/AndroidManifest.xml
deleted file mode 100644
index 317682623..000000000
--- a/core/src/gplay/AndroidManifest.xml
+++ /dev/null
@@ -1,15 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<manifest xmlns:android="http://schemas.android.com/apk/res/android"
-    xmlns:tools="http://schemas.android.com/tools">
-
-    <application>
-        <service android:name=".notifications.FirebaseMessagingService"
-            android:exported="false"
-            tools:ignore="Instantiatable">
-            <intent-filter>
-                <action android:name="com.google.firebase.MESSAGING_EVENT" />
-            </intent-filter>
-        </service>
-    </application>
-
-</manifest>
-- 
GitLab