Skip to content

Commit b9d9c0d

Browse files
Merge pull request #10 from CodingWithTashi/feat/payment-integration
Feat/payment integration
2 parents 7dac3b5 + 2330f40 commit b9d9c0d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+779
-68
lines changed

app/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ android {
1313
applicationId "com.kharagedition.tibetankeyboard"
1414
minSdkVersion 23
1515
targetSdkVersion 36
16-
versionCode 42
17-
versionName "2.1.12"
16+
versionCode 45
17+
versionName "2.1.15"
1818

1919
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
2020
multiDexEnabled true

app/src/main/java/com/kharagedition/tibetankeyboard/LoginActivity.kt

Lines changed: 48 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@ import com.kharagedition.tibetankeyboard.R
3535
import com.kharagedition.tibetankeyboard.UserPreferences
3636
import com.kharagedition.tibetankeyboard.repo.UserRepository
3737
import com.kharagedition.tibetankeyboard.ui.ChatActivity
38+
import com.kharagedition.tibetankeyboard.subscription.RevenueCatManager
39+
import com.kharagedition.tibetankeyboard.auth.AuthManager
40+
import android.util.Log
3841
import kotlinx.coroutines.launch
3942

4043
class LoginActivity : AppCompatActivity() {
@@ -46,6 +49,7 @@ class LoginActivity : AppCompatActivity() {
4649
private lateinit var userPreferences: UserPreferences
4750
private lateinit var textViewPrivacyPolicy: TextView
4851
private lateinit var userRepository: UserRepository
52+
private lateinit var revenueCatManager: RevenueCatManager
4953

5054
private val googleSignInLauncher = registerForActivityResult(
5155
ActivityResultContracts.StartActivityForResult()
@@ -68,10 +72,12 @@ class LoginActivity : AppCompatActivity() {
6872
auth = Firebase.auth
6973
userRepository = UserRepository()
7074
userPreferences = UserPreferences(this)
75+
revenueCatManager = RevenueCatManager.getInstance()
7176

7277
// Check if user is already signed in
7378
if (auth.currentUser != null && userPreferences.isUserLoggedIn()) {
74-
navigateToChatActivity()
79+
Log.d("LoginActivity", "User already logged in, initializing RevenueCat...")
80+
initializeRevenueCatAndNavigate()
7581
return
7682
}
7783

@@ -237,15 +243,33 @@ class LoginActivity : AppCompatActivity() {
237243
)
238244
)
239245

240-
navigateToChatActivity()
246+
// CRITICAL: Initialize RevenueCat immediately after successful login
247+
// This ensures purchases can be acknowledged with Google Play
248+
Log.d("LoginActivity", "Initializing RevenueCat after successful login...")
249+
revenueCatManager.initialize(this@LoginActivity, auth, object : RevenueCatManager.SubscriptionCallback {
250+
override fun onSuccess(message: String) {
251+
Log.d("LoginActivity", "✅ RevenueCat initialized successfully: $message")
252+
navigateToChatActivity()
253+
}
254+
255+
override fun onError(error: String) {
256+
Log.e("LoginActivity", "❌ RevenueCat initialization failed: $error")
257+
// Still navigate even if RevenueCat fails
258+
navigateToChatActivity()
259+
}
260+
261+
override fun onUserCancelled() {
262+
// Not applicable here
263+
}
264+
})
241265
} else {
242266
// Even if Firestore fails, continue with login but show warning
243267
Toast.makeText(
244268
this@LoginActivity,
245269
"Welcome ${firebaseUser.displayName}! (Profile sync pending)",
246270
Toast.LENGTH_SHORT
247271
).show()
248-
navigateToChatActivity()
272+
initializeRevenueCatAndNavigate()
249273
}
250274
} catch (e: Exception) {
251275
hideLoading()
@@ -255,10 +279,30 @@ class LoginActivity : AppCompatActivity() {
255279
"Welcome ${firebaseUser.displayName}!",
256280
Toast.LENGTH_SHORT
257281
).show()
258-
navigateToChatActivity()
282+
initializeRevenueCatAndNavigate()
259283
}
260284
}
261285
}
286+
287+
/**
288+
* Initialize RevenueCat after login and navigate to next screen
289+
*/
290+
private fun initializeRevenueCatAndNavigate() {
291+
Log.d("LoginActivity", "Initializing RevenueCat after login...")
292+
revenueCatManager.initialize(this, auth, object : RevenueCatManager.SubscriptionCallback {
293+
override fun onSuccess(message: String) {
294+
Log.d("LoginActivity", "✅ RevenueCat initialized: $message")
295+
navigateToChatActivity()
296+
}
297+
298+
override fun onError(error: String) {
299+
Log.e("LoginActivity", "❌ RevenueCat init failed: $error")
300+
navigateToChatActivity()
301+
}
302+
303+
override fun onUserCancelled() {}
304+
})
305+
}
262306
private fun handleLoginError(exception: Exception?) {
263307
val errorMessage = when (exception) {
264308
is FirebaseAuthUserCollisionException -> "An account already exists with this email"

app/src/main/java/com/kharagedition/tibetankeyboard/TibetanKeyboard.kt

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -101,15 +101,29 @@ class TibetanKeyboard : InputMethodService(), OnKeyboardActionListener, AIKeyboa
101101

102102
private fun setKeyBoardView() {
103103
val color = prefs.getString("colors", "#FF704C04")
104+
val keyboardStyle = prefs.getString("keyboard_style", "classic")
105+
104106
keyboardView = when (color) {
105107
"#FF704C04" -> {
106-
layoutInflater.inflate(R.layout.keyboard_brown, null) as TibetanKeyboardView
108+
if (keyboardStyle == "modern") {
109+
layoutInflater.inflate(R.layout.keyboard_brown_modern, null) as TibetanKeyboardView
110+
} else {
111+
layoutInflater.inflate(R.layout.keyboard_brown, null) as TibetanKeyboardView
112+
}
107113
}
108114
"#FF000000" -> {
109-
layoutInflater.inflate(R.layout.keyboard_black, null) as TibetanKeyboardView
115+
if (keyboardStyle == "modern") {
116+
layoutInflater.inflate(R.layout.keyboard_black_modern, null) as TibetanKeyboardView
117+
} else {
118+
layoutInflater.inflate(R.layout.keyboard_black, null) as TibetanKeyboardView
119+
}
110120
}
111121
else -> {
112-
layoutInflater.inflate(R.layout.keyboard_green, null) as TibetanKeyboardView
122+
if (keyboardStyle == "modern") {
123+
layoutInflater.inflate(R.layout.keyboard_green_modern, null) as TibetanKeyboardView
124+
} else {
125+
layoutInflater.inflate(R.layout.keyboard_green, null) as TibetanKeyboardView
126+
}
113127
}
114128
}
115129
keyboardView?.setBackgroundColor(Color.parseColor(color))

app/src/main/java/com/kharagedition/tibetankeyboard/TibetanKeyboardApp.kt

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -31,21 +31,9 @@ class TibetanKeyboardApp : Application() {
3131
}
3232

3333
private fun setUpRevenueCat() {
34+
// DO NOT initialize RevenueCat here without a user ID
35+
// RevenueCat will be configured in RevenueCatManager when user is authenticated
36+
// This ensures purchases are always tied to the Firebase user ID
3437
Purchases.logLevel = LogLevel.DEBUG
35-
val apiKey = if (BuildConfig.DEBUG) {
36-
"goog_HqifnUJxdgpKcyrUFhRfJfAYIap"
37-
} else {
38-
"goog_HqifnUJxdgpKcyrUFhRfJfAYIap"
39-
}
40-
Purchases.configure(
41-
PurchasesConfiguration.Builder(this, apiKey)
42-
//.appUserID(null)
43-
.purchasesAreCompletedBy(REVENUECAT)
44-
.build()
45-
46-
)
47-
Purchases.sharedInstance.updatedCustomerInfoListener =
48-
UpdatedCustomerInfoListener { customerInfo -> Log.d("TAG", "onCreate: Customer Info Updated: ${customerInfo.toString()}") }
49-
5038
}
5139
}

app/src/main/java/com/kharagedition/tibetankeyboard/auth/AuthManager.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,8 @@ class AuthManager(private val context: Context) {
9292
return
9393
}
9494

95-
// Initialize RevenueCat with current user
96-
revenueCatManager.initialize(auth, callback)
95+
// Initialize RevenueCat with current user and Firebase UID
96+
revenueCatManager.initialize(context, auth, callback)
9797
}
9898

9999
/**

0 commit comments

Comments
 (0)