Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add setting for image loading #1025

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions app/src/main/java/com/gh4a/fragment/SettingsFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ public interface OnStateChangeListener {
public static final String KEY_START_PAGE = "start_page";
public static final String KEY_TEXT_SIZE = "webview_initial_zoom";
public static final String KEY_GIF_LOADING = "http_gif_load_mode";
public static final String KEY_IMAGE_LOADING = "http_image_load_mode";
public static final String KEY_NOTIFICATIONS = "notifications";
public static final String KEY_NOTIFICATION_INTERVAL = "notification_interval";
private static final String KEY_ABOUT = "about";
Expand Down
19 changes: 17 additions & 2 deletions app/src/main/java/com/gh4a/utils/HttpImageGetter.java
Original file line number Diff line number Diff line change
Expand Up @@ -461,12 +461,13 @@ private Drawable loadImageForUrl(String source) {
bitmap = renderSvgToBitmap(mContext.getResources(), is, mWidth, mHeight);
} else {
boolean isGif = mime != null && mime.startsWith("image/gif");
if (!isGif || canLoadGif()) {
if ((isGif && canLoadGif()) || (!isGif && canLoadImage())) {
output = File.createTempFile("image", ".tmp", mCacheDir);
if (FileUtils.save(output, is)) {
if (isGif) {
GifDrawable d = new GifDrawable(output);
d.setBounds(0, 0, d.getIntrinsicWidth(), d.getIntrinsicHeight());
d.setBounds(0, 0, d.getIntrinsicWidth(),
d.getIntrinsicHeight());
return d;
} else {
bitmap = getBitmap(output, mWidth, mHeight);
Expand Down Expand Up @@ -521,6 +522,20 @@ private boolean canLoadGif() {
}
}

private boolean canLoadImage() {
SharedPreferences prefs = mContext.getSharedPreferences(SettingsFragment.PREF_NAME,
Context.MODE_PRIVATE);
int mode = prefs.getInt(SettingsFragment.KEY_IMAGE_LOADING, 2);
switch (mode) {
case 1: // load via Wifi
return !UiUtils.downloadNeedsWarning(mContext);
case 2: // always load
return true;
default:
return false;
}
}

private static Bitmap getBitmap(final File image, int width, int height) {
final BitmapFactory.Options options = new BitmapFactory.Options();
RandomAccessFile file = null;
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/res/values/arrays.xml
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,12 @@
<item>3</item>
<item>4</item>
</string-array>
<string-array name="load_gif_mode_items">
<string-array name="load_gif_images_mode_items">
<item>Don\'t load</item>
<item>Only load on Wifi</item>
<item>Load always</item>
</string-array>
<string-array name="load_gif_mode_values">
<string-array name="load_gif_images_mode_values">
<item>0</item>
<item>1</item>
<item>2</item>
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -524,6 +524,7 @@
<!-- Webview text size -->
<string name="menu_text_size">Code view text size</string>
<string name="menu_gif_load_mode">Animated GIF loading</string>
<string name="menu_image_load_mode">Image loading</string>

<!-- Print document titles -->
<string name="diff_print_document_title">Diff of file %1$s in commit %2$s in %3$s/%4$s</string>
Expand Down
12 changes: 10 additions & 2 deletions app/src/main/res/xml/settings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,18 @@
android:summary="%s"
android:title="@string/menu_text_size" />

<com.gh4a.widget.IntegerListPreference
android:defaultValue="2"
android:entries="@array/load_gif_images_mode_items"
android:entryValues="@array/load_gif_images_mode_values"
android:key="http_image_load_mode"
android:summary="%s"
android:title="@string/menu_image_load_mode" />

<com.gh4a.widget.IntegerListPreference
android:defaultValue="1"
android:entries="@array/load_gif_mode_items"
android:entryValues="@array/load_gif_mode_values"
android:entries="@array/load_gif_images_mode_items"
android:entryValues="@array/load_gif_images_mode_values"
android:key="http_gif_load_mode"
android:summary="%s"
android:title="@string/menu_gif_load_mode" />
Expand Down