From a3a595d967694c6084eefd46ebafff6829e14ca0 Mon Sep 17 00:00:00 2001 From: Eric Kok Date: Thu, 2 Apr 2015 15:45:42 +0200 Subject: [PATCH] Replaced Croutons with Snackbars. --- .../transdroid/core/gui/TorrentsActivity.java | 30 ++++++++--- .../core/gui/navigation/SetLabelDialog.java | 2 - .../core/gui/search/UrlEntryDialog.java | 50 +++++++------------ app/src/main/res/layout/dialog_setlabel.xml | 32 +++++------- app/src/main/res/layout/dialog_url.xml | 32 ++++++++++++ app/src/main/res/values/strings.xml | 1 + 6 files changed, 88 insertions(+), 59 deletions(-) create mode 100644 app/src/main/res/layout/dialog_url.xml 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 70fa8ddb..aa93f586 100644 --- a/app/src/main/java/org/transdroid/core/gui/TorrentsActivity.java +++ b/app/src/main/java/org/transdroid/core/gui/TorrentsActivity.java @@ -45,6 +45,7 @@ import com.getbase.floatingactionbutton.FloatingActionButton; import com.getbase.floatingactionbutton.FloatingActionsMenu; 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.Background; @@ -580,7 +581,6 @@ public class TorrentsActivity extends ActionBarActivity implements TorrentTasksE * @param hasServerSettings Whether there are server settings available, so we can continue to connect */ private void updateFragmentVisibility(boolean hasServerSettings) { - // TODO Hide hamburger icon? if (fragmentDetails != null && fragmentDetails.isAdded()) { if (hasServerSettings) { getFragmentManager().beginTransaction().show(fragmentDetails).commit(); @@ -729,11 +729,13 @@ public class TorrentsActivity extends ActionBarActivity implements TorrentTasksE @Click(R.id.addmenu_link_button) protected void startUrlEntryDialog() { - UrlEntryDialog.startUrlEntry(this); + addmenuButton.collapse(); + UrlEntryDialog.show(this); } @Click(R.id.addmenu_file_button) protected void startFilePicker() { + addmenuButton.collapse(); FilePickerHelper.startFilePicker(this); } @@ -742,13 +744,28 @@ public class TorrentsActivity extends ActionBarActivity implements TorrentTasksE public void onFilePicked(int resultCode, Intent data) { // We should have received an Intent with a local torrent's Uri as data from the file picker if (data != null && data.getData() != null && !data.getData().toString().equals("")) { - String url = data.getData().getPath(); - addTorrentByFile(data.getData().toString(), url.substring(url.lastIndexOf("/"))); + Uri dataUri = data.getData(); + + // Get torrent title + String title = NavigationHelper.extractNameFromUri(dataUri); + + // Adding a torrent from the via a content:// scheme (access through content provider stream) + if (dataUri.getScheme().equals(ContentResolver.SCHEME_CONTENT)) { + addTorrentFromDownloads(dataUri, title); + return; + } + + // Adding a .torrent file directly via the file:// scheme (we can access it directly) + if (dataUri.getScheme().equals("file")) { + addTorrentByFile(data.getDataString(), title); + } + } } @Click(R.id.addmenu_barcode_button) protected void startBarcodeScanner() { + addmenuButton.collapse(); BarcodeHelper.startBarcodeScanner(this, BarcodeHelper.ACTIVITY_BARCODE_ADDTORRENT); } @@ -764,7 +781,8 @@ 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.crouton_error) + .type(SnackbarType.MULTI_LINE)); } else if (result.startsWith("http") || result.startsWith("https")) { addTorrentByUrl(result, "QR code result"); // No torrent title known } else if (navigationHelper.enableSearchUi()) { @@ -1255,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)); + SnackbarManager.show(Snackbar.with(this).text(error).colorResource(R.color.crouton_error).type(SnackbarType.MULTI_LINE)); fragmentTorrents.updateIsLoading(false); if (isCritical) { fragmentTorrents.updateError(error); 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 01c07304..1234bd46 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 @@ -93,8 +93,6 @@ public class SetLabelDialog extends DialogFragment { if (currentLabels.size() == 0) { // Hide the list (and its label) if there are no labels yet setlabelFrame.findViewById(R.id.pick_label).setVisibility(View.GONE); - setlabelFrame.findViewById(R.id.line1).setVisibility(View.GONE); - setlabelFrame.findViewById(R.id.line2).setVisibility(View.GONE); labelsList.setVisibility(View.GONE); } else { labelsList.setAdapter(new FilterListItemAdapter(getActivity(), currentLabels)); diff --git a/app/src/main/java/org/transdroid/core/gui/search/UrlEntryDialog.java b/app/src/main/java/org/transdroid/core/gui/search/UrlEntryDialog.java index b56592e5..f3099834 100644 --- a/app/src/main/java/org/transdroid/core/gui/search/UrlEntryDialog.java +++ b/app/src/main/java/org/transdroid/core/gui/search/UrlEntryDialog.java @@ -16,21 +16,18 @@ */ package org.transdroid.core.gui.search; -import android.annotation.SuppressLint; -import android.annotation.TargetApi; -import android.app.AlertDialog; -import android.app.DialogFragment; import android.content.ClipboardManager; import android.content.Context; -import android.content.DialogInterface; -import android.content.DialogInterface.OnClickListener; import android.net.Uri; -import android.os.Build; import android.text.InputType; import android.text.TextUtils; -import android.view.inputmethod.InputMethodManager; +import android.view.LayoutInflater; +import android.view.View; import android.widget.EditText; +import com.afollestad.materialdialogs.MaterialDialog; + +import org.transdroid.R; import org.transdroid.core.gui.TorrentsActivity; import org.transdroid.core.gui.navigation.NavigationHelper; @@ -41,25 +38,20 @@ public class UrlEntryDialog { * TorrentsActivity#addTorrentByUrl(String, String) method}. * @param activity The activity that opens (and owns) this dialog */ - @SuppressLint("ValidFragment") - public static void startUrlEntry(final TorrentsActivity activity) { - new DialogFragment() { - @TargetApi(Build.VERSION_CODES.HONEYCOMB) - public android.app.Dialog onCreateDialog(android.os.Bundle savedInstanceState) { - final EditText urlInput = new EditText(activity); - urlInput.setInputType(InputType.TYPE_TEXT_VARIATION_URI); - ClipboardManager clipboard = (ClipboardManager) activity.getSystemService(Context.CLIPBOARD_SERVICE); - if (clipboard.hasPrimaryClip() && clipboard.getPrimaryClip().getItemCount() > 0) { - CharSequence content = clipboard.getPrimaryClip().getItemAt(0).coerceToText(activity); - urlInput.setText(content); - } - ((InputMethodManager) activity.getSystemService(Context.INPUT_METHOD_SERVICE)) - .toggleSoftInput(InputMethodManager.SHOW_FORCED, InputMethodManager.HIDE_IMPLICIT_ONLY); - return new AlertDialog.Builder(activity).setView(urlInput).setPositiveButton(android.R.string.ok, new OnClickListener() { + public static void show(final TorrentsActivity activity) { + View inputLayout = LayoutInflater.from(activity).inflate(R.layout.dialog_url, null); + final EditText urlEdit = (EditText) inputLayout.findViewById(R.id.url_edit); + urlEdit.setInputType(InputType.TYPE_TEXT_VARIATION_URI); + ClipboardManager clipboard = (ClipboardManager) activity.getSystemService(Context.CLIPBOARD_SERVICE); + if (clipboard.hasPrimaryClip() && clipboard.getPrimaryClip().getItemCount() > 0) { + CharSequence content = clipboard.getPrimaryClip().getItemAt(0).coerceToText(activity); + urlEdit.setText(content); + } + new MaterialDialog.Builder(activity).customView(inputLayout, false).positiveText(android.R.string.ok).negativeText(android.R.string.cancel) + .callback(new MaterialDialog.ButtonCallback() { @Override - public void onClick(DialogInterface dialog, int which) { - // Assume text entry box input as URL and treat the filename (after the last /) as title - String url = urlInput.getText().toString(); + public void onPositive(MaterialDialog dialog) { + String url = urlEdit.getText().toString(); Uri uri = Uri.parse(url); if (!TextUtils.isEmpty(url)) { String title = NavigationHelper.extractNameFromUri(uri); @@ -70,11 +62,7 @@ public class UrlEntryDialog { } } } - }).setNegativeButton(android.R.string.cancel, null).create(); - } - - ; - }.show(activity.getFragmentManager(), "urlentry"); + }).show(); } } diff --git a/app/src/main/res/layout/dialog_setlabel.xml b/app/src/main/res/layout/dialog_setlabel.xml index b9f039bd..8f596f2e 100644 --- a/app/src/main/res/layout/dialog_setlabel.xml +++ b/app/src/main/res/layout/dialog_setlabel.xml @@ -16,44 +16,36 @@ along with Transdroid. If not, see . --> + android:padding="@dimen/margin_default" + android:orientation="vertical"> - - + android:layout_marginBottom="@dimen/margin_half" + style="@style/SectionHeader"/> - - - + android:listSelector="?attr/activatable_background" + tools:listitem="@layout/list_item_simple"/> + - + android:layout_marginBottom="@dimen/margin_half" + style="@style/SectionHeader"/> + + + + + + + diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index b3daff04..55edda18 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -96,6 +96,7 @@ Select finished Invert selection Add torrent to… + http://… STATUS: %1$s Waiting to check…