Browse Source

Replaced Croutons with Snackbars.

material
Eric Kok 10 years ago
parent
commit
a3a595d967
  1. 30
      app/src/main/java/org/transdroid/core/gui/TorrentsActivity.java
  2. 2
      app/src/main/java/org/transdroid/core/gui/navigation/SetLabelDialog.java
  3. 50
      app/src/main/java/org/transdroid/core/gui/search/UrlEntryDialog.java
  4. 32
      app/src/main/res/layout/dialog_setlabel.xml
  5. 32
      app/src/main/res/layout/dialog_url.xml
  6. 1
      app/src/main/res/values/strings.xml

30
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.getbase.floatingactionbutton.FloatingActionsMenu;
import com.nispok.snackbar.Snackbar; import com.nispok.snackbar.Snackbar;
import com.nispok.snackbar.SnackbarManager; import com.nispok.snackbar.SnackbarManager;
import com.nispok.snackbar.enums.SnackbarType;
import org.androidannotations.annotations.AfterViews; import org.androidannotations.annotations.AfterViews;
import org.androidannotations.annotations.Background; 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 * @param hasServerSettings Whether there are server settings available, so we can continue to connect
*/ */
private void updateFragmentVisibility(boolean hasServerSettings) { private void updateFragmentVisibility(boolean hasServerSettings) {
// TODO Hide hamburger icon?
if (fragmentDetails != null && fragmentDetails.isAdded()) { if (fragmentDetails != null && fragmentDetails.isAdded()) {
if (hasServerSettings) { if (hasServerSettings) {
getFragmentManager().beginTransaction().show(fragmentDetails).commit(); getFragmentManager().beginTransaction().show(fragmentDetails).commit();
@ -729,11 +729,13 @@ public class TorrentsActivity extends ActionBarActivity implements TorrentTasksE
@Click(R.id.addmenu_link_button) @Click(R.id.addmenu_link_button)
protected void startUrlEntryDialog() { protected void startUrlEntryDialog() {
UrlEntryDialog.startUrlEntry(this); addmenuButton.collapse();
UrlEntryDialog.show(this);
} }
@Click(R.id.addmenu_file_button) @Click(R.id.addmenu_file_button)
protected void startFilePicker() { protected void startFilePicker() {
addmenuButton.collapse();
FilePickerHelper.startFilePicker(this); FilePickerHelper.startFilePicker(this);
} }
@ -742,13 +744,28 @@ public class TorrentsActivity extends ActionBarActivity implements TorrentTasksE
public void onFilePicked(int resultCode, Intent data) { 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 // 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("")) { if (data != null && data.getData() != null && !data.getData().toString().equals("")) {
String url = data.getData().getPath(); Uri dataUri = data.getData();
addTorrentByFile(data.getData().toString(), url.substring(url.lastIndexOf("/")));
// 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) @Click(R.id.addmenu_barcode_button)
protected void startBarcodeScanner() { protected void startBarcodeScanner() {
addmenuButton.collapse();
BarcodeHelper.startBarcodeScanner(this, BarcodeHelper.ACTIVITY_BARCODE_ADDTORRENT); 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) { protected void onBarcodeScanHandled(String barcode, String result) {
log.d(this, "Scanned barcode " + barcode + " and got " + result); log.d(this, "Scanned barcode " + barcode + " and got " + result);
if (TextUtils.isEmpty(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")) { } else if (result.startsWith("http") || result.startsWith("https")) {
addTorrentByUrl(result, "QR code result"); // No torrent title known addTorrentByUrl(result, "QR code result"); // No torrent title known
} else if (navigationHelper.enableSearchUi()) { } else if (navigationHelper.enableSearchUi()) {
@ -1255,7 +1273,7 @@ public class TorrentsActivity extends ActionBarActivity implements TorrentTasksE
//noinspection ThrowableResultOfMethodCallIgnored //noinspection ThrowableResultOfMethodCallIgnored
log.i(this, result.getException().toString()); log.i(this, result.getException().toString());
String error = getString(LocalTorrent.getResourceForDaemonException(result.getException())); 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); fragmentTorrents.updateIsLoading(false);
if (isCritical) { if (isCritical) {
fragmentTorrents.updateError(error); fragmentTorrents.updateError(error);

2
app/src/main/java/org/transdroid/core/gui/navigation/SetLabelDialog.java

@ -93,8 +93,6 @@ public class SetLabelDialog extends DialogFragment {
if (currentLabels.size() == 0) { if (currentLabels.size() == 0) {
// Hide the list (and its label) if there are no labels yet // 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.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); labelsList.setVisibility(View.GONE);
} else { } else {
labelsList.setAdapter(new FilterListItemAdapter(getActivity(), currentLabels)); labelsList.setAdapter(new FilterListItemAdapter(getActivity(), currentLabels));

50
app/src/main/java/org/transdroid/core/gui/search/UrlEntryDialog.java

@ -16,21 +16,18 @@
*/ */
package org.transdroid.core.gui.search; 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.ClipboardManager;
import android.content.Context; import android.content.Context;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import android.net.Uri; import android.net.Uri;
import android.os.Build;
import android.text.InputType; import android.text.InputType;
import android.text.TextUtils; import android.text.TextUtils;
import android.view.inputmethod.InputMethodManager; import android.view.LayoutInflater;
import android.view.View;
import android.widget.EditText; import android.widget.EditText;
import com.afollestad.materialdialogs.MaterialDialog;
import org.transdroid.R;
import org.transdroid.core.gui.TorrentsActivity; import org.transdroid.core.gui.TorrentsActivity;
import org.transdroid.core.gui.navigation.NavigationHelper; import org.transdroid.core.gui.navigation.NavigationHelper;
@ -41,25 +38,20 @@ public class UrlEntryDialog {
* TorrentsActivity#addTorrentByUrl(String, String) method}. * TorrentsActivity#addTorrentByUrl(String, String) method}.
* @param activity The activity that opens (and owns) this dialog * @param activity The activity that opens (and owns) this dialog
*/ */
@SuppressLint("ValidFragment") public static void show(final TorrentsActivity activity) {
public static void startUrlEntry(final TorrentsActivity activity) { View inputLayout = LayoutInflater.from(activity).inflate(R.layout.dialog_url, null);
new DialogFragment() { final EditText urlEdit = (EditText) inputLayout.findViewById(R.id.url_edit);
@TargetApi(Build.VERSION_CODES.HONEYCOMB) urlEdit.setInputType(InputType.TYPE_TEXT_VARIATION_URI);
public android.app.Dialog onCreateDialog(android.os.Bundle savedInstanceState) { ClipboardManager clipboard = (ClipboardManager) activity.getSystemService(Context.CLIPBOARD_SERVICE);
final EditText urlInput = new EditText(activity); if (clipboard.hasPrimaryClip() && clipboard.getPrimaryClip().getItemCount() > 0) {
urlInput.setInputType(InputType.TYPE_TEXT_VARIATION_URI); CharSequence content = clipboard.getPrimaryClip().getItemAt(0).coerceToText(activity);
ClipboardManager clipboard = (ClipboardManager) activity.getSystemService(Context.CLIPBOARD_SERVICE); urlEdit.setText(content);
if (clipboard.hasPrimaryClip() && clipboard.getPrimaryClip().getItemCount() > 0) { }
CharSequence content = clipboard.getPrimaryClip().getItemAt(0).coerceToText(activity); new MaterialDialog.Builder(activity).customView(inputLayout, false).positiveText(android.R.string.ok).negativeText(android.R.string.cancel)
urlInput.setText(content); .callback(new MaterialDialog.ButtonCallback() {
}
((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() {
@Override @Override
public void onClick(DialogInterface dialog, int which) { public void onPositive(MaterialDialog dialog) {
// Assume text entry box input as URL and treat the filename (after the last /) as title String url = urlEdit.getText().toString();
String url = urlInput.getText().toString();
Uri uri = Uri.parse(url); Uri uri = Uri.parse(url);
if (!TextUtils.isEmpty(url)) { if (!TextUtils.isEmpty(url)) {
String title = NavigationHelper.extractNameFromUri(uri); String title = NavigationHelper.extractNameFromUri(uri);
@ -70,11 +62,7 @@ public class UrlEntryDialog {
} }
} }
} }
}).setNegativeButton(android.R.string.cancel, null).create(); }).show();
}
;
}.show(activity.getFragmentManager(), "urlentry");
} }
} }

32
app/src/main/res/layout/dialog_setlabel.xml

@ -16,44 +16,36 @@
along with Transdroid. If not, see <http://www.gnu.org/licenses/>. along with Transdroid. If not, see <http://www.gnu.org/licenses/>.
--> -->
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:padding="@dimen/margin_half" android:padding="@dimen/margin_default"
android:orientation="vertical" > android:orientation="vertical">
<TextView <TextView
android:id="@+id/pick_label" android:id="@+id/pick_label"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:text="@string/status_label_pick" android:text="@string/status_label_pick"
android:textAllCaps="true" /> android:layout_marginBottom="@dimen/margin_half"
style="@style/SectionHeader"/>
<View
android:id="@+id/line1"
android:layout_width="match_parent"
android:layout_height="1dip"
android:background="#28000000" />
<ListView <ListView
android:id="@+id/labels_list" android:id="@+id/labels_list"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="0dip" android:layout_height="0dip"
android:layout_weight="1" android:layout_weight="1"
android:listSelector="?attr/activatable_background" /> android:listSelector="?attr/activatable_background"
tools:listitem="@layout/list_item_simple"/>
<View
android:id="@+id/line2"
android:layout_width="match_parent"
android:layout_height="1dip"
android:background="#28000000" />
<TextView <TextView
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginTop="@dimen/margin_half" android:layout_marginTop="@dimen/margin_default"
android:text="@string/status_label_new" android:text="@string/status_label_new"
android:textAllCaps="true" /> android:layout_marginBottom="@dimen/margin_half"
style="@style/SectionHeader"/>
<EditText <EditText
android:id="@+id/newlabel_edit" android:id="@+id/newlabel_edit"
android:layout_width="match_parent" android:layout_width="match_parent"

32
app/src/main/res/layout/dialog_url.xml

@ -0,0 +1,32 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
Copyright 2010-2013 Eric Kok et al.
Transdroid is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Transdroid is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Transdroid. If not, see <http://www.gnu.org/licenses/>.
-->
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="@dimen/margin_default">
<EditText
android:id="@+id/url_edit"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/navigation_url_hint"
android:inputType="textUri"
android:singleLine="true" />
</FrameLayout>

1
app/src/main/res/values/strings.xml

@ -96,6 +96,7 @@
<string name="navigation_selectfinished">Select finished</string> <string name="navigation_selectfinished">Select finished</string>
<string name="navigation_invertselection">Invert selection</string> <string name="navigation_invertselection">Invert selection</string>
<string name="navigation_pickserver">Add torrent to&#8230;</string> <string name="navigation_pickserver">Add torrent to&#8230;</string>
<string name="navigation_url_hint" translatable="false">http://…</string>
<string name="status_status">STATUS: %1$s</string> <string name="status_status">STATUS: %1$s</string>
<string name="status_waiting">Waiting to check&#8230;</string> <string name="status_waiting">Waiting to check&#8230;</string>

Loading…
Cancel
Save