@ -49,6 +49,7 @@ import java.util.List;
/ * *
/ * *
* Singleton object to access all application settings , including stored servers , web search sites and RSS feeds .
* Singleton object to access all application settings , including stored servers , web search sites and RSS feeds .
*
* @author Eric Kok
* @author Eric Kok
* /
* /
@EBean ( scope = Scope . Singleton )
@EBean ( scope = Scope . Singleton )
@ -59,9 +60,9 @@ public class ApplicationSettings {
@RootContext
@RootContext
protected Context context ;
protected Context context ;
private SharedPreferences prefs ;
@Bean
@Bean
protected SearchHelper searchHelper ;
protected SearchHelper searchHelper ;
private SharedPreferences prefs ;
protected ApplicationSettings ( Context context ) {
protected ApplicationSettings ( Context context ) {
prefs = PreferenceManager . getDefaultSharedPreferences ( context ) ;
prefs = PreferenceManager . getDefaultSharedPreferences ( context ) ;
@ -69,11 +70,11 @@ public class ApplicationSettings {
/ * *
/ * *
* Returns all available user - configured normal and seed servers
* Returns all available user - configured normal and seed servers
*
* @return A list of all stored server settings objects
* @return A list of all stored server settings objects
* /
* /
public List < ServerSetting > getAllServerSettings ( ) {
public List < ServerSetting > getAllServerSettings ( ) {
List < ServerSetting > all = new ArrayList < > ( ) ;
List < ServerSetting > all = new ArrayList < > ( getNormalServerSettings ( ) ) ;
all . addAll ( getNormalServerSettings ( ) ) ;
for ( SeedboxProvider provider : SeedboxProvider . values ( ) ) {
for ( SeedboxProvider provider : SeedboxProvider . values ( ) ) {
all . addAll ( provider . getSettings ( ) . getAllServerSettings ( prefs , all . size ( ) ) ) ;
all . addAll ( provider . getSettings ( ) . getAllServerSettings ( prefs , all . size ( ) ) ) ;
}
}
@ -82,6 +83,7 @@ public class ApplicationSettings {
/ * *
/ * *
* Returns the order number / identifying key of the last server , normal or seedbox configured
* 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
* @return The zero - based order number ( index ) of the last stored server settings
* /
* /
public int getMaxOfAllServers ( ) {
public int getMaxOfAllServers ( ) {
@ -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
* 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 .
* 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
* @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
* first and the seedboxes are numbers thereafter onwards
* @return The server settings object , loaded from shared preferences
* @return The server settings object , loaded from shared preferences
@ -116,6 +119,7 @@ public class ApplicationSettings {
/ * *
/ * *
* Returns all available normal , user - configured servers ( so no seedbox settings )
* Returns all available normal , user - configured servers ( so no seedbox settings )
*
* @return A list of all stored server settings objects
* @return A list of all stored server settings objects
* /
* /
public List < ServerSetting > getNormalServerSettings ( ) {
public List < ServerSetting > getNormalServerSettings ( ) {
@ -128,6 +132,7 @@ public class ApplicationSettings {
/ * *
/ * *
* Returns the order number / identifying key of the last normal server
* 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
* @return The zero - based order number ( index ) of the last stored normal server settings
* /
* /
public int getMaxNormalServer ( ) {
public int getMaxNormalServer ( ) {
@ -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
* 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 .
* 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
* @param order The order number / identifying key of the normal server ' s settings to retrieve
* @return The server settings object , loaded from shared preferences
* @return The server settings object , loaded from shared preferences
* /
* /
@ -198,6 +204,7 @@ public class ApplicationSettings {
/ * *
/ * *
* Removes all settings related to a configured server . Since servers are ordered , the order of the remaining
* Removes all settings related to a configured server . Since servers are ordered , the order of the remaining
* servers will be updated accordingly .
* servers will be updated accordingly .
*
* @param order The identifying order number / key of the settings to remove
* @param order The identifying order number / key of the settings to remove
* /
* /
public void removeNormalServerSettings ( int order ) {
public void removeNormalServerSettings ( int order ) {
@ -275,6 +282,7 @@ public class ApplicationSettings {
* specific default server was selected , the last used server settings . As opposed to getDefaultServerKey ( int ) , this
* 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
* method checks whether the particular server still exists ( and returns the first server if not ) . If no servers are
* configured , null is returned .
* configured , null is returned .
*
* @return A server settings object of the server to use by default , or null if no server is yet configured
* @return A server settings object of the server to use by default , or null if no server is yet configured
* /
* /
public ServerSetting getDefaultServer ( ) {
public ServerSetting getDefaultServer ( ) {
@ -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
* 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
* 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 .
* 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
* @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
* 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
* selected by default for viewing yet it should always ask when adding a new torrent
@ -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
* 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
* 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 .
* 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
* @return A server settings object of the last used server ( or , if not known , the first server ) , or null if no
* servers exist
* servers exist
* /
* /
@ -337,26 +347,29 @@ public class ApplicationSettings {
return getServerSetting ( last ) ;
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
* 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
* call getLastUsedServer directly . WARNING : the returned integer may no longer refer to a known server settings
* object : check the bounds .
* object : check the bounds .
*
* @return An integer indicating the order number / key or the last used server , or - 1 if it was not set
* @return An integer indicating the order number / key or the last used server , or - 1 if it was not set
* /
* /
public int getLastUsedServerKey ( ) {
public int getLastUsedServerKey ( ) {
return prefs . getInt ( "system_lastusedserver" , - 1 ) ;
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
* Registers the order number / unique key of some server as being last used by the user
*
* @param order The key identifying the specific server
* @param order The key identifying the specific server
* /
* /
public void setLastUsedServerKey ( int order ) {
public void setLastUsedServerKey ( int order ) {
@ -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
* Returns the unique code that ( should ) uniquely identify a navigation filter , such as a label , in the list of all
* available filters
* available filters
*
* @return A code that the last used navigation filter reported as uniquely identifying itself , or null if no last
* @return A code that the last used navigation filter reported as uniquely identifying itself , or null if no last
* used filter is known
* used filter is known
* /
* /
@ -375,6 +389,7 @@ public class ApplicationSettings {
/ * *
/ * *
* Registers some navigation filter as being the last used by the user
* 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
* @param filter The navigation filter that the user last used in the interface
* /
* /
public void setLastUsedNavigationFilter ( NavigationFilter filter ) {
public void setLastUsedNavigationFilter ( NavigationFilter filter ) {
@ -383,6 +398,7 @@ public class ApplicationSettings {
/ * *
/ * *
* Returns all available user - configured web - based ( as opped to in - app ) search sites
* 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
* @return A list of all stored web search site settings objects
* /
* /
public List < WebsearchSetting > getWebsearchSettings ( ) {
public List < WebsearchSetting > getWebsearchSettings ( ) {
@ -395,6 +411,7 @@ public class ApplicationSettings {
/ * *
/ * *
* Returns the order number / identifying key of the last web search site
* 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
* @return The zero - based order number ( index ) of the last stored web search site
* /
* /
public int getMaxWebsearch ( ) {
public int getMaxWebsearch ( ) {
@ -406,6 +423,7 @@ public class ApplicationSettings {
/ * *
/ * *
* Returns the user - specified web - based search site setting for a specific site
* 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
* @param order The order number / identifying key of the settings to retrieve
* @return The web search site settings object , loaded from shared preferences
* @return The web search site settings object , loaded from shared preferences
* /
* /
@ -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
* 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 .
* remaining sites will be updated accordingly .
*
* @param order The identifying order number / key of the settings to remove
* @param order The identifying order number / key of the settings to remove
* /
* /
public void removeWebsearchSettings ( int order ) {
public void removeWebsearchSettings ( int order ) {
@ -446,6 +465,7 @@ public class ApplicationSettings {
/ * *
/ * *
* Returns all available user - configured RSS feeds
* Returns all available user - configured RSS feeds
*
* @return A list of all stored RSS feed settings objects
* @return A list of all stored RSS feed settings objects
* /
* /
public List < RssfeedSetting > getRssfeedSettings ( ) {
public List < RssfeedSetting > getRssfeedSettings ( ) {
@ -458,6 +478,7 @@ public class ApplicationSettings {
/ * *
/ * *
* Returns the order number / identifying key of the last stored RSS feed
* 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
* @return The zero - based order number ( index ) of the last stored RSS feed
* /
* /
public int getMaxRssfeed ( ) {
public int getMaxRssfeed ( ) {
@ -469,6 +490,7 @@ public class ApplicationSettings {
/ * *
/ * *
* Returns the user - specified RSS feed setting for a specific feed
* Returns the user - specified RSS feed setting for a specific feed
*
* @param order The order number / identifying key of the settings to retrieve
* @param order The order number / identifying key of the settings to retrieve
* @return The RSS feed settings object , loaded from shared preferences
* @return The RSS feed settings object , loaded from shared preferences
* /
* /
@ -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
* Removes all settings related to a configured RSS feed . Since feeds are ordered , the order of the remaining feeds
* will be updated accordingly .
* will be updated accordingly .
*
* @param order The identifying order number / key of the settings to remove
* @param order The identifying order number / key of the settings to remove
* /
* /
public void removeRssfeedSettings ( int order ) {
public void removeRssfeedSettings ( int order ) {
@ -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
* 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 .
* { @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 .
* 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 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 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
* @param lastViewedItemUrl The url of the last item the last time that the feed was viewed
@ -543,6 +567,7 @@ public class ApplicationSettings {
/ * *
/ * *
* Registers the torrents list sort order as being last used by the user
* Registers the torrents list sort order as being last used by the user
*
* @param currentSortOrder The sort order property the user selected last
* @param currentSortOrder The sort order property the user selected last
* @param currentSortAscending The sort order direction that was last used
* @param currentSortAscending The sort order direction that was last used
* /
* /
@ -556,6 +581,7 @@ public class ApplicationSettings {
/ * *
/ * *
* Returns the sort order property that the user last used . Use together with { @link # getLastUsedSortDescending ( ) }
* Returns the sort order property that the user last used . Use together with { @link # getLastUsedSortDescending ( ) }
* to get the full last used sort settings .
* to get the full last used sort settings .
*
* @return The last used sort order enumeration value
* @return The last used sort order enumeration value
* /
* /
public TorrentsSortBy getLastUsedSortOrder ( ) {
public TorrentsSortBy getLastUsedSortOrder ( ) {
@ -563,8 +589,18 @@ public class ApplicationSettings {
. getStatus ( prefs . getInt ( "system_lastusedsortorder" , TorrentsSortBy . Alphanumeric . getCode ( ) ) ) ;
. 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
* Registers the search list sort order as being last used by the user
*
* @param currentSortOrder The sort order property the user selected last
* @param currentSortOrder The sort order property the user selected last
* /
* /
public void setLastUsedSearchSortOrder ( SearchSortOrder currentSortOrder ) {
public void setLastUsedSearchSortOrder ( SearchSortOrder currentSortOrder ) {
@ -573,17 +609,10 @@ public class ApplicationSettings {
edit . apply ( ) ;
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
* Returns the sort order direction that the user last used . Use together with { @link # getLastUsedSortOrder ( ) } to
* get the full last used sort settings .
* get the full last used sort settings .
*
* @return True if the last used sort direction was descending , false otherwise ( i . e . the default ascending
* @return True if the last used sort direction was descending , false otherwise ( i . e . the default ascending
* direction )
* direction )
* /
* /
@ -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 .
* 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 }
* @return A list of search settings , all of which are either a { @link SearchSite } or { @link WebsearchSetting }
* /
* /
public List < SearchSetting > getSearchSettings ( ) {
public List < SearchSetting > getSearchSettings ( ) {
@ -607,6 +637,7 @@ public class ApplicationSettings {
* site in the main settings . As opposed to getLastUsedSearchSiteKey ( int ) , this method checks whether a site was
* 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
* 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 .
* 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
* @return A site settings object of the last used server ( or , if not known , the first server ) , or null if no
* servers exist
* servers exist
* /
* /
@ -654,10 +685,20 @@ public class ApplicationSettings {
return null ;
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
* 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
* with getLastUsedSearchSite directly . WARNING : the returned string may no longer refer to a known web search site
* or in - app search settings object .
* 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
* @return A string indicating the key of the last used search site , or null if no site was yet used or set as
* default
* default
* /
* /
@ -665,16 +706,9 @@ public class ApplicationSettings {
return prefs . getString ( "header_setsearchsite" , null ) ;
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 .
* 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
* @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
* @return A JSON array of JSON objects , each which represent a since torrent
* /
* /
@ -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
* Stores the now - last seen statistics of the supplied server by the background server checker service to the
* internal stored preferences .
* internal stored preferences .
*
* @param server The server to which the statistics apply to
* @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
* @param lastStats A JSON array of JSON objects that each represent a single seen torrent
* /
* /
@ -701,6 +736,7 @@ public class ApplicationSettings {
/ * *
/ * *
* Returns the user configuration for some specific app widget , if the widget is known at all .
* 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
* @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
* @return A widget configuration object , or null if no settings were stored for the widget ID
* /
* /
@ -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
* Stores the user settings for some specific app widget . Existing settings for the supplied app widget ID will be
* overridden .
* overridden .
*
* @param appWidgetId The unique ID of the app widget to store settings for , as supplied by the AppWidgetManager
* @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
* @param settings A widget configuration object , which may not be null
* /
* /
@ -738,6 +775,7 @@ public class ApplicationSettings {
/ * *
/ * *
* Remove the setting for some specific app widget .
* 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
* @param appWidgetId The unique ID of the app widget to store settings for , as supplied by the AppWidgetManager
* /
* /
public void removeWidgetConfig ( int appWidgetId ) {
public void removeWidgetConfig ( int appWidgetId ) {
@ -753,6 +791,7 @@ public class ApplicationSettings {
/ * *
/ * *
* Trims away whitespace around a string , or returns null if str is null
* Trims away whitespace around a string , or returns null if str is null
*
* @param str The string to trim , or null
* @param str The string to trim , or null
* @return The trimmed string , or null if str is null
* @return The trimmed string , or null if str is null
* /
* /