Skip to content

Commit 24004bc

Browse files
committed
Bump to next release 1.2, update Gradle stuff, add option to only notify on (You)s, fix crash if tracked reply id isn't a number somehow
1 parent 961c5e0 commit 24004bc

9 files changed

Lines changed: 51 additions & 13 deletions

File tree

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ buildscript {
99
}
1010
}
1111
dependencies {
12-
classpath 'com.android.tools.build:gradle:4.0.1'
12+
classpath 'com.android.tools.build:gradle:4.1.1'
1313

1414
// NOTE: Do not place your application dependencies here; they belong
1515
// in the individual module build.gradle files
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
#Thu Sep 03 13:24:27 CDT 2020
1+
#Sat Jun 05 18:51:26 CDT 2021
22
distributionBase=GRADLE_USER_HOME
33
distributionPath=wrapper/dists
44
zipStoreBase=GRADLE_USER_HOME
55
zipStorePath=wrapper/dists
6-
distributionUrl=https\://services.gradle.org/distributions/gradle-6.1.1-all.zip
6+
distributionUrl=https\://services.gradle.org/distributions/gradle-6.5-bin.zip

theadwatch/build.gradle

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ android {
77
applicationId "honkhonk.threadwatch"
88
minSdkVersion 21
99
targetSdkVersion 29
10-
versionCode 3
11-
versionName "1.1.0"
10+
versionCode 4
11+
versionName "1.2.0"
1212
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
1313
vectorDrawables.useSupportLibrary = true
1414
}
@@ -28,11 +28,11 @@ dependencies {
2828
androidTestImplementation('androidx.test.espresso:espresso-core:3.1.0', {
2929
exclude group: 'com.android.support', module: 'support-annotations'
3030
})
31-
implementation 'androidx.appcompat:appcompat:1.2.0'
31+
implementation 'androidx.appcompat:appcompat:1.3.0'
3232
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
33-
implementation 'com.google.android.material:material:1.2.1'
33+
implementation 'com.google.android.material:material:1.3.0'
3434
implementation 'androidx.vectordrawable:vectordrawable:1.1.0'
35-
implementation 'com.android.volley:volley:1.1.0'
35+
implementation 'com.android.volley:volley:1.2.0'
3636
implementation 'com.google.code.gson:gson:2.8.5'
3737
testImplementation 'junit:junit:4.12'
3838
}

theadwatch/src/main/java/honkhonk/threadwatch/activities/MainActivity.java

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,12 @@ public void onCreateContextMenu(ContextMenu menu, View v,
297297
getResources().getString(R.string.thread_menu_enabled);
298298
toggleItem.setTitle(toggleText);
299299

300+
MenuItem youToggleItem = menu.findItem(R.id.thread_menu_notify_you_toggle);
301+
final String youToggleText = thread.notifyOnlyIfRepliesToYou ?
302+
getResources().getString(R.string.thread_menu_notify_you_enabled) :
303+
getResources().getString(R.string.thread_menu_notify_you_disabled);
304+
youToggleItem.setTitle(youToggleText);
305+
300306
// Set delete button color
301307
MenuItem deleteButton = menu.findItem(R.id.thread_menu_delete);
302308
SpannableString s = new SpannableString(deleteButton.getTitle());
@@ -319,6 +325,11 @@ public boolean onContextItemSelected(MenuItem item) {
319325
ThreadDataManager.updateThread(MainActivity.this, thread);
320326
refreshList();
321327
return true;
328+
case R.id.thread_menu_notify_you_toggle:
329+
thread.notifyOnlyIfRepliesToYou = !thread.notifyOnlyIfRepliesToYou;
330+
ThreadDataManager.updateThread(MainActivity.this, thread);
331+
refreshList();
332+
return true;
322333
case R.id.thread_menu_replies:
323334
showThreadReplies(info.position);
324335
return true;
@@ -711,8 +722,8 @@ private void addThread(final String threadUrl) {
711722
String replyId = null;
712723
String urlFragment = url.getEncodedFragment();
713724
if (urlFragment != null) {
714-
// Discard first letter, which can be a 'p' or 'q'
715-
replyId = urlFragment.substring(1);
725+
// Discard non-numbers since the first letter can be a 'p' or 'q'
726+
replyId = urlFragment.replaceAll("\\D+","");
716727
}
717728

718729
final int dupeThreadIndex = getThreadIndex(board, id);

theadwatch/src/main/java/honkhonk/threadwatch/jobs/FetcherJobService.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,15 @@ public void threadsRetrieved(final ArrayList<ThreadModel> threads) {
128128
int newThreadCount = 0;
129129
for (final ThreadModel thread : threads) {
130130
if (thread.newReplyCount > 0 && !thread.disabled && thread.replyCountDelta > 0) {
131+
// Bypass notification if user only cares about (You)s, but
132+
// only if there are (You)s/tracked replies. Otherwise, no notifications will come
133+
// through since the user isn't tracking any replies.
134+
if (!thread.replyIds.isEmpty() &&
135+
(thread.notifyOnlyIfRepliesToYou && !thread.newRepliesToYou))
136+
{
137+
continue;
138+
}
139+
131140
updatedThreadsText.append(thread.getTruncatedTitle());
132141
updatedThreadsText.append(" (+");
133142

@@ -153,7 +162,8 @@ public void threadsRetrieved(final ArrayList<ThreadModel> threads) {
153162
// Save for persistence
154163
ThreadDataManager.setUpdatedThreads(this, updatedThreads);
155164

156-
if (updatedThreads.size() == 0) {
165+
// Only notify if the notification was populated
166+
if (updatedThreads.size() == 0 || newThreadCount == 0) {
157167
return;
158168
}
159169

theadwatch/src/main/java/honkhonk/threadwatch/models/ThreadModel.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,11 @@ public class ThreadModel {
9191
*/
9292
public boolean newRepliesToYou;
9393

94+
/**
95+
* Whether or not to notify only if the thread has new replies to (you)
96+
*/
97+
public boolean notifyOnlyIfRepliesToYou;
98+
9499
/**
95100
* The UNIX timestamp (in seconds) of when the thread was made
96101
*/

theadwatch/src/main/java/honkhonk/threadwatch/retrievers/ThreadsRetriever.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -220,9 +220,17 @@ private void retrieveReplyComments(Context context, ThreadModel thread, final Ar
220220
// Mark posts that weren't found
221221
for (String replyId : thread.replyIds.keySet()) {
222222
ArrayList<PostModel> replyComments = thread.replyIds.get(replyId);
223-
if (replyComments == null || replyComments.size() == 0) {
223+
224+
int postNumber = 0;
225+
try {
226+
postNumber = Integer.parseInt(replyId);
227+
} catch (NumberFormatException e) {
228+
Log.i(TAG, String.format("Reply Id (%s) was not a post number!", replyId));
229+
}
230+
231+
if (postNumber != 0 && replyComments == null || replyComments.size() == 0) {
224232
PostModel failedPost = new PostModel();
225-
failedPost.number = Integer.parseInt(replyId);
233+
failedPost.number = postNumber;
226234
failedPost.comment = context.getString(R.string.reply_not_found);
227235
failedPost.failed = true;
228236

theadwatch/src/main/res/menu/thread_action_menu.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
<menu xmlns:android="http://schemas.android.com/apk/res/android">
33
<item android:id="@+id/thread_menu_notify_toggle"
44
android:title=""/>
5+
<item android:id="@+id/thread_menu_notify_you_toggle"
6+
android:title=""/>
57
<item android:id="@+id/thread_menu_replies"
68
android:title="@string/thread_menu_replies"/>
79
<item android:id="@+id/thread_menu_info"

theadwatch/src/main/res/values/strings.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@
4141
<string name="thread_menu_info">Info</string>
4242
<string name="thread_menu_disabled">Thread refresh: Disabled</string>
4343
<string name="thread_menu_enabled">Thread refresh: Enabled</string>
44+
<string name="thread_menu_notify_you_disabled">Only notify on (You): Disabled</string>
45+
<string name="thread_menu_notify_you_enabled">Only notify on (You): Enabled</string>
4446
<string name="thread_menu_mark_read">Mark as Read</string>
4547
<string name="thread_menu_delete">Delete</string>
4648
<string name="thread_menu_deleted">Deleted</string>

0 commit comments

Comments
 (0)