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