diff options
author | Domingos Lopes <domingos86lopes@gmail.com> | 2016-03-22 02:07:26 -0400 |
---|---|---|
committer | Domingos Lopes <domingos86lopes@gmail.com> | 2016-03-22 02:07:26 -0400 |
commit | a252191d79f09c0f06cf13a700dd48dfdefd3fe4 (patch) | |
tree | 798bf1a99a85f634aece0c88a252b4e550d50193 /app/src/main/java/de/danoeh/antennapod/dialog | |
parent | 5febe9248ab679a37e48c9f1ff46ca643a889510 (diff) | |
download | AntennaPod-a252191d79f09c0f06cf13a700dd48dfdefd3fe4.zip |
code cleaning:
- lambda expressions, method references,
- multi catches,
- remove unnecessary keywords (public keyword on interface method signatures, static on interfaces or enums, final on private method signatures),
- == false expressions,
- diamond type (<>) expressions,
- replace StringBuffer with StringBuilder for local variables used by a single thread,
- replace Arrays.asList with Collections.singletonList whenever applicable,
- inline variable returns (whenever the variable name's meaning is not important to understand the code),
- replace some chains of if/else if/... with switch/case,
- break append(a + b) into append(a).append(b) for StringBuilder objects,
- unused import statements,
- reduce log TAGs to 23 characters,
- MaterialDialog callback deprecated,
- ActionBarActivity for AppCompatActivity,
Diffstat (limited to 'app/src/main/java/de/danoeh/antennapod/dialog')
8 files changed, 39 insertions, 95 deletions
diff --git a/app/src/main/java/de/danoeh/antennapod/dialog/AuthenticationDialog.java b/app/src/main/java/de/danoeh/antennapod/dialog/AuthenticationDialog.java index bdb2d68ba..6f9e221ec 100644 --- a/app/src/main/java/de/danoeh/antennapod/dialog/AuthenticationDialog.java +++ b/app/src/main/java/de/danoeh/antennapod/dialog/AuthenticationDialog.java @@ -2,13 +2,13 @@ package de.danoeh.antennapod.dialog; import android.app.Dialog; import android.content.Context; -import android.content.DialogInterface; import android.os.Bundle; import android.view.View; import android.view.Window; import android.widget.Button; import android.widget.CheckBox; import android.widget.EditText; + import de.danoeh.antennapod.R; /** @@ -58,26 +58,13 @@ public abstract class AuthenticationDialog extends Dialog { if (passwordInitialValue != null) { etxtPassword.setText(passwordInitialValue); } - setOnCancelListener(new OnCancelListener() { - @Override - public void onCancel(DialogInterface dialog) { - onCancelled(); - } - }); - butCancel.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - cancel(); - } - }); - butConfirm.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - onConfirmed(etxtUsername.getText().toString(), - etxtPassword.getText().toString(), - showSaveCredentialsCheckbox && saveUsernamePassword.isChecked()); - dismiss(); - } + setOnCancelListener(dialog -> onCancelled()); + butCancel.setOnClickListener(v -> cancel()); + butConfirm.setOnClickListener(v -> { + onConfirmed(etxtUsername.getText().toString(), + etxtPassword.getText().toString(), + showSaveCredentialsCheckbox && saveUsernamePassword.isChecked()); + dismiss(); }); } diff --git a/app/src/main/java/de/danoeh/antennapod/dialog/AutoFlattrPreferenceDialog.java b/app/src/main/java/de/danoeh/antennapod/dialog/AutoFlattrPreferenceDialog.java index 75b1bc8d2..93425949c 100644 --- a/app/src/main/java/de/danoeh/antennapod/dialog/AutoFlattrPreferenceDialog.java +++ b/app/src/main/java/de/danoeh/antennapod/dialog/AutoFlattrPreferenceDialog.java @@ -3,7 +3,6 @@ package de.danoeh.antennapod.dialog; import android.annotation.SuppressLint; import android.app.Activity; import android.content.Context; -import android.content.DialogInterface; import android.support.v7.app.AlertDialog; import android.view.View; import android.widget.CheckBox; @@ -42,12 +41,9 @@ public class AutoFlattrPreferenceDialog { setStatusMsgText(activity, txtvStatus, initialValue); skbPercent.setProgress(initialValue); - chkAutoFlattr.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - skbPercent.setEnabled(chkAutoFlattr.isChecked()); - txtvStatus.setEnabled(chkAutoFlattr.isChecked()); - } + chkAutoFlattr.setOnClickListener(v -> { + skbPercent.setEnabled(chkAutoFlattr.isChecked()); + txtvStatus.setEnabled(chkAutoFlattr.isChecked()); }); skbPercent.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() { @@ -69,20 +65,14 @@ public class AutoFlattrPreferenceDialog { builder.setTitle(R.string.pref_auto_flattr_title) .setView(view) - .setPositiveButton(R.string.confirm_label, new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialog, int which) { - float progDouble = ((float) skbPercent.getProgress()) / 100.0f; - callback.onConfirmed(chkAutoFlattr.isChecked(), progDouble); - dialog.dismiss(); - } + .setPositiveButton(R.string.confirm_label, (dialog, which) -> { + float progDouble = ((float) skbPercent.getProgress()) / 100.0f; + callback.onConfirmed(chkAutoFlattr.isChecked(), progDouble); + dialog.dismiss(); }) - .setNegativeButton(R.string.cancel_label, new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialog, int which) { - callback.onCancelled(); - dialog.dismiss(); - } + .setNegativeButton(R.string.cancel_label, (dialog, which) -> { + callback.onCancelled(); + dialog.dismiss(); }) .setCancelable(false).show(); } @@ -97,10 +87,10 @@ public class AutoFlattrPreferenceDialog { } } - public static interface AutoFlattrPreferenceDialogInterface { - public void onCancelled(); + public interface AutoFlattrPreferenceDialogInterface { + void onCancelled(); - public void onConfirmed(boolean autoFlattrEnabled, float autoFlattrValue); + void onConfirmed(boolean autoFlattrEnabled, float autoFlattrValue); } diff --git a/app/src/main/java/de/danoeh/antennapod/dialog/EpisodesApplyActionFragment.java b/app/src/main/java/de/danoeh/antennapod/dialog/EpisodesApplyActionFragment.java index ac7a9efee..577a3ecbe 100644 --- a/app/src/main/java/de/danoeh/antennapod/dialog/EpisodesApplyActionFragment.java +++ b/app/src/main/java/de/danoeh/antennapod/dialog/EpisodesApplyActionFragment.java @@ -54,7 +54,7 @@ public class EpisodesApplyActionFragment extends Fragment { private final Map<Long,FeedItem> idMap = new ArrayMap<>(); private final List<FeedItem> episodes = new ArrayList<>(); private int actions; - private final List<String> titles = new ArrayList(); + private final List<String> titles = new ArrayList<>(); private final LongList checkedIds = new LongList(); private MenuItem mSelectToggle; @@ -285,9 +285,9 @@ public class EpisodesApplyActionFragment extends Fragment { private void sortByDuration(final boolean reverse) { Collections.sort(episodes, (lhs, rhs) -> { int ordering; - if (false == lhs.hasMedia()) { + if (!lhs.hasMedia()) { ordering = 1; - } else if (false == rhs.hasMedia()) { + } else if (!rhs.hasMedia()) { ordering = -1; } else { ordering = lhs.getMedia().getDuration() - rhs.getMedia().getDuration(); @@ -304,7 +304,7 @@ public class EpisodesApplyActionFragment extends Fragment { private void checkAll() { for (FeedItem episode : episodes) { - if(false == checkedIds.contains(episode.getId())) { + if(!checkedIds.contains(episode.getId())) { checkedIds.add(episode.getId()); } } @@ -391,14 +391,14 @@ public class EpisodesApplyActionFragment extends Fragment { private void downloadChecked() { // download the check episodes in the same order as they are currently displayed - List<FeedItem> toDownload = new ArrayList<FeedItem>(checkedIds.size()); + List<FeedItem> toDownload = new ArrayList<>(checkedIds.size()); for(FeedItem episode : episodes) { if(checkedIds.contains(episode.getId())) { toDownload.add(episode); } } try { - DBTasks.downloadFeedItems(getActivity(), toDownload.toArray(new FeedItem[0])); + DBTasks.downloadFeedItems(getActivity(), toDownload.toArray(new FeedItem[toDownload.size()])); } catch (DownloadRequestException e) { e.printStackTrace(); DownloadRequestErrorDialogCreator.newRequestErrorDialog(getActivity(), e.getMessage()); diff --git a/app/src/main/java/de/danoeh/antennapod/dialog/GpodnetSetHostnameDialog.java b/app/src/main/java/de/danoeh/antennapod/dialog/GpodnetSetHostnameDialog.java index 5f531e88f..b50e21d15 100644 --- a/app/src/main/java/de/danoeh/antennapod/dialog/GpodnetSetHostnameDialog.java +++ b/app/src/main/java/de/danoeh/antennapod/dialog/GpodnetSetHostnameDialog.java @@ -1,7 +1,6 @@ package de.danoeh.antennapod.dialog; import android.content.Context; -import android.content.DialogInterface; import android.support.v7.app.AlertDialog; import android.text.Editable; import android.text.InputType; diff --git a/app/src/main/java/de/danoeh/antennapod/dialog/ProxyDialog.java b/app/src/main/java/de/danoeh/antennapod/dialog/ProxyDialog.java index d745bb51c..98a4b5356 100644 --- a/app/src/main/java/de/danoeh/antennapod/dialog/ProxyDialog.java +++ b/app/src/main/java/de/danoeh/antennapod/dialog/ProxyDialog.java @@ -98,9 +98,7 @@ public class ProxyDialog { AntennapodHttpClient.reinit(); dialog.dismiss(); }) - .onNegative((dialog1, which) -> { - dialog1.dismiss(); - }) + .onNegative((dialog1, which) -> dialog1.dismiss()) .autoDismiss(false) .build(); View view = dialog.getCustomView(); @@ -208,8 +206,7 @@ public class ProxyDialog { String port = etPort.getText().toString(); if(port.length() > 0) { try { - int portValue = Integer.parseInt(port); - return portValue; + return Integer.parseInt(port); } catch(NumberFormatException e) { // ignore } diff --git a/app/src/main/java/de/danoeh/antennapod/dialog/RatingDialog.java b/app/src/main/java/de/danoeh/antennapod/dialog/RatingDialog.java index ed0db92a4..64fc1fda4 100644 --- a/app/src/main/java/de/danoeh/antennapod/dialog/RatingDialog.java +++ b/app/src/main/java/de/danoeh/antennapod/dialog/RatingDialog.java @@ -94,11 +94,7 @@ public class RatingDialog { long firstDate = mPreferences.getLong(KEY_FIRST_START_DATE, now); long diff = now - firstDate; long diffDays = TimeUnit.DAYS.convert(diff, TimeUnit.MILLISECONDS); - if (diffDays >= AFTER_DAYS) { - return true; - } else { - return false; - } + return diffDays >= AFTER_DAYS; } @Nullable @@ -107,30 +103,16 @@ public class RatingDialog { if(context == null) { return null; } - MaterialDialog dialog = new MaterialDialog.Builder(context) + return new MaterialDialog.Builder(context) .title(R.string.rating_title) .content(R.string.rating_message) .positiveText(R.string.rating_now_label) .negativeText(R.string.rating_never_label) .neutralText(R.string.rating_later_label) - .callback(new MaterialDialog.ButtonCallback() { - @Override - public void onPositive(MaterialDialog dialog) { - rateNow(); - } - - @Override - public void onNegative(MaterialDialog dialog) { - saveRated(); - } - - @Override - public void onNeutral(MaterialDialog dialog) { - resetStartDate(); - } - }) + .onPositive((dialog, which) -> rateNow()) + .onNegative((dialog, which) -> saveRated()) + .onNeutral((dialog, which) -> resetStartDate()) .cancelListener(dialog1 -> resetStartDate()) .build(); - return dialog; } } diff --git a/app/src/main/java/de/danoeh/antennapod/dialog/SleepTimerDialog.java b/app/src/main/java/de/danoeh/antennapod/dialog/SleepTimerDialog.java index 89e24f882..8a13a75d9 100644 --- a/app/src/main/java/de/danoeh/antennapod/dialog/SleepTimerDialog.java +++ b/app/src/main/java/de/danoeh/antennapod/dialog/SleepTimerDialog.java @@ -1,17 +1,13 @@ package de.danoeh.antennapod.dialog; -import android.app.Dialog; import android.content.Context; import android.content.SharedPreferences; -import android.os.Bundle; import android.text.Editable; import android.text.TextWatcher; import android.util.Log; import android.view.View; -import android.view.Window; import android.view.inputmethod.InputMethodManager; import android.widget.ArrayAdapter; -import android.widget.Button; import android.widget.CheckBox; import android.widget.EditText; import android.widget.Spinner; @@ -58,14 +54,8 @@ public abstract class SleepTimerDialog { builder.customView(R.layout.time_dialog, false); builder.positiveText(R.string.set_sleeptimer_label); builder.negativeText(R.string.cancel_label); - builder.callback(new MaterialDialog.ButtonCallback() { - @Override - public void onNegative(MaterialDialog dialog) { - dialog.dismiss(); - } - - @Override - public void onPositive(MaterialDialog dialog) { + builder.onNegative((dialog, which) -> dialog.dismiss()); + builder.onPositive((dialog, which) -> { try { savePreferences(); long input = readTimeMillis(); @@ -77,8 +67,7 @@ public abstract class SleepTimerDialog { Toast.LENGTH_LONG); toast.show(); } - } - }); + }); dialog = builder.build(); View view = dialog.getView(); diff --git a/app/src/main/java/de/danoeh/antennapod/dialog/VariableSpeedDialog.java b/app/src/main/java/de/danoeh/antennapod/dialog/VariableSpeedDialog.java index 3ed82b9bd..2bf9c4e7a 100644 --- a/app/src/main/java/de/danoeh/antennapod/dialog/VariableSpeedDialog.java +++ b/app/src/main/java/de/danoeh/antennapod/dialog/VariableSpeedDialog.java @@ -102,8 +102,8 @@ public class VariableSpeedDialog { builder.setPositiveButton(android.R.string.ok, (dialog, which) -> { int choiceCount = 0; - for (int i = 0; i < speedChecked.length; i++) { - if (speedChecked[i]) { + for (boolean checked : speedChecked) { + if (checked) { choiceCount++; } } |