-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #271 from mash-up-kr/feature/minuk/264-update-reco…
…mmend [Feature] 앱 업데이트 유도 기능 추가
- Loading branch information
Showing
14 changed files
with
192 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 0 additions & 18 deletions
18
app/src/main/java/com/mashup/data/repository/FirebaseRepository.kt
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package com.mashup.ui.splash | ||
|
||
import android.content.Context | ||
import androidx.core.content.pm.PackageInfoCompat | ||
import com.mashup.base.BaseViewModel | ||
import com.mashup.core.firebase.FirebaseRepository | ||
import dagger.hilt.android.lifecycle.HiltViewModel | ||
import kotlinx.coroutines.CancellationException | ||
import kotlinx.coroutines.delay | ||
import kotlinx.coroutines.flow.MutableSharedFlow | ||
import kotlinx.coroutines.flow.SharedFlow | ||
import javax.inject.Inject | ||
|
||
|
||
@HiltViewModel | ||
class SplashViewModel @Inject constructor( | ||
private val firebaseRepository: FirebaseRepository | ||
) : BaseViewModel() { | ||
|
||
private val _onLowerAppVersion = MutableSharedFlow<Unit>() | ||
val onLowerAppVersion: SharedFlow<Unit> = _onLowerAppVersion | ||
|
||
private val _onFinishInit = MutableSharedFlow<Unit>() | ||
val onFinishInit: SharedFlow<Unit> = _onFinishInit | ||
|
||
fun checkAppVersion(context: Context) = mashUpScope { | ||
try { | ||
val localVersionCode = PackageInfoCompat.getLongVersionCode( | ||
context.packageManager.getPackageInfo(context.packageName, 0) | ||
) | ||
val resentAppVersion = firebaseRepository.getRecentAppVersion() | ||
if (localVersionCode < resentAppVersion) { | ||
_onLowerAppVersion.emit(Unit) | ||
} else { | ||
delay(2000L) | ||
_onFinishInit.emit(Unit) | ||
} | ||
} catch (cancelException: CancellationException) { | ||
throw cancelException | ||
} catch (ignore: Exception) { | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/build |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
plugins { | ||
id 'com.android.library' | ||
id 'kotlin-android' | ||
id 'kotlin-kapt' | ||
} | ||
|
||
android { | ||
namespace 'com.mashup.core.firebase' | ||
compileSdk compileVersion | ||
|
||
defaultConfig { | ||
minSdk minVersion | ||
targetSdk targetVersion | ||
} | ||
compileOptions { | ||
sourceCompatibility JavaVersion.VERSION_1_8 | ||
targetCompatibility JavaVersion.VERSION_1_8 | ||
} | ||
kotlinOptions { | ||
jvmTarget = '1.8' | ||
} | ||
} | ||
|
||
dependencies { | ||
|
||
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.6.4' | ||
// hilt | ||
implementation "com.google.dagger:hilt-android:$hiltVersion" | ||
kapt "com.google.dagger:hilt-compiler:$hiltVersion" | ||
|
||
// google firebase | ||
api platform("com.google.firebase:firebase-bom:$firebaseVersion") | ||
api "com.google.firebase:firebase-analytics-ktx" | ||
api "com.google.firebase:firebase-crashlytics-ktx" | ||
api "com.google.firebase:firebase-messaging-ktx" | ||
api 'com.google.firebase:firebase-firestore-ktx' | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"> | ||
|
||
</manifest> |
36 changes: 36 additions & 0 deletions
36
core/firebase/src/main/java/com/mashup/core/firebase/FirebaseRepository.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package com.mashup.core.firebase | ||
|
||
import com.google.firebase.firestore.ktx.firestore | ||
import com.google.firebase.ktx.Firebase | ||
import com.google.firebase.messaging.FirebaseMessaging | ||
import kotlinx.coroutines.suspendCancellableCoroutine | ||
import javax.inject.Inject | ||
import javax.inject.Singleton | ||
|
||
@Singleton | ||
class FirebaseRepository @Inject constructor() { | ||
suspend fun getFcmToken(): String = suspendCancellableCoroutine { continuation -> | ||
FirebaseMessaging.getInstance().token.addOnCompleteListener { task -> | ||
if (task.isSuccessful) { | ||
continuation.resume(task.result) {} | ||
} else { | ||
continuation.cancel() | ||
} | ||
} | ||
} | ||
|
||
suspend fun getRecentAppVersion(): Long = suspendCancellableCoroutine { continuation -> | ||
Firebase.firestore.document("app/config").get() | ||
.addOnSuccessListener { document -> | ||
val version = document?.getLong("version") | ||
if (version != null) { | ||
continuation.resume(version) {} | ||
} else { | ||
continuation.cancel() | ||
} | ||
} | ||
.addOnFailureListener { _ -> | ||
continuation.cancel() | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters