Skip to content

Commit

Permalink
Improved precaching behaviour
Browse files Browse the repository at this point in the history
  • Loading branch information
QuantumBadger committed Jan 14, 2017
1 parent 682296e commit 6e3f07a
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 33 deletions.
1 change: 1 addition & 0 deletions assets/changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ Fix for saving images with no file extension (thanks to Luís Coelho)
Hungarian translation (thanks to András Lengyel-Nagy)
Various codebase improvements (thanks to Daniel Martí)
Removed unnecessary image download when opening in external browser (thanks to m3sv)
Improved precaching behaviour

76/1.9.6.1
Removed all CAPTCHAs as they are no longer needed
Expand Down
43 changes: 32 additions & 11 deletions src/main/java/org/quantumbadger/redreader/common/PrefsUtility.java
Original file line number Diff line number Diff line change
Expand Up @@ -348,9 +348,16 @@ public static Integer pref_behaviour_comment_min(final Context context, final Sh
// pref_behaviour_imageview_mode

public enum ImageViewMode {
INTERNAL_OPENGL,
INTERNAL_BROWSER,
EXTERNAL_BROWSER
INTERNAL_OPENGL(true),
INTERNAL_BROWSER(false),
EXTERNAL_BROWSER(false);

public final boolean downloadInApp;

ImageViewMode(final boolean downloadInApp)
{
this.downloadInApp = downloadInApp;
}
}

public static ImageViewMode pref_behaviour_imageview_mode(final Context context, final SharedPreferences sharedPreferences) {
Expand All @@ -372,10 +379,17 @@ public static AlbumViewMode pref_behaviour_albumview_mode(final Context context,
// pref_behaviour_gifview_mode

public enum GifViewMode {
INTERNAL_MOVIE,
INTERNAL_LEGACY,
INTERNAL_BROWSER,
EXTERNAL_BROWSER
INTERNAL_MOVIE(true),
INTERNAL_LEGACY(true),
INTERNAL_BROWSER(false),
EXTERNAL_BROWSER(false);

public final boolean downloadInApp;

GifViewMode(final boolean downloadInApp)
{
this.downloadInApp = downloadInApp;
}
}

public static GifViewMode pref_behaviour_gifview_mode(final Context context, final SharedPreferences sharedPreferences) {
Expand All @@ -385,10 +399,17 @@ public static GifViewMode pref_behaviour_gifview_mode(final Context context, fin
// pref_behaviour_videoview_mode

public enum VideoViewMode {
INTERNAL_VIDEOVIEW,
INTERNAL_BROWSER,
EXTERNAL_BROWSER,
EXTERNAL_APP_VLC
INTERNAL_VIDEOVIEW(true),
INTERNAL_BROWSER(false),
EXTERNAL_BROWSER(false),
EXTERNAL_APP_VLC(true);

public final boolean downloadInApp;

VideoViewMode(final boolean downloadInApp)
{
this.downloadInApp = downloadInApp;
}
}

public static VideoViewMode pref_behaviour_videoview_mode(final Context context, final SharedPreferences sharedPreferences) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -630,13 +630,6 @@ public void run() {
final PrefsUtility.VideoViewMode videoViewMode
= PrefsUtility.pref_behaviour_videoview_mode(activity, mSharedPreferences);

final boolean imagesOpenedInternally = (imageViewMode == PrefsUtility.ImageViewMode.INTERNAL_OPENGL);

final boolean gifsOpenedInternally
= (gifViewMode == PrefsUtility.GifViewMode.INTERNAL_MOVIE
|| gifViewMode == PrefsUtility.GifViewMode.INTERNAL_LEGACY
|| videoViewMode == PrefsUtility.VideoViewMode.INTERNAL_VIDEOVIEW);

final boolean isAll =
mPostListingURL.pathType() == RedditURLParser.SUBREDDIT_POST_LISTING_URL
&& (mPostListingURL.asSubredditPostListURL().type == SubredditPostListURL.Type.ALL
Expand Down Expand Up @@ -741,38 +734,40 @@ public void onSuccess(final ImageInfo info) {
if(!precacheImages) return;

// Don't precache huge images
if(info.width != null && info.width > 2500) {
Log.i(TAG, String.format(
"Not precaching '%s': too wide (%d px)", post.url, info.width));
return;
}

if(info.height != null && info.height > 2500) {
Log.i(TAG, String.format(
"Not precaching '%s': too tall (%d px)", post.url, info.height));
return;
}

if(info.size != null && info.size > 10 * 1024 * 1024) {
if(info.size != null && info.size > 15 * 1024 * 1024) {
Log.i(TAG, String.format(
"Not precaching '%s': too big (%d kB)", post.url, info.size / 1024));
return;
}

// Don't precache gifs if they're opened externally
if(Boolean.TRUE.equals(info.isAnimated) && !gifsOpenedInternally) {
if(ImageInfo.MediaType.GIF.equals(info.mediaType)
&& !gifViewMode.downloadInApp) {

Log.i(TAG, String.format(
"Not precaching '%s': GIFs are opened externally", post.url));
return;
}

// Don't precache images if they're opened externally
if(!Boolean.TRUE.equals(info.isAnimated) && !imagesOpenedInternally) {
if(ImageInfo.MediaType.IMAGE.equals(info.mediaType)
&& !imageViewMode.downloadInApp) {

Log.i(TAG, String.format(
"Not precaching '%s': images are opened externally", post.url));
return;
}


// Don't precache videos if they're opened externally
if(ImageInfo.MediaType.VIDEO.equals(info.mediaType)
&& !videoViewMode.downloadInApp) {

Log.i(TAG, String.format(
"Not precaching '%s': videos are opened externally", post.url));
return;
}

final URI uri = General.uriFromString(info.urlOriginal);
if(uri == null) return;

Expand Down

0 comments on commit 6e3f07a

Please sign in to comment.