mirror of
https://github.com/mueller-ma/PrepaidBalance.git
synced 2024-09-19 16:02:14 +02:00
Show full response in list (#141)
Click on a balance entry in MainActivity to view the full reponse. Fixes #118
This commit is contained in:
parent
933d8603db
commit
eb42db49ee
@ -0,0 +1,52 @@
|
||||
{
|
||||
"formatVersion": 1,
|
||||
"database": {
|
||||
"version": 2,
|
||||
"identityHash": "f709374e68e6512c74cbe86c3533429c",
|
||||
"entities": [
|
||||
{
|
||||
"tableName": "BalanceEntry",
|
||||
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` INTEGER PRIMARY KEY AUTOINCREMENT, `timestamp` INTEGER NOT NULL, `balance` REAL NOT NULL, `fullResponse` TEXT)",
|
||||
"fields": [
|
||||
{
|
||||
"fieldPath": "id",
|
||||
"columnName": "id",
|
||||
"affinity": "INTEGER",
|
||||
"notNull": false
|
||||
},
|
||||
{
|
||||
"fieldPath": "timestamp",
|
||||
"columnName": "timestamp",
|
||||
"affinity": "INTEGER",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "balance",
|
||||
"columnName": "balance",
|
||||
"affinity": "REAL",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "fullResponse",
|
||||
"columnName": "fullResponse",
|
||||
"affinity": "TEXT",
|
||||
"notNull": false
|
||||
}
|
||||
],
|
||||
"primaryKey": {
|
||||
"columnNames": [
|
||||
"id"
|
||||
],
|
||||
"autoGenerate": true
|
||||
},
|
||||
"indices": [],
|
||||
"foreignKeys": []
|
||||
}
|
||||
],
|
||||
"views": [],
|
||||
"setupQueries": [
|
||||
"CREATE TABLE IF NOT EXISTS room_master_table (id INTEGER PRIMARY KEY,identity_hash TEXT)",
|
||||
"INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, 'f709374e68e6512c74cbe86c3533429c')"
|
||||
]
|
||||
}
|
||||
}
|
@ -19,11 +19,11 @@ class DatabaseTest {
|
||||
AppDatabase.get(appContext)
|
||||
.balanceDao().apply {
|
||||
deleteAll()
|
||||
insert(BalanceEntry(timestamp = now, balance = 10.15))
|
||||
insert(BalanceEntry(timestamp = now - 5 * 60 * 1000, balance = 0.15))
|
||||
insert(BalanceEntry(timestamp = now - 60 * 60 * 1000, balance = 5.12))
|
||||
insert(BalanceEntry(timestamp = now - 30 * 60 * 60 * 1000, balance = 7.12))
|
||||
insert(BalanceEntry(timestamp = 12, balance = 7.12)) // quite old
|
||||
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
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,11 +1,18 @@
|
||||
package com.github.muellerma.prepaidbalance.room
|
||||
|
||||
import android.content.Context
|
||||
import androidx.room.AutoMigration
|
||||
import androidx.room.Database
|
||||
import androidx.room.Room
|
||||
import androidx.room.RoomDatabase
|
||||
|
||||
@Database(entities = [BalanceEntry::class], version = 1)
|
||||
@Database(
|
||||
entities = [BalanceEntry::class],
|
||||
version = 2,
|
||||
autoMigrations = [
|
||||
AutoMigration(from = 1, to = 2)
|
||||
]
|
||||
)
|
||||
abstract class AppDatabase : RoomDatabase() {
|
||||
abstract fun balanceDao(): BalanceDao
|
||||
|
||||
|
@ -9,7 +9,8 @@ import kotlin.math.abs
|
||||
data class BalanceEntry(
|
||||
@PrimaryKey(autoGenerate = true) val id: Int? = null,
|
||||
val timestamp: Long,
|
||||
@ColumnInfo(name = "balance") val balance: Double
|
||||
@ColumnInfo(name = "balance") val balance: Double,
|
||||
val fullResponse: String?
|
||||
) {
|
||||
fun nearlyEquals(other: BalanceEntry): Boolean {
|
||||
if (balance != other.balance) {
|
||||
|
@ -11,7 +11,9 @@ import com.github.muellerma.prepaidbalance.databinding.ListBalanceBinding
|
||||
import com.github.muellerma.prepaidbalance.room.BalanceEntry
|
||||
import com.github.muellerma.prepaidbalance.utils.formatAsCurrency
|
||||
import com.github.muellerma.prepaidbalance.utils.formatAsDiff
|
||||
import com.github.muellerma.prepaidbalance.utils.showToast
|
||||
import com.github.muellerma.prepaidbalance.utils.timestampForUi
|
||||
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
||||
|
||||
class BalanceListAdapter(context: Context) :
|
||||
RecyclerView.Adapter<BalanceListViewHolder>() {
|
||||
@ -42,6 +44,18 @@ class BalanceListAdapter(context: Context) :
|
||||
setTextColor(ContextCompat.getColor(context, color))
|
||||
}
|
||||
|
||||
val fullResponse = balances[position].fullResponse
|
||||
holder.binding.card.setOnClickListener {
|
||||
if (fullResponse.isNullOrEmpty()) {
|
||||
it.context.showToast(R.string.no_response_saved)
|
||||
} else {
|
||||
MaterialAlertDialogBuilder(it.context)
|
||||
.setPositiveButton(R.string.close, null)
|
||||
.setMessage(fullResponse)
|
||||
.show()
|
||||
}
|
||||
}
|
||||
|
||||
holder.binding.date.apply {
|
||||
text = balances[position].timestamp.timestampForUi(context)
|
||||
}
|
||||
|
@ -173,7 +173,11 @@ class CheckBalanceWorker(
|
||||
val database = AppDatabase.get(context)
|
||||
|
||||
val latestInDb = database.balanceDao().getLatest()
|
||||
val new = BalanceEntry(timestamp = System.currentTimeMillis(), balance = balance)
|
||||
val new = BalanceEntry(
|
||||
timestamp = System.currentTimeMillis(),
|
||||
balance = balance,
|
||||
fullResponse = response
|
||||
)
|
||||
|
||||
Log.d(TAG, "Insert $new")
|
||||
database
|
||||
|
@ -3,6 +3,7 @@
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:id="@+id/card"
|
||||
app:cardElevation="4dp"
|
||||
app:cardCornerRadius="4dp"
|
||||
android:layout_marginHorizontal="8dp"
|
||||
|
@ -37,6 +37,8 @@
|
||||
<string name="copied_to_clipboard">Copied to clipboard</string>
|
||||
<string name="retry">Retry</string>
|
||||
<string name="confirm_first_request">A USSD request will be made to %s</string>
|
||||
<string name="close">Close</string>
|
||||
<string name="no_response_saved">No response saved</string>
|
||||
|
||||
<!-- About menu -->
|
||||
<string name="about">About Prepaid Balance</string>
|
||||
|
Loading…
Reference in New Issue
Block a user