-
-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added view models for help and support
- Loading branch information
1 parent
742ad57
commit c81bd8f
Showing
6 changed files
with
159 additions
and
115 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
35 changes: 35 additions & 0 deletions
35
app/src/main/kotlin/com/d4rk/cleaner/ui/help/HelpViewModel.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,35 @@ | ||
package com.d4rk.cleaner.ui.help | ||
|
||
import android.app.Application | ||
import androidx.compose.runtime.* | ||
import androidx.lifecycle.AndroidViewModel | ||
import androidx.lifecycle.viewModelScope | ||
import com.google.android.play.core.review.ReviewInfo | ||
import com.google.android.play.core.review.ReviewManagerFactory | ||
import kotlinx.coroutines.Dispatchers | ||
import kotlinx.coroutines.launch | ||
|
||
class HelpViewModel(application: Application) : AndroidViewModel(application) { | ||
|
||
private var _reviewInfo: MutableState<ReviewInfo?> = mutableStateOf(null) | ||
val reviewInfo: State<ReviewInfo?> = _reviewInfo | ||
|
||
fun requestReviewFlow() { | ||
viewModelScope.launch(Dispatchers.IO) { | ||
val reviewManager = ReviewManagerFactory.create(getApplication()) | ||
val request = reviewManager.requestReviewFlow() | ||
request.addOnCompleteListener { task -> | ||
if (task.isSuccessful) { | ||
_reviewInfo.value = task.result | ||
} else { | ||
task.exception?.printStackTrace() | ||
} | ||
} | ||
} | ||
} | ||
|
||
fun launchReviewFlow(activity: HelpActivity, reviewInfo: ReviewInfo) { | ||
val reviewManager = ReviewManagerFactory.create(activity) | ||
reviewManager.launchReviewFlow(activity, reviewInfo) | ||
} | ||
} |
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
Oops, something went wrong.