import android.support.v7.widget.Toolbar;
import android.util.Log;
import android.view.View;
+import android.widget.LinearLayout;
import android.widget.ProgressBar;
import android.widget.TextView;
private SwipeRefreshLayout swiper;
private RecyclerView root;
private ProgressBar progressBar;
+ private LinearLayout progressLayout;
private TextView tvLastUpdate;
private TransactionListAdapter modelAdapter;
+ private RetrieveTransactionsTask retrieveTransactionsTask;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (swiper == null) throw new RuntimeException("Can't get hold on the swipe layout");
root = findViewById(R.id.transaction_root);
if (root == null) throw new RuntimeException("Can't get hold on the transaction list view");
- progressBar = findViewById(R.id.transaction_progress_bar);
+ progressBar = findViewById(R.id.transaction_list_progress_bar);
if (progressBar == null)
throw new RuntimeException("Can't get hold on the transaction list progress bar");
+ progressLayout = findViewById(R.id.transaction_progress_layout);
+ if (progressLayout == null) throw new RuntimeException(
+ "Can't get hold on the transaction list progress bar layout");
tvLastUpdate = findViewById(R.id.transactions_last_update);
updateLastUpdateText();
model = ViewModelProviders.of(this).get(TransactionListViewModel.class);
overridePendingTransition(R.anim.dummy, R.anim.slide_out_right);
}
private void update_transactions() {
- RetrieveTransactionsTask task = new RetrieveTransactionsTask(new WeakReference<>(this));
+ retrieveTransactionsTask = new RetrieveTransactionsTask(new WeakReference<>(this));
RetrieveTransactionsTask.Params params = new RetrieveTransactionsTask.Params(
PreferenceManager.getDefaultSharedPreferences(this));
- task.execute(params);
+ retrieveTransactionsTask.execute(params);
+ findViewById(R.id.transaction_list_cancel_download).setEnabled(true);
}
public void onRetrieveStart() {
progressBar.setIndeterminate(true);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) progressBar.setProgress(0, false);
else progressBar.setProgress(0);
- progressBar.setVisibility(View.VISIBLE);
+ progressLayout.setVisibility(View.VISIBLE);
}
public void onRetrieveProgress(RetrieveTransactionsTask.Progress progress) {
if ((progress.getTotal() == RetrieveTransactionsTask.Progress.INDETERMINATE) ||
}
public void onRetrieveDone(boolean success) {
- progressBar.setVisibility(View.INVISIBLE);
+ progressLayout.setVisibility(View.GONE);
swiper.setRefreshing(false);
updateLastUpdateText();
if (success) {
}
}
}
+ public void onStopTransactionRefreshClick(View view) {
+ Log.d("interactive", "Cancelling transactions refresh");
+ if (retrieveTransactionsTask != null) retrieveTransactionsTask.cancel(false);
+ findViewById(R.id.transaction_list_cancel_download).setEnabled(false);
+ }
}
tools:ignore="HardcodedText" />
</LinearLayout>
- <ProgressBar
- android:id="@+id/transaction_progress_bar"
- style="?android:attr/progressBarStyleHorizontal"
+ <LinearLayout
+ android:id="@+id/transaction_progress_layout"
android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:layout_marginTop="-8dp"
- android:layout_marginBottom="-7dp"
- android:indeterminate="true"
- android:padding="0dp"
- android:progressTint="@color/colorPrimary"
- android:visibility="invisible"
- app:layout_constraintEnd_toEndOf="parent"
- app:layout_constraintStart_toStartOf="parent"
- app:layout_constraintTop_toBottomOf="@+id/last_update_row" />
+ android:layout_height="match_parent"
+ android:gravity="center_vertical"
+ android:orientation="horizontal"
+ android:visibility="gone">
+
+ <ProgressBar
+ android:id="@+id/transaction_list_progress_bar"
+ style="?android:attr/progressBarStyleHorizontal"
+ android:layout_width="0dp"
+ android:layout_height="wrap_content"
+ android:layout_marginTop="-8dp"
+ android:layout_marginBottom="-7dp"
+ android:layout_weight="1"
+ android:indeterminate="true"
+ android:padding="0dp"
+ android:progressTint="@color/colorPrimary"
+ app:layout_constraintEnd_toEndOf="parent"
+ app:layout_constraintStart_toStartOf="parent"
+ app:layout_constraintTop_toBottomOf="@+id/last_update_row" />
+
+ <TextView
+ android:id="@+id/transaction_list_cancel_download"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:background="@drawable/ic_clear_black_24dp"
+ android:clickable="true"
+ android:onClick="onStopTransactionRefreshClick" />
+ </LinearLayout>
</LinearLayout>