From 6dc1b85b2ada9efc76c8145ade4000a4da016f72 Mon Sep 17 00:00:00 2001 From: TacoTheDank Date: Fri, 10 Jul 2020 16:24:17 -0400 Subject: [PATCH] .editorconfig part 3: Entry rearrangement --- app/src/main/AndroidManifest.xml | 2 +- .../core/app/search/SearchHelper.java | 8 +- .../core/app/search/SearchResult.java | 43 ++- .../app/settings/ApplicationSettings.java | 56 +-- .../core/app/settings/RssfeedSetting.java | 2 +- .../app/settings/SettingsPersistence.java | 9 +- .../core/app/settings/WebsearchSetting.java | 3 +- .../transdroid/core/gui/DetailsActivity.java | 3 +- .../transdroid/core/gui/DetailsFragment.java | 340 +++++++++--------- .../core/gui/ServerPickerDialog.java | 26 +- .../transdroid/core/gui/ServerStatusView.java | 11 +- .../transdroid/core/gui/TorrentsActivity.java | 69 ++-- .../transdroid/core/gui/TorrentsFragment.java | 259 +++++++------ .../core/gui/lists/LocalTorrent.java | 67 ++-- .../core/gui/lists/PiecesMapView.java | 4 +- .../core/gui/lists/SimpleListItemAdapter.java | 12 +- .../gui/lists/TorrentFilePriorityLayout.java | 3 +- .../core/gui/lists/TorrentProgressBar.java | 37 +- .../core/gui/lists/TorrentStatusLayout.java | 3 +- .../core/gui/lists/TorrentsAdapter.java | 3 +- .../core/gui/log/ErrorLogEntry.java | 34 +- .../core/gui/navigation/DialogHelper.java | 56 +-- .../gui/navigation/FilterListAdapter.java | 6 +- .../transdroid/core/gui/navigation/Label.java | 86 +++-- .../core/gui/navigation/NavigationHelper.java | 132 +++---- .../SelectionModificationSpinner.java | 22 +- .../navigation/SetTransferRatesDialog.java | 26 +- .../core/gui/navigation/StatusType.java | 29 +- .../core/gui/rss/RssFeedsActivity.java | 116 +++--- .../core/gui/rss/RssItemsFragment.java | 8 +- .../core/gui/rss/RssfeedsAdapter.java | 3 +- .../core/gui/rss/RssitemsAdapter.java | 3 +- .../core/gui/search/SearchActivity.java | 39 +- .../core/gui/search/SearchResultsAdapter.java | 3 +- .../gui/search/SearchResultsFragment.java | 135 ++++--- .../core/gui/search/SearchSitesAdapter.java | 3 +- .../gui/settings/HelpSettingsActivity.java | 50 ++- .../settings/KeyBoundPreferencesActivity.java | 15 +- .../core/gui/settings/RssfeedPreference.java | 17 +- .../core/gui/settings/ServerPreference.java | 17 +- .../gui/settings/ServerSettingsActivity.java | 4 +- .../gui/settings/SystemSettingsActivity.java | 24 +- .../gui/settings/WebsearchPreference.java | 17 +- .../transdroid/core/rssparser/Channel.java | 85 +++-- .../org/transdroid/core/rssparser/Item.java | 92 +++-- .../core/seedbox/SeedboxPreference.java | 17 +- .../seedbox/XirvikSharedSettingsActivity.java | 3 +- .../core/widget/ListWidgetConfigActivity.java | 12 +- .../java/org/transdroid/daemon/Daemon.java | 4 +- .../transdroid/daemon/DaemonException.java | 20 +- .../org/transdroid/daemon/DaemonMethod.java | 11 +- .../daemon/Deluge/DelugeRemoteRssChannel.java | 19 +- .../daemon/Deluge/DelugeRemoteRssItem.java | 20 +- .../daemon/Deluge/DelugeRpcClient.java | 5 +- .../java/org/transdroid/daemon/Label.java | 35 +- .../java/org/transdroid/daemon/Priority.java | 11 +- .../daemon/Tfb4rt/Tfb4rtAdapter.java | 38 +- .../java/org/transdroid/daemon/Torrent.java | 32 +- .../org/transdroid/daemon/TorrentDetails.java | 19 +- .../org/transdroid/daemon/TorrentFile.java | 80 ++--- .../transdroid/daemon/TorrentFilesSortBy.java | 11 +- .../org/transdroid/daemon/TorrentStatus.java | 11 +- .../org/transdroid/daemon/TorrentsSortBy.java | 11 +- .../daemon/Utorrent/UtorrentAdapter.java | 3 +- .../data/UTorrentRemoteRssChannel.java | 20 +- .../Utorrent/data/UTorrentRemoteRssItem.java | 22 +- .../daemon/Vuze/VuzeXmlOverHttpClient.java | 74 ++-- .../daemon/util/FileSizeConverter.java | 19 +- .../details_list_background.xml | 8 +- .../res/drawable/activatable_background.xml | 8 +- .../res/drawable/details_list_background.xml | 8 +- .../res/layout-land/dialog_color_picker.xml | 8 +- .../res/layout-w600dp/activity_search.xml | 2 +- .../res/layout-w600dp/activity_torrents.xml | 22 +- .../res/layout-w900dp/activity_torrents.xml | 30 +- .../main/res/layout/actionbar_addbutton.xml | 4 +- .../main/res/layout/actionbar_donebutton.xml | 4 +- .../res/layout/actionbar_serverselection.xml | 4 +- .../res/layout/actionbar_serverstatus.xml | 18 +- app/src/main/res/layout/activity_search.xml | 2 +- app/src/main/res/layout/activity_torrents.xml | 14 +- .../main/res/layout/activity_widgetconfig.xml | 2 +- app/src/main/res/layout/dialog_about.xml | 8 +- app/src/main/res/layout/dialog_changelog.xml | 8 +- .../main/res/layout/dialog_color_picker.xml | 6 +- app/src/main/res/layout/dialog_setlabel.xml | 16 +- app/src/main/res/layout/dialog_trackers.xml | 4 +- app/src/main/res/layout/fragment_details.xml | 8 +- .../res/layout/fragment_details_header.xml | 22 +- .../main/res/layout/fragment_remoterss.xml | 4 +- app/src/main/res/layout/fragment_rssfeeds.xml | 2 +- app/src/main/res/layout/fragment_rssitems.xml | 2 +- .../res/layout/fragment_searchresults.xml | 2 +- app/src/main/res/layout/fragment_torrents.xml | 8 +- app/src/main/res/layout/list_item_filter.xml | 4 +- .../res/layout/list_item_remoterssitem.xml | 8 +- app/src/main/res/layout/list_item_rssfeed.xml | 6 +- app/src/main/res/layout/list_item_rssitem.xml | 4 +- .../res/layout/list_item_searchresult.xml | 10 +- .../main/res/layout/list_item_searchsite.xml | 4 +- app/src/main/res/layout/list_item_simple.xml | 4 +- app/src/main/res/layout/list_item_torrent.xml | 36 +- .../main/res/layout/list_item_torrentfile.xml | 8 +- app/src/main/res/layout/list_item_widget.xml | 4 +- .../main/res/layout/list_item_widget_dark.xml | 4 +- app/src/main/res/layout/widget_torrents.xml | 12 +- app/src/main/res/menu/fragment_details.xml | 8 +- app/src/main/res/xml/listwidget_info.xml | 4 +- app/src/main/res/xml/pref_system.xml | 50 +-- app/src/main/res/xml/pref_websearch.xml | 18 +- app/src/main/res/xml/searchable.xml | 4 +- 111 files changed, 1417 insertions(+), 1474 deletions(-) diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 86468441..3b195fac 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -50,9 +50,9 @@ diff --git a/app/src/main/java/org/transdroid/core/app/search/SearchHelper.java b/app/src/main/java/org/transdroid/core/app/search/SearchHelper.java index d5766cb8..9e381185 100644 --- a/app/src/main/java/org/transdroid/core/app/search/SearchHelper.java +++ b/app/src/main/java/org/transdroid/core/app/search/SearchHelper.java @@ -53,10 +53,6 @@ public class SearchHelper { @RootContext protected Context context; - public enum SearchSortOrder { - Combined, BySeeders - } - /** * Return whether the Torrent Search package is installed and available to query against * @@ -169,4 +165,8 @@ public class SearchHelper { } } + public enum SearchSortOrder { + Combined, BySeeders + } + } diff --git a/app/src/main/java/org/transdroid/core/app/search/SearchResult.java b/app/src/main/java/org/transdroid/core/app/search/SearchResult.java index f91ebaf2..49b2144e 100644 --- a/app/src/main/java/org/transdroid/core/app/search/SearchResult.java +++ b/app/src/main/java/org/transdroid/core/app/search/SearchResult.java @@ -28,6 +28,15 @@ import java.util.Date; */ public class SearchResult implements Parcelable { + public static final Parcelable.Creator CREATOR = new Parcelable.Creator() { + public SearchResult createFromParcel(Parcel in) { + return new SearchResult(in); + } + + public SearchResult[] newArray(int size) { + return new SearchResult[size]; + } + }; private final int id; private final String name; private final String torrentUrl; @@ -49,6 +58,18 @@ public class SearchResult implements Parcelable { this.leechers = leechers; } + public SearchResult(Parcel in) { + id = in.readInt(); + name = in.readString(); + torrentUrl = in.readString(); + detailsUrl = in.readString(); + size = in.readString(); + long addedOnIn = in.readLong(); + addedOn = addedOnIn == -1 ? null : new Date(addedOnIn); + seeders = in.readString(); + leechers = in.readString(); + } + public int getId() { return id; } @@ -98,26 +119,4 @@ public class SearchResult implements Parcelable { out.writeString(leechers); } - public static final Parcelable.Creator CREATOR = new Parcelable.Creator() { - public SearchResult createFromParcel(Parcel in) { - return new SearchResult(in); - } - - public SearchResult[] newArray(int size) { - return new SearchResult[size]; - } - }; - - public SearchResult(Parcel in) { - id = in.readInt(); - name = in.readString(); - torrentUrl = in.readString(); - detailsUrl = in.readString(); - size = in.readString(); - long addedOnIn = in.readLong(); - addedOn = addedOnIn == -1 ? null : new Date(addedOnIn); - seeders = in.readString(); - leechers = in.readString(); - } - } diff --git a/app/src/main/java/org/transdroid/core/app/settings/ApplicationSettings.java b/app/src/main/java/org/transdroid/core/app/settings/ApplicationSettings.java index bc4f5c28..da867be5 100644 --- a/app/src/main/java/org/transdroid/core/app/settings/ApplicationSettings.java +++ b/app/src/main/java/org/transdroid/core/app/settings/ApplicationSettings.java @@ -60,9 +60,9 @@ public class ApplicationSettings { @RootContext protected Context context; - private SharedPreferences prefs; @Bean protected SearchHelper searchHelper; + private SharedPreferences prefs; protected ApplicationSettings(Context context) { prefs = PreferenceManager.getDefaultSharedPreferences(context); @@ -348,6 +348,15 @@ public class ApplicationSettings { return getServerSetting(last); } + /** + * Registers some server as being the last used by the user + * + * @param server The settings of the server that the user last used + */ + public void setLastUsedServer(ServerSetting server) { + setLastUsedServerKey(server.getOrder()); + } + /** * Returns the order number/unique key of the server that the used last used; use with getServerSettings(int) or * call getLastUsedServer directly. WARNING: the returned integer may no longer refer to a known server settings @@ -359,15 +368,6 @@ public class ApplicationSettings { return prefs.getInt("system_lastusedserver", -1); } - /** - * Registers some server as being the last used by the user - * - * @param server The settings of the server that the user last used - */ - public void setLastUsedServer(ServerSetting server) { - setLastUsedServerKey(server.getOrder()); - } - /** * Registers the order number/unique key of some server as being last used by the user * @@ -590,6 +590,15 @@ public class ApplicationSettings { .getStatus(prefs.getInt("system_lastusedsortorder", TorrentsSortBy.Alphanumeric.getCode())); } + /** + * Returns the search sort order property that the user last used. + * + * @return The last used sort order enumeration value + */ + public SearchSortOrder getLastUsedSearchSortOrder() { + return SearchSortOrder.values()[(prefs.getInt("system_lastusedsearchsortorder", SearchSortOrder.BySeeders.ordinal()))]; + } + /** * Registers the search list sort order as being last used by the user * @@ -601,15 +610,6 @@ public class ApplicationSettings { edit.apply(); } - /** - * Returns the search sort order property that the user last used. - * - * @return The last used sort order enumeration value - */ - public SearchSortOrder getLastUsedSearchSortOrder() { - return SearchSortOrder.values()[(prefs.getInt("system_lastusedsearchsortorder", SearchSortOrder.BySeeders.ordinal()))]; - } - /** * Returns the sort order direction that the user last used. Use together with {@link #getLastUsedSortOrder()} to * get the full last used sort settings. @@ -686,6 +686,15 @@ public class ApplicationSettings { return null; } + /** + * Registers the unique key of some web search or in-app search site as being last used by the user + * + * @param site The site settings to register as being last used + */ + public void setLastUsedSearchSite(SearchSetting site) { + prefs.edit().putString("header_setsearchsite", site.getKey()).apply(); + } + /** * Returns the unique key of the site that the used last used or selected as default form the main settings; use * with getLastUsedSearchSite directly. WARNING: the returned string may no longer refer to a known web search site @@ -698,15 +707,6 @@ public class ApplicationSettings { return prefs.getString("header_setsearchsite", null); } - /** - * Registers the unique key of some web search or in-app search site as being last used by the user - * - * @param site The site settings to register as being last used - */ - public void setLastUsedSearchSite(SearchSetting site) { - prefs.edit().putString("header_setsearchsite", site.getKey()).apply(); - } - /** * Returns the statistics of this server as it was last seen by the background server checker service. * diff --git a/app/src/main/java/org/transdroid/core/app/settings/RssfeedSetting.java b/app/src/main/java/org/transdroid/core/app/settings/RssfeedSetting.java index 9cd2c6d8..22fd62d6 100644 --- a/app/src/main/java/org/transdroid/core/app/settings/RssfeedSetting.java +++ b/app/src/main/java/org/transdroid/core/app/settings/RssfeedSetting.java @@ -39,8 +39,8 @@ public class RssfeedSetting implements SimpleListItem { private final boolean alarm; private final String excludeFilter; private final String includeFilter; - private Date lastViewed; private final String lastViewedItemUrl; + private Date lastViewed; public RssfeedSetting(int order, String name, String baseUrl, boolean needsAuth, boolean alarm, String excludeFilter, String includeFilter, Date lastViewed, String lastViewedItemUrl) { diff --git a/app/src/main/java/org/transdroid/core/app/settings/SettingsPersistence.java b/app/src/main/java/org/transdroid/core/app/settings/SettingsPersistence.java index 3ca52134..6b639ec5 100644 --- a/app/src/main/java/org/transdroid/core/app/settings/SettingsPersistence.java +++ b/app/src/main/java/org/transdroid/core/app/settings/SettingsPersistence.java @@ -44,15 +44,14 @@ import java.io.OutputStream; @EBean(scope = Scope.Singleton) public class SettingsPersistence { - @Bean - protected ApplicationSettings applicationSettings; - @Bean - protected SystemSettings systemSettings; - public static final String DEFAULT_SETTINGS_DIR = Environment.getExternalStorageDirectory().toString() + "/Transdroid/"; public static final String DEFAULT_SETTINGS_FILENAME = "settings.json"; public static final File DEFAULT_SETTINGS_FILE = new File(DEFAULT_SETTINGS_DIR + DEFAULT_SETTINGS_FILENAME); + @Bean + protected ApplicationSettings applicationSettings; + @Bean + protected SystemSettings systemSettings; /** * Reads the server, web searches, RSS feed, background service and system settings from a JSON-encoded String, such as when read via a QR code. diff --git a/app/src/main/java/org/transdroid/core/app/settings/WebsearchSetting.java b/app/src/main/java/org/transdroid/core/app/settings/WebsearchSetting.java index 5f372274..d1bfd2c3 100644 --- a/app/src/main/java/org/transdroid/core/app/settings/WebsearchSetting.java +++ b/app/src/main/java/org/transdroid/core/app/settings/WebsearchSetting.java @@ -29,9 +29,8 @@ import org.transdroid.core.gui.search.SearchSetting; */ public class WebsearchSetting implements SimpleListItem, SearchSetting { - private static final String DEFAULT_NAME = "Default"; public static final String KEY_PREFIX = "websearch_"; - + private static final String DEFAULT_NAME = "Default"; private final int order; private final String name; private final String baseUrl; diff --git a/app/src/main/java/org/transdroid/core/gui/DetailsActivity.java b/app/src/main/java/org/transdroid/core/gui/DetailsActivity.java index b86233d9..41fdd85f 100644 --- a/app/src/main/java/org/transdroid/core/gui/DetailsActivity.java +++ b/app/src/main/java/org/transdroid/core/gui/DetailsActivity.java @@ -106,13 +106,12 @@ public class DetailsActivity extends AppCompatActivity implements TorrentTasksEx protected ConnectivityHelper connectivityHelper; @Bean protected ApplicationSettings applicationSettings; - private IDaemonAdapter currentConnection = null; - // Details view components @ViewById protected Toolbar selectionToolbar; @FragmentById(R.id.torrentdetails_fragment) protected DetailsFragment fragmentDetails; + private IDaemonAdapter currentConnection = null; @Override public void onCreate(Bundle savedInstanceState) { diff --git a/app/src/main/java/org/transdroid/core/gui/DetailsFragment.java b/app/src/main/java/org/transdroid/core/gui/DetailsFragment.java index 3f391903..be5900d3 100644 --- a/app/src/main/java/org/transdroid/core/gui/DetailsFragment.java +++ b/app/src/main/java/org/transdroid/core/gui/DetailsFragment.java @@ -96,8 +96,6 @@ public class DetailsFragment extends Fragment implements OnTrackersUpdatedListen protected boolean isLoadingTorrent = false; @InstanceState protected boolean hasCriticalError = false; - private ServerSetting currentServerSettings = null; - // Views @ViewById protected View detailsContainer; @@ -113,6 +111,175 @@ public class DetailsFragment extends Fragment implements OnTrackersUpdatedListen protected TextView emptyText, errorText; @ViewById protected ProgressBar loadingProgress; + private ServerSetting currentServerSettings = null; + private MultiChoiceModeListener onDetailsSelected = new MultiChoiceModeListener() { + + SelectionManagerMode selectionManagerMode; + + @Override + public boolean onCreateActionMode(final ActionMode mode, Menu menu) { + // Show contextual action bar to start/stop/remove/etc. torrents in batch mode + detailsMenu.setEnabled(false); + contextualMenu.setVisibility(View.VISIBLE); + contextualMenu.setOnMenuItemClickListener(new ActionMenuView.OnMenuItemClickListener() { + @Override + public boolean onMenuItemClick(MenuItem menuItem) { + return onActionItemClicked(mode, menuItem); + } + }); + contextualMenu.getMenu().clear(); + getActivity().getMenuInflater().inflate(R.menu.fragment_details_cab_main, contextualMenu.getMenu()); + Context themedContext = ((AppCompatActivity) getActivity()).getSupportActionBar().getThemedContext(); + mode.getMenuInflater().inflate(R.menu.fragment_details_cab_secondary, menu); + selectionManagerMode = new SelectionManagerMode(themedContext, detailsList, R.plurals.navigation_filesselected); + selectionManagerMode.setOnlyCheckClass(TorrentFile.class); + selectionManagerMode.onCreateActionMode(mode, menu); + return true; + } + + @Override + public boolean onPrepareActionMode(ActionMode mode, Menu menu) { + selectionManagerMode.onPrepareActionMode(mode, menu); + // Pause autorefresh + if (getActivity() != null && getActivity() instanceof TorrentsActivity) { + ((TorrentsActivity) getActivity()).stopRefresh = true; + ((TorrentsActivity) getActivity()).stopAutoRefresh(); + } + boolean filePaths = currentServerSettings != null && Daemon.supportsFilePaths(currentServerSettings.getType()); + contextualMenu.getMenu().findItem(R.id.action_download).setVisible(filePaths); + boolean filePriorities = currentServerSettings != null && Daemon.supportsFilePrioritySetting(currentServerSettings.getType()); + contextualMenu.getMenu().findItem(R.id.action_priority_off).setVisible(filePriorities); + contextualMenu.getMenu().findItem(R.id.action_priority_low).setVisible(filePriorities); + contextualMenu.getMenu().findItem(R.id.action_priority_normal).setVisible(filePriorities); + contextualMenu.getMenu().findItem(R.id.action_priority_high).setVisible(filePriorities); + return true; + } + + @SuppressLint("SdCardPath") + @Override + public boolean onActionItemClicked(ActionMode mode, MenuItem item) { + + // Get checked torrents + List checked = new ArrayList<>(); + for (int i = 0; i < detailsList.getCheckedItemPositions().size(); i++) { + if (detailsList.getCheckedItemPositions().valueAt(i) && i < detailsList.getAdapter().getCount() && + detailsList.getAdapter().getItem(detailsList.getCheckedItemPositions().keyAt(i)) instanceof TorrentFile) { + checked.add((TorrentFile) detailsList.getAdapter().getItem(detailsList.getCheckedItemPositions().keyAt(i))); + } + } + + int itemId = item.getItemId(); + if (itemId == R.id.action_download) { + + if (checked.size() < 1 || currentServerSettings == null) { + return true; + } + String urlBase = currentServerSettings.getFtpUrl(); + if (urlBase == null || urlBase.equals("")) { + urlBase = "ftp://" + currentServerSettings.getAddress() + "/"; + } + + // Try using AndFTP intents + Intent andftpStart = new Intent(Intent.ACTION_PICK); + andftpStart.setDataAndType(Uri.parse(urlBase), "vnd.android.cursor.dir/lysesoft.andftp.uri"); + andftpStart.putExtra("command_type", "download"); + andftpStart.putExtra("ftp_pasv", "true"); + if (Uri.parse(urlBase).getUserInfo() != null) { + andftpStart.putExtra("ftp_username", Uri.parse(urlBase).getUserInfo()); + } else { + andftpStart.putExtra("ftp_username", currentServerSettings.getUsername()); + } + if (currentServerSettings.getFtpPassword() != null && !currentServerSettings.getFtpPassword().equals("")) { + andftpStart.putExtra("ftp_password", currentServerSettings.getFtpPassword()); + } else { + andftpStart.putExtra("ftp_password", currentServerSettings.getPassword()); + } + // Note: AndFTP doesn't understand the directory that Environment.getExternalStoragePublicDirectory() + // uses :( + andftpStart.putExtra("local_folder", "/sdcard/Download"); + for (int f = 0; f < checked.size(); f++) { + String file = checked.get(f).getRelativePath(); + if (file != null) { + // If the file is directly in the root, AndFTP fails if we supply the proper path (like + // /file.pdf) + // Work around this bug by removing the leading / if no further directories are used in the path + if (file.startsWith("/") && file.indexOf("/", 1) < 0) { + file = file.substring(1); + } + andftpStart.putExtra("remote_file" + (f + 1), file); + } + } + if (andftpStart.resolveActivity(getActivity().getPackageManager()) != null) { + startActivity(andftpStart); + mode.finish(); + return true; + } + + // Try using a VIEW intent given an ftp:// scheme URI + String url = urlBase + checked.get(0).getRelativePath(); + Intent simpleStart = new Intent(Intent.ACTION_VIEW, Uri.parse(url)).setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); + if (simpleStart.resolveActivity(getActivity().getPackageManager()) != null) { + startActivity(simpleStart); + mode.finish(); + return true; + } + + // No app is available that can handle FTP downloads + SnackbarManager.show(Snackbar.with(getActivity()).text(getString(R.string.error_noftpapp, url)).type(SnackbarType.MULTI_LINE) + .colorResource(R.color.red)); + mode.finish(); + return true; + + } else if (itemId == R.id.action_copytoclipboard) { + + StringBuilder names = new StringBuilder(); + for (int f = 0; f < checked.size(); f++) { + if (f != 0) { + names.append("\n"); + } + names.append(checked.get(f).getName()); + } + ClipboardManager clipboardManager = (ClipboardManager) getActivity().getSystemService(Context.CLIPBOARD_SERVICE); + clipboardManager.setPrimaryClip(ClipData.newPlainText("Transdroid", names.toString())); + mode.finish(); + return true; + + } else { + Priority priority = Priority.Off; + if (itemId == R.id.action_priority_low) { + priority = Priority.Low; + } + if (itemId == R.id.action_priority_normal) { + priority = Priority.Normal; + } + if (itemId == R.id.action_priority_high) { + priority = Priority.High; + } + if (getTasksExecutor() != null) + getTasksExecutor().updatePriority(torrent, checked, priority); + mode.finish(); + return true; + } + } + + @Override + public void onItemCheckedStateChanged(ActionMode mode, int position, long id, boolean checked) { + selectionManagerMode.onItemCheckedStateChanged(mode, position, id, checked); + } + + @Override + public void onDestroyActionMode(ActionMode mode) { + // Resume autorefresh + if (getActivity() != null && getActivity() instanceof TorrentsActivity) { + ((TorrentsActivity) getActivity()).stopRefresh = false; + ((TorrentsActivity) getActivity()).startAutoRefresh(); + } + selectionManagerMode.onDestroyActionMode(mode); + contextualMenu.setVisibility(View.GONE); + detailsMenu.setEnabled(true); + } + + }; @AfterViews protected void init() { @@ -516,175 +683,6 @@ public class DetailsFragment extends Fragment implements OnTrackersUpdatedListen } } - private MultiChoiceModeListener onDetailsSelected = new MultiChoiceModeListener() { - - SelectionManagerMode selectionManagerMode; - - @Override - public boolean onCreateActionMode(final ActionMode mode, Menu menu) { - // Show contextual action bar to start/stop/remove/etc. torrents in batch mode - detailsMenu.setEnabled(false); - contextualMenu.setVisibility(View.VISIBLE); - contextualMenu.setOnMenuItemClickListener(new ActionMenuView.OnMenuItemClickListener() { - @Override - public boolean onMenuItemClick(MenuItem menuItem) { - return onActionItemClicked(mode, menuItem); - } - }); - contextualMenu.getMenu().clear(); - getActivity().getMenuInflater().inflate(R.menu.fragment_details_cab_main, contextualMenu.getMenu()); - Context themedContext = ((AppCompatActivity) getActivity()).getSupportActionBar().getThemedContext(); - mode.getMenuInflater().inflate(R.menu.fragment_details_cab_secondary, menu); - selectionManagerMode = new SelectionManagerMode(themedContext, detailsList, R.plurals.navigation_filesselected); - selectionManagerMode.setOnlyCheckClass(TorrentFile.class); - selectionManagerMode.onCreateActionMode(mode, menu); - return true; - } - - @Override - public boolean onPrepareActionMode(ActionMode mode, Menu menu) { - selectionManagerMode.onPrepareActionMode(mode, menu); - // Pause autorefresh - if (getActivity() != null && getActivity() instanceof TorrentsActivity) { - ((TorrentsActivity) getActivity()).stopRefresh = true; - ((TorrentsActivity) getActivity()).stopAutoRefresh(); - } - boolean filePaths = currentServerSettings != null && Daemon.supportsFilePaths(currentServerSettings.getType()); - contextualMenu.getMenu().findItem(R.id.action_download).setVisible(filePaths); - boolean filePriorities = currentServerSettings != null && Daemon.supportsFilePrioritySetting(currentServerSettings.getType()); - contextualMenu.getMenu().findItem(R.id.action_priority_off).setVisible(filePriorities); - contextualMenu.getMenu().findItem(R.id.action_priority_low).setVisible(filePriorities); - contextualMenu.getMenu().findItem(R.id.action_priority_normal).setVisible(filePriorities); - contextualMenu.getMenu().findItem(R.id.action_priority_high).setVisible(filePriorities); - return true; - } - - @SuppressLint("SdCardPath") - @Override - public boolean onActionItemClicked(ActionMode mode, MenuItem item) { - - // Get checked torrents - List checked = new ArrayList<>(); - for (int i = 0; i < detailsList.getCheckedItemPositions().size(); i++) { - if (detailsList.getCheckedItemPositions().valueAt(i) && i < detailsList.getAdapter().getCount() && - detailsList.getAdapter().getItem(detailsList.getCheckedItemPositions().keyAt(i)) instanceof TorrentFile) { - checked.add((TorrentFile) detailsList.getAdapter().getItem(detailsList.getCheckedItemPositions().keyAt(i))); - } - } - - int itemId = item.getItemId(); - if (itemId == R.id.action_download) { - - if (checked.size() < 1 || currentServerSettings == null) { - return true; - } - String urlBase = currentServerSettings.getFtpUrl(); - if (urlBase == null || urlBase.equals("")) { - urlBase = "ftp://" + currentServerSettings.getAddress() + "/"; - } - - // Try using AndFTP intents - Intent andftpStart = new Intent(Intent.ACTION_PICK); - andftpStart.setDataAndType(Uri.parse(urlBase), "vnd.android.cursor.dir/lysesoft.andftp.uri"); - andftpStart.putExtra("command_type", "download"); - andftpStart.putExtra("ftp_pasv", "true"); - if (Uri.parse(urlBase).getUserInfo() != null) { - andftpStart.putExtra("ftp_username", Uri.parse(urlBase).getUserInfo()); - } else { - andftpStart.putExtra("ftp_username", currentServerSettings.getUsername()); - } - if (currentServerSettings.getFtpPassword() != null && !currentServerSettings.getFtpPassword().equals("")) { - andftpStart.putExtra("ftp_password", currentServerSettings.getFtpPassword()); - } else { - andftpStart.putExtra("ftp_password", currentServerSettings.getPassword()); - } - // Note: AndFTP doesn't understand the directory that Environment.getExternalStoragePublicDirectory() - // uses :( - andftpStart.putExtra("local_folder", "/sdcard/Download"); - for (int f = 0; f < checked.size(); f++) { - String file = checked.get(f).getRelativePath(); - if (file != null) { - // If the file is directly in the root, AndFTP fails if we supply the proper path (like - // /file.pdf) - // Work around this bug by removing the leading / if no further directories are used in the path - if (file.startsWith("/") && file.indexOf("/", 1) < 0) { - file = file.substring(1); - } - andftpStart.putExtra("remote_file" + (f + 1), file); - } - } - if (andftpStart.resolveActivity(getActivity().getPackageManager()) != null) { - startActivity(andftpStart); - mode.finish(); - return true; - } - - // Try using a VIEW intent given an ftp:// scheme URI - String url = urlBase + checked.get(0).getRelativePath(); - Intent simpleStart = new Intent(Intent.ACTION_VIEW, Uri.parse(url)).setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); - if (simpleStart.resolveActivity(getActivity().getPackageManager()) != null) { - startActivity(simpleStart); - mode.finish(); - return true; - } - - // No app is available that can handle FTP downloads - SnackbarManager.show(Snackbar.with(getActivity()).text(getString(R.string.error_noftpapp, url)).type(SnackbarType.MULTI_LINE) - .colorResource(R.color.red)); - mode.finish(); - return true; - - } else if (itemId == R.id.action_copytoclipboard) { - - StringBuilder names = new StringBuilder(); - for (int f = 0; f < checked.size(); f++) { - if (f != 0) { - names.append("\n"); - } - names.append(checked.get(f).getName()); - } - ClipboardManager clipboardManager = (ClipboardManager) getActivity().getSystemService(Context.CLIPBOARD_SERVICE); - clipboardManager.setPrimaryClip(ClipData.newPlainText("Transdroid", names.toString())); - mode.finish(); - return true; - - } else { - Priority priority = Priority.Off; - if (itemId == R.id.action_priority_low) { - priority = Priority.Low; - } - if (itemId == R.id.action_priority_normal) { - priority = Priority.Normal; - } - if (itemId == R.id.action_priority_high) { - priority = Priority.High; - } - if (getTasksExecutor() != null) - getTasksExecutor().updatePriority(torrent, checked, priority); - mode.finish(); - return true; - } - } - - @Override - public void onItemCheckedStateChanged(ActionMode mode, int position, long id, boolean checked) { - selectionManagerMode.onItemCheckedStateChanged(mode, position, id, checked); - } - - @Override - public void onDestroyActionMode(ActionMode mode) { - // Resume autorefresh - if (getActivity() != null && getActivity() instanceof TorrentsActivity) { - ((TorrentsActivity) getActivity()).stopRefresh = false; - ((TorrentsActivity) getActivity()).startAutoRefresh(); - } - selectionManagerMode.onDestroyActionMode(mode); - contextualMenu.setVisibility(View.GONE); - detailsMenu.setEnabled(true); - } - - }; - /** * Returns the object responsible for executing torrent tasks against a connected server * diff --git a/app/src/main/java/org/transdroid/core/gui/ServerPickerDialog.java b/app/src/main/java/org/transdroid/core/gui/ServerPickerDialog.java index 199ef60e..cad6a6ee 100644 --- a/app/src/main/java/org/transdroid/core/gui/ServerPickerDialog.java +++ b/app/src/main/java/org/transdroid/core/gui/ServerPickerDialog.java @@ -30,19 +30,6 @@ import java.util.List; public class ServerPickerDialog extends DialogFragment { - @Override - public Dialog onCreateDialog(Bundle savedInstanceState) { - String[] serverNames = getArguments().getStringArray("serverNames"); - return new AlertDialog.Builder(getActivity()).setTitle(R.string.navigation_pickserver) - .setItems(serverNames, new OnClickListener() { - @Override - public void onClick(DialogInterface dialog, int which) { - if (getActivity() != null && getActivity() instanceof TorrentsActivity) - ((TorrentsActivity) getActivity()).switchServerAndAddFromIntent(which); - } - }).create(); - } - /** * Opens a dialog that allows the selection of a configured server (manual or seedbox). The calling activity will * receive a callback on its switchServerAndAddFromIntent(int) method. @@ -63,4 +50,17 @@ public class ServerPickerDialog extends DialogFragment { dialog.show(activity.getFragmentManager(), "serverpicker"); } + @Override + public Dialog onCreateDialog(Bundle savedInstanceState) { + String[] serverNames = getArguments().getStringArray("serverNames"); + return new AlertDialog.Builder(getActivity()).setTitle(R.string.navigation_pickserver) + .setItems(serverNames, new OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { + if (getActivity() != null && getActivity() instanceof TorrentsActivity) + ((TorrentsActivity) getActivity()).switchServerAndAddFromIntent(which); + } + }).create(); + } + } diff --git a/app/src/main/java/org/transdroid/core/gui/ServerStatusView.java b/app/src/main/java/org/transdroid/core/gui/ServerStatusView.java index cfcbaa77..f98c88ad 100644 --- a/app/src/main/java/org/transdroid/core/gui/ServerStatusView.java +++ b/app/src/main/java/org/transdroid/core/gui/ServerStatusView.java @@ -42,6 +42,11 @@ public class ServerStatusView extends RelativeLayout implements OnRatesPickedLis @ViewById protected View speedswrapperLayout; private TorrentsActivity activity; + private OnClickListener onStartDownPickerClicked = new OnClickListener() { + public void onClick(View v) { + SetTransferRatesDialog.show(getContext(), ServerStatusView.this); + } + }; public ServerStatusView(Context context) { super(context); @@ -100,12 +105,6 @@ public class ServerStatusView extends RelativeLayout implements OnRatesPickedLis } - private OnClickListener onStartDownPickerClicked = new OnClickListener() { - public void onClick(View v) { - SetTransferRatesDialog.show(getContext(), ServerStatusView.this); - } - }; - @Override public void onRatesPicked(int maxDownloadSpeed, int maxUploadSpeed) { activity.updateMaxSpeeds(maxDownloadSpeed, maxUploadSpeed); 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 3c423ae0..1ed9c61d 100644 --- a/app/src/main/java/org/transdroid/core/gui/TorrentsActivity.java +++ b/app/src/main/java/org/transdroid/core/gui/TorrentsActivity.java @@ -188,12 +188,6 @@ public class TorrentsActivity extends AppCompatActivity implements TorrentTasksE protected ListView filtersList; @ViewById protected SearchView filterSearch; - private ListView navigationList; - private FilterListAdapter navigationListAdapter; - private ServerSelectionView serverSelectionView; - private ServerStatusView serverStatusView; - private ActionBarDrawerToggle drawerToggle; - // Settings @Bean protected ApplicationSettings applicationSettings; @@ -214,6 +208,11 @@ public class TorrentsActivity extends AppCompatActivity implements TorrentTasksE protected DetailsFragment fragmentDetails; @InstanceState boolean firstStart = true; + private ListView navigationList; + private FilterListAdapter navigationListAdapter; + private ServerSelectionView serverSelectionView; + private ServerStatusView serverStatusView; + private ActionBarDrawerToggle drawerToggle; private MenuItem searchMenu = null; private IDaemonAdapter currentConnection = null; @@ -222,6 +221,34 @@ public class TorrentsActivity extends AppCompatActivity implements TorrentTasksE private String awaitingAddLocalFile; private String awaitingAddTitle; + /** + * Handles item selections on the dedicated list of filter items + */ + private OnItemClickListener onFilterListItemClicked = new OnItemClickListener() { + @Override + public void onItemClick(AdapterView parent, View view, int position, long id) { + navigationList.setItemChecked(position, true); + Object item = navigationList.getAdapter().getItem(position); + if (item instanceof SimpleListItem) { + filterSelected((SimpleListItem) item, false); + } + if (drawerLayout != null) + drawerLayout.closeDrawer(drawerContainer); + } + }; + private SearchView.OnQueryTextListener filterQueryTextChanged = new SearchView.OnQueryTextListener() { + @Override + public boolean onQueryTextSubmit(String query) { + return false; + } + + @Override + public boolean onQueryTextChange(String newText) { + // Redirect to filter method which will directly apply it + filterTorrents(newText); + return true; + } + }; @Override public void onCreate(Bundle savedInstanceState) { @@ -524,22 +551,6 @@ public class TorrentsActivity extends AppCompatActivity implements TorrentTasksE return drawerToggle != null && drawerToggle.onOptionsItemSelected(item); } - /** - * Handles item selections on the dedicated list of filter items - */ - private OnItemClickListener onFilterListItemClicked = new OnItemClickListener() { - @Override - public void onItemClick(AdapterView parent, View view, int position, long id) { - navigationList.setItemChecked(position, true); - Object item = navigationList.getAdapter().getItem(position); - if (item instanceof SimpleListItem) { - filterSelected((SimpleListItem) item, false); - } - if (drawerLayout != null) - drawerLayout.closeDrawer(drawerContainer); - } - }; - /** * A new filter was selected; update the view over the current data * @@ -876,20 +887,6 @@ public class TorrentsActivity extends AppCompatActivity implements TorrentTasksE fragmentTorrents.sortBy(TorrentsSortBy.Size); } - private SearchView.OnQueryTextListener filterQueryTextChanged = new SearchView.OnQueryTextListener() { - @Override - public boolean onQueryTextSubmit(String query) { - return false; - } - - @Override - public boolean onQueryTextChange(String newText) { - // Redirect to filter method which will directly apply it - filterTorrents(newText); - return true; - } - }; - /** * Redirect the newly entered list filter to the torrents fragment. * diff --git a/app/src/main/java/org/transdroid/core/gui/TorrentsFragment.java b/app/src/main/java/org/transdroid/core/gui/TorrentsFragment.java index 7bbf0d80..4271df5e 100644 --- a/app/src/main/java/org/transdroid/core/gui/TorrentsFragment.java +++ b/app/src/main/java/org/transdroid/core/gui/TorrentsFragment.java @@ -71,13 +71,13 @@ import java.util.Locale; @EFragment(R.layout.fragment_torrents) public class TorrentsFragment extends Fragment implements OnLabelPickedListener { + // HACK Working around #391 while hopefully we rework the UI in the future to persist the list in db or something + protected static ArrayList torrents = null; // Local data @Bean protected ApplicationSettings applicationSettings; @Bean protected SystemSettings systemSettings; - // HACK Working around #391 while hopefully we rework the UI in the future to persist the list in db or something - protected static ArrayList torrents = null; @InstanceState protected ArrayList lastMultiSelectedTorrents; @InstanceState @@ -112,6 +112,133 @@ public class TorrentsFragment extends Fragment implements OnLabelPickedListener protected TextView errorText; @ViewById protected ProgressBar loadingProgress; + private MultiChoiceModeListener onTorrentsSelected = new MultiChoiceModeListener() { + + private SelectionManagerMode selectionManagerMode; + private ActionMenuView actionsMenu; + private Toolbar actionsToolbar; + private FloatingActionsMenu addmenuButton; + + @Override + public boolean onCreateActionMode(final ActionMode mode, Menu menu) { + // Show contextual action bars to start/stop/remove/etc. torrents in batch mode + if (actionsMenu == null) { + actionsMenu = ((TorrentsActivity) getActivity()).contextualMenu; + actionsToolbar = ((TorrentsActivity) getActivity()).actionsToolbar; + addmenuButton = ((TorrentsActivity) getActivity()).addmenuButton; + } + actionsToolbar.setEnabled(false); + actionsMenu.setVisibility(View.VISIBLE); + addmenuButton.setVisibility(View.GONE); + actionsMenu.setOnMenuItemClickListener(new ActionMenuView.OnMenuItemClickListener() { + @Override + public boolean onMenuItemClick(MenuItem menuItem) { + return onActionItemClicked(mode, menuItem); + } + }); + actionsMenu.getMenu().clear(); + getActivity().getMenuInflater().inflate(R.menu.fragment_torrents_cab, actionsMenu.getMenu()); + Context themedContext = ((AppCompatActivity) getActivity()).getSupportActionBar().getThemedContext(); + selectionManagerMode = new SelectionManagerMode(themedContext, torrentsList, R.plurals.navigation_torrentsselected); + selectionManagerMode.onCreateActionMode(mode, menu); + return true; + } + + @Override + public boolean onPrepareActionMode(ActionMode mode, Menu menu) { + selectionManagerMode.onPrepareActionMode(mode, menu); + // Hide/show options depending on the type of server we are connected to + if (daemonType != null) { + actionsMenu.getMenu().findItem(R.id.action_start).setVisible(Daemon.supportsStoppingStarting(daemonType)); + actionsMenu.getMenu().findItem(R.id.action_stop).setVisible(Daemon.supportsStoppingStarting(daemonType)); + actionsMenu.getMenu().findItem(R.id.action_setlabel).setVisible(Daemon.supportsSetLabel(daemonType)); + } + // Pause autorefresh + if (getActivity() != null && getActivity() instanceof TorrentsActivity) { + ((TorrentsActivity) getActivity()).stopRefresh = true; + ((TorrentsActivity) getActivity()).stopAutoRefresh(); + } + return true; + } + + public boolean onActionItemClicked(ActionMode mode, MenuItem item) { + + // Get checked torrents + ArrayList checked = new ArrayList<>(); + for (int i = 0; i < torrentsList.getCheckedItemPositions().size(); i++) { + if (torrentsList.getCheckedItemPositions().valueAt(i) && i < torrentsList.getAdapter().getCount()) { + checked.add((Torrent) torrentsList.getAdapter().getItem(torrentsList.getCheckedItemPositions().keyAt(i))); + } + } + + int itemId = item.getItemId(); + if (itemId == R.id.action_resume) { + for (Torrent torrent : checked) { + getTasksExecutor().resumeTorrent(torrent); + } + mode.finish(); + return true; + } else if (itemId == R.id.action_pause) { + for (Torrent torrent : checked) { + getTasksExecutor().pauseTorrent(torrent); + } + mode.finish(); + return true; + } else if (itemId == R.id.action_start) { + for (Torrent torrent : checked) { + getTasksExecutor().startTorrent(torrent, false); + } + mode.finish(); + return true; + } else if (itemId == R.id.action_stop) { + for (Torrent torrent : checked) { + getTasksExecutor().stopTorrent(torrent); + } + mode.finish(); + return true; + } else if (itemId == R.id.action_remove_default) { + for (Torrent torrent : checked) { + getTasksExecutor().removeTorrent(torrent, false); + } + mode.finish(); + return true; + } else if (itemId == R.id.action_remove_withdata) { + for (Torrent torrent : checked) { + getTasksExecutor().removeTorrent(torrent, true); + } + mode.finish(); + return true; + } else if (itemId == R.id.action_setlabel) { + lastMultiSelectedTorrents = checked; + if (currentLabels != null) { + SetLabelDialog.show(getActivity(), TorrentsFragment.this, currentLabels); + } + mode.finish(); + return true; + } else { + return false; + } + } + + @Override + public void onItemCheckedStateChanged(ActionMode mode, int position, long id, boolean checked) { + selectionManagerMode.onItemCheckedStateChanged(mode, position, id, checked); + } + + @Override + public void onDestroyActionMode(ActionMode mode) { + // Resume autorefresh + if (getActivity() != null && getActivity() instanceof TorrentsActivity) { + ((TorrentsActivity) getActivity()).stopRefresh = false; + ((TorrentsActivity) getActivity()).startAutoRefresh(); + } + selectionManagerMode.onDestroyActionMode(mode); + actionsMenu.setVisibility(View.GONE); + actionsToolbar.setEnabled(true); + addmenuButton.setVisibility(View.VISIBLE); + } + + }; @AfterViews protected void init() { @@ -272,134 +399,6 @@ public class TorrentsFragment extends Fragment implements OnLabelPickedListener updateViewVisibility(); } - private MultiChoiceModeListener onTorrentsSelected = new MultiChoiceModeListener() { - - private SelectionManagerMode selectionManagerMode; - private ActionMenuView actionsMenu; - private Toolbar actionsToolbar; - private FloatingActionsMenu addmenuButton; - - @Override - public boolean onCreateActionMode(final ActionMode mode, Menu menu) { - // Show contextual action bars to start/stop/remove/etc. torrents in batch mode - if (actionsMenu == null) { - actionsMenu = ((TorrentsActivity) getActivity()).contextualMenu; - actionsToolbar = ((TorrentsActivity) getActivity()).actionsToolbar; - addmenuButton = ((TorrentsActivity) getActivity()).addmenuButton; - } - actionsToolbar.setEnabled(false); - actionsMenu.setVisibility(View.VISIBLE); - addmenuButton.setVisibility(View.GONE); - actionsMenu.setOnMenuItemClickListener(new ActionMenuView.OnMenuItemClickListener() { - @Override - public boolean onMenuItemClick(MenuItem menuItem) { - return onActionItemClicked(mode, menuItem); - } - }); - actionsMenu.getMenu().clear(); - getActivity().getMenuInflater().inflate(R.menu.fragment_torrents_cab, actionsMenu.getMenu()); - Context themedContext = ((AppCompatActivity) getActivity()).getSupportActionBar().getThemedContext(); - selectionManagerMode = new SelectionManagerMode(themedContext, torrentsList, R.plurals.navigation_torrentsselected); - selectionManagerMode.onCreateActionMode(mode, menu); - return true; - } - - @Override - public boolean onPrepareActionMode(ActionMode mode, Menu menu) { - selectionManagerMode.onPrepareActionMode(mode, menu); - // Hide/show options depending on the type of server we are connected to - if (daemonType != null) { - actionsMenu.getMenu().findItem(R.id.action_start).setVisible(Daemon.supportsStoppingStarting(daemonType)); - actionsMenu.getMenu().findItem(R.id.action_stop).setVisible(Daemon.supportsStoppingStarting(daemonType)); - actionsMenu.getMenu().findItem(R.id.action_setlabel).setVisible(Daemon.supportsSetLabel(daemonType)); - } - // Pause autorefresh - if (getActivity() != null && getActivity() instanceof TorrentsActivity) { - ((TorrentsActivity) getActivity()).stopRefresh = true; - ((TorrentsActivity) getActivity()).stopAutoRefresh(); - } - return true; - } - - public boolean onActionItemClicked(ActionMode mode, MenuItem item) { - - // Get checked torrents - ArrayList checked = new ArrayList<>(); - for (int i = 0; i < torrentsList.getCheckedItemPositions().size(); i++) { - if (torrentsList.getCheckedItemPositions().valueAt(i) && i < torrentsList.getAdapter().getCount()) { - checked.add((Torrent) torrentsList.getAdapter().getItem(torrentsList.getCheckedItemPositions().keyAt(i))); - } - } - - int itemId = item.getItemId(); - if (itemId == R.id.action_resume) { - for (Torrent torrent : checked) { - getTasksExecutor().resumeTorrent(torrent); - } - mode.finish(); - return true; - } else if (itemId == R.id.action_pause) { - for (Torrent torrent : checked) { - getTasksExecutor().pauseTorrent(torrent); - } - mode.finish(); - return true; - } else if (itemId == R.id.action_start) { - for (Torrent torrent : checked) { - getTasksExecutor().startTorrent(torrent, false); - } - mode.finish(); - return true; - } else if (itemId == R.id.action_stop) { - for (Torrent torrent : checked) { - getTasksExecutor().stopTorrent(torrent); - } - mode.finish(); - return true; - } else if (itemId == R.id.action_remove_default) { - for (Torrent torrent : checked) { - getTasksExecutor().removeTorrent(torrent, false); - } - mode.finish(); - return true; - } else if (itemId == R.id.action_remove_withdata) { - for (Torrent torrent : checked) { - getTasksExecutor().removeTorrent(torrent, true); - } - mode.finish(); - return true; - } else if (itemId == R.id.action_setlabel) { - lastMultiSelectedTorrents = checked; - if (currentLabels != null) { - SetLabelDialog.show(getActivity(), TorrentsFragment.this, currentLabels); - } - mode.finish(); - return true; - } else { - return false; - } - } - - @Override - public void onItemCheckedStateChanged(ActionMode mode, int position, long id, boolean checked) { - selectionManagerMode.onItemCheckedStateChanged(mode, position, id, checked); - } - - @Override - public void onDestroyActionMode(ActionMode mode) { - // Resume autorefresh - if (getActivity() != null && getActivity() instanceof TorrentsActivity) { - ((TorrentsActivity) getActivity()).stopRefresh = false; - ((TorrentsActivity) getActivity()).startAutoRefresh(); - } - selectionManagerMode.onDestroyActionMode(mode); - actionsMenu.setVisibility(View.GONE); - actionsToolbar.setEnabled(true); - addmenuButton.setVisibility(View.VISIBLE); - } - - }; - @Click protected void emptyTextClicked() { // Refresh the activity (that contains this fragment) when the empty view gear is clicked diff --git a/app/src/main/java/org/transdroid/core/gui/lists/LocalTorrent.java b/app/src/main/java/org/transdroid/core/gui/lists/LocalTorrent.java index 42b0bba1..8a89ec5d 100644 --- a/app/src/main/java/org/transdroid/core/gui/lists/LocalTorrent.java +++ b/app/src/main/java/org/transdroid/core/gui/lists/LocalTorrent.java @@ -35,6 +35,14 @@ import java.util.Locale; */ public class LocalTorrent { + private static final String DECIMAL_FORMATTER = "%.1f"; + private static final String DECIMAL_FORMATTER_2 = "%.2f"; + private final Torrent t; + + private LocalTorrent(Torrent torrent) { + this.t = torrent; + } + /** * Creates the LocalTorrent object so that the translatable/formattable version of a Torrent can be used. * @@ -45,15 +53,33 @@ public class LocalTorrent { return new LocalTorrent(torrent); } - private final Torrent t; - - private LocalTorrent(Torrent torrent) { - this.t = torrent; + /** + * Convert a DaemonException to a translatable human-readable error message + * + * @param e The exception that was thrown by the server + * @return A string resource ID to show to the user + */ + public static int getResourceForDaemonException(DaemonException e) { + switch (e.getType()) { + case MethodUnsupported: + return R.string.error_unsupported; + case ConnectionError: + return R.string.error_httperror; + case UnexpectedResponse: + return R.string.error_jsonresponseerror; + case ParsingFailed: + return R.string.error_jsonrequesterror; + case NotConnected: + return R.string.error_daemonnotconnected; + case AuthenticationFailure: + return R.string.error_401; + case FileAccessError: + return R.string.error_torrentfile; + default: + return R.string.error_httperror; + } } - private static final String DECIMAL_FORMATTER = "%.1f"; - private static final String DECIMAL_FORMATTER_2 = "%.2f"; - /** * Builds a string showing the upload/download seed ratio. If not downloading, it will base the ratio on the total * size; so if you created the torrent yourself you will have downloaded 0 bytes, but the ratio will pretend you @@ -230,31 +256,4 @@ public class LocalTorrent { TimespanConverter.getTime(t.getEta(), inDays)); } - /** - * Convert a DaemonException to a translatable human-readable error message - * - * @param e The exception that was thrown by the server - * @return A string resource ID to show to the user - */ - public static int getResourceForDaemonException(DaemonException e) { - switch (e.getType()) { - case MethodUnsupported: - return R.string.error_unsupported; - case ConnectionError: - return R.string.error_httperror; - case UnexpectedResponse: - return R.string.error_jsonresponseerror; - case ParsingFailed: - return R.string.error_jsonrequesterror; - case NotConnected: - return R.string.error_daemonnotconnected; - case AuthenticationFailure: - return R.string.error_401; - case FileAccessError: - return R.string.error_torrentfile; - default: - return R.string.error_httperror; - } - } - } diff --git a/app/src/main/java/org/transdroid/core/gui/lists/PiecesMapView.java b/app/src/main/java/org/transdroid/core/gui/lists/PiecesMapView.java index 0c9ed7c5..18c27b5b 100644 --- a/app/src/main/java/org/transdroid/core/gui/lists/PiecesMapView.java +++ b/app/src/main/java/org/transdroid/core/gui/lists/PiecesMapView.java @@ -15,12 +15,10 @@ class PiecesMapView extends View { private final float scale = getContext().getResources().getDisplayMetrics().density; private final int MINIMUM_HEIGHT = (int) (25 * scale); private final int MINIMUM_PIECE_WIDTH = (int) (2 * scale); - - private ArrayList pieces = null; - private final Paint downloadingPaint = new Paint(); private final Paint donePaint = new Paint(); private final Paint partialDonePaint = new Paint(); + private ArrayList pieces = null; public PiecesMapView(Context context) { super(context); diff --git a/app/src/main/java/org/transdroid/core/gui/lists/SimpleListItemAdapter.java b/app/src/main/java/org/transdroid/core/gui/lists/SimpleListItemAdapter.java index f01e81d6..24d58a6c 100644 --- a/app/src/main/java/org/transdroid/core/gui/lists/SimpleListItemAdapter.java +++ b/app/src/main/java/org/transdroid/core/gui/lists/SimpleListItemAdapter.java @@ -84,6 +84,12 @@ public class SimpleListItemAdapter extends BaseAdapter { */ public static class SimpleStringItem implements SimpleListItem { + private final String string; + + public SimpleStringItem(String string) { + this.string = string; + } + /** * Wraps a simple string of strings into a list of SimpleStringItem to add as data to a * {@link SimpleListItemAdapter} @@ -101,12 +107,6 @@ public class SimpleListItemAdapter extends BaseAdapter { return errors; } - private final String string; - - public SimpleStringItem(String string) { - this.string = string; - } - @Override public String getName() { return this.string; diff --git a/app/src/main/java/org/transdroid/core/gui/lists/TorrentFilePriorityLayout.java b/app/src/main/java/org/transdroid/core/gui/lists/TorrentFilePriorityLayout.java index 560e7463..456d39db 100644 --- a/app/src/main/java/org/transdroid/core/gui/lists/TorrentFilePriorityLayout.java +++ b/app/src/main/java/org/transdroid/core/gui/lists/TorrentFilePriorityLayout.java @@ -37,13 +37,12 @@ public class TorrentFilePriorityLayout extends RelativeLayout { private final float scale = getContext().getResources().getDisplayMetrics().density; private final int WIDTH = (int) (6 * scale + 0.5f); - - private Priority priority = null; private final Paint offPaint = new Paint(); private final Paint lowPaint = new Paint(); private final Paint highPaint = new Paint(); private final Paint normalPaint = new Paint(); private final RectF fullRect = new RectF(); + private Priority priority = null; public TorrentFilePriorityLayout(Context context) { super(context); diff --git a/app/src/main/java/org/transdroid/core/gui/lists/TorrentProgressBar.java b/app/src/main/java/org/transdroid/core/gui/lists/TorrentProgressBar.java index 5b9a7fe5..7dec796b 100644 --- a/app/src/main/java/org/transdroid/core/gui/lists/TorrentProgressBar.java +++ b/app/src/main/java/org/transdroid/core/gui/lists/TorrentProgressBar.java @@ -35,10 +35,6 @@ public class TorrentProgressBar extends View { private final float scale = getContext().getResources().getDisplayMetrics().density; private final int MINIMUM_HEIGHT = (int) (3 * scale + 0.5f); - - private int progress; - private boolean isActive; - private boolean isError; private final Paint notdonePaint = new Paint(); private final Paint inactiveDonePaint = new Paint(); private final Paint inactivePaint = new Paint(); @@ -47,21 +43,9 @@ public class TorrentProgressBar extends View { private final Paint errorPaint = new Paint(); private final RectF fullRect = new RectF(); private final RectF progressRect = new RectF(); - - public void setProgress(int progress) { - this.progress = progress; - this.invalidate(); - } - - public void setActive(boolean isActive) { - this.isActive = isActive; - this.invalidate(); - } - - public void setError(boolean isError) { - this.isError = isError; - this.invalidate(); - } + private int progress; + private boolean isActive; + private boolean isError; public TorrentProgressBar(Context context) { super(context); @@ -81,6 +65,21 @@ public class TorrentProgressBar extends View { a.recycle(); } + public void setProgress(int progress) { + this.progress = progress; + this.invalidate(); + } + + public void setActive(boolean isActive) { + this.isActive = isActive; + this.invalidate(); + } + + public void setError(boolean isError) { + this.isError = isError; + this.invalidate(); + } + private void initPaints() { notdonePaint.setColor(getResources().getColor(R.color.torrent_background)); inactiveDonePaint.setColor(getResources().getColor(R.color.torrent_paused)); diff --git a/app/src/main/java/org/transdroid/core/gui/lists/TorrentStatusLayout.java b/app/src/main/java/org/transdroid/core/gui/lists/TorrentStatusLayout.java index 838eabf6..04dace96 100644 --- a/app/src/main/java/org/transdroid/core/gui/lists/TorrentStatusLayout.java +++ b/app/src/main/java/org/transdroid/core/gui/lists/TorrentStatusLayout.java @@ -37,14 +37,13 @@ public class TorrentStatusLayout extends RelativeLayout { private final float scale = getContext().getResources().getDisplayMetrics().density; private final int WIDTH = (int) (6 * scale + 0.5f); - - private TorrentStatus status = null; private final Paint pausedPaint = new Paint(); private final Paint otherPaint = new Paint(); private final Paint downloadingPaint = new Paint(); private final Paint seedingPaint = new Paint(); private final Paint errorPaint = new Paint(); private final RectF fullRect = new RectF(); + private TorrentStatus status = null; public TorrentStatusLayout(Context context) { super(context); diff --git a/app/src/main/java/org/transdroid/core/gui/lists/TorrentsAdapter.java b/app/src/main/java/org/transdroid/core/gui/lists/TorrentsAdapter.java index b681479e..02381ca2 100644 --- a/app/src/main/java/org/transdroid/core/gui/lists/TorrentsAdapter.java +++ b/app/src/main/java/org/transdroid/core/gui/lists/TorrentsAdapter.java @@ -35,10 +35,9 @@ import java.util.ArrayList; @EBean public class TorrentsAdapter extends BaseAdapter { - private ArrayList torrents = null; - @RootContext protected Context context; + private ArrayList torrents = null; /** * Allows updating the full internal list of torrents at once, replacing the old list diff --git a/app/src/main/java/org/transdroid/core/gui/log/ErrorLogEntry.java b/app/src/main/java/org/transdroid/core/gui/log/ErrorLogEntry.java index 460d8af6..bf28ec82 100644 --- a/app/src/main/java/org/transdroid/core/gui/log/ErrorLogEntry.java +++ b/app/src/main/java/org/transdroid/core/gui/log/ErrorLogEntry.java @@ -34,7 +34,15 @@ public class ErrorLogEntry implements Parcelable { public static final String ID = "logId"; public static final String DATEANDTIME = "dateAndTime"; + public static final Parcelable.Creator CREATOR = new Parcelable.Creator() { + public ErrorLogEntry createFromParcel(Parcel in) { + return new ErrorLogEntry(in); + } + public ErrorLogEntry[] newArray(int size) { + return new ErrorLogEntry[size]; + } + }; @DatabaseField(id = true, columnName = ID) private Integer logId; @DatabaseField(columnName = DATEANDTIME) @@ -56,6 +64,14 @@ public class ErrorLogEntry implements Parcelable { this.message = message; } + private ErrorLogEntry(Parcel in) { + logId = in.readInt(); + dateAndTime = new Date(in.readLong()); + priority = in.readInt(); + tag = in.readString(); + message = in.readString(); + } + public Integer getLogId() { return logId; } @@ -88,22 +104,4 @@ public class ErrorLogEntry implements Parcelable { out.writeString(message); } - public static final Parcelable.Creator CREATOR = new Parcelable.Creator() { - public ErrorLogEntry createFromParcel(Parcel in) { - return new ErrorLogEntry(in); - } - - public ErrorLogEntry[] newArray(int size) { - return new ErrorLogEntry[size]; - } - }; - - private ErrorLogEntry(Parcel in) { - logId = in.readInt(); - dateAndTime = new Date(in.readLong()); - priority = in.readInt(); - tag = in.readString(); - message = in.readString(); - } - } diff --git a/app/src/main/java/org/transdroid/core/gui/navigation/DialogHelper.java b/app/src/main/java/org/transdroid/core/gui/navigation/DialogHelper.java index 1b2ca323..a8deff86 100644 --- a/app/src/main/java/org/transdroid/core/gui/navigation/DialogHelper.java +++ b/app/src/main/java/org/transdroid/core/gui/navigation/DialogHelper.java @@ -45,6 +45,27 @@ public class DialogHelper extends Activity { @Extra protected DialogSpecification dialog; + /** + * Call this from {@link Activity#onCreateDialog(int)}, supplying an instance of the {@link DialogSpecification} + * that should be shown to the user. + * + * @param context The activity that calls this method and which will own the constructed dialog + * @param dialog An instance of the specification for the dialog that needs to be shown + * @return Either an instance of a {@link Dialog} that the activity should further control or null if the dialog + * will instead be opened as a full screen activity + */ + public static Dialog showDialog(Context context, DialogSpecification dialog) { + + // If the device is large (i.e. a tablet) then return a dialog to show + if (!NavigationHelper_.getInstance_(context).isSmallScreen()) + return new PopupDialog(context, dialog); + + // This is a small device; create a full screen dialog (which is just an activity) + DialogHelper_.intent(context).dialog(dialog).start(); + return null; + + } + @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); @@ -70,24 +91,16 @@ public class DialogHelper extends Activity { } /** - * Call this from {@link Activity#onCreateDialog(int)}, supplying an instance of the {@link DialogSpecification} - * that should be shown to the user. - * - * @param context The activity that calls this method and which will own the constructed dialog - * @param dialog An instance of the specification for the dialog that needs to be shown - * @return Either an instance of a {@link Dialog} that the activity should further control or null if the dialog - * will instead be opened as a full screen activity + * Specification for some dialog that can be show to the user, consisting of a custom layout and possibly an action + * bar menu. Warning: the action bar, and thus the menu options, is only shown when the dialog is presented as full + * screen activity. Use only for unimportant actions. */ - public static Dialog showDialog(Context context, DialogSpecification dialog) { - - // If the device is large (i.e. a tablet) then return a dialog to show - if (!NavigationHelper_.getInstance_(context).isSmallScreen()) - return new PopupDialog(context, dialog); + public interface DialogSpecification extends Serializable { + int getDialogLayoutId(); - // This is a small device; create a full screen dialog (which is just an activity) - DialogHelper_.intent(context).dialog(dialog).start(); - return null; + int getDialogMenuId(); + boolean onMenuItemSelected(Activity ownerActivity, int selectedItemId); } /** @@ -101,17 +114,4 @@ public class DialogHelper extends Activity { } } - /** - * Specification for some dialog that can be show to the user, consisting of a custom layout and possibly an action - * bar menu. Warning: the action bar, and thus the menu options, is only shown when the dialog is presented as full - * screen activity. Use only for unimportant actions. - */ - public interface DialogSpecification extends Serializable { - int getDialogLayoutId(); - - int getDialogMenuId(); - - boolean onMenuItemSelected(Activity ownerActivity, int selectedItemId); - } - } diff --git a/app/src/main/java/org/transdroid/core/gui/navigation/FilterListAdapter.java b/app/src/main/java/org/transdroid/core/gui/navigation/FilterListAdapter.java index 05201f75..5cf8e89f 100644 --- a/app/src/main/java/org/transdroid/core/gui/navigation/FilterListAdapter.java +++ b/app/src/main/java/org/transdroid/core/gui/navigation/FilterListAdapter.java @@ -41,12 +41,12 @@ public class FilterListAdapter extends MergeAdapter { @RootContext protected Context context; - private FilterListItemAdapter serverItems = null; - private FilterListItemAdapter statusTypeItems = null; - private FilterListItemAdapter labelItems = null; protected ViewHolderAdapter statusTypeSeparator; protected ViewHolderAdapter labelSeperator; protected ViewHolderAdapter serverSeparator; + private FilterListItemAdapter serverItems = null; + private FilterListItemAdapter statusTypeItems = null; + private FilterListItemAdapter labelItems = null; /** * Update the list of available servers diff --git a/app/src/main/java/org/transdroid/core/gui/navigation/Label.java b/app/src/main/java/org/transdroid/core/gui/navigation/Label.java index 10d6e600..adab87e7 100644 --- a/app/src/main/java/org/transdroid/core/gui/navigation/Label.java +++ b/app/src/main/java/org/transdroid/core/gui/navigation/Label.java @@ -34,8 +34,16 @@ import java.util.List; */ public class Label implements SimpleListItem, NavigationFilter, Comparable