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

Fixes micwallace/reddinator#34 - If a thumbnail will be too large as … #35

Open
wants to merge 2 commits 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
6 changes: 3 additions & 3 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Sat Oct 12 18:22:12 AEDT 2019
#Wed Feb 15 18:12:58 EST 2023
distributionBase=GRADLE_USER_HOME
distributionUrl=https\://services.gradle.org/distributions/gradle-6.5-bin.zip
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-5.4.1-all.zip
zipStoreBase=GRADLE_USER_HOME
11 changes: 8 additions & 3 deletions reddinator/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ buildscript {
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.5.1'
classpath 'com.android.tools.build:gradle:4.1.1'
}
}

Expand All @@ -18,6 +18,7 @@ apply plugin: 'com.android.application'
repositories {
maven { url "https://dl.bintray.com/populov/maven" }
maven { url 'https://guardian.github.com/maven/repo-releases' }
maven { url 'https://jitpack.io' }
mavenCentral()
jcenter({ url "https://jcenter.bintray.com/" })
maven {
Expand All @@ -41,7 +42,7 @@ android {
}
signingConfigs {
debug {
storeFile file('/home/michael/.android/debug.keystore')
storeFile file('C:/Users/JMDea/.android/debug.keystore')
keyAlias 'androiddebugkey'
keyPassword 'android'
storePassword 'android'
Expand All @@ -62,6 +63,9 @@ android {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
lintOptions {
abortOnError false
}
}


Expand All @@ -75,7 +79,8 @@ dependencies {
implementation 'io.github.kobakei:ratethisapp:1.2.0'
implementation 'de.cketti.library.changelog:ckchangelog:1.2.2'
implementation 'com.sothree.slidinguppanel:library:3.4.0'
implementation 'com.gu:option:1.3'
// implementation 'com.gu:option:1.3'
implementation 'com.github.guardian:Option:-SNAPSHOT'
implementation 'net.rdrei.android.dirchooser:library:3.2@aar'
implementation 'com.android.support:support-vector-drawable:28.0.0'
implementation 'com.android.support:recyclerview-v7:28.0.0'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,7 @@
import android.content.Intent;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.ColorMatrix;
import android.graphics.ColorMatrixColorFilter;
import android.graphics.Paint;
import android.graphics.Typeface;
import android.graphics.*;
import android.net.Uri;
import android.os.Build;
import android.text.Html;
Expand Down Expand Up @@ -332,4 +326,46 @@ public void onClick(DialogInterface dialog, int which) {
}
Toast.makeText(context, ex.getMessage(), Toast.LENGTH_LONG).show();
}

/*
* See https://developer.android.com/topic/performance/graphics/load-bitmap
* */
public static int calculateInSampleSize(BitmapFactory.Options options, int reqWidth, int reqHeight) {
// Raw height and width of image
final int height = options.outHeight;
final int width = options.outWidth;
int inSampleSize = 1;

if (height > reqHeight || width > reqWidth) {

final int halfHeight = height / 2;
final int halfWidth = width / 2;

// Calculate the largest inSampleSize value that is a power of 2 and keeps both
// height and width larger than the requested height and width.
while ((halfHeight / inSampleSize) >= reqHeight && (halfWidth / inSampleSize) >= reqWidth) {
inSampleSize *= 2;
}
}

return inSampleSize;
}

/*
* See https://developer.android.com/topic/performance/graphics/load-bitmap
* */
public static Bitmap decodeSampledBitmapFromFile(String fileurl, int reqWidth, int reqHeight) {

// First decode with inJustDecodeBounds=true to check dimensions
final BitmapFactory.Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = true;
BitmapFactory.decodeFile(fileurl, options);

// Calculate inSampleSize
options.inSampleSize = calculateInSampleSize(options, reqWidth, reqHeight);

// Decode bitmap with inSampleSize set
options.inJustDecodeBounds = false;
return BitmapFactory.decodeFile(fileurl, options);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,14 @@
* Created by michael on 3/10/16.
*/

import android.app.Activity;
import android.appwidget.AppWidgetManager;
import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Color;
import android.os.Bundle;
import android.util.DisplayMetrics;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
Expand Down Expand Up @@ -76,6 +77,7 @@ public class SubredditFeedAdapter extends BaseAdapter implements VoteTask.Callba
private boolean bigThumbs = false;
private boolean hideInf = false;
private boolean showItemSubreddit = false;
private int maxDisplayPixels = 2048;

public interface ActivityInterface {
void loadMore();
Expand All @@ -101,6 +103,7 @@ public SubredditFeedAdapter(Context context, ActivityInterface feedInterface, Re
// load preferences
loadTheme();
loadFeedPrefs();
setMaxDisplayPixels((Activity) context);
}

public void setFeed(JSONArray data, boolean canLoadMore, boolean hasMultipleSubs){
Expand Down Expand Up @@ -232,6 +235,12 @@ public void loadFeedPrefs() {
hideInf = global.mSharedPreferences.getBoolean("hideinf-app", false);
}

private void setMaxDisplayPixels(Activity activity) {
DisplayMetrics displayMetrics = new DisplayMetrics();
activity.getWindowManager().getDefaultDisplay().getMetrics(displayMetrics);
maxDisplayPixels = displayMetrics.heightPixels;
}

@Override
public int getCount() {
return data.length()>0 ? (data.length() + 1) : 0; // plus 1 advertises the "load more" item to the listview without having to add it to the data source
Expand Down Expand Up @@ -428,7 +437,9 @@ public void onClick(View view) {
// check if the image is in cache
String fileurl = context.getCacheDir() + Reddinator.IMAGE_CACHE_DIR + id + (imageLoadFlag == 2 ? "-preview" : "") + ".png";
if (new File(fileurl).exists()) {
Bitmap bitmap = BitmapFactory.decodeFile(fileurl);

// Load bitmap, making sure to limit dimensions to avoid images that are too large.
Bitmap bitmap = Utilities.decodeSampledBitmapFromFile(fileurl, maxDisplayPixels, maxDisplayPixels);
if (bitmap == null) {
imageView.setVisibility(View.GONE);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.graphics.Bitmap;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
Expand Down Expand Up @@ -142,7 +143,31 @@ public void onPageFinished(WebView view, String url) {
" style = document.createElement('style');" +
"head.appendChild(style);\n" +
"style.type = 'text/css';\n" +
"style.appendChild(document.createTextNode(css));");
"style.appendChild(document.createTextNode(css));\n" +
"let clickRedditButtonCounter = 0;\n" +
"const clickRedditButton = function() {\n" +
" clickRedditButtonCounter++;\n" +
" const shredditExperienceTree = document.querySelector('shreddit-experience-tree');\n" +
" if(shredditExperienceTree != undefined) {\n" +
" const shredditAsyncLoader = shredditExperienceTree.shadowRoot.querySelector('shreddit-async-loader');\n" +
" if(shredditAsyncLoader != undefined) {\n" +
" const xpromoAppSelector = shredditAsyncLoader.shadowRoot.querySelector('xpromo-app-selector'); \n" +
" if(xpromoAppSelector != undefined) {\n" +
" const button = xpromoAppSelector.shadowRoot.querySelector('#secondary-button');\n" +
" if(button != undefined) {\n" +
" button.click();\n" +
" return\n" +
" }\n" +
" }\n" +
" }\n" +
" }\n" +
" \n" +
" if(clickRedditButtonCounter < 60) {\n" +
" setTimeout(clickRedditButton, 1000);\n" +
" }\n" +
"}\n" +
"setTimeout(clickRedditButton, 100)"
);

super.onPageFinished(view, url);
}
Expand Down