Browse Source

Replaced Croutons with Snackbars.

material
Eric Kok 9 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; @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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);

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

@ -93,8 +93,6 @@ public class SetLabelDialog extends DialogFragment { @@ -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));

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

@ -16,21 +16,18 @@ @@ -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 { @@ -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 { @@ -70,11 +62,7 @@ public class UrlEntryDialog {
}
}
}
}).setNegativeButton(android.R.string.cancel, null).create();
}
;
}.show(activity.getFragmentManager(), "urlentry");
}).show();
}
}

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

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

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

@ -0,0 +1,32 @@ @@ -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 @@ @@ -96,6 +96,7 @@
<string name="navigation_selectfinished">Select finished</string>
<string name="navigation_invertselection">Invert selection</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_waiting">Waiting to check&#8230;</string>

Loading…
Cancel
Save