Browse Source

Replacing Holo design with Material design in dialogs.

material
Eric Kok 10 years ago
parent
commit
3506705a82
  1. 5
      app/src/main/java/org/transdroid/core/gui/DetailsActivity.java
  2. 12
      app/src/main/java/org/transdroid/core/gui/DetailsFragment.java
  3. 6
      app/src/main/java/org/transdroid/core/gui/ServerStatusView.java
  4. 20
      app/src/main/java/org/transdroid/core/gui/TorrentsActivity.java
  5. 3
      app/src/main/java/org/transdroid/core/gui/TorrentsFragment.java
  6. 100
      app/src/main/java/org/transdroid/core/gui/navigation/SetLabelDialog.java
  7. 70
      app/src/main/java/org/transdroid/core/gui/navigation/SetStorageLocationDialog.java
  8. 73
      app/src/main/java/org/transdroid/core/gui/navigation/SetTrackersDialog.java
  9. 94
      app/src/main/java/org/transdroid/core/gui/navigation/SetTransferRatesDialog.java
  10. 4
      app/src/main/java/org/transdroid/core/gui/rss/RssfeedsActivity.java
  11. 2
      app/src/main/java/org/transdroid/core/gui/rss/RssitemsFragment.java
  12. 2
      app/src/main/java/org/transdroid/core/gui/search/SearchResultsFragment.java
  13. 1
      app/src/main/java/org/transdroid/core/gui/search/UrlEntryDialog.java
  14. 10
      app/src/main/java/org/transdroid/core/gui/settings/SystemSettingsActivity.java
  15. 2
      app/src/main/java/org/transdroid/core/seedbox/XirvikSharedSettingsActivity.java
  16. 13
      app/src/main/res/layout/actionbar_serverstatus.xml
  17. 1
      app/src/main/res/layout/dialog_setlabel.xml
  18. 2
      app/src/main/res/layout/dialog_storagelocation.xml
  19. 2
      app/src/main/res/layout/dialog_trackers.xml
  20. 57
      app/src/main/res/layout/dialog_transferrates.xml
  21. 1
      app/src/main/res/layout/dialog_url.xml
  22. 3
      app/src/main/res/values/colors.xml
  23. 1
      app/src/main/res/values/styles_transdroid_light.xml

5
app/src/main/java/org/transdroid/core/gui/DetailsActivity.java

@ -22,7 +22,6 @@ import android.os.Build; @@ -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 @@ -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 @@ -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

12
app/src/main/java/org/transdroid/core/gui/DetailsFragment.java

@ -37,6 +37,7 @@ import android.widget.TextView; @@ -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 @@ -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 @@ -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 @@ -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;

6
app/src/main/java/org/transdroid/core/gui/ServerStatusView.java

@ -27,7 +27,6 @@ import com.nispok.snackbar.SnackbarManager; @@ -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 @@ -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 @@ -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));
}
}

20
app/src/main/java/org/transdroid/core/gui/TorrentsActivity.java

@ -648,7 +648,7 @@ public class TorrentsActivity extends ActionBarActivity implements TorrentTasksE @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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);

3
app/src/main/java/org/transdroid/core/gui/TorrentsFragment.java

@ -355,8 +355,7 @@ public class TorrentsFragment extends Fragment implements OnLabelPickedListener @@ -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;

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

