private MobileLedgerDatabase dbHelper;
private boolean monthNamesPrepared = false;
public static SQLiteDatabase getDatabase() {
- if (instance == null) throw new RuntimeException("Application not created yet");
+ if (instance == null)
+ throw new RuntimeException("Application not created yet");
return instance.getDB();
}
+ public static void prepareMonthNames() {
+ instance.prepareMonthNames(false);
+ }
@Override
public void onCreate() {
Logger.debug("flow", "App onCreate()");
final String expectedHost = url.getHost();
if (requestingHost.equalsIgnoreCase(expectedHost))
return new PasswordAuthentication(p.getAuthUserName(),
- p.getAuthPassword().toCharArray());
- else Log.w("http-auth",
- String.format("Requesting host [%s] differs from expected [%s]",
- requestingHost, expectedHost));
+ p.getAuthPassword()
+ .toCharArray());
+ else
+ Log.w("http-auth",
+ String.format("Requesting host [%s] differs from expected [%s]",
+ requestingHost, expectedHost));
}
catch (MalformedURLException e) {
e.printStackTrace();
}
});
}
- public static void prepareMonthNames() {
- instance.prepareMonthNames(false);
- }
private void prepareMonthNames(boolean force) {
if (force || monthNamesPrepared)
return;
if (dbHelper == null)
initDb();
- final SQLiteDatabase db = dbHelper.getWritableDatabase();
-
- return db;
+ return dbHelper.getWritableDatabase();
}
private synchronized void initDb() {
- if (dbHelper != null) return;
+ if (dbHelper != null)
+ return;
dbHelper = new MobileLedgerDatabase(this);
}
private String session;
private LedgerTransaction transaction;
private MobileLedgerProfile mProfile;
- private boolean simulate = false;
+ private boolean simulate;
public SendTransactionTask(TaskCallback callback, MobileLedgerProfile profile,
boolean simulate) {
MobileLedgerProfile profile = Data.getProfile();
return profile.loadCurrencyByName(name);
}
- public int getId() {
- return id;
- }
- public String getName() {
- return name;
- }
- public void setName(String name) {
- this.name = name;
- }
- public Position getPosition() {
- return position;
- }
- public void setPosition(Position position) {
- this.position = position;
- }
- public boolean hasGap() {
- return hasGap;
- }
- public void setHasGap(boolean hasGap) {
- this.hasGap = hasGap;
- }
static public boolean equal(Currency left, Currency right) {
if (left == null) {
return right == null;
return leftName.equals(right);
}
}
+ public int getId() {
+ return id;
+ }
+ public String getName() {
+ return name;
+ }
+ public void setName(String name) {
+ this.name = name;
+ }
+ public Position getPosition() {
+ return position;
+ }
+ public void setPosition(Position position) {
+ this.position = position;
+ }
+ public boolean hasGap() {
+ return hasGap;
+ }
+ public void setHasGap(boolean hasGap) {
+ this.hasGap = hasGap;
+ }
public enum Position {
before(-1), after(1), unknown(0), none(-2);
private int value;
new MutableLiveData<>();
public static final MutableLiveData<Boolean> currencyGap = new MutableLiveData<>(true);
public static final MutableLiveData<Locale> locale = new MutableLiveData<>(Locale.getDefault());
+ public static final MutableLiveData<Boolean> drawerOpen = new MutableLiveData<>(false);
private static final MutableLiveData<MobileLedgerProfile> profile =
new InertMutableLiveData<>();
private static final AtomicInteger backgroundTaskCount = new AtomicInteger(0);
public static MobileLedgerProfile getProfile() {
return Objects.requireNonNull(profile.getValue());
}
- public static final MutableLiveData<Boolean> drawerOpen = new MutableLiveData<>(false);
public static void backgroundTaskStarted() {
int cnt = backgroundTaskCount.incrementAndGet();
debug("data",
public class LedgerTransaction {
private static final String DIGEST_TYPE = "SHA-256";
- public final Comparator<LedgerTransactionAccount> comparator =
- new Comparator<LedgerTransactionAccount>() {
- @Override
- public int compare(LedgerTransactionAccount o1, LedgerTransactionAccount o2) {
- int res = o1.getAccountName()
- .compareTo(o2.getAccountName());
- if (res != 0)
- return res;
- res = o1.getCurrency()
- .compareTo(o2.getCurrency());
- if (res != 0)
- return res;
- res = o1.getComment()
- .compareTo(o2.getComment());
- if (res != 0)
- return res;
- return Float.compare(o1.getAmount(), o2.getAmount());
- }
- };
+ public final Comparator<LedgerTransactionAccount> comparator = (o1, o2) -> {
+ int res = o1.getAccountName()
+ .compareTo(o2.getAccountName());
+ if (res != 0)
+ return res;
+ res = o1.getCurrency()
+ .compareTo(o2.getCurrency());
+ if (res != 0)
+ return res;
+ res = o1.getComment()
+ .compareTo(o2.getComment());
+ if (res != 0)
+ return res;
+ return Float.compare(o1.getAmount(), o2.getAmount());
+ };
private String profile;
private Integer id;
private SimpleDate date;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
-import androidx.annotation.NonNull;
-import androidx.annotation.Nullable;
-import androidx.fragment.app.DialogFragment;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ScrollView;
import android.widget.TextView;
+import androidx.annotation.NonNull;
+import androidx.annotation.Nullable;
+import androidx.fragment.app.DialogFragment;
+
import net.ktnx.mobileledger.R;
import net.ktnx.mobileledger.utils.Globals;
model.currencies.setValue(new CopyOnWriteArrayList<>(profile.getCurrencies()));
CurrencySelectorRecyclerViewAdapter adapter = new CurrencySelectorRecyclerViewAdapter();
- model.currencies.observe(this, list -> adapter.submitList(list));
+ model.currencies.observe(this, adapter::submitList);
recyclerView.setAdapter(adapter);
adapter.setCurrencySelectedListener(this);
gap.setChecked(Data.currencyGap.getValue());
- gap.setOnCheckedChangeListener((v, checked) -> {
- Data.currencyGap.setValue(checked);
- });
+ gap.setOnCheckedChangeListener((v, checked) -> Data.currencyGap.setValue(checked));
- model.observePositionAndPaddingVisible(this, visible -> {
- csd.findViewById(R.id.params_panel)
- .setVisibility(visible ? View.VISIBLE : View.GONE);
- });
+ model.observePositionAndPaddingVisible(this, visible -> csd.findViewById(R.id.params_panel)
+ .setVisibility(
+ visible ? View.VISIBLE
+ : View.GONE));
if ((savedInstanceState != null) ? savedInstanceState.getBoolean(ARG_SHOW_PARAMS,
DEFAULT_SHOW_PARAMS) : DEFAULT_SHOW_PARAMS)
public void hidePositionAndPadding() {
positionAndPaddingVisible.postValue(false);
}
- public void observePositionAndPaddingVisible(LifecycleOwner activity, Observer<Boolean> observer) {
+ public void observePositionAndPaddingVisible(LifecycleOwner activity,
+ Observer<Boolean> observer) {
positionAndPaddingVisible.observe(activity, observer);
}
void setOnCurrencySelectedListener(OnCurrencySelectedListener listener) {
import android.view.MotionEvent;
import android.view.View;
+import androidx.annotation.Nullable;
+
import net.ktnx.mobileledger.utils.Colors;
import net.ktnx.mobileledger.utils.DimensionUtils;
-import androidx.annotation.Nullable;
import static net.ktnx.mobileledger.utils.Logger.debug;
return hueDegrees;
}
public void setHue(int hueDegrees) {
- if (hueDegrees == -1) hueDegrees = Colors.DEFAULT_HUE_DEG;
+ if (hueDegrees == -1)
+ hueDegrees = Colors.DEFAULT_HUE_DEG;
if (hueDegrees != Colors.DEFAULT_HUE_DEG) {
// round to 15 degrees
int rem = hueDegrees % hueStepDegrees;
- if (rem < (hueStepDegrees / 2)) hueDegrees -= rem;
- else hueDegrees += hueStepDegrees - rem;
+ if (rem < (hueStepDegrees / 2))
+ hueDegrees -= rem;
+ else
+ hueDegrees += hueStepDegrees - rem;
}
this.hueDegrees = hueDegrees;
// p.arcTo(-innerEdge, -innerEdge, innerEdge, innerEdge, -hueStepDegrees / 2f,
// hueStepDegrees, true);
// p.lineTo(outerEdge * cr, outerEdge * sr);
- p.arcTo(-outerEdge, -outerEdge, outerEdge, outerEdge, hueStepDegrees / 2f,
- -hueStepDegrees, false);
+ p.arcTo(-outerEdge, -outerEdge, outerEdge, outerEdge, hueStepDegrees / 2f, -hueStepDegrees,
+ false);
// p.close();
canvas.save();
canvas.translate(center, center);
float angleRad = (float) Math.atan2(y, x);
// angleRad is [-𝜋; +𝜋]
float hue = (float) (angleRad / (2 * Math.PI));
- if (hue < 0) hue += 1;
+ if (hue < 0)
+ hue += 1;
debug("TMP",
String.format("x=%1.3f, y=%1.3f, angle=%1.3frad, hueDegrees=%1.3f", x, y,
angleRad, hue));
return true;
}
public void setInitialHue(int initialHue) {
- if (initialHue == -1) initialHue = Colors.DEFAULT_HUE_DEG;
+ if (initialHue == -1)
+ initialHue = Colors.DEFAULT_HUE_DEG;
this.initialHueDegrees = initialHue;
this.initialPaint.setColor(Colors.getPrimaryColorForHue(initialHue));
invalidate();
decimalSeparator = String.valueOf(DecimalFormatSymbols.getInstance()
.getMonetaryDecimalSeparator());
- localeObserver = locale -> {
- decimalSeparator = String.valueOf(DecimalFormatSymbols.getInstance(locale)
- .getMonetaryDecimalSeparator());
- };
+ localeObserver = locale -> decimalSeparator = String.valueOf(
+ DecimalFormatSymbols.getInstance(locale)
+ .getMonetaryDecimalSeparator());
decimalDot = ".";
}
@Override
public void onDatePicked(int year, int month, int day) {
- item.setDate(new SimpleDate(year, month+1, day));
+ item.setDate(new SimpleDate(year, month + 1, day));
boolean focused = tvDescription.requestFocus();
if (focused)
Misc.showSoftKeyboard((NewTransactionActivity) tvAccount.getContext());
debug("description", broaderSql);
debug("description", description);
- activity.runOnUiThread(() -> {
- Snackbar.make(recyclerView, R.string.ignoring_preferred_account,
- Snackbar.LENGTH_LONG)
- .show();
- });
+ activity.runOnUiThread(
+ () -> Snackbar.make(recyclerView, R.string.ignoring_preferred_account,
+ Snackbar.LENGTH_LONG)
+ .show());
MLDB.queryInBackground(broaderSql, new String[]{description},
new MLDB.CallbackHelper() {
((buttonView, isChecked) -> model.setPostingPermitted(isChecked)));
Switch showCommentsByDefault = context.findViewById(R.id.profile_show_comments);
- model.observeShowCommentsByDefault(viewLifecycleOwner, isChecked -> {
- showCommentsByDefault.setChecked(isChecked);
- });
+ model.observeShowCommentsByDefault(viewLifecycleOwner, showCommentsByDefault::setChecked);
showCommentsByDefault.setOnCheckedChangeListener(
((buttonView, isChecked) -> model.setShowCommentsByDefault(isChecked)));
v -> futureDatesText.setText(v.getText(getResources())));
apiVersionText = context.findViewById(R.id.api_version_text);
- model.observeApiVersion(viewLifecycleOwner, apiVer -> {
- apiVersionText.setText(apiVer.getDescription(getResources()));
- });
+ model.observeApiVersion(viewLifecycleOwner,
+ apiVer -> apiVersionText.setText(apiVer.getDescription(getResources())));
context.findViewById(R.id.api_version_layout)
.setOnClickListener(v -> {
MenuInflater mi = new MenuInflater(context);
@NonNull RecyclerView.ViewHolder viewHolder,
@NonNull RecyclerView.ViewHolder target) {
final ArrayList<MobileLedgerProfile> profiles = Data.profiles.getValue();
- if (profiles == null) throw new AssertionError();
+ if (profiles == null)
+ throw new AssertionError();
Collections.swap(profiles, viewHolder.getAdapterPosition(),
target.getAdapterPosition());
MobileLedgerProfile.storeProfilesOrder();
public void onAttachedToRecyclerView(@NonNull RecyclerView recyclerView) {
super.onAttachedToRecyclerView(recyclerView);
this.recyclerView = recyclerView;
- if (editingProfiles.getValue()) rearrangeHelper.attachToRecyclerView(recyclerView);
+ if (editingProfiles.getValue())
+ rearrangeHelper.attachToRecyclerView(recyclerView);
}
public void startEditingProfiles() {
- if (editingProfiles.getValue()) return;
+ if (editingProfiles.getValue())
+ return;
this.editingProfiles.setValue(true);
rearrangeHelper.attachToRecyclerView(recyclerView);
}
public void stopEditingProfiles() {
- if (!editingProfiles.getValue()) return;
+ if (!editingProfiles.getValue())
+ return;
this.editingProfiles.setValue(false);
rearrangeHelper.attachToRecyclerView(null);
}
public void flipEditingProfiles() {
- if (editingProfiles.getValue()) stopEditingProfiles();
- else startEditingProfiles();
+ if (editingProfiles.getValue())
+ stopEditingProfiles();
+ else
+ startEditingProfiles();
}
private void editProfile(View view, MobileLedgerProfile profile) {
int index = Data.getProfileIndex(profile);
Context context = view.getContext();
Intent intent = new Intent(context, ProfileDetailActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_NO_USER_ACTION);
- if (index != -1) intent.putExtra(ProfileDetailFragment.ARG_ITEM_ID, index);
+ if (index != -1)
+ intent.putExtra(ProfileDetailFragment.ARG_ITEM_ID, index);
context.startActivity(intent);
}
private void onProfileRowClicked(View v) {
- if (editingProfiles.getValue()) return;
+ if (editingProfiles.getValue())
+ return;
MobileLedgerProfile profile = (MobileLedgerProfile) v.getTag();
if (profile == null)
throw new IllegalStateException("Profile row without associated profile");
@Override
public ProfileListViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
View view = LayoutInflater.from(parent.getContext())
- .inflate(R.layout.profile_list_content, parent, false);
+ .inflate(R.layout.profile_list_content, parent, false);
ProfileListViewHolder holder = new ProfileListViewHolder(view);
holder.mRow.setOnClickListener(this::onProfileRowClicked);
onProfileRowClicked(row);
});
holder.mColorTag.setOnClickListener(v -> {
- View row = (View) v.getParent().getParent();
+ View row = (View) v.getParent()
+ .getParent();
onProfileRowClicked(row);
});
holder.mTitle.setOnLongClickListener(v -> {
@Override
public void onBindViewHolder(@NonNull final ProfileListViewHolder holder, int position) {
final ArrayList<MobileLedgerProfile> profiles = Data.profiles.getValue();
- if (profiles == null) throw new AssertionError();
+ if (profiles == null)
+ throw new AssertionError();
final MobileLedgerProfile profile = profiles.get(position);
final MobileLedgerProfile currentProfile = Data.getProfile();
debug("profiles", String.format(Locale.ENGLISH, "pos %d: %s, current: %s", position,
holder.itemView.setTag(profile);
int hue = profile.getThemeHue();
- if (hue == -1) holder.mColorTag
- .setBackgroundColor(Colors.getPrimaryColorForHue(Colors.DEFAULT_HUE_DEG));
- else holder.mColorTag.setBackgroundColor(Colors.getPrimaryColorForHue(hue));
+ if (hue == -1)
+ holder.mColorTag.setBackgroundColor(
+ Colors.getPrimaryColorForHue(Colors.DEFAULT_HUE_DEG));
+ else
+ holder.mColorTag.setBackgroundColor(Colors.getPrimaryColorForHue(hue));
holder.mTitle.setText(profile.getName());
// holder.mSubTitle.setText(profile.getUrl());
holder.mEditButton.setOnClickListener(mOnClickListener);
final boolean sameProfile = currentProfile.equals(profile);
- holder.itemView
- .setBackground(sameProfile ? new ColorDrawable(Colors.tableRowDarkBG) : null);
+ holder.itemView.setBackground(
+ sameProfile ? new ColorDrawable(Colors.tableRowDarkBG) : null);
if (editingProfiles.getValue()) {
boolean wasHidden = holder.mEditButton.getVisibility() == View.GONE;
holder.mRearrangeHandle.setVisibility(View.VISIBLE);
holder.mEditButton.setVisibility(View.VISIBLE);
if (wasHidden && animationsEnabled) {
- Animation a = AnimationUtils
- .loadAnimation(holder.mRearrangeHandle.getContext(), R.anim.fade_in);
+ Animation a = AnimationUtils.loadAnimation(holder.mRearrangeHandle.getContext(),
+ R.anim.fade_in);
holder.mRearrangeHandle.startAnimation(a);
holder.mEditButton.startAnimation(a);
}
holder.mRearrangeHandle.setVisibility(View.INVISIBLE);
holder.mEditButton.setVisibility(View.GONE);
if (wasShown && animationsEnabled) {
- Animation a = AnimationUtils
- .loadAnimation(holder.mRearrangeHandle.getContext(), R.anim.fade_out);
+ Animation a = AnimationUtils.loadAnimation(holder.mRearrangeHandle.getContext(),
+ R.anim.fade_out);
holder.mRearrangeHandle.startAnimation(a);
holder.mEditButton.startAnimation(a);
}
import android.os.AsyncTask;
+import androidx.lifecycle.ViewModel;
+
import net.ktnx.mobileledger.async.UpdateTransactionsTask;
import net.ktnx.mobileledger.model.Data;
import net.ktnx.mobileledger.model.TransactionListItem;
import net.ktnx.mobileledger.utils.LockHolder;
import net.ktnx.mobileledger.utils.ObservableValue;
-import androidx.lifecycle.ViewModel;
-
public class TransactionListViewModel extends ViewModel {
public static ObservableValue<Boolean> updating = new ObservableValue<>();
public static ObservableValue<String> updateError = new ObservableValue<>();
public static void scheduleTransactionListReload() {
-
String filter = Data.accountFilter.getValue();
AsyncTask<String, Void, String> task = new UTT();
task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, filter);