Browse Source

Java 8 migration

pull/559/head
TacoTheDank 4 years ago
parent
commit
2c7e36dfce
  1. 109
      app/src/main/java/org/transdroid/core/gui/DetailsFragment.java
  2. 11
      app/src/main/java/org/transdroid/core/gui/ServerPickerDialog.java
  3. 5
      app/src/main/java/org/transdroid/core/gui/ServerStatusView.java
  4. 21
      app/src/main/java/org/transdroid/core/gui/TorrentsActivity.java
  5. 16
      app/src/main/java/org/transdroid/core/gui/TorrentsFragment.java
  6. 11
      app/src/main/java/org/transdroid/core/gui/TransdroidApp.java
  7. 1
      app/src/main/java/org/transdroid/core/gui/navigation/FilterListAdapter.java
  8. 19
      app/src/main/java/org/transdroid/core/gui/navigation/NavigationHelper.java
  9. 38
      app/src/main/java/org/transdroid/core/gui/navigation/SetLabelDialog.java
  10. 12
      app/src/main/java/org/transdroid/core/gui/navigation/SetStorageLocationDialog.java
  11. 11
      app/src/main/java/org/transdroid/core/gui/navigation/SetTrackersDialog.java
  12. 56
      app/src/main/java/org/transdroid/core/gui/navigation/SetTransferRatesDialog.java
  13. 9
      app/src/main/java/org/transdroid/core/gui/rss/RssFeedsActivity.java
  14. 9
      app/src/main/java/org/transdroid/core/gui/rss/RssfeedLoader.java
  15. 11
      app/src/main/java/org/transdroid/core/gui/search/BarcodeHelper.java
  16. 11
      app/src/main/java/org/transdroid/core/gui/search/FilePickerHelper.java
  17. 8
      app/src/main/java/org/transdroid/core/gui/search/SearchActivity.java
  18. 29
      app/src/main/java/org/transdroid/core/gui/search/UrlEntryDialog.java
  19. 27
      app/src/main/java/org/transdroid/core/gui/settings/HelpSettingsActivity.java
  20. 9
      app/src/main/java/org/transdroid/core/gui/settings/KeyBoundPreferencesActivity.java
  21. 102
      app/src/main/java/org/transdroid/core/gui/settings/MainSettingsActivity.java
  22. 11
      app/src/main/java/org/transdroid/core/gui/settings/RssfeedPreference.java
  23. 11
      app/src/main/java/org/transdroid/core/gui/settings/RssfeedSettingsActivity.java
  24. 11
      app/src/main/java/org/transdroid/core/gui/settings/ServerPreference.java
  25. 25
      app/src/main/java/org/transdroid/core/gui/settings/ServerSettingsActivity.java
  26. 46
      app/src/main/java/org/transdroid/core/gui/settings/SystemSettingsActivity.java
  27. 11
      app/src/main/java/org/transdroid/core/gui/settings/WebsearchPreference.java
  28. 11
      app/src/main/java/org/transdroid/core/gui/settings/WebsearchSettingsActivity.java
  29. 13
      app/src/main/java/org/transdroid/core/seedbox/SeedboxPreference.java
  30. 10
      app/src/main/java/org/transdroid/core/service/ConnectivityHelper.java
  31. 7
      app/src/main/java/org/transdroid/core/widget/ListWidgetConfigActivity.java
  32. 9
      app/src/main/java/org/transdroid/daemon/adapters/uTorrent/UTorrentAdapter.java
  33. 35
      app/src/main/java/org/transdroid/daemon/util/HttpHelper.java

109
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 // Show contextual action bar to start/stop/remove/etc. torrents in batch mode
detailsMenu.setEnabled(false); detailsMenu.setEnabled(false);
contextualMenu.setVisibility(View.VISIBLE); contextualMenu.setVisibility(View.VISIBLE);
contextualMenu.setOnMenuItemClickListener(new ActionMenuView.OnMenuItemClickListener() { contextualMenu.setOnMenuItemClickListener(menuItem -> onActionItemClicked(mode, menuItem));
@Override
public boolean onMenuItemClick(MenuItem menuItem) {
return onActionItemClicked(mode, menuItem);
}
});
contextualMenu.getMenu().clear(); contextualMenu.getMenu().clear();
getActivity().getMenuInflater().inflate(R.menu.fragment_details_cab_main, contextualMenu.getMenu()); getActivity().getMenuInflater().inflate(R.menu.fragment_details_cab_main, contextualMenu.getMenu());
Context themedContext = ((AppCompatActivity) getActivity()).getSupportActionBar().getThemedContext(); Context themedContext = ((AppCompatActivity) getActivity()).getSupportActionBar().getThemedContext();
@ -301,12 +296,9 @@ public class DetailsFragment extends Fragment implements OnTrackersUpdatedListen
detailsList.setMultiChoiceModeListener(onDetailsSelected); detailsList.setMultiChoiceModeListener(onDetailsSelected);
detailsList.setFastScrollEnabled(true); detailsList.setFastScrollEnabled(true);
if (getActivity() != null && getActivity() instanceof RefreshableActivity) { if (getActivity() != null && getActivity() instanceof RefreshableActivity) {
swipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() { swipeRefreshLayout.setOnRefreshListener(() -> {
@Override ((RefreshableActivity) getActivity()).refreshScreen();
public void onRefresh() { swipeRefreshLayout.setRefreshing(false); // Use our custom indicator
((RefreshableActivity) getActivity()).refreshScreen();
swipeRefreshLayout.setRefreshing(false); // Use our custom indicator
}
}); });
} }
@ -454,55 +446,52 @@ public class DetailsFragment extends Fragment implements OnTrackersUpdatedListen
public void createMenuOptions() { public void createMenuOptions() {
getActivity().getMenuInflater().inflate(R.menu.fragment_details, detailsMenu.getMenu()); getActivity().getMenuInflater().inflate(R.menu.fragment_details, detailsMenu.getMenu());
detailsMenu.setOnMenuItemClickListener(new ActionMenuView.OnMenuItemClickListener() { detailsMenu.setOnMenuItemClickListener(menuItem -> {
@Override switch (menuItem.getItemId()) {
public boolean onMenuItemClick(MenuItem menuItem) { case R.id.action_pause:
switch (menuItem.getItemId()) { pauseTorrent();
case R.id.action_pause: return true;
pauseTorrent(); case R.id.action_updatetrackers:
return true; updateTrackers();
case R.id.action_updatetrackers: return true;
updateTrackers(); case R.id.action_start_forced:
return true; startTorrentForced();
case R.id.action_start_forced: return true;
startTorrentForced(); case R.id.action_remove_withdata:
return true; removeTorrentWithData();
case R.id.action_remove_withdata: return true;
removeTorrentWithData(); case R.id.action_stop:
return true; stopTorrent();
case R.id.action_stop: return true;
stopTorrent(); case R.id.action_toggle_sequential:
return true; toggleSequentialDownload(menuItem);
case R.id.action_toggle_sequential: return true;
toggleSequentialDownload(menuItem); case R.id.action_toggle_firstlastpiece:
return true; toggleFirstLastPieceDownload(menuItem);
case R.id.action_toggle_firstlastpiece: return true;
toggleFirstLastPieceDownload(menuItem); case R.id.action_forcerecheck:
return true; setForceRecheck();
case R.id.action_forcerecheck: return true;
setForceRecheck(); case R.id.action_changelocation:
return true; changeStorageLocation();
case R.id.action_changelocation: return true;
changeStorageLocation(); case R.id.action_start_default:
return true; startTorrentDefault();
case R.id.action_start_default: return true;
startTorrentDefault(); case R.id.action_remove_default:
return true; removeTorrentDefault();
case R.id.action_remove_default: return true;
removeTorrentDefault(); case R.id.action_start_direct:
return true; startTorrentDirect();
case R.id.action_start_direct: return true;
startTorrentDirect(); case R.id.action_setlabel:
return true; setLabel();
case R.id.action_setlabel: return true;
setLabel(); case R.id.action_resume:
return true; resumeTorrent();
case R.id.action_resume: return true;
resumeTorrent();
return true;
}
return false;
} }
return false;
}); });
} }

