Browse Source

Revert some unnecessary changes

pull/422/head
Alon Albert 7 years ago
parent
commit
4a64c32113
  1. 126
      app/src/main/java/org/transdroid/core/gui/TorrentsActivity.java

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

@ -16,17 +16,31 @@
*/ */
package org.transdroid.core.gui; package org.transdroid.core.gui;
import java.io.File; import android.annotation.TargetApi;
import java.io.FileNotFoundException; import android.app.SearchManager;
import java.io.FileOutputStream; import android.content.ContentResolver;
import java.io.IOException; import android.content.Intent;
import java.io.InputStream; import android.net.Uri;
import java.io.UnsupportedEncodingException; import android.os.AsyncTask;
import java.net.URLDecoder; import android.os.Build;
import java.util.ArrayList; import android.os.Bundle;
import java.util.List; import android.support.annotation.NonNull;
import java.util.Map; import android.support.v4.view.MenuItemCompat;
import java.util.Map.Entry; import android.support.v4.widget.DrawerLayout;
import android.support.v7.app.ActionBarDrawerToggle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.ActionMenuView;
import android.support.v7.widget.SearchView;
import android.support.v7.widget.Toolbar;
import android.text.TextUtils;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ListView;
import com.getbase.floatingactionbutton.FloatingActionButton; import com.getbase.floatingactionbutton.FloatingActionButton;
import com.getbase.floatingactionbutton.FloatingActionsMenu; import com.getbase.floatingactionbutton.FloatingActionsMenu;
@ -114,31 +128,17 @@ import org.transdroid.daemon.task.StartTask;
import org.transdroid.daemon.task.StopTask; import org.transdroid.daemon.task.StopTask;
import org.transdroid.daemon.util.HttpHelper; import org.transdroid.daemon.util.HttpHelper;
import android.annotation.TargetApi; import java.io.File;
import android.app.SearchManager; import java.io.FileNotFoundException;
import android.content.ContentResolver; import java.io.FileOutputStream;
import android.content.Intent; import java.io.IOException;
import android.net.Uri; import java.io.InputStream;
import android.os.AsyncTask; import java.io.UnsupportedEncodingException;
import android.os.Build; import java.net.URLDecoder;
import android.os.Bundle; import java.util.ArrayList;
import android.support.annotation.NonNull; import java.util.List;
import android.support.v4.view.MenuItemCompat; import java.util.Map;
import android.support.v4.widget.DrawerLayout; import java.util.Map.Entry;
import android.support.v7.app.ActionBarDrawerToggle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.ActionMenuView;
import android.support.v7.widget.SearchView;
import android.support.v7.widget.Toolbar;
import android.text.TextUtils;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ListView;
/** /**
* Main activity that holds the fragment that shows the torrents list, presents a way to filter the list (via an action bar spinner or list side list) * Main activity that holds the fragment that shows the torrents list, presents a way to filter the list (via an action bar spinner or list side list)
@ -955,7 +955,7 @@ public class TorrentsActivity extends AppCompatActivity implements TorrentTasksE
if (result instanceof RetrieveTaskSuccessResult) { if (result instanceof RetrieveTaskSuccessResult) {
onTorrentsRetrieved(((RetrieveTaskSuccessResult) result).getTorrents(), ((RetrieveTaskSuccessResult) result).getLabels()); onTorrentsRetrieved(((RetrieveTaskSuccessResult) result).getTorrents(), ((RetrieveTaskSuccessResult) result).getLabels());
} else { } else {
onCommunicationError(((DaemonTaskFailureResult) result).getException(), true); onCommunicationError((DaemonTaskFailureResult) result, true);
} }
} }
@ -973,7 +973,7 @@ public class TorrentsActivity extends AppCompatActivity implements TorrentTasksE
if (result instanceof GetTorrentDetailsTaskSuccessResult) { if (result instanceof GetTorrentDetailsTaskSuccessResult) {
onTorrentDetailsRetrieved(torrent, ((GetTorrentDetailsTaskSuccessResult) result).getTorrentDetails()); onTorrentDetailsRetrieved(torrent, ((GetTorrentDetailsTaskSuccessResult) result).getTorrentDetails());
} else { } else {
onCommunicationError(((DaemonTaskFailureResult) result).getException(), false); onCommunicationError((DaemonTaskFailureResult) result, false);
} }
} }
@ -991,7 +991,7 @@ public class TorrentsActivity extends AppCompatActivity implements TorrentTasksE
if (result instanceof GetFileListTaskSuccessResult) { if (result instanceof GetFileListTaskSuccessResult) {
onTorrentFilesRetrieved(torrent, ((GetFileListTaskSuccessResult) result).getFiles()); onTorrentFilesRetrieved(torrent, ((GetFileListTaskSuccessResult) result).getFiles());
} else { } else {
onCommunicationError(((DaemonTaskFailureResult) result).getException(), false); onCommunicationError((DaemonTaskFailureResult) result, false);
} }
} }
@ -1006,7 +1006,7 @@ public class TorrentsActivity extends AppCompatActivity implements TorrentTasksE
if (result instanceof GetStatsTaskSuccessResult) { if (result instanceof GetStatsTaskSuccessResult) {
onTurtleModeRetrieved(((GetStatsTaskSuccessResult) result).isAlternativeModeEnabled()); onTurtleModeRetrieved(((GetStatsTaskSuccessResult) result).isAlternativeModeEnabled());
} else { } else {
onCommunicationError(((DaemonTaskFailureResult) result).getException(), false); onCommunicationError((DaemonTaskFailureResult) result, false);
} }
} }
@ -1022,7 +1022,7 @@ public class TorrentsActivity extends AppCompatActivity implements TorrentTasksE
// Success; no need to retrieve it again - just update the visual indicator // Success; no need to retrieve it again - just update the visual indicator
onTurtleModeRetrieved(enable); onTurtleModeRetrieved(enable);
} else { } else {
onCommunicationError(((DaemonTaskFailureResult) result).getException(), false); onCommunicationError((DaemonTaskFailureResult) result, false);
} }
} }
@ -1033,7 +1033,7 @@ public class TorrentsActivity extends AppCompatActivity implements TorrentTasksE
onTaskSucceeded((DaemonTaskSuccessResult) result, getString(R.string.result_added, title)); onTaskSucceeded((DaemonTaskSuccessResult) result, getString(R.string.result_added, title));
refreshTorrents(); refreshTorrents();
} else { } else {
onCommunicationError(((DaemonTaskFailureResult) result).getException(), false); onCommunicationError((DaemonTaskFailureResult) result, false);
} }
} }
@ -1047,16 +1047,16 @@ public class TorrentsActivity extends AppCompatActivity implements TorrentTasksE
// Ignore: UTF-8 is always available on Android devices // Ignore: UTF-8 is always available on Android devices
} catch (IllegalArgumentException e) { } catch (IllegalArgumentException e) {
// Illegal character or escape sequence; fail task to show error // Illegal character or escape sequence; fail task to show error
onCommunicationError(new DaemonException(DaemonException.ExceptionType.FileAccessError, onCommunicationError(new DaemonTaskFailureResult(AddByMagnetUrlTask.create(currentConnection, url),
"Invalid characters in magnet link"), false); new DaemonException(DaemonException.ExceptionType.FileAccessError, "Invalid characters in magnet link")), false);
return; return;
} }
AddByMagnetUrlTask addByMagnetUrlTask = AddByMagnetUrlTask.create(currentConnection, url); AddByMagnetUrlTask addByMagnetUrlTask = AddByMagnetUrlTask.create(currentConnection, url);
if (!Daemon.supportsAddByMagnetUrl(currentConnection.getType())) { if (!Daemon.supportsAddByMagnetUrl(currentConnection.getType())) {
// No support for magnet links: forcefully let the task fail to report the error // No support for magnet links: forcefully let the task fail to report the error
onCommunicationError(new DaemonException(DaemonException.ExceptionType.MethodUnsupported, onCommunicationError(new DaemonTaskFailureResult(addByMagnetUrlTask, new DaemonException(DaemonException.ExceptionType.MethodUnsupported,
currentConnection.getType().name() + " does not support magnet links"), false); currentConnection.getType().name() + " does not support magnet links")), false);
return; return;
} }
@ -1065,7 +1065,7 @@ public class TorrentsActivity extends AppCompatActivity implements TorrentTasksE
onTaskSucceeded((DaemonTaskSuccessResult) result, getString(R.string.result_added, title)); onTaskSucceeded((DaemonTaskSuccessResult) result, getString(R.string.result_added, title));
refreshTorrents(); refreshTorrents();
} else { } else {
onCommunicationError(((DaemonTaskFailureResult) result).getException(), false); onCommunicationError((DaemonTaskFailureResult) result, false);
} }
} }
@ -1083,7 +1083,7 @@ public class TorrentsActivity extends AppCompatActivity implements TorrentTasksE
onTaskSucceeded((DaemonTaskSuccessResult) result, getString(R.string.result_added, title)); onTaskSucceeded((DaemonTaskSuccessResult) result, getString(R.string.result_added, title));
refreshTorrents(); refreshTorrents();
} else { } else {
onCommunicationError(((DaemonTaskFailureResult) result).getException(), false); onCommunicationError((DaemonTaskFailureResult) result, false);
} }
} }
@ -1192,7 +1192,7 @@ public class TorrentsActivity extends AppCompatActivity implements TorrentTasksE
if (result instanceof DaemonTaskSuccessResult) { if (result instanceof DaemonTaskSuccessResult) {
onTaskSucceeded((DaemonTaskSuccessResult) result, getString(R.string.result_resumed, torrent.getName())); onTaskSucceeded((DaemonTaskSuccessResult) result, getString(R.string.result_resumed, torrent.getName()));
} else { } else {
onCommunicationError(((DaemonTaskFailureResult) result).getException(), false); onCommunicationError((DaemonTaskFailureResult) result, false);
} }
} }
@ -1204,7 +1204,7 @@ public class TorrentsActivity extends AppCompatActivity implements TorrentTasksE
if (result instanceof DaemonTaskSuccessResult) { if (result instanceof DaemonTaskSuccessResult) {
onTaskSucceeded((DaemonTaskSuccessResult) result, getString(R.string.result_paused, torrent.getName())); onTaskSucceeded((DaemonTaskSuccessResult) result, getString(R.string.result_paused, torrent.getName()));
} else { } else {
onCommunicationError(((DaemonTaskFailureResult) result).getException(), false); onCommunicationError((DaemonTaskFailureResult) result, false);
} }
} }
@ -1216,7 +1216,7 @@ public class TorrentsActivity extends AppCompatActivity implements TorrentTasksE
if (result instanceof DaemonTaskSuccessResult) { if (result instanceof DaemonTaskSuccessResult) {
onTaskSucceeded((DaemonTaskSuccessResult) result, getString(R.string.result_started, torrent.getName())); onTaskSucceeded((DaemonTaskSuccessResult) result, getString(R.string.result_started, torrent.getName()));
} else { } else {
onCommunicationError(((DaemonTaskFailureResult) result).getException(), false); onCommunicationError((DaemonTaskFailureResult) result, false);
} }
} }
@ -1228,7 +1228,7 @@ public class TorrentsActivity extends AppCompatActivity implements TorrentTasksE
if (result instanceof DaemonTaskSuccessResult) { if (result instanceof DaemonTaskSuccessResult) {
onTaskSucceeded((DaemonTaskSuccessResult) result, getString(R.string.result_stopped, torrent.getName())); onTaskSucceeded((DaemonTaskSuccessResult) result, getString(R.string.result_stopped, torrent.getName()));
} else { } else {
onCommunicationError(((DaemonTaskFailureResult) result).getException(), false); onCommunicationError((DaemonTaskFailureResult) result, false);
} }
} }
@ -1240,7 +1240,7 @@ public class TorrentsActivity extends AppCompatActivity implements TorrentTasksE
onTaskSucceeded((DaemonTaskSuccessResult) result, onTaskSucceeded((DaemonTaskSuccessResult) result,
getString(withData ? R.string.result_removed_with_data : R.string.result_removed, torrent.getName())); getString(withData ? R.string.result_removed_with_data : R.string.result_removed, torrent.getName()));
} else { } else {
onCommunicationError(((DaemonTaskFailureResult) result).getException(), false); onCommunicationError((DaemonTaskFailureResult) result, false);
} }
} }
@ -1253,7 +1253,7 @@ public class TorrentsActivity extends AppCompatActivity implements TorrentTasksE
onTaskSucceeded((DaemonTaskSuccessResult) result, onTaskSucceeded((DaemonTaskSuccessResult) result,
newLabel == null ? getString(R.string.result_labelremoved) : getString(R.string.result_labelset, newLabel)); newLabel == null ? getString(R.string.result_labelremoved) : getString(R.string.result_labelset, newLabel));
} else { } else {
onCommunicationError(((DaemonTaskFailureResult) result).getException(), false); onCommunicationError((DaemonTaskFailureResult) result, false);
} }
} }
@ -1265,7 +1265,7 @@ public class TorrentsActivity extends AppCompatActivity implements TorrentTasksE
if (result instanceof DaemonTaskSuccessResult) { if (result instanceof DaemonTaskSuccessResult) {
onTaskSucceeded((DaemonTaskSuccessResult) result, getString(R.string.result_recheckedstarted, torrent.getName())); onTaskSucceeded((DaemonTaskSuccessResult) result, getString(R.string.result_recheckedstarted, torrent.getName()));
} else { } else {
onCommunicationError(((DaemonTaskFailureResult) result).getException(), false); onCommunicationError((DaemonTaskFailureResult) result, false);
} }
} }
@ -1276,7 +1276,7 @@ public class TorrentsActivity extends AppCompatActivity implements TorrentTasksE
if (result instanceof DaemonTaskSuccessResult) { if (result instanceof DaemonTaskSuccessResult) {
onTaskSucceeded((DaemonTaskSuccessResult) result, getString(R.string.result_trackersupdated)); onTaskSucceeded((DaemonTaskSuccessResult) result, getString(R.string.result_trackersupdated));
} else { } else {
onCommunicationError(((DaemonTaskFailureResult) result).getException(), false); onCommunicationError((DaemonTaskFailureResult) result, false);
} }
} }
@ -1287,7 +1287,7 @@ public class TorrentsActivity extends AppCompatActivity implements TorrentTasksE
if (result instanceof DaemonTaskSuccessResult) { if (result instanceof DaemonTaskSuccessResult) {
onTaskSucceeded((DaemonTaskSuccessResult) result, getString(R.string.result_locationset, newLocation)); onTaskSucceeded((DaemonTaskSuccessResult) result, getString(R.string.result_locationset, newLocation));
} else { } else {
onCommunicationError(((DaemonTaskFailureResult) result).getException(), false); onCommunicationError((DaemonTaskFailureResult) result, false);
} }
} }
@ -1298,7 +1298,7 @@ public class TorrentsActivity extends AppCompatActivity implements TorrentTasksE
if (result instanceof DaemonTaskSuccessResult) { if (result instanceof DaemonTaskSuccessResult) {
onTaskSucceeded((DaemonTaskSuccessResult) result, getString(R.string.result_priotitiesset)); onTaskSucceeded((DaemonTaskSuccessResult) result, getString(R.string.result_priotitiesset));
} else { } else {
onCommunicationError(((DaemonTaskFailureResult) result).getException(), false); onCommunicationError((DaemonTaskFailureResult) result, false);
} }
} }
@ -1308,7 +1308,7 @@ public class TorrentsActivity extends AppCompatActivity implements TorrentTasksE
if (result instanceof DaemonTaskSuccessResult) { if (result instanceof DaemonTaskSuccessResult) {
onTaskSucceeded((DaemonTaskSuccessResult) result, getString(R.string.result_maxspeedsset)); onTaskSucceeded((DaemonTaskSuccessResult) result, getString(R.string.result_maxspeedsset));
} else { } else {
onCommunicationError(((DaemonTaskFailureResult) result).getException(), false); onCommunicationError((DaemonTaskFailureResult) result, false);
} }
} }
@ -1320,10 +1320,10 @@ public class TorrentsActivity extends AppCompatActivity implements TorrentTasksE
} }
@UiThread @UiThread
protected void onCommunicationError(DaemonException daemonException, boolean isCritical) { protected void onCommunicationError(DaemonTaskFailureResult result, boolean isCritical) {
//noinspection ThrowableResultOfMethodCallIgnored //noinspection ThrowableResultOfMethodCallIgnored
log.i(this, daemonException.toString()); log.i(this, result.getException().toString());
String error = getString(LocalTorrent.getResourceForDaemonException(daemonException)); String error = getString(LocalTorrent.getResourceForDaemonException(result.getException()));
SnackbarManager.show(Snackbar.with(this).text(error).colorResource(R.color.red).type(SnackbarType.MULTI_LINE)); SnackbarManager.show(Snackbar.with(this).text(error).colorResource(R.color.red).type(SnackbarType.MULTI_LINE));
fragmentTorrents.updateIsLoading(false); fragmentTorrents.updateIsLoading(false);
if (isCritical) { if (isCritical) {
@ -1398,4 +1398,4 @@ public class TorrentsActivity extends AppCompatActivity implements TorrentTasksE
invalidateOptionsMenu(); invalidateOptionsMenu();
} }
} }

Loading…
Cancel
Save