diff options
Diffstat (limited to 'app/src')
11 files changed, 57 insertions, 119 deletions
diff --git a/app/src/main/java/net/lacolaco/smileessence/IntentRouter.java b/app/src/main/java/net/lacolaco/smileessence/IntentRouter.java index e65cea28..2c2096a6 100644 --- a/app/src/main/java/net/lacolaco/smileessence/IntentRouter.java +++ b/app/src/main/java/net/lacolaco/smileessence/IntentRouter.java @@ -143,20 +143,10 @@ public class IntentRouter { } private static void openPostPage(final MainActivity activity, final String str) { - new UIHandler() { - @Override - public void run() { - PostState.newState().beginTransaction().setText(str).commitWithOpen(activity); - } - }.post(); + new UIHandler(() -> PostState.newState().beginTransaction().setText(str).commitWithOpen(activity)).post(); } private static void openPostPageWithImage(final MainActivity activity, final Uri imageUri) { - new UIHandler() { - @Override - public void run() { - activity.openPostPageWithImage(imageUri); - } - }.post(); + new UIHandler(() -> activity.openPostPageWithImage(imageUri)).post(); } } diff --git a/app/src/main/java/net/lacolaco/smileessence/activity/MainActivity.java b/app/src/main/java/net/lacolaco/smileessence/activity/MainActivity.java index 5452051c..3fc33bc6 100644 --- a/app/src/main/java/net/lacolaco/smileessence/activity/MainActivity.java +++ b/app/src/main/java/net/lacolaco/smileessence/activity/MainActivity.java @@ -321,12 +321,7 @@ public class MainActivity extends Activity { } public void setSelectedPageIndex(final int position, final boolean smooth) { - new UIHandler() { - @Override - public void run() { - viewPager.setCurrentItem(position, smooth); - } - }.post(); + new UIHandler(() -> viewPager.setCurrentItem(position, smooth)).post(); } public void startMainLogic() { diff --git a/app/src/main/java/net/lacolaco/smileessence/notification/Notificator.java b/app/src/main/java/net/lacolaco/smileessence/notification/Notificator.java index 16662337..965d4a03 100644 --- a/app/src/main/java/net/lacolaco/smileessence/notification/Notificator.java +++ b/app/src/main/java/net/lacolaco/smileessence/notification/Notificator.java @@ -71,18 +71,15 @@ public class Notificator { if (activity.isFinishing()) { return; } - new UIHandler() { - @Override - public void run() { - if (isForeground) { - Logger.debug(String.format("notify by crouton %s", text)); - Crouton.makeText(activity, text, getStyle(type)).show(); - } else { - Logger.debug(String.format("notify by toast %s", text)); - Toast.makeText(activity, text, Toast.LENGTH_LONG).show(); - } + new UIHandler(() -> { + if (isForeground) { + Logger.debug(String.format("notify by crouton %s", text)); + Crouton.makeText(activity, text, getStyle(type)).show(); + } else { + Logger.debug(String.format("notify by toast %s", text)); + Toast.makeText(activity, text, Toast.LENGTH_LONG).show(); } - }.post(); + }).post(); } public void onForeground() { diff --git a/app/src/main/java/net/lacolaco/smileessence/util/UIHandler.java b/app/src/main/java/net/lacolaco/smileessence/util/UIHandler.java index 2beb2d8e..3171184e 100644 --- a/app/src/main/java/net/lacolaco/smileessence/util/UIHandler.java +++ b/app/src/main/java/net/lacolaco/smileessence/util/UIHandler.java @@ -27,45 +27,36 @@ package net.lacolaco.smileessence.util; import android.os.Handler; import android.os.Looper; -public abstract class UIHandler extends Handler implements Runnable { +public class UIHandler { + private final Runnable runnable; + private final Handler handler; // --------------------------- CONSTRUCTORS --------------------------- - public UIHandler() { - super(Looper.getMainLooper()); + public UIHandler(Runnable _runnable) { + handler = new Handler(Looper.getMainLooper()); + runnable = _runnable; } - public UIHandler(Callback callback) { - super(Looper.getMainLooper(), callback); - } - - // ------------------------ INTERFACE METHODS ------------------------ - - - // --------------------- Interface Runnable --------------------- - - @Override - public abstract void run(); - // -------------------------- OTHER METHODS -------------------------- public boolean post() { - return post(this); + return handler.post(runnable); } public boolean postAtFrontOfQueue() { - return postAtFrontOfQueue(this); + return handler.postAtFrontOfQueue(runnable); } public boolean postAtTime(long uptimeMillis) { - return postAtTime(this, uptimeMillis); + return handler.postAtTime(runnable, uptimeMillis); } public boolean postAtTime(Object token, long uptimeMillis) { - return postAtTime(this, token, uptimeMillis); + return handler.postAtTime(runnable, token, uptimeMillis); } public boolean postDelayed(long delayMillis) { - return postDelayed(this, delayMillis); + return handler.postDelayed(runnable, delayMillis); } } diff --git a/app/src/main/java/net/lacolaco/smileessence/view/HomeFragment.java b/app/src/main/java/net/lacolaco/smileessence/view/HomeFragment.java index 3aece899..fbe0a998 100644 --- a/app/src/main/java/net/lacolaco/smileessence/view/HomeFragment.java +++ b/app/src/main/java/net/lacolaco/smileessence/view/HomeFragment.java @@ -90,13 +90,10 @@ public class HomeFragment extends CustomListFragment<StatusListAdapter> { final MainActivity activity = (MainActivity) getActivity(); final StatusListAdapter adapter = getAdapter(); if (activity.isStreaming()) { - new UIHandler() { - @Override - public void run() { - updateListViewWithNotice(refreshView.getRefreshableView(), true); - refreshView.onRefreshComplete(); - } - }.post(); + new UIHandler(() -> { + updateListViewWithNotice(refreshView.getRefreshableView(), true); + refreshView.onRefreshComplete(); + }).post(); return; } final Account currentAccount = activity.getCurrentAccount(); diff --git a/app/src/main/java/net/lacolaco/smileessence/view/PostFragment.java b/app/src/main/java/net/lacolaco/smileessence/view/PostFragment.java index 439c8c56..30266289 100644 --- a/app/src/main/java/net/lacolaco/smileessence/view/PostFragment.java +++ b/app/src/main/java/net/lacolaco/smileessence/view/PostFragment.java @@ -132,12 +132,7 @@ public class PostFragment extends PageFragment implements TextWatcher, View.OnFo editText.setTextKeepState(postState.getText()); editText.addTextChangedListener(this); updateTextCount(editText.getText()); - new UIHandler() { - @Override - public void run() { - editText.setSelection(start, end); - } - }.postAtFrontOfQueue(); + new UIHandler(() -> editText.setSelection(start, end)).postAtFrontOfQueue(); } if (viewGroupReply != null) { if (postState.getInReplyToStatusID() >= 0) { @@ -359,13 +354,10 @@ public class PostFragment extends PageFragment implements TextWatcher, View.OnFo private void showIME() { if (editText != null) { - new UIHandler() { - @Override - public void run() { - InputMethodManager imm = (InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE); - imm.showSoftInput(editText, InputMethodManager.RESULT_UNCHANGED_SHOWN); - } - }.postDelayed(100); + new UIHandler(() -> { + InputMethodManager imm = (InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE); + imm.showSoftInput(editText, InputMethodManager.RESULT_UNCHANGED_SHOWN); + }).postDelayed(100); } } diff --git a/app/src/main/java/net/lacolaco/smileessence/view/SearchFragment.java b/app/src/main/java/net/lacolaco/smileessence/view/SearchFragment.java index faa56dac..59ec0b8f 100644 --- a/app/src/main/java/net/lacolaco/smileessence/view/SearchFragment.java +++ b/app/src/main/java/net/lacolaco/smileessence/view/SearchFragment.java @@ -141,13 +141,10 @@ public class SearchFragment extends CustomListFragment<SearchListAdapter> implem final SearchListAdapter adapter = getAdapter(); String queryString = adapter.getQuery(); if (TextUtils.isEmpty(queryString)) { - new UIHandler() { - @Override - public void run() { - notifyTextEmpty(activity); - refreshView.onRefreshComplete(); - } - }.post(); + new UIHandler(() -> { + notifyTextEmpty(activity); + refreshView.onRefreshComplete(); + }).post(); return; } final Query query = new Query(); @@ -187,13 +184,10 @@ public class SearchFragment extends CustomListFragment<SearchListAdapter> implem final SearchListAdapter adapter = getAdapter(); String queryString = adapter.getQuery(); if (TextUtils.isEmpty(queryString)) { - new UIHandler() { - @Override - public void run() { - notifyTextEmpty(activity); - refreshView.onRefreshComplete(); - } - }.post(); + new UIHandler(() -> { + notifyTextEmpty(activity); + refreshView.onRefreshComplete(); + }).post(); return; } final Query query = new Query(); diff --git a/app/src/main/java/net/lacolaco/smileessence/view/UserListFragment.java b/app/src/main/java/net/lacolaco/smileessence/view/UserListFragment.java index cd186dca..da1503f5 100644 --- a/app/src/main/java/net/lacolaco/smileessence/view/UserListFragment.java +++ b/app/src/main/java/net/lacolaco/smileessence/view/UserListFragment.java @@ -109,13 +109,10 @@ public class UserListFragment extends CustomListFragment<UserListListAdapter> im final UserListListAdapter adapter = (UserListListAdapter) getAdapter(); String listFullName = adapter.getListFullName(); if (TextUtils.isEmpty(listFullName)) { - new UIHandler() { - @Override - public void run() { - notifyTextEmpty(activity); - refreshView.onRefreshComplete(); - } - }.post(); + new UIHandler(() -> { + notifyTextEmpty(activity); + refreshView.onRefreshComplete(); + }).post(); return; } Paging paging = TwitterUtils.getPaging(TwitterUtils.getPagingCount(activity)); @@ -145,13 +142,10 @@ public class UserListFragment extends CustomListFragment<UserListListAdapter> im final UserListListAdapter adapter = (UserListListAdapter) getAdapter(); String listFullName = adapter.getListFullName(); if (TextUtils.isEmpty(listFullName)) { - new UIHandler() { - @Override - public void run() { - notifyTextEmpty(activity); - refreshView.onRefreshComplete(); - } - }.post(); + new UIHandler(() -> { + notifyTextEmpty(activity); + refreshView.onRefreshComplete(); + }).post(); return; } Paging paging = TwitterUtils.getPaging(TwitterUtils.getPagingCount(activity)); diff --git a/app/src/main/java/net/lacolaco/smileessence/view/adapter/CustomListAdapter.java b/app/src/main/java/net/lacolaco/smileessence/view/adapter/CustomListAdapter.java index 76824e45..16691238 100644 --- a/app/src/main/java/net/lacolaco/smileessence/view/adapter/CustomListAdapter.java +++ b/app/src/main/java/net/lacolaco/smileessence/view/adapter/CustomListAdapter.java @@ -160,12 +160,7 @@ public class CustomListAdapter<T extends IViewModel> extends BaseAdapter { public void updateForce() { synchronized (LOCK) { - new UIHandler() { - @Override - public void run() { - notifyDataSetChanged(); - } - }.post(); + new UIHandler(this::notifyDataSetChanged).post(); } } } diff --git a/app/src/main/java/net/lacolaco/smileessence/view/dialog/UserDetailDialogFragment.java b/app/src/main/java/net/lacolaco/smileessence/view/dialog/UserDetailDialogFragment.java index e7be7485..cd8c935e 100644 --- a/app/src/main/java/net/lacolaco/smileessence/view/dialog/UserDetailDialogFragment.java +++ b/app/src/main/java/net/lacolaco/smileessence/view/dialog/UserDetailDialogFragment.java @@ -347,15 +347,12 @@ public class UserDetailDialogFragment extends StackableDialogFragment implements @Override protected void executeCommand(Command command) { super.executeCommand(command); - new UIHandler() { - @Override - public void run() { - if (UserDetailDialogFragment.this.isDetached()) { - return; - } - updateRelationship(activity, user.getId()); + new UIHandler(() -> { + if (UserDetailDialogFragment.this.isDetached()) { + return; } - }.postDelayed(1000); + updateRelationship(activity, user.getId()); + }).postDelayed(1000); } }; menuFragment.setUserID(user.getId()); diff --git a/app/src/main/java/net/lacolaco/smileessence/view/listener/ListItemClickListener.java b/app/src/main/java/net/lacolaco/smileessence/view/listener/ListItemClickListener.java index bfb3573f..3ed73acb 100644 --- a/app/src/main/java/net/lacolaco/smileessence/view/listener/ListItemClickListener.java +++ b/app/src/main/java/net/lacolaco/smileessence/view/listener/ListItemClickListener.java @@ -55,13 +55,9 @@ public class ListItemClickListener implements View.OnClickListener { final int currentBgColor = ((ColorDrawable) v.getBackground()).getColor(); v.setBackgroundColor(activity.getResources().getColor(R.color.metro_blue)); v.invalidate(); - new UIHandler() { - - @Override - public void run() { - v.setBackgroundColor(currentBgColor); - callback.run(); - } - }.post(); + new UIHandler(() -> { + v.setBackgroundColor(currentBgColor); + callback.run(); + }).post(); } } |