11
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.AlertDialog;
import android.app.Dialog; import android.app.Dialog;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import android.os.Bundle; import android.os.Bundle;
import androidx.fragment.app.DialogFragment; import androidx.fragment.app.DialogFragment;
@ -55,12 +53,9 @@ public class ServerPickerDialog extends DialogFragment {
public Dialog onCreateDialog(Bundle savedInstanceState) { public Dialog onCreateDialog(Bundle savedInstanceState) {
String[] serverNames = getArguments().getStringArray("serverNames"); String[] serverNames = getArguments().getStringArray("serverNames");
return new AlertDialog.Builder(getActivity()).setTitle(R.string.navigation_pickserver) return new AlertDialog.Builder(getActivity()).setTitle(R.string.navigation_pickserver)
.setItems(serverNames, new OnClickListener() { .setItems(serverNames, (dialog, which) -> {
@Override if (getActivity() != null && getActivity() instanceof TorrentsActivity)
public void onClick(DialogInterface dialog, int which) { ((TorrentsActivity) getActivity()).switchServerAndAddFromIntent(which);
if (getActivity() != null && getActivity() instanceof TorrentsActivity)
((TorrentsActivity) getActivity()).switchServerAndAddFromIntent(which);
}
}).create(); }).create();
} }

5
app/src/main/java/org/transdroid/core/gui/ServerStatusView.java

@ -42,11 +42,8 @@ public class ServerStatusView extends RelativeLayout implements OnRatesPickedLis
@ViewById @ViewById
protected View speedswrapperLayout; protected View speedswrapperLayout;
private TorrentsActivity activity; private TorrentsActivity activity;
private OnClickListener onStartDownPickerClicked = new OnClickListener() { private OnClickListener onStartDownPickerClicked = v ->
public void onClick(View v) {
SetTransferRatesDialog.show(getContext(), ServerStatusView.this); SetTransferRatesDialog.show(getContext(), ServerStatusView.this);
}
};
public ServerStatusView(Context context) { public ServerStatusView(Context context) {
super(context); super(context);

21
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.Menu;
import android.view.MenuItem; import android.view.MenuItem;
import android.view.View; import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.widget.AdapterView; import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener; import android.widget.AdapterView.OnItemClickListener;
@ -270,13 +269,8 @@ public class TorrentsActivity extends AppCompatActivity implements TorrentTasksE
torrentsToolbar.addView(serverSelectionView); torrentsToolbar.addView(serverSelectionView);
} }
actionsToolbar.addView(serverStatusView); actionsToolbar.addView(serverStatusView);
actionsToolbar.setOnMenuItemClickListener(new Toolbar.OnMenuItemClickListener() { // Redirect to the classic activity implementation so we can use @OptionsItem methods
@Override actionsToolbar.setOnMenuItemClickListener(this::onOptionsItemSelected);
public boolean onMenuItemClick(MenuItem menuItem) {
// Redirect to the classic activity implementation so we can use @OptionsItem methods
return onOptionsItemSelected(menuItem);
}
});
setSupportActionBar(torrentsToolbar); // For direct menu item inflation by the contained fragments setSupportActionBar(torrentsToolbar); // For direct menu item inflation by the contained fragments
getSupportActionBar().setDisplayShowTitleEnabled(false); getSupportActionBar().setDisplayShowTitleEnabled(false);
@ -458,13 +452,10 @@ public class TorrentsActivity extends AppCompatActivity implements TorrentTasksE
SearchView searchView = new SearchView(torrentsToolbar.getContext()); SearchView searchView = new SearchView(torrentsToolbar.getContext());
searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName())); searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));
searchView.setQueryRefinementEnabled(true); searchView.setQueryRefinementEnabled(true);
searchView.setOnSearchClickListener(new OnClickListener() { searchView.setOnSearchClickListener(v -> {
@Override // Pause autorefresh
public void onClick(View v) { stopRefresh = true;
// Pause autorefresh stopAutoRefresh();
stopRefresh = true;
stopAutoRefresh();
}
}); });
item.setOnActionExpandListener(new MenuItem.OnActionExpandListener() { item.setOnActionExpandListener(new MenuItem.OnActionExpandListener() {
@Override @Override

16
app/src/main/java/org/transdroid/core/gui/TorrentsFragment.java

@ -130,12 +130,7 @@ public class TorrentsFragment extends Fragment implements OnLabelPickedListener
actionsToolbar.setEnabled(false); actionsToolbar.setEnabled(false);
actionsMenu.setVisibility(View.VISIBLE); actionsMenu.setVisibility(View.VISIBLE);
addmenuButton.setVisibility(View.GONE); addmenuButton.setVisibility(View.GONE);
actionsMenu.setOnMenuItemClickListener(new ActionMenuView.OnMenuItemClickListener() { actionsMenu.setOnMenuItemClickListener(menuItem -> onActionItemClicked(mode, menuItem));
@Override
public boolean onMenuItemClick(MenuItem menuItem) {
return onActionItemClicked(mode, menuItem);
}
});
actionsMenu.getMenu().clear(); actionsMenu.getMenu().clear();
getActivity().getMenuInflater().inflate(R.menu.fragment_torrents_cab, actionsMenu.getMenu()); getActivity().getMenuInflater().inflate(R.menu.fragment_torrents_cab, actionsMenu.getMenu());
Context themedContext = ((AppCompatActivity) getActivity()).getSupportActionBar().getThemedContext(); 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 // Allow pulls on the list view to refresh the torrents
if (getActivity() != null && getActivity() instanceof RefreshableActivity) { if (getActivity() != null && getActivity() instanceof RefreshableActivity) {
swipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() { swipeRefreshLayout.setOnRefreshListener(() -> {
@Override ((RefreshableActivity) getActivity()).refreshScreen();
public void onRefresh() { swipeRefreshLayout.setRefreshing(false); // Use our custom indicator
((RefreshableActivity) getActivity()).refreshScreen();
swipeRefreshLayout.setRefreshing(false); // Use our custom indicator
}
}); });
} }
nosettingsText.setText(getString(R.string.navigation_nosettings, getString(R.string.app_name))); nosettingsText.setText(getString(R.string.navigation_nosettings, getString(R.string.app_name)));

11
app/src/main/java/org/transdroid/core/gui/TransdroidApp.java

@ -18,12 +18,8 @@ package org.transdroid.core.gui;
import android.app.Application; import android.app.Application;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import com.evernote.android.job.JobConfig; import com.evernote.android.job.JobConfig;
import com.evernote.android.job.JobManager; import com.evernote.android.job.JobManager;
import com.evernote.android.job.util.JobLogger;
import org.androidannotations.annotations.Bean; import org.androidannotations.annotations.Bean;
import org.androidannotations.annotations.EApplication; import org.androidannotations.annotations.EApplication;
@ -41,12 +37,7 @@ public class TransdroidApp extends Application {
super.onCreate(); super.onCreate();
// Configure Android-Job // Configure Android-Job
JobConfig.addLogger(new JobLogger() { JobConfig.addLogger((priority, tag, message, t) -> log.d(tag, message));
@Override
public void log(int priority, @NonNull String tag, @NonNull String message, @Nullable Throwable t) {
log.d(tag, message);
}
});
JobManager.create(this).addJobCreator(new ScheduledJobCreator()); JobManager.create(this).addJobCreator(new ScheduledJobCreator());
} }

1
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.R;
import org.transdroid.core.app.settings.ServerSetting; import org.transdroid.core.app.settings.ServerSetting;
import org.transdroid.core.gui.lists.MergeAdapter; 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.lists.ViewHolderAdapter;
import org.transdroid.core.gui.navigation.StatusType.StatusTypeFilter; import org.transdroid.core.gui.navigation.StatusType.StatusTypeFilter;

19
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.SpannableString;
import android.text.style.TypefaceSpan; import android.text.style.TypefaceSpan;
import androidx.annotation.NonNull;
import androidx.core.app.ActivityCompat; import androidx.core.app.ActivityCompat;
import androidx.core.content.ContextCompat; import androidx.core.content.ContextCompat;
import com.afollestad.materialdialogs.DialogAction;
import com.afollestad.materialdialogs.MaterialDialog; import com.afollestad.materialdialogs.MaterialDialog;
import com.nostra13.universalimageloader.cache.disc.impl.ext.LruDiskCache; import com.nostra13.universalimageloader.cache.disc.impl.ext.LruDiskCache;
import com.nostra13.universalimageloader.cache.disc.naming.Md5FileNameGenerator; import com.nostra13.universalimageloader.cache.disc.naming.Md5FileNameGenerator;
@ -160,17 +158,12 @@ public class NavigationHelper {
return true; return true;
if (!ActivityCompat.shouldShowRequestPermissionRationale(activity, permission)) { if (!ActivityCompat.shouldShowRequestPermissionRationale(activity, permission)) {
// Never asked again: show a dialog with an explanation // Never asked again: show a dialog with an explanation
activity.runOnUiThread(new Runnable() { activity.runOnUiThread(() ->
public void run() { new MaterialDialog.Builder(context)
new MaterialDialog.Builder(context).content(R.string.permission_readtorrent).positiveText(android.R.string.ok) .content(R.string.permission_readtorrent)
.onPositive(new MaterialDialog.SingleButtonCallback() { .positiveText(android.R.string.ok)
@Override .onPositive((dialog, which) ->
public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) { ActivityCompat.requestPermissions(activity, new String[]{permission}, requestCode)).show());
ActivityCompat.requestPermissions(activity, new String[]{permission}, requestCode);
}
}).show();
}
});
return false; return false;
} }
// Permission not granted (and we asked for it already before) // Permission not granted (and we asked for it already before)

38
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.text.TextUtils;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.EditText; import android.widget.EditText;
import android.widget.ListView; import android.widget.ListView;
import androidx.annotation.NonNull;
import com.afollestad.materialdialogs.DialogAction;
import com.afollestad.materialdialogs.MaterialDialog; import com.afollestad.materialdialogs.MaterialDialog;
import com.nispok.snackbar.Snackbar; import com.nispok.snackbar.Snackbar;
import com.nispok.snackbar.SnackbarManager; import com.nispok.snackbar.SnackbarManager;
@ -65,23 +60,17 @@ public class SetLabelDialog {
.positiveText(R.string.status_update) .positiveText(R.string.status_update)
.neutralText(R.string.status_label_remove) .neutralText(R.string.status_label_remove)
.negativeText(android.R.string.cancel) .negativeText(android.R.string.cancel)
.onPositive(new MaterialDialog.SingleButtonCallback() { .onPositive((dialog, which) -> {
@Override // User should have provided a new label
public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) { if (TextUtils.isEmpty(newLabelEdit.getText())) {
// User should have provided a new label SnackbarManager.show(Snackbar.with(context).text(R.string.error_notalabel).colorResource(R.color.red));
if (TextUtils.isEmpty(newLabelEdit.getText())) { return;
SnackbarManager.show(Snackbar.with(context).text(R.string.error_notalabel).colorResource(R.color.red));
return;
}
onLabelPickedListener.onLabelPicked(newLabelEdit.getText().toString());
} }
onLabelPickedListener.onLabelPicked(newLabelEdit.getText().toString());
}) })
.onNeutral(new MaterialDialog.SingleButtonCallback() { .onNeutral((dialog, which) ->
@Override onLabelPickedListener.onLabelPicked(null));
public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
onLabelPickedListener.onLabelPicked(null);
}
});
final MaterialDialog dialog = SettingsUtils final MaterialDialog dialog = SettingsUtils
.applyDialogTheme(builder) .applyDialogTheme(builder)
.build(); .build();
@ -92,12 +81,9 @@ public class SetLabelDialog {
labelsList.setVisibility(View.GONE); labelsList.setVisibility(View.GONE);
} else { } else {
labelsList.setAdapter(new FilterListItemAdapter(context, currentLabels)); labelsList.setAdapter(new FilterListItemAdapter(context, currentLabels));
labelsList.setOnItemClickListener(new OnItemClickListener() { labelsList.setOnItemClickListener((parent, view, position, id) -> {
@Override onLabelPickedListener.onLabelPicked(((Label) labelsList.getItemAtPosition(position)).getName());
public void onItemClick(AdapterView<?> parent, View view, int position, long id) { dialog.dismiss();
onLabelPickedListener.onLabelPicked(((Label) labelsList.getItemAtPosition(position)).getName());
dialog.dismiss();
}
}); });
} }

