Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ android {
applicationId "com.kharagedition.tibetankeyboard"
minSdkVersion 23
targetSdkVersion 36
versionCode 42
versionName "2.1.12"
versionCode 45
versionName "2.1.15"

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
multiDexEnabled true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ import com.kharagedition.tibetankeyboard.R
import com.kharagedition.tibetankeyboard.UserPreferences
import com.kharagedition.tibetankeyboard.repo.UserRepository
import com.kharagedition.tibetankeyboard.ui.ChatActivity
import com.kharagedition.tibetankeyboard.subscription.RevenueCatManager
import com.kharagedition.tibetankeyboard.auth.AuthManager
import android.util.Log
import kotlinx.coroutines.launch

class LoginActivity : AppCompatActivity() {
Expand All @@ -46,6 +49,7 @@ class LoginActivity : AppCompatActivity() {
private lateinit var userPreferences: UserPreferences
private lateinit var textViewPrivacyPolicy: TextView
private lateinit var userRepository: UserRepository
private lateinit var revenueCatManager: RevenueCatManager

private val googleSignInLauncher = registerForActivityResult(
ActivityResultContracts.StartActivityForResult()
Expand All @@ -68,10 +72,12 @@ class LoginActivity : AppCompatActivity() {
auth = Firebase.auth
userRepository = UserRepository()
userPreferences = UserPreferences(this)
revenueCatManager = RevenueCatManager.getInstance()

// Check if user is already signed in
if (auth.currentUser != null && userPreferences.isUserLoggedIn()) {
navigateToChatActivity()
Log.d("LoginActivity", "User already logged in, initializing RevenueCat...")
initializeRevenueCatAndNavigate()
return
}

Expand Down Expand Up @@ -237,15 +243,33 @@ class LoginActivity : AppCompatActivity() {
)
)

navigateToChatActivity()
// CRITICAL: Initialize RevenueCat immediately after successful login
// This ensures purchases can be acknowledged with Google Play
Log.d("LoginActivity", "Initializing RevenueCat after successful login...")
revenueCatManager.initialize(this@LoginActivity, auth, object : RevenueCatManager.SubscriptionCallback {
override fun onSuccess(message: String) {
Log.d("LoginActivity", "✅ RevenueCat initialized successfully: $message")
navigateToChatActivity()
}

override fun onError(error: String) {
Log.e("LoginActivity", "❌ RevenueCat initialization failed: $error")
// Still navigate even if RevenueCat fails
navigateToChatActivity()
}

override fun onUserCancelled() {
// Not applicable here
}
})
} else {
// Even if Firestore fails, continue with login but show warning
Toast.makeText(
this@LoginActivity,
"Welcome ${firebaseUser.displayName}! (Profile sync pending)",
Toast.LENGTH_SHORT
).show()
navigateToChatActivity()
initializeRevenueCatAndNavigate()
}
} catch (e: Exception) {
hideLoading()
Expand All @@ -255,10 +279,30 @@ class LoginActivity : AppCompatActivity() {
"Welcome ${firebaseUser.displayName}!",
Toast.LENGTH_SHORT
).show()
navigateToChatActivity()
initializeRevenueCatAndNavigate()
}
}
}

/**
* Initialize RevenueCat after login and navigate to next screen
*/
private fun initializeRevenueCatAndNavigate() {
Log.d("LoginActivity", "Initializing RevenueCat after login...")
revenueCatManager.initialize(this, auth, object : RevenueCatManager.SubscriptionCallback {
override fun onSuccess(message: String) {
Log.d("LoginActivity", "✅ RevenueCat initialized: $message")
navigateToChatActivity()
}

override fun onError(error: String) {
Log.e("LoginActivity", "❌ RevenueCat init failed: $error")
navigateToChatActivity()
}

override fun onUserCancelled() {}
})
}
private fun handleLoginError(exception: Exception?) {
val errorMessage = when (exception) {
is FirebaseAuthUserCollisionException -> "An account already exists with this email"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,15 +101,29 @@ class TibetanKeyboard : InputMethodService(), OnKeyboardActionListener, AIKeyboa

private fun setKeyBoardView() {
val color = prefs.getString("colors", "#FF704C04")
val keyboardStyle = prefs.getString("keyboard_style", "classic")

keyboardView = when (color) {
"#FF704C04" -> {
layoutInflater.inflate(R.layout.keyboard_brown, null) as TibetanKeyboardView
if (keyboardStyle == "modern") {
layoutInflater.inflate(R.layout.keyboard_brown_modern, null) as TibetanKeyboardView
} else {
layoutInflater.inflate(R.layout.keyboard_brown, null) as TibetanKeyboardView
}
}
"#FF000000" -> {
layoutInflater.inflate(R.layout.keyboard_black, null) as TibetanKeyboardView
if (keyboardStyle == "modern") {
layoutInflater.inflate(R.layout.keyboard_black_modern, null) as TibetanKeyboardView
} else {
layoutInflater.inflate(R.layout.keyboard_black, null) as TibetanKeyboardView
}
}
else -> {
layoutInflater.inflate(R.layout.keyboard_green, null) as TibetanKeyboardView
if (keyboardStyle == "modern") {
layoutInflater.inflate(R.layout.keyboard_green_modern, null) as TibetanKeyboardView
} else {
layoutInflater.inflate(R.layout.keyboard_green, null) as TibetanKeyboardView
}
}
}
keyboardView?.setBackgroundColor(Color.parseColor(color))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,21 +31,9 @@ class TibetanKeyboardApp : Application() {
}

private fun setUpRevenueCat() {
// DO NOT initialize RevenueCat here without a user ID
// RevenueCat will be configured in RevenueCatManager when user is authenticated
// This ensures purchases are always tied to the Firebase user ID
Purchases.logLevel = LogLevel.DEBUG
val apiKey = if (BuildConfig.DEBUG) {
"goog_HqifnUJxdgpKcyrUFhRfJfAYIap"
} else {
"goog_HqifnUJxdgpKcyrUFhRfJfAYIap"
}
Purchases.configure(
PurchasesConfiguration.Builder(this, apiKey)
//.appUserID(null)
.purchasesAreCompletedBy(REVENUECAT)
.build()

)
Purchases.sharedInstance.updatedCustomerInfoListener =
UpdatedCustomerInfoListener { customerInfo -> Log.d("TAG", "onCreate: Customer Info Updated: ${customerInfo.toString()}") }

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,8 @@ class AuthManager(private val context: Context) {
return
}

// Initialize RevenueCat with current user
revenueCatManager.initialize(auth, callback)
// Initialize RevenueCat with current user and Firebase UID
revenueCatManager.initialize(context, auth, callback)
}

/**
Expand Down
Loading
Loading