@ -16,110 +16,80 @@ @@ -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<? extends SimpleListItem> 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<Label> currentLabels) {
/**
* Sets the list of currently known labels as are active on the server. These are offered to the user to pick a new label for the target
* torrents.
* @param currentLabels The list of torrent labels
* @return This dialog, for method chaining
*/
public SetLabelDialog setCurrentLabels(List<Label> currentLabels) {
// Discard the empty label in this list before storing it locally
for (Iterator<Label> iter = currentLabels.iterator(); iter.hasNext(); ) {
if (iter.next().isEmptyLabel()) {
iter.remove();
}
}
this.currentLabels = currentLabels;
return this;
}
final View setLabelLayout = LayoutInflater.from(context).inflate(R.layout.dialog_setlabel, null);
final ListView labelsList = (ListView) setLabelLayout.findViewById(R.id.labels_list);
final EditText newLabelEdit = (EditText) setLabelLayout.findViewById(R.id.newlabel_edit);
final MaterialDialog dialog = new MaterialDialog.Builder(context).customView(setLabelLayout, false).positiveText(R.string.status_update)
.neutralText(R.string.status_label_remove).negativeText(android.R.string.cancel).callback(new MaterialDialog.ButtonCallback() {
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
if (onLabelPickedListener == null) {
throw new InvalidParameterException("Please first set the callback listener using setOnLabelPickedListener before opening the dialog.");
public void onPositive(MaterialDialog dialog) {
// User should have provided a new label
if (TextUtils.isEmpty(newLabelEdit.getText())) {
SnackbarManager.show(Snackbar.with(context).text(R.string.error_notalabel).colorResource(R.color.red));
return;
}
onLabelPickedListener.onLabelPicked(newLabelEdit.getText().toString());
}
if (currentLabels == null) {
throw new InvalidParameterException(
"Please first set the list of currently known labels before opening the dialog, even if the list is empty.");
@Override
public void onNeutral(MaterialDialog dialog) {
onLabelPickedListener.onLabelPicked(null);
}
final View setlabelFrame = getActivity().getLayoutInflater().inflate(R.layout.dialog_setlabel, null, false);
final ListView labelsList = (ListView) setlabelFrame.findViewById(R.id.labels_list);
final EditText newlabelEdit = (EditText) setlabelFrame.findViewById(R.id.newlabel_edit);
}).build();
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);
setLabelLayout.findViewById(R.id.pick_label).setVisibility(View.GONE);
labelsList.setVisibility(View.GONE);
} else {
labelsList.setAdapter(new FilterListItemAdapter(getActivity(), currentLabels));
labelsList.setAdapter(new FilterListItemAdapter(context, currentLabels));
labelsList.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
onLabelPickedListener.onLabelPicked(((Label) labelsList.getItemAtPosition(position)).getName());
dismiss();
dialog.dismiss();
}
});
}
return new AlertDialog.Builder(getActivity()).setView(setlabelFrame).setPositiveButton(R.string.status_update, new OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
// User should have provided a new label
if (newlabelEdit.getText().toString().equals("")) {
SnackbarManager.show(Snackbar.with(getActivity()).text(R.string.error_notalabel).colorResource(R.color.crouton_error));
return;
}
onLabelPickedListener.onLabelPicked(newlabelEdit.getText().toString());
}
}).setNeutralButton(R.string.status_label_remove, new OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
onLabelPickedListener.onLabelPicked(null);
}
}).setNegativeButton(android.R.string.cancel, null).show();
dialog.show();
}
public interface OnLabelPickedListener {

70
app/src/main/java/org/transdroid/core/gui/navigation/SetStorageLocationDialog.java

@ -16,73 +16,35 @@ @@ -16,73 +16,35 @@
*/
package org.transdroid.core.gui.navigation;
import java.security.InvalidParameterException;
import org.transdroid.R;
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.view.LayoutInflater;
import android.view.View;
import android.widget.EditText;
/**
* A dialog fragment that allows changing of the storage location by editing the path text directly.
* @author Eric Kok
*/
public class SetStorageLocationDialog extends DialogFragment {
import com.afollestad.materialdialogs.MaterialDialog;
private OnStorageLocationUpdatedListener onStorageLocationUpdatedListener = null;
private String currentLocation = null;
import org.transdroid.R;
public SetStorageLocationDialog() {
setRetainInstance(true);
}
public class SetStorageLocationDialog {
/**
* Sets the callback for when the user is done updating the storage location.
* @param onStorageLocationUpdatedListener The event listener to this dialog
* @return This dialog, for method chaining
*/
public SetStorageLocationDialog setOnStorageLocationUpdated(
OnStorageLocationUpdatedListener onStorageLocationUpdatedListener) {
this.onStorageLocationUpdatedListener = onStorageLocationUpdatedListener;
return this;
}
/**
* Sets the current storage location that will be available to the user to edit
* @param currentLocation The current storage location path as text
* @return This dialog, for method chaining
* A dialog fragment that allows changing of the storage location by editing the path text directly.
* @param context The activity context that opens (and owns) this dialog
* @param onStorageLocationUpdatedListener The callback for when the user is done updating the storage location
* @param currentLocation The current storage location that will be available to the user to edit
*/
public SetStorageLocationDialog setCurrentLocation(String currentLocation) {
this.currentLocation = currentLocation;
return this;
}
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
if (currentLocation == null)
throw new InvalidParameterException(
"Please first set the current trackers text using setCurrentLocation before opening the dialog.");
if (onStorageLocationUpdatedListener == null)
throw new InvalidParameterException(
"Please first set the callback listener using setOnStorageLocationUpdated before opening the dialog.");
final View locationFrame = getActivity().getLayoutInflater().inflate(R.layout.dialog_storagelocation, null,
false);
final EditText locationText = (EditText) locationFrame.findViewById(R.id.location_edit);
public static void show(final Context context, final OnStorageLocationUpdatedListener onStorageLocationUpdatedListener, String currentLocation) {
View locationLayout = LayoutInflater.from(context).inflate(R.layout.dialog_storagelocation, null);
final EditText locationText = (EditText) locationLayout.findViewById(R.id.location_edit);
locationText.setText(currentLocation);
return new AlertDialog.Builder(getActivity()).setView(locationFrame)
.setPositiveButton(R.string.status_update, new OnClickListener() {
new MaterialDialog.Builder(context).customView(locationLayout, false).positiveText(R.string.status_update)
.negativeText(android.R.string.cancel).callback(new MaterialDialog.ButtonCallback() {
@Override
public void onClick(DialogInterface dialog, int which) {
public void onPositive(MaterialDialog dialog) {
// User is done editing and requested to update given the text input
onStorageLocationUpdatedListener.onStorageLocationUpdated(locationText.getText().toString());
}
}).setNegativeButton(android.R.string.cancel, null).show();
}).show();
}
public interface OnStorageLocationUpdatedListener {

73
app/src/main/java/org/transdroid/core/gui/navigation/SetTrackersDialog.java

@ -16,74 +16,39 @@ @@ -16,74 +16,39 @@
*/
package org.transdroid.core.gui.navigation;
import java.security.InvalidParameterException;
import java.util.Arrays;
import java.util.List;
import org.transdroid.R;
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.view.LayoutInflater;
import android.view.View;
import android.widget.EditText;
/**
* A dialog fragment that allows changing the trackers of a torrent by editing the text directly.
* @author Eric Kok
*/
public class SetTrackersDialog extends DialogFragment {
import com.afollestad.materialdialogs.MaterialDialog;
private OnTrackersUpdatedListener onTrackersUpdatedListener = null;
private String currentTrackers = null;
import org.transdroid.R;
public SetTrackersDialog() {
setRetainInstance(true);
}
import java.util.Arrays;
import java.util.List;
/**
* Sets the callback for when the user is done updating the trackers list.
* @param onTrackersUpdatedListener The event listener to this dialog
* @return This dialog, for method chaining
*/
public SetTrackersDialog setOnTrackersUpdated(OnTrackersUpdatedListener onTrackersUpdatedListener) {
this.onTrackersUpdatedListener = onTrackersUpdatedListener;
return this;
}
public class SetTrackersDialog extends DialogFragment {
/**
* Sets the current trackers text/list that will be available to the user to edit
* @param currentTrackers The current trackers for the target torrent
* @return This dialog, for method chaining
* A dialog fragment that allows changing the trackers of a torrent by editing the text directly.
* @param context The activity context that opens (and owns) this dialog
* @param onTrackersUpdatedListener The callback for when the user is done updating the trackers list
* @param currentTrackers The current trackers text/list that will be available to the user to edit
*/
public SetTrackersDialog setCurrentTrackers(String currentTrackers) {
this.currentTrackers = currentTrackers;
return this;
}
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
if (currentTrackers == null)
throw new InvalidParameterException(
"Please first set the current trackers text using setCurrentTrackers before opening the dialog.");
if (onTrackersUpdatedListener == null)
throw new InvalidParameterException(
"Please first set the callback listener using setOnTrackersUpdated before opening the dialog.");
final View trackersFrame = getActivity().getLayoutInflater().inflate(R.layout.dialog_trackers, null, false);
final EditText trackersText = (EditText) trackersFrame.findViewById(R.id.trackers_edit);
public static void show(final Context context, final OnTrackersUpdatedListener onTrackersUpdatedListener, String currentTrackers) {
View trackersLayout = LayoutInflater.from(context).inflate(R.layout.dialog_trackers, null);
final EditText trackersText = (EditText) trackersLayout.findViewById(R.id.trackers_edit);
trackersText.setText(currentTrackers);
return new AlertDialog.Builder(getActivity()).setView(trackersFrame)
.setPositiveButton(R.string.status_update, new OnClickListener() {
new MaterialDialog.Builder(context).customView(trackersLayout, false).positiveText(R.string.status_update)
.negativeText(android.R.string.cancel).callback(new MaterialDialog.ButtonCallback() {
@Override
public void onClick(DialogInterface dialog, int which) {
public void onPositive(MaterialDialog dialog) {
// User is done editing and requested to update given the text input
onTrackersUpdatedListener.onTrackersUpdated(Arrays.asList(trackersText.getText().toString()
.split("\n")));
onTrackersUpdatedListener.onTrackersUpdated(Arrays.asList(trackersText.getText().toString().split("\n")));
}
}).setNegativeButton(android.R.string.cancel, null).show();
}).show();
}
public interface OnTrackersUpdatedListener {

94
app/src/main/java/org/transdroid/core/gui/navigation/SetTransferRatesDialog.java

@ -16,93 +16,64 @@ @@ -16,93 +16,64 @@
*/
package org.transdroid.core.gui.navigation;
import java.security.InvalidParameterException;
import org.transdroid.R;
import android.app.Dialog;
import android.app.DialogFragment;
import android.os.Bundle;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.widget.Button;
import android.widget.TextView;
/**
* A dialog fragment that allow picking of maximum download and upload transfer rates as well as the resetting of these
* values.
* @author Eric Kok
*/
public class SetTransferRatesDialog extends DialogFragment {
import com.afollestad.materialdialogs.MaterialDialog;
private OnRatesPickedListener onRatesPickedListener = null;
private TextView maxSpeedDown, maxSpeedUp;
import org.transdroid.R;
public SetTransferRatesDialog() {
setRetainInstance(true);
}
public class SetTransferRatesDialog {
/**
* Sets the callback for results in this dialog (with newly selected values or a reset).
* @param onRatesPickedListener The event listener to this dialog
* @return This dialog, for method chaining
* A dialog fragment that allow picking of maximum download and upload transfer rates as well as the resetting of these values.
* @param context The activity context that opens (and owns) this dialog
* @param onRatesPickedListener The callback for results in this dialog (with newly selected values or a reset)
*/
public SetTransferRatesDialog setOnRatesPickedListener(OnRatesPickedListener onRatesPickedListener) {
this.onRatesPickedListener = onRatesPickedListener;
return this;
}
public static void show(final Context context, final OnRatesPickedListener onRatesPickedListener) {
View transferRatesLayout = LayoutInflater.from(context).inflate(R.layout.dialog_transferrates, null);
final TextView maxSpeedDown = (TextView) transferRatesLayout.findViewById(R.id.maxspeeddown_text);
final TextView maxSpeedUp = (TextView) transferRatesLayout.findViewById(R.id.maxspeedup_text);
MaterialDialog dialog = new MaterialDialog.Builder(context).customView(transferRatesLayout, false).positiveText(R.string.status_update)
.neutralText(R.string.status_maxspeed_reset).negativeText(android.R.string.cancel).callback(new MaterialDialog.ButtonCallback() {
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
if (onRatesPickedListener == null)
throw new InvalidParameterException(
"Please first set the callback listener using setOnRatesPickedListener before opening the dialog.");
final View transferRatesContent = getActivity().getLayoutInflater().inflate(R.layout.dialog_transferrates,
null, false);
maxSpeedDown = (TextView) transferRatesContent.findViewById(R.id.maxspeeddown_text);
maxSpeedUp = (TextView) transferRatesContent.findViewById(R.id.maxspeedup_text);
bindButtons(transferRatesContent, maxSpeedDown, R.id.down1Button, R.id.down2Button, R.id.down3Button,
R.id.down4Button, R.id.down5Button, R.id.down6Button, R.id.down7Button, R.id.down8Button,
R.id.down9Button, R.id.down0Button);
bindButtons(transferRatesContent, maxSpeedUp, R.id.up1Button, R.id.up2Button, R.id.up3Button, R.id.up4Button,
R.id.up5Button, R.id.up6Button, R.id.up7Button, R.id.up8Button, R.id.up9Button, R.id.up0Button);
((Button) transferRatesContent.findViewById(R.id.ok_button)).setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
public void onPositive(MaterialDialog dialog) {
int maxDown = -1, maxUp = -1;
try {
maxDown = Integer.parseInt(maxSpeedDown.getText().toString());
maxUp = Integer.parseInt(maxSpeedUp.getText().toString());
} catch (NumberFormatException e) {
// Impossible as we only input via the number buttons
}
if (maxDown <= 0 || maxUp <= 0) {
onRatesPickedListener.onInvalidNumber();
return;
}
onRatesPickedListener.onRatesPicked(maxDown, maxUp);
dismiss();
}
});
((Button) transferRatesContent.findViewById(R.id.reset_button)).setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
public void onNeutral(MaterialDialog dialog) {
onRatesPickedListener.resetRates();
dismiss();
}
});
((Button) transferRatesContent.findViewById(R.id.cancel_button)).setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
dismiss();
}
});
Dialog dialog = new Dialog(getActivity());
dialog.getWindow().requestFeature(Window.FEATURE_NO_TITLE);
dialog.setContentView(transferRatesContent);
return dialog;
}).build();
bindButtons(dialog.getCustomView(), maxSpeedDown, R.id.down1Button, R.id.down2Button, R.id.down3Button, R.id.down4Button, R.id.down5Button,
R.id.down6Button, R.id.down7Button, R.id.down8Button, R.id.down9Button, R.id.down0Button);
bindButtons(dialog.getCustomView(), maxSpeedUp, R.id.up1Button, R.id.up2Button, R.id.up3Button, R.id.up4Button, R.id.up5Button,
R.id.up6Button, R.id.up7Button, R.id.up8Button, R.id.up9Button, R.id.up0Button);
dialog.show();
}
private void bindButtons(View transferRatesContent, View numberView, int... buttonResource) {
private static void bindButtons(View transferRatesContent, View numberView, int... buttonResource) {
for (int i : buttonResource) {
// Keep the relevant number as reference in the view tag and bind the click listerner
transferRatesContent.findViewById(i).setTag(numberView);
@ -110,14 +81,15 @@ public class SetTransferRatesDialog extends DialogFragment { @@ -110,14 +81,15 @@ public class SetTransferRatesDialog extends DialogFragment {
}
}
private android.view.View.OnClickListener onNumberClicked = new android.view.View.OnClickListener() {
private static OnClickListener onNumberClicked = new OnClickListener() {
@Override
public void onClick(View v) {
// Append the text contents of the button itself as text to the current number (as reference in the view's
// tag)
TextView numberView = (TextView) v.getTag();
if (numberView.getText().toString().equals(getString(R.string.status_maxspeed_novalue)))
if (numberView.getText().toString().equals(v.getContext().getString(R.string.status_maxspeed_novalue))) {
numberView.setText("");
}
numberView.setText(numberView.getText().toString() + ((Button) v).getText().toString());
}
};

4
app/src/main/java/org/transdroid/core/gui/rss/RssfeedsActivity.java

@ -168,11 +168,11 @@ public class RssfeedsActivity extends ActionBarActivity { @@ -168,11 +168,11 @@ public class RssfeedsActivity extends ActionBarActivity {
// Error message or not yet loaded? Show a toast message instead of opening the items activity
if (loader.hasError()) {
SnackbarManager.show(Snackbar.with(this).text(R.string.rss_error).colorResource(R.color.crouton_error));
SnackbarManager.show(Snackbar.with(this).text(R.string.rss_error).colorResource(R.color.red));
return;
}
if (loader.getChannel() == null || loader.getChannel().getItems().size() == 0) {
SnackbarManager.show(Snackbar.with(this).text(R.string.rss_notloaded).colorResource(R.color.crouton_error));
SnackbarManager.show(Snackbar.with(this).text(R.string.rss_notloaded).colorResource(R.color.red));
return;
}

2
app/src/main/java/org/transdroid/core/gui/rss/RssitemsFragment.java

@ -155,7 +155,7 @@ public class RssitemsFragment extends Fragment { @@ -155,7 +155,7 @@ public class RssitemsFragment extends Fragment {
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(first.getLink())));
} else {
// No URL was specified in the RSS feed item link tag (or no link tag was present)
SnackbarManager.show(Snackbar.with(getActivity()).text(R.string.error_no_link).colorResource(R.color.crouton_error));
SnackbarManager.show(Snackbar.with(getActivity()).text(R.string.error_no_link).colorResource(R.color.red));
}
} else if (itemId == R.id.action_useassearch) {
// Use the RSS item title to start a new search (mimicking the search manager style)

2
app/src/main/java/org/transdroid/core/gui/search/SearchResultsFragment.java

@ -131,7 +131,7 @@ public class SearchResultsFragment extends Fragment { @@ -131,7 +131,7 @@ public class SearchResultsFragment extends Fragment {
@ItemClick(R.id.searchresults_list)
protected void onItemClicked(SearchResult item) {
if (item.getTorrentUrl() == null) {
SnackbarManager.show(Snackbar.with(getActivity()).text(R.string.error_notorrentfile).colorResource(R.color.crouton_error));
SnackbarManager.show(Snackbar.with(getActivity()).text(R.string.error_notorrentfile).colorResource(R.color.red));
return;
}
// Don't broadcast this intent; we can safely assume this is intended for Transdroid only

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

@ -41,7 +41,6 @@ public class UrlEntryDialog { @@ -41,7 +41,6 @@ public class UrlEntryDialog {
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);

10
app/src/main/java/org/transdroid/core/gui/settings/SystemSettingsActivity.java

@ -109,10 +109,10 @@ public class SystemSettingsActivity extends PreferenceActivity { @@ -109,10 +109,10 @@ public class SystemSettingsActivity extends PreferenceActivity {
SnackbarManager.show(Snackbar.with(SystemSettingsActivity.this).text(R.string.pref_import_success));
} catch (FileNotFoundException e) {
SnackbarManager
.show(Snackbar.with(SystemSettingsActivity.this).text(R.string.error_file_not_found).colorResource(R.color.crouton_error));
.show(Snackbar.with(SystemSettingsActivity.this).text(R.string.error_file_not_found).colorResource(R.color.red));
} catch (JSONException e) {
SnackbarManager.show(Snackbar.with(SystemSettingsActivity.this)
.text(getString(R.string.error_no_valid_settings_file, getString(R.string.app_name))).colorResource(R.color.crouton_error));
.text(getString(R.string.error_no_valid_settings_file, getString(R.string.app_name))).colorResource(R.color.red));
}
}
};
@ -131,7 +131,7 @@ public class SystemSettingsActivity extends PreferenceActivity { @@ -131,7 +131,7 @@ public class SystemSettingsActivity extends PreferenceActivity {
SnackbarManager.show(Snackbar.with(SystemSettingsActivity.this).text(R.string.pref_export_success));
} catch (JSONException | IOException e) {
SnackbarManager.show(Snackbar.with(SystemSettingsActivity.this).text(R.string.error_cant_write_settings_file)
.colorResource(R.color.crouton_error));
.colorResource(R.color.red));
}
}
};
@ -144,7 +144,7 @@ public class SystemSettingsActivity extends PreferenceActivity { @@ -144,7 +144,7 @@ public class SystemSettingsActivity extends PreferenceActivity {
BarcodeHelper.shareContentBarcode(SystemSettingsActivity.this, settings);
} catch (JSONException e) {
SnackbarManager.show(Snackbar.with(SystemSettingsActivity.this).text(R.string.error_cant_write_settings_file)
.colorResource(R.color.crouton_error));
.colorResource(R.color.red));
}
}
};
@ -188,7 +188,7 @@ public class SystemSettingsActivity extends PreferenceActivity { @@ -188,7 +188,7 @@ public class SystemSettingsActivity extends PreferenceActivity {
SnackbarManager.show(Snackbar.with(SystemSettingsActivity.this).text(R.string.pref_import_success));
} catch (JSONException e) {
SnackbarManager
.show(Snackbar.with(SystemSettingsActivity.this).text(R.string.error_file_not_found).colorResource(R.color.crouton_error));
.show(Snackbar.with(SystemSettingsActivity.this).text(R.string.error_file_not_found).colorResource(R.color.red));
}
}
}

2
app/src/main/java/org/transdroid/core/seedbox/XirvikSharedSettingsActivity.java

@ -121,7 +121,7 @@ public class XirvikSharedSettingsActivity extends KeyBoundPreferencesActivity { @@ -121,7 +121,7 @@ public class XirvikSharedSettingsActivity extends KeyBoundPreferencesActivity {
Editor edit = PreferenceManager.getDefaultSharedPreferences(XirvikSharedSettingsActivity.this).edit();
EditTextPreference pref = (EditTextPreference) findPreference("seedbox_xirvikshared_rpc_" + key);
if (result == null) {
SnackbarManager.show(Snackbar.with(this).text(R.string.pref_seedbox_xirviknofolder).colorResource(R.color.crouton_error));
SnackbarManager.show(Snackbar.with(this).text(R.string.pref_seedbox_xirviknofolder).colorResource(R.color.red));
edit.remove("seedbox_xirvikshared_rpc_" + key);
pref.setSummary("");
} else {

13
app/src/main/res/layout/actionbar_serverstatus.xml

@ -41,7 +41,7 @@ @@ -41,7 +41,7 @@
android:layout_width="@dimen/ui_serverstatus_width"
android:layout_height="wrap_content"
android:fontFamily="sans-serif-light"
android:gravity="right"
android:gravity="end"
android:textColor="?attr/text_actionbar"
android:textSize="@dimen/ui_serverstatus_bignumber"
tools:text="7"/>
@ -51,6 +51,7 @@ @@ -51,6 +51,7 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="@id/downcount_text"
android:layout_toEndOf="@id/downcount_text"
android:fontFamily="sans-serif-light"
android:text="↓"
android:textColor="?attr/text_actionbar"
@ -64,8 +65,9 @@ @@ -64,8 +65,9 @@
android:layout_width="@dimen/ui_serverstatus_width"
android:layout_height="wrap_content"
android:layout_toRightOf="@id/downcount_sign"
android:layout_toEndOf="@id/downcount_sign"
android:fontFamily="sans-serif-light"
android:gravity="right"
android:gravity="end"
android:textColor="?attr/text_actionbar"
android:textSize="@dimen/ui_serverstatus_bignumber"
tools:text="128"/>
@ -75,6 +77,7 @@ @@ -75,6 +77,7 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="@id/upcount_text"
android:layout_toEndOf="@id/upcount_text"
android:fontFamily="sans-serif-light"
android:text="↑"
android:textColor="?attr/text_actionbar"
@ -92,7 +95,7 @@ @@ -92,7 +95,7 @@
android:layout_below="@id/downcount_text"
android:layout_marginTop="-4dip"
android:fontFamily="sans-serif-light"
android:gravity="right"
android:gravity="end"
android:textColor="?attr/text_actionbar"
android:textSize="@dimen/ui_serverstatus_smallnumber"
tools:text="1.2 MB/s"/>
@ -102,11 +105,13 @@ @@ -102,11 +105,13 @@
android:layout_width="@dimen/ui_serverstatus_width"
android:layout_height="wrap_content"
android:layout_alignLeft="@id/upcount_text"
android:layout_alignStart="@id/upcount_text"
android:layout_alignRight="@id/upcount_sign"
android:layout_alignEnd="@id/upcount_sign"
android:layout_below="@id/upcount_text"
android:layout_marginTop="-4dip"
android:fontFamily="sans-serif-light"
android:gravity="right"
android:gravity="end"
android:textColor="?attr/text_actionbar"
android:textSize="@dimen/ui_serverstatus_smallnumber"
tools:text="678 KB/s"/>

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

@ -35,7 +35,6 @@ @@ -35,7 +35,6 @@
android:layout_width="match_parent"
android:layout_height="0dip"
android:layout_weight="1"
android:listSelector="?attr/activatable_background"
tools:listitem="@layout/list_item_simple"/>
<TextView

2
app/src/main/res/layout/dialog_storagelocation.xml

@ -18,7 +18,7 @@ @@ -18,7 +18,7 @@
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="@dimen/margin_half" >
android:padding="@dimen/margin_default">
<EditText
android:id="@+id/location_edit"

2
app/src/main/res/layout/dialog_trackers.xml

@ -18,7 +18,7 @@ @@ -18,7 +18,7 @@
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="@dimen/margin_half" >
android:padding="@dimen/margin_default">
<EditText
android:id="@+id/trackers_edit"

57
app/src/main/res/layout/dialog_transferrates.xml

@ -55,8 +55,8 @@ @@ -55,8 +55,8 @@
<View
android:layout_width="match_parent"
android:layout_height="1dip"
android:background="#28000000" />
android:layout_height="0.75dp"
android:background="@color/green_light" />
<LinearLayout
android:layout_width="match_parent"
@ -162,8 +162,8 @@ @@ -162,8 +162,8 @@
<View
android:layout_width="match_parent"
android:layout_height="1dip"
android:background="#28000000" />
android:layout_height="0.75dp"
android:background="@color/green_light" />
<LinearLayout
android:layout_width="match_parent"
@ -199,7 +199,7 @@ @@ -199,7 +199,7 @@
<View
android:layout_width="match_parent"
android:layout_height="1dip"
android:layout_height="0.75dp"
android:background="#28000000" />
<LinearLayout
@ -306,50 +306,7 @@ @@ -306,50 +306,7 @@
<View
android:layout_width="match_parent"
android:layout_height="1dip"
android:background="#28000000" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="48dp"
android:orientation="horizontal" >
<Button
android:id="@+id/cancel_button"
android:layout_width="0dip"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="?attr/activatable_background"
android:textSize="14sp"
android:text="@android:string/cancel" />
<View
android:layout_width="1dip"
android:layout_height="match_parent"
android:background="#28000000" />
<Button
android:id="@+id/reset_button"
android:layout_width="0dip"
android:layout_height="match_parent"
android:layout_weight="1"
android:textSize="14sp"
android:background="?attr/activatable_background"
android:text="@string/status_maxspeed_reset" />
<View
android:layout_width="1dip"
android:layout_height="match_parent"
android:background="#28000000" />
<Button
android:id="@+id/ok_button"
android:layout_width="0dip"
android:layout_height="match_parent"
android:layout_weight="1"
android:textSize="14sp"
android:background="?attr/activatable_background"
android:text="@android:string/ok" />
</LinearLayout>
android:layout_height="0.75dp"
android:background="@color/green_light" />
</LinearLayout>

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

@ -18,7 +18,6 @@ @@ -18,7 +18,6 @@
<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

3
app/src/main/res/values/colors.xml

@ -23,8 +23,7 @@ @@ -23,8 +23,7 @@
<color name="green_dark">#1B5E20</color>
<color name="grey">#757575</color>
<color name="ledgreen">#7dbb21</color>
<color name="crouton_error">#C62828</color>
<color name="crouton_info">#A5D6A7</color>
<color name="red">#C62828</color>
<!-- Torrent and file status colours -->
<color name="torrent_downloading">#1E88E5</color> <!-- Blue -->

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

@ -22,7 +22,6 @@ @@ -22,7 +22,6 @@
<style name="Theme.Transdroid.Light" parent="Theme.AppCompat.Light.NoActionBar">
<item name="colorPrimary">@color/green</item>
<item name="colorPrimaryDark">@color/green_dark</item>
<item name="colorAccent">@color/green_light</item>
<item name="colorControlHighlight">@color/green_light</item>
<item name="windowActionModeOverlay">true</item>
<item name="actionModeBackground">@color/grey</item>

Loading…
Cancel
Save