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

Loading…
Cancel
Save