diff --git a/app/src/main/assets/changelogs/357.txt b/app/src/main/assets/changelogs/357.txt index d8df46a2e..b3dcd7e75 100644 --- a/app/src/main/assets/changelogs/357.txt +++ b/app/src/main/assets/changelogs/357.txt @@ -1,3 +1,5 @@ Changed: -- One logout entry in menu (it will removed the account from the app) +- One logout entry in the menu (it will remove the account from the app) - Improve memory management +- Improve scroll +- Clear push notifications when visiting notifications tab \ No newline at end of file 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() { + .asBitmap() + .load(account.getAvatar()) + .into(new SimpleTarget() { @Override - public void onResourceReady(@NonNull Drawable resource, Transition transition) { - item.setIcon(resource); + public void onResourceReady(@NonNull Bitmap resource, Transition 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; - } - 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(); - } - }); + 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.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() { - @Override - public boolean onResourceReady(Bitmap resource, Object model, Target target, DataSource dataSource, boolean isFirstResource) { - return false; - } + Runnable myRunnable = () -> { + if (finalMessage != null) { + Glide.with(LiveNotificationService.this) + .asBitmap() + .load(notification.getAccount().getAvatar()) + .listener(new RequestListener() { + @Override + public boolean onResourceReady(Bitmap resource, Object model, Target 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() { - @Override - public void onResourceReady(@NonNull Bitmap resource, Transition transition) { + @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() { + @Override + public void onResourceReady(@NonNull Bitmap resource, Transition transition) { - Helper.notify_user(LiveNotificationService.this, account, intent, resource, finalNotifType, "@" + notification.getAccount().getAcct(), finalMessage); - } - }); - } + Helper.notify_user(LiveNotificationService.this, account, intent, resource, finalNotifType, "@" + notification.getAccount().getAcct(), finalMessage); + } + }); } }; mainHandler.post(myRunnable);