Java 8 migration aid

This commit is contained in:
TacoTheDank 2020-05-31 02:32:14 -04:00
parent 67b0af9cb4
commit 5bc9d6770e
10 changed files with 52 additions and 119 deletions

View File

@ -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<ParcelableStatus>, Cloneable {
public static final Comparator<ParcelableStatus> REVERSE_COMPARATOR = new Comparator<ParcelableStatus>() {
@Override
public int compare(final ParcelableStatus object1, final ParcelableStatus object2) {
return object2.compareTo(object1);
}
};
public static final Comparator<ParcelableStatus> REVERSE_COMPARATOR = (object1, object2) -> object2.compareTo(object1);
public static final Creator<ParcelableStatus> CREATOR = new Creator<ParcelableStatus>() {
@Override
public ParcelableStatus createFromParcel(Parcel source) {

View File

@ -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;
};
}

View File

@ -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<File> NAME_COMPARATOR = new Comparator<File>() {
@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<File> 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) {

View File

@ -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;
}
}

View File

@ -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

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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;

View File

@ -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<I extends IInterface> implements IInte
final Intent intent = new Intent(IntentConstants.INTENT_ACTION_EXTENSION_SHORTEN_STATUS);
final ComponentName component = ComponentName.unflattenFromString(mShortenerName);
intent.setComponent(component);
final FutureTask<Boolean> futureTask = new FutureTask<>(new Callable<Boolean>() {
@Override
public Boolean call() throws Exception {
return mIInterface != null;
}
});
final FutureTask<Boolean> 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<I extends IInterface> implements IInte
}
public interface CheckServiceAction {
@SuppressWarnings("RedundantThrows")
void check(@Nullable Bundle metaData) throws CheckServiceException;
}

View File

@ -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));