Skip to content

Commit

Permalink
Writes play time on stop not each pulse
Browse files Browse the repository at this point in the history
  • Loading branch information
Jerboa-app committed Jul 20, 2024
1 parent fb4983d commit 36dc849
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
12 changes: 7 additions & 5 deletions app/src/main/java/app/jerboa/spp/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ class MainActivity : AppCompatActivity() {
private lateinit var reviewManager: ReviewManager

private var lastPlayTime: Long = 0L
private var totalTime: Long = 0L
private var seenReview: Boolean = false
private var lastReviewTries: Long = 0L

Expand Down Expand Up @@ -469,15 +470,11 @@ class MainActivity : AppCompatActivity() {
renderViewModel.playTime.observe(
this, androidx.lifecycle.Observer { time ->
run {
val prefs = getSharedPreferences("jerboa.app.spp.prefs", MODE_PRIVATE)
val prefsEdit = prefs.edit()
val totalTime = if (seenReview) {
totalTime = if (seenReview) {
0L
} else {
lastPlayTime + time
}
prefsEdit.putLong("playTime", totalTime)
prefsEdit.apply()
}
}
)
Expand Down Expand Up @@ -514,6 +511,7 @@ class MainActivity : AppCompatActivity() {
requestUserReviewPrompt()
}
}
Log.d("play time", "$lastPlayTime")

val versionString =
BuildConfig.VERSION_NAME + " (vc" + BuildConfig.VERSION_CODE + ") : " + Date(BuildConfig.TIMESTAMP)
Expand Down Expand Up @@ -609,6 +607,10 @@ class MainActivity : AppCompatActivity() {

public override fun onStop()
{
val prefs = getSharedPreferences("jerboa.app.spp.prefs", MODE_PRIVATE)
val prefsEdit = prefs.edit()
prefsEdit.putLong("playTime", totalTime)
prefsEdit.apply()
super.onStop()
renderViewModel.stopClock()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ enum class TOY {ATTRACTOR,REPELLOR,SPINNER,FREEZER, NOTHING}

enum class SOCIAL {NOTHING, WEB, PLAY, YOUTUBE, GITHUB}

const val REVIEW_RATE_LIMIT_MILLIS = 1000*60*10
const val REVIEW_RATE_LIMIT_MILLIS = 1000*60*30

class RenderViewModel : ViewModel() {

Expand Down

0 comments on commit 36dc849

Please sign in to comment.