From 3506705a827e45caff10239d846b9164373d513a Mon Sep 17 00:00:00 2001 From: Eric Kok Date: Tue, 14 Apr 2015 10:22:50 +0200 Subject: [PATCH] Replacing Holo design with Material design in dialogs. --- .../transdroid/core/gui/DetailsActivity.java | 5 +- .../transdroid/core/gui/DetailsFragment.java | 12 +- .../transdroid/core/gui/ServerStatusView.java | 6 +- .../transdroid/core/gui/TorrentsActivity.java | 20 +-- .../transdroid/core/gui/TorrentsFragment.java | 3 +- .../core/gui/navigation/SetLabelDialog.java | 106 ++++++--------- .../navigation/SetStorageLocationDialog.java | 78 +++-------- .../gui/navigation/SetTrackersDialog.java | 79 ++++------- .../navigation/SetTransferRatesDialog.java | 124 +++++++----------- .../core/gui/rss/RssfeedsActivity.java | 4 +- .../core/gui/rss/RssitemsFragment.java | 2 +- .../gui/search/SearchResultsFragment.java | 2 +- .../core/gui/search/UrlEntryDialog.java | 1 - .../gui/settings/SystemSettingsActivity.java | 10 +- .../seedbox/XirvikSharedSettingsActivity.java | 2 +- .../res/layout/actionbar_serverstatus.xml | 13 +- app/src/main/res/layout/dialog_setlabel.xml | 1 - .../res/layout/dialog_storagelocation.xml | 2 +- app/src/main/res/layout/dialog_trackers.xml | 2 +- .../main/res/layout/dialog_transferrates.xml | 57 +------- app/src/main/res/layout/dialog_url.xml | 1 - app/src/main/res/values/colors.xml | 3 +- .../res/values/styles_transdroid_light.xml | 1 - 23 files changed, 178 insertions(+), 356 deletions(-) diff --git a/app/src/main/java/org/transdroid/core/gui/DetailsActivity.java b/app/src/main/java/org/transdroid/core/gui/DetailsActivity.java index 94c90640..8dd9c5fa 100644 --- a/app/src/main/java/org/transdroid/core/gui/DetailsActivity.java +++ b/app/src/main/java/org/transdroid/core/gui/DetailsActivity.java @@ -22,7 +22,6 @@ import android.os.Build; import android.os.Bundle; import android.support.v7.app.ActionBarActivity; import android.support.v7.widget.Toolbar; -import android.widget.Toast; import com.nispok.snackbar.Snackbar; import com.nispok.snackbar.SnackbarManager; @@ -260,7 +259,7 @@ public class DetailsActivity extends ActionBarActivity implements TorrentTasksEx setResult(RESULT_OK, new Intent().putExtra("torrent_removed", true).putExtra("affected_torrent", torrent)); finish(); if (closeText != null) { - Toast.makeText(this, closeText, Toast.LENGTH_LONG).show(); + SnackbarManager.show(Snackbar.with(this).text(closeText)); } } @@ -349,7 +348,7 @@ public class DetailsActivity extends ActionBarActivity implements TorrentTasksEx String error = getString(LocalTorrent.getResourceForDaemonException(result.getException())); fragmentDetails.updateIsLoading(false, isCritical ? error : null); SnackbarManager.show(Snackbar.with(this).text(getString(LocalTorrent.getResourceForDaemonException(result.getException()))) - .colorResource(R.color.crouton_error)); + .colorResource(R.color.red)); } @UiThread 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 d80e4961..5e2db024 100644 --- a/app/src/main/java/org/transdroid/core/gui/DetailsFragment.java +++ b/app/src/main/java/org/transdroid/core/gui/DetailsFragment.java @@ -37,6 +37,7 @@ import android.widget.TextView; import com.nispok.snackbar.Snackbar; import com.nispok.snackbar.SnackbarManager; +import com.nispok.snackbar.enums.SnackbarType; import org.androidannotations.annotations.AfterViews; import org.androidannotations.annotations.Click; @@ -406,7 +407,7 @@ public class DetailsFragment extends Fragment implements OnTrackersUpdatedListen @OptionsItem(R.id.action_setlabel) protected void setLabel() { if (currentLabels != null) { - new SetLabelDialog().setOnLabelPickedListener(this).setCurrentLabels(currentLabels).show(getFragmentManager(), "SetLabelDialog"); + SetLabelDialog.show(getActivity(), this, currentLabels); } } @@ -421,14 +422,12 @@ public class DetailsFragment extends Fragment implements OnTrackersUpdatedListen SnackbarManager.show(Snackbar.with(getActivity()).text(R.string.error_stillloadingdetails)); return; } - new SetTrackersDialog().setOnTrackersUpdated(this).setCurrentTrackers(torrentDetails.getTrackersText()) - .show(getFragmentManager(), "SetTrackersDialog"); + SetTrackersDialog.show(getActivity(), this, torrentDetails.getTrackersText()); } @OptionsItem(R.id.action_changelocation) protected void changeStorageLocation() { - new SetStorageLocationDialog().setOnStorageLocationUpdated(this).setCurrentLocation(torrent.getLocationDir()) - .show(getFragmentManager(), "SetStorageLocationDialog"); + SetStorageLocationDialog.show(getActivity(), this, torrent.getLocationDir()); } @Override @@ -585,7 +584,8 @@ public class DetailsFragment extends Fragment implements OnTrackersUpdatedListen } // No app is available that can handle FTP downloads - SnackbarManager.show(Snackbar.with(getActivity()).text(R.string.error_noftpapp).colorResource(R.color.crouton_error)); + SnackbarManager.show(Snackbar.with(getActivity()).text(getString(R.string.error_noftpapp, url)).type(SnackbarType.MULTI_LINE) + .colorResource(R.color.red)); mode.finish(); return true; 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 f55fff18..ceead744 100644 --- a/app/src/main/java/org/transdroid/core/gui/ServerStatusView.java +++ b/app/src/main/java/org/transdroid/core/gui/ServerStatusView.java @@ -27,7 +27,6 @@ import com.nispok.snackbar.SnackbarManager; import org.androidannotations.annotations.EViewGroup; import org.androidannotations.annotations.ViewById; import org.transdroid.R; -import org.transdroid.core.gui.navigation.NavigationHelper; import org.transdroid.core.gui.navigation.SetTransferRatesDialog; import org.transdroid.core.gui.navigation.SetTransferRatesDialog.OnRatesPickedListener; import org.transdroid.daemon.Torrent; @@ -99,8 +98,7 @@ public class ServerStatusView extends RelativeLayout implements OnRatesPickedLis private OnClickListener onStartDownPickerClicked = new OnClickListener() { public void onClick(View v) { - new SetTransferRatesDialog().setOnRatesPickedListener(ServerStatusView.this) - .show(activity.getFragmentManager(), "SetTransferRatesDialog"); + SetTransferRatesDialog.show(getContext(), ServerStatusView.this); } }; @@ -116,7 +114,7 @@ public class ServerStatusView extends RelativeLayout implements OnRatesPickedLis @Override public void onInvalidNumber() { - SnackbarManager.show(Snackbar.with(activity).text(R.string.error_notanumber).colorResource(R.color.crouton_error)); + SnackbarManager.show(Snackbar.with(activity).text(R.string.error_notanumber).colorResource(R.color.red)); } } 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 aa93f586..978edcc4 100644 --- a/app/src/main/java/org/transdroid/core/gui/TorrentsActivity.java +++ b/app/src/main/java/org/transdroid/core/gui/TorrentsActivity.java @@ -648,7 +648,7 @@ public class TorrentsActivity extends ActionBarActivity implements TorrentTasksE return; } if (dataUri.getScheme() == null) { - SnackbarManager.show(Snackbar.with(this).text(R.string.error_invalid_url_form).colorResource(R.color.crouton_error)); + SnackbarManager.show(Snackbar.with(this).text(R.string.error_invalid_url_form).colorResource(R.color.red)); return; } @@ -781,7 +781,7 @@ public class TorrentsActivity extends ActionBarActivity implements TorrentTasksE protected void onBarcodeScanHandled(String barcode, String result) { log.d(this, "Scanned barcode " + barcode + " and got " + result); if (TextUtils.isEmpty(result)) { - SnackbarManager.show(Snackbar.with(this).text(R.string.error_noproductforcode).colorResource(R.color.crouton_error) + SnackbarManager.show(Snackbar.with(this).text(R.string.error_noproductforcode).colorResource(R.color.red) .type(SnackbarType.MULTI_LINE)); } else if (result.startsWith("http") || result.startsWith("https")) { addTorrentByUrl(result, "QR code result"); // No torrent title known @@ -1044,10 +1044,10 @@ public class TorrentsActivity extends ActionBarActivity implements TorrentTasksE } catch (SecurityException e) { // No longer access to this file log.e(this, "No access given to " + contentUri.toString() + ": " + e.toString()); - SnackbarManager.show(Snackbar.with(this).text(R.string.error_torrentfile).colorResource(R.color.crouton_error)); + SnackbarManager.show(Snackbar.with(this).text(R.string.error_torrentfile).colorResource(R.color.red)); } catch (FileNotFoundException e) { log.e(this, contentUri.toString() + " does not exist: " + e.toString()); - SnackbarManager.show(Snackbar.with(this).text(R.string.error_torrentfile).colorResource(R.color.crouton_error)); + SnackbarManager.show(Snackbar.with(this).text(R.string.error_torrentfile).colorResource(R.color.red)); } } @@ -1059,7 +1059,7 @@ public class TorrentsActivity extends ActionBarActivity implements TorrentTasksE addTorrentFromStream(input, title); } catch (Exception e) { log.e(this, "Can't download private site torrent " + url + " from " + source + ": " + e.toString()); - SnackbarManager.show(Snackbar.with(this).text(R.string.error_torrentfile).colorResource(R.color.crouton_error)); + SnackbarManager.show(Snackbar.with(this).text(R.string.error_torrentfile).colorResource(R.color.red)); } } @@ -1087,14 +1087,14 @@ public class TorrentsActivity extends ActionBarActivity implements TorrentTasksE response.getStatusLine().getStatusCode() == HttpStatus.SC_NOT_FOUND) { log.e(this, "Can't retrieve web torrent " + url + ": Unexpected HTTP response status code " + response.getStatusLine().toString()); - SnackbarManager.show(Snackbar.with(this).text(R.string.error_401).colorResource(R.color.crouton_error)); + SnackbarManager.show(Snackbar.with(this).text(R.string.error_401).colorResource(R.color.red)); return; } InputStream input = response.getEntity().getContent(); addTorrentFromStream(input, title); } catch (Exception e) { log.e(this, "Can't retrieve web torrent " + url + ": " + e.toString()); - SnackbarManager.show(Snackbar.with(this).text(R.string.error_torrentfile).colorResource(R.color.crouton_error)); + SnackbarManager.show(Snackbar.with(this).text(R.string.error_torrentfile).colorResource(R.color.red)); } } @@ -1120,7 +1120,7 @@ public class TorrentsActivity extends ActionBarActivity implements TorrentTasksE } } catch (IOException e) { log.e(this, "Can't write input stream to " + tempFile.toString() + ": " + e.toString()); - SnackbarManager.show(Snackbar.with(this).text(R.string.error_torrentfile).colorResource(R.color.crouton_error)); + SnackbarManager.show(Snackbar.with(this).text(R.string.error_torrentfile).colorResource(R.color.red)); } finally { try { if (input != null) { @@ -1128,7 +1128,7 @@ public class TorrentsActivity extends ActionBarActivity implements TorrentTasksE } } catch (IOException e) { log.e(this, "Error closing the input stream " + tempFile.toString() + ": " + e.toString()); - SnackbarManager.show(Snackbar.with(this).text(R.string.error_torrentfile).colorResource(R.color.crouton_error)); + SnackbarManager.show(Snackbar.with(this).text(R.string.error_torrentfile).colorResource(R.color.red)); } } } @@ -1273,7 +1273,7 @@ public class TorrentsActivity extends ActionBarActivity implements TorrentTasksE //noinspection ThrowableResultOfMethodCallIgnored log.i(this, result.getException().toString()); String error = getString(LocalTorrent.getResourceForDaemonException(result.getException())); - SnackbarManager.show(Snackbar.with(this).text(error).colorResource(R.color.crouton_error).type(SnackbarType.MULTI_LINE)); + SnackbarManager.show(Snackbar.with(this).text(error).colorResource(R.color.red).type(SnackbarType.MULTI_LINE)); fragmentTorrents.updateIsLoading(false); if (isCritical) { fragmentTorrents.updateError(error); 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 e640890c..b5d371c3 100644 --- a/app/src/main/java/org/transdroid/core/gui/TorrentsFragment.java +++ b/app/src/main/java/org/transdroid/core/gui/TorrentsFragment.java @@ -355,8 +355,7 @@ public class TorrentsFragment extends Fragment implements OnLabelPickedListener } else if (itemId == R.id.action_setlabel) { lastMultiSelectedTorrents = checked; if (currentLabels != null) { - new SetLabelDialog().setOnLabelPickedListener(TorrentsFragment.this).setCurrentLabels(currentLabels) - .show(getFragmentManager(), "SetLabelDialog"); + SetLabelDialog.show(getActivity(), TorrentsFragment.this,currentLabels); } mode.finish(); return true; 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 1234bd46..1a949580 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 @@ -16,110 +16,80 @@ */ package org.transdroid.core.gui.navigation; -import android.app.AlertDialog; -import android.app.Dialog; -import android.app.DialogFragment; -import android.content.DialogInterface; -import android.content.DialogInterface.OnClickListener; -import android.os.Bundle; +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 com.afollestad.materialdialogs.MaterialDialog; import com.nispok.snackbar.Snackbar; import com.nispok.snackbar.SnackbarManager; import org.transdroid.R; -import org.transdroid.core.gui.lists.SimpleListItem; -import java.security.InvalidParameterException; import java.util.Iterator; import java.util.List; -/** - * A dialog fragment that allows picking a label or entering a new label to set this new label to the torrent. - * @author Eric Kok - */ -public class SetLabelDialog extends DialogFragment { - - private OnLabelPickedListener onLabelPickedListener = null; - private List currentLabels = null; - - public SetLabelDialog() { - setRetainInstance(true); - } +public class SetLabelDialog { /** - * Sets the callback for when the user is has picked a label for the target torrent. - * @param onLabelPickedListener The event listener to this dialog - * @return This dialog, for method chaining + * A dialog fragment that allows picking a label or entering a new label to set this new label to the torrent. + * @param context The activity context that opens (and owns) this dialog + * @param onLabelPickedListener The callback when a new label has been entered or picked by the user + * @param currentLabels The list of labels as currently exist on the server, to present as list for easy selection */ - public SetLabelDialog setOnLabelPickedListener(OnLabelPickedListener onLabelPickedListener) { - this.onLabelPickedListener = onLabelPickedListener; - return this; - } + public static void show(final Context context, final OnLabelPickedListener onLabelPickedListener, List