Skip to content

Commit

Permalink
Merge pull request #34 from deed02392/patch-1
Browse files Browse the repository at this point in the history
Fix BTN adaptor by making it support token settings
  • Loading branch information
erickok committed Nov 4, 2015
2 parents 219d2f3 + c943121 commit 6d45980
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
8 changes: 2 additions & 6 deletions app/src/main/java/org/transdroid/search/BTN/BTNAdapter.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,14 +59,10 @@ public class BTNAdapter implements ISearchAdapter {
@Override
public List<SearchResult> search(Context context, String query, SortOrder order, int maxResults) throws Exception {

// transdroid fudge - the user can enter the API key in either field
String username = SettingsHelper.getSiteUser(context, TorrentSite.BTN);
String password = SettingsHelper.getSitePass(context, TorrentSite.BTN);
String apikey = (username == null ? password : username);
String apikey = SettingsHelper.getSiteToken(context, TorrentSite.BTN);

if (username == null && password == null) {
if (apikey == null)
throw new LoginException("The BTN user API key was not provided, please configure BTN site settings");
}

// Try and get the search results - if we can't, assume invalid API key
JSONObject apiSearchResults;
Expand Down
12 changes: 12 additions & 0 deletions app/src/main/java/org/transdroid/search/gui/SettingsHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -95,5 +95,17 @@ public static String getSitePass(Context context, TorrentSite site) {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
return prefs.getString(PREF_SITE_PASS + site.name(), null);
}

/**
* Returns the API token that the user specified in the settings as site-specific credentials.
* @param context The android activity or provider context to access shared preferences from
* @param site The site for which to retrieve the API key/access token
* @return The API token that the user entered in the settings as site-specific user pass, or null if none
* entered
*/
public static String getSiteToken(Context context, TorrentSite site) {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
return prefs.getString(PREF_SITE_TOKEN + site.name(), null);
}

}

0 comments on commit 6d45980

Please sign in to comment.