12
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.view.View;
import android.widget.EditText; import android.widget.EditText;
import androidx.annotation.NonNull;
import com.afollestad.materialdialogs.DialogAction;
import com.afollestad.materialdialogs.MaterialDialog; import com.afollestad.materialdialogs.MaterialDialog;
import org.transdroid.R; import org.transdroid.R;
@ -46,12 +43,9 @@ public class SetStorageLocationDialog {
.customView(locationLayout, false) .customView(locationLayout, false)
.positiveText(R.string.status_update) .positiveText(R.string.status_update)
.negativeText(android.R.string.cancel) .negativeText(android.R.string.cancel)
.onPositive(new MaterialDialog.SingleButtonCallback() { .onPositive((dialog, which) -> {
@Override // User is done editing and requested to update given the text input
public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) { onStorageLocationUpdatedListener.onStorageLocationUpdated(locationText.getText().toString());
// User is done editing and requested to update given the text input
onStorageLocationUpdatedListener.onStorageLocationUpdated(locationText.getText().toString());
}
}); });
SettingsUtils SettingsUtils

11
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.view.View;
import android.widget.EditText; import android.widget.EditText;
import androidx.annotation.NonNull;
import androidx.fragment.app.DialogFragment; import androidx.fragment.app.DialogFragment;
import com.afollestad.materialdialogs.DialogAction;
import com.afollestad.materialdialogs.MaterialDialog; import com.afollestad.materialdialogs.MaterialDialog;
import org.transdroid.R; import org.transdroid.R;
@ -50,12 +48,9 @@ public class SetTrackersDialog extends DialogFragment {
.customView(trackersLayout, false) .customView(trackersLayout, false)
.positiveText(R.string.status_update) .positiveText(R.string.status_update)
.negativeText(android.R.string.cancel) .negativeText(android.R.string.cancel)
.onPositive(new MaterialDialog.SingleButtonCallback() { .onPositive((dialog, which) -> {
@Override // User is done editing and requested to update given the text input
public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) { onTrackersUpdatedListener.onTrackersUpdated(Arrays.asList(trackersText.getText().toString().split("\n")));
// 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(); SettingsUtils.applyDialogTheme(builder).show();
} }

56
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.Button;
import android.widget.TextView; import android.widget.TextView;
import androidx.annotation.NonNull;
import com.afollestad.materialdialogs.DialogAction;
import com.afollestad.materialdialogs.MaterialDialog; import com.afollestad.materialdialogs.MaterialDialog;
import org.transdroid.R; import org.transdroid.R;
@ -33,17 +30,14 @@ import org.transdroid.core.app.settings.SettingsUtils;
public class SetTransferRatesDialog { public class SetTransferRatesDialog {
private static OnClickListener onNumberClicked = new OnClickListener() { private static OnClickListener onNumberClicked = v -> {
@Override // Append the text contents of the button itself as text to the current number (as reference in the view's
public void onClick(View v) { // tag)
// Append the text contents of the button itself as text to the current number (as reference in the view's TextView numberView = (TextView) v.getTag();
// tag) if (numberView.getText().toString().equals(v.getContext().getString(R.string.status_maxspeed_novalue))) {
TextView numberView = (TextView) v.getTag(); numberView.setText("");
if (numberView.getText().toString().equals(v.getContext().getString(R.string.status_maxspeed_novalue))) {
numberView.setText("");
}
numberView.setText(numberView.getText().toString() + ((Button) v).getText().toString());
} }
numberView.setText(numberView.getText().toString() + ((Button) v).getText().toString());
}; };
/** /**
@ -63,29 +57,23 @@ public class SetTransferRatesDialog {
.positiveText(R.string.status_update) .positiveText(R.string.status_update)
.neutralText(R.string.status_maxspeed_reset) .neutralText(R.string.status_maxspeed_reset)
.negativeText(android.R.string.cancel) .negativeText(android.R.string.cancel)
.onPositive(new MaterialDialog.SingleButtonCallback() { .onPositive((dialog, which) -> {
@Override int maxDown = -1, maxUp = -1;
public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) { try {
int maxDown = -1, maxUp = -1; maxDown = Integer.parseInt(maxSpeedDown.getText().toString());
try { maxUp = Integer.parseInt(maxSpeedUp.getText().toString());
maxDown = Integer.parseInt(maxSpeedDown.getText().toString()); } catch (NumberFormatException e) {
maxUp = Integer.parseInt(maxSpeedUp.getText().toString()); // Impossible as we only input via the number buttons
} catch (NumberFormatException e) {
// Impossible as we only input via the number buttons
}
if (maxDown <= 0 || maxUp <= 0) {
onRatesPickedListener.onInvalidNumber();
return;
}
onRatesPickedListener.onRatesPicked(maxDown, maxUp);
} }
}) if (maxDown <= 0 || maxUp <= 0) {
.onNeutral(new MaterialDialog.SingleButtonCallback() { onRatesPickedListener.onInvalidNumber();
@Override return;
public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
onRatesPickedListener.resetRates();
} }
}); onRatesPickedListener.onRatesPicked(maxDown, maxUp);
})
.onNeutral((dialog, which) ->
onRatesPickedListener.resetRates());
MaterialDialog dialog = SettingsUtils.applyDialogTheme(builder).build(); 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, bindButtons(dialog.getCustomView(), maxSpeedDown, R.id.down1Button, R.id.down2Button, R.id.down3Button, R.id.down4Button, R.id.down5Button,

9
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.ArrayList;
import java.util.Calendar; import java.util.Calendar;
import java.util.Collections; import java.util.Collections;
import java.util.Comparator;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
@ -301,12 +300,8 @@ public class RssFeedsActivity extends AppCompatActivity {
} }
// Sort by -newest // Sort by -newest
Collections.sort(recentItems, new Comparator<RemoteRssItem>() { Collections.sort(recentItems, (lhs, rhs) ->
@Override rhs.getTimestamp().compareTo(lhs.getTimestamp()));
public int compare(RemoteRssItem lhs, RemoteRssItem rhs) {
return rhs.getTimestamp().compareTo(lhs.getTimestamp());
}
});
} catch (DaemonException e) { } catch (DaemonException e) {
onCommunicationError(e); onCommunicationError(e);
return; return;

9
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 org.transdroid.core.rssparser.Item;
import java.util.Collections; import java.util.Collections;
import java.util.Comparator;
import java.util.Date; import java.util.Date;
import java.util.List; 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 // Count the number of new items, based on the date that this RSS feed was last viewed by the user
List<Item> items = channel.getItems(); List<Item> items = channel.getItems();
// Reverse-order sort the items on their published date // Reverse-order sort the items on their published date
Collections.sort(items, new Comparator<Item>() { Collections.sort(items, (lhs, rhs) ->
@Override -lhs.getPubdate().compareTo(rhs.getPubdate()));
public int compare(Item lhs, Item rhs) {
return -lhs.getPubdate().compareTo(rhs.getPubdate());
}
});
for (Item item : items) { for (Item item : items) {
if (item.getPubdate() == null || setting.getLastViewed() == null || item.getPubdate().after(setting.getLastViewed())) { if (item.getPubdate() == null || setting.getLastViewed() == null || item.getPubdate().after(setting.getLastViewed())) {
newCount++; newCount++;

11
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.Activity;
import android.app.AlertDialog; import android.app.AlertDialog;
import android.content.Context; import android.content.Context;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import android.content.Intent; import android.content.Intent;
import android.net.Uri; import android.net.Uri;
@ -76,12 +74,9 @@ public class BarcodeHelper {
final WeakReference<Context> intentStartContext = new WeakReference<>(activity); final WeakReference<Context> intentStartContext = new WeakReference<>(activity);
new AlertDialog.Builder(activity).setIcon(android.R.drawable.ic_dialog_alert) new AlertDialog.Builder(activity).setIcon(android.R.drawable.ic_dialog_alert)
.setMessage(activity.getString(R.string.search_barcodescannernotfound)) .setMessage(activity.getString(R.string.search_barcodescannernotfound))
.setPositiveButton(android.R.string.yes, new OnClickListener() { .setPositiveButton(android.R.string.yes, (dialog, which) -> {
@Override if (intentStartContext.get() != null)
public void onClick(DialogInterface dialog, int which) { intentStartContext.get().startActivity(new Intent(Intent.ACTION_VIEW, SCANNER_MARKET_URI));
if (intentStartContext.get() != null)
intentStartContext.get().startActivity(new Intent(Intent.ACTION_VIEW, SCANNER_MARKET_URI));
}
}).setNegativeButton(android.R.string.no, null).show(); }).setNegativeButton(android.R.string.no, null).show();
} }
} }

11
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.Activity;
import android.app.AlertDialog; import android.app.AlertDialog;
import android.content.Context; import android.content.Context;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import android.content.Intent; import android.content.Intent;
import android.net.Uri; import android.net.Uri;
@ -56,12 +54,9 @@ public class FilePickerHelper {
final WeakReference<Context> intentStartContext = new WeakReference<>(activity); final WeakReference<Context> intentStartContext = new WeakReference<>(activity);
new AlertDialog.Builder(activity).setIcon(android.R.drawable.ic_dialog_alert) new AlertDialog.Builder(activity).setIcon(android.R.drawable.ic_dialog_alert)
.setMessage(activity.getString(R.string.search_filemanagernotfound)) .setMessage(activity.getString(R.string.search_filemanagernotfound))
.setPositiveButton(android.R.string.yes, new OnClickListener() { .setPositiveButton(android.R.string.yes, (dialog, which) -> {
@Override if (intentStartContext.get() != null)
public void onClick(DialogInterface dialog, int which) { intentStartContext.get().startActivity(new Intent(Intent.ACTION_VIEW, FILEMANAGER_MARKET_URI));
if (intentStartContext.get() != null)
intentStartContext.get().startActivity(new Intent(Intent.ACTION_VIEW, FILEMANAGER_MARKET_URI));
}
}).setNegativeButton(android.R.string.no, null).show(); }).setNegativeButton(android.R.string.no, null).show();
} }
} }

8
app/src/main/java/org/transdroid/core/gui/search/SearchActivity.java

@ -116,12 +116,8 @@ public class SearchActivity extends AppCompatActivity {
protected void init() { protected void init() {
searchToolbar.setNavigationIcon(R.drawable.abc_ic_ab_back_material); searchToolbar.setNavigationIcon(R.drawable.abc_ic_ab_back_material);
searchToolbar.setNavigationOnClickListener(new View.OnClickListener() { searchToolbar.setNavigationOnClickListener(v ->
@Override TorrentsActivity_.intent(SearchActivity.this).flags(Intent.FLAG_ACTIVITY_CLEAR_TOP).start());
public void onClick(View v) {
TorrentsActivity_.intent(SearchActivity.this).flags(Intent.FLAG_ACTIVITY_CLEAR_TOP).start();
}
});
setSupportActionBar(searchToolbar); setSupportActionBar(searchToolbar);
// Get the user query, as coming from the standard SearchManager // Get the user query, as coming from the standard SearchManager

29
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.view.View;
import android.widget.EditText; import android.widget.EditText;
import androidx.annotation.NonNull;
import com.afollestad.materialdialogs.DialogAction;
import com.afollestad.materialdialogs.MaterialDialog; import com.afollestad.materialdialogs.MaterialDialog;
import org.transdroid.R; import org.transdroid.R;
@ -49,19 +46,19 @@ public class UrlEntryDialog {
CharSequence content = clipboard.getPrimaryClip().getItemAt(0).coerceToText(activity); CharSequence content = clipboard.getPrimaryClip().getItemAt(0).coerceToText(activity);
urlEdit.setText(content); urlEdit.setText(content);
} }
new MaterialDialog.Builder(activity).customView(inputLayout, false).positiveText(android.R.string.ok).negativeText(android.R.string.cancel) new MaterialDialog.Builder(activity)
.onPositive(new MaterialDialog.SingleButtonCallback() { .customView(inputLayout, false)
@Override .positiveText(android.R.string.ok)
public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) { .negativeText(android.R.string.cancel)
String url = urlEdit.getText().toString(); .onPositive((dialog, which) -> {
Uri uri = Uri.parse(url); String url = urlEdit.getText().toString();
if (!TextUtils.isEmpty(url)) { Uri uri = Uri.parse(url);
String title = NavigationHelper.extractNameFromUri(uri); if (!TextUtils.isEmpty(url)) {
if (uri.getScheme() != null && uri.getScheme().equals("magnet")) { String title = NavigationHelper.extractNameFromUri(uri);
activity.addTorrentByMagnetUrl(url, title); if (uri.getScheme() != null && uri.getScheme().equals("magnet")) {
} else { activity.addTorrentByMagnetUrl(url, title);
activity.addTorrentByUrl(url, title); } else {
} activity.addTorrentByUrl(url, title);
} }
} }
}).show(); }).show();

27
app/src/main/java/org/transdroid/core/gui/settings/HelpSettingsActivity.java

@ -58,26 +58,17 @@ public class HelpSettingsActivity extends PreferenceCompatActivity {
return true; return true;
} }
}; };
private OnPreferenceClickListener onInstallHelpClick = new OnPreferenceClickListener() { private OnPreferenceClickListener onInstallHelpClick = preference -> {
@Override startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(INSTALLHELP_URI)));
public boolean onPreferenceClick(Preference preference) { return true;
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(INSTALLHELP_URI)));
return true;
}
}; };
private OnPreferenceClickListener onChangeLogClick = new OnPreferenceClickListener() { private OnPreferenceClickListener onChangeLogClick = preference -> {
@Override showDialog(DIALOG_CHANGELOG);
public boolean onPreferenceClick(Preference preference) { return true;
showDialog(DIALOG_CHANGELOG);
return true;
}
}; };
private OnPreferenceClickListener onAboutClick = new OnPreferenceClickListener() { private OnPreferenceClickListener onAboutClick = preference -> {
@Override showDialog(DIALOG_ABOUT);
public boolean onPreferenceClick(Preference preference) { return true;
showDialog(DIALOG_ABOUT);
return true;
}
}; };
@Override @Override

9
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 SharedPreferences sharedPrefs;
private Map<String, String> originalSummaries = new HashMap<>(); private Map<String, String> originalSummaries = new HashMap<>();
private OnSharedPreferenceChangeListener onPreferenceChangeListener = new OnSharedPreferenceChangeListener() { private OnSharedPreferenceChangeListener onPreferenceChangeListener = (sharedPreferences, key) -> {
@Override showValueOnSummary(key);
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) { onPreferencesChanged();
showValueOnSummary(key);
onPreferencesChanged();
}
}; };
/** /**

102
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.annotation.TargetApi;
import android.app.AlertDialog; import android.app.AlertDialog;
import android.app.Dialog; import android.app.Dialog;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener; import android.content.DialogInterface.OnClickListener;
import android.content.Intent; import android.content.Intent;
import android.content.SharedPreferences; import android.content.SharedPreferences;
@ -80,83 +79,44 @@ public class MainSettingsActivity extends PreferenceCompatActivity {
return true; return true;
} }
}; };
private OnPreferenceClickListener onAddWebsearch = new OnPreferenceClickListener() { private OnPreferenceClickListener onAddWebsearch = preference -> {
@Override WebsearchSettingsActivity_.intent(MainSettingsActivity.this).start();
public boolean onPreferenceClick(Preference preference) { return true;
WebsearchSettingsActivity_.intent(MainSettingsActivity.this).start();
return true;
}
}; };
private OnPreferenceClickListener onAddRssfeed = new OnPreferenceClickListener() { private OnPreferenceClickListener onAddRssfeed = preference -> {
@Override RssfeedSettingsActivity_.intent(MainSettingsActivity.this).start();
public boolean onPreferenceClick(Preference preference) { return true;
RssfeedSettingsActivity_.intent(MainSettingsActivity.this).start();
return true;
}
}; };
private OnPreferenceClickListener onBackgroundSettings = new OnPreferenceClickListener() { private OnPreferenceClickListener onBackgroundSettings = preference -> {
@Override NotificationSettingsActivity_.intent(MainSettingsActivity.this).start();
public boolean onPreferenceClick(Preference preference) { return true;
NotificationSettingsActivity_.intent(MainSettingsActivity.this).start();
return true;
}
}; };
private OnPreferenceClickListener onSystemSettings = new OnPreferenceClickListener() { private OnPreferenceClickListener onSystemSettings = preference -> {
@Override SystemSettingsActivity_.intent(MainSettingsActivity.this).start();
public boolean onPreferenceClick(Preference preference) { return true;
SystemSettingsActivity_.intent(MainSettingsActivity.this).start();
return true;
}
}; };
private OnPreferenceClickListener onHelpSettings = new OnPreferenceClickListener() { private OnPreferenceClickListener onHelpSettings = preference -> {
@Override HelpSettingsActivity_.intent(MainSettingsActivity.this).start();
public boolean onPreferenceClick(Preference preference) { return true;
HelpSettingsActivity_.intent(MainSettingsActivity.this).start();
return true;
}
}; };
private OnPreferenceClickListener onDonate = new OnPreferenceClickListener() { private OnPreferenceClickListener onDonate = preference -> {
@Override startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(getString(R.string.donate_url))));
public boolean onPreferenceClick(Preference preference) { return true;
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 OnSeedboxClickedListener onSeedboxClicked = new OnSeedboxClickedListener() { private OnServerClickedListener onServerClicked = serverSetting -> ServerSettingsActivity_.intent(MainSettingsActivity.this).key(serverSetting.getOrder()).start();
@Override private OnSeedboxClickedListener onSeedboxClicked = (serverSetting, provider, seedboxOffset) -> {
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
// NOTE: The seedboxOffset is the seedbox type-unique order that we need to supply uin the Extras bundle to // edit this specific seedbox
// edit this specific seedbox startActivity(provider.getSettings().getSettingsActivityIntent(MainSettingsActivity.this).putExtra("key", seedboxOffset));
startActivity(provider.getSettings().getSettingsActivityIntent(MainSettingsActivity.this).putExtra("key", seedboxOffset));
}
}; };
private OnWebsearchClickedListener onWebsearchClicked = new OnWebsearchClickedListener() { private OnWebsearchClickedListener onWebsearchClicked = websearchSetting -> WebsearchSettingsActivity_.intent(MainSettingsActivity.this).key(websearchSetting.getOrder()).start();
@Override private OnRssfeedClickedListener onRssfeedClicked = rssfeedSetting -> RssfeedSettingsActivity_.intent(MainSettingsActivity.this).key(rssfeedSetting.getOrder()).start();
public void onWebsearchClicked(WebsearchSetting websearchSetting) { private OnClickListener onAddSeedbox = (dialog, which) -> {
WebsearchSettingsActivity_.intent(MainSettingsActivity.this).key(websearchSetting.getOrder()).start(); // Start the configuration activity for this specific chosen seedbox
} if (which == 0)
}; ServerSettingsActivity_.intent(MainSettingsActivity.this).start();
private OnRssfeedClickedListener onRssfeedClicked = new OnRssfeedClickedListener() { else
@Override startActivity(SeedboxProvider.values()[which - 1].getSettings().getSettingsActivityIntent(MainSettingsActivity.this));
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));
}
}; };
@Override @Override

11
app/src/main/java/org/transdroid/core/gui/settings/RssfeedPreference.java

@ -36,13 +36,10 @@ public class RssfeedPreference extends Preference {
public RssfeedPreference(Context context) { public RssfeedPreference(Context context) {
super(context); super(context);
OnPreferenceClickListener onPreferenceClicked = new OnPreferenceClickListener() { OnPreferenceClickListener onPreferenceClicked = preference -> {
@Override if (onRssfeedClickedListener != null)
public boolean onPreferenceClick(Preference preference) { onRssfeedClickedListener.onRssfeedClicked(rssfeedSetting);
if (onRssfeedClickedListener != null) return true;
onRssfeedClickedListener.onRssfeedClicked(rssfeedSetting);
return true;
}
}; };
setOnPreferenceClickListener(onPreferenceClicked); setOnPreferenceClickListener(onPreferenceClicked);
setIconSpaceReserved(false); setIconSpaceReserved(false);

11
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.annotation.TargetApi;
import android.app.AlertDialog; import android.app.AlertDialog;
import android.app.Dialog; import android.app.Dialog;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import android.content.Intent; import android.content.Intent;
import android.os.Build; import android.os.Build;
import android.os.Bundle; import android.os.Bundle;
@ -76,12 +74,9 @@ public class RssfeedSettingsActivity extends KeyBoundPreferencesActivity {
protected Dialog onCreateDialog(int id) { protected Dialog onCreateDialog(int id) {
if (id == DIALOG_CONFIRMREMOVE) { if (id == DIALOG_CONFIRMREMOVE) {
return new AlertDialog.Builder(this).setMessage(R.string.pref_confirmremove) return new AlertDialog.Builder(this).setMessage(R.string.pref_confirmremove)
.setPositiveButton(android.R.string.ok, new OnClickListener() { .setPositiveButton(android.R.string.ok, (dialog, which) -> {
@Override ApplicationSettings_.getInstance_(RssfeedSettingsActivity.this).removeRssfeedSettings(key);
public void onClick(DialogInterface dialog, int which) { finish();
ApplicationSettings_.getInstance_(RssfeedSettingsActivity.this).removeRssfeedSettings(key);
finish();
}
}).setNegativeButton(android.R.string.cancel, null).create(); }).setNegativeButton(android.R.string.cancel, null).create();
} }
return null; return null;

11
app/src/main/java/org/transdroid/core/gui/settings/ServerPreference.java

@ -36,13 +36,10 @@ public class ServerPreference extends Preference {
public ServerPreference(Context context) { public ServerPreference(Context context) {
super(context); super(context);
OnPreferenceClickListener onPreferenceClicked = new OnPreferenceClickListener() { OnPreferenceClickListener onPreferenceClicked = preference -> {
@Override if (onServerClickedListener != null)
public boolean onPreferenceClick(Preference preference) { onServerClickedListener.onServerClicked(serverSetting);
if (onServerClickedListener != null) return true;
onServerClickedListener.onServerClicked(serverSetting);
return true;
}
}; };
setOnPreferenceClickListener(onPreferenceClicked); setOnPreferenceClickListener(onPreferenceClicked);
setIconSpaceReserved(false); setIconSpaceReserved(false);

25
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.annotation.TargetApi;
import android.app.AlertDialog; import android.app.AlertDialog;
import android.app.Dialog; import android.app.Dialog;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import android.content.Intent; import android.content.Intent;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.os.Build; import android.os.Build;
@ -28,7 +26,6 @@ import android.os.Bundle;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.preference.EditTextPreference; import androidx.preference.EditTextPreference;
import androidx.preference.Preference;
import androidx.preference.PreferenceManager; import androidx.preference.PreferenceManager;
import org.androidannotations.annotations.Bean; import org.androidannotations.annotations.Bean;
@ -89,15 +86,12 @@ public class ServerSettingsActivity extends KeyBoundPreferencesActivity {
initTextPreference("server_ssltrustkey", null, "server_sslenabled"); initTextPreference("server_ssltrustkey", null, "server_sslenabled");
onPreferencesChanged(); onPreferencesChanged();
localNetworkPreference.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() { localNetworkPreference.setOnPreferenceClickListener(preference -> {
@Override if (!connectivityHelper.hasNetworkNamePermission(ServerSettingsActivity.this)) {
public boolean onPreferenceClick(final Preference preference) { connectivityHelper.askNetworkNamePermission(ServerSettingsActivity.this);
if (!connectivityHelper.hasNetworkNamePermission(ServerSettingsActivity.this)) { return true;
connectivityHelper.askNetworkNamePermission(ServerSettingsActivity.this);
return true;
}
return false;
} }
return false;
}); });
} }
@ -116,12 +110,9 @@ public class ServerSettingsActivity extends KeyBoundPreferencesActivity {
protected Dialog onCreateDialog(int id) { protected Dialog onCreateDialog(int id) {
if (id == DIALOG_CONFIRMREMOVE) { if (id == DIALOG_CONFIRMREMOVE) {
return new AlertDialog.Builder(this).setMessage(R.string.pref_confirmremove) return new AlertDialog.Builder(this).setMessage(R.string.pref_confirmremove)
.setPositiveButton(android.R.string.ok, new OnClickListener() { .setPositiveButton(android.R.string.ok, (dialog, which) -> {
@Override ApplicationSettings_.getInstance_(ServerSettingsActivity.this).removeNormalServerSettings(key);
public void onClick(DialogInterface dialog, int which) { finish();
ApplicationSettings_.getInstance_(ServerSettingsActivity.this).removeNormalServerSettings(key);
finish();
}
}).setNegativeButton(android.R.string.cancel, null).create(); }).setNegativeButton(android.R.string.cancel, null).create();
} }
return null; return null;

46
app/src/main/java/org/transdroid/core/gui/settings/SystemSettingsActivity.java

@ -28,7 +28,6 @@ import android.os.Bundle;
import android.text.TextUtils; import android.text.TextUtils;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.preference.Preference;
import androidx.preference.Preference.OnPreferenceClickListener; import androidx.preference.Preference.OnPreferenceClickListener;
import androidx.preference.PreferenceManager; import androidx.preference.PreferenceManager;
@ -69,34 +68,22 @@ public class SystemSettingsActivity extends PreferenceCompatActivity {
protected ErrorLogSender errorLogSender; protected ErrorLogSender errorLogSender;
@Bean @Bean
protected SettingsPersistence settingsPersistence; protected SettingsPersistence settingsPersistence;
private OnPreferenceClickListener onImportSettingsClick = new OnPreferenceClickListener() { private OnPreferenceClickListener onImportSettingsClick = preference -> {
@Override showDialog(DIALOG_IMPORTSETTINGS);
public boolean onPreferenceClick(Preference preference) { return true;
showDialog(DIALOG_IMPORTSETTINGS);
return true;
}
}; };
private OnPreferenceClickListener onExportSettingsClick = new OnPreferenceClickListener() { private OnPreferenceClickListener onExportSettingsClick = preference -> {
@Override showDialog(DIALOG_EXPORTSETTINGS);
public boolean onPreferenceClick(Preference preference) { return true;
showDialog(DIALOG_EXPORTSETTINGS);
return true;
}
}; };
private OnPreferenceClickListener onCheckUpdatesClick = new OnPreferenceClickListener() { private OnPreferenceClickListener onCheckUpdatesClick = preference -> {
@Override AppUpdateJob.schedule(getApplicationContext());
public boolean onPreferenceClick(Preference preference) { return true;
AppUpdateJob.schedule(getApplicationContext());
return true;
}
}; };
private OnPreferenceClickListener onClearSearchClick = new OnPreferenceClickListener() { private OnPreferenceClickListener onClearSearchClick = preference -> {
@Override SearchHistoryProvider.clearHistory(getApplicationContext());
public boolean onPreferenceClick(Preference preference) { SnackbarManager.show(Snackbar.with(SystemSettingsActivity.this).text(R.string.pref_clearsearch_success));
SearchHistoryProvider.clearHistory(getApplicationContext()); return true;
SnackbarManager.show(Snackbar.with(SystemSettingsActivity.this).text(R.string.pref_clearsearch_success));
return true;
}
}; };
private OnClickListener importSettingsFromFile = new OnClickListener() { private OnClickListener importSettingsFromFile = new OnClickListener() {
@Override @Override
@ -108,12 +95,9 @@ public class SystemSettingsActivity extends PreferenceCompatActivity {
} }
}; };
private OnClickListener importSettingsFromQr = new OnClickListener() { private OnClickListener importSettingsFromQr = (dialog, which) ->
@Override
public void onClick(DialogInterface dialog, int which) {
BarcodeHelper.startBarcodeScanner(SystemSettingsActivity.this, BarcodeHelper.ACTIVITY_BARCODE_QRSETTINGS); BarcodeHelper.startBarcodeScanner(SystemSettingsActivity.this, BarcodeHelper.ACTIVITY_BARCODE_QRSETTINGS);
}
};
private OnClickListener exportSettingsToFile = new OnClickListener() { private OnClickListener exportSettingsToFile = new OnClickListener() {
@Override @Override
public void onClick(DialogInterface dialog, int which) { public void onClick(DialogInterface dialog, int which) {

11
app/src/main/java/org/transdroid/core/gui/settings/WebsearchPreference.java

@ -36,13 +36,10 @@ public class WebsearchPreference extends Preference {
public WebsearchPreference(Context context) { public WebsearchPreference(Context context) {
super(context); super(context);
OnPreferenceClickListener onPreferenceClicked = new OnPreferenceClickListener() { OnPreferenceClickListener onPreferenceClicked = preference -> {
@Override if (onWebsearchClickedListener != null)
public boolean onPreferenceClick(Preference preference) { onWebsearchClickedListener.onWebsearchClicked(websearchSetting);
if (onWebsearchClickedListener != null) return true;
onWebsearchClickedListener.onWebsearchClicked(websearchSetting);
return true;
}
}; };
setOnPreferenceClickListener(onPreferenceClicked); setOnPreferenceClickListener(onPreferenceClicked);
setIconSpaceReserved(false); setIconSpaceReserved(false);

11
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.annotation.TargetApi;
import android.app.AlertDialog; import android.app.AlertDialog;
import android.app.Dialog; import android.app.Dialog;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import android.content.Intent; import android.content.Intent;
import android.os.Build; import android.os.Build;
import android.os.Bundle; import android.os.Bundle;
@ -72,12 +70,9 @@ public class WebsearchSettingsActivity extends KeyBoundPreferencesActivity {
protected Dialog onCreateDialog(int id) { protected Dialog onCreateDialog(int id) {
if (id == DIALOG_CONFIRMREMOVE) { if (id == DIALOG_CONFIRMREMOVE) {
return new AlertDialog.Builder(this).setMessage(R.string.pref_confirmremove) return new AlertDialog.Builder(this).setMessage(R.string.pref_confirmremove)
.setPositiveButton(android.R.string.ok, new OnClickListener() { .setPositiveButton(android.R.string.ok, (dialog, which) -> {
@Override ApplicationSettings_.getInstance_(WebsearchSettingsActivity.this).removeWebsearchSettings(key);
public void onClick(DialogInterface dialog, int which) { finish();
ApplicationSettings_.getInstance_(WebsearchSettingsActivity.this).removeWebsearchSettings(key);
finish();
}
}).setNegativeButton(android.R.string.cancel, null).create(); }).setNegativeButton(android.R.string.cancel, null).create();
} }
return null; return null;

13
app/src/main/java/org/transdroid/core/seedbox/SeedboxPreference.java

@ -18,8 +18,6 @@ package org.transdroid.core.seedbox;
import android.content.Context; import android.content.Context;
import androidx.preference.Preference;
import org.transdroid.core.app.settings.ServerSetting; import org.transdroid.core.app.settings.ServerSetting;
import org.transdroid.core.gui.settings.ServerPreference; import org.transdroid.core.gui.settings.ServerPreference;
@ -36,13 +34,10 @@ public class SeedboxPreference extends ServerPreference {
public SeedboxPreference(Context context) { public SeedboxPreference(Context context) {
super(context); super(context);
OnPreferenceClickListener onSeedboxPreferenceClicked = new OnPreferenceClickListener() { OnPreferenceClickListener onSeedboxPreferenceClicked = preference -> {
@Override if (onSeedboxClickedListener != null)
public boolean onPreferenceClick(Preference preference) { onSeedboxClickedListener.onSeedboxClicked(serverSetting, provider, onSeedboxClickedListenerOffset);
if (onSeedboxClickedListener != null) return true;
onSeedboxClickedListener.onSeedboxClicked(serverSetting, provider, onSeedboxClickedListenerOffset);
return true;
}
}; };
setOnPreferenceClickListener(onSeedboxPreferenceClicked); setOnPreferenceClickListener(onSeedboxPreferenceClicked);
} }

10
app/src/main/java/org/transdroid/core/service/ConnectivityHelper.java

@ -19,7 +19,6 @@ package org.transdroid.core.service;
import android.Manifest; import android.Manifest;
import android.app.Activity; import android.app.Activity;
import android.content.Context; import android.content.Context;
import android.content.DialogInterface;
import android.content.pm.PackageManager; import android.content.pm.PackageManager;
import android.net.ConnectivityManager; import android.net.ConnectivityManager;
import android.net.wifi.WifiManager; import android.net.wifi.WifiManager;
@ -66,13 +65,8 @@ public class ConnectivityHelper {
.setTitle(R.string.pref_local_permission_title) .setTitle(R.string.pref_local_permission_title)
.setMessage(activity.getString(R.string.pref_local_permission_rationale, .setMessage(activity.getString(R.string.pref_local_permission_rationale,
activity.getString(R.string.app_name))) activity.getString(R.string.app_name)))
.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() { .setPositiveButton(android.R.string.ok, (dialog, which) -> ActivityCompat.requestPermissions(activity,
@Override new String[]{Manifest.permission.ACCESS_FINE_LOCATION}, REQUEST_LOCATION_PERMISSION))
public void onClick(DialogInterface dialog, int which) {
ActivityCompat.requestPermissions(activity,
new String[]{Manifest.permission.ACCESS_FINE_LOCATION}, REQUEST_LOCATION_PERMISSION);
}
})
.setNegativeButton(android.R.string.cancel, null) .setNegativeButton(android.R.string.cancel, null)
.show(); .show();
} }

7
app/src/main/java/org/transdroid/core/widget/ListWidgetConfigActivity.java

@ -100,12 +100,7 @@ public class ListWidgetConfigActivity extends AppCompatActivity {
} }
}; };
private List<Torrent> previewTorrents = null; private List<Torrent> previewTorrents = null;
protected OnCheckedChangeListener reverseorderCheckedChanged = new OnCheckedChangeListener() { protected OnCheckedChangeListener reverseorderCheckedChanged = (buttonView, isChecked) -> filterTorrents();
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
filterTorrents();
}
};
private int appWidgetId; private int appWidgetId;
private OnClickListener doneClicked = new OnClickListener() { private OnClickListener doneClicked = new OnClickListener() {
@Override @Override

9
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.net.URLEncoder;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.Comparator;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
@ -339,12 +338,8 @@ public class UTorrentAdapter implements IDaemonAdapter, RemoteRssSupplier {
} }
} }
Collections.sort(remoteRssChannels, new Comparator<RemoteRssChannel>() { Collections.sort(remoteRssChannels, (lhs, rhs) ->
@Override lhs.getName().compareToIgnoreCase(rhs.getName()));
public int compare(RemoteRssChannel lhs, RemoteRssChannel rhs) {
return lhs.getName().compareToIgnoreCase(rhs.getName());
}
});
} }
private ArrayList<Label> parseJsonRetrieveGetLabels(JSONArray lresults) throws JSONException { private ArrayList<Label> parseJsonRetrieveGetLabels(JSONArray lresults) throws JSONException {

35
app/src/main/java/org/transdroid/daemon/util/HttpHelper.java

@ -22,10 +22,7 @@ import android.net.Uri;
import org.apache.http.Header; import org.apache.http.Header;
import org.apache.http.HeaderElement; import org.apache.http.HeaderElement;
import org.apache.http.HttpEntity; import org.apache.http.HttpEntity;
import org.apache.http.HttpException;
import org.apache.http.HttpRequest;
import org.apache.http.HttpRequestInterceptor; import org.apache.http.HttpRequestInterceptor;
import org.apache.http.HttpResponse;
import org.apache.http.HttpResponseInterceptor; import org.apache.http.HttpResponseInterceptor;
import org.apache.http.auth.AuthScope; import org.apache.http.auth.AuthScope;
import org.apache.http.auth.UsernamePasswordCredentials; import org.apache.http.auth.UsernamePasswordCredentials;
@ -40,7 +37,6 @@ import org.apache.http.params.BasicHttpParams;
import org.apache.http.params.HttpConnectionParams; import org.apache.http.params.HttpConnectionParams;
import org.apache.http.params.HttpParams; import org.apache.http.params.HttpParams;
import org.apache.http.params.HttpProtocolParams; import org.apache.http.params.HttpProtocolParams;
import org.apache.http.protocol.HttpContext;
import org.transdroid.daemon.DaemonException; import org.transdroid.daemon.DaemonException;
import org.transdroid.daemon.DaemonException.ExceptionType; import org.transdroid.daemon.DaemonException.ExceptionType;
import org.transdroid.daemon.DaemonSettings; import org.transdroid.daemon.DaemonSettings;
@ -71,32 +67,27 @@ public class HttpHelper {
/** /**
* HTTP request interceptor to allow for GZip-encoded data transfer * HTTP request interceptor to allow for GZip-encoded data transfer
*/ */
public static HttpRequestInterceptor gzipRequestInterceptor = new HttpRequestInterceptor() { public static HttpRequestInterceptor gzipRequestInterceptor = (request, context) -> {
public void process(final HttpRequest request, final HttpContext context) throws HttpException, IOException { if (!request.containsHeader("Accept-Encoding")) {
if (!request.containsHeader("Accept-Encoding")) { request.addHeader("Accept-Encoding", "gzip");
request.addHeader("Accept-Encoding", "gzip");
}
} }
}; };
/** /**
* HTTP response interceptor that decodes GZipped data * HTTP response interceptor that decodes GZipped data
*/ */
public static HttpResponseInterceptor gzipResponseInterceptor = new HttpResponseInterceptor() { public static HttpResponseInterceptor gzipResponseInterceptor = (response, context) -> {
public void process(final HttpResponse response, final HttpContext context) throws HttpException, IOException { HttpEntity entity = response.getEntity();
HttpEntity entity = response.getEntity(); Header ceheader = entity.getContentEncoding();
Header ceheader = entity.getContentEncoding(); if (ceheader != null) {
if (ceheader != null) { HeaderElement[] codecs = ceheader.getElements();
HeaderElement[] codecs = ceheader.getElements(); for (HeaderElement codec : codecs) {
for (HeaderElement codec : codecs) {
if (codec.getName().equalsIgnoreCase("gzip")) {
if (codec.getName().equalsIgnoreCase("gzip")) { response.setEntity(new GzipDecompressingEntity(response.getEntity()));
response.setEntity(new GzipDecompressingEntity(response.getEntity())); return;
return;
}
} }
} }
} }
}; };
/** /**

Loading…
Cancel
Save