Browse Source

Merge pull request #559 from TacoTheDank/master

Lots of code cleanup
pull/565/head
Eric Kok 4 years ago committed by GitHub
parent
commit
6f07529b6a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 9
      .editorconfig
  2. 107
      README.md
  3. 2
      app/build.gradle
  4. 3
      app/src/full/res/values/bools.xml
  5. 3
      app/src/lite/res/values/bools.xml
  6. 4
      app/src/lite/res/values/strings.xml
  7. 12
      app/src/main/AndroidManifest.xml
  8. 3
      app/src/main/java/androidx/preference/PreferenceManagerBinder.java
  9. 30
      app/src/main/java/org/transdroid/core/app/search/SearchHelper.java
  10. 48
      app/src/main/java/org/transdroid/core/app/search/SearchResult.java
  11. 1
      app/src/main/java/org/transdroid/core/app/search/SearchSite.java
  12. 93
      app/src/main/java/org/transdroid/core/app/settings/ApplicationSettings.java
  13. 8
      app/src/main/java/org/transdroid/core/app/settings/NotificationSettings.java
  14. 12
      app/src/main/java/org/transdroid/core/app/settings/RssfeedSetting.java
  15. 6
      app/src/main/java/org/transdroid/core/app/settings/ServerSetting.java
  16. 14
      app/src/main/java/org/transdroid/core/app/settings/SettingsPersistence.java
  17. 1
      app/src/main/java/org/transdroid/core/app/settings/SettingsUtils.java
  18. 4
      app/src/main/java/org/transdroid/core/app/settings/SystemSettings.java
  19. 11
      app/src/main/java/org/transdroid/core/app/settings/WebsearchSetting.java
  20. 9
      app/src/main/java/org/transdroid/core/gui/DetailsActivity.java
  21. 363
      app/src/main/java/org/transdroid/core/gui/DetailsFragment.java
  22. 37
      app/src/main/java/org/transdroid/core/gui/ServerPickerDialog.java
  23. 2
      app/src/main/java/org/transdroid/core/gui/ServerSelectionView.java
  24. 9
      app/src/main/java/org/transdroid/core/gui/ServerStatusView.java
  25. 4
      app/src/main/java/org/transdroid/core/gui/TorrentTasksExecutor.java
  26. 131
      app/src/main/java/org/transdroid/core/gui/TorrentsActivity.java
  27. 280
      app/src/main/java/org/transdroid/core/gui/TorrentsFragment.java
  28. 12
      app/src/main/java/org/transdroid/core/gui/TransdroidApp.java
  29. 31
      app/src/main/java/org/transdroid/core/gui/lists/DetailsAdapter.java
  30. 86
      app/src/main/java/org/transdroid/core/gui/lists/LocalTorrent.java
  31. 21
      app/src/main/java/org/transdroid/core/gui/lists/MergeAdapter.java
  32. 24
      app/src/main/java/org/transdroid/core/gui/lists/PiecesMapView.java
  33. 3
      app/src/main/java/org/transdroid/core/gui/lists/SimpleListItem.java
  34. 25
      app/src/main/java/org/transdroid/core/gui/lists/SimpleListItemAdapter.java
  35. 6
      app/src/main/java/org/transdroid/core/gui/lists/SimpleListItemSpinnerAdapter.java
  36. 1
      app/src/main/java/org/transdroid/core/gui/lists/SimpleListItemView.java
  37. 3
      app/src/main/java/org/transdroid/core/gui/lists/SortByListItem.java
  38. 2
      app/src/main/java/org/transdroid/core/gui/lists/TorrentDetailsView.java
  39. 14
      app/src/main/java/org/transdroid/core/gui/lists/TorrentFilePriorityLayout.java
  40. 1
      app/src/main/java/org/transdroid/core/gui/lists/TorrentFileView.java
  41. 41
      app/src/main/java/org/transdroid/core/gui/lists/TorrentProgressBar.java
  42. 15
      app/src/main/java/org/transdroid/core/gui/lists/TorrentStatusLayout.java
  43. 1
      app/src/main/java/org/transdroid/core/gui/lists/TorrentView.java
  44. 5
      app/src/main/java/org/transdroid/core/gui/lists/TorrentsAdapter.java
  45. 4
      app/src/main/java/org/transdroid/core/gui/lists/ViewHolderAdapter.java
  46. 10
      app/src/main/java/org/transdroid/core/gui/log/DatabaseHelper.java
  47. 39
      app/src/main/java/org/transdroid/core/gui/log/ErrorLogEntry.java
  48. 14
      app/src/main/java/org/transdroid/core/gui/log/ErrorLogSender.java
  49. 1
      app/src/main/java/org/transdroid/core/gui/log/Log.java
  50. 66
      app/src/main/java/org/transdroid/core/gui/navigation/DialogHelper.java
  51. 17
      app/src/main/java/org/transdroid/core/gui/navigation/FilterListAdapter.java
  52. 3
      app/src/main/java/org/transdroid/core/gui/navigation/FilterListItemAdapter.java
  53. 1
      app/src/main/java/org/transdroid/core/gui/navigation/FilterListItemView.java
  54. 2
      app/src/main/java/org/transdroid/core/gui/navigation/FilterSeparatorView.java
  55. 87
      app/src/main/java/org/transdroid/core/gui/navigation/Label.java
  56. 4
      app/src/main/java/org/transdroid/core/gui/navigation/NavigationFilter.java
  57. 154
      app/src/main/java/org/transdroid/core/gui/navigation/NavigationHelper.java
  58. 1
      app/src/main/java/org/transdroid/core/gui/navigation/RefreshableActivity.java
  59. 9
      app/src/main/java/org/transdroid/core/gui/navigation/SelectionManagerMode.java
  60. 35
      app/src/main/java/org/transdroid/core/gui/navigation/SelectionModificationSpinner.java
  61. 21
      app/src/main/java/org/transdroid/core/gui/navigation/SetLabelDialog.java
  62. 6
      app/src/main/java/org/transdroid/core/gui/navigation/SetStorageLocationDialog.java
  63. 9
      app/src/main/java/org/transdroid/core/gui/navigation/SetTrackersDialog.java
  64. 37
      app/src/main/java/org/transdroid/core/gui/navigation/SetTransferRatesDialog.java
  65. 44
      app/src/main/java/org/transdroid/core/gui/navigation/StatusType.java
  66. 7
      app/src/main/java/org/transdroid/core/gui/remoterss/RemoteRssFragment.java
  67. 1
      app/src/main/java/org/transdroid/core/gui/remoterss/RemoteRssItemView.java
  68. 3
      app/src/main/java/org/transdroid/core/gui/remoterss/RemoteRssItemsAdapter.java
  69. 151
      app/src/main/java/org/transdroid/core/gui/rss/RssFeedsActivity.java
  70. 4
      app/src/main/java/org/transdroid/core/gui/rss/RssFeedsFragment.java
  71. 1
      app/src/main/java/org/transdroid/core/gui/rss/RssItemsActivity.java
  72. 15
      app/src/main/java/org/transdroid/core/gui/rss/RssItemsFragment.java
  73. 13
      app/src/main/java/org/transdroid/core/gui/rss/RssfeedLoader.java
  74. 1
      app/src/main/java/org/transdroid/core/gui/rss/RssfeedView.java
  75. 5
      app/src/main/java/org/transdroid/core/gui/rss/RssfeedsAdapter.java
  76. 5
      app/src/main/java/org/transdroid/core/gui/rss/RssitemStatusLayout.java
  77. 1
      app/src/main/java/org/transdroid/core/gui/rss/RssitemView.java
  78. 5
      app/src/main/java/org/transdroid/core/gui/rss/RssitemsAdapter.java
  79. 11
      app/src/main/java/org/transdroid/core/gui/search/BarcodeHelper.java
  80. 14
      app/src/main/java/org/transdroid/core/gui/search/FilePickerHelper.java
  81. 62
      app/src/main/java/org/transdroid/core/gui/search/SearchActivity.java
  82. 1
      app/src/main/java/org/transdroid/core/gui/search/SearchHistoryProvider.java
  83. 11
      app/src/main/java/org/transdroid/core/gui/search/SearchResultView.java
  84. 5
      app/src/main/java/org/transdroid/core/gui/search/SearchResultsAdapter.java
  85. 144
      app/src/main/java/org/transdroid/core/gui/search/SearchResultsFragment.java
  86. 6
      app/src/main/java/org/transdroid/core/gui/search/SearchSetting.java
  87. 1
      app/src/main/java/org/transdroid/core/gui/search/SearchSettingSelectionView.java
  88. 3
      app/src/main/java/org/transdroid/core/gui/search/SearchSettingsDropDownAdapter.java
  89. 1
      app/src/main/java/org/transdroid/core/gui/search/SearchSiteView.java
  90. 5
      app/src/main/java/org/transdroid/core/gui/search/SearchSitesAdapter.java
  91. 2
      app/src/main/java/org/transdroid/core/gui/search/SendIntentHelper.java
  92. 12
      app/src/main/java/org/transdroid/core/gui/search/UrlEntryDialog.java
  93. 7
      app/src/main/java/org/transdroid/core/gui/settings/AboutDialog.java
  94. 7
      app/src/main/java/org/transdroid/core/gui/settings/ChangelogDialog.java
  95. 53
      app/src/main/java/org/transdroid/core/gui/settings/HelpSettingsActivity.java
  96. 22
      app/src/main/java/org/transdroid/core/gui/settings/KeyBoundPreferencesActivity.java
  97. 75
      app/src/main/java/org/transdroid/core/gui/settings/MainSettingsActivity.java
  98. 17
      app/src/main/java/org/transdroid/core/gui/settings/RssfeedPreference.java
  99. 12
      app/src/main/java/org/transdroid/core/gui/settings/RssfeedSettingsActivity.java
  100. 19
      app/src/main/java/org/transdroid/core/gui/settings/ServerPreference.java
  101. Some files were not shown because too many files have changed in this diff Show More

9
.editorconfig

@ -0,0 +1,9 @@ @@ -0,0 +1,9 @@
# editorconfig.org
root = true
[*]
charset = utf-8
end_of_line = lf
indent_style = space
insert_final_newline = true
trim_trailing_whitespace = true

107
README.md

