From 5bc9d6770eed0662e47c73d67aa3b05a1c9c5cb7 Mon Sep 17 00:00:00 2001 From: TacoTheDank Date: Sun, 31 May 2020 02:32:14 -0400 Subject: [PATCH] Java 8 migration aid --- .../twidere/model/ParcelableStatus.java | 9 +-- .../ExtendedDividerItemDecoration.java | 9 +-- .../fragment/FileSelectorDialogFragment.java | 22 +++----- .../fragment/KeyboardShortcutsFragment.java | 15 +---- ...medListPreferenceDialogFragmentCompat.java | 20 +++---- .../preference/MultiSelectListPreference.java | 7 +-- .../SettingsImportExportPreference.java | 15 +---- .../preference/ThemeBackgroundPreference.java | 56 ++++++++----------- .../twidere/util/AbsServiceInterface.java | 9 +-- .../SwipeDismissListViewTouchListener.java | 9 +-- 10 files changed, 52 insertions(+), 119 deletions(-) diff --git a/twidere.component.common/src/main/java/org/mariotaku/twidere/model/ParcelableStatus.java b/twidere.component.common/src/main/java/org/mariotaku/twidere/model/ParcelableStatus.java index f27948213..b83ac6790 100644 --- a/twidere.component.common/src/main/java/org/mariotaku/twidere/model/ParcelableStatus.java +++ b/twidere.component.common/src/main/java/org/mariotaku/twidere/model/ParcelableStatus.java @@ -20,7 +20,6 @@ package org.mariotaku.twidere.model; import android.os.Parcel; import android.os.Parcelable; -import androidx.annotation.IntDef; import androidx.annotation.LongDef; import androidx.annotation.NonNull; import androidx.annotation.Nullable; @@ -52,13 +51,7 @@ import java.util.Comparator; @ParcelablePlease public class ParcelableStatus implements Parcelable, Comparable, Cloneable { - public static final Comparator REVERSE_COMPARATOR = new Comparator() { - - @Override - public int compare(final ParcelableStatus object1, final ParcelableStatus object2) { - return object2.compareTo(object1); - } - }; + public static final Comparator REVERSE_COMPARATOR = (object1, object2) -> object2.compareTo(object1); public static final Creator CREATOR = new Creator() { @Override public ParcelableStatus createFromParcel(Parcel source) { diff --git a/twidere/src/main/java/org/mariotaku/twidere/adapter/decorator/ExtendedDividerItemDecoration.java b/twidere/src/main/java/org/mariotaku/twidere/adapter/decorator/ExtendedDividerItemDecoration.java index 595d86935..ddff1c494 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/adapter/decorator/ExtendedDividerItemDecoration.java +++ b/twidere/src/main/java/org/mariotaku/twidere/adapter/decorator/ExtendedDividerItemDecoration.java @@ -84,12 +84,9 @@ public class ExtendedDividerItemDecoration extends RecyclerView.ItemDecoration { } public void setPadding(final int left, final int top, final int right, final int bottom) { - mPadding = new Padding() { - @Override - public boolean get(int position, Rect rect) { - rect.set(left, top, right, bottom); - return true; - } + mPadding = (position, rect) -> { + rect.set(left, top, right, bottom); + return true; }; } diff --git a/twidere/src/main/java/org/mariotaku/twidere/fragment/FileSelectorDialogFragment.java b/twidere/src/main/java/org/mariotaku/twidere/fragment/FileSelectorDialogFragment.java index e6569702d..b3848a953 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/fragment/FileSelectorDialogFragment.java +++ b/twidere/src/main/java/org/mariotaku/twidere/fragment/FileSelectorDialogFragment.java @@ -118,14 +118,11 @@ public class FileSelectorDialogFragment extends BaseDialogFragment implements Lo builder.setPositiveButton(android.R.string.ok, this); } final AlertDialog dialog = builder.create(); - dialog.setOnShowListener(new DialogInterface.OnShowListener() { - @Override - public void onShow(final DialogInterface dialog) { - final AlertDialog alertDialog = (AlertDialog) dialog; - DialogExtensionsKt.applyTheme(alertDialog); - final ListView listView = alertDialog.getListView(); - listView.setOnItemClickListener(FileSelectorDialogFragment.this); - } + dialog.setOnShowListener(dialog1 -> { + final AlertDialog alertDialog = (AlertDialog) dialog1; + DialogExtensionsKt.applyTheme(alertDialog); + final ListView listView = alertDialog.getListView(); + listView.setOnItemClickListener(FileSelectorDialogFragment.this); }); return dialog; } @@ -268,12 +265,9 @@ public class FileSelectorDialogFragment extends BaseDialogFragment implements Lo private final String[] extensions; private final Pattern extensions_regex; - private static final Comparator NAME_COMPARATOR = new Comparator() { - @Override - public int compare(final File file1, final File file2) { - final Locale loc = Locale.getDefault(); - return file1.getName().toLowerCase(loc).compareTo(file2.getName().toLowerCase(loc)); - } + private static final Comparator NAME_COMPARATOR = (file1, file2) -> { + final Locale loc = Locale.getDefault(); + return file1.getName().toLowerCase(loc).compareTo(file2.getName().toLowerCase(loc)); }; public FilesLoader(final Context context, final File path, final String[] extensions) { diff --git a/twidere/src/main/java/org/mariotaku/twidere/fragment/KeyboardShortcutsFragment.java b/twidere/src/main/java/org/mariotaku/twidere/fragment/KeyboardShortcutsFragment.java index 66fa84f94..f0a3d88d0 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/fragment/KeyboardShortcutsFragment.java +++ b/twidere/src/main/java/org/mariotaku/twidere/fragment/KeyboardShortcutsFragment.java @@ -24,7 +24,6 @@ import android.content.Context; import android.content.DialogInterface; import android.content.DialogInterface.OnClickListener; import android.content.Intent; -import android.content.SharedPreferences; import android.content.SharedPreferences.OnSharedPreferenceChangeListener; import android.os.Bundle; import androidx.annotation.NonNull; @@ -88,12 +87,7 @@ public class KeyboardShortcutsFragment extends BasePreferenceFragment implements mAction = action; setPersistent(false); setTitle(KeyboardShortcutsHandler.getActionLabel(context, action)); - mPreferencesChangeListener = new OnSharedPreferenceChangeListener() { - @Override - public void onSharedPreferenceChanged(SharedPreferences preferences, String key) { - updateSummary(); - } - }; + mPreferencesChangeListener = (preferences, key) -> updateSummary(); updateSummary(); } @@ -143,12 +137,7 @@ public class KeyboardShortcutsFragment extends BasePreferenceFragment implements builder.setPositiveButton(android.R.string.ok, this); builder.setNegativeButton(android.R.string.cancel, this); final AlertDialog dialog = builder.create(); - dialog.setOnShowListener(new DialogInterface.OnShowListener() { - @Override - public void onShow(final DialogInterface dialog) { - DialogExtensionsKt.applyTheme((AlertDialog) dialog); - } - }); + dialog.setOnShowListener(dialog1 -> DialogExtensionsKt.applyTheme((AlertDialog) dialog1)); return dialog; } } diff --git a/twidere/src/main/java/org/mariotaku/twidere/fragment/ThemedListPreferenceDialogFragmentCompat.java b/twidere/src/main/java/org/mariotaku/twidere/fragment/ThemedListPreferenceDialogFragmentCompat.java index 6d70643d2..4455099f8 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/fragment/ThemedListPreferenceDialogFragmentCompat.java +++ b/twidere/src/main/java/org/mariotaku/twidere/fragment/ThemedListPreferenceDialogFragmentCompat.java @@ -47,17 +47,15 @@ public class ThemedListPreferenceDialogFragmentCompat extends ThemedPreferenceDi } mClickedDialogEntryIndex = preference.findIndexOfValue(preference.getValue()); builder.setSingleChoiceItems(entries, mClickedDialogEntryIndex, - new DialogInterface.OnClickListener() { - public void onClick(DialogInterface dialog, int which) { - mClickedDialogEntryIndex = which; - /* - * Clicking on an item simulates the positive button - * click, and dismisses the dialog. - */ - ThemedListPreferenceDialogFragmentCompat.this.onClick(dialog, - DialogInterface.BUTTON_POSITIVE); - dialog.dismiss(); - } + (dialog, which) -> { + mClickedDialogEntryIndex = which; + /* + * Clicking on an item simulates the positive button + * click, and dismisses the dialog. + */ + ThemedListPreferenceDialogFragmentCompat.this.onClick(dialog, + DialogInterface.BUTTON_POSITIVE); + dialog.dismiss(); }); /* * The typical interaction for list-based dialogs is to have diff --git a/twidere/src/main/java/org/mariotaku/twidere/preference/MultiSelectListPreference.java b/twidere/src/main/java/org/mariotaku/twidere/preference/MultiSelectListPreference.java index 40f003f7a..b4e77996b 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/preference/MultiSelectListPreference.java +++ b/twidere/src/main/java/org/mariotaku/twidere/preference/MultiSelectListPreference.java @@ -100,12 +100,7 @@ abstract class MultiSelectListPreference extends DialogPreference implements IDi builder.setNegativeButton(android.R.string.cancel, null); builder.setMultiChoiceItems(mNames, mValues, this); final AlertDialog dialog = builder.create(); - dialog.setOnShowListener(new DialogInterface.OnShowListener() { - @Override - public void onShow(final DialogInterface dialog) { - DialogExtensionsKt.applyTheme((AlertDialog) dialog); - } - }); + dialog.setOnShowListener(dialog1 -> DialogExtensionsKt.applyTheme((AlertDialog) dialog1)); return dialog; } diff --git a/twidere/src/main/java/org/mariotaku/twidere/preference/SettingsImportExportPreference.java b/twidere/src/main/java/org/mariotaku/twidere/preference/SettingsImportExportPreference.java index 7c9bbdb74..7d520e36c 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/preference/SettingsImportExportPreference.java +++ b/twidere/src/main/java/org/mariotaku/twidere/preference/SettingsImportExportPreference.java @@ -21,7 +21,6 @@ package org.mariotaku.twidere.preference; import android.app.Dialog; import android.content.Context; -import android.content.DialogInterface; import android.content.Intent; import android.os.Bundle; import androidx.annotation.NonNull; @@ -78,19 +77,9 @@ public class SettingsImportExportPreference extends DialogPreference implements entries[1] = context.getString(R.string.export_settings); values[0] = new Intent(context, DataImportActivity.class); values[1] = new Intent(context, DataExportActivity.class); - builder.setItems(entries, new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialog, int which) { - startActivity(values[which]); - } - }); + builder.setItems(entries, (dialog, which) -> startActivity(values[which])); final AlertDialog dialog = builder.create(); - dialog.setOnShowListener(new DialogInterface.OnShowListener() { - @Override - public void onShow(final DialogInterface dialog) { - DialogExtensionsKt.applyTheme((AlertDialog) dialog); - } - }); + dialog.setOnShowListener(dialog1 -> DialogExtensionsKt.applyTheme((AlertDialog) dialog1)); return dialog; } diff --git a/twidere/src/main/java/org/mariotaku/twidere/preference/ThemeBackgroundPreference.java b/twidere/src/main/java/org/mariotaku/twidere/preference/ThemeBackgroundPreference.java index bc7346649..ad66c6aef 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/preference/ThemeBackgroundPreference.java +++ b/twidere/src/main/java/org/mariotaku/twidere/preference/ThemeBackgroundPreference.java @@ -2,8 +2,6 @@ package org.mariotaku.twidere.preference; import android.app.Dialog; import android.content.Context; -import android.content.DialogInterface; -import android.content.DialogInterface.OnClickListener; import android.content.SharedPreferences; import android.content.res.Resources; import android.os.Bundle; @@ -17,7 +15,6 @@ import android.util.AttributeSet; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; -import android.widget.AdapterView; import android.widget.ListView; import android.widget.SeekBar; @@ -160,42 +157,33 @@ public class ThemeBackgroundPreference extends DialogPreference implements Const final SharedPreferences preferences = preference.getSharedPreferences(); preference.setValue(preference.getPersistedString(null)); builder.setTitle(preference.getDialogTitle()); - builder.setSingleChoiceItems(preference.mBackgroundEntries, preference.getValueIndex(), new OnClickListener() { - @Override - public void onClick(DialogInterface dialog, int which) { - preference.setSelectedOption(which); - updateAlphaVisibility(); - } + builder.setSingleChoiceItems(preference.mBackgroundEntries, preference.getValueIndex(), (dialog, which) -> { + preference.setSelectedOption(which); + updateAlphaVisibility(); }); builder.setPositiveButton(android.R.string.ok, this); builder.setNegativeButton(android.R.string.cancel, this); final Dialog dialog = builder.create(); - dialog.setOnShowListener(new DialogInterface.OnShowListener() { - @Override - public void onShow(DialogInterface dialog) { - final AlertDialog alertDialog = (AlertDialog) dialog; - DialogExtensionsKt.applyTheme(alertDialog); - if (preferences != null) { - final LayoutInflater inflater = alertDialog.getLayoutInflater(); - final ListView listView = alertDialog.getListView(); - assert listView != null; - final ViewGroup listViewParent = (ViewGroup) listView.getParent(); - listViewParent.removeView(listView); - final View view = inflater.inflate(R.layout.dialog_theme_background_preference, listViewParent); - ((ViewGroup) view.findViewById(R.id.list_container)).addView(listView); - mAlphaContainer = view.findViewById(R.id.alpha_container); - mAlphaSlider = view.findViewById(R.id.alpha_slider); - mAlphaSlider.setMax(MAX_ALPHA - MIN_ALPHA); - mAlphaSlider.setProgress(preferences.getInt(KEY_THEME_BACKGROUND_ALPHA, DEFAULT_THEME_BACKGROUND_ALPHA) - MIN_ALPHA); - listView.setOnItemClickListener(new AdapterView.OnItemClickListener() { - @Override - public void onItemClick(AdapterView parent, View view, int position, long id) { - preference.setSelectedOption(position); - updateAlphaVisibility(); - } - }); + dialog.setOnShowListener(dialog1 -> { + final AlertDialog alertDialog = (AlertDialog) dialog1; + DialogExtensionsKt.applyTheme(alertDialog); + if (preferences != null) { + final LayoutInflater inflater = alertDialog.getLayoutInflater(); + final ListView listView = alertDialog.getListView(); + assert listView != null; + final ViewGroup listViewParent = (ViewGroup) listView.getParent(); + listViewParent.removeView(listView); + final View view = inflater.inflate(R.layout.dialog_theme_background_preference, listViewParent); + ((ViewGroup) view.findViewById(R.id.list_container)).addView(listView); + mAlphaContainer = view.findViewById(R.id.alpha_container); + mAlphaSlider = view.findViewById(R.id.alpha_slider); + mAlphaSlider.setMax(MAX_ALPHA - MIN_ALPHA); + mAlphaSlider.setProgress(preferences.getInt(KEY_THEME_BACKGROUND_ALPHA, DEFAULT_THEME_BACKGROUND_ALPHA) - MIN_ALPHA); + listView.setOnItemClickListener((parent, view1, position, id) -> { + preference.setSelectedOption(position); updateAlphaVisibility(); - } + }); + updateAlphaVisibility(); } }); return dialog; diff --git a/twidere/src/main/java/org/mariotaku/twidere/util/AbsServiceInterface.java b/twidere/src/main/java/org/mariotaku/twidere/util/AbsServiceInterface.java index 254a2a412..f678104a9 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/util/AbsServiceInterface.java +++ b/twidere/src/main/java/org/mariotaku/twidere/util/AbsServiceInterface.java @@ -31,7 +31,6 @@ import androidx.annotation.Nullable; import org.mariotaku.twidere.constant.IntentConstants; import org.mariotaku.twidere.util.ServiceUtils.ServiceToken; -import java.util.concurrent.Callable; import java.util.concurrent.ExecutionException; import java.util.concurrent.FutureTask; @@ -73,12 +72,7 @@ public abstract class AbsServiceInterface implements IInte final Intent intent = new Intent(IntentConstants.INTENT_ACTION_EXTENSION_SHORTEN_STATUS); final ComponentName component = ComponentName.unflattenFromString(mShortenerName); intent.setComponent(component); - final FutureTask futureTask = new FutureTask<>(new Callable() { - @Override - public Boolean call() throws Exception { - return mIInterface != null; - } - }); + final FutureTask futureTask = new FutureTask<>(() -> mIInterface != null); mToken = ServiceUtils.bindToService(mContext, intent, new ServiceConnection() { @Override public void onServiceConnected(final ComponentName name, final IBinder obj) { @@ -112,7 +106,6 @@ public abstract class AbsServiceInterface implements IInte } public interface CheckServiceAction { - @SuppressWarnings("RedundantThrows") void check(@Nullable Bundle metaData) throws CheckServiceException; } diff --git a/twidere/src/main/java/org/mariotaku/twidere/util/SwipeDismissListViewTouchListener.java b/twidere/src/main/java/org/mariotaku/twidere/util/SwipeDismissListViewTouchListener.java index 1e1d57991..c3c5d0dd7 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/util/SwipeDismissListViewTouchListener.java +++ b/twidere/src/main/java/org/mariotaku/twidere/util/SwipeDismissListViewTouchListener.java @@ -391,12 +391,9 @@ public class SwipeDismissListViewTouchListener implements View.OnTouchListener { } }); - animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { - @Override - public void onAnimationUpdate(ValueAnimator valueAnimator) { - lp.height = (Integer) valueAnimator.getAnimatedValue(); - dismissView.setLayoutParams(lp); - } + animator.addUpdateListener(valueAnimator -> { + lp.height = (Integer) valueAnimator.getAnimatedValue(); + dismissView.setLayoutParams(lp); }); mPendingDismisses.add(new PendingDismissData(dismissPosition, dismissView));