From 6d58d1186b23dd015454eb7c3ead2b34eacd65c4 Mon Sep 17 00:00:00 2001 From: twig Date: Fri, 3 Jun 2016 00:17:50 +1000 Subject: [PATCH] - removed supportsRemoteRssManagement() check in openRemoteRss() - show/hide remote rss navigation drawer according to normal behaviour - change nav drawer icon - removed cruft code - close drawer on filter selection - init rssFeedItems --- .../transdroid/core/gui/TorrentsActivity.java | 18 +- .../core/gui/remoterss/RemoteRssActivity.java | 238 ++---------------- .../daemon/Utorrent/UtorrentAdapter.java | 2 +- .../main/res/drawable/ic_cloud_download.xml | 9 + .../main/res/menu/activity_torrents_main.xml | 2 +- 5 files changed, 44 insertions(+), 225 deletions(-) create mode 100644 app/src/main/res/drawable/ic_cloud_download.xml diff --git a/app/src/main/java/org/transdroid/core/gui/TorrentsActivity.java b/app/src/main/java/org/transdroid/core/gui/TorrentsActivity.java index dc5fc0eb..0b99e814 100644 --- a/app/src/main/java/org/transdroid/core/gui/TorrentsActivity.java +++ b/app/src/main/java/org/transdroid/core/gui/TorrentsActivity.java @@ -855,18 +855,16 @@ public class TorrentsActivity extends AppCompatActivity implements TorrentTasksE @OptionsItem(R.id.action_remoterss) protected void openRemoteRss() { - if (Daemon.supportsRemoteRssManagement(currentConnection.getType())) { - ArrayList rssFeedItems = ((UtorrentAdapter) (currentConnection)).getRemoteRssChannels(); + ArrayList rssFeedItems = ((UtorrentAdapter) (currentConnection)).getRemoteRssChannels(); - if (rssFeedItems.size() == 0) { - return; - } - - RemoteRssActivity_.intent(this) - .feeds(rssFeedItems) - .start() - ; + if (rssFeedItems.size() == 0) { + return; } + + RemoteRssActivity_.intent(this) + .feeds(rssFeedItems) + .start() + ; } @OptionsItem(R.id.action_help) diff --git a/app/src/main/java/org/transdroid/core/gui/remoterss/RemoteRssActivity.java b/app/src/main/java/org/transdroid/core/gui/remoterss/RemoteRssActivity.java index a24d8133..a8f1af53 100644 --- a/app/src/main/java/org/transdroid/core/gui/remoterss/RemoteRssActivity.java +++ b/app/src/main/java/org/transdroid/core/gui/remoterss/RemoteRssActivity.java @@ -17,12 +17,13 @@ package org.transdroid.core.gui.remoterss; import android.annotation.TargetApi; -import android.content.Intent; import android.os.Build; import android.os.Bundle; import android.os.Parcel; +import android.support.v4.widget.DrawerLayout; import android.support.v7.app.AppCompatActivity; import android.support.v7.widget.Toolbar; +import android.widget.LinearLayout; import android.widget.ListView; import org.androidannotations.annotations.AfterViews; @@ -39,7 +40,6 @@ import org.transdroid.core.app.settings.ApplicationSettings; import org.transdroid.core.app.settings.ServerSetting; import org.transdroid.core.app.settings.SystemSettings_; import org.transdroid.core.gui.TorrentsActivity; -import org.transdroid.core.gui.TorrentsActivity_; import org.transdroid.core.gui.lists.SimpleListItemAdapter; import org.transdroid.core.gui.remoterss.data.RemoteRssChannel; import org.transdroid.core.gui.remoterss.data.RemoteRssItem; @@ -77,6 +77,11 @@ public class RemoteRssActivity extends AppCompatActivity { private IDaemonAdapter currentConnection; // Details view components + @ViewById + protected DrawerLayout drawerLayout; + @ViewById + protected LinearLayout drawerContainer; + @ViewById protected Toolbar torrentsToolbar; @@ -105,6 +110,7 @@ public class RemoteRssActivity extends AppCompatActivity { } // Simple action bar with up, torrent name as title and refresh button + torrentsToolbar.setNavigationIcon(R.drawable.ic_action_drawer); setSupportActionBar(torrentsToolbar); getSupportActionBar().setDisplayHomeAsUpEnabled(true); // getSupportActionBar().setTitle(NavigationHelper.buildCondensedFontString(torrent.getName())); @@ -120,222 +126,26 @@ public class RemoteRssActivity extends AppCompatActivity { showChannelFilters(); } + + @TargetApi(Build.VERSION_CODES.HONEYCOMB) @OptionsItem(android.R.id.home) protected void navigateUp() { - TorrentsActivity_.intent(this) - .flags(Intent.FLAG_ACTIVITY_CLEAR_TOP) - .start(); + if (drawerLayout.isDrawerOpen(drawerContainer)) { + drawerLayout.closeDrawers(); + } else { + drawerLayout.openDrawer(drawerContainer); + } } -// @OptionsItem(R.id.action_refresh) -// public void refreshScreen() { -// fragmentRemoteRss.updateIsLoading(true, null); -// refreshTorrent(); -// refreshTorrentDetails(torrent); -// refreshTorrentFiles(torrent); -// } - -// @Background -// protected void refreshTorrent() { -// DaemonTaskResult result = RetrieveTask.create(currentConnection).execute(log); -// if (result instanceof RetrieveTaskSuccessResult) { -// onTorrentsRetrieved(((RetrieveTaskSuccessResult) result).getTorrents(), ((RetrieveTaskSuccessResult) result).getLabels()); -// } else { -// onCommunicationError((DaemonTaskFailureResult) result, true); -// } -// } -// -// @Background -// public void refreshTorrentDetails(Torrent torrent) { -// if (!Daemon.supportsFineDetails(torrent.getDaemon())) { -// return; -// } -// DaemonTaskResult result = GetTorrentDetailsTask.create(currentConnection, torrent).execute(log); -// if (result instanceof GetTorrentDetailsTaskSuccessResult) { -// onTorrentDetailsRetrieved(torrent, ((GetTorrentDetailsTaskSuccessResult) result).getTorrentDetails()); -// } else { -// onCommunicationError((DaemonTaskFailureResult) result, false); -// } -// } -// -// @Background -// public void refreshTorrentFiles(Torrent torrent) { -// if (!Daemon.supportsFileListing(torrent.getDaemon())) { -// return; -// } -// DaemonTaskResult result = GetFileListTask.create(currentConnection, torrent).execute(log); -// if (result instanceof GetFileListTaskSuccessResult) { -// onTorrentFilesRetrieved(torrent, ((GetFileListTaskSuccessResult) result).getFiles()); -// } else { -// onCommunicationError((DaemonTaskFailureResult) result, false); -// } -// } -// -// @Background -// @Override -// public void resumeTorrent(Torrent torrent) { -// torrent.mimicResume(); -// DaemonTaskResult result = ResumeTask.create(currentConnection, torrent).execute(log); -// if (result instanceof DaemonTaskSuccessResult) { -// onTaskSucceeded((DaemonTaskSuccessResult) result, getString(R.string.result_resumed, torrent.getName())); -// } else { -// onCommunicationError((DaemonTaskFailureResult) result, false); -// } -// } -// -// @Background -// @Override -// public void pauseTorrent(Torrent torrent) { -// torrent.mimicPause(); -// DaemonTaskResult result = PauseTask.create(currentConnection, torrent).execute(log); -// if (result instanceof DaemonTaskSuccessResult) { -// onTaskSucceeded((DaemonTaskSuccessResult) result, getString(R.string.result_paused, torrent.getName())); -// } else { -// onCommunicationError((DaemonTaskFailureResult) result, false); -// } -// } -// -// @Background -// @Override -// public void startTorrent(Torrent torrent, boolean forced) { -// torrent.mimicStart(); -// DaemonTaskResult result = StartTask.create(currentConnection, torrent, forced).execute(log); -// if (result instanceof DaemonTaskSuccessResult) { -// onTaskSucceeded((DaemonTaskSuccessResult) result, getString(R.string.result_started, torrent.getName())); -// } else { -// onCommunicationError((DaemonTaskFailureResult) result, false); -// } -// } -// -// @Background -// @Override -// public void stopTorrent(Torrent torrent) { -// torrent.mimicStop(); -// DaemonTaskResult result = StopTask.create(currentConnection, torrent).execute(log); -// if (result instanceof DaemonTaskSuccessResult) { -// onTaskSucceeded((DaemonTaskSuccessResult) result, getString(R.string.result_stopped, torrent.getName())); -// } else { -// onCommunicationError((DaemonTaskFailureResult) result, false); -// } -// } -// -// @Background -// @Override -// public void removeTorrent(Torrent torrent, boolean withData) { -// DaemonTaskResult result = RemoveTask.create(currentConnection, torrent, withData).execute(log); -// if (result instanceof DaemonTaskSuccessResult) { -// // Close the details activity (as the torrent is now removed) -// closeActivity(getString(withData ? R.string.result_removed_with_data : R.string.result_removed, torrent.getName())); -// } else { -// onCommunicationError((DaemonTaskFailureResult) result, false); -// } -// } -// -// @UiThread -// protected void closeActivity(String closeText) { -// setResult(RESULT_OK, new Intent().putExtra("torrent_removed", true).putExtra("affected_torrent", torrent)); -// finish(); -// if (closeText != null) { -// SnackbarManager.show(Snackbar.with(this).text(closeText)); -// } -// } -// -// @Background -// @Override -// public void updateLabel(Torrent torrent, String newLabel) { -// torrent.mimicNewLabel(newLabel); -// DaemonTaskResult result = SetLabelTask.create(currentConnection, torrent, newLabel == null ? "" : newLabel).execute(log); -// if (result instanceof DaemonTaskSuccessResult) { -// onTaskSucceeded((DaemonTaskSuccessResult) result, getString(R.string.result_labelset, newLabel)); -// } else { -// onCommunicationError((DaemonTaskFailureResult) result, false); -// } -// } -// -// @Background -// @Override -// public void forceRecheckTorrent(Torrent torrent) { -// torrent.mimicCheckingStatus(); -// DaemonTaskResult result = ForceRecheckTask.create(currentConnection, torrent).execute(log); -// if (result instanceof DaemonTaskSuccessResult) { -// onTaskSucceeded((DaemonTaskSuccessResult) result, getString(R.string.result_recheckedstarted, torrent.getName())); -// } else { -// onCommunicationError((DaemonTaskFailureResult) result, false); -// } -// } -// -// @Background -// @Override -// public void updateTrackers(Torrent torrent, List newTrackers) { -// DaemonTaskResult result = SetTrackersTask.create(currentConnection, torrent, newTrackers).execute(log); -// if (result instanceof DaemonTaskSuccessResult) { -// onTaskSucceeded((DaemonTaskSuccessResult) result, getString(R.string.result_trackersupdated)); -// } else { -// onCommunicationError((DaemonTaskFailureResult) result, false); -// } -// } -// -// @Background -// @Override -// public void updateLocation(Torrent torrent, String newLocation) { -// DaemonTaskResult result = SetDownloadLocationTask.create(currentConnection, torrent, newLocation).execute(log); -// if (result instanceof DaemonTaskSuccessResult) { -// onTaskSucceeded((DaemonTaskSuccessResult) result, getString(R.string.result_locationset, newLocation)); -// } else { -// onCommunicationError((DaemonTaskFailureResult) result, false); -// } -// } -// -// @Background -// @Override -// public void updatePriority(Torrent torrent, List files, Priority priority) { -// DaemonTaskResult result = SetFilePriorityTask.create(currentConnection, torrent, priority, new ArrayList<>(files)).execute(log); -// if (result instanceof DaemonTaskSuccessResult) { -// onTaskSucceeded((DaemonTaskSuccessResult) result, getString(R.string.result_priotitiesset)); -// } else { -// onCommunicationError((DaemonTaskFailureResult) result, false); -// } -// } -// -// @UiThread -// protected void onTaskSucceeded(DaemonTaskSuccessResult result, String successMessage) { -// // Set the activity result so the calling activity knows it needs to update its view -// setResult(RESULT_OK, new Intent().putExtra("torrent_updated", true).putExtra("affected_torrent", torrent)); -// // Refresh the screen as well -// refreshTorrent(); -// refreshTorrentDetails(torrent); -// SnackbarManager.show(Snackbar.with(this).text(successMessage)); -// } -// -// @UiThread -// protected void onTorrentDetailsRetrieved(Torrent torrent, TorrentDetails torrentDetails) { -// // Update the details fragment with the new fine details for the shown torrent -// fragmentDetails.updateTorrentDetails(torrent, torrentDetails); -// } -// -// @UiThread -// protected void onTorrentFilesRetrieved(Torrent torrent, List torrentFiles) { -// // Update the details fragment with the newly retrieved list of files -// fragmentDetails.updateTorrentFiles(torrent, new ArrayList<>(torrentFiles)); -// } -// -// @UiThread -// protected void onCommunicationError(DaemonTaskFailureResult result, boolean isCritical) { -// log.i(this, result.getException().toString()); -// 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.red)); -// } -// -// @UiThread -// protected void onTorrentsRetrieved(List torrents, List labels) { -// // Update the details fragment accordingly -// fragmentDetails.updateIsLoading(false, null); -// fragmentDetails.perhapsUpdateTorrent(torrents); -// fragmentDetails.updateLabels(Label.convertToNavigationLabels(labels, getResources().getString(R.string.labels_unlabeled))); -// } + @Override + public void onBackPressed() { + if (drawerLayout.isDrawerOpen(drawerContainer)) { + drawerLayout.closeDrawers(); + } else { + finish(); + } + } protected void showRecentItems() { if (recentItems == null) { @@ -389,6 +199,8 @@ public class RemoteRssActivity extends AppCompatActivity { else { fragmentRemoteRss.updateTorrentFiles(feeds.get(position -1).getItems()); } + + drawerLayout.closeDrawers(); } public IDaemonAdapter getCurrentConnection() { diff --git a/app/src/main/java/org/transdroid/daemon/Utorrent/UtorrentAdapter.java b/app/src/main/java/org/transdroid/daemon/Utorrent/UtorrentAdapter.java index 1ea2b120..7019b5f3 100644 --- a/app/src/main/java/org/transdroid/daemon/Utorrent/UtorrentAdapter.java +++ b/app/src/main/java/org/transdroid/daemon/Utorrent/UtorrentAdapter.java @@ -117,7 +117,7 @@ public class UtorrentAdapter implements IDaemonAdapter { private DaemonSettings settings; private DefaultHttpClient httpclient; - private static ArrayList rssFeedItems; + private static ArrayList rssFeedItems = new ArrayList<>(); diff --git a/app/src/main/res/drawable/ic_cloud_download.xml b/app/src/main/res/drawable/ic_cloud_download.xml new file mode 100644 index 00000000..5930f79b --- /dev/null +++ b/app/src/main/res/drawable/ic_cloud_download.xml @@ -0,0 +1,9 @@ + + + diff --git a/app/src/main/res/menu/activity_torrents_main.xml b/app/src/main/res/menu/activity_torrents_main.xml index 427872af..1ce9faa7 100644 --- a/app/src/main/res/menu/activity_torrents_main.xml +++ b/app/src/main/res/menu/activity_torrents_main.xml @@ -30,7 +30,7 @@ app:showAsAction="ifRoom" />