Skip to content

Commit

Permalink
probably resolved some issue to do with Random
Browse files Browse the repository at this point in the history
  • Loading branch information
yellowbluesky committed Apr 30, 2019
1 parent 20952d0 commit f9fa240
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 13 deletions.
18 changes: 11 additions & 7 deletions app/src/main/java/com/antony/muzei/pixiv/PixivArtProvider.java
Original file line number Diff line number Diff line change
Expand Up @@ -69,16 +69,19 @@ private Boolean getAccessToken()
if (!sharedPreferences.getString("accessToken", "").isEmpty() &&
sharedPreferences.getLong("accessTokenIssueTime", 0) > System.currentTimeMillis() - 3600)
{
Log.d(LOG_TAG, "Found valid access token");
return true;
}
Log.d(LOG_TAG, "No valid access token found, acquiring one");

// If we did not have an access token or if it had expired, we proceed to build a request to acquire one
Uri.Builder authQueryBuilder = new Uri.Builder()
.appendQueryParameter("get_secure_url", Integer.toString(1))
.appendQueryParameter("client_id", PixivArtProviderDefines.CLIENT_ID)
.appendQueryParameter("client_secret", PixivArtProviderDefines.CLIENT_SECRET);

// If we did not have an access token or if it had expired, we proceed to build a request to acquire one
if (sharedPreferences.getString("refreshToken", "").isEmpty())
//if (sharedPreferences.getString("refreshToken", "").isEmpty())
if(true)
{
Log.i(LOG_TAG, "No refresh token found, proceeding with username / password authentication");
authQueryBuilder.appendQueryParameter("grant_type", "password")
Expand Down Expand Up @@ -114,7 +117,7 @@ private Boolean getAccessToken()
editor.putString("refreshToken", tokens.getString("refresh_token"));
editor.putString("userId", tokens.getJSONObject("user").getString("id"));
editor.putString("deviceToken", tokens.getString("device_token"));
editor.commit();
editor.apply();
} catch (IOException | JSONException ex)
{
ex.printStackTrace();
Expand Down Expand Up @@ -201,7 +204,7 @@ private Uri downloadFile(Response response, String token)
Context context = getContext();
// File extensions doesn't even matter when saving locally
// Only there to more easily allow local file manager access
File downloadedFile = new File(context.getExternalCacheDir(), token + ".png");
File downloadedFile = new File(context.getCacheDir(), token + ".png");
try
{
FileOutputStream fileStream = new FileOutputStream(downloadedFile);
Expand Down Expand Up @@ -304,7 +307,7 @@ protected void onLoadRequested(boolean initial)
overallJson = new JSONObject((rankingResponse.body().string()));
rankingResponse.close();

Random random = new Random();
Random random = new Random(System.currentTimeMillis());
if(!mode.equals("follow") && !mode.equals("bookmark"))
{
Log.d(LOG_TAG, "Ranking");
Expand All @@ -313,7 +316,7 @@ protected void onLoadRequested(boolean initial)
do
{
pictureMetadata = overallJson.getJSONArray("contents")
.getJSONObject(random.nextInt(overallJson.length()));
.getJSONObject(random.nextInt(50));
} while (pictureMetadata.getInt("illust_type") != 0);
Log.d(LOG_TAG, "ranking");
title = pictureMetadata.getString("title");
Expand All @@ -326,8 +329,9 @@ protected void onLoadRequested(boolean initial)
else
{
Log.d(LOG_TAG, "feed or bookmark");
Log.d(LOG_TAG,overallJson.toString());
pictureMetadata = overallJson.getJSONArray("illusts")
.getJSONObject(random.nextInt(overallJson.length()));
.getJSONObject(random.nextInt(30));
title = pictureMetadata.getString("title");
byline = pictureMetadata.getJSONObject("user").getString("name");
token = pictureMetadata.getString("id");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ protected void onCreate(Bundle savedInstanceState)
.beginTransaction()
.replace(R.id.settings, new SettingsFragment())
.commit();
ActionBar actionBar = getSupportActionBar();
if (actionBar != null)
{
actionBar.setDisplayHomeAsUpEnabled(true);
}
// ActionBar actionBar = getSupportActionBar();
// if (actionBar != null)
// {
// actionBar.setDisplayHomeAsUpEnabled(true);
// }
// String sharedPrefFile = getApplicationContext().getPackageName() + "_implementation";
// SharedPreferences sharedPref = getPreferences(Context.MODE_PRIVATE);
}
Expand Down
3 changes: 2 additions & 1 deletion app/src/main/res/xml/root_preferences.xml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@
android:entries="@array/pref_updateMode_entries"
android:entryValues="@array/pref_updateMode_entryValues"
android:defaultValue="@string/pref_updateMode_default"
android:persistent="true" />
android:persistent="true"
android:summary="%s"/>

</PreferenceCategory>

Expand Down

0 comments on commit f9fa240

Please sign in to comment.