Use long for ids
This commit is contained in:
@@ -14,7 +14,7 @@ import java.util.List;
|
||||
import static com.github.gotify.api.Callback.call;
|
||||
|
||||
public class MissedMessageUtil {
|
||||
static final int NO_MESSAGES = 0;
|
||||
static final long NO_MESSAGES = 0;
|
||||
|
||||
private final MessageApi api;
|
||||
|
||||
@@ -22,8 +22,8 @@ public class MissedMessageUtil {
|
||||
this.api = api;
|
||||
}
|
||||
|
||||
public void lastReceivedMessage(Callback.SuccessCallback<Integer> successCallback) {
|
||||
api.getMessages(1, 0)
|
||||
public void lastReceivedMessage(Callback.SuccessCallback<Long> successCallback) {
|
||||
api.getMessages(1, 0L)
|
||||
.enqueue(
|
||||
call(
|
||||
(messages) -> {
|
||||
@@ -37,11 +37,11 @@ public class MissedMessageUtil {
|
||||
(e) -> {}));
|
||||
}
|
||||
|
||||
public List<Message> missingMessages(int till) {
|
||||
public List<Message> missingMessages(long till) {
|
||||
List<Message> result = new ArrayList<>();
|
||||
try {
|
||||
|
||||
Integer since = null;
|
||||
Long since = null;
|
||||
while (true) {
|
||||
PagedMessages pagedMessages = Api.execute(api.getMessages(10, since));
|
||||
List<Message> messages = pagedMessages.getMessages();
|
||||
@@ -61,7 +61,7 @@ public class MissedMessageUtil {
|
||||
return result;
|
||||
}
|
||||
|
||||
private List<Message> filter(List<Message> messages, int till) {
|
||||
private List<Message> filter(List<Message> messages, long till) {
|
||||
List<Message> result = new ArrayList<>();
|
||||
|
||||
for (Message message : messages) {
|
||||
|
||||
@@ -33,6 +33,10 @@ public class Utils {
|
||||
Snackbar.make(rootView, message, Snackbar.LENGTH_SHORT).show();
|
||||
}
|
||||
|
||||
public static int longToInt(long value) {
|
||||
return (int) (value % Integer.MAX_VALUE);
|
||||
}
|
||||
|
||||
public static String dateToRelative(OffsetDateTime data) {
|
||||
long time = data.toInstant().toEpochMilli();
|
||||
long now = System.currentTimeMillis();
|
||||
|
||||
@@ -114,10 +114,10 @@ public class MessagesActivity extends AppCompatActivity
|
||||
private Settings settings;
|
||||
protected ApplicationHolder appsHolder;
|
||||
|
||||
private int appId = MessageState.ALL_MESSAGES;
|
||||
private long appId = MessageState.ALL_MESSAGES;
|
||||
|
||||
private boolean isLoadMore = false;
|
||||
private Integer selectAppIdOnDrawerClose = null;
|
||||
private Long selectAppIdOnDrawerClose = null;
|
||||
|
||||
private PicassoHandler picassoHandler;
|
||||
|
||||
@@ -223,7 +223,12 @@ public class MessagesActivity extends AppCompatActivity
|
||||
targetReferences.clear();
|
||||
updateMessagesAndStopLoading(messages.get(appId));
|
||||
for (Application app : applications) {
|
||||
MenuItem item = menu.add(R.id.apps, app.getId(), APPLICATION_ORDER, app.getName());
|
||||
MenuItem item =
|
||||
menu.add(
|
||||
R.id.apps,
|
||||
Utils.longToInt(app.getId()),
|
||||
APPLICATION_ORDER,
|
||||
app.getName());
|
||||
item.setCheckable(true);
|
||||
Target t = Utils.toDrawable(getResources(), item::setIcon);
|
||||
targetReferences.add(t);
|
||||
@@ -284,7 +289,7 @@ public class MessagesActivity extends AppCompatActivity
|
||||
int id = item.getItemId();
|
||||
|
||||
if (item.getGroupId() == R.id.apps) {
|
||||
selectAppIdOnDrawerClose = id;
|
||||
selectAppIdOnDrawerClose = (long) id;
|
||||
startLoading();
|
||||
toolbar.setSubtitle(item.getTitle());
|
||||
} else if (id == R.id.nav_all_messages) {
|
||||
@@ -340,7 +345,10 @@ public class MessagesActivity extends AppCompatActivity
|
||||
new UpdateMissedMessages().execute(messages.getLastReceivedMessage());
|
||||
navigationView
|
||||
.getMenu()
|
||||
.findItem(appId == MessageState.ALL_MESSAGES ? R.id.nav_all_messages : appId)
|
||||
.findItem(
|
||||
appId == MessageState.ALL_MESSAGES
|
||||
? R.id.nav_all_messages
|
||||
: Utils.longToInt(appId))
|
||||
.setChecked(true);
|
||||
super.onResume();
|
||||
}
|
||||
@@ -525,10 +533,10 @@ public class MessagesActivity extends AppCompatActivity
|
||||
}
|
||||
}
|
||||
|
||||
private class UpdateMissedMessages extends AsyncTask<Integer, Void, Boolean> {
|
||||
private class UpdateMissedMessages extends AsyncTask<Long, Void, Boolean> {
|
||||
@Override
|
||||
protected Boolean doInBackground(Integer... ids) {
|
||||
Integer id = first(ids);
|
||||
protected Boolean doInBackground(Long... ids) {
|
||||
Long id = first(ids);
|
||||
if (id == -1) {
|
||||
return false;
|
||||
}
|
||||
@@ -562,10 +570,10 @@ public class MessagesActivity extends AppCompatActivity
|
||||
return super.onContextItemSelected(item);
|
||||
}
|
||||
|
||||
private class LoadMore extends AsyncTask<Integer, Void, List<MessageWithImage>> {
|
||||
private class LoadMore extends AsyncTask<Long, Void, List<MessageWithImage>> {
|
||||
|
||||
@Override
|
||||
protected List<MessageWithImage> doInBackground(Integer... appId) {
|
||||
protected List<MessageWithImage> doInBackground(Long... appId) {
|
||||
return messages.loadMore(first(appId));
|
||||
}
|
||||
|
||||
@@ -575,7 +583,7 @@ public class MessagesActivity extends AppCompatActivity
|
||||
}
|
||||
}
|
||||
|
||||
private class SelectApplicationAndUpdateMessages extends AsyncTask<Integer, Void, Integer> {
|
||||
private class SelectApplicationAndUpdateMessages extends AsyncTask<Long, Void, Long> {
|
||||
|
||||
private SelectApplicationAndUpdateMessages(boolean withLoadingSpinner) {
|
||||
if (withLoadingSpinner) {
|
||||
@@ -584,14 +592,14 @@ public class MessagesActivity extends AppCompatActivity
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Integer doInBackground(Integer... appIds) {
|
||||
Integer appId = first(appIds);
|
||||
protected Long doInBackground(Long... appIds) {
|
||||
Long appId = first(appIds);
|
||||
messages.loadMoreIfNotPresent(appId);
|
||||
return appId;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPostExecute(Integer appId) {
|
||||
protected void onPostExecute(Long appId) {
|
||||
updateMessagesAndStopLoading(messages.get(appId));
|
||||
}
|
||||
}
|
||||
@@ -624,14 +632,14 @@ public class MessagesActivity extends AppCompatActivity
|
||||
}
|
||||
}
|
||||
|
||||
private class DeleteMessages extends AsyncTask<Integer, Void, Boolean> {
|
||||
private class DeleteMessages extends AsyncTask<Long, Void, Boolean> {
|
||||
|
||||
DeleteMessages() {
|
||||
startLoading();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Boolean doInBackground(Integer... appId) {
|
||||
protected Boolean doInBackground(Long... appId) {
|
||||
return messages.deleteAll(first(appId));
|
||||
}
|
||||
|
||||
|
||||
@@ -18,7 +18,7 @@ public class MessageFacade {
|
||||
this.state = new MessageStateHolder();
|
||||
}
|
||||
|
||||
public synchronized List<MessageWithImage> get(Integer appId) {
|
||||
public synchronized List<MessageWithImage> get(long appId) {
|
||||
return combiner.combine(state.state(appId).messages, applicationHolder.get());
|
||||
}
|
||||
|
||||
@@ -28,7 +28,7 @@ public class MessageFacade {
|
||||
}
|
||||
}
|
||||
|
||||
public synchronized List<MessageWithImage> loadMore(Integer appId) {
|
||||
public synchronized List<MessageWithImage> loadMore(long appId) {
|
||||
MessageState state = this.state.state(appId);
|
||||
if (state.hasNext || !state.loaded) {
|
||||
PagedMessages pagedMessages = requester.loadMore(state);
|
||||
@@ -37,7 +37,7 @@ public class MessageFacade {
|
||||
return get(appId);
|
||||
}
|
||||
|
||||
public synchronized void loadMoreIfNotPresent(Integer appId) {
|
||||
public synchronized void loadMoreIfNotPresent(long appId) {
|
||||
MessageState state = this.state.state(appId);
|
||||
if (!state.loaded) {
|
||||
loadMore(appId);
|
||||
@@ -48,7 +48,7 @@ public class MessageFacade {
|
||||
this.state.clear();
|
||||
}
|
||||
|
||||
public int getLastReceivedMessage() {
|
||||
public long getLastReceivedMessage() {
|
||||
return state.getLastReceivedMessage();
|
||||
}
|
||||
|
||||
@@ -70,13 +70,13 @@ public class MessageFacade {
|
||||
return this.state.undoPendingDeletion();
|
||||
}
|
||||
|
||||
public synchronized boolean deleteAll(Integer appId) {
|
||||
public synchronized boolean deleteAll(long appId) {
|
||||
boolean success = this.requester.deleteAll(appId);
|
||||
this.state.deleteAll(appId);
|
||||
return success;
|
||||
}
|
||||
|
||||
public synchronized boolean canLoadMore(Integer appId) {
|
||||
public synchronized boolean canLoadMore(long appId) {
|
||||
return state.state(appId).hasNext;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,7 +10,7 @@ import java.util.concurrent.ConcurrentHashMap;
|
||||
public class MessageImageCombiner {
|
||||
|
||||
List<MessageWithImage> combine(List<Message> messages, List<Application> applications) {
|
||||
Map<Integer, String> appIdToImage = appIdToImage(applications);
|
||||
Map<Long, String> appIdToImage = appIdToImage(applications);
|
||||
|
||||
List<MessageWithImage> result = new ArrayList<>();
|
||||
|
||||
@@ -26,8 +26,8 @@ public class MessageImageCombiner {
|
||||
return result;
|
||||
}
|
||||
|
||||
public static Map<Integer, String> appIdToImage(List<Application> applications) {
|
||||
Map<Integer, String> map = new ConcurrentHashMap<>();
|
||||
public static Map<Long, String> appIdToImage(List<Application> applications) {
|
||||
Map<Long, String> map = new ConcurrentHashMap<>();
|
||||
for (Application app : applications) {
|
||||
map.put(app.getId(), app.getImage());
|
||||
}
|
||||
|
||||
@@ -35,7 +35,7 @@ class MessageRequester {
|
||||
messageApi.deleteMessage(message.getId()).enqueue(Callback.call());
|
||||
}
|
||||
|
||||
boolean deleteAll(Integer appId) {
|
||||
boolean deleteAll(Long appId) {
|
||||
try {
|
||||
Log.i("Deleting all messages for " + appId);
|
||||
if (MessageState.ALL_MESSAGES == appId) {
|
||||
|
||||
@@ -5,11 +5,11 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class MessageState {
|
||||
public static final int ALL_MESSAGES = -1;
|
||||
public static final long ALL_MESSAGES = -1;
|
||||
|
||||
int appId;
|
||||
long appId;
|
||||
boolean loaded;
|
||||
boolean hasNext;
|
||||
int nextSince = 0;
|
||||
long nextSince = 0;
|
||||
List<Message> messages = new ArrayList<>();
|
||||
}
|
||||
|
||||
@@ -6,8 +6,8 @@ import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
class MessageStateHolder {
|
||||
private int lastReceivedMessage = -1;
|
||||
private Map<Integer, MessageState> states = new HashMap<>();
|
||||
private long lastReceivedMessage = -1;
|
||||
private Map<Long, MessageState> states = new HashMap<>();
|
||||
|
||||
private MessageDeletion pendingDeletion = null;
|
||||
|
||||
@@ -15,7 +15,7 @@ class MessageStateHolder {
|
||||
states = new HashMap<>();
|
||||
}
|
||||
|
||||
synchronized void newMessages(Integer appId, PagedMessages pagedMessages) {
|
||||
synchronized void newMessages(Long appId, PagedMessages pagedMessages) {
|
||||
MessageState state = state(appId);
|
||||
|
||||
if (!state.loaded && pagedMessages.getMessages().size() > 0) {
|
||||
@@ -49,7 +49,7 @@ class MessageStateHolder {
|
||||
if (deletion != null) deleteMessage(deletion.getMessage());
|
||||
}
|
||||
|
||||
synchronized MessageState state(Integer appId) {
|
||||
synchronized MessageState state(Long appId) {
|
||||
MessageState state = states.get(appId);
|
||||
if (state == null) {
|
||||
return emptyState(appId);
|
||||
@@ -57,14 +57,14 @@ class MessageStateHolder {
|
||||
return state;
|
||||
}
|
||||
|
||||
synchronized void deleteAll(Integer appId) {
|
||||
synchronized void deleteAll(Long appId) {
|
||||
clear();
|
||||
MessageState state = state(appId);
|
||||
state.loaded = true;
|
||||
states.put(appId, state);
|
||||
}
|
||||
|
||||
private MessageState emptyState(Integer appId) {
|
||||
private MessageState emptyState(Long appId) {
|
||||
MessageState emptyState = new MessageState();
|
||||
emptyState.loaded = false;
|
||||
emptyState.hasNext = false;
|
||||
@@ -73,7 +73,7 @@ class MessageStateHolder {
|
||||
return emptyState;
|
||||
}
|
||||
|
||||
synchronized int getLastReceivedMessage() {
|
||||
synchronized long getLastReceivedMessage() {
|
||||
return lastReceivedMessage;
|
||||
}
|
||||
|
||||
|
||||
@@ -32,7 +32,7 @@ public class PicassoHandler {
|
||||
private Cache picassoCache;
|
||||
|
||||
private Picasso picasso;
|
||||
private Map<Integer, String> appIdToAppImage = new ConcurrentHashMap<>();
|
||||
private Map<Long, String> appIdToAppImage = new ConcurrentHashMap<>();
|
||||
|
||||
public PicassoHandler(Context context, Settings settings) {
|
||||
this.context = context;
|
||||
@@ -53,7 +53,7 @@ public class PicassoHandler {
|
||||
return new Picasso.Builder(context).downloader(downloader).build();
|
||||
}
|
||||
|
||||
public Bitmap getIcon(Integer appId) {
|
||||
public Bitmap getIcon(Long appId) {
|
||||
if (appId == -1) {
|
||||
return BitmapFactory.decodeResource(context.getResources(), R.drawable.gotify);
|
||||
}
|
||||
|
||||
@@ -33,19 +33,19 @@ import com.github.gotify.messages.MessagesActivity;
|
||||
import com.github.gotify.picasso.PicassoHandler;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import java.util.concurrent.atomic.AtomicLong;
|
||||
|
||||
public class WebSocketService extends Service {
|
||||
|
||||
public static final String NEW_MESSAGE_BROADCAST =
|
||||
WebSocketService.class.getName() + ".NEW_MESSAGE";
|
||||
|
||||
private static final int NOT_LOADED = -2;
|
||||
private static final long NOT_LOADED = -2;
|
||||
|
||||
private Settings settings;
|
||||
private WebSocketConnection connection;
|
||||
|
||||
private AtomicInteger lastReceivedMessage = new AtomicInteger(NOT_LOADED);
|
||||
private AtomicLong lastReceivedMessage = new AtomicLong(NOT_LOADED);
|
||||
private MissedMessageUtil missingMessageUtil;
|
||||
|
||||
private PicassoHandler picassoHandler;
|
||||
@@ -143,7 +143,7 @@ public class WebSocketService extends Service {
|
||||
}
|
||||
|
||||
private void notifyMissedNotifications() {
|
||||
int messageId = lastReceivedMessage.get();
|
||||
long messageId = lastReceivedMessage.get();
|
||||
if (messageId == NOT_LOADED) {
|
||||
return;
|
||||
}
|
||||
@@ -231,16 +231,16 @@ public class WebSocketService extends Service {
|
||||
|
||||
private void showNotification(
|
||||
int id, String title, String message, long priority, Map<String, Object> extras) {
|
||||
showNotification(id, title, message, priority, extras, -1);
|
||||
showNotification(id, title, message, priority, extras, -1L);
|
||||
}
|
||||
|
||||
private void showNotification(
|
||||
int id,
|
||||
long id,
|
||||
String title,
|
||||
String message,
|
||||
long priority,
|
||||
Map<String, Object> extras,
|
||||
Integer appid) {
|
||||
Long appid) {
|
||||
|
||||
Intent intent;
|
||||
|
||||
@@ -293,7 +293,7 @@ public class WebSocketService extends Service {
|
||||
|
||||
NotificationManager notificationManager =
|
||||
(NotificationManager) this.getSystemService(Context.NOTIFICATION_SERVICE);
|
||||
notificationManager.notify(id, b.build());
|
||||
notificationManager.notify(Utils.longToInt(id), b.build());
|
||||
}
|
||||
|
||||
@RequiresApi(Build.VERSION_CODES.N)
|
||||
|
||||
Reference in New Issue
Block a user