Skip to content

Commit

Permalink
fix: fixes for only showing onboarding on first run, debug-workaround…
Browse files Browse the repository at this point in the history
… for Unknown app name
  • Loading branch information
ErikBjare committed Oct 7, 2023
1 parent 6d3b06d commit e737d31
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ class AWPreferences(context: Context) {
context.getSharedPreferences("AWPreferences", Context.MODE_PRIVATE)

// To check if it is the first time the app is being run
// Set to false when user finishes onboarding
fun isFirstTime(): Boolean {
return sharedPreferences.getBoolean("isFirstTime", true)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class MainActivity : AppCompatActivity(), NavigationView.OnNavigationItemSelecte

// If first time, or usage not allowed, show onboarding activity
val prefs = AWPreferences(this)
if (prefs.isFirstTime() || UsageStatsWatcher.isUsageAllowed(this)) {
if (prefs.isFirstTime() || !UsageStatsWatcher.isUsageAllowed(this)) {
Log.i(TAG, "First time or usage not allowed, starting onboarding activity")
val intent = Intent(this, OnboardingActivity::class.java)
startActivity(intent)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ class OnboardingActivity : AppCompatActivity() {
// Handle finish button click (e.g., navigate to the main activity)
// First, check if the user has granted the usage permission
if(UsageStatsWatcher.isUsageAllowed(this)) {
AWPreferences(this).setFirstTimeRunFlag()
finish()
} else {
// Show a snackbar and don't finish the activity
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package net.activitywatch.android.models
import android.app.usage.UsageEvents
import android.content.Context
import android.content.pm.PackageManager
import android.util.Log
import org.json.JSONObject
import org.threeten.bp.DateTimeUtils
import org.threeten.bp.Instant
Expand All @@ -13,9 +14,9 @@ data class Event(val timestamp: Instant, val duration: Double = 0.0, val data: J
val timestamp = DateTimeUtils.toInstant(java.util.Date(usageEvent.timeStamp))
val pm = context.packageManager
val appName = try {
pm.getApplicationLabel(pm.getApplicationInfo(usageEvent.packageName, PackageManager.GET_META_DATA))
pm.getApplicationLabel(pm.getApplicationInfo(usageEvent.packageName, PackageManager.GET_META_DATA or PackageManager.MATCH_UNINSTALLED_PACKAGES))
} catch(e: PackageManager.NameNotFoundException) {
"Unknown"
"Unknown (${usageEvent.packageName})"
}

// Construct the data object in an exception-safe manner
Expand Down

0 comments on commit e737d31

Please sign in to comment.