summaryrefslogtreecommitdiffstats
path: root/app/src/main/java
diff options
context:
space:
mode:
authortom79 <tschneider.ac@gmail.com>2020-04-08 19:12:11 +0200
committertom79 <tschneider.ac@gmail.com>2020-04-08 19:12:11 +0200
commit56e74e3120c798cb14d7d5ee1ac8058021e56a22 (patch)
tree692e0d8cb477db090ae5d84028360e0b0564ef5e /app/src/main/java
parent1e76c1dbeca8dedce59112abcc543d1e9d2e96dd (diff)
Some improvements
Diffstat (limited to 'app/src/main/java')
-rw-r--r--app/src/main/java/app/fedilab/android/client/API.java3
-rw-r--r--app/src/main/java/app/fedilab/android/helper/Helper.java36
-rw-r--r--app/src/main/java/app/fedilab/android/services/LiveNotificationService.java110
3 files changed, 54 insertions, 95 deletions
diff --git a/app/src/main/java/app/fedilab/android/client/API.java b/app/src/main/java/app/fedilab/android/client/API.java
index eb42c5353..50ee68282 100644
--- a/app/src/main/java/app/fedilab/android/client/API.java
+++ b/app/src/main/java/app/fedilab/android/client/API.java
@@ -1378,6 +1378,9 @@ public class API {
account.setUsername(resobj.get("username").toString());
account.setAcct(resobj.get("acct").toString());
account.setDisplay_name(resobj.get("display_name").toString());
+ if( account.getDisplay_name() == null || account.getDisplay_name().compareTo("") == 0){
+ account.setDisplay_name(resobj.get("username").toString());
+ }
account.setLocked(Boolean.parseBoolean(resobj.get("locked").toString()));
if (resobj.has("created_at") && !resobj.isNull("created_at")) {
account.setCreated_at(Helper.mstStringToDate(resobj.get("created_at").toString()));
diff --git a/app/src/main/java/app/fedilab/android/helper/Helper.java b/app/src/main/java/app/fedilab/android/helper/Helper.java
index 18f04f328..cfec8f6ef 100644
--- a/app/src/main/java/app/fedilab/android/helper/Helper.java
+++ b/app/src/main/java/app/fedilab/android/helper/Helper.java
@@ -1328,11 +1328,13 @@ public class Helper {
}
if (!url.equals("null"))
Glide.with(navigationView.getContext())
- .load(!disableGif ? account.getAvatar() : account.getAvatar_static())
- .into(new SimpleTarget<Drawable>() {
+ .asBitmap()
+ .load(account.getAvatar())
+ .into(new SimpleTarget<Bitmap>() {
@Override
- public void onResourceReady(@NonNull Drawable resource, Transition<? super Drawable> transition) {
- item.setIcon(resource);
+ public void onResourceReady(@NonNull Bitmap resource, Transition<? super Bitmap> transition) {
+ Drawable drawable = new BitmapDrawable(activity.getResources(), resource);
+ item.setIcon(drawable);
item.getIcon().setColorFilter(0xFFFFFFFF, PorterDuff.Mode.MULTIPLY);
}
});
@@ -1358,32 +1360,6 @@ public class Helper {
}
return false;
});
- item.setActionView(R.layout.update_account);
- ImageView deleteButton = item.getActionView().findViewById(R.id.account_remove_button);
- deleteButton.setOnClickListener(v -> {
- final SharedPreferences sharedpreferences1 = activity.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
- int theme1 = sharedpreferences1.getInt(Helper.SET_THEME, Helper.THEME_DARK);
- int style;
- if (theme1 == Helper.THEME_DARK) {
- style = R.style.DialogDark;
- } else if (theme1 == Helper.THEME_BLACK) {
- style = R.style.DialogBlack;
- } else {
- style = R.style.Dialog;
- }
- new AlertDialog.Builder(activity, style)
- .setTitle(activity.getString(R.string.delete_account_title))
- .setMessage(activity.getString(R.string.delete_account_message, "@" + account.getAcct() + "@" + account.getInstance()))
- .setPositiveButton(android.R.string.yes, (dialog, which) -> {
- new RemoveAccountAsyncTask(activity, account).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
- item.setVisible(false);
- })
- .setNegativeButton(android.R.string.no, (dialog, which) -> {
- // do nothing
- })
- .setIcon(android.R.drawable.ic_dialog_alert)
- .show();
- });
}
}
diff --git a/app/src/main/java/app/fedilab/android/services/LiveNotificationService.java b/app/src/main/java/app/fedilab/android/services/LiveNotificationService.java
index 2f04c4638..36f39a30c 100644
--- a/app/src/main/java/app/fedilab/android/services/LiveNotificationService.java
+++ b/app/src/main/java/app/fedilab/android/services/LiveNotificationService.java
@@ -47,10 +47,6 @@ import com.bumptech.glide.request.RequestListener;
import com.bumptech.glide.request.target.SimpleTarget;
import com.bumptech.glide.request.target.Target;
import com.bumptech.glide.request.transition.Transition;
-import com.koushikdutta.async.ByteBufferList;
-import com.koushikdutta.async.DataEmitter;
-import com.koushikdutta.async.callback.CompletedCallback;
-import com.koushikdutta.async.callback.DataCallback;
import com.koushikdutta.async.http.AsyncHttpClient;
import com.koushikdutta.async.http.AsyncHttpRequest;
import com.koushikdutta.async.http.Headers;
@@ -242,38 +238,28 @@ public class LiveNotificationService extends Service implements NetworkStateRece
}
String key = account.getAcct() + "@" + account.getInstance();
if (webSocketFutures.get(key) == null || !Objects.requireNonNull(webSocketFutures.get(key)).isOpen()) {
- AsyncHttpClient.getDefaultInstance().websocket("wss://" + account.getInstance() + "/api/v1/streaming/?stream=" + notif_url + "&access_token=" + account.getToken(), "wss", new AsyncHttpClient.WebSocketConnectCallback() {
- @Override
- public void onCompleted(Exception ex, WebSocket webSocket) {
- webSocketFutures.put(account.getAcct() + "@" + account.getInstance(), webSocket);
- if (ex != null) {
- return;
+ AsyncHttpClient.getDefaultInstance().websocket("wss://" + account.getInstance() + "/api/v1/streaming/?stream=" + notif_url + "&access_token=" + account.getToken(), "wss", (ex, webSocket) -> {
+ webSocketFutures.put(account.getAcct() + "@" + account.getInstance(), webSocket);
+ if (ex != null) {
+ return;
+ }
+ webSocket.setStringCallback(s -> {
+ try {
+ JSONObject eventJson = new JSONObject(s);
+ onRetrieveStreaming(account, eventJson);
+ } catch (JSONException ignored) {
}
- webSocket.setStringCallback(new WebSocket.StringCallback() {
- public void onStringAvailable(String s) {
- try {
- JSONObject eventJson = new JSONObject(s);
- onRetrieveStreaming(account, eventJson);
- } catch (JSONException ignored) {
- }
- }
- });
+ });
- webSocket.setClosedCallback(new CompletedCallback() {
- @Override
- public void onCompleted(Exception ex) {
- if (networkStateReceiver.connected) {
- startWork(account);
- }
- }
- });
- webSocket.setDataCallback(new DataCallback() {
- public void onDataAvailable(DataEmitter emitter, ByteBufferList byteBufferList) {
- // note that this data has been read
- byteBufferList.recycle();
- }
- });
- }
+ webSocket.setClosedCallback(ex1 -> {
+ if (networkStateReceiver.connected) {
+ startWork(account);
+ }
+ });
+ webSocket.setDataCallback((emitter, byteBufferList) -> {
+ // note that this data has been read
+ byteBufferList.recycle();
+ });
});
}
}
@@ -337,9 +323,6 @@ public class LiveNotificationService extends Service implements NetworkStateRece
event = Helper.EventStreaming.NOTIFICATION;
notification = API.parseNotificationResponse(LiveNotificationService.this, new JSONObject(response.get("payload").toString()));
- if (notification == null) {
- return;
- }
b.putParcelable("data", notification);
boolean liveNotifications = sharedpreferences.getBoolean(Helper.SET_LIVE_NOTIFICATIONS, true);
boolean canNotify = Helper.canNotify(LiveNotificationService.this);
@@ -467,34 +450,31 @@ public class LiveNotificationService extends Service implements NetworkStateRece
final String finalMessage = message;
Handler mainHandler = new Handler(Looper.getMainLooper());
Helper.NotifType finalNotifType = notifType;
- Runnable myRunnable = new Runnable() {
- @Override
- public void run() {
- if (finalMessage != null) {
- Glide.with(LiveNotificationService.this)
- .asBitmap()
- .load(notification.getAccount().getAvatar())
- .listener(new RequestListener<Bitmap>() {
- @Override
- public boolean onResourceReady(Bitmap resource, Object model, Target<Bitmap> target, DataSource dataSource, boolean isFirstResource) {
- return false;
- }
-
- @Override
- public boolean onLoadFailed(@Nullable GlideException e, Object model, Target target, boolean isFirstResource) {
- Helper.notify_user(LiveNotificationService.this, account, intent, BitmapFactory.decodeResource(getResources(),
- getMainLogo(LiveNotificationService.this)), finalNotifType, "@" + notification.getAccount().getAcct(), finalMessage);
- return false;
- }
- })
- .into(new SimpleTarget<Bitmap>() {
- @Override
- public void onResourceReady(@NonNull Bitmap resource, Transition<? super Bitmap> transition) {
-
- Helper.notify_user(LiveNotificationService.this, account, intent, resource, finalNotifType, "@" + notification.getAccount().getAcct(), finalMessage);
- }
- });
- }
+ Runnable myRunnable = () -> {
+ if (finalMessage != null) {
+ Glide.with(LiveNotificationService.this)
+ .asBitmap()
+ .load(notification.getAccount().getAvatar())
+ .listener(new RequestListener<Bitmap>() {
+ @Override
+ public boolean onResourceReady(Bitmap resource, Object model, Target<Bitmap> target, DataSource dataSource, boolean isFirstResource) {
+ return false;
+ }
+
+ @Override
+ public boolean onLoadFailed(@Nullable GlideException e, Object model, Target target, boolean isFirstResource) {
+ Helper.notify_user(LiveNotificationService.this, account, intent, BitmapFactory.decodeResource(getResources(),
+ getMainLogo(LiveNotificationService.this)), finalNotifType, "@" + notification.getAccount().getAcct(), finalMessage);
+ return false;
+ }
+ })
+ .into(new SimpleTarget<Bitmap>() {
+ @Override
+ public void onResourceReady(@NonNull Bitmap resource, Transition<? super Bitmap> transition) {
+
+ Helper.notify_user(LiveNotificationService.this, account, intent, resource, finalNotifType, "@" + notification.getAccount().getAcct(), finalMessage);
+ }
+ });
}
};
mainHandler.post(myRunnable);