Skip to content

Commit

Permalink
Merge branch 'develop' into beta
Browse files Browse the repository at this point in the history
# Conflicts:
#	Awful.apk/src/main/AndroidManifest.xml
#	Awful.apk/src/main/assets/changelog.html
  • Loading branch information
baka-kaba committed Mar 31, 2019
2 parents 259818b + 47a0b75 commit 29bbf5d
Show file tree
Hide file tree
Showing 104 changed files with 3,082 additions and 3,660 deletions.
2 changes: 1 addition & 1 deletion Awful.apk/build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
buildscript {
ext.kotlin_version = '1.2.71'
ext.kotlin_version = '1.3.11'

repositories {
google()
Expand Down
8 changes: 5 additions & 3 deletions Awful.apk/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.ferg.awfulapp"
android:versionCode="10006"
android:versionName="3.6.2"
android:versionCode="10007"
android:versionName="3.6.3"
android:installLocation="auto">
<supports-screens
android:smallScreens="true"
Expand All @@ -23,7 +23,9 @@
android:hardwareAccelerated="true"
android:icon="@mipmap/ic_launcher"
android:roundIcon="@mipmap/ic_launcher"
android:theme="@style/Theme.AwfulTheme.Launcher">
android:theme="@style/Theme.AwfulTheme.Launcher"
android:usesCleartextTraffic="true"
>
<uses-library android:name="org.apache.http.legacy" android:required="false" />

<!--
Expand Down
9 changes: 9 additions & 0 deletions Awful.apk/src/main/assets/changelog.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,15 @@
<!-- See the Changelog code for the expected structure of this document -->

<main>
<section>
<h2>3.6.3</h2>
<ul>
<li>Fixed broken stuff from the terrible non-https internet badlands</li>
<li>WebP is an image format, we knew that, so do our menus</li>
<li>"Keep screen on" keeps on keeping the screen on (should be more reliable)</li>
</ul>
</section>

<section>
<h2>3.6.2</h2>
<ul>
Expand Down
6 changes: 3 additions & 3 deletions Awful.apk/src/main/java/com/ferg/awfulapp/Authentication.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import android.support.v7.app.AlertDialog
import com.ferg.awfulapp.Authentication.logOut
import com.ferg.awfulapp.Authentication.reAuthenticate
import com.ferg.awfulapp.constants.Constants
import com.ferg.awfulapp.network.NetworkUtils
import com.ferg.awfulapp.network.CookieController
import com.ferg.awfulapp.preferences.AwfulPreferences

/**
Expand All @@ -36,13 +36,13 @@ class LogOutDialog : DialogFragment() {

object Authentication {

fun isUserLoggedIn() = NetworkUtils.restoreLoginCookies(context)
fun isUserLoggedIn() = CookieController.restoreLoginCookies(context)

/**
* Logs the user out silently - call [reAuthenticate] if you want to show the login screen instead
*/
fun logOut() {
NetworkUtils.clearLoginCookies(context)
CookieController.clearLoginCookies(context)
}


Expand Down
6 changes: 3 additions & 3 deletions Awful.apk/src/main/java/com/ferg/awfulapp/AwfulActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import com.ferg.awfulapp.provider.AwfulTheme
import com.ferg.awfulapp.provider.ColorProvider
import com.ferg.awfulapp.task.AwfulRequest
import com.ferg.awfulapp.task.FeatureRequest
import com.ferg.awfulapp.task.ProfileRequest
import com.ferg.awfulapp.task.RefreshUserProfileRequest
import timber.log.Timber
import java.io.File

Expand Down Expand Up @@ -66,7 +66,7 @@ abstract class AwfulActivity : AppCompatActivity(), AwfulPreferences.AwfulPrefer
updateOrientation()
when {
Authentication.isUserLoggedIn() -> with(mPrefs) {
if (ignoreFormkey == null || userTitle == null) ProfileRequest(this@AwfulActivity).sendBlind()
if (ignoreFormkey == null || userAvatarUrl == null) RefreshUserProfileRequest(this@AwfulActivity).sendBlind()
if (ignoreFormkey == null) FeatureRequest(this@AwfulActivity).sendBlind()
}
// TODO: this interferes with the code in AwfulFragment#reAuthenticate - i.e. it forces "return to this activity" behaviour, but fragments may want to return to the main activity.
Expand Down Expand Up @@ -187,7 +187,7 @@ abstract class AwfulActivity : AppCompatActivity(), AwfulPreferences.AwfulPrefer

@JvmOverloads
fun setPreferredFont(view: View?, flags: Int = -1) =
view?.let { (application as AwfulApplication).setPreferredFont(view, flags) }
view?.let { FontManager.getInstance().setTypefaceToCurrentFont(view, flags) }

protected fun updateTheme() = setTheme(AwfulTheme.forForum(null).themeResId)

Expand Down
237 changes: 74 additions & 163 deletions Awful.apk/src/main/java/com/ferg/awfulapp/AwfulApplication.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,7 @@
import android.content.SharedPreferences;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.graphics.Typeface;
import android.os.StrictMode;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.crashlytics.android.Crashlytics;
import com.ferg.awfulapp.announcements.AnnouncementsManager;
Expand All @@ -19,78 +15,80 @@
import com.jakewharton.threetenabp.AndroidThreeTen;

import java.io.File;
import java.io.IOException;
import java.util.HashMap;
import java.util.Set;
import java.util.concurrent.TimeUnit;

import io.fabric.sdk.android.Fabric;
import timber.log.Timber;

public class AwfulApplication extends Application implements AwfulPreferences.AwfulPreferenceUpdate {
private static final String APP_STATE_PREFERENCES = "app_state_prefs";
/**
* Used for storing misc app data, separate from user preferences, so onPreferenceChange callbacks aren't triggered
*/
private static SharedPreferences appStatePrefs;
public class AwfulApplication extends Application {
private static final String APP_STATE_PREFERENCES = "app_state_prefs";
/**
* Used for storing misc app data, separate from user preferences, so onPreferenceChange callbacks aren't triggered
*/
private static SharedPreferences appStatePrefs;
private static boolean crashlyticsEnabled = false;

private AwfulPreferences mPref;
private final HashMap<String, Typeface> fonts = new HashMap<>();
private Typeface currentFont;

@Override
public void onCreate() {
super.onCreate();
// initialise the AwfulPreferences singleton first since a lot of things rely on it for a Context
mPref = AwfulPreferences.getInstance(this, this);
appStatePrefs = this.getSharedPreferences(APP_STATE_PREFERENCES, MODE_PRIVATE);

NetworkUtils.init(this);
AndroidThreeTen.init(this);
AnnouncementsManager.init();
onPreferenceChange(mPref,null);

// work out how long it's been since the app was updated
long hoursSinceInstall = Long.MAX_VALUE;
try {
PackageInfo packageInfo = getPackageManager().getPackageInfo(getPackageName(), 0);
long millisSinceInstall = System.currentTimeMillis() - packageInfo.lastUpdateTime;
hoursSinceInstall = TimeUnit.HOURS.convert(millisSinceInstall, TimeUnit.MILLISECONDS);
} catch (PackageManager.NameNotFoundException e) {
e.printStackTrace();
}
Timber.i("App installed %d hours ago", hoursSinceInstall);

// enable Crashlytics on non-debug builds, or debug builds that have been installed for a while
crashlyticsEnabled = !BuildConfig.DEBUG || hoursSinceInstall > 4;

// initialise the AwfulPreferences singleton first since a lot of things rely on it for a Context
AwfulPreferences mPref = AwfulPreferences.getInstance(this);

appStatePrefs = this.getSharedPreferences(APP_STATE_PREFERENCES, MODE_PRIVATE);

NetworkUtils.init(this);
AndroidThreeTen.init(this);
AnnouncementsManager.init();
FontManager.createInstance(mPref, getAssets());

long hoursSinceInstall = getHoursSinceInstall();

// enable Crashlytics on non-debug builds, or debug builds that have been installed for a while
crashlyticsEnabled = !BuildConfig.DEBUG || hoursSinceInstall > 4;

if (crashlyticsEnabled) {
Fabric.with(this, new Crashlytics());
Timber.plant(new CrashlyticsReportingTree());
if (mPref.sendUsernameInReport) {
Crashlytics.setUserName(mPref.username);
}
} else {
Timber.plant(new Timber.DebugTree());
}

if (Constants.DEBUG) {
Timber.d("*\n*\n*Debug active\n*\n*");
Fabric.with(this, new Crashlytics());

if (mPref.sendUsernameInReport)
Crashlytics.setUserName(mPref.username);
}

Timber.plant(crashlyticsEnabled ? new CrashlyticsReportingTree() : new Timber.DebugTree());

Timber.i("App installed %d hours ago", hoursSinceInstall);

if (Constants.DEBUG) {
Timber.d("*\n*\n*Debug active\n*\n*");
/*
This checks destroyed cursors aren't left open, and crashes (with a log) if it finds one
Really this is here to avoid introducing any more leaks, since there are some issues with
too many open cursors
*/
StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder()
.detectLeakedSqlLiteObjects()
.penaltyLog()
.penaltyDeath()
.build());
}

SyncManager.sync(this);
StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder()
.detectLeakedSqlLiteObjects()
.penaltyLog()
.penaltyDeath()
.build());
}

SyncManager.sync(this);
}

/**
* @return how long it's been since the app was updated
*/
private long getHoursSinceInstall() {
long hoursSinceInstall = Long.MAX_VALUE;
try {
PackageInfo packageInfo = getPackageManager().getPackageInfo(getPackageName(), 0);
long millisSinceInstall = System.currentTimeMillis() - packageInfo.lastUpdateTime;
hoursSinceInstall = TimeUnit.HOURS.convert(millisSinceInstall, TimeUnit.MILLISECONDS);
} catch (PackageManager.NameNotFoundException e) {
e.printStackTrace();
}
return hoursSinceInstall;
}

/**
* Returns true if the Crashlytics singleton has been initialised and can be used.
Expand All @@ -99,121 +97,34 @@ public static boolean crashlyticsEnabled() {
return crashlyticsEnabled;
}


/**
* Get the SharedPreferences used for storing basic app state.
* <p>
* These are separate from the default shared preferences, and won't trigger onPreferenceChange callbacks.
*
* @see AwfulPreferences.AwfulPreferenceUpdate#onPreferenceChange(AwfulPreferences, String)
*/
public static SharedPreferences getAppStatePrefs() {
return appStatePrefs;
}


public void setFontFromPreference(TextView textView, int flags){
if(flags < 0 && textView.getTypeface() != null){
flags = textView.getTypeface().getStyle();
}else{
flags = Typeface.NORMAL;
}
if(fonts.size() == 0){
processFonts();
}
if(currentFont != null){
if(mPref.preferredFont.contains("mono")){
switch(flags){
case Typeface.BOLD:
textView.setTypeface(currentFont, Typeface.MONOSPACE.BOLD);
break;
case Typeface.ITALIC:
textView.setTypeface(currentFont, Typeface.MONOSPACE.ITALIC);
break;
case Typeface.BOLD_ITALIC:
textView.setTypeface(currentFont, Typeface.MONOSPACE.BOLD_ITALIC);
break;
case Typeface.NORMAL:
default:
textView.setTypeface(currentFont, Typeface.MONOSPACE.NORMAL);
break;
}
}else{
textView.setTypeface(currentFont, flags);
}
}
}

public void setFontFromPreferenceRecurse(ViewGroup viewGroup, int flags){
for(int x=0;x<viewGroup.getChildCount();x++){
View child = viewGroup.getChildAt(x);
if(child instanceof TextView){
setFontFromPreference((TextView)child, flags);
}else if(child instanceof ViewGroup){
setFontFromPreferenceRecurse((ViewGroup)child, flags);
}
}
/**
* Get the SharedPreferences used for storing basic app state.
* <p>
* These are separate from the default shared preferences, and won't trigger onPreferenceChange callbacks.
*
* @see AwfulPreferences.AwfulPreferenceUpdate#onPreferenceChange(AwfulPreferences, String)
*/
public static SharedPreferences getAppStatePrefs() {
return appStatePrefs;
}

public void setPreferredFont(View view, int flags) {
if(view instanceof TextView){
setFontFromPreference((TextView)view, flags);
}else if(view instanceof ViewGroup){
setFontFromPreferenceRecurse((ViewGroup)view, flags);
}
}

@Override
public void onPreferenceChange(AwfulPreferences prefs, String key) {
currentFont = fonts.get(mPref.preferredFont);
Timber.i("FONT SELECTED: "+mPref.preferredFont);
}

public String[] getFontList() {
if(fonts.size() == 0){
processFonts();
}
Set<String> keys = fonts.keySet();
for(String key : keys){
Timber.i("Font: "+key);
}
return keys.toArray(new String[keys.size()]);
}

private void processFonts(){
fonts.clear();
fonts.put("default",Typeface.defaultFromStyle(Typeface.NORMAL));
try {
String[] files = getAssets().list("fonts");
for(String file : files){
String fileName = "fonts/"+file;
fonts.put(fileName, Typeface.createFromAsset(getAssets(), fileName));
Timber.i("Processed Font: "+fileName);
}
} catch (IOException | RuntimeException e) {
e.printStackTrace();
}
onPreferenceChange(mPref, null);
}

@Override
public File getCacheDir() {
Timber.i("getCacheDir(): " + super.getCacheDir());
return super.getCacheDir();
}

@Override
public File getCacheDir() {
Timber.i("getCacheDir(): %s", super.getCacheDir());
return super.getCacheDir();
}

@Override
public void onTrimMemory(int level) {
super.onTrimMemory(level);
if(level != Application.TRIM_MEMORY_UI_HIDDEN && level != Application.TRIM_MEMORY_BACKGROUND){
NetworkUtils.clearImageCache();
if (level != Application.TRIM_MEMORY_UI_HIDDEN && level != Application.TRIM_MEMORY_BACKGROUND) {
NetworkUtils.clearImageCache();
}
}

@Override
public void onLowMemory() {
super.onLowMemory();
NetworkUtils.clearImageCache();
super.onLowMemory();
NetworkUtils.clearImageCache();
}
}
Loading

0 comments on commit 29bbf5d

Please sign in to comment.