Some improvements

This commit is contained in:
tom79 2020-04-08 19:12:11 +02:00
parent 1e76c1dbec
commit 56e74e3120
4 changed files with 56 additions and 95 deletions

View File

@ -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

View File

@ -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()));

View File

@ -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();
});
}
}

View File

@ -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<Bitmap>() {
@Override
public boolean onResourceReady(Bitmap resource, Object model, Target<Bitmap> target, DataSource dataSource, boolean isFirstResource) {
return false;
}
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) {
@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);
}
});
}
Helper.notify_user(LiveNotificationService.this, account, intent, resource, finalNotifType, "@" + notification.getAccount().getAcct(), finalMessage);
}
});
}
};
mainHandler.post(myRunnable);