Skip to content

Commit 1237679

Browse files
committed
Merge branch 'develop' into beta
2 parents fa5de30 + fb14e60 commit 1237679

File tree

8 files changed

+40
-36
lines changed

8 files changed

+40
-36
lines changed

Awful.apk/src/main/AndroidManifest.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
33
package="com.ferg.awfulapp"
4-
android:versionCode="10008"
5-
android:versionName="3.6.4"
4+
android:versionCode="10009"
5+
android:versionName="3.6.5"
66
android:installLocation="auto">
77
<supports-screens
88
android:smallScreens="true"

Awful.apk/src/main/assets/changelog.html

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,14 @@
66

77
<main>
88
<section>
9-
<h2>3.6.3</h2>
9+
<h2>3.6.5</h2>
10+
<ul>
11+
<li>Important fixes for probations and other weird behavior (the app's, not yours...)</li>
12+
</ul>
13+
</section>
14+
15+
<section>
16+
<h2>3.6.4</h2>
1017
<ul>
1118
<li>Fixed broken stuff from the terrible non-https internet badlands</li>
1219
<li>WebP is an image format, we knew that, so do our menus</li>

Awful.apk/src/main/java/com/ferg/awfulapp/forums/UpdateTask.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ internal abstract class UpdateTask(protected val context: Context, private val t
235235
}
236236

237237

238-
override fun handleError(error: AwfulError, doc: Document): Boolean {
238+
override fun handleCriticalError(error: AwfulError, doc: Document): Boolean {
239239
onRequestFailed(error)
240240
finishTask(false)
241241
return true

Awful.apk/src/main/java/com/ferg/awfulapp/network/CookieController.java

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -72,12 +72,15 @@ public static synchronized boolean restoreLoginCookies(Context ctx) {
7272
long expiry = prefs.getLong(Constants.COOKIE_PREF_EXPIRY_DATE, -1);
7373
int cookieVersion = prefs.getInt(Constants.COOKIE_PREF_VERSION, 0);
7474

75-
if (useridCookieValue == null || passwordCookieValue == null || expiry == -1) {
75+
long maxAge = expiry - System.currentTimeMillis();
76+
boolean cookieExpired = maxAge <= 0;
77+
// verify the cookie is valid - if not, we need to clear the cookie and return a failure
78+
if (useridCookieValue == null || passwordCookieValue == null || cookieExpired) {
7679
if (Constants.DEBUG) {
7780
Timber.w("Unable to restore cookies! Reasons:\n" +
7881
(useridCookieValue == null ? "USER_ID is NULL\n" : "") +
7982
(passwordCookieValue == null ? "PASSWORD is NULL\n" : "") +
80-
(expiry == -1 ? "EXPIRY is -1" : ""));
83+
(cookieExpired ? "cookie has expired, max age = " + maxAge : ""));
8184
}
8285

8386
cookie = "";
@@ -90,8 +93,6 @@ public static synchronized boolean restoreLoginCookies(Context ctx) {
9093
Constants.COOKIE_NAME_SESSIONID, sessionidCookieValue,
9194
Constants.COOKIE_NAME_SESSIONHASH, sessionhashCookieValue);
9295

93-
Date expiryDate = new Date(expiry);
94-
Date now = new Date();
9596

9697
HttpCookie[] allCookies = {
9798
new HttpCookie(Constants.COOKIE_NAME_USERID, useridCookieValue),
@@ -100,8 +101,6 @@ public static synchronized boolean restoreLoginCookies(Context ctx) {
100101
new HttpCookie(Constants.COOKIE_NAME_SESSIONHASH, sessionhashCookieValue)
101102
};
102103

103-
long maxAge = expiryDate.getTime() - now.getTime();
104-
Timber.e("now.compareTo(expiryDate):%s", maxAge);
105104

106105
for (HttpCookie tempCookie : allCookies) {
107106
tempCookie.setVersion(cookieVersion);
@@ -113,8 +112,8 @@ public static synchronized boolean restoreLoginCookies(Context ctx) {
113112
}
114113

115114
if (Constants.DEBUG) {
116-
Timber.w("Cookies restored from prefs");
117-
Timber.w("Cookie dump: %s", TextUtils.join("\n", cookieManager.getCookieStore().getCookies()));
115+
Timber.i("Cookies restored from prefs");
116+
Timber.i("Cookie dump: %s", TextUtils.join("\n", cookieManager.getCookieStore().getCookies()));
118117
}
119118

120119
return true;

Awful.apk/src/main/java/com/ferg/awfulapp/task/AwfulRequest.kt

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,9 @@ import java.io.IOException
4747
* do anything with the response (e.g. a fire-and-forget message to the site) you can just set [T]
4848
* to a nullable type (Void? makes most sense if there's no meaningful result) and return null here.
4949
*
50-
* [handleError] and [customizeProgressListenerError] both have default implementations, but can be
50+
* [handleCriticalError] and [customizeProgressListenerError] both have default implementations, but can be
5151
* overridden for special error handling and creating custom notification messages. You probably
52-
* won't want to change [handleError] in most cases, and if you do add any handler code (e.g. if
52+
* won't want to change [handleCriticalError] in most cases, and if you do add any handler code (e.g. if
5353
* a network failure requires the app to update some state) you'll probably just want to call the
5454
* super method to get the standard error handling when you're done.
5555
*/
@@ -159,16 +159,17 @@ abstract class AwfulRequest<T>(protected val context: Context, private val baseU
159159

160160

161161
/**
162-
* Handler for [error]s thrown by [AwfulError.checkPageErrors] when parsing a response.
162+
* Handler for critical [error]s thrown by [AwfulError.checkPageErrors] when parsing a response.
163163
*
164-
* The main response-handler logic calls this when it encounters an [AwfulError], to check whether
165-
* the request implementation will handle it (and processing can proceed to [handleResponse]).
166-
* Returns true if the error was handled.
164+
* The main response-handler logic calls this when it encounters a critical [AwfulError],
165+
* to check whether the request implementation will handle it (and processing can proceed
166+
* to [handleResponse]). Returns true if the error was handled.
167167
*
168-
* By default this swallows non-critical errors, and returns false for everything else. If you need
169-
* different behaviour for some reason, override this!
168+
* This is only called for errors that return true for [AwfulError.isCritical], and returns
169+
* false by default. If you want to handle any of these errors, override this and return true
170+
* for those.
170171
*/
171-
protected open fun handleError(error: AwfulError, doc: Document): Boolean = !error.isCritical
172+
protected open fun handleCriticalError(error: AwfulError, doc: Document): Boolean = false
172173

173174
/**
174175
* Customize the error a request delivers in its [ProgressListener.requestEnded] callback.
@@ -247,9 +248,9 @@ abstract class AwfulRequest<T>(protected val context: Context, private val baseU
247248
try {
248249
val doc = parseAsHtml(response)
249250
updateProgress(50)
250-
val error = AwfulError.checkPageErrors(doc, preferences)
251-
if (error != null && handleError(error, doc)) {
252-
throw error
251+
// we only pass critical errors for requests to handle - anything else (i.e. probations) gets swallowed
252+
AwfulError.checkPageErrors(doc, preferences)?.let { error ->
253+
if (error.isCritical && !handleCriticalError(error, doc)) throw error
253254
}
254255

255256
val result = handleResponseDocument(doc)

Awful.apk/src/main/java/com/ferg/awfulapp/task/LepersColonyRequest.kt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import com.ferg.awfulapp.constants.Constants.*
66
import com.ferg.awfulapp.task.LepersColonyRequest.LepersColonyPage
77
import com.ferg.awfulapp.users.LepersColonyFragment.Companion.FIRST_PAGE
88
import com.ferg.awfulapp.users.Punishment
9-
import com.ferg.awfulapp.util.AwfulError
109
import org.jsoup.nodes.Document
1110

1211
/**
@@ -56,7 +55,6 @@ class LepersColonyRequest(context: Context, val page: Int = 1, val userId: Strin
5655
return LepersColonyPage(punishments, thisPage, lastPage, userId)
5756
}
5857

59-
override fun handleError(error: AwfulError, doc: Document) = false
6058

6159
/**
6260
* Represents the contents and metadata for a page from the Leper's Colony

Awful.apk/src/main/java/com/ferg/awfulapp/task/LoginRequest.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ class LoginRequest(context: Context, private val username: String, password: Str
2626
@Throws(AwfulError::class)
2727
override fun handleResponse(doc: Document): Boolean = validateLoginState()
2828

29-
override fun handleError(error: AwfulError, doc: Document): Boolean =
30-
error.networkResponse?.isRedirect == true || !error.isCritical
29+
override fun handleCriticalError(error: AwfulError, doc: Document): Boolean =
30+
error.networkResponse?.isRedirect == true
3131

3232

3333
private val NetworkResponse.isRedirect get() = this.statusCode == 302

Awful.apk/src/main/java/com/ferg/awfulapp/util/AwfulError.java

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,15 @@
3232
* requests we make can focus on looking for specific problems.
3333
*/
3434
public class AwfulError extends VolleyError {
35-
private static final String TAG = "AwfulError";
3635

3736
public static final int ERROR_LOGGED_OUT = 0x00000001;
3837
public static final int ERROR_FORUM_CLOSED = 0x00000002;
3938
public static final int ERROR_PROBATION = 0x00000004;
4039
public static final int ERROR_GENERIC_FAILURE = 0x00000008;
4140
public static final int ERROR_ACCESS_DENIED = 0x00000010;
4241

42+
private static final Pattern PROBATION_MESSAGE_REGEX = Pattern.compile("(.*)until\\s(([\\s\\w:,])+).\\sYou(.*)");
43+
4344
private final int errorCode;
4445
@Nullable
4546
private final String errorMessage;
@@ -60,7 +61,6 @@ public AwfulError(@Nullable String message) {
6061
public AwfulError(int code, @Nullable String message) {
6162
errorCode = code;
6263
errorMessage = message;
63-
Timber.e("Error: " + code + " - " + getMessage());
6464
}
6565

6666
/**
@@ -157,7 +157,7 @@ public static AwfulError checkPageErrors(Document page, AwfulPreferences prefs)
157157
}
158158
}
159159

160-
// you're probed!
160+
// handle probation status by looking for the probation message (or lack of it)
161161
Element probation = page.getElementById("probation_warn");
162162
if (probation == null) {
163163
// clear any probation
@@ -171,9 +171,8 @@ public static AwfulError checkPageErrors(Document page, AwfulPreferences prefs)
171171
}
172172

173173
// try to parse the probation date - default to 1 day in case we can't parse it (not too scary)
174-
Long probTimestamp = System.currentTimeMillis() + TimeUnit.DAYS.toMillis(1);
175-
Pattern p = Pattern.compile("(.*)until\\s(([\\s\\w:,])+).\\sYou(.*)");
176-
Matcher m = p.matcher(probation.text());
174+
long probTimestamp = System.currentTimeMillis() + TimeUnit.DAYS.toMillis(1);
175+
Matcher m = PROBATION_MESSAGE_REGEX.matcher(probation.text());
177176
if (m.find()) {
178177
String date = m.group(2);
179178
//for example January 11, 2013 10:35 AM CST
@@ -182,10 +181,10 @@ public static AwfulError checkPageErrors(Document page, AwfulPreferences prefs)
182181
//TODO this might have timezone issues?
183182
probTimestamp = probationFormat.parse(date).getTime();
184183
} catch (ParseException e) {
185-
Timber.tag(TAG).w(e, "checkPageErrors: couldn't parse probation date text: %s", date);
184+
Timber.w(e, "checkPageErrors: couldn't parse probation date text: %s", date);
186185
}
187186
} else {
188-
Timber.tag(TAG).w("checkPageErrors: couldn't find expected probation date text!\nFull text: %s", probation.text());
187+
Timber.w("checkPageErrors: couldn't find expected probation date text!\nFull text: %s", probation.text());
189188
}
190189

191190
prefs.setPreference(Keys.PROBATION_TIME, probTimestamp);

0 commit comments

Comments
 (0)