From c27aa72c2c641bcd568692b4a20b125605cfb3b5 Mon Sep 17 00:00:00 2001 From: Damyan Ivanov Date: Sat, 15 Aug 2020 10:08:00 +0000 Subject: [PATCH] whitespace --- .../main/java/net/ktnx/mobileledger/App.java | 26 +++++----- .../async/SendTransactionTask.java | 2 +- .../net/ktnx/mobileledger/model/Currency.java | 42 +++++++-------- .../net/ktnx/mobileledger/model/Data.java | 2 +- .../mobileledger/model/LedgerTransaction.java | 34 ++++++------ .../ui/CrashReportDialogFragment.java | 7 +-- .../ui/CurrencySelectorFragment.java | 14 +++-- .../ui/CurrencySelectorModel.java | 3 +- .../net/ktnx/mobileledger/ui/HueRing.java | 22 +++++--- .../ui/activity/NewTransactionItemHolder.java | 9 ++-- .../activity/NewTransactionItemsAdapter.java | 9 ++-- .../ui/profiles/ProfileDetailFragment.java | 9 ++-- .../profiles/ProfilesRecyclerViewAdapter.java | 52 ++++++++++++------- .../TransactionListViewModel.java | 5 +- 14 files changed, 123 insertions(+), 113 deletions(-) diff --git a/app/src/main/java/net/ktnx/mobileledger/App.java b/app/src/main/java/net/ktnx/mobileledger/App.java index f0f7c013..72462797 100644 --- a/app/src/main/java/net/ktnx/mobileledger/App.java +++ b/app/src/main/java/net/ktnx/mobileledger/App.java @@ -42,10 +42,14 @@ public class App extends Application { 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()"); @@ -63,10 +67,12 @@ public class App extends Application { 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(); @@ -77,9 +83,6 @@ public class App extends Application { } }); } - public static void prepareMonthNames() { - instance.prepareMonthNames(false); - } private void prepareMonthNames(boolean force) { if (force || monthNamesPrepared) return; @@ -105,12 +108,11 @@ public class App extends Application { 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); } diff --git a/app/src/main/java/net/ktnx/mobileledger/async/SendTransactionTask.java b/app/src/main/java/net/ktnx/mobileledger/async/SendTransactionTask.java index f67e1844..f2ed99ff 100644 --- a/app/src/main/java/net/ktnx/mobileledger/async/SendTransactionTask.java +++ b/app/src/main/java/net/ktnx/mobileledger/async/SendTransactionTask.java @@ -64,7 +64,7 @@ public class SendTransactionTask extends AsyncTask(); public static final MutableLiveData currencyGap = new MutableLiveData<>(true); public static final MutableLiveData locale = new MutableLiveData<>(Locale.getDefault()); + public static final MutableLiveData drawerOpen = new MutableLiveData<>(false); private static final MutableLiveData profile = new InertMutableLiveData<>(); private static final AtomicInteger backgroundTaskCount = new AtomicInteger(0); @@ -70,7 +71,6 @@ public final class Data { public static MobileLedgerProfile getProfile() { return Objects.requireNonNull(profile.getValue()); } - public static final MutableLiveData drawerOpen = new MutableLiveData<>(false); public static void backgroundTaskStarted() { int cnt = backgroundTaskCount.incrementAndGet(); debug("data", diff --git a/app/src/main/java/net/ktnx/mobileledger/model/LedgerTransaction.java b/app/src/main/java/net/ktnx/mobileledger/model/LedgerTransaction.java index e31d1582..6a8234f2 100644 --- a/app/src/main/java/net/ktnx/mobileledger/model/LedgerTransaction.java +++ b/app/src/main/java/net/ktnx/mobileledger/model/LedgerTransaction.java @@ -36,25 +36,21 @@ import java.util.Comparator; public class LedgerTransaction { private static final String DIGEST_TYPE = "SHA-256"; - public final Comparator comparator = - new Comparator() { - @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 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; diff --git a/app/src/main/java/net/ktnx/mobileledger/ui/CrashReportDialogFragment.java b/app/src/main/java/net/ktnx/mobileledger/ui/CrashReportDialogFragment.java index 617a006c..fcb53193 100644 --- a/app/src/main/java/net/ktnx/mobileledger/ui/CrashReportDialogFragment.java +++ b/app/src/main/java/net/ktnx/mobileledger/ui/CrashReportDialogFragment.java @@ -22,14 +22,15 @@ import android.app.Dialog; 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; diff --git a/app/src/main/java/net/ktnx/mobileledger/ui/CurrencySelectorFragment.java b/app/src/main/java/net/ktnx/mobileledger/ui/CurrencySelectorFragment.java index 9c527fe0..4993df37 100644 --- a/app/src/main/java/net/ktnx/mobileledger/ui/CurrencySelectorFragment.java +++ b/app/src/main/java/net/ktnx/mobileledger/ui/CurrencySelectorFragment.java @@ -112,7 +112,7 @@ public class CurrencySelectorFragment extends AppCompatDialogFragment 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); @@ -184,14 +184,12 @@ public class CurrencySelectorFragment extends AppCompatDialogFragment 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) diff --git a/app/src/main/java/net/ktnx/mobileledger/ui/CurrencySelectorModel.java b/app/src/main/java/net/ktnx/mobileledger/ui/CurrencySelectorModel.java index 58950244..89b78792 100644 --- a/app/src/main/java/net/ktnx/mobileledger/ui/CurrencySelectorModel.java +++ b/app/src/main/java/net/ktnx/mobileledger/ui/CurrencySelectorModel.java @@ -39,7 +39,8 @@ public class CurrencySelectorModel extends ViewModel { public void hidePositionAndPadding() { positionAndPaddingVisible.postValue(false); } - public void observePositionAndPaddingVisible(LifecycleOwner activity, Observer observer) { + public void observePositionAndPaddingVisible(LifecycleOwner activity, + Observer observer) { positionAndPaddingVisible.observe(activity, observer); } void setOnCurrencySelectedListener(OnCurrencySelectedListener listener) { diff --git a/app/src/main/java/net/ktnx/mobileledger/ui/HueRing.java b/app/src/main/java/net/ktnx/mobileledger/ui/HueRing.java index c97741a9..006cd4ba 100644 --- a/app/src/main/java/net/ktnx/mobileledger/ui/HueRing.java +++ b/app/src/main/java/net/ktnx/mobileledger/ui/HueRing.java @@ -28,10 +28,11 @@ import android.util.AttributeSet; 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; @@ -114,13 +115,16 @@ public class HueRing extends View { 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; @@ -161,8 +165,8 @@ public class HueRing extends View { // 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); @@ -224,7 +228,8 @@ public class HueRing extends View { 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)); @@ -235,7 +240,8 @@ public class HueRing extends View { 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(); diff --git a/app/src/main/java/net/ktnx/mobileledger/ui/activity/NewTransactionItemHolder.java b/app/src/main/java/net/ktnx/mobileledger/ui/activity/NewTransactionItemHolder.java index e311eb94..c274c455 100644 --- a/app/src/main/java/net/ktnx/mobileledger/ui/activity/NewTransactionItemHolder.java +++ b/app/src/main/java/net/ktnx/mobileledger/ui/activity/NewTransactionItemHolder.java @@ -186,10 +186,9 @@ class NewTransactionItemHolder extends RecyclerView.ViewHolder 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 = "."; @@ -719,7 +718,7 @@ class NewTransactionItemHolder extends RecyclerView.ViewHolder } @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()); diff --git a/app/src/main/java/net/ktnx/mobileledger/ui/activity/NewTransactionItemsAdapter.java b/app/src/main/java/net/ktnx/mobileledger/ui/activity/NewTransactionItemsAdapter.java index d3e9d8f2..4b3fa8e6 100644 --- a/app/src/main/java/net/ktnx/mobileledger/ui/activity/NewTransactionItemsAdapter.java +++ b/app/src/main/java/net/ktnx/mobileledger/ui/activity/NewTransactionItemsAdapter.java @@ -247,11 +247,10 @@ class NewTransactionItemsAdapter extends RecyclerView.Adapter { - 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() { diff --git a/app/src/main/java/net/ktnx/mobileledger/ui/profiles/ProfileDetailFragment.java b/app/src/main/java/net/ktnx/mobileledger/ui/profiles/ProfileDetailFragment.java index 95faf5d1..ee01017e 100644 --- a/app/src/main/java/net/ktnx/mobileledger/ui/profiles/ProfileDetailFragment.java +++ b/app/src/main/java/net/ktnx/mobileledger/ui/profiles/ProfileDetailFragment.java @@ -263,9 +263,7 @@ public class ProfileDetailFragment extends Fragment { ((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))); @@ -288,9 +286,8 @@ public class ProfileDetailFragment extends Fragment { 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); diff --git a/app/src/main/java/net/ktnx/mobileledger/ui/profiles/ProfilesRecyclerViewAdapter.java b/app/src/main/java/net/ktnx/mobileledger/ui/profiles/ProfilesRecyclerViewAdapter.java index b2b5cb7f..ac90ce32 100644 --- a/app/src/main/java/net/ktnx/mobileledger/ui/profiles/ProfilesRecyclerViewAdapter.java +++ b/app/src/main/java/net/ktnx/mobileledger/ui/profiles/ProfilesRecyclerViewAdapter.java @@ -75,7 +75,8 @@ public class ProfilesRecyclerViewAdapter @NonNull RecyclerView.ViewHolder viewHolder, @NonNull RecyclerView.ViewHolder target) { final ArrayList 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(); @@ -105,33 +106,40 @@ public class ProfilesRecyclerViewAdapter 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"); @@ -144,7 +152,7 @@ public class ProfilesRecyclerViewAdapter @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); @@ -153,7 +161,8 @@ public class ProfilesRecyclerViewAdapter onProfileRowClicked(row); }); holder.mColorTag.setOnClickListener(v -> { - View row = (View) v.getParent().getParent(); + View row = (View) v.getParent() + .getParent(); onProfileRowClicked(row); }); holder.mTitle.setOnLongClickListener(v -> { @@ -175,7 +184,8 @@ public class ProfilesRecyclerViewAdapter @Override public void onBindViewHolder(@NonNull final ProfileListViewHolder holder, int position) { final ArrayList 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, @@ -183,9 +193,11 @@ public class ProfilesRecyclerViewAdapter 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()); @@ -193,15 +205,15 @@ public class ProfilesRecyclerViewAdapter 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); } @@ -211,8 +223,8 @@ public class ProfilesRecyclerViewAdapter 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); } diff --git a/app/src/main/java/net/ktnx/mobileledger/ui/transaction_list/TransactionListViewModel.java b/app/src/main/java/net/ktnx/mobileledger/ui/transaction_list/TransactionListViewModel.java index 16b9c2dc..fd4dd8a9 100644 --- a/app/src/main/java/net/ktnx/mobileledger/ui/transaction_list/TransactionListViewModel.java +++ b/app/src/main/java/net/ktnx/mobileledger/ui/transaction_list/TransactionListViewModel.java @@ -19,20 +19,19 @@ package net.ktnx.mobileledger.ui.transaction_list; 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 updating = new ObservableValue<>(); public static ObservableValue updateError = new ObservableValue<>(); public static void scheduleTransactionListReload() { - String filter = Data.accountFilter.getValue(); AsyncTask task = new UTT(); task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, filter); -- 2.39.2