import android.widget.AutoCompleteTextView;
import android.widget.EditText;
import android.widget.FrameLayout;
-import android.widget.LinearLayout;
+import android.widget.ProgressBar;
import android.widget.TextView;
import androidx.annotation.NonNull;
private AutoCompleteTextView tvAccount;
private TextView tvComment;
private EditText tvAmount;
- private LinearLayout lHead;
+ private ViewGroup lHead;
private ViewGroup lAccount;
private FrameLayout lPadding;
private MobileLedgerProfile mProfile;
private Observer<Currency> currencyObserver;
private Observer<Boolean> showCurrencyObserver;
private Observer<String> commentObserver;
+ private Observer<Boolean> busyFlagObserver;
private boolean inUpdate = false;
private boolean syncingData = false;
private View commentButton;
lAccount = itemView.findViewById(R.id.ntr_account);
lPadding = itemView.findViewById(R.id.ntr_padding);
View commentLayout = itemView.findViewById(R.id.comment_layout);
+ ProgressBar p = itemView.findViewById(R.id.progressBar);
tvDescription.setNextFocusForwardId(View.NO_ID);
tvAccount.setNextFocusForwardId(View.NO_ID);
((focusedView != tvComment) && Misc.isEmptyOrNull(comment)) ? View.INVISIBLE
: View.VISIBLE);
};
+
+ busyFlagObserver = isBusy -> {p.setVisibility(isBusy ? View.VISIBLE : View.INVISIBLE);};
}
private void updateCurrencyPositionAndPadding(Currency.Position position, boolean hasGap) {
ConstraintLayout.LayoutParams amountLP =
this.item.stopObservingCurrency(currencyObserver);
this.item.getModel().showCurrency.removeObserver(showCurrencyObserver);
this.item.stopObservingComment(commentObserver);
+ this.item.getModel().stopObservingBusyFlag(busyFlagObserver);
this.item = null;
}
case generalData:
item.observeDate(activity, dateObserver);
item.observeDescription(activity, descriptionObserver);
+ item.getModel().observeBusyFlag(activity, busyFlagObserver);
break;
case transactionRow:
item.observeAmountHint(activity, hintObserver);
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.Locale;
+import java.util.concurrent.atomic.AtomicInteger;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
private boolean observingDataProfile;
private Observer<MobileLedgerProfile> profileObserver =
profile -> showCurrency.postValue(profile.getShowCommodityByDefault());
+ private final AtomicInteger busyCounter = new AtomicInteger(0);
+ private final MutableLiveData<Boolean> busyFlag = new MutableLiveData<>(false);
+ void observeBusyFlag(LifecycleOwner owner, Observer<? super Boolean> observer) {
+ busyFlag.observe(owner, observer);
+ }
void observeDataProfile(LifecycleOwner activity) {
if (!observingDataProfile)
Data.profile.observe(activity, profileObserver);
void toggleCurrencyVisible() {
showCurrency.setValue(!showCurrency.getValue());
}
+ void stopObservingBusyFlag(Observer<Boolean> observer) {
+ busyFlag.removeObserver(observer);
+ }
+ void incrementBusyCounter() {
+ int newValue = busyCounter.incrementAndGet();
+ if (newValue == 1) busyFlag.postValue(true);
+ }
+ void decrementBusyCounter() {
+ int newValue = busyCounter.decrementAndGet();
+ if (newValue == 0) busyFlag.postValue(false);
+ }
enum ItemType {generalData, transactionRow, bottomFiller}
enum FocusedElement {Account, Comment, Amount}
-->
<androidx.coordinatorlayout.widget.CoordinatorLayout 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:layout_width="match_parent"
android:layout_height="match_parent">
- <androidx.constraintlayout.widget.ConstraintLayout xmlns:tools="http://schemas.android.com/tools"
+ <androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="net.ktnx.mobileledger.ui.activity.NewTransactionActivity">
android:animateLayoutChanges="false"
android:orientation="vertical">
- <LinearLayout
+ <androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/ntr_data"
android:layout_width="match_parent"
- android:layout_height="wrap_content">
+ android:layout_height="wrap_content"
+ android:orientation="horizontal">
<EditText
android:id="@+id/new_transaction_date"
android:textAlignment="gravity"
android:textCursorDrawable="@android:color/transparent"
app:layout_constrainedHeight="true"
- app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintHorizontal_weight="8"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
<net.ktnx.mobileledger.ui.AutoCompleteTextViewWithClear
android:id="@+id/new_transaction_description"
- android:layout_width="match_parent"
+ android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:layout_marginStart="8dp"
android:nextFocusUp="@+id/new_transaction_date"
android:selectAllOnFocus="false"
android:singleLine="true"
- app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_weight="30"
- app:layout_constraintStart_toEndOf="@+id/new_transaction_date"
+ app:layout_constraintStart_toEndOf="@id/new_transaction_date"
app:layout_constraintTop_toTopOf="parent" />
- </LinearLayout>
+
+ <ProgressBar
+ android:id="@+id/progressBar"
+ style="@style/Widget.AppCompat.ProgressBar.Horizontal"
+ android:layout_width="0dp"
+ android:layout_height="wrap_content"
+ android:indeterminate="true"
+ android:indeterminateBehavior="cycle"
+ android:orientation="horizontal"
+ android:visibility="invisible"
+ app:layout_constraintTop_toBottomOf="@id/new_transaction_date"
+ app:layout_constraintStart_toStartOf="parent"
+ app:layout_constraintEnd_toEndOf="parent
+"/>
+ </androidx.constraintlayout.widget.ConstraintLayout>
<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/ntr_account"