summaryrefslogtreecommitdiff
path: root/app/src/main/java/net
diff options
context:
space:
mode:
authorTorsten Grote <t@grobox.de>2020-01-02 10:00:48 -0300
committerTorsten Grote <t@grobox.de>2020-01-02 10:00:48 -0300
commit208d7ab1872cc7f5183a553d590ec4debc911292 (patch)
treeb3b67f07f391a3ed686f8b872373b2f07b27459f /app/src/main/java/net
parent1ec44435ab0ab098a04b3f4ee9f2599d99535c41 (diff)
downloadwallet-android-208d7ab1872cc7f5183a553d590ec4debc911292.tar.gz
wallet-android-208d7ab1872cc7f5183a553d590ec4debc911292.tar.bz2
wallet-android-208d7ab1872cc7f5183a553d590ec4debc911292.zip
Hide detailed history events by default
Also implement history changes after latest feedback
Diffstat (limited to 'app/src/main/java/net')
-rw-r--r--app/src/main/java/net/taler/wallet/WalletViewModel.kt32
-rw-r--r--app/src/main/java/net/taler/wallet/history/HistoryEvent.kt7
-rw-r--r--app/src/main/java/net/taler/wallet/history/WalletHistory.kt58
-rw-r--r--app/src/main/java/net/taler/wallet/history/WalletHistoryAdapter.kt15
4 files changed, 76 insertions, 36 deletions
diff --git a/app/src/main/java/net/taler/wallet/WalletViewModel.kt b/app/src/main/java/net/taler/wallet/WalletViewModel.kt
index f556ff3..f932cff 100644
--- a/app/src/main/java/net/taler/wallet/WalletViewModel.kt
+++ b/app/src/main/java/net/taler/wallet/WalletViewModel.kt
@@ -18,11 +18,15 @@ package net.taler.wallet
import android.app.Application
import android.util.Log
-import androidx.lifecycle.AndroidViewModel
-import androidx.lifecycle.MutableLiveData
+import androidx.lifecycle.*
import com.fasterxml.jackson.databind.ObjectMapper
import com.fasterxml.jackson.module.kotlin.KotlinModule
import com.fasterxml.jackson.module.kotlin.readValue
+import kotlinx.coroutines.Dispatchers
+import kotlinx.coroutines.channels.awaitClose
+import kotlinx.coroutines.flow.callbackFlow
+import kotlinx.coroutines.flow.onCompletion
+import kotlinx.coroutines.flow.onStart
import net.taler.wallet.backend.WalletBackendApi
import net.taler.wallet.history.History
import org.json.JSONObject
@@ -61,6 +65,7 @@ open class WithdrawStatus {
val tosText: String,
val tosEtag: String
) : WithdrawStatus()
+
class Success : WithdrawStatus()
data class ReceivedDetails(
val talerWithdrawUri: String,
@@ -81,6 +86,7 @@ open class PendingOperations(
)
+@Suppress("EXPERIMENTAL_API_USAGE")
class WalletViewModel(val app: Application) : AndroidViewModel(app) {
private var initialized = false
@@ -104,6 +110,18 @@ class WalletViewModel(val app: Application) : AndroidViewModel(app) {
value = PendingOperations(listOf())
}
+ private val mHistoryProgress = MutableLiveData<Boolean>()
+ val historyProgress: LiveData<Boolean> = mHistoryProgress
+
+ val historyShowAll = MutableLiveData<Boolean>()
+
+ val history: LiveData<History> = historyShowAll.switchMap { showAll ->
+ loadHistory(showAll)
+ .onStart { mHistoryProgress.postValue(true) }
+ .onCompletion { mHistoryProgress.postValue(false) }
+ .asLiveData(Dispatchers.IO)
+ }
+
private var activeGetBalance = 0
private var activeGetPending = 0
@@ -188,15 +206,21 @@ class WalletViewModel(val app: Application) : AndroidViewModel(app) {
}
}
- fun getHistory(cb: (r: History) -> Unit) {
+ private fun loadHistory(showAll: Boolean) = callbackFlow {
+ mHistoryProgress.postValue(true)
walletBackendApi.sendRequest("getHistory", null) { isError, result ->
if (isError) {
// TODO show error message in [WalletHistory] fragment
+ close()
return@sendRequest
}
val history: History = mapper.readValue(result.getString("history"))
- cb(history)
+ history.reverse() // show latest first
+ mHistoryProgress.postValue(false)
+ offer(if (showAll) history else history.filter { it.showToUser } as History)
+ close()
}
+ awaitClose()
}
fun withdrawTestkudos() {
diff --git a/app/src/main/java/net/taler/wallet/history/HistoryEvent.kt b/app/src/main/java/net/taler/wallet/history/HistoryEvent.kt
index 31473f6..b21147a 100644
--- a/app/src/main/java/net/taler/wallet/history/HistoryEvent.kt
+++ b/app/src/main/java/net/taler/wallet/history/HistoryEvent.kt
@@ -80,7 +80,7 @@ class ReserveShortInfo(
val reserveCreationDetail: ReserveCreationDetail
)
-class History : ArrayList<HistoryEvent>()
+typealias History = ArrayList<HistoryEvent>
@JsonTypeInfo(
use = NAME,
@@ -109,7 +109,8 @@ abstract class HistoryEvent(
@get:StringRes
open val title: Int = 0,
@get:DrawableRes
- open val icon: Int = R.drawable.ic_account_balance
+ open val icon: Int = R.drawable.ic_account_balance,
+ open val showToUser: Boolean = false
)
@@ -178,6 +179,7 @@ class HistoryWithdrawnEvent(
override val layout = R.layout.history_withdrawn
override val title = R.string.history_event_withdrawn
override val icon = R.drawable.history_withdrawn
+ override val showToUser = true
}
@JsonTypeName("order-accepted")
@@ -232,6 +234,7 @@ class HistoryPaymentSentEvent(
override val layout = R.layout.history_payment_sent
override val title = R.string.history_event_payment_sent
override val icon = R.drawable.ic_cash_usd_outline
+ override val showToUser = true
}
@JsonTypeName("refreshed")
diff --git a/app/src/main/java/net/taler/wallet/history/WalletHistory.kt b/app/src/main/java/net/taler/wallet/history/WalletHistory.kt
index cdc90ae..0b2e214 100644
--- a/app/src/main/java/net/taler/wallet/history/WalletHistory.kt
+++ b/app/src/main/java/net/taler/wallet/history/WalletHistory.kt
@@ -19,11 +19,14 @@ package net.taler.wallet.history
import android.os.Bundle
import android.view.*
+import android.view.View.INVISIBLE
+import android.view.View.VISIBLE
import androidx.fragment.app.Fragment
-import androidx.lifecycle.ViewModelProviders
+import androidx.lifecycle.Observer
+import androidx.lifecycle.ViewModelProvider
import androidx.recyclerview.widget.DividerItemDecoration
import androidx.recyclerview.widget.LinearLayoutManager
-import androidx.recyclerview.widget.RecyclerView
+import kotlinx.android.synthetic.main.fragment_show_history.*
import net.taler.wallet.R
import net.taler.wallet.WalletViewModel
@@ -34,64 +37,65 @@ import net.taler.wallet.WalletViewModel
class WalletHistory : Fragment() {
lateinit var model: WalletViewModel
+ private lateinit var showAllItem: MenuItem
private val historyAdapter = WalletHistoryAdapter()
- lateinit var historyPlaceholder: View
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setHasOptionsMenu(true)
model = activity?.run {
- ViewModelProviders.of(this)[WalletViewModel::class.java]
+ ViewModelProvider(this)[WalletViewModel::class.java]
} ?: throw Exception("Invalid Activity")
}
override fun onCreateOptionsMenu(menu: Menu, inflater: MenuInflater) {
- activity?.menuInflater?.inflate(R.menu.history, menu)
+ inflater.inflate(R.menu.history, menu)
+ showAllItem = menu.findItem(R.id.show_all_history)
}
override fun onOptionsItemSelected(item: MenuItem): Boolean {
return when (item.itemId) {
+ R.id.show_all_history -> {
+ item.isChecked = !item.isChecked
+ model.historyShowAll.value = item.isChecked
+ true
+ }
R.id.reload_history -> {
- updateHistory()
+ model.historyShowAll.value = showAllItem.isChecked
true
}
else -> super.onOptionsItemSelected(item)
}
}
- private fun updateHistory() {
- model.getHistory {
- if (it.isEmpty()) {
- historyPlaceholder.visibility = View.VISIBLE
- }
- historyAdapter.update(it)
- }
- }
-
override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
- // Inflate the layout for this fragment
- val view = inflater.inflate(R.layout.fragment_show_history, container, false)
- val myLayoutManager = LinearLayoutManager(context).apply {
- reverseLayout = true // show latest events first
- }
- val myItemDecoration = DividerItemDecoration(context, myLayoutManager.orientation)
- view.findViewById<RecyclerView>(R.id.list_history).apply {
+ return inflater.inflate(R.layout.fragment_show_history, container, false)
+ }
+
+ override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
+ historyList.apply {
+ val myLayoutManager = LinearLayoutManager(context)
+ val myItemDecoration = DividerItemDecoration(context, myLayoutManager.orientation)
layoutManager = myLayoutManager
adapter = historyAdapter
addItemDecoration(myItemDecoration)
}
- historyPlaceholder = view.findViewById<View>(R.id.list_history_placeholder)
- historyPlaceholder.visibility = View.GONE
-
- updateHistory()
+ model.historyProgress.observe(this, Observer { show ->
+ historyProgressBar.visibility = if (show) VISIBLE else INVISIBLE
+ })
+ model.history.observe(this, Observer { history ->
+ historyEmptyState.visibility = if (history.isEmpty()) VISIBLE else INVISIBLE
+ historyAdapter.update(history)
+ })
- return view
+ // kicks off initial load, needs to be adapted if showAll state is ever saved
+ if (savedInstanceState == null) model.historyShowAll.value = false
}
companion object {
diff --git a/app/src/main/java/net/taler/wallet/history/WalletHistoryAdapter.kt b/app/src/main/java/net/taler/wallet/history/WalletHistoryAdapter.kt
index 14fc1e9..9d601e1 100644
--- a/app/src/main/java/net/taler/wallet/history/WalletHistoryAdapter.kt
+++ b/app/src/main/java/net/taler/wallet/history/WalletHistoryAdapter.kt
@@ -64,7 +64,7 @@ internal class WalletHistoryAdapter(private var history: History = History()) :
internal abstract class HistoryEventViewHolder(protected val v: View) : ViewHolder(v) {
private val icon: ImageView = v.findViewById(R.id.icon)
- private val title: TextView = v.findViewById(R.id.title)
+ protected val title: TextView = v.findViewById(R.id.title)
private val time: TextView = v.findViewById(R.id.time)
@CallSuper
@@ -77,7 +77,15 @@ internal abstract class HistoryEventViewHolder(protected val v: View) : ViewHold
private fun getRelativeTime(timestamp: Long): CharSequence {
val now = System.currentTimeMillis()
- return getRelativeTimeSpanString(timestamp, now, MINUTE_IN_MILLIS, FORMAT_ABBREV_RELATIVE)
+ return if (now - timestamp > DAY_IN_MILLIS * 2) {
+ formatDateTime(
+ v.context,
+ timestamp,
+ FORMAT_SHOW_TIME or FORMAT_SHOW_DATE or FORMAT_ABBREV_MONTH or FORMAT_NO_YEAR
+ )
+ } else {
+ getRelativeTimeSpanString(timestamp, now, MINUTE_IN_MILLIS, FORMAT_ABBREV_RELATIVE)
+ }
}
}
@@ -132,7 +140,8 @@ internal class HistoryPaymentSentViewHolder(v: View) : HistoryEventViewHolder(v)
super.bind(event)
event as HistoryPaymentSentEvent
- summary.text = event.orderShortInfo.summary
+ title.text = event.orderShortInfo.summary
+ summary.setText(event.title)
amountPaidWithFees.text = parseAmount(event.amountPaidWithFees).toString()
}