Skip to content

Commit

Permalink
Add hidden button to add demo values
Browse files Browse the repository at this point in the history
  • Loading branch information
mueller-ma committed Nov 5, 2023
1 parent 5b75669 commit b24e644
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 1 deletion.
1 change: 1 addition & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ android {
}
buildFeatures {
viewBinding true
buildConfig true
}
testOptions {
unitTests.returnDefaultValues = true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,20 @@ import androidx.core.view.isVisible
import androidx.preference.PreferenceManager
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout
import com.github.muellerma.prepaidbalance.BuildConfig
import com.github.muellerma.prepaidbalance.R
import com.github.muellerma.prepaidbalance.databinding.ActivityMainBinding
import com.github.muellerma.prepaidbalance.room.AppDatabase
import com.github.muellerma.prepaidbalance.room.BalanceEntry
import com.github.muellerma.prepaidbalance.utils.hasPermissions
import com.github.muellerma.prepaidbalance.utils.prefs
import com.github.muellerma.prepaidbalance.utils.timestampForUi
import com.github.muellerma.prepaidbalance.work.CheckBalanceWorker
import com.github.muellerma.prepaidbalance.work.CheckBalanceWorker.Companion.CheckResult
import com.google.android.material.color.DynamicColors
import com.google.android.material.snackbar.Snackbar
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import java.io.File

Expand Down Expand Up @@ -127,6 +131,7 @@ class MainActivity : AbstractBaseActivity(), SwipeRefreshLayout.OnRefreshListene
Log.d(TAG, "onCreateOptionsMenu()")
menuInflater.inflate(R.menu.main_menu, menu)
(menu as? MenuBuilder)?.setOptionalIconsVisible(true)
menu.findItem(R.id.demo_values).isVisible = BuildConfig.DEBUG
return true
}

Expand Down Expand Up @@ -156,6 +161,21 @@ class MainActivity : AbstractBaseActivity(), SwipeRefreshLayout.OnRefreshListene
}
true
}
R.id.demo_values -> {
val now = System.currentTimeMillis()
CoroutineScope(Dispatchers.IO).launch {
AppDatabase.get(this@MainActivity)
.balanceDao().apply {
insert(BalanceEntry(timestamp = now, balance = 10.15, fullResponse = "foobar 10.15"))
insert(BalanceEntry(timestamp = now - 5 * 60 * 1000, balance = 0.15, fullResponse = "foobar 0.15"))
insert(BalanceEntry(timestamp = now - 60 * 60 * 1000, balance = 5.12, fullResponse = "foobar 5.12"))
insert(BalanceEntry(timestamp = now - 30 * 60 * 60 * 1000, balance = 7.12, fullResponse = "foobar 7.12"))
insert(BalanceEntry(timestamp = 12, balance = 7.12, fullResponse = null)) // quite old
}
updateBalanceList()
}
true
}
android.R.id.home -> {
onBackPressedDispatcher.onBackPressed()
true
Expand Down
8 changes: 7 additions & 1 deletion app/src/main/res/menu/main_menu.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
<menu xmlns:tools="http://schemas.android.com/tools"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item
android:id="@+id/export"
Expand All @@ -13,4 +14,9 @@
app:showAsAction="never"
android:icon="@drawable/ic_outline_settings_24"
app:iconTint="?android:textColorSecondary" />
<item
android:id="@+id/demo_values"
android:title="Add demo values"
app:showAsAction="never"
tools:ignore="HardcodedText" />
</menu>

0 comments on commit b24e644

Please sign in to comment.