summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThomas <tom79@noreply.codeberg.org>2023-09-09 13:36:12 +0000
committerThomas <tom79@noreply.codeberg.org>2023-09-09 13:36:12 +0000
commit63e444ffb549cdacc1120cc3454e535ffbbcb6b8 (patch)
tree65bbe985b26c5a395a6b4b4ce5f9f14076cfb257
parent57860793ff64fc78d9c54fd83d2c7f4c5d3b20e5 (diff)
parenta441ce8ff47b7801b8513f3250fd548ba11f5970 (diff)
Merge pull request 'fix-lock' (#959) from s1m/Fedilab:fix-lock into develop
Reviewed-on: https://codeberg.org/tom79/Fedilab/pulls/959
-rw-r--r--app/src/main/java/app/fedilab/android/mastodon/helper/NotificationsHelper.java22
1 files changed, 14 insertions, 8 deletions
diff --git a/app/src/main/java/app/fedilab/android/mastodon/helper/NotificationsHelper.java b/app/src/main/java/app/fedilab/android/mastodon/helper/NotificationsHelper.java
index a4572df6d..960dc3aef 100644
--- a/app/src/main/java/app/fedilab/android/mastodon/helper/NotificationsHelper.java
+++ b/app/src/main/java/app/fedilab/android/mastodon/helper/NotificationsHelper.java
@@ -41,6 +41,7 @@ import java.net.IDN;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
+import java.util.concurrent.TimeUnit;
import java.util.concurrent.locks.ReentrantLock;
import app.fedilab.android.BaseMainActivity;
@@ -105,9 +106,9 @@ public class NotificationsHelper {
new Thread(() -> {
ReentrantLock lock = getLock(slug);
- try {
- // fetch if we get the lock, or ignore, another thread is doing the job
- if (lock.tryLock()) {
+ // fetch if we get the lock, or ignore, another thread is doing the job
+ if (lock.tryLock()) {
+ try {
MastodonNotificationsService mastodonNotificationsService = init(context, slugArray[1]);
Notifications notifications = new Notifications();
Call<List<Notification>> notificationsCall;
@@ -135,10 +136,11 @@ public class NotificationsHelper {
Runnable myRunnable = () -> onRetrieveNotifications(context, notifications, accountDb, last_notif_id);
mainHandler.post(myRunnable);
}
- }
- } finally {
- if (lock.isHeldByCurrentThread()) {
- lock.unlock();
+
+ } finally {
+ if (lock.isHeldByCurrentThread()) {
+ lock.unlock();
+ }
}
}
}).start();
@@ -147,7 +149,11 @@ public class NotificationsHelper {
private static MastodonNotificationsService init(Context context, String instance) {
- final OkHttpClient okHttpClient = Helper.myOkHttpClient(context);
+ final OkHttpClient okHttpClient = new OkHttpClient.Builder()
+ .readTimeout(60, TimeUnit.SECONDS)
+ .connectTimeout(60, TimeUnit.SECONDS)
+ .proxy(Helper.getProxy(context))
+ .build();
Retrofit retrofit = new Retrofit.Builder()
.baseUrl("https://" + (instance != null ? IDN.toASCII(instance, IDN.ALLOW_UNASSIGNED) : null) + "/api/v1/")
.addConverterFactory(GsonConverterFactory.create(Helper.getDateBuilder()))