summaryrefslogtreecommitdiff
path: root/wallet/src/main/java
diff options
context:
space:
mode:
authorIván Ávalos <avalos@disroot.org>2024-02-26 16:49:44 -0600
committerTorsten Grote <t@grobox.de>2024-02-27 17:18:25 -0300
commitfec49163d1580677291f4971590a0d449ede2902 (patch)
treedb17678e0d2f2fe7c7f8d3f2d49ab25fe8113e83 /wallet/src/main/java
parentd496ff3c6a2ed16786cf3cc42e3a9f8df7629538 (diff)
downloadtaler-android-fec49163d1580677291f4971590a0d449ede2902.tar.gz
taler-android-fec49163d1580677291f4971590a0d449ede2902.tar.bz2
taler-android-fec49163d1580677291f4971590a0d449ede2902.zip
[wallet] Pending operations are no more!
bug 0008508
Diffstat (limited to 'wallet/src/main/java')
-rw-r--r--wallet/src/main/java/net/taler/wallet/MainActivity.kt6
-rw-r--r--wallet/src/main/java/net/taler/wallet/MainViewModel.kt7
-rw-r--r--wallet/src/main/java/net/taler/wallet/pending/PendingOperationsFragment.kt152
-rw-r--r--wallet/src/main/java/net/taler/wallet/pending/PendingOperationsManager.kt68
4 files changed, 3 insertions, 230 deletions
diff --git a/wallet/src/main/java/net/taler/wallet/MainActivity.kt b/wallet/src/main/java/net/taler/wallet/MainActivity.kt
index 631897a..ffc6c88 100644
--- a/wallet/src/main/java/net/taler/wallet/MainActivity.kt
+++ b/wallet/src/main/java/net/taler/wallet/MainActivity.kt
@@ -101,7 +101,7 @@ class MainActivity : AppCompatActivity(), OnNavigationItemSelectedListener,
setSupportActionBar(ui.content.toolbar)
val appBarConfiguration = AppBarConfiguration(
- setOf(R.id.nav_main, R.id.nav_settings, R.id.nav_pending_operations),
+ setOf(R.id.nav_main, R.id.nav_settings),
ui.drawerLayout
)
ui.content.toolbar.setupWithNavController(nav, appBarConfiguration)
@@ -112,7 +112,8 @@ class MainActivity : AppCompatActivity(), OnNavigationItemSelectedListener,
val versionView: TextView = ui.navView.getHeaderView(0).findViewById(R.id.versionView)
model.devMode.observe(this) { enabled ->
- ui.navView.menu.findItem(R.id.nav_dev).isVisible = enabled
+ // Uncomment if any dev options are added in the future
+ // ui.navView.menu.findItem(R.id.nav_dev).isVisible = enabled
if (enabled) {
@SuppressLint("SetTextI18n")
versionView.text = "$VERSION_NAME ($VERSION_CODE)"
@@ -164,7 +165,6 @@ class MainActivity : AppCompatActivity(), OnNavigationItemSelectedListener,
when (item.itemId) {
R.id.nav_home -> nav.navigate(R.id.nav_main)
R.id.nav_settings -> nav.navigate(R.id.nav_settings)
- R.id.nav_pending_operations -> nav.navigate(R.id.nav_pending_operations)
}
ui.drawerLayout.closeDrawer(START)
return true
diff --git a/wallet/src/main/java/net/taler/wallet/MainViewModel.kt b/wallet/src/main/java/net/taler/wallet/MainViewModel.kt
index b58636e..c2b04ca 100644
--- a/wallet/src/main/java/net/taler/wallet/MainViewModel.kt
+++ b/wallet/src/main/java/net/taler/wallet/MainViewModel.kt
@@ -40,7 +40,6 @@ import net.taler.wallet.deposit.DepositManager
import net.taler.wallet.exchanges.ExchangeManager
import net.taler.wallet.payment.PaymentManager
import net.taler.wallet.peer.PeerManager
-import net.taler.wallet.pending.PendingOperationsManager
import net.taler.wallet.refund.RefundManager
import net.taler.wallet.settings.SettingsManager
import net.taler.wallet.transactions.TransactionManager
@@ -73,8 +72,6 @@ class MainViewModel(
val networkManager = NetworkManager(app.applicationContext)
val withdrawManager = WithdrawManager(api, viewModelScope)
val paymentManager = PaymentManager(api, viewModelScope)
- val pendingOperationsManager: PendingOperationsManager =
- PendingOperationsManager(api, viewModelScope)
val transactionManager: TransactionManager = TransactionManager(api, viewModelScope)
val refundManager = RefundManager(api, viewModelScope)
val balanceManager = BalanceManager(api, viewModelScope)
@@ -111,10 +108,6 @@ class MainViewModel(
// update currently selected transaction list
transactionManager.loadTransactions()
}
- // refresh pending ops and history with each notification
- if (devMode.value == true) {
- pendingOperationsManager.getPending()
- }
}
/**
diff --git a/wallet/src/main/java/net/taler/wallet/pending/PendingOperationsFragment.kt b/wallet/src/main/java/net/taler/wallet/pending/PendingOperationsFragment.kt
deleted file mode 100644
index a76a7d1..0000000
--- a/wallet/src/main/java/net/taler/wallet/pending/PendingOperationsFragment.kt
+++ /dev/null
@@ -1,152 +0,0 @@
-/*
- * This file is part of GNU Taler
- * (C) 2020 Taler Systems S.A.
- *
- * GNU Taler is free software; you can redistribute it and/or modify it under the
- * terms of the GNU General Public License as published by the Free Software
- * Foundation; either version 3, or (at your option) any later version.
- *
- * GNU Taler is distributed in the hope that it will be useful, but WITHOUT ANY
- * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
- * A PARTICULAR PURPOSE. See the GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License along with
- * GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
- */
-
-package net.taler.wallet.pending
-
-import android.os.Bundle
-import android.view.LayoutInflater
-import android.view.Menu
-import android.view.MenuInflater
-import android.view.MenuItem
-import android.view.View
-import android.view.ViewGroup
-import android.widget.LinearLayout
-import android.widget.TextView
-import androidx.fragment.app.Fragment
-import androidx.fragment.app.activityViewModels
-import androidx.recyclerview.widget.DividerItemDecoration
-import androidx.recyclerview.widget.LinearLayoutManager
-import androidx.recyclerview.widget.RecyclerView
-import net.taler.common.showError
-import net.taler.wallet.MainViewModel
-import net.taler.wallet.R
-import net.taler.wallet.databinding.FragmentPendingOperationsBinding
-import org.json.JSONObject
-
-interface PendingOperationClickListener {
- fun onPendingOperationClick(type: String, detail: JSONObject)
-}
-
-class PendingOperationsFragment : Fragment(), PendingOperationClickListener {
-
- private val model: MainViewModel by activityViewModels()
- private val pendingOperationsManager by lazy { model.pendingOperationsManager }
-
- private lateinit var ui: FragmentPendingOperationsBinding
- private val pendingAdapter = PendingOperationsAdapter(emptyList(), this)
-
- override fun onCreate(savedInstanceState: Bundle?) {
- super.onCreate(savedInstanceState)
- setHasOptionsMenu(true)
- }
-
- override fun onCreateView(
- inflater: LayoutInflater,
- container: ViewGroup?,
- savedInstanceState: Bundle?
- ): View {
- ui = FragmentPendingOperationsBinding.inflate(inflater, container, false)
- return ui.root
- }
-
- override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
- super.onViewCreated(view, savedInstanceState)
-
- ui.listPending.apply {
- val myLayoutManager = LinearLayoutManager(requireContext())
- val myItemDecoration =
- DividerItemDecoration(requireContext(), myLayoutManager.orientation)
- layoutManager = myLayoutManager
- adapter = pendingAdapter
- addItemDecoration(myItemDecoration)
- }
-
- pendingOperationsManager.pendingOperations.observe(viewLifecycleOwner) {
- updatePending(it)
- }
- }
-
- override fun onStart() {
- super.onStart()
- pendingOperationsManager.getPending()
- }
-
- @Deprecated("Deprecated in Java")
- override fun onOptionsItemSelected(item: MenuItem): Boolean {
- return when (item.itemId) {
- R.id.retry_pending -> {
- pendingOperationsManager.retryPendingNow()
- true
- }
- else -> super.onOptionsItemSelected(item)
- }
- }
-
- @Deprecated("Deprecated in Java")
- override fun onCreateOptionsMenu(menu: Menu, inflater: MenuInflater) {
- inflater.inflate(R.menu.pending_operations, menu)
- super.onCreateOptionsMenu(menu, inflater)
- }
-
- private fun updatePending(pendingOperations: List<PendingOperationInfo>) {
- pendingAdapter.update(pendingOperations)
- }
-
- override fun onPendingOperationClick(type: String, detail: JSONObject) {
- requireActivity().showError("No detail view for $type implemented yet.")
- }
-}
-
-class PendingOperationsAdapter(
- private var items: List<PendingOperationInfo>,
- private val listener: PendingOperationClickListener
-) :
- RecyclerView.Adapter<PendingOperationsAdapter.MyViewHolder>() {
-
- init {
- setHasStableIds(false)
- }
-
- override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): MyViewHolder {
- val rowView =
- LayoutInflater.from(parent.context).inflate(R.layout.list_item_pending_operation, parent, false)
- return MyViewHolder(rowView)
- }
-
- override fun getItemCount(): Int {
- return items.size
- }
-
- override fun onBindViewHolder(holder: MyViewHolder, position: Int) {
- val p = items[position]
- val pendingContainer = holder.rowView.findViewById<LinearLayout>(R.id.pending_container)
- pendingContainer.setOnClickListener {
- listener.onPendingOperationClick(p.type, p.detail)
- }
- val textView = holder.rowView.findViewById<TextView>(R.id.pending_text)
- val subTextView = holder.rowView.findViewById<TextView>(R.id.pending_subtext)
- subTextView.text = p.detail.toString(1)
- textView.text = p.type
- }
-
- fun update(items: List<PendingOperationInfo>) {
- this.items = items
- this.notifyDataSetChanged()
- }
-
- class MyViewHolder(val rowView: View) : RecyclerView.ViewHolder(rowView)
-
-}
diff --git a/wallet/src/main/java/net/taler/wallet/pending/PendingOperationsManager.kt b/wallet/src/main/java/net/taler/wallet/pending/PendingOperationsManager.kt
deleted file mode 100644
index f5079f6..0000000
--- a/wallet/src/main/java/net/taler/wallet/pending/PendingOperationsManager.kt
+++ /dev/null
@@ -1,68 +0,0 @@
-/*
- * This file is part of GNU Taler
- * (C) 2020 Taler Systems S.A.
- *
- * GNU Taler is free software; you can redistribute it and/or modify it under the
- * terms of the GNU General Public License as published by the Free Software
- * Foundation; either version 3, or (at your option) any later version.
- *
- * GNU Taler is distributed in the hope that it will be useful, but WITHOUT ANY
- * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
- * A PARTICULAR PURPOSE. See the GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License along with
- * GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
- */
-
-package net.taler.wallet.pending
-
-import android.util.Log
-import androidx.lifecycle.MutableLiveData
-import kotlinx.coroutines.CoroutineScope
-import kotlinx.coroutines.launch
-import kotlinx.serialization.json.jsonArray
-import net.taler.wallet.TAG
-import net.taler.wallet.backend.ApiResponse
-import net.taler.wallet.backend.WalletBackendApi
-import org.json.JSONObject
-
-open class PendingOperationInfo(
- val type: String,
- val detail: JSONObject,
-)
-
-class PendingOperationsManager(
- private val walletBackendApi: WalletBackendApi,
- private val scope: CoroutineScope,
-) {
-
- val pendingOperations = MutableLiveData<List<PendingOperationInfo>>()
-
- internal fun getPending() {
- scope.launch {
- val response = walletBackendApi.sendRequest("getPendingOperations")
- if (response is ApiResponse.Error) {
- Log.i(TAG, "got getPending error result: ${response.error}")
- return@launch
- } else if (response is ApiResponse.Response) {
- Log.i(TAG, "got getPending result")
- val pendingList = mutableListOf<PendingOperationInfo>()
- val pendingJson = response.result["pendingOperations"]?.jsonArray ?: return@launch
- for (i in 0 until pendingJson.size) {
- val p = JSONObject(pendingJson[i].toString())
- val type = p.getString("type")
- pendingList.add(PendingOperationInfo(type, p))
- }
- Log.i(TAG, "Got ${pendingList.size} pending operations")
- pendingOperations.postValue((pendingList))
- }
- }
- }
-
- fun retryPendingNow() {
- scope.launch {
- walletBackendApi.sendRequest("retryPendingNow")
- }
- }
-
-}