From 2c7e36dfce8b91f0b0018d4730d57cca90f5250c Mon Sep 17 00:00:00 2001 From: TacoTheDank Date: Fri, 10 Jul 2020 18:56:58 -0400 Subject: [PATCH] Java 8 migration --- .../transdroid/core/gui/DetailsFragment.java | 109 ++++++++---------- .../core/gui/ServerPickerDialog.java | 11 +- .../transdroid/core/gui/ServerStatusView.java | 5 +- .../transdroid/core/gui/TorrentsActivity.java | 21 +--- .../transdroid/core/gui/TorrentsFragment.java | 16 +-- .../transdroid/core/gui/TransdroidApp.java | 11 +- .../gui/navigation/FilterListAdapter.java | 1 - .../core/gui/navigation/NavigationHelper.java | 19 +-- .../core/gui/navigation/SetLabelDialog.java | 38 ++---- .../navigation/SetStorageLocationDialog.java | 12 +- .../gui/navigation/SetTrackersDialog.java | 11 +- .../navigation/SetTransferRatesDialog.java | 56 ++++----- .../core/gui/rss/RssFeedsActivity.java | 9 +- .../core/gui/rss/RssfeedLoader.java | 9 +- .../core/gui/search/BarcodeHelper.java | 11 +- .../core/gui/search/FilePickerHelper.java | 11 +- .../core/gui/search/SearchActivity.java | 8 +- .../core/gui/search/UrlEntryDialog.java | 29 +++-- .../gui/settings/HelpSettingsActivity.java | 27 ++--- .../settings/KeyBoundPreferencesActivity.java | 9 +- .../gui/settings/MainSettingsActivity.java | 102 +++++----------- .../core/gui/settings/RssfeedPreference.java | 11 +- .../gui/settings/RssfeedSettingsActivity.java | 11 +- .../core/gui/settings/ServerPreference.java | 11 +- .../gui/settings/ServerSettingsActivity.java | 25 ++-- .../gui/settings/SystemSettingsActivity.java | 46 +++----- .../gui/settings/WebsearchPreference.java | 11 +- .../settings/WebsearchSettingsActivity.java | 11 +- .../core/seedbox/SeedboxPreference.java | 13 +-- .../core/service/ConnectivityHelper.java | 10 +- .../core/widget/ListWidgetConfigActivity.java | 7 +- .../adapters/uTorrent/UTorrentAdapter.java | 9 +- .../transdroid/daemon/util/HttpHelper.java | 35 +++--- 33 files changed, 241 insertions(+), 484 deletions(-) diff --git a/app/src/main/java/org/transdroid/core/gui/DetailsFragment.java b/app/src/main/java/org/transdroid/core/gui/DetailsFragment.java index e146086f..19578638 100644 --- a/app/src/main/java/org/transdroid/core/gui/DetailsFragment.java +++ b/app/src/main/java/org/transdroid/core/gui/DetailsFragment.java @@ -121,12 +121,7 @@ public class DetailsFragment extends Fragment implements OnTrackersUpdatedListen // Show contextual action bar to start/stop/remove/etc. torrents in batch mode detailsMenu.setEnabled(false); contextualMenu.setVisibility(View.VISIBLE); - contextualMenu.setOnMenuItemClickListener(new ActionMenuView.OnMenuItemClickListener() { - @Override - public boolean onMenuItemClick(MenuItem menuItem) { - return onActionItemClicked(mode, menuItem); - } - }); + contextualMenu.setOnMenuItemClickListener(menuItem -> onActionItemClicked(mode, menuItem)); contextualMenu.getMenu().clear(); getActivity().getMenuInflater().inflate(R.menu.fragment_details_cab_main, contextualMenu.getMenu()); Context themedContext = ((AppCompatActivity) getActivity()).getSupportActionBar().getThemedContext(); @@ -301,12 +296,9 @@ public class DetailsFragment extends Fragment implements OnTrackersUpdatedListen detailsList.setMultiChoiceModeListener(onDetailsSelected); detailsList.setFastScrollEnabled(true); if (getActivity() != null && getActivity() instanceof RefreshableActivity) { - swipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() { - @Override - public void onRefresh() { - ((RefreshableActivity) getActivity()).refreshScreen(); - swipeRefreshLayout.setRefreshing(false); // Use our custom indicator - } + swipeRefreshLayout.setOnRefreshListener(() -> { + ((RefreshableActivity) getActivity()).refreshScreen(); + swipeRefreshLayout.setRefreshing(false); // Use our custom indicator }); } @@ -454,55 +446,52 @@ public class DetailsFragment extends Fragment implements OnTrackersUpdatedListen public void createMenuOptions() { getActivity().getMenuInflater().inflate(R.menu.fragment_details, detailsMenu.getMenu()); - detailsMenu.setOnMenuItemClickListener(new ActionMenuView.OnMenuItemClickListener() { - @Override - public boolean onMenuItemClick(MenuItem menuItem) { - switch (menuItem.getItemId()) { - case R.id.action_pause: - pauseTorrent(); - return true; - case R.id.action_updatetrackers: - updateTrackers(); - return true; - case R.id.action_start_forced: - startTorrentForced(); - return true; - case R.id.action_remove_withdata: - removeTorrentWithData(); - return true; - case R.id.action_stop: - stopTorrent(); - return true; - case R.id.action_toggle_sequential: - toggleSequentialDownload(menuItem); - return true; - case R.id.action_toggle_firstlastpiece: - toggleFirstLastPieceDownload(menuItem); - return true; - case R.id.action_forcerecheck: - setForceRecheck(); - return true; - case R.id.action_changelocation: - changeStorageLocation(); - return true; - case R.id.action_start_default: - startTorrentDefault(); - return true; - case R.id.action_remove_default: - removeTorrentDefault(); - return true; - case R.id.action_start_direct: - startTorrentDirect(); - return true; - case R.id.action_setlabel: - setLabel(); - return true; - case R.id.action_resume: - resumeTorrent(); - return true; - } - return false; + detailsMenu.setOnMenuItemClickListener(menuItem -> { + switch (menuItem.getItemId()) { + case R.id.action_pause: + pauseTorrent(); + return true; + case R.id.action_updatetrackers: + updateTrackers(); + return true; + case R.id.action_start_forced: + startTorrentForced(); + return true; + case R.id.action_remove_withdata: + removeTorrentWithData(); + return true; + case R.id.action_stop: + stopTorrent(); + return true; + case R.id.action_toggle_sequential: + toggleSequentialDownload(menuItem); + return true; + case R.id.action_toggle_firstlastpiece: + toggleFirstLastPieceDownload(menuItem); + return true; + case R.id.action_forcerecheck: + setForceRecheck(); + return true; + case R.id.action_changelocation: + changeStorageLocation(); + return true; + case R.id.action_start_default: + startTorrentDefault(); + return true; + case R.id.action_remove_default: + removeTorrentDefault(); + return true; + case R.id.action_start_direct: + startTorrentDirect(); + return true; + case R.id.action_setlabel: + setLabel(); + return true; + case R.id.action_resume: + resumeTorrent(); + return true; } + return false; }); } diff --git a/app/src/main/java/org/transdroid/core/gui/ServerPickerDialog.java b/app/src/main/java/org/transdroid/core/gui/ServerPickerDialog.java index 5d6788cb..dd889321 100644 --- a/app/src/main/java/org/transdroid/core/gui/ServerPickerDialog.java +++ b/app/src/main/java/org/transdroid/core/gui/ServerPickerDialog.java @@ -18,8 +18,6 @@ package org.transdroid.core.gui; import android.app.AlertDialog; import android.app.Dialog; -import android.content.DialogInterface; -import android.content.DialogInterface.OnClickListener; import android.os.Bundle; import androidx.fragment.app.DialogFragment; @@ -55,12 +53,9 @@ public class ServerPickerDialog extends DialogFragment { public Dialog onCreateDialog(Bundle savedInstanceState) { String[] serverNames = getArguments().getStringArray("serverNames"); return new AlertDialog.Builder(getActivity()).setTitle(R.string.navigation_pickserver) - .setItems(serverNames, new OnClickListener() { - @Override - public void onClick(DialogInterface dialog, int which) { - if (getActivity() != null && getActivity() instanceof TorrentsActivity) - ((TorrentsActivity) getActivity()).switchServerAndAddFromIntent(which); - } + .setItems(serverNames, (dialog, which) -> { + if (getActivity() != null && getActivity() instanceof TorrentsActivity) + ((TorrentsActivity) getActivity()).switchServerAndAddFromIntent(which); }).create(); } diff --git a/app/src/main/java/org/transdroid/core/gui/ServerStatusView.java b/app/src/main/java/org/transdroid/core/gui/ServerStatusView.java index f98c88ad..3740c288 100644 --- a/app/src/main/java/org/transdroid/core/gui/ServerStatusView.java +++ b/app/src/main/java/org/transdroid/core/gui/ServerStatusView.java @@ -42,11 +42,8 @@ public class ServerStatusView extends RelativeLayout implements OnRatesPickedLis @ViewById protected View speedswrapperLayout; private TorrentsActivity activity; - private OnClickListener onStartDownPickerClicked = new OnClickListener() { - public void onClick(View v) { + private OnClickListener onStartDownPickerClicked = v -> SetTransferRatesDialog.show(getContext(), ServerStatusView.this); - } - }; public ServerStatusView(Context context) { super(context); diff --git a/app/src/main/java/org/transdroid/core/gui/TorrentsActivity.java b/app/src/main/java/org/transdroid/core/gui/TorrentsActivity.java index 5097627d..791eba05 100644 --- a/app/src/main/java/org/transdroid/core/gui/TorrentsActivity.java +++ b/app/src/main/java/org/transdroid/core/gui/TorrentsActivity.java @@ -27,7 +27,6 @@ import android.os.Bundle; import android.view.Menu; import android.view.MenuItem; import android.view.View; -import android.view.View.OnClickListener; import android.view.ViewGroup; import android.widget.AdapterView; import android.widget.AdapterView.OnItemClickListener; @@ -270,13 +269,8 @@ public class TorrentsActivity extends AppCompatActivity implements TorrentTasksE torrentsToolbar.addView(serverSelectionView); } actionsToolbar.addView(serverStatusView); - actionsToolbar.setOnMenuItemClickListener(new Toolbar.OnMenuItemClickListener() { - @Override - public boolean onMenuItemClick(MenuItem menuItem) { - // Redirect to the classic activity implementation so we can use @OptionsItem methods - return onOptionsItemSelected(menuItem); - } - }); + // Redirect to the classic activity implementation so we can use @OptionsItem methods + actionsToolbar.setOnMenuItemClickListener(this::onOptionsItemSelected); setSupportActionBar(torrentsToolbar); // For direct menu item inflation by the contained fragments getSupportActionBar().setDisplayShowTitleEnabled(false); @@ -458,13 +452,10 @@ public class TorrentsActivity extends AppCompatActivity implements TorrentTasksE SearchView searchView = new SearchView(torrentsToolbar.getContext()); searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName())); searchView.setQueryRefinementEnabled(true); - searchView.setOnSearchClickListener(new OnClickListener() { - @Override - public void onClick(View v) { - // Pause autorefresh - stopRefresh = true; - stopAutoRefresh(); - } + searchView.setOnSearchClickListener(v -> { + // Pause autorefresh + stopRefresh = true; + stopAutoRefresh(); }); item.setOnActionExpandListener(new MenuItem.OnActionExpandListener() { @Override diff --git a/app/src/main/java/org/transdroid/core/gui/TorrentsFragment.java b/app/src/main/java/org/transdroid/core/gui/TorrentsFragment.java index 70a3f020..978d10a4 100644 --- a/app/src/main/java/org/transdroid/core/gui/TorrentsFragment.java +++ b/app/src/main/java/org/transdroid/core/gui/TorrentsFragment.java @@ -130,12 +130,7 @@ public class TorrentsFragment extends Fragment implements OnLabelPickedListener actionsToolbar.setEnabled(false); actionsMenu.setVisibility(View.VISIBLE); addmenuButton.setVisibility(View.GONE); - actionsMenu.setOnMenuItemClickListener(new ActionMenuView.OnMenuItemClickListener() { - @Override - public boolean onMenuItemClick(MenuItem menuItem) { - return onActionItemClicked(mode, menuItem); - } - }); + actionsMenu.setOnMenuItemClickListener(menuItem -> onActionItemClicked(mode, menuItem)); actionsMenu.getMenu().clear(); getActivity().getMenuInflater().inflate(R.menu.fragment_torrents_cab, actionsMenu.getMenu()); Context themedContext = ((AppCompatActivity) getActivity()).getSupportActionBar().getThemedContext(); @@ -256,12 +251,9 @@ public class TorrentsFragment extends Fragment implements OnLabelPickedListener } // Allow pulls on the list view to refresh the torrents if (getActivity() != null && getActivity() instanceof RefreshableActivity) { - swipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() { - @Override - public void onRefresh() { - ((RefreshableActivity) getActivity()).refreshScreen(); - swipeRefreshLayout.setRefreshing(false); // Use our custom indicator - } + swipeRefreshLayout.setOnRefreshListener(() -> { + ((RefreshableActivity) getActivity()).refreshScreen(); + swipeRefreshLayout.setRefreshing(false); // Use our custom indicator }); } nosettingsText.setText(getString(R.string.navigation_nosettings, getString(R.string.app_name))); diff --git a/app/src/main/java/org/transdroid/core/gui/TransdroidApp.java b/app/src/main/java/org/transdroid/core/gui/TransdroidApp.java index 3b704954..af0d0c29 100644 --- a/app/src/main/java/org/transdroid/core/gui/TransdroidApp.java +++ b/app/src/main/java/org/transdroid/core/gui/TransdroidApp.java @@ -18,12 +18,8 @@ package org.transdroid.core.gui; import android.app.Application; -import androidx.annotation.NonNull; -import androidx.annotation.Nullable; - import com.evernote.android.job.JobConfig; import com.evernote.android.job.JobManager; -import com.evernote.android.job.util.JobLogger; import org.androidannotations.annotations.Bean; import org.androidannotations.annotations.EApplication; @@ -41,12 +37,7 @@ public class TransdroidApp extends Application { super.onCreate(); // Configure Android-Job - JobConfig.addLogger(new JobLogger() { - @Override - public void log(int priority, @NonNull String tag, @NonNull String message, @Nullable Throwable t) { - log.d(tag, message); - } - }); + JobConfig.addLogger((priority, tag, message, t) -> log.d(tag, message)); JobManager.create(this).addJobCreator(new ScheduledJobCreator()); } diff --git a/app/src/main/java/org/transdroid/core/gui/navigation/FilterListAdapter.java b/app/src/main/java/org/transdroid/core/gui/navigation/FilterListAdapter.java index 6153ea38..22f02b73 100644 --- a/app/src/main/java/org/transdroid/core/gui/navigation/FilterListAdapter.java +++ b/app/src/main/java/org/transdroid/core/gui/navigation/FilterListAdapter.java @@ -24,7 +24,6 @@ import org.androidannotations.annotations.RootContext; import org.transdroid.R; import org.transdroid.core.app.settings.ServerSetting; import org.transdroid.core.gui.lists.MergeAdapter; -import org.transdroid.core.gui.lists.SimpleListItem; import org.transdroid.core.gui.lists.ViewHolderAdapter; import org.transdroid.core.gui.navigation.StatusType.StatusTypeFilter; diff --git a/app/src/main/java/org/transdroid/core/gui/navigation/NavigationHelper.java b/app/src/main/java/org/transdroid/core/gui/navigation/NavigationHelper.java index 0a0d6b2c..a51557de 100644 --- a/app/src/main/java/org/transdroid/core/gui/navigation/NavigationHelper.java +++ b/app/src/main/java/org/transdroid/core/gui/navigation/NavigationHelper.java @@ -30,11 +30,9 @@ import android.text.Spannable; import android.text.SpannableString; import android.text.style.TypefaceSpan; -import androidx.annotation.NonNull; import androidx.core.app.ActivityCompat; import androidx.core.content.ContextCompat; -import com.afollestad.materialdialogs.DialogAction; import com.afollestad.materialdialogs.MaterialDialog; import com.nostra13.universalimageloader.cache.disc.impl.ext.LruDiskCache; import com.nostra13.universalimageloader.cache.disc.naming.Md5FileNameGenerator; @@ -160,17 +158,12 @@ public class NavigationHelper { return true; if (!ActivityCompat.shouldShowRequestPermissionRationale(activity, permission)) { // Never asked again: show a dialog with an explanation - activity.runOnUiThread(new Runnable() { - public void run() { - new MaterialDialog.Builder(context).content(R.string.permission_readtorrent).positiveText(android.R.string.ok) - .onPositive(new MaterialDialog.SingleButtonCallback() { - @Override - public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) { - ActivityCompat.requestPermissions(activity, new String[]{permission}, requestCode); - } - }).show(); - } - }); + activity.runOnUiThread(() -> + new MaterialDialog.Builder(context) + .content(R.string.permission_readtorrent) + .positiveText(android.R.string.ok) + .onPositive((dialog, which) -> + ActivityCompat.requestPermissions(activity, new String[]{permission}, requestCode)).show()); return false; } // Permission not granted (and we asked for it already before) diff --git a/app/src/main/java/org/transdroid/core/gui/navigation/SetLabelDialog.java b/app/src/main/java/org/transdroid/core/gui/navigation/SetLabelDialog.java index db00ce8e..bb12e5ad 100644 --- a/app/src/main/java/org/transdroid/core/gui/navigation/SetLabelDialog.java +++ b/app/src/main/java/org/transdroid/core/gui/navigation/SetLabelDialog.java @@ -20,14 +20,9 @@ import android.content.Context; import android.text.TextUtils; import android.view.LayoutInflater; import android.view.View; -import android.widget.AdapterView; -import android.widget.AdapterView.OnItemClickListener; import android.widget.EditText; import android.widget.ListView; -import androidx.annotation.NonNull; - -import com.afollestad.materialdialogs.DialogAction; import com.afollestad.materialdialogs.MaterialDialog; import com.nispok.snackbar.Snackbar; import com.nispok.snackbar.SnackbarManager; @@ -65,23 +60,17 @@ public class SetLabelDialog { .positiveText(R.string.status_update) .neutralText(R.string.status_label_remove) .negativeText(android.R.string.cancel) - .onPositive(new MaterialDialog.SingleButtonCallback() { - @Override - public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) { - // User should have provided a new label - if (TextUtils.isEmpty(newLabelEdit.getText())) { - SnackbarManager.show(Snackbar.with(context).text(R.string.error_notalabel).colorResource(R.color.red)); - return; - } - onLabelPickedListener.onLabelPicked(newLabelEdit.getText().toString()); + .onPositive((dialog, which) -> { + // User should have provided a new label + if (TextUtils.isEmpty(newLabelEdit.getText())) { + SnackbarManager.show(Snackbar.with(context).text(R.string.error_notalabel).colorResource(R.color.red)); + return; } + onLabelPickedListener.onLabelPicked(newLabelEdit.getText().toString()); }) - .onNeutral(new MaterialDialog.SingleButtonCallback() { - @Override - public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) { - onLabelPickedListener.onLabelPicked(null); - } - }); + .onNeutral((dialog, which) -> + onLabelPickedListener.onLabelPicked(null)); + final MaterialDialog dialog = SettingsUtils .applyDialogTheme(builder) .build(); @@ -92,12 +81,9 @@ public class SetLabelDialog { labelsList.setVisibility(View.GONE); } else { labelsList.setAdapter(new FilterListItemAdapter(context, currentLabels)); - labelsList.setOnItemClickListener(new OnItemClickListener() { - @Override - public void onItemClick(AdapterView parent, View view, int position, long id) { - onLabelPickedListener.onLabelPicked(((Label) labelsList.getItemAtPosition(position)).getName()); - dialog.dismiss(); - } + labelsList.setOnItemClickListener((parent, view, position, id) -> { + onLabelPickedListener.onLabelPicked(((Label) labelsList.getItemAtPosition(position)).getName()); + dialog.dismiss(); }); } diff --git a/app/src/main/java/org/transdroid/core/gui/navigation/SetStorageLocationDialog.java b/app/src/main/java/org/transdroid/core/gui/navigation/SetStorageLocationDialog.java index 3ea6434a..088b83c1 100644 --- a/app/src/main/java/org/transdroid/core/gui/navigation/SetStorageLocationDialog.java +++ b/app/src/main/java/org/transdroid/core/gui/navigation/SetStorageLocationDialog.java @@ -21,9 +21,6 @@ import android.view.LayoutInflater; import android.view.View; import android.widget.EditText; -import androidx.annotation.NonNull; - -import com.afollestad.materialdialogs.DialogAction; import com.afollestad.materialdialogs.MaterialDialog; import org.transdroid.R; @@ -46,12 +43,9 @@ public class SetStorageLocationDialog { .customView(locationLayout, false) .positiveText(R.string.status_update) .negativeText(android.R.string.cancel) - .onPositive(new MaterialDialog.SingleButtonCallback() { - @Override - public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) { - // User is done editing and requested to update given the text input - onStorageLocationUpdatedListener.onStorageLocationUpdated(locationText.getText().toString()); - } + .onPositive((dialog, which) -> { + // User is done editing and requested to update given the text input + onStorageLocationUpdatedListener.onStorageLocationUpdated(locationText.getText().toString()); }); SettingsUtils diff --git a/app/src/main/java/org/transdroid/core/gui/navigation/SetTrackersDialog.java b/app/src/main/java/org/transdroid/core/gui/navigation/SetTrackersDialog.java index 38745ecb..5aa41424 100644 --- a/app/src/main/java/org/transdroid/core/gui/navigation/SetTrackersDialog.java +++ b/app/src/main/java/org/transdroid/core/gui/navigation/SetTrackersDialog.java @@ -21,10 +21,8 @@ import android.view.LayoutInflater; import android.view.View; import android.widget.EditText; -import androidx.annotation.NonNull; import androidx.fragment.app.DialogFragment; -import com.afollestad.materialdialogs.DialogAction; import com.afollestad.materialdialogs.MaterialDialog; import org.transdroid.R; @@ -50,12 +48,9 @@ public class SetTrackersDialog extends DialogFragment { .customView(trackersLayout, false) .positiveText(R.string.status_update) .negativeText(android.R.string.cancel) - .onPositive(new MaterialDialog.SingleButtonCallback() { - @Override - public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) { - // User is done editing and requested to update given the text input - onTrackersUpdatedListener.onTrackersUpdated(Arrays.asList(trackersText.getText().toString().split("\n"))); - } + .onPositive((dialog, which) -> { + // User is done editing and requested to update given the text input + onTrackersUpdatedListener.onTrackersUpdated(Arrays.asList(trackersText.getText().toString().split("\n"))); }); SettingsUtils.applyDialogTheme(builder).show(); } diff --git a/app/src/main/java/org/transdroid/core/gui/navigation/SetTransferRatesDialog.java b/app/src/main/java/org/transdroid/core/gui/navigation/SetTransferRatesDialog.java index 1ed2d839..52e3ee16 100644 --- a/app/src/main/java/org/transdroid/core/gui/navigation/SetTransferRatesDialog.java +++ b/app/src/main/java/org/transdroid/core/gui/navigation/SetTransferRatesDialog.java @@ -23,9 +23,6 @@ import android.view.View.OnClickListener; import android.widget.Button; import android.widget.TextView; -import androidx.annotation.NonNull; - -import com.afollestad.materialdialogs.DialogAction; import com.afollestad.materialdialogs.MaterialDialog; import org.transdroid.R; @@ -33,17 +30,14 @@ import org.transdroid.core.app.settings.SettingsUtils; public class SetTransferRatesDialog { - private static OnClickListener onNumberClicked = new OnClickListener() { - @Override - public void onClick(View v) { - // Append the text contents of the button itself as text to the current number (as reference in the view's - // tag) - TextView numberView = (TextView) v.getTag(); - if (numberView.getText().toString().equals(v.getContext().getString(R.string.status_maxspeed_novalue))) { - numberView.setText(""); - } - numberView.setText(numberView.getText().toString() + ((Button) v).getText().toString()); + private static OnClickListener onNumberClicked = v -> { + // Append the text contents of the button itself as text to the current number (as reference in the view's + // tag) + TextView numberView = (TextView) v.getTag(); + if (numberView.getText().toString().equals(v.getContext().getString(R.string.status_maxspeed_novalue))) { + numberView.setText(""); } + numberView.setText(numberView.getText().toString() + ((Button) v).getText().toString()); }; /** @@ -63,29 +57,23 @@ public class SetTransferRatesDialog { .positiveText(R.string.status_update) .neutralText(R.string.status_maxspeed_reset) .negativeText(android.R.string.cancel) - .onPositive(new MaterialDialog.SingleButtonCallback() { - @Override - public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) { - int maxDown = -1, maxUp = -1; - try { - maxDown = Integer.parseInt(maxSpeedDown.getText().toString()); - maxUp = Integer.parseInt(maxSpeedUp.getText().toString()); - } catch (NumberFormatException e) { - // Impossible as we only input via the number buttons - } - if (maxDown <= 0 || maxUp <= 0) { - onRatesPickedListener.onInvalidNumber(); - return; - } - onRatesPickedListener.onRatesPicked(maxDown, maxUp); + .onPositive((dialog, which) -> { + int maxDown = -1, maxUp = -1; + try { + maxDown = Integer.parseInt(maxSpeedDown.getText().toString()); + maxUp = Integer.parseInt(maxSpeedUp.getText().toString()); + } catch (NumberFormatException e) { + // Impossible as we only input via the number buttons } - }) - .onNeutral(new MaterialDialog.SingleButtonCallback() { - @Override - public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) { - onRatesPickedListener.resetRates(); + if (maxDown <= 0 || maxUp <= 0) { + onRatesPickedListener.onInvalidNumber(); + return; } - }); + onRatesPickedListener.onRatesPicked(maxDown, maxUp); + }) + .onNeutral((dialog, which) -> + onRatesPickedListener.resetRates()); + MaterialDialog dialog = SettingsUtils.applyDialogTheme(builder).build(); bindButtons(dialog.getCustomView(), maxSpeedDown, R.id.down1Button, R.id.down2Button, R.id.down3Button, R.id.down4Button, R.id.down5Button, diff --git a/app/src/main/java/org/transdroid/core/gui/rss/RssFeedsActivity.java b/app/src/main/java/org/transdroid/core/gui/rss/RssFeedsActivity.java index 317cc715..11af9ad5 100644 --- a/app/src/main/java/org/transdroid/core/gui/rss/RssFeedsActivity.java +++ b/app/src/main/java/org/transdroid/core/gui/rss/RssFeedsActivity.java @@ -72,7 +72,6 @@ import org.transdroid.daemon.task.DaemonTaskSuccessResult; import java.util.ArrayList; import java.util.Calendar; import java.util.Collections; -import java.util.Comparator; import java.util.Date; import java.util.List; @@ -301,12 +300,8 @@ public class RssFeedsActivity extends AppCompatActivity { } // Sort by -newest - Collections.sort(recentItems, new Comparator() { - @Override - public int compare(RemoteRssItem lhs, RemoteRssItem rhs) { - return rhs.getTimestamp().compareTo(lhs.getTimestamp()); - } - }); + Collections.sort(recentItems, (lhs, rhs) -> + rhs.getTimestamp().compareTo(lhs.getTimestamp())); } catch (DaemonException e) { onCommunicationError(e); return; diff --git a/app/src/main/java/org/transdroid/core/gui/rss/RssfeedLoader.java b/app/src/main/java/org/transdroid/core/gui/rss/RssfeedLoader.java index d39503da..a1fa8c0f 100644 --- a/app/src/main/java/org/transdroid/core/gui/rss/RssfeedLoader.java +++ b/app/src/main/java/org/transdroid/core/gui/rss/RssfeedLoader.java @@ -21,7 +21,6 @@ import org.transdroid.core.rssparser.Channel; import org.transdroid.core.rssparser.Item; import java.util.Collections; -import java.util.Comparator; import java.util.Date; import java.util.List; @@ -61,12 +60,8 @@ public class RssfeedLoader { // Count the number of new items, based on the date that this RSS feed was last viewed by the user List items = channel.getItems(); // Reverse-order sort the items on their published date - Collections.sort(items, new Comparator() { - @Override - public int compare(Item lhs, Item rhs) { - return -lhs.getPubdate().compareTo(rhs.getPubdate()); - } - }); + Collections.sort(items, (lhs, rhs) -> + -lhs.getPubdate().compareTo(rhs.getPubdate())); for (Item item : items) { if (item.getPubdate() == null || setting.getLastViewed() == null || item.getPubdate().after(setting.getLastViewed())) { newCount++; diff --git a/app/src/main/java/org/transdroid/core/gui/search/BarcodeHelper.java b/app/src/main/java/org/transdroid/core/gui/search/BarcodeHelper.java index 2020db6c..6ff8406d 100644 --- a/app/src/main/java/org/transdroid/core/gui/search/BarcodeHelper.java +++ b/app/src/main/java/org/transdroid/core/gui/search/BarcodeHelper.java @@ -20,8 +20,6 @@ import android.annotation.SuppressLint; import android.app.Activity; import android.app.AlertDialog; import android.content.Context; -import android.content.DialogInterface; -import android.content.DialogInterface.OnClickListener; import android.content.Intent; import android.net.Uri; @@ -76,12 +74,9 @@ public class BarcodeHelper { final WeakReference intentStartContext = new WeakReference<>(activity); new AlertDialog.Builder(activity).setIcon(android.R.drawable.ic_dialog_alert) .setMessage(activity.getString(R.string.search_barcodescannernotfound)) - .setPositiveButton(android.R.string.yes, new OnClickListener() { - @Override - public void onClick(DialogInterface dialog, int which) { - if (intentStartContext.get() != null) - intentStartContext.get().startActivity(new Intent(Intent.ACTION_VIEW, SCANNER_MARKET_URI)); - } + .setPositiveButton(android.R.string.yes, (dialog, which) -> { + if (intentStartContext.get() != null) + intentStartContext.get().startActivity(new Intent(Intent.ACTION_VIEW, SCANNER_MARKET_URI)); }).setNegativeButton(android.R.string.no, null).show(); } } diff --git a/app/src/main/java/org/transdroid/core/gui/search/FilePickerHelper.java b/app/src/main/java/org/transdroid/core/gui/search/FilePickerHelper.java index 22a4408e..8d5471d1 100644 --- a/app/src/main/java/org/transdroid/core/gui/search/FilePickerHelper.java +++ b/app/src/main/java/org/transdroid/core/gui/search/FilePickerHelper.java @@ -20,8 +20,6 @@ import android.annotation.SuppressLint; import android.app.Activity; import android.app.AlertDialog; import android.content.Context; -import android.content.DialogInterface; -import android.content.DialogInterface.OnClickListener; import android.content.Intent; import android.net.Uri; @@ -56,12 +54,9 @@ public class FilePickerHelper { final WeakReference intentStartContext = new WeakReference<>(activity); new AlertDialog.Builder(activity).setIcon(android.R.drawable.ic_dialog_alert) .setMessage(activity.getString(R.string.search_filemanagernotfound)) - .setPositiveButton(android.R.string.yes, new OnClickListener() { - @Override - public void onClick(DialogInterface dialog, int which) { - if (intentStartContext.get() != null) - intentStartContext.get().startActivity(new Intent(Intent.ACTION_VIEW, FILEMANAGER_MARKET_URI)); - } + .setPositiveButton(android.R.string.yes, (dialog, which) -> { + if (intentStartContext.get() != null) + intentStartContext.get().startActivity(new Intent(Intent.ACTION_VIEW, FILEMANAGER_MARKET_URI)); }).setNegativeButton(android.R.string.no, null).show(); } } diff --git a/app/src/main/java/org/transdroid/core/gui/search/SearchActivity.java b/app/src/main/java/org/transdroid/core/gui/search/SearchActivity.java index e93f3b5a..37e3b18a 100644 --- a/app/src/main/java/org/transdroid/core/gui/search/SearchActivity.java +++ b/app/src/main/java/org/transdroid/core/gui/search/SearchActivity.java @@ -116,12 +116,8 @@ public class SearchActivity extends AppCompatActivity { protected void init() { searchToolbar.setNavigationIcon(R.drawable.abc_ic_ab_back_material); - searchToolbar.setNavigationOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - TorrentsActivity_.intent(SearchActivity.this).flags(Intent.FLAG_ACTIVITY_CLEAR_TOP).start(); - } - }); + searchToolbar.setNavigationOnClickListener(v -> + TorrentsActivity_.intent(SearchActivity.this).flags(Intent.FLAG_ACTIVITY_CLEAR_TOP).start()); setSupportActionBar(searchToolbar); // Get the user query, as coming from the standard SearchManager diff --git a/app/src/main/java/org/transdroid/core/gui/search/UrlEntryDialog.java b/app/src/main/java/org/transdroid/core/gui/search/UrlEntryDialog.java index 691d5bf9..4cb329c2 100644 --- a/app/src/main/java/org/transdroid/core/gui/search/UrlEntryDialog.java +++ b/app/src/main/java/org/transdroid/core/gui/search/UrlEntryDialog.java @@ -24,9 +24,6 @@ import android.view.LayoutInflater; import android.view.View; import android.widget.EditText; -import androidx.annotation.NonNull; - -import com.afollestad.materialdialogs.DialogAction; import com.afollestad.materialdialogs.MaterialDialog; import org.transdroid.R; @@ -49,19 +46,19 @@ public class UrlEntryDialog { CharSequence content = clipboard.getPrimaryClip().getItemAt(0).coerceToText(activity); urlEdit.setText(content); } - new MaterialDialog.Builder(activity).customView(inputLayout, false).positiveText(android.R.string.ok).negativeText(android.R.string.cancel) - .onPositive(new MaterialDialog.SingleButtonCallback() { - @Override - public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) { - String url = urlEdit.getText().toString(); - Uri uri = Uri.parse(url); - if (!TextUtils.isEmpty(url)) { - String title = NavigationHelper.extractNameFromUri(uri); - if (uri.getScheme() != null && uri.getScheme().equals("magnet")) { - activity.addTorrentByMagnetUrl(url, title); - } else { - activity.addTorrentByUrl(url, title); - } + new MaterialDialog.Builder(activity) + .customView(inputLayout, false) + .positiveText(android.R.string.ok) + .negativeText(android.R.string.cancel) + .onPositive((dialog, which) -> { + String url = urlEdit.getText().toString(); + Uri uri = Uri.parse(url); + if (!TextUtils.isEmpty(url)) { + String title = NavigationHelper.extractNameFromUri(uri); + if (uri.getScheme() != null && uri.getScheme().equals("magnet")) { + activity.addTorrentByMagnetUrl(url, title); + } else { + activity.addTorrentByUrl(url, title); } } }).show(); diff --git a/app/src/main/java/org/transdroid/core/gui/settings/HelpSettingsActivity.java b/app/src/main/java/org/transdroid/core/gui/settings/HelpSettingsActivity.java index 3013e02d..c4bf2b2f 100644 --- a/app/src/main/java/org/transdroid/core/gui/settings/HelpSettingsActivity.java +++ b/app/src/main/java/org/transdroid/core/gui/settings/HelpSettingsActivity.java @@ -58,26 +58,17 @@ public class HelpSettingsActivity extends PreferenceCompatActivity { return true; } }; - private OnPreferenceClickListener onInstallHelpClick = new OnPreferenceClickListener() { - @Override - public boolean onPreferenceClick(Preference preference) { - startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(INSTALLHELP_URI))); - return true; - } + private OnPreferenceClickListener onInstallHelpClick = preference -> { + startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(INSTALLHELP_URI))); + return true; }; - private OnPreferenceClickListener onChangeLogClick = new OnPreferenceClickListener() { - @Override - public boolean onPreferenceClick(Preference preference) { - showDialog(DIALOG_CHANGELOG); - return true; - } + private OnPreferenceClickListener onChangeLogClick = preference -> { + showDialog(DIALOG_CHANGELOG); + return true; }; - private OnPreferenceClickListener onAboutClick = new OnPreferenceClickListener() { - @Override - public boolean onPreferenceClick(Preference preference) { - showDialog(DIALOG_ABOUT); - return true; - } + private OnPreferenceClickListener onAboutClick = preference -> { + showDialog(DIALOG_ABOUT); + return true; }; @Override diff --git a/app/src/main/java/org/transdroid/core/gui/settings/KeyBoundPreferencesActivity.java b/app/src/main/java/org/transdroid/core/gui/settings/KeyBoundPreferencesActivity.java index 243d104a..d5e52994 100644 --- a/app/src/main/java/org/transdroid/core/gui/settings/KeyBoundPreferencesActivity.java +++ b/app/src/main/java/org/transdroid/core/gui/settings/KeyBoundPreferencesActivity.java @@ -51,12 +51,9 @@ public abstract class KeyBoundPreferencesActivity extends PreferenceCompatActivi private SharedPreferences sharedPrefs; private Map originalSummaries = new HashMap<>(); - private OnSharedPreferenceChangeListener onPreferenceChangeListener = new OnSharedPreferenceChangeListener() { - @Override - public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) { - showValueOnSummary(key); - onPreferencesChanged(); - } + private OnSharedPreferenceChangeListener onPreferenceChangeListener = (sharedPreferences, key) -> { + showValueOnSummary(key); + onPreferencesChanged(); }; /** diff --git a/app/src/main/java/org/transdroid/core/gui/settings/MainSettingsActivity.java b/app/src/main/java/org/transdroid/core/gui/settings/MainSettingsActivity.java index 24fafbce..c5f589f5 100644 --- a/app/src/main/java/org/transdroid/core/gui/settings/MainSettingsActivity.java +++ b/app/src/main/java/org/transdroid/core/gui/settings/MainSettingsActivity.java @@ -19,7 +19,6 @@ package org.transdroid.core.gui.settings; import android.annotation.TargetApi; import android.app.AlertDialog; import android.app.Dialog; -import android.content.DialogInterface; import android.content.DialogInterface.OnClickListener; import android.content.Intent; import android.content.SharedPreferences; @@ -80,83 +79,44 @@ public class MainSettingsActivity extends PreferenceCompatActivity { return true; } }; - private OnPreferenceClickListener onAddWebsearch = new OnPreferenceClickListener() { - @Override - public boolean onPreferenceClick(Preference preference) { - WebsearchSettingsActivity_.intent(MainSettingsActivity.this).start(); - return true; - } + private OnPreferenceClickListener onAddWebsearch = preference -> { + WebsearchSettingsActivity_.intent(MainSettingsActivity.this).start(); + return true; }; - private OnPreferenceClickListener onAddRssfeed = new OnPreferenceClickListener() { - @Override - public boolean onPreferenceClick(Preference preference) { - RssfeedSettingsActivity_.intent(MainSettingsActivity.this).start(); - return true; - } + private OnPreferenceClickListener onAddRssfeed = preference -> { + RssfeedSettingsActivity_.intent(MainSettingsActivity.this).start(); + return true; }; - private OnPreferenceClickListener onBackgroundSettings = new OnPreferenceClickListener() { - @Override - public boolean onPreferenceClick(Preference preference) { - NotificationSettingsActivity_.intent(MainSettingsActivity.this).start(); - return true; - } + private OnPreferenceClickListener onBackgroundSettings = preference -> { + NotificationSettingsActivity_.intent(MainSettingsActivity.this).start(); + return true; }; - private OnPreferenceClickListener onSystemSettings = new OnPreferenceClickListener() { - @Override - public boolean onPreferenceClick(Preference preference) { - SystemSettingsActivity_.intent(MainSettingsActivity.this).start(); - return true; - } + private OnPreferenceClickListener onSystemSettings = preference -> { + SystemSettingsActivity_.intent(MainSettingsActivity.this).start(); + return true; }; - private OnPreferenceClickListener onHelpSettings = new OnPreferenceClickListener() { - @Override - public boolean onPreferenceClick(Preference preference) { - HelpSettingsActivity_.intent(MainSettingsActivity.this).start(); - return true; - } + private OnPreferenceClickListener onHelpSettings = preference -> { + HelpSettingsActivity_.intent(MainSettingsActivity.this).start(); + return true; }; - private OnPreferenceClickListener onDonate = new OnPreferenceClickListener() { - @Override - public boolean onPreferenceClick(Preference preference) { - startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(getString(R.string.donate_url)))); - return true; - } - }; - private OnServerClickedListener onServerClicked = new OnServerClickedListener() { - @Override - public void onServerClicked(ServerSetting serverSetting) { - ServerSettingsActivity_.intent(MainSettingsActivity.this).key(serverSetting.getOrder()).start(); - } + private OnPreferenceClickListener onDonate = preference -> { + startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(getString(R.string.donate_url)))); + return true; }; - private OnSeedboxClickedListener onSeedboxClicked = new OnSeedboxClickedListener() { - @Override - public void onSeedboxClicked(ServerSetting serverSetting, SeedboxProvider provider, int seedboxOffset) { - // NOTE: The seedboxOffset is the seedbox type-unique order that we need to supply uin the Extras bundle to - // edit this specific seedbox - startActivity(provider.getSettings().getSettingsActivityIntent(MainSettingsActivity.this).putExtra("key", seedboxOffset)); - } + private OnServerClickedListener onServerClicked = serverSetting -> ServerSettingsActivity_.intent(MainSettingsActivity.this).key(serverSetting.getOrder()).start(); + private OnSeedboxClickedListener onSeedboxClicked = (serverSetting, provider, seedboxOffset) -> { + // NOTE: The seedboxOffset is the seedbox type-unique order that we need to supply uin the Extras bundle to + // edit this specific seedbox + startActivity(provider.getSettings().getSettingsActivityIntent(MainSettingsActivity.this).putExtra("key", seedboxOffset)); }; - private OnWebsearchClickedListener onWebsearchClicked = new OnWebsearchClickedListener() { - @Override - public void onWebsearchClicked(WebsearchSetting websearchSetting) { - WebsearchSettingsActivity_.intent(MainSettingsActivity.this).key(websearchSetting.getOrder()).start(); - } - }; - private OnRssfeedClickedListener onRssfeedClicked = new OnRssfeedClickedListener() { - @Override - public void onRssfeedClicked(RssfeedSetting rssfeedSetting) { - RssfeedSettingsActivity_.intent(MainSettingsActivity.this).key(rssfeedSetting.getOrder()).start(); - } - }; - private OnClickListener onAddSeedbox = new OnClickListener() { - @Override - public void onClick(DialogInterface dialog, int which) { - // Start the configuration activity for this specific chosen seedbox - if (which == 0) - ServerSettingsActivity_.intent(MainSettingsActivity.this).start(); - else - startActivity(SeedboxProvider.values()[which - 1].getSettings().getSettingsActivityIntent(MainSettingsActivity.this)); - } + private OnWebsearchClickedListener onWebsearchClicked = websearchSetting -> WebsearchSettingsActivity_.intent(MainSettingsActivity.this).key(websearchSetting.getOrder()).start(); + private OnRssfeedClickedListener onRssfeedClicked = rssfeedSetting -> RssfeedSettingsActivity_.intent(MainSettingsActivity.this).key(rssfeedSetting.getOrder()).start(); + private OnClickListener onAddSeedbox = (dialog, which) -> { + // Start the configuration activity for this specific chosen seedbox + if (which == 0) + ServerSettingsActivity_.intent(MainSettingsActivity.this).start(); + else + startActivity(SeedboxProvider.values()[which - 1].getSettings().getSettingsActivityIntent(MainSettingsActivity.this)); }; @Override diff --git a/app/src/main/java/org/transdroid/core/gui/settings/RssfeedPreference.java b/app/src/main/java/org/transdroid/core/gui/settings/RssfeedPreference.java index 9049c021..7b985ad3 100644 --- a/app/src/main/java/org/transdroid/core/gui/settings/RssfeedPreference.java +++ b/app/src/main/java/org/transdroid/core/gui/settings/RssfeedPreference.java @@ -36,13 +36,10 @@ public class RssfeedPreference extends Preference { public RssfeedPreference(Context context) { super(context); - OnPreferenceClickListener onPreferenceClicked = new OnPreferenceClickListener() { - @Override - public boolean onPreferenceClick(Preference preference) { - if (onRssfeedClickedListener != null) - onRssfeedClickedListener.onRssfeedClicked(rssfeedSetting); - return true; - } + OnPreferenceClickListener onPreferenceClicked = preference -> { + if (onRssfeedClickedListener != null) + onRssfeedClickedListener.onRssfeedClicked(rssfeedSetting); + return true; }; setOnPreferenceClickListener(onPreferenceClicked); setIconSpaceReserved(false); diff --git a/app/src/main/java/org/transdroid/core/gui/settings/RssfeedSettingsActivity.java b/app/src/main/java/org/transdroid/core/gui/settings/RssfeedSettingsActivity.java index b58d59a3..3fd5ff5e 100644 --- a/app/src/main/java/org/transdroid/core/gui/settings/RssfeedSettingsActivity.java +++ b/app/src/main/java/org/transdroid/core/gui/settings/RssfeedSettingsActivity.java @@ -19,8 +19,6 @@ package org.transdroid.core.gui.settings; import android.annotation.TargetApi; import android.app.AlertDialog; import android.app.Dialog; -import android.content.DialogInterface; -import android.content.DialogInterface.OnClickListener; import android.content.Intent; import android.os.Build; import android.os.Bundle; @@ -76,12 +74,9 @@ public class RssfeedSettingsActivity extends KeyBoundPreferencesActivity { protected Dialog onCreateDialog(int id) { if (id == DIALOG_CONFIRMREMOVE) { return new AlertDialog.Builder(this).setMessage(R.string.pref_confirmremove) - .setPositiveButton(android.R.string.ok, new OnClickListener() { - @Override - public void onClick(DialogInterface dialog, int which) { - ApplicationSettings_.getInstance_(RssfeedSettingsActivity.this).removeRssfeedSettings(key); - finish(); - } + .setPositiveButton(android.R.string.ok, (dialog, which) -> { + ApplicationSettings_.getInstance_(RssfeedSettingsActivity.this).removeRssfeedSettings(key); + finish(); }).setNegativeButton(android.R.string.cancel, null).create(); } return null; diff --git a/app/src/main/java/org/transdroid/core/gui/settings/ServerPreference.java b/app/src/main/java/org/transdroid/core/gui/settings/ServerPreference.java index 418bdbd9..e5116d96 100644 --- a/app/src/main/java/org/transdroid/core/gui/settings/ServerPreference.java +++ b/app/src/main/java/org/transdroid/core/gui/settings/ServerPreference.java @@ -36,13 +36,10 @@ public class ServerPreference extends Preference { public ServerPreference(Context context) { super(context); - OnPreferenceClickListener onPreferenceClicked = new OnPreferenceClickListener() { - @Override - public boolean onPreferenceClick(Preference preference) { - if (onServerClickedListener != null) - onServerClickedListener.onServerClicked(serverSetting); - return true; - } + OnPreferenceClickListener onPreferenceClicked = preference -> { + if (onServerClickedListener != null) + onServerClickedListener.onServerClicked(serverSetting); + return true; }; setOnPreferenceClickListener(onPreferenceClicked); setIconSpaceReserved(false); diff --git a/app/src/main/java/org/transdroid/core/gui/settings/ServerSettingsActivity.java b/app/src/main/java/org/transdroid/core/gui/settings/ServerSettingsActivity.java index acfddb1c..d774b9f4 100644 --- a/app/src/main/java/org/transdroid/core/gui/settings/ServerSettingsActivity.java +++ b/app/src/main/java/org/transdroid/core/gui/settings/ServerSettingsActivity.java @@ -19,8 +19,6 @@ package org.transdroid.core.gui.settings; import android.annotation.TargetApi; import android.app.AlertDialog; import android.app.Dialog; -import android.content.DialogInterface; -import android.content.DialogInterface.OnClickListener; import android.content.Intent; import android.content.SharedPreferences; import android.os.Build; @@ -28,7 +26,6 @@ import android.os.Bundle; import androidx.annotation.NonNull; import androidx.preference.EditTextPreference; -import androidx.preference.Preference; import androidx.preference.PreferenceManager; import org.androidannotations.annotations.Bean; @@ -89,15 +86,12 @@ public class ServerSettingsActivity extends KeyBoundPreferencesActivity { initTextPreference("server_ssltrustkey", null, "server_sslenabled"); onPreferencesChanged(); - localNetworkPreference.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() { - @Override - public boolean onPreferenceClick(final Preference preference) { - if (!connectivityHelper.hasNetworkNamePermission(ServerSettingsActivity.this)) { - connectivityHelper.askNetworkNamePermission(ServerSettingsActivity.this); - return true; - } - return false; + localNetworkPreference.setOnPreferenceClickListener(preference -> { + if (!connectivityHelper.hasNetworkNamePermission(ServerSettingsActivity.this)) { + connectivityHelper.askNetworkNamePermission(ServerSettingsActivity.this); + return true; } + return false; }); } @@ -116,12 +110,9 @@ public class ServerSettingsActivity extends KeyBoundPreferencesActivity { protected Dialog onCreateDialog(int id) { if (id == DIALOG_CONFIRMREMOVE) { return new AlertDialog.Builder(this).setMessage(R.string.pref_confirmremove) - .setPositiveButton(android.R.string.ok, new OnClickListener() { - @Override - public void onClick(DialogInterface dialog, int which) { - ApplicationSettings_.getInstance_(ServerSettingsActivity.this).removeNormalServerSettings(key); - finish(); - } + .setPositiveButton(android.R.string.ok, (dialog, which) -> { + ApplicationSettings_.getInstance_(ServerSettingsActivity.this).removeNormalServerSettings(key); + finish(); }).setNegativeButton(android.R.string.cancel, null).create(); } return null; diff --git a/app/src/main/java/org/transdroid/core/gui/settings/SystemSettingsActivity.java b/app/src/main/java/org/transdroid/core/gui/settings/SystemSettingsActivity.java index b1109021..059986f8 100644 --- a/app/src/main/java/org/transdroid/core/gui/settings/SystemSettingsActivity.java +++ b/app/src/main/java/org/transdroid/core/gui/settings/SystemSettingsActivity.java @@ -28,7 +28,6 @@ import android.os.Bundle; import android.text.TextUtils; import androidx.annotation.NonNull; -import androidx.preference.Preference; import androidx.preference.Preference.OnPreferenceClickListener; import androidx.preference.PreferenceManager; @@ -69,34 +68,22 @@ public class SystemSettingsActivity extends PreferenceCompatActivity { protected ErrorLogSender errorLogSender; @Bean protected SettingsPersistence settingsPersistence; - private OnPreferenceClickListener onImportSettingsClick = new OnPreferenceClickListener() { - @Override - public boolean onPreferenceClick(Preference preference) { - showDialog(DIALOG_IMPORTSETTINGS); - return true; - } + private OnPreferenceClickListener onImportSettingsClick = preference -> { + showDialog(DIALOG_IMPORTSETTINGS); + return true; }; - private OnPreferenceClickListener onExportSettingsClick = new OnPreferenceClickListener() { - @Override - public boolean onPreferenceClick(Preference preference) { - showDialog(DIALOG_EXPORTSETTINGS); - return true; - } + private OnPreferenceClickListener onExportSettingsClick = preference -> { + showDialog(DIALOG_EXPORTSETTINGS); + return true; }; - private OnPreferenceClickListener onCheckUpdatesClick = new OnPreferenceClickListener() { - @Override - public boolean onPreferenceClick(Preference preference) { - AppUpdateJob.schedule(getApplicationContext()); - return true; - } + private OnPreferenceClickListener onCheckUpdatesClick = preference -> { + AppUpdateJob.schedule(getApplicationContext()); + return true; }; - private OnPreferenceClickListener onClearSearchClick = new OnPreferenceClickListener() { - @Override - public boolean onPreferenceClick(Preference preference) { - SearchHistoryProvider.clearHistory(getApplicationContext()); - SnackbarManager.show(Snackbar.with(SystemSettingsActivity.this).text(R.string.pref_clearsearch_success)); - return true; - } + private OnPreferenceClickListener onClearSearchClick = preference -> { + SearchHistoryProvider.clearHistory(getApplicationContext()); + SnackbarManager.show(Snackbar.with(SystemSettingsActivity.this).text(R.string.pref_clearsearch_success)); + return true; }; private OnClickListener importSettingsFromFile = new OnClickListener() { @Override @@ -108,12 +95,9 @@ public class SystemSettingsActivity extends PreferenceCompatActivity { } }; - private OnClickListener importSettingsFromQr = new OnClickListener() { - @Override - public void onClick(DialogInterface dialog, int which) { + private OnClickListener importSettingsFromQr = (dialog, which) -> BarcodeHelper.startBarcodeScanner(SystemSettingsActivity.this, BarcodeHelper.ACTIVITY_BARCODE_QRSETTINGS); - } - }; + private OnClickListener exportSettingsToFile = new OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { diff --git a/app/src/main/java/org/transdroid/core/gui/settings/WebsearchPreference.java b/app/src/main/java/org/transdroid/core/gui/settings/WebsearchPreference.java index a1ccea1d..cfe9cc02 100644 --- a/app/src/main/java/org/transdroid/core/gui/settings/WebsearchPreference.java +++ b/app/src/main/java/org/transdroid/core/gui/settings/WebsearchPreference.java @@ -36,13 +36,10 @@ public class WebsearchPreference extends Preference { public WebsearchPreference(Context context) { super(context); - OnPreferenceClickListener onPreferenceClicked = new OnPreferenceClickListener() { - @Override - public boolean onPreferenceClick(Preference preference) { - if (onWebsearchClickedListener != null) - onWebsearchClickedListener.onWebsearchClicked(websearchSetting); - return true; - } + OnPreferenceClickListener onPreferenceClicked = preference -> { + if (onWebsearchClickedListener != null) + onWebsearchClickedListener.onWebsearchClicked(websearchSetting); + return true; }; setOnPreferenceClickListener(onPreferenceClicked); setIconSpaceReserved(false); diff --git a/app/src/main/java/org/transdroid/core/gui/settings/WebsearchSettingsActivity.java b/app/src/main/java/org/transdroid/core/gui/settings/WebsearchSettingsActivity.java index 4ddc1f50..3fe73fec 100644 --- a/app/src/main/java/org/transdroid/core/gui/settings/WebsearchSettingsActivity.java +++ b/app/src/main/java/org/transdroid/core/gui/settings/WebsearchSettingsActivity.java @@ -19,8 +19,6 @@ package org.transdroid.core.gui.settings; import android.annotation.TargetApi; import android.app.AlertDialog; import android.app.Dialog; -import android.content.DialogInterface; -import android.content.DialogInterface.OnClickListener; import android.content.Intent; import android.os.Build; import android.os.Bundle; @@ -72,12 +70,9 @@ public class WebsearchSettingsActivity extends KeyBoundPreferencesActivity { protected Dialog onCreateDialog(int id) { if (id == DIALOG_CONFIRMREMOVE) { return new AlertDialog.Builder(this).setMessage(R.string.pref_confirmremove) - .setPositiveButton(android.R.string.ok, new OnClickListener() { - @Override - public void onClick(DialogInterface dialog, int which) { - ApplicationSettings_.getInstance_(WebsearchSettingsActivity.this).removeWebsearchSettings(key); - finish(); - } + .setPositiveButton(android.R.string.ok, (dialog, which) -> { + ApplicationSettings_.getInstance_(WebsearchSettingsActivity.this).removeWebsearchSettings(key); + finish(); }).setNegativeButton(android.R.string.cancel, null).create(); } return null; diff --git a/app/src/main/java/org/transdroid/core/seedbox/SeedboxPreference.java b/app/src/main/java/org/transdroid/core/seedbox/SeedboxPreference.java index bca53a03..7839d6e8 100644 --- a/app/src/main/java/org/transdroid/core/seedbox/SeedboxPreference.java +++ b/app/src/main/java/org/transdroid/core/seedbox/SeedboxPreference.java @@ -18,8 +18,6 @@ package org.transdroid.core.seedbox; import android.content.Context; -import androidx.preference.Preference; - import org.transdroid.core.app.settings.ServerSetting; import org.transdroid.core.gui.settings.ServerPreference; @@ -36,13 +34,10 @@ public class SeedboxPreference extends ServerPreference { public SeedboxPreference(Context context) { super(context); - OnPreferenceClickListener onSeedboxPreferenceClicked = new OnPreferenceClickListener() { - @Override - public boolean onPreferenceClick(Preference preference) { - if (onSeedboxClickedListener != null) - onSeedboxClickedListener.onSeedboxClicked(serverSetting, provider, onSeedboxClickedListenerOffset); - return true; - } + OnPreferenceClickListener onSeedboxPreferenceClicked = preference -> { + if (onSeedboxClickedListener != null) + onSeedboxClickedListener.onSeedboxClicked(serverSetting, provider, onSeedboxClickedListenerOffset); + return true; }; setOnPreferenceClickListener(onSeedboxPreferenceClicked); } diff --git a/app/src/main/java/org/transdroid/core/service/ConnectivityHelper.java b/app/src/main/java/org/transdroid/core/service/ConnectivityHelper.java index 09d9ed8c..d10d0c22 100644 --- a/app/src/main/java/org/transdroid/core/service/ConnectivityHelper.java +++ b/app/src/main/java/org/transdroid/core/service/ConnectivityHelper.java @@ -19,7 +19,6 @@ package org.transdroid.core.service; import android.Manifest; import android.app.Activity; import android.content.Context; -import android.content.DialogInterface; import android.content.pm.PackageManager; import android.net.ConnectivityManager; import android.net.wifi.WifiManager; @@ -66,13 +65,8 @@ public class ConnectivityHelper { .setTitle(R.string.pref_local_permission_title) .setMessage(activity.getString(R.string.pref_local_permission_rationale, activity.getString(R.string.app_name))) - .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialog, int which) { - ActivityCompat.requestPermissions(activity, - new String[]{Manifest.permission.ACCESS_FINE_LOCATION}, REQUEST_LOCATION_PERMISSION); - } - }) + .setPositiveButton(android.R.string.ok, (dialog, which) -> ActivityCompat.requestPermissions(activity, + new String[]{Manifest.permission.ACCESS_FINE_LOCATION}, REQUEST_LOCATION_PERMISSION)) .setNegativeButton(android.R.string.cancel, null) .show(); } diff --git a/app/src/main/java/org/transdroid/core/widget/ListWidgetConfigActivity.java b/app/src/main/java/org/transdroid/core/widget/ListWidgetConfigActivity.java index ef7d619f..995cbe70 100644 --- a/app/src/main/java/org/transdroid/core/widget/ListWidgetConfigActivity.java +++ b/app/src/main/java/org/transdroid/core/widget/ListWidgetConfigActivity.java @@ -100,12 +100,7 @@ public class ListWidgetConfigActivity extends AppCompatActivity { } }; private List previewTorrents = null; - protected OnCheckedChangeListener reverseorderCheckedChanged = new OnCheckedChangeListener() { - @Override - public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { - filterTorrents(); - } - }; + protected OnCheckedChangeListener reverseorderCheckedChanged = (buttonView, isChecked) -> filterTorrents(); private int appWidgetId; private OnClickListener doneClicked = new OnClickListener() { @Override diff --git a/app/src/main/java/org/transdroid/daemon/adapters/uTorrent/UTorrentAdapter.java b/app/src/main/java/org/transdroid/daemon/adapters/uTorrent/UTorrentAdapter.java index e5557864..e6e58f93 100644 --- a/app/src/main/java/org/transdroid/daemon/adapters/uTorrent/UTorrentAdapter.java +++ b/app/src/main/java/org/transdroid/daemon/adapters/uTorrent/UTorrentAdapter.java @@ -74,7 +74,6 @@ import java.net.URI; import java.net.URLEncoder; import java.util.ArrayList; import java.util.Collections; -import java.util.Comparator; import java.util.Date; import java.util.List; @@ -339,12 +338,8 @@ public class UTorrentAdapter implements IDaemonAdapter, RemoteRssSupplier { } } - Collections.sort(remoteRssChannels, new Comparator() { - @Override - public int compare(RemoteRssChannel lhs, RemoteRssChannel rhs) { - return lhs.getName().compareToIgnoreCase(rhs.getName()); - } - }); + Collections.sort(remoteRssChannels, (lhs, rhs) -> + lhs.getName().compareToIgnoreCase(rhs.getName())); } private ArrayList