From 198f2762d2236a57cec413322c0bde6985ead88a Mon Sep 17 00:00:00 2001 From: Damyan Ivanov Date: Sat, 5 Jan 2019 13:06:16 +0000 Subject: [PATCH] some lambdas --- .../AccountSummaryFragment.java | 18 ++++----------- .../ui/activity/MainActivity.java | 23 ++++++++----------- .../TransactionListFragment.java | 18 ++++----------- 3 files changed, 20 insertions(+), 39 deletions(-) diff --git a/app/src/main/java/net/ktnx/mobileledger/ui/account_summary/AccountSummaryFragment.java b/app/src/main/java/net/ktnx/mobileledger/ui/account_summary/AccountSummaryFragment.java index 19c88f2f..82709138 100644 --- a/app/src/main/java/net/ktnx/mobileledger/ui/account_summary/AccountSummaryFragment.java +++ b/app/src/main/java/net/ktnx/mobileledger/ui/account_summary/AccountSummaryFragment.java @@ -79,13 +79,10 @@ public class AccountSummaryFragment extends MobileLedgerListFragment { public void update(Observable o, Object arg) { if (mActivity == null) return; if (swiper == null) return; - mActivity.runOnUiThread(new Runnable() { - @Override - public void run() { - int cnt = Data.backgroundTaskCount.get(); - Log.d("acc", String.format("background task count changed to %d", cnt)); - swiper.setRefreshing(cnt > 0); - } + mActivity.runOnUiThread(() -> { + int cnt = Data.backgroundTaskCount.get(); + Log.d("acc", String.format("background task count changed to %d", cnt)); + swiper.setRefreshing(cnt > 0); }); } }); @@ -174,12 +171,7 @@ public class AccountSummaryFragment extends MobileLedgerListFragment { Data.accounts.addObserver(new Observer() { @Override public void update(Observable o, Object arg) { - mActivity.runOnUiThread(new Runnable() { - @Override - public void run() { - modelAdapter.notifyDataSetChanged(); - } - }); + mActivity.runOnUiThread(() -> modelAdapter.notifyDataSetChanged()); } }); update_account_table(); diff --git a/app/src/main/java/net/ktnx/mobileledger/ui/activity/MainActivity.java b/app/src/main/java/net/ktnx/mobileledger/ui/activity/MainActivity.java index c2ff5c27..6e17983b 100644 --- a/app/src/main/java/net/ktnx/mobileledger/ui/activity/MainActivity.java +++ b/app/src/main/java/net/ktnx/mobileledger/ui/activity/MainActivity.java @@ -109,21 +109,18 @@ public class MainActivity extends AppCompatActivity { @Override public void update(Observable o, Object arg) { Log.d("main", "lastUpdateDate changed"); - runOnUiThread(new Runnable() { - @Override - public void run() { - Date date = Data.lastUpdateDate.get(); - if (date == null) { - tvLastUpdate.setText(R.string.transaction_last_update_never); + runOnUiThread(() -> { + Date date = Data.lastUpdateDate.get(); + if (date == null) { + tvLastUpdate.setText(R.string.transaction_last_update_never); + } + else { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { + tvLastUpdate.setText(date.toInstant().atZone(ZoneId.systemDefault()) + .format(DateTimeFormatter.ISO_LOCAL_DATE_TIME)); } else { - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { - tvLastUpdate.setText(date.toInstant().atZone(ZoneId.systemDefault()) - .format(DateTimeFormatter.ISO_LOCAL_DATE_TIME)); - } - else { - tvLastUpdate.setText(date.toLocaleString()); - } + tvLastUpdate.setText(date.toLocaleString()); } } }); diff --git a/app/src/main/java/net/ktnx/mobileledger/ui/transaction_list/TransactionListFragment.java b/app/src/main/java/net/ktnx/mobileledger/ui/transaction_list/TransactionListFragment.java index e3496a08..a15650ae 100644 --- a/app/src/main/java/net/ktnx/mobileledger/ui/transaction_list/TransactionListFragment.java +++ b/app/src/main/java/net/ktnx/mobileledger/ui/transaction_list/TransactionListFragment.java @@ -94,13 +94,10 @@ public class TransactionListFragment extends MobileLedgerListFragment { Data.backgroundTaskCount.addObserver(backgroundTaskCountObserver = new Observer() { @Override public void update(Observable o, Object arg) { - mActivity.runOnUiThread(new Runnable() { - @Override - public void run() { - int cnt = Data.backgroundTaskCount.get(); - Log.d("trl", String.format("background task count changed to %d", cnt)); - swiper.setRefreshing(cnt > 0); - } + mActivity.runOnUiThread(() -> { + int cnt = Data.backgroundTaskCount.get(); + Log.d("trl", String.format("background task count changed to %d", cnt)); + swiper.setRefreshing(cnt > 0); }); } }); @@ -197,12 +194,7 @@ public class TransactionListFragment extends MobileLedgerListFragment { Data.transactions.addObserver(new Observer() { @Override public void update(Observable o, Object arg) { - mActivity.runOnUiThread(new Runnable() { - @Override - public void run() { - modelAdapter.notifyDataSetChanged(); - } - }); + mActivity.runOnUiThread(() -> modelAdapter.notifyDataSetChanged()); } }); -- 2.39.5