|
22 | 22 | package io.scalaproject.vault; |
23 | 23 |
|
24 | 24 | import android.content.Context; |
| 25 | +import android.os.AsyncTask; |
25 | 26 | import android.os.Bundle; |
26 | 27 | import android.os.Handler; |
27 | 28 | import android.os.Looper; |
28 | 29 | import androidx.annotation.Nullable; |
29 | 30 | import androidx.fragment.app.Fragment; |
30 | 31 | import androidx.recyclerview.widget.RecyclerView; |
| 32 | +import androidx.swiperefreshlayout.widget.SwipeRefreshLayout; |
| 33 | + |
31 | 34 | import android.view.LayoutInflater; |
32 | 35 | import android.view.Menu; |
33 | 36 | import android.view.MenuInflater; |
|
49 | 52 | import io.scalaproject.vault.layout.TransactionInfoAdapter; |
50 | 53 | import io.scalaproject.vault.model.TransactionInfo; |
51 | 54 | import io.scalaproject.vault.model.Wallet; |
| 55 | +import io.scalaproject.vault.model.WalletManager; |
52 | 56 | import io.scalaproject.vault.service.exchange.api.ExchangeApi; |
53 | 57 | import io.scalaproject.vault.service.exchange.api.ExchangeCallback; |
54 | 58 | import io.scalaproject.vault.service.exchange.api.ExchangeRate; |
@@ -78,6 +82,8 @@ public class WalletFragment extends Fragment |
78 | 82 | private LinearLayout llNoTransaction; |
79 | 83 | private RecyclerView rvTransactions; |
80 | 84 |
|
| 85 | + private SwipeRefreshLayout pullToRefresh; |
| 86 | + |
81 | 87 | private Spinner sCurrency; |
82 | 88 |
|
83 | 89 | private List<String> dismissedTransactions = new ArrayList<>(); |
@@ -144,6 +150,14 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, |
144 | 150 | bSend = view.findViewById(R.id.bSend); |
145 | 151 | bReceive = view.findViewById(R.id.bReceive); |
146 | 152 |
|
| 153 | + pullToRefresh = view.findViewById(R.id.pullToRefresh); |
| 154 | + pullToRefresh.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() { |
| 155 | + @Override |
| 156 | + public void onRefresh() { |
| 157 | + refresh(); |
| 158 | + } |
| 159 | + }); |
| 160 | + |
147 | 161 | txInfoAdapter = new TransactionInfoAdapter(getActivity(), this, this); |
148 | 162 | rvTransactions.setAdapter(txInfoAdapter); |
149 | 163 |
|
@@ -215,6 +229,47 @@ public void onNothingSelected(AdapterView<?> parentView) { |
215 | 229 | return view; |
216 | 230 | } |
217 | 231 |
|
| 232 | + private AsyncRefreshWallet asyncRefreshWallet = null; |
| 233 | + |
| 234 | + private void refresh() { |
| 235 | + if (asyncRefreshWallet != null) return; // ignore refresh request as one is ongoing |
| 236 | + |
| 237 | + asyncRefreshWallet = new AsyncRefreshWallet(); |
| 238 | + asyncRefreshWallet.execute(); |
| 239 | + } |
| 240 | + |
| 241 | + private class AsyncRefreshWallet extends AsyncTask<Void, WalletManager.WalletInfo, Boolean> { |
| 242 | + @Override |
| 243 | + protected void onPreExecute() { |
| 244 | + super.onPreExecute(); |
| 245 | + } |
| 246 | + |
| 247 | + @Override |
| 248 | + protected Boolean doInBackground(Void... params) { |
| 249 | + Timber.d("refreshing"); |
| 250 | + activityCallback.forceUpdate(); |
| 251 | + |
| 252 | + return true; |
| 253 | + } |
| 254 | + |
| 255 | + @Override |
| 256 | + protected void onPostExecute(Boolean result) { |
| 257 | + Timber.d("done scanning"); |
| 258 | + complete(); |
| 259 | + } |
| 260 | + |
| 261 | + @Override |
| 262 | + protected void onCancelled(Boolean result) { |
| 263 | + Timber.d("cancelled scanning"); |
| 264 | + complete(); |
| 265 | + } |
| 266 | + |
| 267 | + private void complete() { |
| 268 | + asyncRefreshWallet = null; |
| 269 | + pullToRefresh.setRefreshing(false); |
| 270 | + } |
| 271 | + } |
| 272 | + |
218 | 273 | void showBalance(String balance) { |
219 | 274 | tvBalance.setText(balance); |
220 | 275 | if (!activityCallback.isStealthMode()) { |
|
0 commit comments