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: 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 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.setUsername(resobj.get("username").toString());
account.setAcct(resobj.get("acct").toString()); account.setAcct(resobj.get("acct").toString());
account.setDisplay_name(resobj.get("display_name").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())); account.setLocked(Boolean.parseBoolean(resobj.get("locked").toString()));
if (resobj.has("created_at") && !resobj.isNull("created_at")) { if (resobj.has("created_at") && !resobj.isNull("created_at")) {
account.setCreated_at(Helper.mstStringToDate(resobj.get("created_at").toString())); account.setCreated_at(Helper.mstStringToDate(resobj.get("created_at").toString()));

View File

@ -1328,11 +1328,13 @@ public class Helper {
} }
if (!url.equals("null")) if (!url.equals("null"))
Glide.with(navigationView.getContext()) Glide.with(navigationView.getContext())
.load(!disableGif ? account.getAvatar() : account.getAvatar_static()) .asBitmap()
.into(new SimpleTarget<Drawable>() { .load(account.getAvatar())
.into(new SimpleTarget<Bitmap>() {
@Override @Override
public void onResourceReady(@NonNull Drawable resource, Transition<? super Drawable> transition) { public void onResourceReady(@NonNull Bitmap resource, Transition<? super Bitmap> transition) {
item.setIcon(resource); Drawable drawable = new BitmapDrawable(activity.getResources(), resource);
item.setIcon(drawable);
item.getIcon().setColorFilter(0xFFFFFFFF, PorterDuff.Mode.MULTIPLY); item.getIcon().setColorFilter(0xFFFFFFFF, PorterDuff.Mode.MULTIPLY);
} }
}); });
@ -1358,32 +1360,6 @@ public class Helper {
} }
return false; 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.SimpleTarget;
import com.bumptech.glide.request.target.Target; import com.bumptech.glide.request.target.Target;
import com.bumptech.glide.request.transition.Transition; 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.AsyncHttpClient;
import com.koushikdutta.async.http.AsyncHttpRequest; import com.koushikdutta.async.http.AsyncHttpRequest;
import com.koushikdutta.async.http.Headers; import com.koushikdutta.async.http.Headers;
@ -242,38 +238,28 @@ public class LiveNotificationService extends Service implements NetworkStateRece
} }
String key = account.getAcct() + "@" + account.getInstance(); String key = account.getAcct() + "@" + account.getInstance();
if (webSocketFutures.get(key) == null || !Objects.requireNonNull(webSocketFutures.get(key)).isOpen()) { 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() { AsyncHttpClient.getDefaultInstance().websocket("wss://" + account.getInstance() + "/api/v1/streaming/?stream=" + notif_url + "&access_token=" + account.getToken(), "wss", (ex, webSocket) -> {
@Override webSocketFutures.put(account.getAcct() + "@" + account.getInstance(), webSocket);
public void onCompleted(Exception ex, WebSocket webSocket) { if (ex != null) {
webSocketFutures.put(account.getAcct() + "@" + account.getInstance(), webSocket); return;
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();
}
});
} }
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; event = Helper.EventStreaming.NOTIFICATION;
notification = API.parseNotificationResponse(LiveNotificationService.this, new JSONObject(response.get("payload").toString())); notification = API.parseNotificationResponse(LiveNotificationService.this, new JSONObject(response.get("payload").toString()));
if (notification == null) {
return;
}
b.putParcelable("data", notification); b.putParcelable("data", notification);
boolean liveNotifications = sharedpreferences.getBoolean(Helper.SET_LIVE_NOTIFICATIONS, true); boolean liveNotifications = sharedpreferences.getBoolean(Helper.SET_LIVE_NOTIFICATIONS, true);
boolean canNotify = Helper.canNotify(LiveNotificationService.this); boolean canNotify = Helper.canNotify(LiveNotificationService.this);
@ -467,34 +450,31 @@ public class LiveNotificationService extends Service implements NetworkStateRece
final String finalMessage = message; final String finalMessage = message;
Handler mainHandler = new Handler(Looper.getMainLooper()); Handler mainHandler = new Handler(Looper.getMainLooper());
Helper.NotifType finalNotifType = notifType; Helper.NotifType finalNotifType = notifType;
Runnable myRunnable = new Runnable() { Runnable myRunnable = () -> {
@Override if (finalMessage != null) {
public void run() { Glide.with(LiveNotificationService.this)
if (finalMessage != null) { .asBitmap()
Glide.with(LiveNotificationService.this) .load(notification.getAccount().getAvatar())
.asBitmap() .listener(new RequestListener<Bitmap>() {
.load(notification.getAccount().getAvatar()) @Override
.listener(new RequestListener<Bitmap>() { public boolean onResourceReady(Bitmap resource, Object model, Target<Bitmap> target, DataSource dataSource, boolean isFirstResource) {
@Override return false;
public boolean onResourceReady(Bitmap resource, Object model, Target<Bitmap> target, DataSource dataSource, boolean isFirstResource) { }
return false;
}
@Override @Override
public boolean onLoadFailed(@Nullable GlideException e, Object model, Target target, boolean isFirstResource) { public boolean onLoadFailed(@Nullable GlideException e, Object model, Target target, boolean isFirstResource) {
Helper.notify_user(LiveNotificationService.this, account, intent, BitmapFactory.decodeResource(getResources(), Helper.notify_user(LiveNotificationService.this, account, intent, BitmapFactory.decodeResource(getResources(),
getMainLogo(LiveNotificationService.this)), finalNotifType, "@" + notification.getAccount().getAcct(), finalMessage); getMainLogo(LiveNotificationService.this)), finalNotifType, "@" + notification.getAccount().getAcct(), finalMessage);
return false; return false;
} }
}) })
.into(new SimpleTarget<Bitmap>() { .into(new SimpleTarget<Bitmap>() {
@Override @Override
public void onResourceReady(@NonNull Bitmap resource, Transition<? super Bitmap> transition) { 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); mainHandler.post(myRunnable);