@ -1,44 +1,65 @@ @@ -1,44 +1,65 @@
Transdroid
==========
[www.transdroid.org](http://www.transdroid.org)
[www.transdroid.org](https://www.transdroid.org/)
[Twitter](https://twitter.com/transdroid) - [transdroid@2312.nl](transdroid@2312.nl)
"Manage your torrents from your Android device"
<a href="https://transdroid.org/latest" target="_blank">
<img src="https://transdroid.org/images/getontransdroid.png" alt="Get it on transdroid.org" height="80"/></a>
<a href="https://f-droid.org/repository/browse/?fdid=org.transdroid.full" target="_blank">
<img src="https://f-droid.org/badge/get-it-on.png" alt="Get it on F-Droid" height="80"/></a>
<a href="https://play.google.com/store/apps/details?id=org.transdroid.lite" target="_blank">
<img src="https://play.google.com/intl/en_us/badges/images/generic/en-play-badge.png" alt="Get it on Google Play" height="80"/></a>
<img src="http://2312.nl/images/screenshot_transdroid_main.png" alt="Screen shot of the main torrents listing screen" width="280" />
Manage your torrents from your Android device with Transdroid. All popular clients are supported: µTorrent, Transmission, rTorrent, Vuze, Deluge, BitTorrent 6, qBittorrent and many more. You can view and manage the running torrents and individual files. Adding is easy via the integrated search or RSS feeds (full version required). Monitor progress using the home screen widget or background alarm service.
Manage torrents from your Android device.
<a href="https://transdroid.org/latest">
<img src="https://transdroid.org/images/getontransdroid.png"
alt="Get it on transdroid.org"
height="80">
</a>
<a href="https://f-droid.org/packages/org.transdroid.full/">
<img src="https://fdroid.gitlab.io/artwork/badge/get-it-on.png"
alt="Get it on F-Droid"
height="80">
</a>
<a href="https://play.google.com/store/apps/details?id=org.transdroid.lite">
<img src="https://play.google.com/intl/en_us/badges/static/images/badges/en_badge_web_generic.png"
alt="Get it on Google Play"
height="80">
</a>
<img src="https://2312.nl/images/screenshot_transdroid_main.png" alt="Screen shot of the main torrents listing screen" width="280" />
Manage your torrents from your Android device with Transdroid.
All popular clients are supported: µTorrent, Transmission, rTorrent, Vuze, Deluge, BitTorrent 6, qBittorrent, and many more.
You can view and manage running torrents and individual files.
Adding is easy via the integrated search or RSS feeds (full version required).
Monitor progress using the home screen widget or background alarm service.
Contributions
=============
Code and design contributions are very welcome. You might want to contact me via social networks (G+, Twitter) or e-mail first. Please note all code will be GNU GPL v3 licensed.
Code and design contributions are very welcome.
You might want to contact me via social networks (Twitter) or e-mail first.
Please note that all code will be licensed in GNU GPLv3.
Please respect the coding standards for easier merging. master contains the current release version of Transdroid while dev contains the active development version. However, larger, new features are developed in their own branch.
Please respect the coding standards for easier merging.
`master` contains the current release version of Transdroid while `dev` contains the active development version.
However, larger and new features will be developed in their own branch.
Code structure
==============
Starting with version 2.3.0, Transdroid is developed in Android Studio, fully integrating with the Gradle build system. It is (since version 2.5.0) compiled against Android 5.1 (API level 22) and (since version 2.2.0) supporting ICS (API level 15) and up only. To support lite (Transdrone, specially for the Play Store) and full (Transdroid) versions of the app, build flavours are defined in gradle, which contain version-specific resources. Dependencies are managed via JCentral et al. in the app's build.gradle file.
Starting with version 2.3.0, Transdroid is developed in Android Studio, fully integrating with the Gradle build system.
It is (since version 2.5.18) compiled against Android 10 (API level 29) and (since version 2.2.0) supporting Android ICS (API level 15) and up only.
To support lite (Transdrone, specially for the Play Store) and full (Transdroid) versions of the app, build flavours are defined in gradle, which contain version-specific resources.
Dependencies are managed via JCentral et al. in the app's build.gradle file.
Developed By
============
Designed and developed by [Eric Kok](eric@2312.nl) of [2312 development](http://2312.nl). Contributions by various others (see commit log).
Designed and developed by [Eric Kok](eric@2312.nl) of [2312 development](https://2312.nl/).
Contributions by various others (see commit log).
License
=======
Copyright 2010-2018 Eric Kok et al.
Copyright 2010-2020 Eric Kok et al.
Transdroid is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@ -51,39 +72,51 @@ License @@ -51,39 +72,51 @@ License
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Transdroid. If not, see <http://www.gnu.org/licenses/>.
along with Transdroid. If not, see <https://www.gnu.org/licenses/>.
Some code/libraries/resources are used in the project:
* [Android Jetpack (AndroidX)](https://developer.android.com/jetpack)
The Android Open Source Project
Apache License, Version 2.0
* [AndroidAnnotations](http://androidannotations.org/)
Pierre-Yves Ricau (eBusinessInformations) et al.
Apache License, Version 2.0
* [ActionBar-PullToRefresh](https://github.com/chrisbanes/ActionBar-PullToRefresh)
Chris Banes
* [ORMLite](https://github.com/j256/ormlite-core) and [ORMLite Android](https://github.com/j256/ormlite-android)
Gray Watson
ISC License
* [Android Universal Image Loader](https://github.com/nostra13/Android-Universal-Image-Loader)
Sergey Tarasevich
Apache License, Version 2.0
* [Crouton](https://github.com/keyboardsurfer/Crouton)
Code: Benjamin Weiss (Neofonie Mobile Gmbh) et al.
Idea: Cyril Mottier
* [FloatingActionButton](https://github.com/zendesk/android-floating-action-button)
Oleksandr Melnykov, Zendesk
Apache License, Version 2.0
* [Base16Encoder](http://openjpa.apache.org/)
* [Snackbar](https://github.com/nispok/snackbar)
William Mora
MIT License
* [Java implementation of Rencode](https://github.com/aegnor/rencode-java)
Daniel Dimovski
MIT License
* [OpenJPA's Base16Encoder](https://github.com/apache/openjpa)
Marc Prud'hommeaux
Apache OpenJPA
* MultipartEntity
Apache Software Foundation
Apache License, Version 2.0
* RssParser ([learning-android](http://github.com/digitalspaghetti/learning-android))
Tane Piper
Public Domain
* [Base64](http://iharder.net/base64)
* [Base64](http://iharder.sourceforge.net/current/java/base64/)
Robert Harder
Public Domain
* [aXMLRPC](https://github.com/timroes/aXMLRPC)
* [aXMLRPC](https://github.com/gturri/aXMLRPC)
Tim Roes
MIT License
* [Material Dialogs](https://github.com/afollestad/material-dialogs)
Aidan Follestad
Apache License, Version 2.0
* [Android-Job](https://github.com/evernote/android-job)
Evernote Corporation
Apache License, Version 2.0
* [android-ColorPickerPreference](https://github.com/attenzione/android-ColorPickerPreference)
Daniel Nilsson and Sergey Margaritov
Apache License, Version 2.0
* [Funnel icon](http://thenounproject.com/noun/funnel/#icon-No5608)
* RssParser ([learning-android](https://github.com/tanepiper/learning-android))
Tane Piper
Public Domain
* [Funnel icon](https://thenounproject.com/term/funnel/5608/)
Naomi Atkinson from The Noun Project
Creative Commons Attribution 3.0

2
app/build.gradle

@ -79,7 +79,7 @@ dependencies { @@ -79,7 +79,7 @@ dependencies {
// Android support
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'androidx.preference:preference:1.1.1'
implementation 'androidx.swiperefreshlayout:swiperefreshlayout:1.0.0'
implementation 'androidx.swiperefreshlayout:swiperefreshlayout:1.1.0'
implementation 'com.google.android.material:material:1.1.0'
// Other

3
app/src/full/res/values/bools.xml

@ -1,5 +1,4 @@ @@ -1,5 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
<?xml version="1.0" encoding="utf-8"?><!--
Copyright 2010-2018 Eric Kok et al.
Transdroid is free software: you can redistribute it and/or modify

3
app/src/lite/res/values/bools.xml

@ -1,5 +1,4 @@ @@ -1,5 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
<?xml version="1.0" encoding="utf-8"?><!--
Copyright 2010-2018 Eric Kok et al.
Transdroid is free software: you can redistribute it and/or modify

4
app/src/lite/res/values/strings.xml

@ -18,7 +18,7 @@ @@ -18,7 +18,7 @@
<string name="app_name" translatable="false">Transdrone</string>
<string name="donate_text"></string>
<string name="donate_url"></string>
<string name="donate_text" />
<string name="donate_url" />
</resources>

12
app/src/main/AndroidManifest.xml

@ -1,5 +1,4 @@ @@ -1,5 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
<?xml version="1.0" encoding="utf-8"?><!--
Copyright 2010-2018 Eric Kok et al.
Transdroid is free software: you can redistribute it and/or modify
@ -51,10 +50,11 @@ @@ -51,10 +50,11 @@
<application
android:name=".core.gui.TransdroidApp_"
android:allowBackup="true"
android:banner="@drawable/banner"
android:hardwareAccelerated="true"
android:icon="@drawable/ic_launcher"
android:banner="@drawable/banner"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/Theme.AppCompat"
android:usesCleartextTraffic="true">
@ -193,8 +193,7 @@ @@ -193,8 +193,7 @@
<activity
android:name="org.transdroid.core.gui.DetailsActivity_"
android:theme="@style/TransdroidTheme"
android:uiOptions="splitActionBarWhenNarrow" >
</activity>
android:uiOptions="splitActionBarWhenNarrow" />
<!-- Settings screens -->
<activity
@ -318,8 +317,7 @@ @@ -318,8 +317,7 @@
android:exported="false"
android:permission="android.permission.BIND_REMOTEVIEWS" />
<receiver
android:name="org.transdroid.core.widget.ListWidgetProvider_">
<receiver android:name="org.transdroid.core.widget.ListWidgetProvider_">
<intent-filter>
<action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
</intent-filter>

3
app/src/main/java/androidx/preference/PreferenceManagerBinder.java

@ -5,7 +5,8 @@ package androidx.preference; @@ -5,7 +5,8 @@ package androidx.preference;
* around the protected visibility of {@link Preference#onAttachedToHierarchy(PreferenceManager)}.
*/
public class PreferenceManagerBinder {
private PreferenceManagerBinder() {}
private PreferenceManagerBinder() {
}
public static void bind(Preference pref, PreferenceManager manager) {
pref.onAttachedToHierarchy(manager);

30
app/src/main/java/org/transdroid/core/app/search/SearchHelper.java

@ -16,6 +16,15 @@ @@ -16,6 +16,15 @@
*/
package org.transdroid.core.app.search;
import android.content.ContentProviderClient;
import android.content.Context;
import android.database.Cursor;
import android.net.Uri;
import org.androidannotations.annotations.EBean;
import org.androidannotations.annotations.EBean.Scope;
import org.androidannotations.annotations.RootContext;
import java.io.FileNotFoundException;
import java.io.InputStream;
import java.io.UnsupportedEncodingException;
@ -23,15 +32,6 @@ import java.net.URLEncoder; @@ -23,15 +32,6 @@ import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.List;
import org.androidannotations.annotations.EBean;
import org.androidannotations.annotations.EBean.Scope;
import org.androidannotations.annotations.RootContext;
import android.content.ContentProviderClient;
import android.content.Context;
import android.database.Cursor;
import android.net.Uri;
@EBean(scope = Scope.Singleton)
public class SearchHelper {
@ -53,12 +53,9 @@ public class SearchHelper { @@ -53,12 +53,9 @@ 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
*
* @return True if the available sites can be retrieved from the content provider, false otherwise
*/
public boolean isTorrentSearchInstalled() {
@ -67,6 +64,7 @@ public class SearchHelper { @@ -67,6 +64,7 @@ public class SearchHelper {
/**
* Queries the Torrent Search package for all available in-app search sites. This method is synchronous.
*
* @return A list of available search sites as POJOs, or null if the Torrent Search package is not installed
*/
public List<SearchSite> getAvailableSites() {
@ -103,6 +101,7 @@ public class SearchHelper { @@ -103,6 +101,7 @@ public class SearchHelper {
/**
* Queries the Torrent Search module to search for torrents on the web. This method is synchronous and should always
* be called in a background thread.
*
* @param query The search query to pass to the torrent site
* @param site The site to search, as retrieved from the TorrentSitesProvider, or null if the Torrent Search package
* @param sortBy The sort order to request from the torrent site, if supported
@ -148,6 +147,7 @@ public class SearchHelper { @@ -148,6 +147,7 @@ public class SearchHelper {
* Asks the Torrent Search module to download a torrent file given the provided url, while using the specifics of
* the supplied torrent search site to do so. This way the Search Module can take care of user credentials, for
* example.
*
* @param site The unique key of the search site that this url belongs to, which is used to create a connection
* specific to this (private) site
* @param url The full url of the torrent to download
@ -165,4 +165,8 @@ public class SearchHelper { @@ -165,4 +165,8 @@ public class SearchHelper {
}
}
public enum SearchSortOrder {
Combined, BySeeders
}
}

48
app/src/main/java/org/transdroid/core/app/search/SearchResult.java

@ -16,17 +16,27 @@ @@ -16,17 +16,27 @@
*/
package org.transdroid.core.app.search;
import java.util.Date;
import android.os.Parcel;
import android.os.Parcelable;
import java.util.Date;
/**
* Represents a search result as retrieved by querying the Torrent Search package.
*
* @author Eric Kok
*/
public class SearchResult implements Parcelable {
public static final Parcelable.Creator<SearchResult> CREATOR = new Parcelable.Creator<SearchResult>() {
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;
@ -48,6 +58,18 @@ public class SearchResult implements Parcelable { @@ -48,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;
}
@ -97,26 +119,4 @@ public class SearchResult implements Parcelable { @@ -97,26 +119,4 @@ public class SearchResult implements Parcelable {
out.writeString(leechers);
}
public static final Parcelable.Creator<SearchResult> CREATOR = new Parcelable.Creator<SearchResult>() {
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();
}
}

1
app/src/main/java/org/transdroid/core/app/search/SearchSite.java

@ -21,6 +21,7 @@ import org.transdroid.core.gui.search.SearchSetting; @@ -21,6 +21,7 @@ import org.transdroid.core.gui.search.SearchSetting;
/**
* Represents an available torrent site that can be searched using the Torrent Search package.
*
* @author Eric Kok
*/
public class SearchSite implements SimpleListItem, SearchSetting {

93
app/src/main/java/org/transdroid/core/app/settings/ApplicationSettings.java

@ -49,6 +49,7 @@ import java.util.List; @@ -49,6 +49,7 @@ import java.util.List;
/**
* Singleton object to access all application settings, including stored servers, web search sites and RSS feeds.
*
* @author Eric Kok
*/
@EBean(scope = Scope.Singleton)
@ -59,9 +60,9 @@ public class ApplicationSettings { @@ -59,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);
@ -69,11 +70,11 @@ public class ApplicationSettings { @@ -69,11 +70,11 @@ public class ApplicationSettings {
/**
* Returns all available user-configured normal and seed servers
*
* @return A list of all stored server settings objects
*/
public List<ServerSetting> getAllServerSettings() {
List<ServerSetting> all = new ArrayList<>();
all.addAll(getNormalServerSettings());
List<ServerSetting> all = new ArrayList<>(getNormalServerSettings());
for (SeedboxProvider provider : SeedboxProvider.values()) {
all.addAll(provider.getSettings().getAllServerSettings(prefs, all.size()));
}
@ -82,6 +83,7 @@ public class ApplicationSettings { @@ -82,6 +83,7 @@ public class ApplicationSettings {
/**
* Returns the order number/identifying key of the last server, normal or seedbox configured
*
* @return The zero-based order number (index) of the last stored server settings
*/
public int getMaxOfAllServers() {
@ -95,6 +97,7 @@ public class ApplicationSettings { @@ -95,6 +97,7 @@ public class ApplicationSettings {
/**
* Returns the server settings for either a normal or a seedbox server as the user configured. WARNING: This method
* does not check if the settings actually exist and may reply on empty default if called for a non-existing server.
*
* @param order The order number/identifying key of the server's settings to retrieve, where the normal servers are
* first and the seedboxes are numbers thereafter onwards
* @return The server settings object, loaded from shared preferences
@ -116,6 +119,7 @@ public class ApplicationSettings { @@ -116,6 +119,7 @@ public class ApplicationSettings {
/**
* Returns all available normal, user-configured servers (so no seedbox settings)
*
* @return A list of all stored server settings objects
*/
public List<ServerSetting> getNormalServerSettings() {
@ -128,6 +132,7 @@ public class ApplicationSettings { @@ -128,6 +132,7 @@ public class ApplicationSettings {
/**
* Returns the order number/identifying key of the last normal server
*
* @return The zero-based order number (index) of the last stored normal server settings
*/
public int getMaxNormalServer() {
@ -140,6 +145,7 @@ public class ApplicationSettings { @@ -140,6 +145,7 @@ public class ApplicationSettings {
/**
* Returns the user-specified server settings for a normal (non-seedbox) server. WARNING: This method does not check
* if the settings actually exist and may rely on empty defaults if called for a non-existing server.
*
* @param order The order number/identifying key of the normal server's settings to retrieve
* @return The server settings object, loaded from shared preferences
*/
@ -198,6 +204,7 @@ public class ApplicationSettings { @@ -198,6 +204,7 @@ public class ApplicationSettings {
/**
* Removes all settings related to a configured server. Since servers are ordered, the order of the remaining
* servers will be updated accordingly.
*
* @param order The identifying order number/key of the settings to remove
*/
public void removeNormalServerSettings(int order) {
@ -275,6 +282,7 @@ public class ApplicationSettings { @@ -275,6 +282,7 @@ public class ApplicationSettings {
* specific default server was selected, the last used server settings. As opposed to getDefaultServerKey(int), this
* method checks whether the particular server still exists (and returns the first server if not). If no servers are
* configured, null is returned.
*
* @return A server settings object of the server to use by default, or null if no server is yet configured
*/
public ServerSetting getDefaultServer() {
@ -302,6 +310,7 @@ public class ApplicationSettings { @@ -302,6 +310,7 @@ public class ApplicationSettings {
* Returns the unique key of the server setting that the user selected as their default server, or code indicating
* that the last used server should be selected by default; use with getDefaultServer directly. WARNING: the
* returned string may no longer refer to a known server setting key.
*
* @return An integer; if it is 0 or higher it represents the unique key of a configured server setting, -2 means
* the last used server should be selected as default instead and -1 means the last used server should be
* selected by default for viewing yet it should always ask when adding a new torrent
@ -320,6 +329,7 @@ public class ApplicationSettings { @@ -320,6 +329,7 @@ public class ApplicationSettings {
* Returns the settings of the server that was last used by the user. As opposed to getLastUsedServerKey(int), this
* method checks whether a server was already registered as being last used and check whether the server still
* exists. It returns the first server if that fails. If no servers are configured, null is returned.
*
* @return A server settings object of the last used server (or, if not known, the first server), or null if no
* servers exist
*/
@ -337,26 +347,29 @@ public class ApplicationSettings { @@ -337,26 +347,29 @@ 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
* object: check the bounds.
*
* @return An integer indicating the order number/key or the last used server, or -1 if it was not set
*/
public int getLastUsedServerKey() {
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
*
* @param order The key identifying the specific server
*/
public void setLastUsedServerKey(int order) {
@ -366,6 +379,7 @@ public class ApplicationSettings { @@ -366,6 +379,7 @@ public class ApplicationSettings {
/**
* Returns the unique code that (should) uniquely identify a navigation filter, such as a label, in the list of all
* available filters
*
* @return A code that the last used navigation filter reported as uniquely identifying itself, or null if no last
* used filter is known
*/
@ -375,6 +389,7 @@ public class ApplicationSettings { @@ -375,6 +389,7 @@ public class ApplicationSettings {
/**
* Registers some navigation filter as being the last used by the user
*
* @param filter The navigation filter that the user last used in the interface
*/
public void setLastUsedNavigationFilter(NavigationFilter filter) {
@ -383,6 +398,7 @@ public class ApplicationSettings { @@ -383,6 +398,7 @@ public class ApplicationSettings {
/**
* Returns all available user-configured web-based (as opped to in-app) search sites
*
* @return A list of all stored web search site settings objects
*/
public List<WebsearchSetting> getWebsearchSettings() {
@ -395,6 +411,7 @@ public class ApplicationSettings { @@ -395,6 +411,7 @@ public class ApplicationSettings {
/**
* Returns the order number/identifying key of the last web search site
*
* @return The zero-based order number (index) of the last stored web search site
*/
public int getMaxWebsearch() {
@ -406,6 +423,7 @@ public class ApplicationSettings { @@ -406,6 +423,7 @@ public class ApplicationSettings {
/**
* Returns the user-specified web-based search site setting for a specific site
*
* @param order The order number/identifying key of the settings to retrieve
* @return The web search site settings object, loaded from shared preferences
*/
@ -421,6 +439,7 @@ public class ApplicationSettings { @@ -421,6 +439,7 @@ public class ApplicationSettings {
/**
* Removes all settings related to a configured web-based search site. Since sites are ordered, the order of the
* remaining sites will be updated accordingly.
*
* @param order The identifying order number/key of the settings to remove
*/
public void removeWebsearchSettings(int order) {
@ -446,6 +465,7 @@ public class ApplicationSettings { @@ -446,6 +465,7 @@ public class ApplicationSettings {
/**
* Returns all available user-configured RSS feeds
*
* @return A list of all stored RSS feed settings objects
*/
public List<RssfeedSetting> getRssfeedSettings() {
@ -458,6 +478,7 @@ public class ApplicationSettings { @@ -458,6 +478,7 @@ public class ApplicationSettings {
/**
* Returns the order number/identifying key of the last stored RSS feed
*
* @return The zero-based order number (index) of the last stored RSS feed
*/
public int getMaxRssfeed() {
@ -469,6 +490,7 @@ public class ApplicationSettings { @@ -469,6 +490,7 @@ public class ApplicationSettings {
/**
* Returns the user-specified RSS feed setting for a specific feed
*
* @param order The order number/identifying key of the settings to retrieve
* @return The RSS feed settings object, loaded from shared preferences
*/
@ -490,6 +512,7 @@ public class ApplicationSettings { @@ -490,6 +512,7 @@ public class ApplicationSettings {
/**
* Removes all settings related to a configured RSS feed. Since feeds are ordered, the order of the remaining feeds
* will be updated accordingly.
*
* @param order The identifying order number/key of the settings to remove
*/
public void removeRssfeedSettings(int order) {
@ -528,6 +551,7 @@ public class ApplicationSettings { @@ -528,6 +551,7 @@ public class ApplicationSettings {
* the user. This is used to determine which items in an RSS feed are 'new'. Warning: any previously retrieved
* {@link RssfeedSetting} object is now no longer in sync, as this will not automatically be updated in the object.
* Use {@link #getRssfeedSetting(int)} to get fresh data.
*
* @param order The identifying order number/key of the settings of te RSS feed that was viewed
* @param lastViewed The date and time that the feed was last viewed; typically now
* @param lastViewedItemUrl The url of the last item the last time that the feed was viewed
@ -543,6 +567,7 @@ public class ApplicationSettings { @@ -543,6 +567,7 @@ public class ApplicationSettings {
/**
* Registers the torrents list sort order as being last used by the user
*
* @param currentSortOrder The sort order property the user selected last
* @param currentSortAscending The sort order direction that was last used
*/
@ -556,6 +581,7 @@ public class ApplicationSettings { @@ -556,6 +581,7 @@ public class ApplicationSettings {
/**
* Returns the sort order property that the user last used. Use together with {@link #getLastUsedSortDescending()}
* to get the full last used sort settings.
*
* @return The last used sort order enumeration value
*/
public TorrentsSortBy getLastUsedSortOrder() {
@ -563,8 +589,18 @@ public class ApplicationSettings { @@ -563,8 +589,18 @@ 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
*
* @param currentSortOrder The sort order property the user selected last
*/
public void setLastUsedSearchSortOrder(SearchSortOrder currentSortOrder) {
@ -573,17 +609,10 @@ public class ApplicationSettings { @@ -573,17 +609,10 @@ 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.
*
* @return True if the last used sort direction was descending, false otherwise (i.e. the default ascending
* direction)
*/
@ -593,6 +622,7 @@ public class ApplicationSettings { @@ -593,6 +622,7 @@ public class ApplicationSettings {
/**
* Returns the list of all available in-app search sites as well as all web searches that the user configured.
*
* @return A list of search settings, all of which are either a {@link SearchSite} or {@link WebsearchSetting}
*/
public List<SearchSetting> getSearchSettings() {
@ -607,6 +637,7 @@ public class ApplicationSettings { @@ -607,6 +637,7 @@ public class ApplicationSettings {
* site in the main settings. As opposed to getLastUsedSearchSiteKey(int), this method checks whether a site was
* already registered as being last used (or set as default) and checks whether the site still exists. It returns
* the first in-app search site if that fails.
*
* @return A site settings object of the last used server (or, if not known, the first server), or null if no
* servers exist
*/
@ -654,10 +685,20 @@ public class ApplicationSettings { @@ -654,10 +685,20 @@ 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
* or in-app search settings object.
*
* @return A string indicating the key of the last used search site, or null if no site was yet used or set as
* default
*/
@ -665,16 +706,9 @@ public class ApplicationSettings { @@ -665,16 +706,9 @@ 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.
*
* @param server The server for which to retrieved the statistics from the stored preferences
* @return A JSON array of JSON objects, each which represent a since torrent
*/
@ -692,6 +726,7 @@ public class ApplicationSettings { @@ -692,6 +726,7 @@ public class ApplicationSettings {
/**
* Stores the now-last seen statistics of the supplied server by the background server checker service to the
* internal stored preferences.
*
* @param server The server to which the statistics apply to
* @param lastStats A JSON array of JSON objects that each represent a single seen torrent
*/
@ -701,6 +736,7 @@ public class ApplicationSettings { @@ -701,6 +736,7 @@ public class ApplicationSettings {
/**
* Returns the user configuration for some specific app widget, if the widget is known at all.
*
* @param appWidgetId The unique ID of the app widget to retrieve settings for, as supplied by the AppWidgetManager
* @return A widget configuration object, or null if no settings were stored for the widget ID
*/
@ -720,6 +756,7 @@ public class ApplicationSettings { @@ -720,6 +756,7 @@ public class ApplicationSettings {
/**
* Stores the user settings for some specific app widget. Existing settings for the supplied app widget ID will be
* overridden.
*
* @param appWidgetId The unique ID of the app widget to store settings for, as supplied by the AppWidgetManager
* @param settings A widget configuration object, which may not be null
*/
@ -738,6 +775,7 @@ public class ApplicationSettings { @@ -738,6 +775,7 @@ public class ApplicationSettings {
/**
* Remove the setting for some specific app widget.
*
* @param appWidgetId The unique ID of the app widget to store settings for, as supplied by the AppWidgetManager
*/
public void removeWidgetConfig(int appWidgetId) {
@ -753,6 +791,7 @@ public class ApplicationSettings { @@ -753,6 +791,7 @@ public class ApplicationSettings {
/**
* Trims away whitespace around a string, or returns null if str is null
*
* @param str The string to trim, or null
* @return The trimmed string, or null if str is null
*/

8
app/src/main/java/org/transdroid/core/app/settings/NotificationSettings.java

@ -30,6 +30,7 @@ import org.transdroid.R; @@ -30,6 +30,7 @@ import org.transdroid.R;
/**
* Allows instantiation of the settings specified in R.xml.pref_notifications.
*
* @author Eric Kok
*/
@EBean(scope = Scope.Singleton)
@ -47,6 +48,7 @@ public class NotificationSettings { @@ -47,6 +48,7 @@ public class NotificationSettings {
/**
* Whether the background service is enabled and the user wants to receive RSS-related notifications
*
* @return True if the server should be checked for RSS feed updates
*/
public boolean isEnabledForRss() {
@ -55,6 +57,7 @@ public class NotificationSettings { @@ -55,6 +57,7 @@ public class NotificationSettings {
/**
* Whether the background service is enabled and the user wants to receive torrent-related notifications
*
* @return True if the server should be checked for torrent status updates
*/
public boolean isEnabledForTorrents() {
@ -67,6 +70,7 @@ public class NotificationSettings { @@ -67,6 +70,7 @@ public class NotificationSettings {
/**
* Returns the interval between two server checks
*
* @return The interval, in milliseconds
*/
public Long getInvervalInMilliseconds() {
@ -79,6 +83,7 @@ public class NotificationSettings { @@ -79,6 +83,7 @@ public class NotificationSettings {
/**
* Returns the sound (ring tone) to play on a new notification, or null if it should not play any
*
* @return Either the user-specified sound, null if the user specified 'Silent' or the system default notification sound
*/
public Uri getSound() {
@ -100,6 +105,7 @@ public class NotificationSettings { @@ -100,6 +105,7 @@ public class NotificationSettings {
/**
* Returns the default vibrate pattern to use if the user enabled notification vibrations; check
* {@link #shouldVibrate()},
*
* @return A unique pattern for vibrations in Transdroid
*/
public long[] getDefaultVibratePattern() {
@ -112,6 +118,7 @@ public class NotificationSettings { @@ -112,6 +118,7 @@ public class NotificationSettings {
/**
* Returns the LED colour to use on a new notification
*
* @return The integer value of the user-specified or default colour
*/
public int getDesiredLedColour() {
@ -123,6 +130,7 @@ public class NotificationSettings { @@ -123,6 +130,7 @@ public class NotificationSettings {
/**
* Whether the background service should report to ADW Launcher
*
* @return True if the user want Transdroid to report to ADW Launcher
*/
public boolean shouldReportToAdwLauncher() {

12
app/src/main/java/org/transdroid/core/app/settings/RssfeedSetting.java

@ -16,15 +16,16 @@ @@ -16,15 +16,16 @@
*/
package org.transdroid.core.app.settings;
import java.util.Date;
import android.net.Uri;
import android.text.TextUtils;
import org.transdroid.core.gui.lists.SimpleListItem;
import android.net.Uri;
import android.text.TextUtils;
import java.util.Date;
/**
* Represents a user-specified RSS feed.
*
* @author Eric Kok
*/
public class RssfeedSetting implements SimpleListItem {
@ -38,8 +39,8 @@ public class RssfeedSetting implements SimpleListItem { @@ -38,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) {
@ -93,6 +94,7 @@ public class RssfeedSetting implements SimpleListItem { @@ -93,6 +94,7 @@ public class RssfeedSetting implements SimpleListItem {
* Returns the date on which we last checked this feed. Note that this is NOT updated automatically after the
* settings were loaded from {@link ApplicationSettings}; instead the settings have to be manually loaded again
* using {@link ApplicationSettings#getRssfeedSetting(int)}.
*
* @return The last new item's URL as URL-encoded string
*/
public Date getLastViewed() {
@ -103,6 +105,7 @@ public class RssfeedSetting implements SimpleListItem { @@ -103,6 +105,7 @@ public class RssfeedSetting implements SimpleListItem {
* Returns the URL of the item that was the newest last time we checked this feed. Note that this is NOT updated
* automatically after the settings were loaded from {@link ApplicationSettings}; instead the settings have to be
* manually loaded again using {@link ApplicationSettings#getRssfeedSetting(int)}.
*
* @return The last new item's URL as URL-encoded string
*/
public String getLastViewedItemUrl() {
@ -111,6 +114,7 @@ public class RssfeedSetting implements SimpleListItem { @@ -111,6 +114,7 @@ public class RssfeedSetting implements SimpleListItem {
/**
* Returns a nicely formatted identifier containing (a portion of) the feed URL
*
* @return A string to identify this feed's URL
*/
public String getHumanReadableIdentifier() {

6
app/src/main/java/org/transdroid/core/app/settings/ServerSetting.java

@ -29,6 +29,7 @@ import org.transdroid.daemon.OS; @@ -29,6 +29,7 @@ import org.transdroid.daemon.OS;
/**
* Represents a user-configured remote server.
*
* @author Eric Kok
*/
public class ServerSetting implements SimpleListItem {
@ -65,6 +66,7 @@ public class ServerSetting implements SimpleListItem { @@ -65,6 +66,7 @@ public class ServerSetting implements SimpleListItem {
/**
* Creates a daemon settings instance, providing full connection details
*
* @param name A name used to identify this server to the user
* @param type The server daemon type
* @param address The server domain name or IP address
@ -235,6 +237,7 @@ public class ServerSetting implements SimpleListItem { @@ -235,6 +237,7 @@ public class ServerSetting implements SimpleListItem {
/**
* Returns a string that the user can use to identify the server by internal settings (rather than the name).
*
* @return A human-readable identifier in the form [https://]username@address:port/folder
*/
public String getHumanReadableIdentifier() {
@ -253,6 +256,7 @@ public class ServerSetting implements SimpleListItem { @@ -253,6 +256,7 @@ public class ServerSetting implements SimpleListItem {
* Returns a string that acts as a unique identifier for this server, non-depending on the internal storage
* order/index. THis may be used to store additional details about this server elsewhere. It may change if the user
* changes server settings, but not with name or notification settings.
*
* @return A unique identifying string, based primarily on the configured address, port number, SSL settings and
* user name; returns null if the server is not yet fully identifiable (during configuration, for example)
*/
@ -284,6 +288,7 @@ public class ServerSetting implements SimpleListItem { @@ -284,6 +288,7 @@ public class ServerSetting implements SimpleListItem {
/**
* Returns the appropriate daemon adapter to which tasks can be executed, in accordance with this server's settings
*
* @param connectedToNetwork The name of the (wifi) network we are currently connected to, or null if this could not
* be determined
* @param context A context to access the logger
@ -295,6 +300,7 @@ public class ServerSetting implements SimpleListItem { @@ -295,6 +300,7 @@ public class ServerSetting implements SimpleListItem {
/**
* Converts local server settings into an old-style {@link DaemonSettings} object.
*
* @param connectedToNetwork The name of the (wifi) network we are currently connected to, or null if this could not
* be determined
* @param caller A context to access the logger

14
app/src/main/java/org/transdroid/core/app/settings/SettingsPersistence.java

@ -44,18 +44,18 @@ import java.io.OutputStream; @@ -44,18 +44,18 @@ 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.
*
* @param prefs The application-global preferences object to write settings to
* @param contents The JSON-encoded settings as raw String
* @throws JSONException Thrown when the file did not contain valid JSON content
@ -67,6 +67,7 @@ public class SettingsPersistence { @@ -67,6 +67,7 @@ public class SettingsPersistence {
/**
* Synchronously reads the server, web searches, RSS feed, background service and system settings from a file in
* JSON format.
*
* @param prefs The application-global preferences object to write settings to
* @param settingsFile The local file to read the settings from
* @throws FileNotFoundException Thrown when the settings file doesn't exist or couldn't be read
@ -79,6 +80,7 @@ public class SettingsPersistence { @@ -79,6 +80,7 @@ public class SettingsPersistence {
/**
* Synchronously reads the server, web searches, RSS feed, background service and system settings from a stream (file) in
* JSON format.
*
* @param prefs The application-global preferences object to write settings to
* @param settingsStream The stream to read the settings from
* @throws JSONException Thrown when the file did not contain valid JSON content
@ -229,6 +231,7 @@ public class SettingsPersistence { @@ -229,6 +231,7 @@ public class SettingsPersistence {
/**
* Returns encoded server, web searches, RSS feed, background service and system settings as a JSON data object structure, serialized to a String.
*
* @param prefs The application-global preferences object to read settings from
* @throws JSONException Thrown when the JSON content could not be constructed properly
*/
@ -239,6 +242,7 @@ public class SettingsPersistence { @@ -239,6 +242,7 @@ public class SettingsPersistence {
/**
* Synchronously writes the server, web searches, RSS feed, background service and system settings to a file in JSON
* format.
*
* @param prefs The application-global preferences object to read settings from
* @param settingsFile The local file to read the settings from
* @throws JSONException Thrown when the JSON content could not be constructed properly

1
app/src/main/java/org/transdroid/core/app/settings/SettingsUtils.java

@ -1,7 +1,6 @@ @@ -1,7 +1,6 @@
package org.transdroid.core.app.settings;
import android.content.Context;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.app.AppCompatDelegate;

4
app/src/main/java/org/transdroid/core/app/settings/SystemSettings.java

@ -29,6 +29,7 @@ import java.util.Date; @@ -29,6 +29,7 @@ import java.util.Date;
/**
* Allows instantiation of the settings specified in R.xml.pref_system.
*
* @author Eric Kok
*/
@EBean(scope = Scope.Singleton)
@ -48,6 +49,7 @@ public class SystemSettings { @@ -48,6 +49,7 @@ public class SystemSettings {
/**
* Returns the interval in which automatic screen refreshes should be scheduled.
*
* @return The selected refresh interval in milliseconds or 0 if automatic refreshes should be disabled
*/
public long getRefreshIntervalMilliseconds() {
@ -68,6 +70,7 @@ public class SystemSettings { @@ -68,6 +70,7 @@ public class SystemSettings {
/**
* Returns the date when we last checked transdroid.org for the latest app version.
*
* @return The date/time when the {@link org.transdroid.core.service.AppUpdateJob} checked on the server for updates
*/
public Date getLastCheckedForAppUpdates() {
@ -77,6 +80,7 @@ public class SystemSettings { @@ -77,6 +80,7 @@ public class SystemSettings {
/**
* Stores the date at which was last successfully, fully checked for new updates to the app.
*
* @param lastChecked The date/time at which the {@link org.transdroid.core.service.AppUpdateJob} last checked the server for updates
*/
public void setLastCheckedForAppUpdates(Date lastChecked) {

11
app/src/main/java/org/transdroid/core/app/settings/WebsearchSetting.java

@ -16,21 +16,21 @@ @@ -16,21 +16,21 @@
*/
package org.transdroid.core.app.settings;
import org.transdroid.core.gui.lists.SimpleListItem;
import org.transdroid.core.gui.search.SearchSetting;
import android.net.Uri;
import android.text.TextUtils;
import org.transdroid.core.gui.lists.SimpleListItem;
import org.transdroid.core.gui.search.SearchSetting;
/**
* Represents a user-specified website that can be searched (by starting the browser, rather than in-app)
*
* @author Eric Kok
*/
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;
@ -72,6 +72,7 @@ public class WebsearchSetting implements SimpleListItem, SearchSetting { @@ -72,6 +72,7 @@ public class WebsearchSetting implements SimpleListItem, SearchSetting {
/**
* Returns a nicely formatted identifier containing (a portion of) the search base URL
*
* @return A string to identify this site's search URL
*/
public String getHumanReadableIdentifier() {

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

@ -20,6 +20,7 @@ import android.annotation.TargetApi; @@ -20,6 +20,7 @@ import android.annotation.TargetApi;
import android.content.Intent;
import android.os.Build;
import android.os.Bundle;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar;
@ -56,8 +57,6 @@ import org.transdroid.daemon.TorrentFile; @@ -56,8 +57,6 @@ import org.transdroid.daemon.TorrentFile;
import org.transdroid.daemon.task.DaemonTaskFailureResult;
import org.transdroid.daemon.task.DaemonTaskResult;
import org.transdroid.daemon.task.DaemonTaskSuccessResult;
import org.transdroid.daemon.task.ToggleSequentialDownloadTask;
import org.transdroid.daemon.task.ToggleFirstLastPieceDownloadTask;
import org.transdroid.daemon.task.ForceRecheckTask;
import org.transdroid.daemon.task.GetFileListTask;
import org.transdroid.daemon.task.GetFileListTaskSuccessResult;
@ -74,6 +73,8 @@ import org.transdroid.daemon.task.SetLabelTask; @@ -74,6 +73,8 @@ import org.transdroid.daemon.task.SetLabelTask;
import org.transdroid.daemon.task.SetTrackersTask;
import org.transdroid.daemon.task.StartTask;
import org.transdroid.daemon.task.StopTask;
import org.transdroid.daemon.task.ToggleFirstLastPieceDownloadTask;
import org.transdroid.daemon.task.ToggleSequentialDownloadTask;
import java.util.ArrayList;
import java.util.List;
@ -82,6 +83,7 @@ import java.util.List; @@ -82,6 +83,7 @@ import java.util.List;
* An activity that holds a single torrents details fragment. It is used on devices (i.e. phones) where there is no room to show details in the {@link
* TorrentsActivity} directly. Task execution, such as loading of more details and updating file priorities, is performed in this activity via
* background methods.
*
* @author Eric Kok
*/
@EActivity(R.layout.activity_details)
@ -104,13 +106,12 @@ public class DetailsActivity extends AppCompatActivity implements TorrentTasksEx @@ -104,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) {

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

@ -17,15 +17,11 @@ @@ -17,15 +17,11 @@
package org.transdroid.core.gui;
import android.annotation.SuppressLint;
import android.app.Fragment;
import android.content.ClipData;
import android.content.ClipboardManager;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.ActionMenuView;
import android.view.ActionMode;
import android.view.Menu;
import android.view.MenuItem;
@ -35,6 +31,11 @@ import android.widget.ListView; @@ -35,6 +31,11 @@ import android.widget.ListView;
import android.widget.ProgressBar;
import android.widget.TextView;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.ActionMenuView;
import androidx.fragment.app.Fragment;
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;
import com.nispok.snackbar.Snackbar;
import com.nispok.snackbar.SnackbarManager;
import com.nispok.snackbar.enums.SnackbarType;
@ -48,7 +49,6 @@ import org.androidannotations.annotations.OptionsItem; @@ -48,7 +49,6 @@ import org.androidannotations.annotations.OptionsItem;
import org.androidannotations.annotations.ViewById;
import org.transdroid.R;
import org.transdroid.core.app.settings.ServerSetting;
import org.transdroid.core.app.settings.SystemSettings_;
import org.transdroid.core.gui.lists.DetailsAdapter;
import org.transdroid.core.gui.lists.SimpleListItemAdapter;
import org.transdroid.core.gui.navigation.Label;
@ -75,6 +75,7 @@ import java.util.List; @@ -75,6 +75,7 @@ import java.util.List;
* Fragment that shows detailed statistics about some torrent. These come from some already fetched {@link Torrent} object, but it also retrieves
* further detailed statistics. The actual execution of tasks is performed by the activity that contains this fragment, as per the {@link
* TorrentTasksExecutor} interface.
*
* @author Eric Kok
*/
@EFragment(R.layout.fragment_details)
@ -95,8 +96,6 @@ public class DetailsFragment extends Fragment implements OnTrackersUpdatedListen @@ -95,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;
@ -112,6 +111,170 @@ public class DetailsFragment extends Fragment implements OnTrackersUpdatedListen @@ -112,6 +111,170 @@ 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(menuItem -> 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<TorrentFile> 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() {
@ -133,12 +296,9 @@ public class DetailsFragment extends Fragment implements OnTrackersUpdatedListen @@ -133,12 +296,9 @@ public class DetailsFragment extends Fragment implements OnTrackersUpdatedListen
detailsList.setMultiChoiceModeListener(onDetailsSelected);
detailsList.setFastScrollEnabled(true);
if (getActivity() != null && getActivity() instanceof RefreshableActivity) {
swipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
@Override
public void onRefresh() {
swipeRefreshLayout.setOnRefreshListener(() -> {
((RefreshableActivity) getActivity()).refreshScreen();
swipeRefreshLayout.setRefreshing(false); // Use our custom indicator
}
});
}
@ -161,6 +321,7 @@ public class DetailsFragment extends Fragment implements OnTrackersUpdatedListen @@ -161,6 +321,7 @@ public class DetailsFragment extends Fragment implements OnTrackersUpdatedListen
/**
* Updates the details adapter header to show the new torrent data.
*
* @param newTorrent The new, non-null torrent object
*/
public void updateTorrent(Torrent newTorrent) {
@ -186,6 +347,7 @@ public class DetailsFragment extends Fragment implements OnTrackersUpdatedListen @@ -186,6 +347,7 @@ public class DetailsFragment extends Fragment implements OnTrackersUpdatedListen
/**
* Updates the details adapter to show the list of trackers and tracker errors.
*
* @param checkTorrent The torrent for which the details were retrieved
* @param newTorrentDetails The new fine details object of some torrent
*/
@ -205,6 +367,7 @@ public class DetailsFragment extends Fragment implements OnTrackersUpdatedListen @@ -205,6 +367,7 @@ public class DetailsFragment extends Fragment implements OnTrackersUpdatedListen
/**
* Updates the list adapter to show a new list of torrent files, replacing the old files list.
*
* @param checkTorrent The torrent for which the details were retrieved
* @param newTorrentFiles The new, updated list of torrent file objects
*/
@ -220,6 +383,7 @@ public class DetailsFragment extends Fragment implements OnTrackersUpdatedListen @@ -220,6 +383,7 @@ public class DetailsFragment extends Fragment implements OnTrackersUpdatedListen
/**
* Can be called if some outside activity returned new torrents, so we can perhaps piggyback on this by update our data as well.
*
* @param torrents The last of retrieved torrents
*/
public void perhapsUpdateTorrent(List<Torrent> torrents) {
@ -239,6 +403,7 @@ public class DetailsFragment extends Fragment implements OnTrackersUpdatedListen @@ -239,6 +403,7 @@ public class DetailsFragment extends Fragment implements OnTrackersUpdatedListen
/**
* Updates the locally maintained list of labels that are active on the server. Used in the label picking dialog and should be updated every time
* after the list of torrents was retrieved to keep it updated.
*
* @param currentLabels The list of known server labels
*/
public void updateLabels(ArrayList<Label> currentLabels) {
@ -261,6 +426,7 @@ public class DetailsFragment extends Fragment implements OnTrackersUpdatedListen @@ -261,6 +426,7 @@ public class DetailsFragment extends Fragment implements OnTrackersUpdatedListen
/**
* Updates the shown screen depending on whether the torrent is loading
*
* @param isLoading True if the torrent is (re)loading, false otherwise
* @param connectionErrorMessage The error message text to show to the user, or null if there was no error
*/
@ -280,9 +446,7 @@ public class DetailsFragment extends Fragment implements OnTrackersUpdatedListen @@ -280,9 +446,7 @@ public class DetailsFragment extends Fragment implements OnTrackersUpdatedListen
public void createMenuOptions() {
getActivity().getMenuInflater().inflate(R.menu.fragment_details, detailsMenu.getMenu());
detailsMenu.setOnMenuItemClickListener(new ActionMenuView.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem menuItem) {
detailsMenu.setOnMenuItemClickListener(menuItem -> {
switch (menuItem.getItemId()) {
case R.id.action_pause:
pauseTorrent();
@ -328,7 +492,6 @@ public class DetailsFragment extends Fragment implements OnTrackersUpdatedListen @@ -328,7 +492,6 @@ public class DetailsFragment extends Fragment implements OnTrackersUpdatedListen
return true;
}
return false;
}
});
}
@ -509,177 +672,9 @@ public class DetailsFragment extends Fragment implements OnTrackersUpdatedListen @@ -509,177 +672,9 @@ 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<TorrentFile> 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
*
* @return The executor for tasks on some torrent
*/
private TorrentTasksExecutor getTasksExecutor() {

37
app/src/main/java/org/transdroid/core/gui/ServerPickerDialog.java

@ -16,36 +16,23 @@ @@ -16,36 +16,23 @@
*/
package org.transdroid.core.gui;
import java.util.List;
import android.app.AlertDialog;
import android.app.Dialog;
import android.app.DialogFragment;
import android.os.Bundle;
import androidx.fragment.app.DialogFragment;
import org.transdroid.R;
import org.transdroid.core.app.settings.ServerSetting;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
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.
*
* @param activity The torrents activity from which the picker is started (and which received the callback)
* @param serverSettings The list of all available servers, of which their names will be offered to the user to pick
* from (and its position in the list is returned to the activity)
@ -59,7 +46,17 @@ public class ServerPickerDialog extends DialogFragment { @@ -59,7 +46,17 @@ public class ServerPickerDialog extends DialogFragment {
Bundle arguments = new Bundle();
arguments.putStringArray("serverNames", serverNames);
dialog.setArguments(arguments);
dialog.show(activity.getFragmentManager(), "serverpicker");
dialog.show(activity.getSupportFragmentManager(), "serverpicker");
}
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
String[] serverNames = getArguments().getStringArray("serverNames");
return new AlertDialog.Builder(getActivity()).setTitle(R.string.navigation_pickserver)
.setItems(serverNames, (dialog, which) -> {
if (getActivity() != null && getActivity() instanceof TorrentsActivity)
((TorrentsActivity) getActivity()).switchServerAndAddFromIntent(which);
}).create();
}
}

2
app/src/main/java/org/transdroid/core/gui/ServerSelectionView.java

@ -42,6 +42,7 @@ public class ServerSelectionView extends RelativeLayout { @@ -42,6 +42,7 @@ public class ServerSelectionView extends RelativeLayout {
/**
* Updates the name of the current connected server.
*
* @param currentServer The server currently connected to
*/
public void updateCurrentServer(IDaemonAdapter currentServer) {
@ -50,6 +51,7 @@ public class ServerSelectionView extends RelativeLayout { @@ -50,6 +51,7 @@ public class ServerSelectionView extends RelativeLayout {
/**
* Updates the name of the selected filter.
*
* @param currentFilter The filter that is currently selected
*/
public void updateCurrentFilter(NavigationFilter currentFilter) {

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

@ -42,6 +42,8 @@ public class ServerStatusView extends RelativeLayout implements OnRatesPickedLis @@ -42,6 +42,8 @@ public class ServerStatusView extends RelativeLayout implements OnRatesPickedLis
@ViewById
protected View speedswrapperLayout;
private TorrentsActivity activity;
private OnClickListener onStartDownPickerClicked = v ->
SetTransferRatesDialog.show(getContext(), ServerStatusView.this);
public ServerStatusView(Context context) {
super(context);
@ -54,6 +56,7 @@ public class ServerStatusView extends RelativeLayout implements OnRatesPickedLis @@ -54,6 +56,7 @@ public class ServerStatusView extends RelativeLayout implements OnRatesPickedLis
/**
* Updates the statistics as shown in the action bar through this server status view.
*
* @param torrents The most recently received list of torrents
* @param dormantAsInactive Whether to treat dormant (0KB/s) torrent as inactive state torrents
* @param supportsSetTransferRates Whether the connected torrent client supports setting of max transfer speeds
@ -99,12 +102,6 @@ public class ServerStatusView extends RelativeLayout implements OnRatesPickedLis @@ -99,12 +102,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);

4
app/src/main/java/org/transdroid/core/gui/TorrentTasksExecutor.java

@ -16,9 +16,6 @@ @@ -16,9 +16,6 @@
*/
package org.transdroid.core.gui;
import androidx.appcompat.widget.ActionMenuView;
import androidx.appcompat.widget.Toolbar;
import org.transdroid.daemon.Priority;
import org.transdroid.daemon.Torrent;
import org.transdroid.daemon.TorrentFile;
@ -27,6 +24,7 @@ import java.util.List; @@ -27,6 +24,7 @@ import java.util.List;
/**
* Interface to be implemented by any activity that wants containing fragments to be able to load data and execute commands against a torrent server.
*
* @author Eric Kok
*/
public interface TorrentTasksExecutor {

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

@ -24,23 +24,22 @@ import android.net.Uri; @@ -24,23 +24,22 @@ import android.net.Uri;
import android.os.AsyncTask;
import android.os.Build;
import android.os.Bundle;
import androidx.annotation.NonNull;
import androidx.core.view.MenuItemCompat;
import androidx.drawerlayout.widget.DrawerLayout;
import androidx.appcompat.app.ActionBarDrawerToggle;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.ActionMenuView;
import androidx.appcompat.widget.SearchView;
import androidx.appcompat.widget.Toolbar;
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 androidx.annotation.NonNull;
import androidx.appcompat.app.ActionBarDrawerToggle;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.ActionMenuView;
import androidx.appcompat.widget.SearchView;
import androidx.appcompat.widget.Toolbar;
import androidx.drawerlayout.widget.DrawerLayout;
import com.getbase.floatingactionbutton.FloatingActionButton;
import com.getbase.floatingactionbutton.FloatingActionsMenu;
import com.nispok.snackbar.Snackbar;
@ -86,7 +85,10 @@ import org.transdroid.core.gui.rss.RssFeedsActivity_; @@ -86,7 +85,10 @@ import org.transdroid.core.gui.rss.RssFeedsActivity_;
import org.transdroid.core.gui.search.FilePickerHelper;
import org.transdroid.core.gui.search.UrlEntryDialog;
import org.transdroid.core.gui.settings.MainSettingsActivity_;
import org.transdroid.core.service.*;
import org.transdroid.core.service.AppUpdateJob;
import org.transdroid.core.service.ConnectivityHelper;
import org.transdroid.core.service.RssCheckerJob;
import org.transdroid.core.service.ServerCheckerJob;
import org.transdroid.core.widget.ListWidgetProvider;
import org.transdroid.daemon.Daemon;
import org.transdroid.daemon.DaemonException;
@ -102,8 +104,6 @@ import org.transdroid.daemon.task.AddByUrlTask; @@ -102,8 +104,6 @@ import org.transdroid.daemon.task.AddByUrlTask;
import org.transdroid.daemon.task.DaemonTaskFailureResult;
import org.transdroid.daemon.task.DaemonTaskResult;
import org.transdroid.daemon.task.DaemonTaskSuccessResult;
import org.transdroid.daemon.task.ToggleSequentialDownloadTask;
import org.transdroid.daemon.task.ToggleFirstLastPieceDownloadTask;
import org.transdroid.daemon.task.ForceRecheckTask;
import org.transdroid.daemon.task.GetFileListTask;
import org.transdroid.daemon.task.GetFileListTaskSuccessResult;
@ -124,6 +124,8 @@ import org.transdroid.daemon.task.SetTrackersTask; @@ -124,6 +124,8 @@ import org.transdroid.daemon.task.SetTrackersTask;
import org.transdroid.daemon.task.SetTransferRatesTask;
import org.transdroid.daemon.task.StartTask;
import org.transdroid.daemon.task.StopTask;
import org.transdroid.daemon.task.ToggleFirstLastPieceDownloadTask;
import org.transdroid.daemon.task.ToggleSequentialDownloadTask;
import org.transdroid.daemon.util.HttpHelper;
import java.io.File;
@ -142,6 +144,7 @@ import java.util.Map.Entry; @@ -142,6 +144,7 @@ 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)
* and potentially shows a torrent details fragment too, if there is room. Task execution such as loading of and adding torrents is performs in this
* activity, using background methods. Finally, the activity offers navigation elements such as access to settings and showing connection issues.
*
* @author Eric Kok
*/
@EActivity(R.layout.activity_torrents)
@ -183,12 +186,6 @@ public class TorrentsActivity extends AppCompatActivity implements TorrentTasksE @@ -183,12 +186,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;
@ -209,6 +206,11 @@ public class TorrentsActivity extends AppCompatActivity implements TorrentTasksE @@ -209,6 +206,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;
@ -217,6 +219,34 @@ public class TorrentsActivity extends AppCompatActivity implements TorrentTasksE @@ -217,6 +219,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) {
@ -239,13 +269,8 @@ public class TorrentsActivity extends AppCompatActivity implements TorrentTasksE @@ -239,13 +269,8 @@ public class TorrentsActivity extends AppCompatActivity implements TorrentTasksE
torrentsToolbar.addView(serverSelectionView);
}
actionsToolbar.addView(serverStatusView);
actionsToolbar.setOnMenuItemClickListener(new Toolbar.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem menuItem) {
// Redirect to the classic activity implementation so we can use @OptionsItem methods
return onOptionsItemSelected(menuItem);
}
});
actionsToolbar.setOnMenuItemClickListener(this::onOptionsItemSelected);
setSupportActionBar(torrentsToolbar); // For direct menu item inflation by the contained fragments
getSupportActionBar().setDisplayShowTitleEnabled(false);
@ -254,7 +279,7 @@ public class TorrentsActivity extends AppCompatActivity implements TorrentTasksE @@ -254,7 +279,7 @@ public class TorrentsActivity extends AppCompatActivity implements TorrentTasksE
navigationListAdapter.updateServers(applicationSettings.getAllServerSettings());
navigationListAdapter.updateStatusTypes(StatusType.getAllStatusTypes(this));
// Add an empty labels list (which will be updated later, but the adapter needs to be created now)
navigationListAdapter.updateLabels(new ArrayList<Label>());
navigationListAdapter.updateLabels(new ArrayList<>());
// Apply the filters list to the navigation drawer (on phones) or the dedicated side bar (i.e. on tablets)
if (filtersList != null) {
@ -264,7 +289,7 @@ public class TorrentsActivity extends AppCompatActivity implements TorrentTasksE @@ -264,7 +289,7 @@ public class TorrentsActivity extends AppCompatActivity implements TorrentTasksE
drawerToggle =
new ActionBarDrawerToggle(this, drawerLayout, torrentsToolbar, R.string.navigation_opendrawer, R.string.navigation_closedrawer);
drawerToggle.setDrawerIndicatorEnabled(true);
drawerLayout.setDrawerListener(drawerToggle);
drawerLayout.addDrawerListener(drawerToggle);
}
navigationList.setAdapter(navigationListAdapter);
navigationList.setOnItemClickListener(onFilterListItemClicked);
@ -427,15 +452,12 @@ public class TorrentsActivity extends AppCompatActivity implements TorrentTasksE @@ -427,15 +452,12 @@ public class TorrentsActivity extends AppCompatActivity implements TorrentTasksE
SearchView searchView = new SearchView(torrentsToolbar.getContext());
searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));
searchView.setQueryRefinementEnabled(true);
searchView.setOnSearchClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
searchView.setOnSearchClickListener(v -> {
// Pause autorefresh
stopRefresh = true;
stopAutoRefresh();
}
});
MenuItemCompat.setOnActionExpandListener(item, new MenuItemCompat.OnActionExpandListener() {
item.setOnActionExpandListener(new MenuItem.OnActionExpandListener() {
@Override
public boolean onMenuItemActionExpand(MenuItem item) {
return true;
@ -448,7 +470,7 @@ public class TorrentsActivity extends AppCompatActivity implements TorrentTasksE @@ -448,7 +470,7 @@ public class TorrentsActivity extends AppCompatActivity implements TorrentTasksE
return true;
}
});
MenuItemCompat.setActionView(item, searchView);
item.setActionView(searchView);
searchMenu = item;
}
return true;
@ -519,24 +541,9 @@ public class TorrentsActivity extends AppCompatActivity implements TorrentTasksE @@ -519,24 +541,9 @@ 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
*
* @param item The touched filter item
* @param forceNewConnection Whether a new connection should be initialised regardless of the old server selection
*/
@ -596,14 +603,15 @@ public class TorrentsActivity extends AppCompatActivity implements TorrentTasksE @@ -596,14 +603,15 @@ public class TorrentsActivity extends AppCompatActivity implements TorrentTasksE
/**
* Hides the filter list and details fragment's full view if there is no configured connection
*
* @param hasServerSettings Whether there are server settings available, so we can continue to connect
*/
private void updateFragmentVisibility(boolean hasServerSettings) {
if (fragmentDetails != null && fragmentDetails.isResumed()) {
if (hasServerSettings) {
getFragmentManager().beginTransaction().show(fragmentDetails).commit();
getSupportFragmentManager().beginTransaction().show(fragmentDetails).commit();
} else {
getFragmentManager().beginTransaction().hide(fragmentDetails).commit();
getSupportFragmentManager().beginTransaction().hide(fragmentDetails).commit();
}
}
invalidateOptionsMenu();
@ -611,6 +619,7 @@ public class TorrentsActivity extends AppCompatActivity implements TorrentTasksE @@ -611,6 +619,7 @@ public class TorrentsActivity extends AppCompatActivity implements TorrentTasksE
@Override
protected void onNewIntent(Intent intent) {
super.onNewIntent(intent);
setIntent(intent);
handleStartIntent();
}
@ -869,22 +878,9 @@ public class TorrentsActivity extends AppCompatActivity implements TorrentTasksE @@ -869,22 +878,9 @@ 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.
*
* @param newFilterText The newly entered filter (or empty to clear the current filter).
*/
public void filterTorrents(String newFilterText) {
@ -894,6 +890,7 @@ public class TorrentsActivity extends AppCompatActivity implements TorrentTasksE @@ -894,6 +890,7 @@ public class TorrentsActivity extends AppCompatActivity implements TorrentTasksE
/**
* Shows the a details fragment for the given torrent, either in the dedicated details fragment pane, in the same pane as the torrent list was
* displayed or by starting a details activity.
*
* @param torrent The torrent to show detailed statistics for
*/
public void openDetails(Torrent torrent) {
@ -1116,8 +1113,7 @@ public class TorrentsActivity extends AppCompatActivity implements TorrentTasksE @@ -1116,8 +1113,7 @@ public class TorrentsActivity extends AppCompatActivity implements TorrentTasksE
try {
// Write a temporary file with the torrent contents
tempFile = File.createTempFile("transdroid_", ".torrent", getCacheDir());
FileOutputStream output = new FileOutputStream(tempFile);
try {
try (FileOutputStream output = new FileOutputStream(tempFile)) {
final byte[] buffer = new byte[1024];
int read;
while ((read = input.read(buffer)) != -1) {
@ -1126,8 +1122,6 @@ public class TorrentsActivity extends AppCompatActivity implements TorrentTasksE @@ -1126,8 +1122,6 @@ public class TorrentsActivity extends AppCompatActivity implements TorrentTasksE
output.flush();
String fileName = Uri.fromFile(tempFile).toString();
addTorrentByFile(fileName, title);
} finally {
output.close();
}
} catch (IOException e) {
log.e(this, "Can't write input stream to " + tempFile.toString() + ": " + e.toString());
@ -1305,7 +1299,6 @@ public class TorrentsActivity extends AppCompatActivity implements TorrentTasksE @@ -1305,7 +1299,6 @@ public class TorrentsActivity extends AppCompatActivity implements TorrentTasksE
@UiThread
protected void onCommunicationError(DaemonTaskFailureResult result, boolean isCritical) {
//noinspection ThrowableResultOfMethodCallIgnored
log.i(this, result.getException().toString());
String error = getString(LocalTorrent.getResourceForDaemonException(result.getException()));
SnackbarManager.show(Snackbar.with(this).text(error).colorResource(R.color.red).type(SnackbarType.MULTI_LINE));

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

@ -16,12 +16,7 @@ @@ -16,12 +16,7 @@
*/
package org.transdroid.core.gui;
import android.app.Fragment;
import android.content.Context;
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.ActionMenuView;
import androidx.appcompat.widget.Toolbar;
import android.view.ActionMode;
import android.view.Menu;
import android.view.MenuItem;
@ -31,6 +26,12 @@ import android.widget.ListView; @@ -31,6 +26,12 @@ import android.widget.ListView;
import android.widget.ProgressBar;
import android.widget.TextView;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.ActionMenuView;
import androidx.appcompat.widget.Toolbar;
import androidx.fragment.app.Fragment;
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;
import com.getbase.floatingactionbutton.FloatingActionsMenu;
import org.androidannotations.annotations.AfterViews;
@ -64,18 +65,19 @@ import java.util.Locale; @@ -64,18 +65,19 @@ import java.util.Locale;
/**
* Fragment that shows a list of torrents that are active on the server. It supports sorting and filtering and can show connection progress and
* issues. However, actual task starting and execution and overall navigation elements are part of the containing activity, not this fragment.
*
* @author Eric Kok
*/
@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<Torrent> 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<Torrent> torrents = null;
@InstanceState
protected ArrayList<Torrent> lastMultiSelectedTorrents;
@InstanceState
@ -110,6 +112,128 @@ public class TorrentsFragment extends Fragment implements OnLabelPickedListener @@ -110,6 +112,128 @@ 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(menuItem -> 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<Torrent> 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() {
@ -127,12 +251,9 @@ public class TorrentsFragment extends Fragment implements OnLabelPickedListener @@ -127,12 +251,9 @@ public class TorrentsFragment extends Fragment implements OnLabelPickedListener
}
// Allow pulls on the list view to refresh the torrents
if (getActivity() != null && getActivity() instanceof RefreshableActivity) {
swipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
@Override
public void onRefresh() {
swipeRefreshLayout.setOnRefreshListener(() -> {
((RefreshableActivity) getActivity()).refreshScreen();
swipeRefreshLayout.setRefreshing(false); // Use our custom indicator
}
});
}
nosettingsText.setText(getString(R.string.navigation_nosettings, getString(R.string.app_name)));
@ -141,6 +262,7 @@ public class TorrentsFragment extends Fragment implements OnLabelPickedListener @@ -141,6 +262,7 @@ public class TorrentsFragment extends Fragment implements OnLabelPickedListener
/**
* Updates the list adapter to show a new list of torrent objects, replacing the old torrents completely
*
* @param newTorrents The new, updated list of torrents
*/
public void updateTorrents(ArrayList<Torrent> newTorrents, ArrayList<Label> currentLabels) {
@ -155,6 +277,7 @@ public class TorrentsFragment extends Fragment implements OnLabelPickedListener @@ -155,6 +277,7 @@ public class TorrentsFragment extends Fragment implements OnLabelPickedListener
/**
* Just look for a specific torrent in the currently shown list (by its unique id) and update only this
*
* @param affected The affected torrent to update
* @param wasRemoved Whether the affected torrent was indeed removed; otherwise it was updated somehow
*/
@ -182,6 +305,7 @@ public class TorrentsFragment extends Fragment implements OnLabelPickedListener @@ -182,6 +305,7 @@ public class TorrentsFragment extends Fragment implements OnLabelPickedListener
/**
* Clears the currently visible list of torrents.
*
* @param clearError Also clear any error message
* @param clearFilter Also clear any selected filter
*/
@ -200,6 +324,7 @@ public class TorrentsFragment extends Fragment implements OnLabelPickedListener @@ -200,6 +324,7 @@ public class TorrentsFragment extends Fragment implements OnLabelPickedListener
/**
* Stores the new sort order (for future refreshes) and sorts the current visible list. If the given new sort property equals the existing
* property, the list sort order is reversed instead.
*
* @param newSortOrder The sort order that the user selected.
*/
public void sortBy(TorrentsSortBy newSortOrder) {
@ -222,6 +347,7 @@ public class TorrentsFragment extends Fragment implements OnLabelPickedListener @@ -222,6 +347,7 @@ public class TorrentsFragment extends Fragment implements OnLabelPickedListener
/**
* Apply a filter on the current list of all torrents, showing the appropriate sublist of torrents only
*
* @param newFilter The new filter to apply to the local list of torrents
*/
public void applyNavigationFilter(NavigationFilter newFilter) {
@ -265,134 +391,6 @@ public class TorrentsFragment extends Fragment implements OnLabelPickedListener @@ -265,134 +391,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<Torrent> 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
@ -425,6 +423,7 @@ public class TorrentsFragment extends Fragment implements OnLabelPickedListener @@ -425,6 +423,7 @@ public class TorrentsFragment extends Fragment implements OnLabelPickedListener
/**
* Updates the shown screen depending on whether we have a connection (so torrents can be shown) or not (in case we need to show a message
* suggesting help). This should only ever be called on the UI thread.
*
* @param hasAConnection True if the user has servers configured and therefore has a connection that can be used
*/
public void updateConnectionStatus(boolean hasAConnection, Daemon daemonType) {
@ -446,6 +445,7 @@ public class TorrentsFragment extends Fragment implements OnLabelPickedListener @@ -446,6 +445,7 @@ public class TorrentsFragment extends Fragment implements OnLabelPickedListener
/**
* Updates the shown screen depending on whether the torrents are loading. This should only ever be called on the UI thread.
*
* @param isLoading True if the list of torrents is (re)loading, false otherwise
*/
public void updateIsLoading(boolean isLoading) {
@ -460,6 +460,7 @@ public class TorrentsFragment extends Fragment implements OnLabelPickedListener @@ -460,6 +460,7 @@ public class TorrentsFragment extends Fragment implements OnLabelPickedListener
/**
* Updates the shown screen depending on whether a connection error occurred. This should only ever be called on the UI thread.
*
* @param connectionErrorMessage The error message from the last failed connection attempt, or null to clear the visible error text
*/
public void updateError(String connectionErrorMessage) {
@ -489,6 +490,7 @@ public class TorrentsFragment extends Fragment implements OnLabelPickedListener @@ -489,6 +490,7 @@ public class TorrentsFragment extends Fragment implements OnLabelPickedListener
/**
* Returns the object responsible for executing torrent tasks against a connected server
*
* @return The executor for tasks on some torrent
*/
private TorrentTasksExecutor getTasksExecutor() {

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

@ -17,11 +17,10 @@ @@ -17,11 +17,10 @@
package org.transdroid.core.gui;
import android.app.Application;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import com.evernote.android.job.JobConfig;
import com.evernote.android.job.JobManager;
import com.evernote.android.job.util.JobLogger;
import org.androidannotations.annotations.Bean;
import org.androidannotations.annotations.EApplication;
import org.transdroid.core.gui.log.Log;
@ -38,12 +37,7 @@ public class TransdroidApp extends Application { @@ -38,12 +37,7 @@ public class TransdroidApp extends Application {
super.onCreate();
// Configure Android-Job
JobConfig.addLogger(new JobLogger() {
@Override
public void log(int priority, @NonNull String tag, @NonNull String message, @Nullable Throwable t) {
log.d(tag, message);
}
});
JobConfig.addLogger((priority, tag, message, t) -> log.d(tag, message));
JobManager.create(this).addJobCreator(new ScheduledJobCreator());
}

31
app/src/main/java/org/transdroid/core/gui/lists/DetailsAdapter.java

@ -16,23 +16,23 @@ @@ -16,23 +16,23 @@
*/
package org.transdroid.core.gui.lists;
import java.util.ArrayList;
import java.util.List;
import org.transdroid.R;
import org.transdroid.core.gui.navigation.*;
import org.transdroid.core.gui.lists.PiecesMapView;
import org.transdroid.daemon.Torrent;
import org.transdroid.daemon.TorrentFile;
import android.content.Context;
import android.text.util.Linkify;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import org.transdroid.R;
import org.transdroid.core.gui.navigation.FilterSeparatorView_;
import org.transdroid.daemon.Torrent;
import org.transdroid.daemon.TorrentFile;
import java.util.ArrayList;
import java.util.List;
/**
* List adapter that holds a header view showing torrent details and show the list list contained by the torrent.
*
* @author Eric Kok
*/
public class DetailsAdapter extends MergeAdapter {
@ -78,7 +78,7 @@ public class DetailsAdapter extends MergeAdapter { @@ -78,7 +78,7 @@ public class DetailsAdapter extends MergeAdapter {
errorsSeparatorAdapter.setViewEnabled(false);
errorsSeparatorAdapter.setViewVisibility(View.GONE);
addAdapter(errorsSeparatorAdapter);
this.errorsAdapter = new SimpleListItemAdapter(context, new ArrayList<SimpleListItem>());
this.errorsAdapter = new SimpleListItemAdapter(context, new ArrayList<>());
this.errorsAdapter.setAutoLinkMask(Linkify.WEB_URLS);
addAdapter(errorsAdapter);
@ -88,7 +88,7 @@ public class DetailsAdapter extends MergeAdapter { @@ -88,7 +88,7 @@ public class DetailsAdapter extends MergeAdapter {
trackersSeparatorAdapter.setViewEnabled(false);
trackersSeparatorAdapter.setViewVisibility(View.GONE);
addAdapter(trackersSeparatorAdapter);
this.trackersAdapter = new SimpleListItemAdapter(context, new ArrayList<SimpleListItem>());
this.trackersAdapter = new SimpleListItemAdapter(context, new ArrayList<>());
addAdapter(trackersAdapter);
// Torrent files
@ -97,13 +97,14 @@ public class DetailsAdapter extends MergeAdapter { @@ -97,13 +97,14 @@ public class DetailsAdapter extends MergeAdapter {
torrentFilesSeparatorAdapter.setViewEnabled(false);
torrentFilesSeparatorAdapter.setViewVisibility(View.GONE);
addAdapter(torrentFilesSeparatorAdapter);
this.torrentFilesAdapter = new TorrentFilesAdapter(context, new ArrayList<TorrentFile>());
this.torrentFilesAdapter = new TorrentFilesAdapter(context, new ArrayList<>());
addAdapter(torrentFilesAdapter);
}
/**
* Update the torrent data in the details header of this merge adapter
*
* @param torrent The torrent for which detailed data is shown
*/
public void updateTorrent(Torrent torrent) {
@ -113,11 +114,12 @@ public class DetailsAdapter extends MergeAdapter { @@ -113,11 +114,12 @@ public class DetailsAdapter extends MergeAdapter {
/**
* Update the list of files contained in this torrent
*
* @param torrentFiles The new list of files, or null if the list and header should be hidden
*/
public void updateTorrentFiles(List<TorrentFile> torrentFiles) {
if (torrentFiles == null) {
torrentFilesAdapter.update(new ArrayList<TorrentFile>());
torrentFilesAdapter.update(new ArrayList<>());
torrentFilesSeparatorAdapter.setViewVisibility(View.GONE);
} else {
torrentFilesAdapter.update(torrentFiles);
@ -127,6 +129,7 @@ public class DetailsAdapter extends MergeAdapter { @@ -127,6 +129,7 @@ public class DetailsAdapter extends MergeAdapter {
/**
* Update the list of trackers
*
* @param trackers The new list of trackers known for this torrent, or null if the list and header should be hidden
*/
public void updateTrackers(List<? extends SimpleListItem> trackers) {
@ -141,6 +144,7 @@ public class DetailsAdapter extends MergeAdapter { @@ -141,6 +144,7 @@ public class DetailsAdapter extends MergeAdapter {
/**
* Update the list of errors
*
* @param errors The new list of errors known for this torrent, or null if the list and header should be hidden
*/
public void updateErrors(List<? extends SimpleListItem> errors) {
@ -191,6 +195,7 @@ public class DetailsAdapter extends MergeAdapter { @@ -191,6 +195,7 @@ public class DetailsAdapter extends MergeAdapter {
/**
* Allows updating of the full data list underlying this adapter, replacing all items
*
* @param newItems The new list of files to display
*/
public void update(List<TorrentFile> newItems) {

86
app/src/main/java/org/transdroid/core/gui/lists/LocalTorrent.java

@ -16,7 +16,7 @@ @@ -16,7 +16,7 @@
*/
package org.transdroid.core.gui.lists;
import java.util.Locale;
import android.content.res.Resources;
import org.transdroid.R;
import org.transdroid.daemon.DaemonException;
@ -25,17 +25,27 @@ import org.transdroid.daemon.TorrentStatus; @@ -25,17 +25,27 @@ import org.transdroid.daemon.TorrentStatus;
import org.transdroid.daemon.util.FileSizeConverter;
import org.transdroid.daemon.util.TimespanConverter;
import android.content.res.Resources;
import java.util.Locale;
/**
* Wrapper around Torrent to provide some addition getters that give translatable or otherwise formatted Strings of
* torrent statistics.
*
* @author Eric Kok
*/
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.
*
* @param torrent The Torrent object
* @return The torrent wrapped as LocalTorrent object
*/
@ -43,19 +53,37 @@ public class LocalTorrent { @@ -43,19 +53,37 @@ 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 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;
case ConnectionError:
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
* have 100%.
*
* @return A nicely formatted string containing the upload/download seed ratio
*/
public String getRatioString() {
@ -74,6 +102,7 @@ public class LocalTorrent { @@ -74,6 +102,7 @@ public class LocalTorrent {
/**
* Returns a formatted string indicating the current progress in terms of transferred bytes
*
* @param r The context resources, to access translations
* @param withAvailability Whether to show file availability in-line
* @return A nicely formatted string indicating torrent status and, if applicable, progress in bytes
@ -111,6 +140,7 @@ public class LocalTorrent { @@ -111,6 +140,7 @@ public class LocalTorrent {
/**
* Returns a formatted string indicating either the expected time to download (ETA) or, when seeding, the ratio
*
* @param r The context resources, to access translations
* @return A string like '~ 34 seconds', or 'RATIO 8.2' or an empty string
*/
@ -134,6 +164,7 @@ public class LocalTorrent { @@ -134,6 +164,7 @@ public class LocalTorrent {
/**
* Returns a formatted string indicating the torrent status and connected peers
*
* @param r The context resources, to access translations
* @return A string like 'Queued' or, when seeding or leeching, '2 OF 28 PEERS'
*/
@ -162,22 +193,22 @@ public class LocalTorrent { @@ -162,22 +193,22 @@ public class LocalTorrent {
/**
* Returns a formatted string indicating current transfer speeds for the torrent
*
* @param r The context resources, to access translations
* @return A string like ' 28KB/s 1.8MB/s', or an empty string when not transferrring
*/
public String getProgressSpeedText(Resources r) {
switch (t.getStatusCode()) {
case Waiting:
case Checking:
case Paused:
case Queued:
return "";
case Downloading:
return r.getString(R.string.status_speed_down, FileSizeConverter.getSize(t.getRateDownload()) + "/s") + " "
+ r.getString(R.string.status_speed_up, FileSizeConverter.getSize(t.getRateUpload()) + "/s");
case Seeding:
return r.getString(R.string.status_speed_up, FileSizeConverter.getSize(t.getRateUpload()) + "/s");
case Waiting:
case Checking:
case Paused:
case Queued:
default:
return "";
}
@ -210,6 +241,7 @@ public class LocalTorrent { @@ -210,6 +241,7 @@ public class LocalTorrent {
/**
* Returns a formatted string indicating the remaining download time
*
* @param r The context resources, to access translations
* @param inDays Whether to show days or use hours for > 24 hours left instead
* @return A string like '4d 8h 34m 5s' or '2m 3s'
@ -222,30 +254,4 @@ public class LocalTorrent { @@ -222,30 +254,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;
}
}
}

21
app/src/main/java/org/transdroid/core/gui/lists/MergeAdapter.java

@ -16,8 +16,6 @@ @@ -16,8 +16,6 @@
*/
package org.transdroid.core.gui.lists;
import java.util.ArrayList;
import android.database.DataSetObserver;
import android.view.View;
import android.view.ViewGroup;
@ -27,17 +25,21 @@ import android.widget.ListAdapter; @@ -27,17 +25,21 @@ import android.widget.ListAdapter;
import android.widget.SectionIndexer;
import android.widget.TextView;
import java.util.ArrayList;
import java.util.Arrays;
/**
* An adapter that can contain many other adapters and shows them in sequence. Taken from
* http://stackoverflow.com/questions/7964259/android-attaching-multiple-adapters-to-one-adapter and based on the Apache
* 2-licensed CommonsWare MergeAdapter.
*
* @author Eric Kok
* @author Alex Amiryan
* @author Mark Murphy
*/
public class MergeAdapter extends BaseAdapter implements SectionIndexer {
protected ArrayList<ListAdapter> pieces = new ArrayList<ListAdapter>();
protected ArrayList<ListAdapter> pieces = new ArrayList<>();
protected String noItemsText;
/**
@ -49,6 +51,7 @@ public class MergeAdapter extends BaseAdapter implements SectionIndexer { @@ -49,6 +51,7 @@ public class MergeAdapter extends BaseAdapter implements SectionIndexer {
/**
* Adds a new adapter to the roster of things to appear in the aggregate list.
*
* @param adapter Source for row views for this section
*/
public void addAdapter(ListAdapter adapter) {
@ -58,6 +61,7 @@ public class MergeAdapter extends BaseAdapter implements SectionIndexer { @@ -58,6 +61,7 @@ public class MergeAdapter extends BaseAdapter implements SectionIndexer {
/**
* Get the data item associated with the specified position in the data set.
*
* @param position Position of the item whose data we want
*/
public Object getItem(int position) {
@ -80,6 +84,7 @@ public class MergeAdapter extends BaseAdapter implements SectionIndexer { @@ -80,6 +84,7 @@ public class MergeAdapter extends BaseAdapter implements SectionIndexer {
/**
* Get the adapter associated with the specified position in the data set.
*
* @param position Position of the item whose adapter we want
*/
public ListAdapter getAdapter(int position) {
@ -130,6 +135,7 @@ public class MergeAdapter extends BaseAdapter implements SectionIndexer { @@ -130,6 +135,7 @@ public class MergeAdapter extends BaseAdapter implements SectionIndexer {
/**
* Get the type of {@link View} that will be created by {@link #getView(int, View, ViewGroup)} for the specified item.
*
* @param position Position of the item whose data we want
*/
@Override
@ -162,6 +168,7 @@ public class MergeAdapter extends BaseAdapter implements SectionIndexer { @@ -162,6 +168,7 @@ public class MergeAdapter extends BaseAdapter implements SectionIndexer {
/**
* Returns true if the item at the specified position is not a separator.
*
* @param position Position of the item whose data we want
*/
@Override
@ -181,6 +188,7 @@ public class MergeAdapter extends BaseAdapter implements SectionIndexer { @@ -181,6 +188,7 @@ public class MergeAdapter extends BaseAdapter implements SectionIndexer {
/**
* Get a {@link View} that displays the data at the specified position in the data set.
*
* @param position Position of the item whose data we want
* @param convertView View to recycle, if not null
* @param parent ViewGroup containing the returned View
@ -208,6 +216,7 @@ public class MergeAdapter extends BaseAdapter implements SectionIndexer { @@ -208,6 +216,7 @@ public class MergeAdapter extends BaseAdapter implements SectionIndexer {
/**
* Get the row id associated with the specified position in the list.
*
* @param position Position of the item whose data we want
*/
public long getItemId(int position) {
@ -278,16 +287,14 @@ public class MergeAdapter extends BaseAdapter implements SectionIndexer { @@ -278,16 +287,14 @@ public class MergeAdapter extends BaseAdapter implements SectionIndexer {
}
public final Object[] getSections() {
ArrayList<Object> sections = new ArrayList<Object>();
ArrayList<Object> sections = new ArrayList<>();
for (ListAdapter piece : pieces) {
if (piece instanceof SectionIndexer) {
Object[] curSections = ((SectionIndexer) piece).getSections();
if (curSections != null) {
for (Object section : curSections) {
sections.add(section);
}
sections.addAll(Arrays.asList(curSections));
}
}
}

24
app/src/main/java/org/transdroid/core/gui/lists/PiecesMapView.java

@ -1,27 +1,24 @@ @@ -1,27 +1,24 @@
package org.transdroid.core.gui.lists;
import org.transdroid.R;
import android.content.Context;
import android.view.View;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.view.View;
import org.transdroid.R;
import java.util.ArrayList;
import java.util.List;
import java.lang.Math;
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<Integer> pieces = null;
private final Paint downloadingPaint = new Paint();
private final Paint donePaint = new Paint();
private final Paint partialDonePaint = new Paint();
private ArrayList<Integer> pieces = null;
public PiecesMapView(Context context) {
super(context);
@ -35,7 +32,7 @@ class PiecesMapView extends View { @@ -35,7 +32,7 @@ class PiecesMapView extends View {
}
public void setPieces(List<Integer> pieces) {
this.pieces = new ArrayList<Integer>(pieces);
this.pieces = new ArrayList<>(pieces);
invalidate();
}
@ -62,7 +59,7 @@ class PiecesMapView extends View { @@ -62,7 +59,7 @@ class PiecesMapView extends View {
int pieceWidth;
pieceWidth = MINIMUM_PIECE_WIDTH;
piecesScaled = new ArrayList<Integer>();
piecesScaled = new ArrayList<>();
int bucketCount = (int) Math.ceil((double) width / (double) pieceWidth);
int bucketSize = (int) Math.floor((double) this.pieces.size() / (double) bucketCount);
@ -76,7 +73,7 @@ class PiecesMapView extends View { @@ -76,7 +73,7 @@ class PiecesMapView extends View {
// If this is the last bucket, throw the remainder of the pieces array into it
int end = (i == bucketCount - 1) ? this.pieces.size() : (i + 1) * bucketSize;
ArrayList<Integer> bucket = new ArrayList<Integer>(this.pieces.subList(start, end));
ArrayList<Integer> bucket = new ArrayList<>(this.pieces.subList(start, end));
int doneCount = 0;
int downloadingCount = 0;
@ -114,10 +111,9 @@ class PiecesMapView extends View { @@ -114,10 +111,9 @@ class PiecesMapView extends View {
piecesScaled.add(state);
}
String scaledPiecesString = "";
for (int s : piecesScaled)
{
scaledPiecesString += s;
StringBuilder scaledPiecesString = new StringBuilder();
for (int s : piecesScaled) {
scaledPiecesString.append(s);
}
// Draw downscaled peices

3
app/src/main/java/org/transdroid/core/gui/lists/SimpleListItem.java

@ -19,10 +19,11 @@ package org.transdroid.core.gui.lists; @@ -19,10 +19,11 @@ package org.transdroid.core.gui.lists;
/**
* Represents a filter item as shown in the navigation list or spinner.
*
* @author Eric Kok
*/
public interface SimpleListItem {
public String getName();
String getName();
}

25
app/src/main/java/org/transdroid/core/gui/lists/SimpleListItemAdapter.java

@ -16,14 +16,14 @@ @@ -16,14 +16,14 @@
*/
package org.transdroid.core.gui.lists;
import java.util.ArrayList;
import java.util.List;
import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import java.util.ArrayList;
import java.util.List;
public class SimpleListItemAdapter extends BaseAdapter {
private final Context context;
@ -37,6 +37,7 @@ public class SimpleListItemAdapter extends BaseAdapter { @@ -37,6 +37,7 @@ public class SimpleListItemAdapter extends BaseAdapter {
/**
* Allows updating of the full data list underlying this adapter, replacing all items
*
* @param newItems The new list of simple list items to display
*/
public void update(List<? extends SimpleListItem> newItems) {
@ -66,7 +67,7 @@ public class SimpleListItemAdapter extends BaseAdapter { @@ -66,7 +67,7 @@ public class SimpleListItemAdapter extends BaseAdapter {
@Override
public View getView(int position, View convertView, ViewGroup parent) {
SimpleListItemView filterItemView;
if (convertView == null || !(convertView instanceof SimpleListItemView)) {
if (!(convertView instanceof SimpleListItemView)) {
filterItemView = SimpleListItemView_.build(context);
} else {
filterItemView = (SimpleListItemView) convertView;
@ -78,18 +79,26 @@ public class SimpleListItemAdapter extends BaseAdapter { @@ -78,18 +79,26 @@ public class SimpleListItemAdapter extends BaseAdapter {
/**
* Represents a very simple list item that only contains a single string to show in the list. Use wrapStringsList to
* wrap an existing list of strings into a list of {@link SimpleListItem}s.
*
* @author Eric Kok
*/
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}
*
* @param strings A list of string
* @return A list of SimpleStringItem objects representing the input strings
*/
public static List<SimpleStringItem> wrapStringsList(List<String> strings) {
ArrayList<SimpleStringItem> errors = new ArrayList<SimpleStringItem>();
ArrayList<SimpleStringItem> errors = new ArrayList<>();
if (strings != null) {
for (String string : strings) {
errors.add(new SimpleStringItem(string));
@ -98,12 +107,6 @@ public class SimpleListItemAdapter extends BaseAdapter { @@ -98,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;

6
app/src/main/java/org/transdroid/core/gui/lists/SimpleListItemSpinnerAdapter.java

@ -16,17 +16,18 @@ @@ -16,17 +16,18 @@
*/
package org.transdroid.core.gui.lists;
import java.util.List;
import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;
import java.util.List;
/**
* A wrapper around {@link ArrayAdapter} that contains {@link SimpleListItem}s which simply show their name in the
* Spinner. The standard Android spinner resources are used for the layout.
*
* @author Eric Kok
*/
public class SimpleListItemSpinnerAdapter<T extends SimpleListItem> extends ArrayAdapter<T> {
@ -34,6 +35,7 @@ public class SimpleListItemSpinnerAdapter<T extends SimpleListItem> extends Arra @@ -34,6 +35,7 @@ public class SimpleListItemSpinnerAdapter<T extends SimpleListItem> extends Arra
/**
* Constructs the adapter, supplying the {@link SimpleListItem}s to show in the spinner. The given resource will be
* ignored as the standard Android Spinner layout is used instead.
*
* @param context The UI context to inflate the layout in
* @param resource This is ignored; android.R.layout.simple_spinner_item is always used instead
* @param objects The items to show in the spinner, which can simply display some name

1
app/src/main/java/org/transdroid/core/gui/lists/SimpleListItemView.java

@ -26,6 +26,7 @@ import org.transdroid.R; @@ -26,6 +26,7 @@ import org.transdroid.R;
/**
* View that represents some {@link SimpleListItem} object and simple prints out the text (in proper style)
*
* @author Eric Kok
*/
@EViewGroup(R.layout.list_item_simple)

3
app/src/main/java/org/transdroid/core/gui/lists/SortByListItem.java

@ -17,11 +17,13 @@ @@ -17,11 +17,13 @@
package org.transdroid.core.gui.lists;
import android.content.Context;
import org.transdroid.R;
import org.transdroid.daemon.TorrentsSortBy;
/**
* Represents a way in which a torrents list can be sorted.
*
* @author Eric Kok
*/
public class SortByListItem implements SimpleListItem {
@ -64,6 +66,7 @@ public class SortByListItem implements SimpleListItem { @@ -64,6 +66,7 @@ public class SortByListItem implements SimpleListItem {
/**
* Returns the contained represented sort order.
*
* @return The sort by order as its enumeration value
*/
public TorrentsSortBy getSortBy() {

2
app/src/main/java/org/transdroid/core/gui/lists/TorrentDetailsView.java

@ -32,6 +32,7 @@ import org.transdroid.daemon.util.FileSizeConverter; @@ -32,6 +32,7 @@ import org.transdroid.daemon.util.FileSizeConverter;
/**
* Represents a group of views that show torrent status, sizes, speeds and other details.
*
* @author Eric Kok
*/
@EViewGroup(R.layout.fragment_details_header)
@ -49,6 +50,7 @@ public class TorrentDetailsView extends RelativeLayout { @@ -49,6 +50,7 @@ public class TorrentDetailsView extends RelativeLayout {
/**
* Update the text fields with new/updated torrent details
*
* @param torrent The torrent for which to show details
*/
public void update(Torrent torrent) {

14
app/src/main/java/org/transdroid/core/gui/lists/TorrentFilePriorityLayout.java

@ -16,9 +16,6 @@ @@ -16,9 +16,6 @@
*/
package org.transdroid.core.gui.lists;
import org.transdroid.R;
import org.transdroid.daemon.Priority;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Paint;
@ -26,23 +23,26 @@ import android.graphics.RectF; @@ -26,23 +23,26 @@ import android.graphics.RectF;
import android.util.AttributeSet;
import android.widget.RelativeLayout;
import org.transdroid.R;
import org.transdroid.daemon.Priority;
/**
* A relative layout that that is checkable (to be used in a contextual action bar) and shows a coloured bar in the far
* left indicating the priority of the represented file. The darker the green, the higher the priority, while grey means
* the file isn't downloaded at all.
*
* @author Eric Kok
*/
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);
@ -72,9 +72,7 @@ public class TorrentFilePriorityLayout extends RelativeLayout { @@ -72,9 +72,7 @@ public class TorrentFilePriorityLayout extends RelativeLayout {
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
int height = getHeight();
int width = WIDTH;
fullRect.set(0, 0, width, height);
fullRect.set(0, 0, WIDTH, getHeight());
if (priority == null) {
return;

1
app/src/main/java/org/transdroid/core/gui/lists/TorrentFileView.java

@ -26,6 +26,7 @@ import org.transdroid.daemon.TorrentFile; @@ -26,6 +26,7 @@ import org.transdroid.daemon.TorrentFile;
/**
* View that represents some {@link TorrentFile} object and show the file's name, status and priority
*
* @author Eric Kok
*/
@EViewGroup(R.layout.list_item_torrentfile)

41
app/src/main/java/org/transdroid/core/gui/lists/TorrentProgressBar.java

@ -16,8 +16,6 @@ @@ -16,8 +16,6 @@
*/
package org.transdroid.core.gui.lists;
import org.transdroid.R;
import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Canvas;
@ -26,6 +24,8 @@ import android.graphics.RectF; @@ -26,6 +24,8 @@ import android.graphics.RectF;
import android.util.AttributeSet;
import android.view.View;
import org.transdroid.R;
/**
* Draws a progress bar indicating the download progress as well as the torrent status.
*
@ -35,10 +35,6 @@ public class TorrentProgressBar extends View { @@ -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 { @@ -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 { @@ -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));

15
app/src/main/java/org/transdroid/core/gui/lists/TorrentStatusLayout.java

@ -16,9 +16,6 @@ @@ -16,9 +16,6 @@
*/
package org.transdroid.core.gui.lists;
import org.transdroid.R;
import org.transdroid.daemon.TorrentStatus;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Paint;
@ -26,24 +23,27 @@ import android.graphics.RectF; @@ -26,24 +23,27 @@ import android.graphics.RectF;
import android.util.AttributeSet;
import android.widget.RelativeLayout;
import org.transdroid.R;
import org.transdroid.daemon.TorrentStatus;
/**
* A relative layout that is checkable (to be used in a contextual action bar) and shows a coloured bar in the far left
* indicating the status of the represented torrent. Active downloads are blue, seeding torrents are green, errors are
* red, etc.
*
* @author Eric Kok
*/
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);
@ -68,6 +68,7 @@ public class TorrentStatusLayout extends RelativeLayout { @@ -68,6 +68,7 @@ public class TorrentStatusLayout extends RelativeLayout {
/**
* Registers the status of the represented torrent and invalidates the view so the status colour will be updated
* accordingly.
*
* @param status The updated torrent status to show
*/
public void setStatus(TorrentStatus status) {
@ -79,9 +80,7 @@ public class TorrentStatusLayout extends RelativeLayout { @@ -79,9 +80,7 @@ public class TorrentStatusLayout extends RelativeLayout {
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
int height = getHeight();
int width = WIDTH;
fullRect.set(0, 0, width, height);
fullRect.set(0, 0, WIDTH, getHeight());
if (status == null) {
return;

1
app/src/main/java/org/transdroid/core/gui/lists/TorrentView.java

@ -29,6 +29,7 @@ import org.transdroid.daemon.TorrentStatus; @@ -29,6 +29,7 @@ import org.transdroid.daemon.TorrentStatus;
/**
* View that represents some {@link Torrent} object and displays progress, status, speeds, etc.
*
* @author Eric Kok
*/
@EViewGroup(R.layout.list_item_torrent)

5
app/src/main/java/org/transdroid/core/gui/lists/TorrentsAdapter.java

@ -29,18 +29,19 @@ import java.util.ArrayList; @@ -29,18 +29,19 @@ import java.util.ArrayList;
/**
* Adapter that contains a list of torrent objects to show.
*
* @author Eric Kok
*/
@EBean
public class TorrentsAdapter extends BaseAdapter {
private ArrayList<Torrent> torrents = null;
@RootContext
protected Context context;
private ArrayList<Torrent> torrents = null;
/**
* Allows updating the full internal list of torrents at once, replacing the old list
*
* @param newTorrents The new list of torrent objects
*/
public void update(ArrayList<Torrent> newTorrents) {

4
app/src/main/java/org/transdroid/core/gui/lists/ViewHolderAdapter.java

@ -28,6 +28,7 @@ import android.widget.ListView; @@ -28,6 +28,7 @@ import android.widget.ListView;
* the view object. This is required since otherwise the adapter's consumer (i.e. a {@link ListView}) does not update
* the list row accordingly. Use {@link #setViewEnabled(boolean)} to enable or disable this contained view for user
* interaction.
*
* @author Eric Kok
*/
public class ViewHolderAdapter extends BaseAdapter {
@ -38,6 +39,7 @@ public class ViewHolderAdapter extends BaseAdapter { @@ -38,6 +39,7 @@ public class ViewHolderAdapter extends BaseAdapter {
* Instantiates this wrapper adapter with the one and only view to show. It can not be updated and view visibility
* should be set directly on this adapter using {@link #setViewVisibility(int)}. Use
* {@link #setViewEnabled(boolean)} to enable or disable this contained view for user interaction.
*
* @param view The view that will be wrapper in an adapter to show in a list view
*/
public ViewHolderAdapter(View view) {
@ -47,6 +49,7 @@ public class ViewHolderAdapter extends BaseAdapter { @@ -47,6 +49,7 @@ public class ViewHolderAdapter extends BaseAdapter {
/**
* Sets the visibility on the contained view and notifies consumers of this adapter (i.e. a {@link ListView})
* accordingly. Use {@link View#GONE} to hide this adapter's view altogether.
*
* @param visibility The visibility to set on the contained view
*/
public void setViewVisibility(int visibility) {
@ -57,6 +60,7 @@ public class ViewHolderAdapter extends BaseAdapter { @@ -57,6 +60,7 @@ public class ViewHolderAdapter extends BaseAdapter {
/**
* Sets whether the contained view should be enabled and notifies consumers of this adapter (i.e. a {@link ListView}
* ) accordingly. A contained enabled view allows user interaction (clicks, focus), while a disabled view does not.
*
* @param enabled Whether the contained view should be enabled
*/
public void setViewEnabled(boolean enabled) {

10
app/src/main/java/org/transdroid/core/gui/log/DatabaseHelper.java

@ -16,19 +16,21 @@ @@ -16,19 +16,21 @@
*/
package org.transdroid.core.gui.log;
import java.sql.SQLException;
import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import androidx.annotation.Keep;
import android.util.Log;
import androidx.annotation.Keep;
import com.j256.ormlite.android.apptools.OrmLiteSqliteOpenHelper;
import com.j256.ormlite.support.ConnectionSource;
import com.j256.ormlite.table.TableUtils;
import java.sql.SQLException;
/**
* Helper to access the database to access persisting objects.
*
* @author Eric Kok
*/
public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
@ -57,7 +59,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { @@ -57,7 +59,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
switch (oldVersion) {
case 1:
TableUtils.createTable(connectionSource, ErrorLogEntry.class);
/*case 1:
/*case 2:
etc...*/
}

39
app/src/main/java/org/transdroid/core/gui/log/ErrorLogEntry.java

@ -16,16 +16,17 @@ @@ -16,16 +16,17 @@
*/
package org.transdroid.core.gui.log;
import java.util.Date;
import android.os.Parcel;
import android.os.Parcelable;
import com.j256.ormlite.field.DatabaseField;
import com.j256.ormlite.table.DatabaseTable;
import java.util.Date;
/**
* Represents an error log entry to be registered in the database.
*
* @author Eric Kok
*/
@DatabaseTable(tableName = "ErrorLogEntry")
@ -33,7 +34,15 @@ public class ErrorLogEntry implements Parcelable { @@ -33,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<ErrorLogEntry> CREATOR = new Parcelable.Creator<ErrorLogEntry>() {
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)
@ -55,6 +64,14 @@ public class ErrorLogEntry implements Parcelable { @@ -55,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;
}
@ -87,22 +104,4 @@ public class ErrorLogEntry implements Parcelable { @@ -87,22 +104,4 @@ public class ErrorLogEntry implements Parcelable {
out.writeString(message);
}
public static final Parcelable.Creator<ErrorLogEntry> CREATOR = new Parcelable.Creator<ErrorLogEntry>() {
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();
}
}

14
app/src/main/java/org/transdroid/core/gui/log/ErrorLogSender.java

@ -16,8 +16,11 @@ @@ -16,8 +16,11 @@
*/
package org.transdroid.core.gui.log;
import java.sql.SQLException;
import java.util.List;
import android.app.Activity;
import android.content.ActivityNotFoundException;
import android.content.Intent;
import com.j256.ormlite.dao.Dao;
import org.androidannotations.annotations.Bean;
import org.androidannotations.annotations.EBean;
@ -26,11 +29,8 @@ import org.transdroid.R; @@ -26,11 +29,8 @@ import org.transdroid.R;
import org.transdroid.core.app.settings.ServerSetting;
import org.transdroid.core.gui.navigation.NavigationHelper;
import android.app.Activity;
import android.content.ActivityNotFoundException;
import android.content.Intent;
import com.j256.ormlite.dao.Dao;
import java.sql.SQLException;
import java.util.List;
@EBean
public class ErrorLogSender {

1
app/src/main/java/org/transdroid/core/gui/log/Log.java

@ -28,6 +28,7 @@ import java.util.Date; @@ -28,6 +28,7 @@ import java.util.Date;
/**
* Application-wide logging class that registers entries in the database (for a certain time).
*
* @author Eric Kok
*/
@EBean(scope = Scope.Singleton)

66
app/src/main/java/org/transdroid/core/gui/navigation/DialogHelper.java

@ -16,12 +16,6 @@ @@ -16,12 +16,6 @@
*/
package org.transdroid.core.gui.navigation;
import java.io.Serializable;
import org.androidannotations.annotations.EActivity;
import org.androidannotations.annotations.Extra;
import org.transdroid.core.gui.*;
import android.app.Activity;
import android.app.Dialog;
import android.content.Context;
@ -32,10 +26,17 @@ import android.view.MenuInflater; @@ -32,10 +26,17 @@ import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.Window;
import org.androidannotations.annotations.EActivity;
import org.androidannotations.annotations.Extra;
import org.transdroid.core.gui.TorrentsActivity_;
import java.io.Serializable;
/**
* Helper class that show a dialog either as pop-up or as full screen activity. Should be used by calling
* {@link #showDialog(Context, DialogSpecification)} with in instance of the dialog specification that should be shown,
* from the calling activity's {@link Activity#onCreateDialog(int)}.
*
* @author Eric Kok
*/
@EActivity
@ -44,6 +45,27 @@ public class DialogHelper extends Activity { @@ -44,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);
@ -69,23 +91,16 @@ public class DialogHelper extends Activity { @@ -69,23 +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);
}
/**
@ -99,15 +114,4 @@ public class DialogHelper extends Activity { @@ -99,15 +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);
}
}

17
app/src/main/java/org/transdroid/core/gui/navigation/FilterListAdapter.java

@ -24,7 +24,6 @@ import org.androidannotations.annotations.RootContext; @@ -24,7 +24,6 @@ import org.androidannotations.annotations.RootContext;
import org.transdroid.R;
import org.transdroid.core.app.settings.ServerSetting;
import org.transdroid.core.gui.lists.MergeAdapter;
import org.transdroid.core.gui.lists.SimpleListItem;
import org.transdroid.core.gui.lists.ViewHolderAdapter;
import org.transdroid.core.gui.navigation.StatusType.StatusTypeFilter;
@ -33,6 +32,7 @@ import java.util.List; @@ -33,6 +32,7 @@ import java.util.List;
/**
* List adapter that holds filter items, that is, servers, view types and labels. A header item is inserted where appropriate.
*
* @author Eric Kok
*/
@EBean
@ -40,15 +40,16 @@ public class FilterListAdapter extends MergeAdapter { @@ -40,15 +40,16 @@ 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
*
* @param servers The new list of available servers
*/
public void updateServers(List<ServerSetting> servers) {
@ -63,13 +64,14 @@ public class FilterListAdapter extends MergeAdapter { @@ -63,13 +64,14 @@ public class FilterListAdapter extends MergeAdapter {
this.serverItems.update(servers);
} else {
serverSeparator.setViewVisibility(View.GONE);
this.serverItems.update(new ArrayList<SimpleListItem>());
this.serverItems.update(new ArrayList<>());
}
notifyDataSetChanged();
}
/**
* Update the list of available status types
*
* @param statusTypes The new list of available status types
*/
public void updateStatusTypes(List<StatusTypeFilter> statusTypes) {
@ -84,13 +86,14 @@ public class FilterListAdapter extends MergeAdapter { @@ -84,13 +86,14 @@ public class FilterListAdapter extends MergeAdapter {
this.statusTypeItems.update(statusTypes);
} else {
statusTypeSeparator.setViewVisibility(View.GONE);
this.statusTypeItems.update(new ArrayList<SimpleListItem>());
this.statusTypeItems.update(new ArrayList<>());
}
notifyDataSetChanged();
}
/**
* Update the list of available labels
*
* @param labels The new list of available labels
*/
public void updateLabels(List<Label> labels) {
@ -105,7 +108,7 @@ public class FilterListAdapter extends MergeAdapter { @@ -105,7 +108,7 @@ public class FilterListAdapter extends MergeAdapter {
this.labelItems.update(labels);
} else {
labelSeperator.setViewVisibility(View.GONE);
this.labelItems.update(new ArrayList<SimpleListItem>());
this.labelItems.update(new ArrayList<>());
}
notifyDataSetChanged();
}

3
app/src/main/java/org/transdroid/core/gui/navigation/FilterListItemAdapter.java

@ -38,6 +38,7 @@ public class FilterListItemAdapter extends BaseAdapter { @@ -38,6 +38,7 @@ public class FilterListItemAdapter extends BaseAdapter {
/**
* Allows updating of the full data list underlying this adapter, replacing all items
*
* @param newItems The new list of filter items to display
*/
public void update(List<? extends SimpleListItem> newItems) {
@ -63,7 +64,7 @@ public class FilterListItemAdapter extends BaseAdapter { @@ -63,7 +64,7 @@ public class FilterListItemAdapter extends BaseAdapter {
@Override
public View getView(int position, View convertView, ViewGroup parent) {
FilterListItemView filterItemView;
if (convertView == null || !(convertView instanceof SimpleListItemView)) {
if (!(convertView instanceof SimpleListItemView)) {
filterItemView = FilterListItemView_.build(context);
} else {
filterItemView = (FilterListItemView) convertView;

1
app/src/main/java/org/transdroid/core/gui/navigation/FilterListItemView.java

@ -27,6 +27,7 @@ import org.transdroid.core.gui.lists.SimpleListItem; @@ -27,6 +27,7 @@ import org.transdroid.core.gui.lists.SimpleListItem;
/**
* View that represents some {@link SimpleListItem} object specifically used to represent a navigation filter item.
*
* @author Eric Kok
*/
@EViewGroup(R.layout.list_item_filter)

2
app/src/main/java/org/transdroid/core/gui/navigation/FilterSeparatorView.java

@ -27,6 +27,7 @@ import org.transdroid.R; @@ -27,6 +27,7 @@ import org.transdroid.R;
/**
* A list item that shows a sub header or separator (in underlined Holo style).
*
* @author Eric Kok
*/
@EViewGroup(R.layout.list_item_separator)
@ -43,6 +44,7 @@ public class FilterSeparatorView extends FrameLayout { @@ -43,6 +44,7 @@ public class FilterSeparatorView extends FrameLayout {
/**
* Sets the text that will be shown in this separator (sub header)
*
* @param text The new text to show
* @return Itself, for convenience of method chaining
*/

87
app/src/main/java/org/transdroid/core/gui/navigation/Label.java

@ -29,12 +29,21 @@ import java.util.List; @@ -29,12 +29,21 @@ import java.util.List;
/**
* Represents some label that is active or available on the server.
*
* @author Eric Kok
*/
public class Label implements SimpleListItem, NavigationFilter, Comparable<Label> {
private static String unnamedLabelText = null;
public static final Parcelable.Creator<Label> CREATOR = new Parcelable.Creator<Label>() {
public Label createFromParcel(Parcel in) {
return new Label(in);
}
public Label[] newArray(int size) {
return new Label[size];
}
};
private static String unnamedLabelText = null;
private final boolean isEmptyLabel;
private final String name;
private final int count;
@ -49,6 +58,39 @@ public class Label implements SimpleListItem, NavigationFilter, Comparable<Label @@ -49,6 +58,39 @@ public class Label implements SimpleListItem, NavigationFilter, Comparable<Label
this(daemonLabel.getName(), daemonLabel.getCount(), false);
}
private Label(Parcel in) {
this.name = in.readString();
this.count = in.readInt();
this.isEmptyLabel = in.readInt() == 1;
}
/**
* Converts a list of labels as retrieved from a server daemon into a list of labels that can be used in the UI as navigation filters.
*
* @param daemonLabels The raw list of labels as received from the server daemon adapter
* @param unnamedLabel The text to show for the empty label (i.e. the unnamed label)
* @return A label items that can be used in a filter list such as the action bar spinner
*/
public static ArrayList<Label> convertToNavigationLabels(List<org.transdroid.daemon.Label> daemonLabels, String unnamedLabel) {
if (daemonLabels == null) {
return null;
}
ArrayList<Label> localLabels = new ArrayList<>();
unnamedLabelText = unnamedLabel;
for (org.transdroid.daemon.Label label : daemonLabels) {
if (label != null && !TextUtils.isEmpty(label.getName())) {
localLabels.add(new Label(label));
}
}
Collections.sort(localLabels);
// force unlabelled to be at the top
localLabels.add(0, new Label(unnamedLabel, -1, true));
return localLabels;
}
@Override
public String getName() {
if (TextUtils.isEmpty(this.name)) {
@ -73,6 +115,7 @@ public class Label implements SimpleListItem, NavigationFilter, Comparable<Label @@ -73,6 +115,7 @@ public class Label implements SimpleListItem, NavigationFilter, Comparable<Label
/**
* Returns true if the torrent label's name matches this (selected) label's name, false otherwise
*
* @param torrent The torrent to match against this label
* @param dormantAsInactive This property is ignored for label comparisons
*/
@ -89,48 +132,6 @@ public class Label implements SimpleListItem, NavigationFilter, Comparable<Label @@ -89,48 +132,6 @@ public class Label implements SimpleListItem, NavigationFilter, Comparable<Label
return this.name.compareTo(another.getName());
}
/**
* Converts a list of labels as retrieved from a server daemon into a list of labels that can be used in the UI as navigation filters.
* @param daemonLabels The raw list of labels as received from the server daemon adapter
* @param unnamedLabel The text to show for the empty label (i.e. the unnamed label)
* @return A label items that can be used in a filter list such as the action bar spinner
*/
public static ArrayList<Label> convertToNavigationLabels(List<org.transdroid.daemon.Label> daemonLabels, String unnamedLabel) {
if (daemonLabels == null) {
return null;
}
ArrayList<Label> localLabels = new ArrayList<>();
unnamedLabelText = unnamedLabel;
for (org.transdroid.daemon.Label label : daemonLabels) {
if (label != null && !TextUtils.isEmpty(label.getName())) {
localLabels.add(new Label(label));
}
}
Collections.sort(localLabels);
// force unlabelled to be at the top
localLabels.add(0, new Label(unnamedLabel, -1, true));
return localLabels;
}
private Label(Parcel in) {
this.name = in.readString();
this.count = in.readInt();
this.isEmptyLabel = in.readInt() == 1;
}
public static final Parcelable.Creator<Label> CREATOR = new Parcelable.Creator<Label>() {
public Label createFromParcel(Parcel in) {
return new Label(in);
}
public Label[] newArray(int size) {
return new Label[size];
}
};
@Override
public int describeContents() {
return 0;

4
app/src/main/java/org/transdroid/core/gui/navigation/NavigationFilter.java

@ -22,6 +22,7 @@ import org.transdroid.daemon.Torrent; @@ -22,6 +22,7 @@ import org.transdroid.daemon.Torrent;
/**
* Represents a filter, used in the app navigation, that can check if some torrent matches the user-set filter
*
* @author Eric Kok
*/
public interface NavigationFilter extends Parcelable {
@ -29,6 +30,7 @@ public interface NavigationFilter extends Parcelable { @@ -29,6 +30,7 @@ public interface NavigationFilter extends Parcelable {
/**
* Implementations should check if the supplied torrent matches the filter; for example a label filter should return true if the torrent's label
* equals this items label name.
*
* @param torrent The torrent to check for matches
* @param dormantAsInactive If true, dormant (0KB/s, so no data transfer) torrents are never actively downloading or seeding
* @return True if the torrent matches the filter and should be shown in the current screen, false otherwise
@ -37,12 +39,14 @@ public interface NavigationFilter extends Parcelable { @@ -37,12 +39,14 @@ public interface NavigationFilter extends Parcelable {
/**
* Implementations should return a name that can be shown to indicate the active filter
*
* @return The name of the filter item as string
*/
String getName();
/**
* Implementations should return a code that (within reasonable expectations) uniquely identifies it in the list of navigation filters
*
* @return The code to uniquely identify this specific navigation filter, such as the name with a class name prefix
*/
String getCode();

154
app/src/main/java/org/transdroid/core/gui/navigation/NavigationHelper.java

@ -26,14 +26,13 @@ import android.content.pm.PackageManager; @@ -26,14 +26,13 @@ import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.net.Uri;
import android.os.Build;
import androidx.annotation.NonNull;
import androidx.core.app.ActivityCompat;
import androidx.core.content.ContextCompat;
import android.text.Spannable;
import android.text.SpannableString;
import android.text.style.TypefaceSpan;
import com.afollestad.materialdialogs.DialogAction;
import androidx.core.app.ActivityCompat;
import androidx.core.content.ContextCompat;
import com.afollestad.materialdialogs.MaterialDialog;
import com.nostra13.universalimageloader.cache.disc.impl.ext.LruDiskCache;
import com.nostra13.universalimageloader.cache.disc.naming.Md5FileNameGenerator;
@ -54,6 +53,7 @@ import java.util.List; @@ -54,6 +53,7 @@ import java.util.List;
/**
* Helper for activities to make navigation-related decisions, such as when a device can display a larger, tablet style layout or how to display
* errors.
*
* @author Eric Kok
*/
@SuppressLint("ResourceAsColor")
@ -68,78 +68,9 @@ public class NavigationHelper { @@ -68,78 +68,9 @@ public class NavigationHelper {
@RootContext
protected Context context;
@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
public boolean checkTorrentReadPermission(final Activity activity) {
return Build.VERSION.SDK_INT <= Build.VERSION_CODES.KITKAT ||
checkPermission(activity, Manifest.permission.READ_EXTERNAL_STORAGE, REQUEST_TORRENT_READ_PERMISSION);
}
@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
public boolean checkSettingsReadPermission(final Activity activity) {
return Build.VERSION.SDK_INT <= Build.VERSION_CODES.KITKAT ||
checkPermission(activity, Manifest.permission.READ_EXTERNAL_STORAGE, REQUEST_SETTINGS_READ_PERMISSION);
}
@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
public boolean checkSettingsWritePermission(final Activity activity) {
return Build.VERSION.SDK_INT <= Build.VERSION_CODES.KITKAT ||
checkPermission(activity, Manifest.permission.WRITE_EXTERNAL_STORAGE, REQUEST_SETTINGS_WRITE_PERMISSION);
}
private boolean checkPermission(final Activity activity, final String permission, final int requestCode) {
if (hasPermission(permission))
// Permission already granted
return true;
if (!ActivityCompat.shouldShowRequestPermissionRationale(activity, permission)) {
// Never asked again: show a dialog with an explanation
activity.runOnUiThread(new Runnable() {
public void run() {
new MaterialDialog.Builder(context).content(R.string.permission_readtorrent).positiveText(android.R.string.ok)
.onPositive(new MaterialDialog.SingleButtonCallback() {
@Override
public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
ActivityCompat.requestPermissions(activity, new String[]{permission}, requestCode);
}
}).show();
}
});
return false;
}
// Permission not granted (and we asked for it already before)
ActivityCompat.requestPermissions(activity, new String[]{permission}, REQUEST_TORRENT_READ_PERMISSION);
return false;
}
private boolean hasPermission(String requiredPermission) {
return ContextCompat.checkSelfPermission(context, requiredPermission) == PackageManager.PERMISSION_GRANTED;
}
public Boolean handleTorrentReadPermissionResult(int requestCode, int[] grantResults) {
if (requestCode == REQUEST_TORRENT_READ_PERMISSION) {
// Return permission granting result
return grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED;
}
return null;
}
public Boolean handleSettingsReadPermissionResult(int requestCode, int[] grantResults) {
if (requestCode == REQUEST_SETTINGS_READ_PERMISSION) {
// Return permission granting result
return grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED;
}
return null;
}
public Boolean handleSettingsWritePermissionResult(int requestCode, int[] grantResults) {
if (requestCode == REQUEST_SETTINGS_WRITE_PERMISSION) {
// Return permission granting result
return grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED;
}
return null;
}
/**
* Converts a string into a {@link Spannable} that displays the string in the Roboto Condensed font
*
* @param string A plain text {@link String}
* @return A {@link Spannable} that can be applied to supporting views (such as the action bar title) so that the input string will be displayed
* using the Roboto Condensed font (if the OS has this)
@ -155,6 +86,7 @@ public class NavigationHelper { @@ -155,6 +86,7 @@ public class NavigationHelper {
/**
* Analyses a torrent http or magnet URI and tries to come up with a reasonable human-readable name.
*
* @param rawTorrentUri The raw http:// or magnet: link to the torrent
* @return A best-guess, reasonably long name for the linked torrent
*/
@ -202,8 +134,74 @@ public class NavigationHelper { @@ -202,8 +134,74 @@ public class NavigationHelper {
return null;
}
@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
public boolean checkTorrentReadPermission(final Activity activity) {
return Build.VERSION.SDK_INT <= Build.VERSION_CODES.KITKAT ||
checkPermission(activity, Manifest.permission.READ_EXTERNAL_STORAGE, REQUEST_TORRENT_READ_PERMISSION);
}
@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
public boolean checkSettingsReadPermission(final Activity activity) {
return Build.VERSION.SDK_INT <= Build.VERSION_CODES.KITKAT ||
checkPermission(activity, Manifest.permission.READ_EXTERNAL_STORAGE, REQUEST_SETTINGS_READ_PERMISSION);
}
@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
public boolean checkSettingsWritePermission(final Activity activity) {
return Build.VERSION.SDK_INT <= Build.VERSION_CODES.KITKAT ||
checkPermission(activity, Manifest.permission.WRITE_EXTERNAL_STORAGE, REQUEST_SETTINGS_WRITE_PERMISSION);
}
private boolean checkPermission(final Activity activity, final String permission, final int requestCode) {
if (hasPermission(permission))
// Permission already granted
return true;
if (!ActivityCompat.shouldShowRequestPermissionRationale(activity, permission)) {
// Never asked again: show a dialog with an explanation
activity.runOnUiThread(() ->
new MaterialDialog.Builder(context)
.content(R.string.permission_readtorrent)
.positiveText(android.R.string.ok)
.onPositive((dialog, which) ->
ActivityCompat.requestPermissions(activity, new String[]{permission}, requestCode)).show());
return false;
}
// Permission not granted (and we asked for it already before)
ActivityCompat.requestPermissions(activity, new String[]{permission}, REQUEST_TORRENT_READ_PERMISSION);
return false;
}
private boolean hasPermission(String requiredPermission) {
return ContextCompat.checkSelfPermission(context, requiredPermission) == PackageManager.PERMISSION_GRANTED;
}
public Boolean handleTorrentReadPermissionResult(int requestCode, int[] grantResults) {
if (requestCode == REQUEST_TORRENT_READ_PERMISSION) {
// Return permission granting result
return grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED;
}
return null;
}
public Boolean handleSettingsReadPermissionResult(int requestCode, int[] grantResults) {
if (requestCode == REQUEST_SETTINGS_READ_PERMISSION) {
// Return permission granting result
return grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED;
}
return null;
}
public Boolean handleSettingsWritePermissionResult(int requestCode, int[] grantResults) {
if (requestCode == REQUEST_SETTINGS_WRITE_PERMISSION) {
// Return permission granting result
return grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED;
}
return null;
}
/**
* Returns (and initialises, if needed) an image cache that uses memory and (1MB) local storage.
*
* @return An image cache that loads web images synchronously and transparently
*/
public ImageLoader getImageCache() {
@ -250,15 +248,17 @@ public class NavigationHelper { @@ -250,15 +248,17 @@ public class NavigationHelper {
/**
* Returns the application name (like Transdroid) and version name (like 1.5.0), appended by the version code (like 180).
*
* @return The app name and version, such as 'Transdroid 1.5.0 (180)'
*/
public String getAppNameAndVersion() {
return context.getString(R.string.app_name) + " " + BuildConfig.VERSION_NAME + " (" + Integer.toString(BuildConfig.VERSION_CODE) + ")";
return context.getString(R.string.app_name) + " " + BuildConfig.VERSION_NAME + " (" + BuildConfig.VERSION_CODE + ")";
}
/**
* Returns whether the device is considered small (i.e. a phone) rather than large (i.e. a tablet). Can, for example, be used to determine if a
* dialog should be shown full screen. Currently is true if the device's smallest dimension is 500 dip.
*
* @return True if the app runs on a small device, false otherwise
*/
public boolean isSmallScreen() {
@ -268,6 +268,7 @@ public class NavigationHelper { @@ -268,6 +268,7 @@ public class NavigationHelper {
/**
* Whether any search-related UI components should be shown in the interface. At the moment returns false only if we run as Transdroid Lite
* version.
*
* @return True if search is enabled, false otherwise
*/
public boolean enableSearchUi() {
@ -276,6 +277,7 @@ public class NavigationHelper { @@ -276,6 +277,7 @@ public class NavigationHelper {
/**
* Whether any RSS-related UI components should be shown in the interface. At the moment returns false only if we run as Transdroid Lite version.
*
* @return True if search is enabled, false otherwise
*/
public boolean enableRssUi() {
@ -285,6 +287,7 @@ public class NavigationHelper { @@ -285,6 +287,7 @@ public class NavigationHelper {
/**
* Returns whether any seedbox-related components should be shown in the interface; specifically the option to add server settings via easy
* seedbox-specific screens.
*
* @return True if seedbox settings should be shown, false otherwise
*/
public boolean enableSeedboxes() {
@ -293,6 +296,7 @@ public class NavigationHelper { @@ -293,6 +296,7 @@ public class NavigationHelper {
/**
* Whether the custom app update checker should be used to check for new app and search module versions.
*
* @return True if it should be checked against transdroid.org if there are app updates (as opposed to using the Play Store for updates, for
* example), false otherwise
*/

1
app/src/main/java/org/transdroid/core/gui/navigation/RefreshableActivity.java

@ -18,6 +18,7 @@ package org.transdroid.core.gui.navigation; @@ -18,6 +18,7 @@ package org.transdroid.core.gui.navigation;
/**
* Interface to be implemented by any activity that allows its content to be refreshed; fragments can ask for user-initiated refreshes.
*
* @author Eric Kok
*/
public interface RefreshableActivity {

9
app/src/main/java/org/transdroid/core/gui/navigation/SelectionManagerMode.java

@ -16,9 +16,6 @@ @@ -16,9 +16,6 @@
*/
package org.transdroid.core.gui.navigation;
import org.transdroid.core.gui.navigation.SelectionModificationSpinner.OnModificationActionSelectedListener;
import org.transdroid.daemon.Finishable;
import android.content.Context;
import android.util.SparseBooleanArray;
import android.view.ActionMode;
@ -28,10 +25,14 @@ import android.view.ViewGroup; @@ -28,10 +25,14 @@ import android.view.ViewGroup;
import android.widget.AbsListView.MultiChoiceModeListener;
import android.widget.ListView;
import org.transdroid.core.gui.navigation.SelectionModificationSpinner.OnModificationActionSelectedListener;
import org.transdroid.daemon.Finishable;
/**
* A helper to implement {@link ListView} selection modification behaviour with the {@link SelectionModificationSpinner}
* by implementing the specific actions and providing a title based on the number of currently selected items. It is
* important that the provided list was instantiated already.
*
* @author Eric Kok
*/
public class SelectionManagerMode implements MultiChoiceModeListener, OnModificationActionSelectedListener {
@ -44,6 +45,7 @@ public class SelectionManagerMode implements MultiChoiceModeListener, OnModifica @@ -44,6 +45,7 @@ public class SelectionManagerMode implements MultiChoiceModeListener, OnModifica
/**
* Instantiates the helper by binding it to a specific {@link ListView} and providing the text resource to display
* as title in the spinner.
*
* @param themedContext The context which is associated with the correct theme to apply when inflating views, i.e. the toolbar context
* @param managedList The list to manage the selection for and execute selection action to
* @param titleTemplateResource The string resource id to show as the spinners title; the number of selected items
@ -58,6 +60,7 @@ public class SelectionManagerMode implements MultiChoiceModeListener, OnModifica @@ -58,6 +60,7 @@ public class SelectionManagerMode implements MultiChoiceModeListener, OnModifica
/**
* Set the class type of items that are allowed to be checked in the {@link ListView}. Defaults to null, which means
* every list view row can be checked.
*
* @param onlyCheckClass The {@link Class} instance to use to check list item types against
*/
public void setOnlyCheckClass(Class<?> onlyCheckClass) {

35
app/src/main/java/org/transdroid/core/gui/navigation/SelectionModificationSpinner.java

@ -16,27 +16,30 @@ @@ -16,27 +16,30 @@
*/
package org.transdroid.core.gui.navigation;
import org.transdroid.R;
import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.Spinner;
import android.widget.TextView;
import androidx.appcompat.widget.AppCompatSpinner;
import org.transdroid.R;
/**
* Spinner that holds actions that can be performed on list selections. The spinner itself has some title, which can for
* example be used to show the number of selected items.
*
* @author Eric Kok
*/
public class SelectionModificationSpinner extends Spinner {
public class SelectionModificationSpinner extends AppCompatSpinner {
private SelectionDropDownAdapter selectionAdapter;
private OnModificationActionSelectedListener onModificationActionSelected = null;
/**
* Instantiates a spinner that contains some fixed actions for a user to modify selections.
*
* @param context The interface context where the spinner will be shown in
*/
public SelectionModificationSpinner(Context context) {
@ -47,6 +50,7 @@ public class SelectionModificationSpinner extends Spinner { @@ -47,6 +50,7 @@ public class SelectionModificationSpinner extends Spinner {
/**
* Updates the fixed title text shown in the spinner, regardless of spinner item action selection.
*
* @param title The new static string to show, such as the number of selected items
*/
public void updateTitle(String title) {
@ -56,6 +60,7 @@ public class SelectionModificationSpinner extends Spinner { @@ -56,6 +60,7 @@ public class SelectionModificationSpinner extends Spinner {
/**
* Sets the listener for action selection events.
*
* @param onModificationActionSelected The listener that handles performing of the actions as selected in this
* spinner by the user
*/
@ -75,11 +80,22 @@ public class SelectionModificationSpinner extends Spinner { @@ -75,11 +80,22 @@ public class SelectionModificationSpinner extends Spinner {
super.setSelection(position);
}
/**
* Interface to implement if an interface want to respond to selection modification actions.
*/
public interface OnModificationActionSelectedListener {
void selectAll();
void selectFinished();
void invertSelection();
}
/**
* Local adapter that holds the actions which can be performed and a title text view that always shows instead of a
* list item as in a normal spinner.
*/
private class SelectionDropDownAdapter extends ArrayAdapter<String> {
private static class SelectionDropDownAdapter extends ArrayAdapter<String> {
protected TextView titleView = null;
@ -105,13 +121,4 @@ public class SelectionModificationSpinner extends Spinner { @@ -105,13 +121,4 @@ public class SelectionModificationSpinner extends Spinner {
}
/**
* Interface to implement if an interface want to respond to selection modification actions.
*/
public interface OnModificationActionSelectedListener {
public void selectAll();
public void selectFinished();
public void invertSelection();
}
}

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

@ -20,8 +20,6 @@ import android.content.Context; @@ -20,8 +20,6 @@ import android.content.Context;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.EditText;
import android.widget.ListView;
@ -39,6 +37,7 @@ public class SetLabelDialog { @@ -39,6 +37,7 @@ public class SetLabelDialog {
/**
* A dialog fragment that allows picking a label or entering a new label to set this new label to the torrent.
*
* @param context The activity context that opens (and owns) this dialog
* @param onLabelPickedListener The callback when a new label has been entered or picked by the user
* @param currentLabels The list of labels as currently exist on the server, to present as list for easy selection
@ -61,22 +60,17 @@ public class SetLabelDialog { @@ -61,22 +60,17 @@ public class SetLabelDialog {
.positiveText(R.string.status_update)
.neutralText(R.string.status_label_remove)
.negativeText(android.R.string.cancel)
.callback(new MaterialDialog.ButtonCallback() {
@Override
public void onPositive(MaterialDialog dialog) {
.onPositive((dialog, which) -> {
// User should have provided a new label
if (TextUtils.isEmpty(newLabelEdit.getText())) {
SnackbarManager.show(Snackbar.with(context).text(R.string.error_notalabel).colorResource(R.color.red));
return;
}
onLabelPickedListener.onLabelPicked(newLabelEdit.getText().toString());
}
})
.onNeutral((dialog, which) ->
onLabelPickedListener.onLabelPicked(null));
@Override
public void onNeutral(MaterialDialog dialog) {
onLabelPickedListener.onLabelPicked(null);
}
});
final MaterialDialog dialog = SettingsUtils
.applyDialogTheme(builder)
.build();
@ -87,12 +81,9 @@ public class SetLabelDialog { @@ -87,12 +81,9 @@ public class SetLabelDialog {
labelsList.setVisibility(View.GONE);
} else {
labelsList.setAdapter(new FilterListItemAdapter(context, currentLabels));
labelsList.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
labelsList.setOnItemClickListener((parent, view, position, id) -> {
onLabelPickedListener.onLabelPicked(((Label) labelsList.getItemAtPosition(position)).getName());
dialog.dismiss();
}
});
}

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

@ -30,6 +30,7 @@ public class SetStorageLocationDialog { @@ -30,6 +30,7 @@ public class SetStorageLocationDialog {
/**
* A dialog fragment that allows changing of the storage location by editing the path text directly.
*
* @param context The activity context that opens (and owns) this dialog
* @param onStorageLocationUpdatedListener The callback for when the user is done updating the storage location
* @param currentLocation The current storage location that will be available to the user to edit
@ -42,12 +43,9 @@ public class SetStorageLocationDialog { @@ -42,12 +43,9 @@ public class SetStorageLocationDialog {
.customView(locationLayout, false)
.positiveText(R.string.status_update)
.negativeText(android.R.string.cancel)
.callback(new MaterialDialog.ButtonCallback() {
@Override
public void onPositive(MaterialDialog dialog) {
.onPositive((dialog, which) -> {
// User is done editing and requested to update given the text input
onStorageLocationUpdatedListener.onStorageLocationUpdated(locationText.getText().toString());
}
});
SettingsUtils

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

@ -16,12 +16,13 @@ @@ -16,12 +16,13 @@
*/
package org.transdroid.core.gui.navigation;
import android.app.DialogFragment;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.EditText;
import androidx.fragment.app.DialogFragment;
import com.afollestad.materialdialogs.MaterialDialog;
import org.transdroid.R;
@ -34,6 +35,7 @@ public class SetTrackersDialog extends DialogFragment { @@ -34,6 +35,7 @@ public class SetTrackersDialog extends DialogFragment {
/**
* A dialog fragment that allows changing the trackers of a torrent by editing the text directly.
*
* @param context The activity context that opens (and owns) this dialog
* @param onTrackersUpdatedListener The callback for when the user is done updating the trackers list
* @param currentTrackers The current trackers text/list that will be available to the user to edit
@ -46,12 +48,9 @@ public class SetTrackersDialog extends DialogFragment { @@ -46,12 +48,9 @@ public class SetTrackersDialog extends DialogFragment {
.customView(trackersLayout, false)
.positiveText(R.string.status_update)
.negativeText(android.R.string.cancel)
.callback(new MaterialDialog.ButtonCallback() {
@Override
public void onPositive(MaterialDialog dialog) {
.onPositive((dialog, which) -> {
// User is done editing and requested to update given the text input
onTrackersUpdatedListener.onTrackersUpdated(Arrays.asList(trackersText.getText().toString().split("\n")));
}
});
SettingsUtils.applyDialogTheme(builder).show();
}

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

@ -30,8 +30,19 @@ import org.transdroid.core.app.settings.SettingsUtils; @@ -30,8 +30,19 @@ import org.transdroid.core.app.settings.SettingsUtils;
public class SetTransferRatesDialog {
private static OnClickListener onNumberClicked = v -> {
// Append the text contents of the button itself as text to the current number (as reference in the view's
// tag)
TextView numberView = (TextView) v.getTag();
if (numberView.getText().toString().equals(v.getContext().getString(R.string.status_maxspeed_novalue))) {
numberView.setText("");
}
numberView.setText(numberView.getText().toString() + ((Button) v).getText().toString());
};
/**
* A dialog fragment that allow picking of maximum download and upload transfer rates as well as the resetting of these values.
*
* @param context The activity context that opens (and owns) this dialog
* @param onRatesPickedListener The callback for results in this dialog (with newly selected values or a reset)
*/
@ -46,9 +57,7 @@ public class SetTransferRatesDialog { @@ -46,9 +57,7 @@ public class SetTransferRatesDialog {
.positiveText(R.string.status_update)
.neutralText(R.string.status_maxspeed_reset)
.negativeText(android.R.string.cancel)
.callback(new MaterialDialog.ButtonCallback() {
@Override
public void onPositive(MaterialDialog dialog) {
.onPositive((dialog, which) -> {
int maxDown = -1, maxUp = -1;
try {
maxDown = Integer.parseInt(maxSpeedDown.getText().toString());
@ -61,13 +70,10 @@ public class SetTransferRatesDialog { @@ -61,13 +70,10 @@ public class SetTransferRatesDialog {
return;
}
onRatesPickedListener.onRatesPicked(maxDown, maxUp);
}
})
.onNeutral((dialog, which) ->
onRatesPickedListener.resetRates());
@Override
public void onNeutral(MaterialDialog dialog) {
onRatesPickedListener.resetRates();
}
});
MaterialDialog dialog = SettingsUtils.applyDialogTheme(builder).build();
bindButtons(dialog.getCustomView(), maxSpeedDown, R.id.down1Button, R.id.down2Button, R.id.down3Button, R.id.down4Button, R.id.down5Button,
@ -87,19 +93,6 @@ public class SetTransferRatesDialog { @@ -87,19 +93,6 @@ public class SetTransferRatesDialog {
}
}
private static OnClickListener onNumberClicked = new OnClickListener() {
@Override
public void onClick(View v) {
// Append the text contents of the button itself as text to the current number (as reference in the view's
// tag)
TextView numberView = (TextView) v.getTag();
if (numberView.getText().toString().equals(v.getContext().getString(R.string.status_maxspeed_novalue))) {
numberView.setText("");
}
numberView.setText(numberView.getText().toString() + ((Button) v).getText().toString());
}
};
/**
* Listener interface to the user having picked or wanting to resets the current maximum transfer speeds;
*/

44
app/src/main/java/org/transdroid/core/gui/navigation/StatusType.java

@ -16,19 +16,20 @@ @@ -16,19 +16,20 @@
*/
package org.transdroid.core.gui.navigation;
import java.util.Arrays;
import java.util.List;
import android.content.Context;
import android.os.Parcel;
import android.os.Parcelable;
import org.transdroid.R;
import org.transdroid.core.gui.lists.SimpleListItem;
import org.transdroid.daemon.Torrent;
import android.content.Context;
import android.os.Parcel;
import android.os.Parcelable;
import java.util.Arrays;
import java.util.List;
/**
* Enumeration of all status types, which filter the list of shown torrents based on transfer activity.
*
* @author Eric Kok
*/
public enum StatusType {
@ -61,6 +62,7 @@ public enum StatusType { @@ -61,6 +62,7 @@ public enum StatusType {
/**
* Returns the status type to show all torrents, represented as filter item to show in the navigation list.
*
* @param context The Android UI context, to access translations
* @return The show ShowAll status type filter item
*/
@ -70,6 +72,7 @@ public enum StatusType { @@ -70,6 +72,7 @@ public enum StatusType {
/**
* Returns a list with all status types, represented as filter item that can be shown in the GUI.
*
* @param context The Android UI context, to access translations
* @return A list of filter items for all available status types
*/
@ -81,6 +84,7 @@ public enum StatusType { @@ -81,6 +84,7 @@ public enum StatusType {
/**
* Every status type can return a filter item that represents it in the navigation
*
* @param context The Android UI context, to access translations
* @return A filter item object to show in the GUI
*/
@ -88,6 +92,15 @@ public enum StatusType { @@ -88,6 +92,15 @@ public enum StatusType {
public static class StatusTypeFilter implements SimpleListItem, NavigationFilter {
public static final Parcelable.Creator<StatusTypeFilter> CREATOR = new Parcelable.Creator<StatusTypeFilter>() {
public StatusTypeFilter createFromParcel(Parcel in) {
return new StatusTypeFilter(in);
}
public StatusTypeFilter[] newArray(int size) {
return new StatusTypeFilter[size];
}
};
private final StatusType statusType;
private final String name;
@ -96,6 +109,11 @@ public enum StatusType { @@ -96,6 +109,11 @@ public enum StatusType {
this.name = name;
}
private StatusTypeFilter(Parcel in) {
this.statusType = StatusType.valueOf(in.readString());
this.name = in.readString();
}
public StatusType getStatusType() {
return statusType;
}
@ -113,6 +131,7 @@ public enum StatusType { @@ -113,6 +131,7 @@ public enum StatusType {
/**
* Returns true if the torrent status matches this (selected) status type, false otherwise
*
* @param torrent The torrent to match against this status type
* @param dormantAsInactive If true, dormant (0KB/s, so no data transfer) torrents are never actively
* downloading or seeding
@ -134,21 +153,6 @@ public enum StatusType { @@ -134,21 +153,6 @@ public enum StatusType {
}
}
private StatusTypeFilter(Parcel in) {
this.statusType = StatusType.valueOf(in.readString());
this.name = in.readString();
}
public static final Parcelable.Creator<StatusTypeFilter> CREATOR = new Parcelable.Creator<StatusTypeFilter>() {
public StatusTypeFilter createFromParcel(Parcel in) {
return new StatusTypeFilter(in);
}
public StatusTypeFilter[] newArray(int size) {
return new StatusTypeFilter[size];
}
};
@Override
public int describeContents() {
return 0;

7
app/src/main/java/org/transdroid/core/gui/remoterss/RemoteRssFragment.java

@ -17,13 +17,14 @@ @@ -17,13 +17,14 @@
package org.transdroid.core.gui.remoterss;
import androidx.fragment.app.Fragment;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.Spinner;
import android.widget.TextView;
import androidx.fragment.app.Fragment;
import org.androidannotations.annotations.AfterViews;
import org.androidannotations.annotations.Bean;
import org.androidannotations.annotations.EFragment;
@ -44,6 +45,7 @@ import java.util.List; @@ -44,6 +45,7 @@ import java.util.List;
/**
* Fragment that shows a list of RSS items from the server and allows the user
* to download remotely, without having to set up RSS feeds on the Android device.
*
* @author Twig
*/
@EFragment(R.layout.fragment_remoterss)
@ -108,8 +110,7 @@ public class RemoteRssFragment extends Fragment { @@ -108,8 +110,7 @@ public class RemoteRssFragment extends Fragment {
// Show/hide a nice message if there are no items to show
if (remoteRssItems.size() > 0) {
remoteRssStatusMessage.setVisibility(View.GONE);
}
else {
} else {
remoteRssStatusMessage.setVisibility(View.VISIBLE);
remoteRssStatusMessage.setText(R.string.remoterss_no_files);
}

1
app/src/main/java/org/transdroid/core/gui/remoterss/RemoteRssItemView.java

@ -28,6 +28,7 @@ import org.transdroid.core.gui.remoterss.data.RemoteRssItem; @@ -28,6 +28,7 @@ import org.transdroid.core.gui.remoterss.data.RemoteRssItem;
/**
* View that represents some {@link RemoteRssItem} object.
*
* @author Twig
*/
@EViewGroup(R.layout.list_item_remoterssitem)

3
app/src/main/java/org/transdroid/core/gui/remoterss/RemoteRssItemsAdapter.java

@ -40,8 +40,7 @@ public class RemoteRssItemsAdapter extends BaseAdapter { @@ -40,8 +40,7 @@ public class RemoteRssItemsAdapter extends BaseAdapter {
if (convertView == null) {
itemView = RemoteRssItemView_.build(context);
}
else {
} else {
itemView = (RemoteRssItemView) convertView;
}

151
app/src/main/java/org/transdroid/core/gui/rss/RssFeedsActivity.java

@ -22,17 +22,18 @@ import android.net.Uri; @@ -22,17 +22,18 @@ import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.os.Parcel;
import android.text.TextUtils;
import android.view.View;
import android.view.ViewGroup;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import com.google.android.material.tabs.TabLayout;
import androidx.viewpager.widget.PagerAdapter;
import androidx.viewpager.widget.ViewPager;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar;
import android.text.TextUtils;
import android.view.View;
import android.view.ViewGroup;
import androidx.viewpager.widget.PagerAdapter;
import androidx.viewpager.widget.ViewPager;
import com.google.android.material.tabs.TabLayout;
import com.nispok.snackbar.Snackbar;
import com.nispok.snackbar.SnackbarManager;
import com.nispok.snackbar.enums.SnackbarType;
@ -71,22 +72,19 @@ import org.transdroid.daemon.task.DaemonTaskSuccessResult; @@ -71,22 +72,19 @@ import org.transdroid.daemon.task.DaemonTaskSuccessResult;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Collections;
import java.util.Comparator;
import java.util.Date;
import java.util.List;
@EActivity(R.layout.activity_rssfeeds)
public class RssFeedsActivity extends AppCompatActivity {
protected static final int RSS_FEEDS_LOCAL = 0;
protected static final int RSS_FEEDS_REMOTE = 1;
// Settings and local data
@Bean
protected Log log;
@Bean
protected ApplicationSettings applicationSettings;
protected static final int RSS_FEEDS_LOCAL = 0;
protected static final int RSS_FEEDS_REMOTE = 1;
@FragmentById(R.id.rssfeeds_fragment)
protected RssFeedsFragment fragmentLocalFeeds;
@FragmentById(R.id.rssitems_fragment)
@ -111,62 +109,6 @@ public class RssFeedsActivity extends AppCompatActivity { @@ -111,62 +109,6 @@ public class RssFeedsActivity extends AppCompatActivity {
@Bean
protected ConnectivityHelper connectivityHelper;
protected class LayoutPagerAdapter extends PagerAdapter {
boolean hasRemoteRss;
String serverName;
public LayoutPagerAdapter(boolean hasRemoteRss, String name) {
super();
this.hasRemoteRss = hasRemoteRss;
this.serverName = (name.length() > 0 ? name : getString(R.string.navigation_rss_tabs_remote));
}
@NonNull
@Override
public Object instantiateItem(@NonNull ViewGroup container, int position) {
int resId = 0;
if (position == RSS_FEEDS_LOCAL) {
resId = R.id.layout_rssfeeds_local;
}
else if (position == RSS_FEEDS_REMOTE) {
resId = R.id.layout_rss_feeds_remote;
}
return findViewById(resId);
}
@Override
public int getCount() {
return (this.hasRemoteRss ? 2 : 1);
}
@Override
public boolean isViewFromObject(@NonNull View view, @NonNull Object o) {
return (view == o);
}
@Override
public void destroyItem(@NonNull ViewGroup container, int position, @NonNull Object object) {
container.removeView((View) object);
}
@Nullable
@Override
public CharSequence getPageTitle(int position) {
switch (position) {
case RSS_FEEDS_LOCAL:
return getString(R.string.navigation_rss_tabs_local);
case RSS_FEEDS_REMOTE:
return this.serverName;
}
return super.getPageTitle(position);
}
}
@Override
public void onCreate(Bundle savedInstanceState) {
SettingsUtils.applyDayNightTheme(this);
@ -196,7 +138,8 @@ public class RssFeedsActivity extends AppCompatActivity { @@ -196,7 +138,8 @@ public class RssFeedsActivity extends AppCompatActivity {
try {
hasRemoteFeeds = remoteConnection.getRemoteRssChannels(log).size() > 0;
} catch (DaemonException e) {}
} catch (DaemonException ignored) {
}
if (hasRemoteFeeds) {
defaultTab = RSS_FEEDS_REMOTE;
@ -234,6 +177,7 @@ public class RssFeedsActivity extends AppCompatActivity { @@ -234,6 +177,7 @@ public class RssFeedsActivity extends AppCompatActivity {
/**
* Performs the loading of the RSS feed content and parsing of items, in a background thread.
*
* @param loader The RSS feed loader for which to retrieve the contents
*/
@Background
@ -253,6 +197,7 @@ public class RssFeedsActivity extends AppCompatActivity { @@ -253,6 +197,7 @@ public class RssFeedsActivity extends AppCompatActivity {
/**
* Stores the retrieved RSS feed content channel into the loader and updates the RSS feed in the feeds list fragment.
*
* @param loader The RSS feed loader that was executed
* @param channel The data that was retrieved, or null if it could not be parsed
* @param hasError True if a connection error occurred in the loading of the feed; false otherwise
@ -267,6 +212,7 @@ public class RssFeedsActivity extends AppCompatActivity { @@ -267,6 +212,7 @@ public class RssFeedsActivity extends AppCompatActivity {
/**
* Opens an RSS feed in the dedicated fragment (if there was space in the UI) or a new {@link RssItemsActivity}. Optionally this also registers in
* the user preferences that the feed was now viewed, so that in the future the new items can be properly marked.
*
* @param loader The RSS feed loader (with settings and the loaded content channel) to show
* @param markAsViewedNow True if the user settings should be updated to reflect this feed's last viewed date; false otherwise
*/
@ -332,7 +278,7 @@ public class RssFeedsActivity extends AppCompatActivity { @@ -332,7 +278,7 @@ public class RssFeedsActivity extends AppCompatActivity {
IDaemonAdapter currentConnection = this.getCurrentConnection();
// remote rss not supported for this connection type
if (currentConnection instanceof RemoteRssSupplier == false) {
if (!(currentConnection instanceof RemoteRssSupplier)) {
return;
}
@ -354,12 +300,8 @@ public class RssFeedsActivity extends AppCompatActivity { @@ -354,12 +300,8 @@ public class RssFeedsActivity extends AppCompatActivity {
}
// Sort by -newest
Collections.sort(recentItems, new Comparator<RemoteRssItem>() {
@Override
public int compare(RemoteRssItem lhs, RemoteRssItem rhs) {
return rhs.getTimestamp().compareTo(lhs.getTimestamp());
}
});
Collections.sort(recentItems, (lhs, rhs) ->
rhs.getTimestamp().compareTo(lhs.getTimestamp()));
} catch (DaemonException e) {
onCommunicationError(e);
return;
@ -374,20 +316,17 @@ public class RssFeedsActivity extends AppCompatActivity { @@ -374,20 +316,17 @@ public class RssFeedsActivity extends AppCompatActivity {
@UiThread
protected void onCommunicationError(DaemonException daemonException) {
//noinspection ThrowableResultOfMethodCallIgnored
log.i(this, daemonException.toString());
String error = getString(LocalTorrent.getResourceForDaemonException(daemonException));
SnackbarManager.show(Snackbar.with(this).text(error).colorResource(R.color.red).type(SnackbarType.MULTI_LINE));
}
public void onFeedSelected(int position) {
selectedFilter = position;
if (position == 0) {
fragmentRemoteFeeds.updateRemoteItems(recentItems, true);
}
else {
} else {
RemoteRssChannel channel = feeds.get(selectedFilter - 1);
fragmentRemoteFeeds.updateRemoteItems(channel.getItems(), true);
}
@ -439,4 +378,58 @@ public class RssFeedsActivity extends AppCompatActivity { @@ -439,4 +378,58 @@ public class RssFeedsActivity extends AppCompatActivity {
fragmentRemoteFeeds.updateChannelFilters(feedLabels);
}
protected class LayoutPagerAdapter extends PagerAdapter {
boolean hasRemoteRss;
String serverName;
public LayoutPagerAdapter(boolean hasRemoteRss, String name) {
super();
this.hasRemoteRss = hasRemoteRss;
this.serverName = (name.length() > 0 ? name : getString(R.string.navigation_rss_tabs_remote));
}
@NonNull
@Override
public Object instantiateItem(@NonNull ViewGroup container, int position) {
int resId = 0;
if (position == RSS_FEEDS_LOCAL) {
resId = R.id.layout_rssfeeds_local;
} else if (position == RSS_FEEDS_REMOTE) {
resId = R.id.layout_rss_feeds_remote;
}
return findViewById(resId);
}
@Override
public int getCount() {
return (this.hasRemoteRss ? 2 : 1);
}
@Override
public boolean isViewFromObject(@NonNull View view, @NonNull Object o) {
return (view == o);
}
@Override
public void destroyItem(@NonNull ViewGroup container, int position, @NonNull Object object) {
container.removeView((View) object);
}
@Nullable
@Override
public CharSequence getPageTitle(int position) {
switch (position) {
case RSS_FEEDS_LOCAL:
return getString(R.string.navigation_rss_tabs_local);
case RSS_FEEDS_REMOTE:
return this.serverName;
}
return super.getPageTitle(position);
}
}
}

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

@ -16,13 +16,14 @@ @@ -16,13 +16,14 @@
*/
package org.transdroid.core.gui.rss;
import androidx.fragment.app.Fragment;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.ListView;
import android.widget.TextView;
import androidx.fragment.app.Fragment;
import org.androidannotations.annotations.AfterViews;
import org.androidannotations.annotations.Bean;
import org.androidannotations.annotations.EFragment;
@ -37,6 +38,7 @@ import java.util.List; @@ -37,6 +38,7 @@ import java.util.List;
/**
* Fragment lists the RSS feeds the user wants to monitor and, if room, the list of items in a feed in a right pane.
*
* @author Eric Kok
*/
@EFragment(R.layout.fragment_rssfeeds)

1
app/src/main/java/org/transdroid/core/gui/rss/RssItemsActivity.java

@ -20,6 +20,7 @@ import android.annotation.TargetApi; @@ -20,6 +20,7 @@ import android.annotation.TargetApi;
import android.content.Intent;
import android.os.Build;
import android.os.Bundle;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar;

15
app/src/main/java/org/transdroid/core/gui/rss/RssItemsFragment.java

@ -23,8 +23,6 @@ import android.content.ClipboardManager; @@ -23,8 +23,6 @@ import android.content.ClipboardManager;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import androidx.fragment.app.Fragment;
import androidx.appcompat.app.AppCompatActivity;
import android.text.TextUtils;
import android.view.ActionMode;
import android.view.Menu;
@ -35,6 +33,9 @@ import android.widget.ListView; @@ -35,6 +33,9 @@ import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;
import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.Fragment;
import com.nispok.snackbar.Snackbar;
import com.nispok.snackbar.SnackbarManager;
@ -57,6 +58,7 @@ import java.util.List; @@ -57,6 +58,7 @@ import java.util.List;
/**
* Fragment that lists the items in a specific RSS feed
*
* @author Eric Kok
*/
@EFragment(R.layout.fragment_rssitems)
@ -75,6 +77,10 @@ public class RssItemsFragment extends Fragment { @@ -75,6 +77,10 @@ public class RssItemsFragment extends Fragment {
// Views
@ViewById(R.id.rssitems_list)
protected ListView rssItemsList;
@Bean
protected RssitemsAdapter rssitemsAdapter;
@ViewById
protected TextView emptyText;
private MultiChoiceModeListener onItemsSelected = new MultiChoiceModeListener() {
SelectionManagerMode selectionManagerMode;
@ -180,10 +186,6 @@ public class RssItemsFragment extends Fragment { @@ -180,10 +186,6 @@ public class RssItemsFragment extends Fragment {
}
};
@Bean
protected RssitemsAdapter rssitemsAdapter;
@ViewById
protected TextView emptyText;
@AfterViews
protected void init() {
@ -197,6 +199,7 @@ public class RssItemsFragment extends Fragment { @@ -197,6 +199,7 @@ public class RssItemsFragment extends Fragment {
/**
* Update the shown RSS items in the list.
*
* @param channel The loaded RSS content channel object
* @param hasError True if there were errors in loading the channel, in which case an error text is shown; false otherwise
* @param requiresExternalAuthentication Whether this RSS feed requires external authentication and should thus be redirected to a browser

13
app/src/main/java/org/transdroid/core/gui/rss/RssfeedLoader.java

@ -21,13 +21,13 @@ import org.transdroid.core.rssparser.Channel; @@ -21,13 +21,13 @@ import org.transdroid.core.rssparser.Channel;
import org.transdroid.core.rssparser.Item;
import java.util.Collections;
import java.util.Comparator;
import java.util.Date;
import java.util.List;
/**
* A container class that holds RSS feed settings and, after they have been retrieved, the contents as {@link Channel}, the number of new items and an
* indication of a connection error.
*
* @author Eric Kok
*/
public class RssfeedLoader {
@ -55,17 +55,13 @@ public class RssfeedLoader { @@ -55,17 +55,13 @@ public class RssfeedLoader {
Date pubDate = channel.getItems().get(0).getPubdate();
usePublishDate = pubDate != null && pubDate.getTime() > 0;
}
newCount = 0;
if (usePublishDate) {
// Count the number of new items, based on the date that this RSS feed was last viewed by the user
newCount = 0;
List<Item> items = channel.getItems();
// Reverse-order sort the items on their published date
Collections.sort(items, new Comparator<Item>() {
@Override
public int compare(Item lhs, Item rhs) {
return 0 - lhs.getPubdate().compareTo(rhs.getPubdate());
}
});
Collections.sort(items, (lhs, rhs) ->
-lhs.getPubdate().compareTo(rhs.getPubdate()));
for (Item item : items) {
if (item.getPubdate() == null || setting.getLastViewed() == null || item.getPubdate().after(setting.getLastViewed())) {
newCount++;
@ -76,7 +72,6 @@ public class RssfeedLoader { @@ -76,7 +72,6 @@ public class RssfeedLoader {
}
} else {
// Use the url of the last RSS item the last time the feed was viewed by the user to count new items
newCount = 0;
boolean isNew = true;
for (Item item : channel.getItems()) {
if (item.getTheLink() != null && setting.getLastViewedItemUrl() != null && item.getTheLink().equals(setting.getLastViewedItemUrl())) {

1
app/src/main/java/org/transdroid/core/gui/rss/RssfeedView.java

@ -33,6 +33,7 @@ import org.transdroid.core.gui.navigation.NavigationHelper; @@ -33,6 +33,7 @@ import org.transdroid.core.gui.navigation.NavigationHelper;
/**
* View that represents some {@link RssfeedSetting} object and displays name as well as loads a favicon for the feed's site and can load how many new
* items are available.
*
* @author Eric Kok
*/
@EViewGroup(R.layout.list_item_rssfeed)

5
app/src/main/java/org/transdroid/core/gui/rss/RssfeedsAdapter.java

@ -29,18 +29,19 @@ import java.util.List; @@ -29,18 +29,19 @@ import java.util.List;
/**
* Adapter that contains a list of {@link RssfeedSetting}s, each with associated loaded RSS feed {@link org.transdroid.core.rssparser.Channel}.
*
* @author Eric Kok
*/
@EBean
public class RssfeedsAdapter extends BaseAdapter {
private List<RssfeedLoader> loaders = null;
@RootContext
protected Context context;
private List<RssfeedLoader> loaders = null;
/**
* Allows updating the full internal list of feed loaders at once, replacing the old list
*
* @param loaders The new list of RSS feed loader objects, which pair settings and a loaded channel
*/
public void update(List<RssfeedLoader> loaders) {

5
app/src/main/java/org/transdroid/core/gui/rss/RssitemStatusLayout.java

@ -28,6 +28,7 @@ import org.transdroid.R; @@ -28,6 +28,7 @@ import org.transdroid.R;
/**
* A relative layout that that is checkable (to be used in a contextual action bar) and shows a coloured bar in the far left indicating the view
* status, that is, if the item is new to the user or was viewed earlier.
*
* @author Eric Kok
*/
public class RssitemStatusLayout extends RelativeLayout {
@ -65,9 +66,7 @@ public class RssitemStatusLayout extends RelativeLayout { @@ -65,9 +66,7 @@ public class RssitemStatusLayout extends RelativeLayout {
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
int height = getHeight();
int width = WIDTH;
fullRect.set(0, 0, width, height);
fullRect.set(0, 0, WIDTH, getHeight());
if (isNew == null) {
return;

1
app/src/main/java/org/transdroid/core/gui/rss/RssitemView.java

@ -27,6 +27,7 @@ import org.transdroid.core.rssparser.Item; @@ -27,6 +27,7 @@ import org.transdroid.core.rssparser.Item;
/**
* View that represents some {@link Item} object, which is a single item in some RSS feed.
*
* @author Eric Kok
*/
@EViewGroup(R.layout.list_item_rssitem)

5
app/src/main/java/org/transdroid/core/gui/rss/RssitemsAdapter.java

@ -28,18 +28,19 @@ import org.transdroid.core.rssparser.Item; @@ -28,18 +28,19 @@ import org.transdroid.core.rssparser.Item;
/**
* Adapter that contains a list of {@link Item}s in an RSS feed.
*
* @author Eric Kok
*/
@EBean
public class RssitemsAdapter extends BaseAdapter {
private Channel rssfeed = null;
@RootContext
protected Context context;
private Channel rssfeed = null;
/**
* Allows updating the full RSS feed (channel and contained items), replacing the old data
*
* @param rssfeed The new RSS feed contents
*/
public void update(Channel rssfeed) {

11
app/src/main/java/org/transdroid/core/gui/search/BarcodeHelper.java

@ -20,8 +20,6 @@ import android.annotation.SuppressLint; @@ -20,8 +20,6 @@ import android.annotation.SuppressLint;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import android.content.Intent;
import android.net.Uri;
@ -38,6 +36,7 @@ public class BarcodeHelper { @@ -38,6 +36,7 @@ public class BarcodeHelper {
/**
* Call this to start a bar code scanner intent. The calling activity will receive an Intent result with the given
* request code.
*
* @param activity The calling activity, to which the result is returned or a dialog is bound that asks to install
* the bar code scanner
* @param requestCode {@link #ACTIVITY_BARCODE_QRSETTINGS}
@ -51,6 +50,7 @@ public class BarcodeHelper { @@ -51,6 +50,7 @@ public class BarcodeHelper {
* Call this to share content encoded in a QR code, specially used to share settings. The calling activity will
* receive an Intent result with ID {@link #ACTIVITY_BARCODE_QRSETTINGS}. From there the returned intent will
* contain the data as SCAN_RESULT String extra.
*
* @param activity The calling activity, to which the result is returned or a dialog is bound that asks to install
* the bar code scanner
* @param content The content to share, that is, the raw data (Transdroid settings encoded as JSON data structure)
@ -71,15 +71,12 @@ public class BarcodeHelper { @@ -71,15 +71,12 @@ public class BarcodeHelper {
activity.startActivityForResult(intent, requestCode);
} catch (Exception e) {
// Can't start the bar code scanner, for example with a SecurityException or when ZXing is not present
final WeakReference<Context> intentStartContext = new WeakReference<Context>(activity);
final WeakReference<Context> intentStartContext = new WeakReference<>(activity);
new AlertDialog.Builder(activity).setIcon(android.R.drawable.ic_dialog_alert)
.setMessage(activity.getString(R.string.search_barcodescannernotfound))
.setPositiveButton(android.R.string.yes, new OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
.setPositiveButton(android.R.string.yes, (dialog, which) -> {
if (intentStartContext.get() != null)
intentStartContext.get().startActivity(new Intent(Intent.ACTION_VIEW, SCANNER_MARKET_URI));
}
}).setNegativeButton(android.R.string.no, null).show();
}
}

14
app/src/main/java/org/transdroid/core/gui/search/FilePickerHelper.java

@ -16,17 +16,15 @@ @@ -16,17 +16,15 @@
*/
package org.transdroid.core.gui.search;
import org.transdroid.R;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import android.content.Intent;
import android.net.Uri;
import org.transdroid.R;
import java.lang.ref.WeakReference;
public class FilePickerHelper {
@ -37,6 +35,7 @@ public class FilePickerHelper { @@ -37,6 +35,7 @@ public class FilePickerHelper {
/**
* Call this to start a file picker intent. The calling activity will receive an Intent result with ID
* {@link #ACTIVITY_FILEPICKER} with an Intent that contains the selected local file as data Intent.
*
* @param activity The calling activity, to which the result is returned or a dialog is bound that asks to install
* the file picker
*/
@ -52,15 +51,12 @@ public class FilePickerHelper { @@ -52,15 +51,12 @@ public class FilePickerHelper {
activity.startActivityForResult(new Intent("org.openintents.action.PICK_FILE"), ACTIVITY_FILEPICKER);
} catch (Exception e2) {
// Can't start the file manager, for example with a SecurityException or when IO File Manager is not present
final WeakReference<Context> intentStartContext = new WeakReference<Context>(activity);
final WeakReference<Context> intentStartContext = new WeakReference<>(activity);
new AlertDialog.Builder(activity).setIcon(android.R.drawable.ic_dialog_alert)
.setMessage(activity.getString(R.string.search_filemanagernotfound))
.setPositiveButton(android.R.string.yes, new OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
.setPositiveButton(android.R.string.yes, (dialog, which) -> {
if (intentStartContext.get() != null)
intentStartContext.get().startActivity(new Intent(Intent.ACTION_VIEW, FILEMANAGER_MARKET_URI));
}
}).setNegativeButton(android.R.string.no, null).show();
}
}

62
app/src/main/java/org/transdroid/core/gui/search/SearchActivity.java

@ -23,9 +23,6 @@ import android.net.Uri; @@ -23,9 +23,6 @@ import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.provider.SearchRecentSuggestions;
import androidx.core.view.MenuItemCompat;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
@ -36,6 +33,9 @@ import android.widget.SearchView; @@ -36,6 +33,9 @@ import android.widget.SearchView;
import android.widget.Spinner;
import android.widget.TextView;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar;
import org.androidannotations.annotations.AfterViews;
import org.androidannotations.annotations.Bean;
import org.androidannotations.annotations.EActivity;
@ -58,6 +58,7 @@ import java.util.List; @@ -58,6 +58,7 @@ import java.util.List;
/**
* An activity that shows search results to the user (after a query was supplied by the standard Android search manager) and either shows the list of
* search sites on the left (e.g. on tablets) or allows switching between search sites via the action bar spinner.
*
* @author Eric Kok
*/
@EActivity(R.layout.activity_search)
@ -85,6 +86,25 @@ public class SearchActivity extends AppCompatActivity { @@ -85,6 +86,25 @@ public class SearchActivity extends AppCompatActivity {
private List<SearchSetting> searchSites;
private SearchSetting lastUsedSite;
private String lastUsedQuery;
private OnItemClickListener onSearchSiteClicked = new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
lastUsedSite = searchSites.get(position);
refreshSearch();
}
};
private AdapterView.OnItemSelectedListener onSearchSiteSelected = new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
lastUsedSite = searchSites.get(position);
refreshSearch();
}
@Override
public void onNothingSelected(AdapterView<?> parent) {
}
};
@Override
public void onCreate(Bundle savedInstanceState) {
@ -96,12 +116,8 @@ public class SearchActivity extends AppCompatActivity { @@ -96,12 +116,8 @@ public class SearchActivity extends AppCompatActivity {
protected void init() {
searchToolbar.setNavigationIcon(R.drawable.abc_ic_ab_back_material);
searchToolbar.setNavigationOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
TorrentsActivity_.intent(SearchActivity.this).flags(Intent.FLAG_ACTIVITY_CLEAR_TOP).start();
}
});
searchToolbar.setNavigationOnClickListener(v ->
TorrentsActivity_.intent(SearchActivity.this).flags(Intent.FLAG_ACTIVITY_CLEAR_TOP).start());
setSupportActionBar(searchToolbar);
// Get the user query, as coming from the standard SearchManager
@ -172,7 +188,7 @@ public class SearchActivity extends AppCompatActivity { @@ -172,7 +188,7 @@ public class SearchActivity extends AppCompatActivity {
searchView.setQueryRefinementEnabled(true);
searchView.setIconified(false);
searchView.setIconifiedByDefault(false);
MenuItemCompat.setActionView(item, searchView);
item.setActionView(searchView);
searchMenu = item;
final MenuItem sortBySeeders = menu.findItem(R.id.action_sort_seeders);
final MenuItem sortByAdded = menu.findItem(R.id.action_sort_added);
@ -197,9 +213,9 @@ public class SearchActivity extends AppCompatActivity { @@ -197,9 +213,9 @@ public class SearchActivity extends AppCompatActivity {
searchsitesList.setVisibility(searchInstalled ? View.VISIBLE : View.GONE);
}
if (searchInstalled) {
getFragmentManager().beginTransaction().show(fragmentResults).commit();
getSupportFragmentManager().beginTransaction().show(fragmentResults).commit();
} else {
getFragmentManager().beginTransaction().hide(fragmentResults).commit();
getSupportFragmentManager().beginTransaction().hide(fragmentResults).commit();
}
installmoduleText.setVisibility(searchInstalled ? View.GONE : View.VISIBLE);
@ -208,6 +224,7 @@ public class SearchActivity extends AppCompatActivity { @@ -208,6 +224,7 @@ public class SearchActivity extends AppCompatActivity {
@Override
protected void onNewIntent(Intent intent) {
super.onNewIntent(intent);
handleIntent(intent);
refreshSearch();
}
@ -236,28 +253,9 @@ public class SearchActivity extends AppCompatActivity { @@ -236,28 +253,9 @@ public class SearchActivity extends AppCompatActivity {
return true;
}
private OnItemClickListener onSearchSiteClicked = new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
lastUsedSite = searchSites.get(position);
refreshSearch();
}
};
private AdapterView.OnItemSelectedListener onSearchSiteSelected = new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
lastUsedSite = searchSites.get(position);
refreshSearch();
}
@Override
public void onNothingSelected(AdapterView<?> parent) {
}
};
/**
* Extracts the query string from the search {@link Intent}
*
* @return The query string that was entered by the user
*/
private String parseQuery(Intent intent) {

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

@ -24,6 +24,7 @@ import org.transdroid.BuildConfig; @@ -24,6 +24,7 @@ import org.transdroid.BuildConfig;
/**
* Provides search suggestions by simply returning previous user entries.
*
* @author Eric Kok
*/
public class SearchHistoryProvider extends SearchRecentSuggestionsProvider {

11
app/src/main/java/org/transdroid/core/gui/search/SearchResultView.java

@ -16,18 +16,19 @@ @@ -16,18 +16,19 @@
*/
package org.transdroid.core.gui.search;
import org.androidannotations.annotations.EViewGroup;
import org.androidannotations.annotations.ViewById;
import org.transdroid.R;
import org.transdroid.core.app.search.SearchResult;
import android.content.Context;
import android.text.format.DateUtils;
import android.widget.RelativeLayout;
import android.widget.TextView;
import org.androidannotations.annotations.EViewGroup;
import org.androidannotations.annotations.ViewById;
import org.transdroid.R;
import org.transdroid.core.app.search.SearchResult;
/**
* View that represents a {@link SearchResult} object from an in-app search
*
* @author Eric Kok
*/
@EViewGroup(resName = "list_item_searchresult")

5
app/src/main/java/org/transdroid/core/gui/search/SearchResultsAdapter.java

@ -29,18 +29,19 @@ import java.util.List; @@ -29,18 +29,19 @@ import java.util.List;
/**
* Adapter that contains a list of {@link SearchResult}s.
*
* @author Eric Kok
*/
@EBean
public class SearchResultsAdapter extends BaseAdapter {
private List<SearchResult> results = null;
@RootContext
protected Context context;
private List<SearchResult> results = null;
/**
* Allows updating the search results, replacing the old data
*
* @param results The new list of search results
*/
public void update(List<SearchResult> results) {

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

@ -16,11 +16,9 @@ @@ -16,11 +16,9 @@
*/
package org.transdroid.core.gui.search;
import android.app.Fragment;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import androidx.appcompat.app.AppCompatActivity;
import android.text.TextUtils;
import android.view.ActionMode;
import android.view.Menu;
@ -32,6 +30,9 @@ import android.widget.ProgressBar; @@ -32,6 +30,9 @@ import android.widget.ProgressBar;
import android.widget.TextView;
import android.widget.Toast;
import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.Fragment;
import com.nispok.snackbar.Snackbar;
import com.nispok.snackbar.SnackbarManager;
@ -48,7 +49,6 @@ import org.transdroid.core.app.search.SearchHelper; @@ -48,7 +49,6 @@ import org.transdroid.core.app.search.SearchHelper;
import org.transdroid.core.app.search.SearchHelper.SearchSortOrder;
import org.transdroid.core.app.search.SearchResult;
import org.transdroid.core.app.search.SearchSite;
import org.transdroid.core.app.settings.SystemSettings_;
import org.transdroid.core.gui.TorrentsActivity_;
import org.transdroid.core.gui.navigation.NavigationHelper_;
import org.transdroid.core.gui.navigation.SelectionManagerMode;
@ -58,6 +58,7 @@ import java.util.List; @@ -58,6 +58,7 @@ import java.util.List;
/**
* Fragment that lists the items in a specific RSS feed
*
* @author Eric Kok
*/
@EFragment(R.layout.fragment_searchresults)
@ -79,74 +80,6 @@ public class SearchResultsFragment extends Fragment { @@ -79,74 +80,6 @@ public class SearchResultsFragment extends Fragment {
protected TextView emptyText;
@ViewById
protected ProgressBar loadingProgress;
@AfterViews
protected void init() {
// On large screens where this fragment is shown next to the sites list; we show a continues grey vertical line
// to separate the lists visually
if (!NavigationHelper_.getInstance_(getActivity()).isSmallScreen()) {
resultsList.setBackgroundResource(R.drawable.details_list_background);
}
// Set up the list adapter, which allows multi-select
resultsList.setAdapter(resultsAdapter);
resultsList.setMultiChoiceModeListener(onItemsSelected);
if (results != null) {
showResults();
}
}
public void startSearch(String query, SearchSite site, SearchSortOrder sortBy) {
loadingProgress.setVisibility(View.VISIBLE);
resultsList.setVisibility(View.GONE);
emptyText.setVisibility(View.GONE);
performSearch(query, site, sortBy);
}
@Background
protected void performSearch(String query, SearchSite site, SearchSortOrder sortBy) {
results = searchHelper.search(query, site, sortBy);
resultsSource = site.isPrivate() ? site.getKey() : null;
showResults();
}
@UiThread
protected void showResults() {
loadingProgress.setVisibility(View.GONE);
if (results == null || results.size() == 0) {
resultsList.setVisibility(View.GONE);
emptyText.setVisibility(View.VISIBLE);
return;
}
resultsAdapter.update(results);
resultsList.setVisibility(View.VISIBLE);
emptyText.setVisibility(View.GONE);
}
public void clearResults() {
loadingProgress.setVisibility(View.GONE);
resultsList.setVisibility(View.GONE);
emptyText.setVisibility(View.VISIBLE);
}
@ItemClick(R.id.searchresults_list)
protected void onItemClicked(SearchResult item) {
if (item.getTorrentUrl() == null) {
SnackbarManager.show(Snackbar.with(getActivity()).text(R.string.error_notorrentfile).colorResource(R.color.red));
return;
}
// Don't broadcast this intent; we can safely assume this is intended for Transdroid only
Intent i = TorrentsActivity_.intent(getActivity()).get();
i.setData(Uri.parse(item.getTorrentUrl()));
i.putExtra("TORRENT_TITLE", item.getName());
if (resultsSource != null) {
i.putExtra("PRIVATE_SOURCE", resultsSource);
}
startActivity(i);
}
private MultiChoiceModeListener onItemsSelected = new MultiChoiceModeListener() {
SelectionManagerMode selectionManagerMode;
@ -169,7 +102,7 @@ public class SearchResultsFragment extends Fragment { @@ -169,7 +102,7 @@ public class SearchResultsFragment extends Fragment {
public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
// Get checked torrents
List<SearchResult> checked = new ArrayList<SearchResult>();
List<SearchResult> checked = new ArrayList<>();
for (int i = 0; i < resultsList.getCheckedItemPositions().size(); i++) {
if (resultsList.getCheckedItemPositions().valueAt(i)) {
checked.add(resultsAdapter.getItem(resultsList.getCheckedItemPositions().keyAt(i)));
@ -224,4 +157,71 @@ public class SearchResultsFragment extends Fragment { @@ -224,4 +157,71 @@ public class SearchResultsFragment extends Fragment {
};
@AfterViews
protected void init() {
// On large screens where this fragment is shown next to the sites list; we show a continues grey vertical line
// to separate the lists visually
if (!NavigationHelper_.getInstance_(getActivity()).isSmallScreen()) {
resultsList.setBackgroundResource(R.drawable.details_list_background);
}
// Set up the list adapter, which allows multi-select
resultsList.setAdapter(resultsAdapter);
resultsList.setMultiChoiceModeListener(onItemsSelected);
if (results != null) {
showResults();
}
}
public void startSearch(String query, SearchSite site, SearchSortOrder sortBy) {
loadingProgress.setVisibility(View.VISIBLE);
resultsList.setVisibility(View.GONE);
emptyText.setVisibility(View.GONE);
performSearch(query, site, sortBy);
}
@Background
protected void performSearch(String query, SearchSite site, SearchSortOrder sortBy) {
results = searchHelper.search(query, site, sortBy);
resultsSource = site.isPrivate() ? site.getKey() : null;
showResults();
}
@UiThread
protected void showResults() {
loadingProgress.setVisibility(View.GONE);
if (results == null || results.size() == 0) {
resultsList.setVisibility(View.GONE);
emptyText.setVisibility(View.VISIBLE);
return;
}
resultsAdapter.update(results);
resultsList.setVisibility(View.VISIBLE);
emptyText.setVisibility(View.GONE);
}
public void clearResults() {
loadingProgress.setVisibility(View.GONE);
resultsList.setVisibility(View.GONE);
emptyText.setVisibility(View.VISIBLE);
}
@ItemClick(R.id.searchresults_list)
protected void onItemClicked(SearchResult item) {
if (item.getTorrentUrl() == null) {
SnackbarManager.show(Snackbar.with(getActivity()).text(R.string.error_notorrentfile).colorResource(R.color.red));
return;
}
// Don't broadcast this intent; we can safely assume this is intended for Transdroid only
Intent i = TorrentsActivity_.intent(getActivity()).get();
i.setData(Uri.parse(item.getTorrentUrl()));
i.putExtra("TORRENT_TITLE", item.getName());
if (resultsSource != null) {
i.putExtra("PRIVATE_SOURCE", resultsSource);
}
startActivity(i);
}
}

6
app/src/main/java/org/transdroid/core/gui/search/SearchSetting.java

@ -22,14 +22,16 @@ public interface SearchSetting extends SimpleListItem { @@ -22,14 +22,16 @@ public interface SearchSetting extends SimpleListItem {
/**
* Should return a unique key for this search setting, so that it can be compared (using equals()) to other settings.
*
* @return A unique string identifying this search setting
*/
public String getKey();
String getKey();
/**
* Should return an URL (which may still be abstract and not the actual search URL) specific to the search site
*
* @return A clean URL directing to the search site, to, for example, get the favicon of the site
*/
public String getBaseUrl();
String getBaseUrl();
}

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

@ -26,6 +26,7 @@ import org.transdroid.R; @@ -26,6 +26,7 @@ import org.transdroid.R;
/**
* View that shows, as part of the action bar spinner, which {@link SearchSetting} is currently chosen.
*
* @author Eric Kok
*/
@EViewGroup(R.layout.actionbar_searchsite)

3
app/src/main/java/org/transdroid/core/gui/search/SearchSettingsDropDownAdapter.java

@ -27,6 +27,7 @@ import java.util.List; @@ -27,6 +27,7 @@ import java.util.List;
/**
* List adapter that holds search settings, that is, web searches and in-app search sites, displayed as content to a Spinner instead of a ListView.
*
* @author Eric Kok
*/
public class SearchSettingsDropDownAdapter extends FilterListItemAdapter {
@ -42,7 +43,7 @@ public class SearchSettingsDropDownAdapter extends FilterListItemAdapter { @@ -42,7 +43,7 @@ public class SearchSettingsDropDownAdapter extends FilterListItemAdapter {
public View getView(int position, View convertView, ViewGroup parent) {
// This returns the item to show in the action bar spinner
SearchSettingSelectionView filterItemView;
if (convertView == null || !(convertView instanceof SearchSettingSelectionView)) {
if (!(convertView instanceof SearchSettingSelectionView)) {
filterItemView = SearchSettingSelectionView_.build(context);
} else {
filterItemView = (SearchSettingSelectionView) convertView;

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

@ -31,6 +31,7 @@ import org.transdroid.core.gui.navigation.NavigationHelper; @@ -31,6 +31,7 @@ import org.transdroid.core.gui.navigation.NavigationHelper;
/**
* View that represents some {@link RssfeedSetting} object and displays name as well as loads a favicon for the feed's site and can load how many new
* items are available.
*
* @author Eric Kok
*/
@EViewGroup(R.layout.list_item_searchsite)

5
app/src/main/java/org/transdroid/core/gui/search/SearchSitesAdapter.java

@ -30,18 +30,19 @@ import java.util.List; @@ -30,18 +30,19 @@ import java.util.List;
/**
* Adapter that contains a list of {@link SearchSetting}s, either {@link SearchSite} or {@link WebsearchSetting}.
*
* @author Eric Kok
*/
@EBean
public class SearchSitesAdapter extends BaseAdapter {
private List<SearchSetting> sites = null;
@RootContext
protected Context context;
private List<SearchSetting> sites = null;
/**
* Allows updating the full internal list of sites at once, replacing the old list
*
* @param sites The new list of search sites, either in-app or web search settings
*/
public void update(List<SearchSetting> sites) {

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

@ -21,6 +21,7 @@ import android.content.Intent; @@ -21,6 +21,7 @@ import android.content.Intent;
/**
* Used to clean up text as received from a generic ACTION_SEND intent. This class is highly custom-based for known
* applications, i.e. the EXTRA_TEXT send by some known applications.
*
* @author Eric Kok
*/
public class SendIntentHelper {
@ -36,6 +37,7 @@ public class SendIntentHelper { @@ -36,6 +37,7 @@ public class SendIntentHelper {
/**
* Cleans a SEND intent text string by removing irrelevant parts, so that the remaining text can be used as search
* string. Typically deals with specific known applications such as Shazam and YouTube's SEND intents.
*
* @param intent The original SEND intent that was received
* @return A cleaned string to be used as search query
*/

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

@ -19,7 +19,6 @@ package org.transdroid.core.gui.search; @@ -19,7 +19,6 @@ package org.transdroid.core.gui.search;
import android.content.ClipboardManager;
import android.content.Context;
import android.net.Uri;
import android.text.InputType;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
@ -36,6 +35,7 @@ public class UrlEntryDialog { @@ -36,6 +35,7 @@ public class UrlEntryDialog {
/**
* Opens a dialog that allows entry of a single URL string, which (on confirmation) will be supplied to the calling activity's {@link
* TorrentsActivity#addTorrentByUrl(String, String) method}.
*
* @param activity The activity that opens (and owns) this dialog
*/
public static void show(final TorrentsActivity activity) {
@ -46,10 +46,11 @@ public class UrlEntryDialog { @@ -46,10 +46,11 @@ public class UrlEntryDialog {
CharSequence content = clipboard.getPrimaryClip().getItemAt(0).coerceToText(activity);
urlEdit.setText(content);
}
new MaterialDialog.Builder(activity).customView(inputLayout, false).positiveText(android.R.string.ok).negativeText(android.R.string.cancel)
.callback(new MaterialDialog.ButtonCallback() {
@Override
public void onPositive(MaterialDialog dialog) {
new MaterialDialog.Builder(activity)
.customView(inputLayout, false)
.positiveText(android.R.string.ok)
.negativeText(android.R.string.cancel)
.onPositive((dialog, which) -> {
String url = urlEdit.getText().toString();
Uri uri = Uri.parse(url);
if (!TextUtils.isEmpty(url)) {
@ -60,7 +61,6 @@ public class UrlEntryDialog { @@ -60,7 +61,6 @@ public class UrlEntryDialog {
activity.addTorrentByUrl(url, title);
}
}
}
}).show();
}

7
app/src/main/java/org/transdroid/core/gui/settings/AboutDialog.java

@ -16,15 +16,16 @@ @@ -16,15 +16,16 @@
*/
package org.transdroid.core.gui.settings;
import org.transdroid.R;
import org.transdroid.core.gui.navigation.DialogHelper;
import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import org.transdroid.R;
import org.transdroid.core.gui.navigation.DialogHelper;
/**
* Fragment that shows info about the application developer and used open source libraries.
*
* @author Eric Kok
*/
public class AboutDialog implements DialogHelper.DialogSpecification {

7
app/src/main/java/org/transdroid/core/gui/settings/ChangelogDialog.java

@ -16,15 +16,16 @@ @@ -16,15 +16,16 @@
*/
package org.transdroid.core.gui.settings;
import org.transdroid.R;
import org.transdroid.core.gui.navigation.DialogHelper;
import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import org.transdroid.R;
import org.transdroid.core.gui.navigation.DialogHelper;
/**
* Fragment that shows recent app changes.
*
* @author Eric Kok
*/
public class ChangelogDialog implements DialogHelper.DialogSpecification {

53
app/src/main/java/org/transdroid/core/gui/settings/HelpSettingsActivity.java

@ -51,6 +51,25 @@ public class HelpSettingsActivity extends PreferenceCompatActivity { @@ -51,6 +51,25 @@ public class HelpSettingsActivity extends PreferenceCompatActivity {
protected ErrorLogSender errorLogSender;
@Bean
protected SettingsPersistence settingsPersistence;
private OnPreferenceClickListener onSendLogClick = new OnPreferenceClickListener() {
@Override
public boolean onPreferenceClick(Preference preference) {
errorLogSender.collectAndSendLog(HelpSettingsActivity.this, applicationSettings.getLastUsedServer());
return true;
}
};
private OnPreferenceClickListener onInstallHelpClick = preference -> {
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(INSTALLHELP_URI)));
return true;
};
private OnPreferenceClickListener onChangeLogClick = preference -> {
showDialog(DIALOG_CHANGELOG);
return true;
};
private OnPreferenceClickListener onAboutClick = preference -> {
showDialog(DIALOG_ABOUT);
return true;
};
@Override
protected void onCreate(Bundle savedInstanceState) {
@ -75,40 +94,6 @@ public class HelpSettingsActivity extends PreferenceCompatActivity { @@ -75,40 +94,6 @@ public class HelpSettingsActivity extends PreferenceCompatActivity {
MainSettingsActivity_.intent(this).flags(Intent.FLAG_ACTIVITY_CLEAR_TOP).start();
}
private OnPreferenceClickListener onSendLogClick = new OnPreferenceClickListener() {
@Override
public boolean onPreferenceClick(Preference preference) {
errorLogSender.collectAndSendLog(HelpSettingsActivity.this, applicationSettings.getLastUsedServer());
return true;
}
};
private OnPreferenceClickListener onInstallHelpClick = new OnPreferenceClickListener() {
@Override
public boolean onPreferenceClick(Preference preference) {
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(INSTALLHELP_URI)));
return true;
}
};
private OnPreferenceClickListener onChangeLogClick = new OnPreferenceClickListener() {
@SuppressWarnings("deprecation")
@Override
public boolean onPreferenceClick(Preference preference) {
showDialog(DIALOG_CHANGELOG);
return true;
}
};
private OnPreferenceClickListener onAboutClick = new OnPreferenceClickListener() {
@SuppressWarnings("deprecation")
@Override
public boolean onPreferenceClick(Preference preference) {
showDialog(DIALOG_ABOUT);
return true;
}
};
protected Dialog onCreateDialog(int id) {
switch (id) {
case DIALOG_CHANGELOG:

22
app/src/main/java/org/transdroid/core/gui/settings/KeyBoundPreferencesActivity.java

@ -40,6 +40,7 @@ import java.util.Map; @@ -40,6 +40,7 @@ import java.util.Map;
* and then call initXPreference for each contained preference. {@link #onPreferencesChanged()} can be overridden to
* react to preference changes, e.g. when field availability should be updated (and where preference dependency isn't
* enough).
*
* @author Eric Kok
*/
@EActivity
@ -50,10 +51,15 @@ public abstract class KeyBoundPreferencesActivity extends PreferenceCompatActivi @@ -50,10 +51,15 @@ public abstract class KeyBoundPreferencesActivity extends PreferenceCompatActivi
private SharedPreferences sharedPrefs;
private Map<String, String> originalSummaries = new HashMap<>();
private OnSharedPreferenceChangeListener onPreferenceChangeListener = (sharedPreferences, key) -> {
showValueOnSummary(key);
onPreferencesChanged();
};
/**
* Should be called during the activity {@link #onCreate(android.os.Bundle)} (but after super.onCreate(Bundle)) to
* load the preferences for this screen from an XML resource.
*
* @param preferencesResId The XML resource to read preferences from, which may contain embedded
* {@link PreferenceScreen} objects
* @param currentMaxKey The value of what is currently the last defined settings object, or -1 of no settings were
@ -86,14 +92,6 @@ public abstract class KeyBoundPreferencesActivity extends PreferenceCompatActivi @@ -86,14 +92,6 @@ public abstract class KeyBoundPreferencesActivity extends PreferenceCompatActivi
onPreferenceChangeListener);
}
private OnSharedPreferenceChangeListener onPreferenceChangeListener = new OnSharedPreferenceChangeListener() {
@Override
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
showValueOnSummary(key);
onPreferencesChanged();
}
};
/**
* Key-bound preference activities may override this method if they want to react to preference changes.
*/
@ -103,6 +101,7 @@ public abstract class KeyBoundPreferencesActivity extends PreferenceCompatActivi @@ -103,6 +101,7 @@ public abstract class KeyBoundPreferencesActivity extends PreferenceCompatActivi
/**
* Updates a preference that allows for text entry via a dialog. This is used for both string and integer values. No
* default value will be shown.
*
* @param baseName The base name of the stored preference, e.g. item_name, which will then actually be stored under
* item_name_[key]
* @return The concrete {@link EditTextPreference} that is bound to this preference
@ -113,6 +112,7 @@ public abstract class KeyBoundPreferencesActivity extends PreferenceCompatActivi @@ -113,6 +112,7 @@ public abstract class KeyBoundPreferencesActivity extends PreferenceCompatActivi
/**
* Updates a preference that allows for text entry via a dialog. This is used for both string and integer values.
*
* @param baseName The base name of the stored preference, e.g. item_name, which will then actually be stored under
* item_name_[key]
* @param defValue The default value for this preference, as shown when no value was yet stored
@ -125,6 +125,7 @@ public abstract class KeyBoundPreferencesActivity extends PreferenceCompatActivi @@ -125,6 +125,7 @@ public abstract class KeyBoundPreferencesActivity extends PreferenceCompatActivi
/**
* Updates a preference (including dependency) that allows for text entry via a dialog. This is used for both string
* and integer values.
*
* @param baseName The base name of the stored preference, e.g. item_name, which will then actually be stored under
* item_name_[key]
* @param defValue The default value for this preference, as shown when no value was yet stored
@ -146,6 +147,7 @@ public abstract class KeyBoundPreferencesActivity extends PreferenceCompatActivi @@ -146,6 +147,7 @@ public abstract class KeyBoundPreferencesActivity extends PreferenceCompatActivi
/**
* Updates a preference that simply shows a check box. No default value will be shown.
*
* @param baseName The base name of the stored preference, e.g. item_name, which will then actually be stored under
* item_name_[key]
* @return The concrete {@link CheckBoxPreference} that is bound to this preference
@ -156,6 +158,7 @@ public abstract class KeyBoundPreferencesActivity extends PreferenceCompatActivi @@ -156,6 +158,7 @@ public abstract class KeyBoundPreferencesActivity extends PreferenceCompatActivi
/**
* Updates a preference that simply shows a check box.
*
* @param baseName The base name of the stored preference, e.g. item_name, which will then actually be stored under
* item_name_[key]
* @param defValue The default value for this preference, as shown when no value was yet stored
@ -167,6 +170,7 @@ public abstract class KeyBoundPreferencesActivity extends PreferenceCompatActivi @@ -167,6 +170,7 @@ public abstract class KeyBoundPreferencesActivity extends PreferenceCompatActivi
/**
* Updates a preference (including dependency) that simply shows a check box.
*
* @param baseName The base name of the stored preference, e.g. item_name, which will then actually be stored under
* item_name_[key]
* @param defValue The default value for this preference, as shown when no value was yet stored
@ -185,6 +189,7 @@ public abstract class KeyBoundPreferencesActivity extends PreferenceCompatActivi @@ -185,6 +189,7 @@ public abstract class KeyBoundPreferencesActivity extends PreferenceCompatActivi
/**
* Updates a preference that allows picking an item from a list. No default value will be shown.
*
* @param baseName The base name of the stored preference, e.g. item_name, which will then actually be stored under
* item_name_[key]
* @return The concrete {@link ListPreference} that is bound to this preference
@ -195,6 +200,7 @@ public abstract class KeyBoundPreferencesActivity extends PreferenceCompatActivi @@ -195,6 +200,7 @@ public abstract class KeyBoundPreferencesActivity extends PreferenceCompatActivi
/**
* Updates a preference that allows picking an item from a list.
*
* @param baseName The base name of the stored preference, e.g. item_name, which will then actually be stored under
* item_name_[key]
* @param defValue The default value for this preference, as shown when no value was yet stored

75
app/src/main/java/org/transdroid/core/gui/settings/MainSettingsActivity.java

@ -19,13 +19,13 @@ package org.transdroid.core.gui.settings; @@ -19,13 +19,13 @@ package org.transdroid.core.gui.settings;
import android.annotation.TargetApi;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import android.content.Intent;
import android.content.SharedPreferences;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import androidx.preference.ListPreference;
import androidx.preference.Preference;
import androidx.preference.Preference.OnPreferenceClickListener;
@ -55,6 +55,7 @@ import java.util.List; @@ -55,6 +55,7 @@ import java.util.List;
/**
* The main activity that provides access to all application settings. It shows the configured serves, web search sites and RSS feeds along with other
* general settings.
*
* @author Eric Kok
*/
@EActivity
@ -78,83 +79,44 @@ public class MainSettingsActivity extends PreferenceCompatActivity { @@ -78,83 +79,44 @@ public class MainSettingsActivity extends PreferenceCompatActivity {
return true;
}
};
private OnPreferenceClickListener onAddWebsearch = new OnPreferenceClickListener() {
@Override
public boolean onPreferenceClick(Preference preference) {
private OnPreferenceClickListener onAddWebsearch = preference -> {
WebsearchSettingsActivity_.intent(MainSettingsActivity.this).start();
return true;
}
};
private OnPreferenceClickListener onAddRssfeed = new OnPreferenceClickListener() {
@Override
public boolean onPreferenceClick(Preference preference) {
private OnPreferenceClickListener onAddRssfeed = preference -> {
RssfeedSettingsActivity_.intent(MainSettingsActivity.this).start();
return true;
}
};
private OnPreferenceClickListener onBackgroundSettings = new OnPreferenceClickListener() {
@Override
public boolean onPreferenceClick(Preference preference) {
private OnPreferenceClickListener onBackgroundSettings = preference -> {
NotificationSettingsActivity_.intent(MainSettingsActivity.this).start();
return true;
}
};
private OnPreferenceClickListener onSystemSettings = new OnPreferenceClickListener() {
@Override
public boolean onPreferenceClick(Preference preference) {
private OnPreferenceClickListener onSystemSettings = preference -> {
SystemSettingsActivity_.intent(MainSettingsActivity.this).start();
return true;
}
};
private OnPreferenceClickListener onHelpSettings = new OnPreferenceClickListener() {
@Override
public boolean onPreferenceClick(Preference preference) {
private OnPreferenceClickListener onHelpSettings = preference -> {
HelpSettingsActivity_.intent(MainSettingsActivity.this).start();
return true;
}
};
private OnPreferenceClickListener onDonate = new OnPreferenceClickListener() {
@Override
public boolean onPreferenceClick(Preference preference) {
private OnPreferenceClickListener onDonate = preference -> {
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(getString(R.string.donate_url))));
return true;
}
};
private OnServerClickedListener onServerClicked = new OnServerClickedListener() {
@Override
public void onServerClicked(ServerSetting serverSetting) {
ServerSettingsActivity_.intent(MainSettingsActivity.this).key(serverSetting.getOrder()).start();
}
};
private OnSeedboxClickedListener onSeedboxClicked = new OnSeedboxClickedListener() {
@Override
public void onSeedboxClicked(ServerSetting serverSetting, SeedboxProvider provider, int seedboxOffset) {
private OnServerClickedListener onServerClicked = serverSetting -> ServerSettingsActivity_.intent(MainSettingsActivity.this).key(serverSetting.getOrder()).start();
private OnSeedboxClickedListener onSeedboxClicked = (serverSetting, provider, seedboxOffset) -> {
// NOTE: The seedboxOffset is the seedbox type-unique order that we need to supply uin the Extras bundle to
// edit this specific seedbox
startActivity(provider.getSettings().getSettingsActivityIntent(MainSettingsActivity.this).putExtra("key", seedboxOffset));
}
};
private OnWebsearchClickedListener onWebsearchClicked = new OnWebsearchClickedListener() {
@Override
public void onWebsearchClicked(WebsearchSetting websearchSetting) {
WebsearchSettingsActivity_.intent(MainSettingsActivity.this).key(websearchSetting.getOrder()).start();
}
};
private OnRssfeedClickedListener onRssfeedClicked = new OnRssfeedClickedListener() {
@Override
public void onRssfeedClicked(RssfeedSetting rssfeedSetting) {
RssfeedSettingsActivity_.intent(MainSettingsActivity.this).key(rssfeedSetting.getOrder()).start();
}
};
private OnClickListener onAddSeedbox = new OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
private OnWebsearchClickedListener onWebsearchClicked = websearchSetting -> WebsearchSettingsActivity_.intent(MainSettingsActivity.this).key(websearchSetting.getOrder()).start();
private OnRssfeedClickedListener onRssfeedClicked = rssfeedSetting -> RssfeedSettingsActivity_.intent(MainSettingsActivity.this).key(rssfeedSetting.getOrder()).start();
private OnClickListener onAddSeedbox = (dialog, which) -> {
// Start the configuration activity for this specific chosen seedbox
if (which == 0)
ServerSettingsActivity_.intent(MainSettingsActivity.this).start();
else
startActivity(SeedboxProvider.values()[which - 1].getSettings().getSettingsActivityIntent(MainSettingsActivity.this));
}
};
@Override
@ -228,8 +190,8 @@ public class MainSettingsActivity extends PreferenceCompatActivity { @@ -228,8 +190,8 @@ public class MainSettingsActivity extends PreferenceCompatActivity {
}
// Allow selection of the default server
ListPreference defaultServerPreference = (ListPreference) findPreference("header_defaultserver");
defaultServerPreference.setEntries(serverNames.toArray(new String[serverNames.size()]));
defaultServerPreference.setEntryValues(serverCodes.toArray(new String[serverCodes.size()]));
defaultServerPreference.setEntries(serverNames.toArray(new String[0]));
defaultServerPreference.setEntryValues(serverCodes.toArray(new String[0]));
// Add existing RSS feeds
if (!enableRssUi) {
@ -274,8 +236,8 @@ public class MainSettingsActivity extends PreferenceCompatActivity { @@ -274,8 +236,8 @@ public class MainSettingsActivity extends PreferenceCompatActivity {
siteValues.add(websearch.getKey());
}
// Supply the Preference list names and values
setSite.setEntries(siteNames.toArray(new String[siteNames.size()]));
setSite.setEntryValues(siteValues.toArray(new String[siteValues.size()]));
setSite.setEntries(siteNames.toArray(new String[0]));
setSite.setEntryValues(siteValues.toArray(new String[0]));
}
@ -287,8 +249,7 @@ public class MainSettingsActivity extends PreferenceCompatActivity { @@ -287,8 +249,7 @@ public class MainSettingsActivity extends PreferenceCompatActivity {
@Override
protected Dialog onCreateDialog(int id) {
switch (id) {
case DIALOG_ADDSEEDBOX:
if (id == DIALOG_ADDSEEDBOX) {
// Open dialog to pick one of the supported seedbox providers (or a normal server)
String[] seedboxes = new String[SeedboxProvider.values().length + 1];
seedboxes[0] = getString(R.string.pref_addserver_normal);

17
app/src/main/java/org/transdroid/core/gui/settings/RssfeedPreference.java

@ -24,6 +24,7 @@ import org.transdroid.core.app.settings.RssfeedSetting; @@ -24,6 +24,7 @@ import org.transdroid.core.app.settings.RssfeedSetting;
/**
* Represents a {@link RssfeedSetting} in a preferences screen.
*
* @author Eric Kok
*/
public class RssfeedPreference extends Preference {
@ -35,12 +36,18 @@ public class RssfeedPreference extends Preference { @@ -35,12 +36,18 @@ public class RssfeedPreference extends Preference {
public RssfeedPreference(Context context) {
super(context);
OnPreferenceClickListener onPreferenceClicked = preference -> {
if (onRssfeedClickedListener != null)
onRssfeedClickedListener.onRssfeedClicked(rssfeedSetting);
return true;
};
setOnPreferenceClickListener(onPreferenceClicked);
setIconSpaceReserved(false);
}
/**
* Set the RSS feed settings object that is bound to this preference item
*
* @param rssfeedSetting The RSS feed settings
* @return Itself, for method chaining
*/
@ -54,6 +61,7 @@ public class RssfeedPreference extends Preference { @@ -54,6 +61,7 @@ public class RssfeedPreference extends Preference {
/**
* Set a listener that will be notified of click events on this preference
*
* @param onRssfeedClickedListener The click listener to register
* @return Itself, for method chaining
*/
@ -62,15 +70,6 @@ public class RssfeedPreference extends Preference { @@ -62,15 +70,6 @@ public class RssfeedPreference extends Preference {
return this;
}
private OnPreferenceClickListener onPreferenceClicked = new OnPreferenceClickListener() {
@Override
public boolean onPreferenceClick(Preference preference) {
if (onRssfeedClickedListener != null)
onRssfeedClickedListener.onRssfeedClicked(rssfeedSetting);
return true;
}
};
public interface OnRssfeedClickedListener {
void onRssfeedClicked(RssfeedSetting rssfeedSetting);
}

12
app/src/main/java/org/transdroid/core/gui/settings/RssfeedSettingsActivity.java

@ -19,8 +19,6 @@ package org.transdroid.core.gui.settings; @@ -19,8 +19,6 @@ package org.transdroid.core.gui.settings;
import android.annotation.TargetApi;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import android.content.Intent;
import android.os.Build;
import android.os.Bundle;
@ -34,6 +32,7 @@ import org.transdroid.core.app.settings.ApplicationSettings_; @@ -34,6 +32,7 @@ import org.transdroid.core.app.settings.ApplicationSettings_;
/**
* Activity that allows for a configuration of some RSS feed. The key can be supplied to update an existing RSS feed setting instead of creating a new
* one.
*
* @author Eric Kok
*/
@EActivity
@ -66,7 +65,6 @@ public class RssfeedSettingsActivity extends KeyBoundPreferencesActivity { @@ -66,7 +65,6 @@ public class RssfeedSettingsActivity extends KeyBoundPreferencesActivity {
MainSettingsActivity_.intent(this).flags(Intent.FLAG_ACTIVITY_CLEAR_TOP).start();
}
@SuppressWarnings("deprecation")
@OptionsItem(R.id.action_removesettings)
protected void removeSettings() {
showDialog(DIALOG_CONFIRMREMOVE);
@ -74,15 +72,11 @@ public class RssfeedSettingsActivity extends KeyBoundPreferencesActivity { @@ -74,15 +72,11 @@ public class RssfeedSettingsActivity extends KeyBoundPreferencesActivity {
@Override
protected Dialog onCreateDialog(int id) {
switch (id) {
case DIALOG_CONFIRMREMOVE:
if (id == DIALOG_CONFIRMREMOVE) {
return new AlertDialog.Builder(this).setMessage(R.string.pref_confirmremove)
.setPositiveButton(android.R.string.ok, new OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
.setPositiveButton(android.R.string.ok, (dialog, which) -> {
ApplicationSettings_.getInstance_(RssfeedSettingsActivity.this).removeRssfeedSettings(key);
finish();
}
}).setNegativeButton(android.R.string.cancel, null).create();
}
return null;

19
app/src/main/java/org/transdroid/core/gui/settings/ServerPreference.java

@ -24,6 +24,7 @@ import org.transdroid.core.app.settings.ServerSetting; @@ -24,6 +24,7 @@ import org.transdroid.core.app.settings.ServerSetting;
/**
* Represents a {@link ServerSetting} in a preferences screen.
*
* @author Eric Kok
*/
public class ServerPreference extends Preference {
@ -35,12 +36,18 @@ public class ServerPreference extends Preference { @@ -35,12 +36,18 @@ public class ServerPreference extends Preference {
public ServerPreference(Context context) {
super(context);
OnPreferenceClickListener onPreferenceClicked = preference -> {
if (onServerClickedListener != null)
onServerClickedListener.onServerClicked(serverSetting);
return true;
};
setOnPreferenceClickListener(onPreferenceClicked);
setIconSpaceReserved(false);
}
/**
* Set the server settings object that is bound to this preference item
*
* @param serverSetting The server settings
* @return Itself, for method chaining
*/
@ -54,6 +61,7 @@ public class ServerPreference extends Preference { @@ -54,6 +61,7 @@ public class ServerPreference extends Preference {
/**
* Set a listener that will be notified of click events on this preference
*
* @param onServerClickedListener The click listener to register
* @return Itself, for method chaining
*/
@ -62,17 +70,8 @@ public class ServerPreference extends Preference { @@ -62,17 +70,8 @@ public class ServerPreference extends Preference {
return this;
}
private OnPreferenceClickListener onPreferenceClicked = new OnPreferenceClickListener() {
@Override
public boolean onPreferenceClick(Preference preference) {
if (onServerClickedListener != null)
onServerClickedListener.onServerClicked(serverSetting);
return true;
}
};
public interface OnServerClickedListener {
public void onServerClicked(ServerSetting serverSetting);
void onServerClicked(ServerSetting serverSetting);
}
}

Some files were not shown because too many files have changed in this diff Show More

Loading…
Cancel
Save