From 735c96d0a0fc75323b461c9c20ac9c298064e6f1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20N=C3=BCsse?= Date: Mon, 20 Apr 2020 18:44:23 +0200 Subject: [PATCH 01/13] Show Appicon in notification --- .../gotify/messages/MessagesActivity.java | 2 +- .../provider/MessageImageCombiner.java | 4 +- .../gotify/service/WebSocketService.java | 90 +++++++++++++++++-- 3 files changed, 86 insertions(+), 10 deletions(-) diff --git a/app/src/main/java/com/github/gotify/messages/MessagesActivity.java b/app/src/main/java/com/github/gotify/messages/MessagesActivity.java index ad53830a..38317cb1 100644 --- a/app/src/main/java/com/github/gotify/messages/MessagesActivity.java +++ b/app/src/main/java/com/github/gotify/messages/MessagesActivity.java @@ -120,7 +120,7 @@ public void onReceive(Context context, Intent intent) { private boolean isLoadMore = false; private Integer selectAppIdOnDrawerClose = null; - int PICASSO_CACHE_SIZE = 50 * 1024 * 1024; // 50 MB + public static int PICASSO_CACHE_SIZE = 50 * 1024 * 1024; // 50 MB private Cache picassoCache; private Picasso picasso; diff --git a/app/src/main/java/com/github/gotify/messages/provider/MessageImageCombiner.java b/app/src/main/java/com/github/gotify/messages/provider/MessageImageCombiner.java index 4a145f66..ee37d221 100644 --- a/app/src/main/java/com/github/gotify/messages/provider/MessageImageCombiner.java +++ b/app/src/main/java/com/github/gotify/messages/provider/MessageImageCombiner.java @@ -7,7 +7,7 @@ import java.util.List; import java.util.Map; -class MessageImageCombiner { +public class MessageImageCombiner { List combine(List messages, List applications) { Map appIdToImage = appIdToImage(applications); @@ -26,7 +26,7 @@ List combine(List messages, List applica return result; } - private Map appIdToImage(List applications) { + public static Map appIdToImage(List applications) { Map map = new HashMap<>(); for (Application app : applications) { map.put(app.getId(), app.getImage()); diff --git a/app/src/main/java/com/github/gotify/service/WebSocketService.java b/app/src/main/java/com/github/gotify/service/WebSocketService.java index 480fc01f..3a52005b 100644 --- a/app/src/main/java/com/github/gotify/service/WebSocketService.java +++ b/app/src/main/java/com/github/gotify/service/WebSocketService.java @@ -7,6 +7,8 @@ import android.content.Context; import android.content.Intent; import android.content.IntentFilter; +import android.graphics.Bitmap; +import android.graphics.BitmapFactory; import android.graphics.Color; import android.net.ConnectivityManager; import android.net.Uri; @@ -21,18 +23,32 @@ import com.github.gotify.R; import com.github.gotify.Settings; import com.github.gotify.Utils; +import com.github.gotify.api.CertUtils; import com.github.gotify.api.ClientFactory; +import com.github.gotify.client.ApiClient; +import com.github.gotify.client.api.ApplicationApi; import com.github.gotify.client.api.MessageApi; +import com.github.gotify.client.model.Application; import com.github.gotify.client.model.Message; import com.github.gotify.log.Log; import com.github.gotify.log.UncaughtExceptionHandler; import com.github.gotify.messages.Extras; import com.github.gotify.messages.MessagesActivity; +import com.github.gotify.messages.provider.MessageImageCombiner; +import com.squareup.picasso.OkHttp3Downloader; +import com.squareup.picasso.Picasso; +import com.squareup.picasso.RequestCreator; + +import java.io.File; +import java.io.IOException; import java.util.List; import java.util.Map; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicInteger; +import okhttp3.Cache; +import okhttp3.OkHttpClient; + public class WebSocketService extends Service { public static final String NEW_MESSAGE_BROADCAST = @@ -46,16 +62,17 @@ public class WebSocketService extends Service { private AtomicInteger lastReceivedMessage = new AtomicInteger(NOT_LOADED); private MissedMessageUtil missingMessageUtil; + private Picasso cache; + private Map appIdMap; + @Override public void onCreate() { super.onCreate(); settings = new Settings(this); - missingMessageUtil = - new MissedMessageUtil( - ClientFactory.clientToken( - settings.url(), settings.sslSettings(), settings.token()) - .createService(MessageApi.class)); + ApiClient client = ClientFactory.clientToken(settings.url(), settings.sslSettings(), settings.token()); + missingMessageUtil = new MissedMessageUtil(client .createService(MessageApi.class)); Log.i("Create " + getClass().getSimpleName()); + cache = makePicasso(); } @Override @@ -110,6 +127,18 @@ private void startPushService() { intentFilter.addAction(ConnectivityManager.CONNECTIVITY_ACTION); ReconnectListener receiver = new ReconnectListener(this::doReconnect); registerReceiver(receiver, intentFilter); + + Thread thread = new Thread(new Runnable() { + @Override + public void run() { + try { + updateAppIds(); + } catch (Exception e) { + e.printStackTrace(); + } + } + }); + thread.start(); } private void onDisconnect() { @@ -171,13 +200,15 @@ private void onMessage(Message message) { if (lastReceivedMessage.get() < message.getId()) { lastReceivedMessage.set(message.getId()); } + broadcast(message); showNotification( message.getId(), message.getTitle(), message.getMessage(), message.getPriority(), - message.getExtras()); + message.getExtras(), + message.getAppid()); } private void broadcast(Message message) { @@ -217,8 +248,12 @@ private void foreground(String message) { startForeground(NotificationSupport.ID.FOREGROUND, notification); } + private void showNotification(int id, String title, String message, long priority, Map extras) { + showNotification(id, title, message, priority, extras, -1); + } + private void showNotification( - int id, String title, String message, long priority, Map extras) { + int id, String title, String message, long priority, Map extras, Integer appid) { Intent intent; @@ -258,6 +293,7 @@ private void showNotification( .setDefaults(Notification.DEFAULT_ALL) .setWhen(System.currentTimeMillis()) .setSmallIcon(R.drawable.ic_gotify) + .setLargeIcon(getIcon(appid)) .setTicker(getString(R.string.app_name) + " - " + title) .setGroup(NotificationSupport.Group.MESSAGES) .setContentTitle(title) @@ -300,4 +336,44 @@ public void showNotificationGroup(long priority) { (NotificationManager) this.getSystemService(Context.NOTIFICATION_SERVICE); notificationManager.notify(-5, b.build()); } + + private Bitmap getIcon(Integer appid) { + + if(appid==-1){ + return BitmapFactory.decodeResource(getResources(), R.drawable.gotify); + } + + Bitmap icon; + RequestCreator request; + try { + request= cache.load(Utils.resolveAbsoluteUrl(settings.url() + "/", appIdMap.get(appid))); + icon = request.get(); + } catch (IOException e) { + icon = BitmapFactory.decodeResource(getResources(), R.drawable.gotify); + } + + return icon; + } + + private Picasso makePicasso() { + Cache picassoCache = new Cache(new File(getCacheDir(), "picasso-cache"), MessagesActivity.PICASSO_CACHE_SIZE); + OkHttpClient.Builder builder = new OkHttpClient.Builder(); + builder.cache(picassoCache); + CertUtils.applySslSettings(builder, settings.sslSettings()); + OkHttp3Downloader downloader = new OkHttp3Downloader(builder.build()); + return new Picasso.Builder(this).downloader(downloader).build(); + } + + private void updateAppIds(){ + ApiClient client = ClientFactory.clientToken(settings.url(), settings.sslSettings(), settings.token()); + + List applications = null; + try { + applications = client.createService(ApplicationApi.class).getApps().execute().body(); + appIdMap = MessageImageCombiner.appIdToImage(applications); + } catch (IOException e) { + e.printStackTrace(); + } + + } } From 4bbb31ac764000805d9ca6760ecdb8e75e1a1e60 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20N=C3=BCsse?= Date: Wed, 29 Apr 2020 12:35:13 +0200 Subject: [PATCH 02/13] reduce allocated variables --- .../com/github/gotify/service/WebSocketService.java | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/app/src/main/java/com/github/gotify/service/WebSocketService.java b/app/src/main/java/com/github/gotify/service/WebSocketService.java index 3a52005b..fc267414 100644 --- a/app/src/main/java/com/github/gotify/service/WebSocketService.java +++ b/app/src/main/java/com/github/gotify/service/WebSocketService.java @@ -343,16 +343,12 @@ private Bitmap getIcon(Integer appid) { return BitmapFactory.decodeResource(getResources(), R.drawable.gotify); } - Bitmap icon; - RequestCreator request; try { - request= cache.load(Utils.resolveAbsoluteUrl(settings.url() + "/", appIdMap.get(appid))); - icon = request.get(); + return cache.load(Utils.resolveAbsoluteUrl(settings.url() + "/", appIdMap.get(appid))).get(); } catch (IOException e) { - icon = BitmapFactory.decodeResource(getResources(), R.drawable.gotify); + com.github.gotify.log.Log.e("java.lang.String", e); } - - return icon; + return BitmapFactory.decodeResource(getResources(), R.drawable.gotify); } private Picasso makePicasso() { @@ -374,6 +370,5 @@ private void updateAppIds(){ } catch (IOException e) { e.printStackTrace(); } - } } From 84554861175b0376dfce9dbf02be81007433ec9d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20N=C3=BCsse?= Date: Wed, 29 Apr 2020 12:37:19 +0200 Subject: [PATCH 03/13] rename cache to picasso --- .../java/com/github/gotify/service/WebSocketService.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/com/github/gotify/service/WebSocketService.java b/app/src/main/java/com/github/gotify/service/WebSocketService.java index fc267414..0c043049 100644 --- a/app/src/main/java/com/github/gotify/service/WebSocketService.java +++ b/app/src/main/java/com/github/gotify/service/WebSocketService.java @@ -62,7 +62,7 @@ public class WebSocketService extends Service { private AtomicInteger lastReceivedMessage = new AtomicInteger(NOT_LOADED); private MissedMessageUtil missingMessageUtil; - private Picasso cache; + private Picasso picasso; private Map appIdMap; @Override @@ -72,7 +72,7 @@ public void onCreate() { ApiClient client = ClientFactory.clientToken(settings.url(), settings.sslSettings(), settings.token()); missingMessageUtil = new MissedMessageUtil(client .createService(MessageApi.class)); Log.i("Create " + getClass().getSimpleName()); - cache = makePicasso(); + picasso = makePicasso(); } @Override @@ -344,7 +344,7 @@ private Bitmap getIcon(Integer appid) { } try { - return cache.load(Utils.resolveAbsoluteUrl(settings.url() + "/", appIdMap.get(appid))).get(); + return picasso.load(Utils.resolveAbsoluteUrl(settings.url() + "/", appIdMap.get(appid))).get(); } catch (IOException e) { com.github.gotify.log.Log.e("java.lang.String", e); } From 33dbfafaa556b9f6bbd290e9e86997d330739b20 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20N=C3=BCsse?= Date: Wed, 29 Apr 2020 12:39:07 +0200 Subject: [PATCH 04/13] fix error message in log.e() --- .../main/java/com/github/gotify/service/WebSocketService.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/java/com/github/gotify/service/WebSocketService.java b/app/src/main/java/com/github/gotify/service/WebSocketService.java index 0c043049..437e9cad 100644 --- a/app/src/main/java/com/github/gotify/service/WebSocketService.java +++ b/app/src/main/java/com/github/gotify/service/WebSocketService.java @@ -346,7 +346,7 @@ private Bitmap getIcon(Integer appid) { try { return picasso.load(Utils.resolveAbsoluteUrl(settings.url() + "/", appIdMap.get(appid))).get(); } catch (IOException e) { - com.github.gotify.log.Log.e("java.lang.String", e); + com.github.gotify.log.Log.e("Could not load image for notification", e); } return BitmapFactory.decodeResource(getResources(), R.drawable.gotify); } From b6a1bf334bc70cf73a7d2a7c05bb0d02f725c5da Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20N=C3=BCsse?= Date: Mon, 1 Jun 2020 20:23:14 +0200 Subject: [PATCH 05/13] moved picasso to handlerclass --- .../com/github/gotify/PicassoHandler.java | 131 ++++++++++++++++++ .../gotify/messages/MessagesActivity.java | 29 ++-- .../gotify/service/WebSocketService.java | 67 +-------- 3 files changed, 146 insertions(+), 81 deletions(-) create mode 100644 app/src/main/java/com/github/gotify/PicassoHandler.java diff --git a/app/src/main/java/com/github/gotify/PicassoHandler.java b/app/src/main/java/com/github/gotify/PicassoHandler.java new file mode 100644 index 00000000..472328cc --- /dev/null +++ b/app/src/main/java/com/github/gotify/PicassoHandler.java @@ -0,0 +1,131 @@ +package com.github.gotify; + +import android.content.Context; +import android.graphics.Bitmap; +import android.graphics.BitmapFactory; + +import com.github.gotify.api.CertUtils; +import com.github.gotify.api.ClientFactory; +import com.github.gotify.client.ApiClient; +import com.github.gotify.client.api.ApplicationApi; +import com.github.gotify.client.model.Application; +import com.github.gotify.messages.MessagesActivity; +import com.github.gotify.messages.provider.MessageImageCombiner; +import com.squareup.picasso.OkHttp3Downloader; +import com.squareup.picasso.Picasso; + +import java.io.File; +import java.io.IOException; +import java.util.List; +import java.util.Map; + +import okhttp3.Cache; +import okhttp3.OkHttpClient; + +/** + * Copyright (C) 2019 Felix Nüsse + * Created on 01.06.20 - 20:03 + *

+ * Edited by: Felix Nüsse felix.nuesse(at)t-online.de + *

+ * gotify-android + *

+ * This program is released under the GPLv3 license + *

+ *

+ * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + *

+ * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + *

+ * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ +public class PicassoHandler { + + public static int PICASSO_CACHE_SIZE = 50 * 1024 * 1024; // 50 MB + public static String PICASSO_CACHE_SUBFOLDER = "picasso-cache"; + + private Context context; + private Settings settings; + + private Cache picassoCache; + + private Picasso picasso; + private Map appIdMap; + + public PicassoHandler(Context context, Settings settings) { + this.context = context; + this.settings = settings; + + picasso = makePicasso(); + + } + + private void prepareCache(){ + if(picassoCache == null){ + picassoCache = new Cache(new File(context.getCacheDir(), PICASSO_CACHE_SUBFOLDER), PICASSO_CACHE_SIZE); + } + } + + private Picasso makePicasso() { + prepareCache(); + OkHttpClient.Builder builder = new OkHttpClient.Builder(); + builder.cache(picassoCache); + CertUtils.applySslSettings(builder, settings.sslSettings()); + OkHttp3Downloader downloader = new OkHttp3Downloader(builder.build()); + return new Picasso.Builder(context).downloader(downloader).build(); + } + + + public Bitmap getIcon(Integer appId) { + if(appId==-1){ + return BitmapFactory.decodeResource(context.getResources(), R.drawable.gotify); + } + + try { + return picasso.load(Utils.resolveAbsoluteUrl(settings.url() + "/", appIdMap.get(appId))).get(); + } catch (IOException e) { + com.github.gotify.log.Log.e("Could not load image for notification", e); + } + return BitmapFactory.decodeResource(context.getResources(), R.drawable.gotify); + } + + + public void updateAppIds(){ + Thread thread = new Thread(() -> { + try { + updateAppIds_nonasync(); + } catch (Exception e) { + e.printStackTrace(); + } + }); + thread.start(); + } + + private void updateAppIds_nonasync(){ + ApiClient client = ClientFactory.clientToken(settings.url(), settings.sslSettings(), settings.token()); + + List applications = null; + try { + applications = client.createService(ApplicationApi.class).getApps().execute().body(); + appIdMap = MessageImageCombiner.appIdToImage(applications); + } catch (IOException e) { + e.printStackTrace(); + } + } + + public Picasso exposedPicasso() { + return picasso; + } + + public void evict() throws IOException { + picassoCache.evictAll(); + } +} diff --git a/app/src/main/java/com/github/gotify/messages/MessagesActivity.java b/app/src/main/java/com/github/gotify/messages/MessagesActivity.java index 38317cb1..63312224 100644 --- a/app/src/main/java/com/github/gotify/messages/MessagesActivity.java +++ b/app/src/main/java/com/github/gotify/messages/MessagesActivity.java @@ -37,6 +37,7 @@ import butterknife.OnClick; import com.github.gotify.BuildConfig; import com.github.gotify.MissedMessageUtil; +import com.github.gotify.PicassoHandler; import com.github.gotify.R; import com.github.gotify.Settings; import com.github.gotify.Utils; @@ -74,6 +75,7 @@ import okhttp3.Cache; import okhttp3.OkHttpClient; +import static com.github.gotify.PicassoHandler.PICASSO_CACHE_SIZE; import static java.util.Collections.emptyList; public class MessagesActivity extends AppCompatActivity @@ -120,9 +122,8 @@ public void onReceive(Context context, Intent intent) { private boolean isLoadMore = false; private Integer selectAppIdOnDrawerClose = null; - public static int PICASSO_CACHE_SIZE = 50 * 1024 * 1024; // 50 MB - private Cache picassoCache; - private Picasso picasso; + //private Picasso picasso; + private PicassoHandler picassoHandler; // we need to keep the target references otherwise they get gc'ed before they can be called. @SuppressWarnings("MismatchedQueryAndUpdateOfCollection") @@ -136,8 +137,7 @@ protected void onCreate(Bundle savedInstanceState) { Log.i("Entering " + getClass().getSimpleName()); settings = new Settings(this); - picassoCache = new Cache(new File(getCacheDir(), "picasso-cache"), PICASSO_CACHE_SIZE); - picasso = makePicasso(); + picassoHandler = new PicassoHandler(this, settings); client = ClientFactory.clientToken(settings.url(), settings.sslSettings(), settings.token()); @@ -154,7 +154,7 @@ protected void onCreate(Bundle savedInstanceState) { messagesView.getContext(), layoutManager.getOrientation()); ListMessageAdapter adapter = new ListMessageAdapter( - this, settings, picasso, emptyList(), this::scheduleDeletion); + this, settings, picassoHandler.exposedPicasso(), emptyList(), this::scheduleDeletion); messagesView.addItemDecoration(dividerItemDecoration); messagesView.setHasFixedSize(true); @@ -197,7 +197,7 @@ public void onDrawerClosed(View drawerView) { public void onRefreshAll(View view) { try { - picassoCache.evictAll(); + picassoHandler.evict(); } catch (IOException e) { Log.e("Problem evicting Picasso cache", e); } @@ -231,7 +231,7 @@ protected void onUpdateApps(List applications) { item.setCheckable(true); Target t = Utils.toDrawable(getResources(), item::setIcon); targetReferences.add(t); - picasso.load(Utils.resolveAbsoluteUrl(settings.url() + "/", app.getImage())) + picassoHandler.exposedPicasso().load(Utils.resolveAbsoluteUrl(settings.url() + "/", app.getImage())) .error(R.drawable.ic_alarm) .placeholder(R.drawable.ic_placeholder) .resize(100, 100) @@ -239,17 +239,6 @@ protected void onUpdateApps(List applications) { } } - private Picasso makePicasso() { - OkHttpClient.Builder builder = new OkHttpClient.Builder(); - builder.cache(picassoCache); - - CertUtils.applySslSettings(builder, settings.sslSettings()); - - OkHttp3Downloader downloader = new OkHttp3Downloader(builder.build()); - - return new Picasso.Builder(this).downloader(downloader).build(); - } - private void initDrawer() { setSupportActionBar(toolbar); navigationView.setItemIconTintList(null); @@ -362,7 +351,7 @@ protected void onPause() { @Override protected void onDestroy() { super.onDestroy(); - picasso.shutdown(); + picassoHandler.exposedPicasso().shutdown(); } private void scheduleDeletion(int position, Message message, boolean listAnimation) { diff --git a/app/src/main/java/com/github/gotify/service/WebSocketService.java b/app/src/main/java/com/github/gotify/service/WebSocketService.java index 437e9cad..9cb39e81 100644 --- a/app/src/main/java/com/github/gotify/service/WebSocketService.java +++ b/app/src/main/java/com/github/gotify/service/WebSocketService.java @@ -7,8 +7,6 @@ import android.content.Context; import android.content.Intent; import android.content.IntentFilter; -import android.graphics.Bitmap; -import android.graphics.BitmapFactory; import android.graphics.Color; import android.net.ConnectivityManager; import android.net.Uri; @@ -20,34 +18,24 @@ import androidx.core.content.ContextCompat; import com.github.gotify.MissedMessageUtil; import com.github.gotify.NotificationSupport; +import com.github.gotify.PicassoHandler; import com.github.gotify.R; import com.github.gotify.Settings; import com.github.gotify.Utils; -import com.github.gotify.api.CertUtils; import com.github.gotify.api.ClientFactory; import com.github.gotify.client.ApiClient; -import com.github.gotify.client.api.ApplicationApi; import com.github.gotify.client.api.MessageApi; -import com.github.gotify.client.model.Application; import com.github.gotify.client.model.Message; import com.github.gotify.log.Log; import com.github.gotify.log.UncaughtExceptionHandler; import com.github.gotify.messages.Extras; import com.github.gotify.messages.MessagesActivity; -import com.github.gotify.messages.provider.MessageImageCombiner; -import com.squareup.picasso.OkHttp3Downloader; -import com.squareup.picasso.Picasso; -import com.squareup.picasso.RequestCreator; -import java.io.File; -import java.io.IOException; import java.util.List; import java.util.Map; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicInteger; -import okhttp3.Cache; -import okhttp3.OkHttpClient; public class WebSocketService extends Service { @@ -62,8 +50,8 @@ public class WebSocketService extends Service { private AtomicInteger lastReceivedMessage = new AtomicInteger(NOT_LOADED); private MissedMessageUtil missingMessageUtil; - private Picasso picasso; - private Map appIdMap; + private PicassoHandler picassoHandler; + @Override public void onCreate() { @@ -72,7 +60,7 @@ public void onCreate() { ApiClient client = ClientFactory.clientToken(settings.url(), settings.sslSettings(), settings.token()); missingMessageUtil = new MissedMessageUtil(client .createService(MessageApi.class)); Log.i("Create " + getClass().getSimpleName()); - picasso = makePicasso(); + picassoHandler = new PicassoHandler(this, settings); } @Override @@ -128,17 +116,7 @@ private void startPushService() { ReconnectListener receiver = new ReconnectListener(this::doReconnect); registerReceiver(receiver, intentFilter); - Thread thread = new Thread(new Runnable() { - @Override - public void run() { - try { - updateAppIds(); - } catch (Exception e) { - e.printStackTrace(); - } - } - }); - thread.start(); + picassoHandler.updateAppIds(); } private void onDisconnect() { @@ -293,7 +271,7 @@ private void showNotification( .setDefaults(Notification.DEFAULT_ALL) .setWhen(System.currentTimeMillis()) .setSmallIcon(R.drawable.ic_gotify) - .setLargeIcon(getIcon(appid)) + .setLargeIcon(picassoHandler.getIcon(appid)) .setTicker(getString(R.string.app_name) + " - " + title) .setGroup(NotificationSupport.Group.MESSAGES) .setContentTitle(title) @@ -337,38 +315,5 @@ public void showNotificationGroup(long priority) { notificationManager.notify(-5, b.build()); } - private Bitmap getIcon(Integer appid) { - - if(appid==-1){ - return BitmapFactory.decodeResource(getResources(), R.drawable.gotify); - } - - try { - return picasso.load(Utils.resolveAbsoluteUrl(settings.url() + "/", appIdMap.get(appid))).get(); - } catch (IOException e) { - com.github.gotify.log.Log.e("Could not load image for notification", e); - } - return BitmapFactory.decodeResource(getResources(), R.drawable.gotify); - } - private Picasso makePicasso() { - Cache picassoCache = new Cache(new File(getCacheDir(), "picasso-cache"), MessagesActivity.PICASSO_CACHE_SIZE); - OkHttpClient.Builder builder = new OkHttpClient.Builder(); - builder.cache(picassoCache); - CertUtils.applySslSettings(builder, settings.sslSettings()); - OkHttp3Downloader downloader = new OkHttp3Downloader(builder.build()); - return new Picasso.Builder(this).downloader(downloader).build(); - } - - private void updateAppIds(){ - ApiClient client = ClientFactory.clientToken(settings.url(), settings.sslSettings(), settings.token()); - - List applications = null; - try { - applications = client.createService(ApplicationApi.class).getApps().execute().body(); - appIdMap = MessageImageCombiner.appIdToImage(applications); - } catch (IOException e) { - e.printStackTrace(); - } - } } From 64245a7510e6341967ebff9ac44aac9c801aa862 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20N=C3=BCsse?= Date: Mon, 1 Jun 2020 20:30:26 +0200 Subject: [PATCH 06/13] move maps to hashmaps --- app/src/main/java/com/github/gotify/PicassoHandler.java | 7 ++++--- .../gotify/messages/provider/MessageImageCombiner.java | 4 ++-- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/com/github/gotify/PicassoHandler.java b/app/src/main/java/com/github/gotify/PicassoHandler.java index 472328cc..26a0f0bf 100644 --- a/app/src/main/java/com/github/gotify/PicassoHandler.java +++ b/app/src/main/java/com/github/gotify/PicassoHandler.java @@ -18,6 +18,7 @@ import java.io.IOException; import java.util.List; import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; import okhttp3.Cache; import okhttp3.OkHttpClient; @@ -58,7 +59,7 @@ public class PicassoHandler { private Cache picassoCache; private Picasso picasso; - private Map appIdMap; + private Map appIdToAppImage = new ConcurrentHashMap<>(); public PicassoHandler(Context context, Settings settings) { this.context = context; @@ -90,7 +91,7 @@ public Bitmap getIcon(Integer appId) { } try { - return picasso.load(Utils.resolveAbsoluteUrl(settings.url() + "/", appIdMap.get(appId))).get(); + return picasso.load(Utils.resolveAbsoluteUrl(settings.url() + "/", appIdToAppImage.get(appId))).get(); } catch (IOException e) { com.github.gotify.log.Log.e("Could not load image for notification", e); } @@ -115,7 +116,7 @@ private void updateAppIds_nonasync(){ List applications = null; try { applications = client.createService(ApplicationApi.class).getApps().execute().body(); - appIdMap = MessageImageCombiner.appIdToImage(applications); + appIdToAppImage = MessageImageCombiner.appIdToImage(applications); } catch (IOException e) { e.printStackTrace(); } diff --git a/app/src/main/java/com/github/gotify/messages/provider/MessageImageCombiner.java b/app/src/main/java/com/github/gotify/messages/provider/MessageImageCombiner.java index ee37d221..95cb18c9 100644 --- a/app/src/main/java/com/github/gotify/messages/provider/MessageImageCombiner.java +++ b/app/src/main/java/com/github/gotify/messages/provider/MessageImageCombiner.java @@ -3,9 +3,9 @@ import com.github.gotify.client.model.Application; import com.github.gotify.client.model.Message; import java.util.ArrayList; -import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; public class MessageImageCombiner { @@ -27,7 +27,7 @@ List combine(List messages, List applica } public static Map appIdToImage(List applications) { - Map map = new HashMap<>(); + Map map = new ConcurrentHashMap<>(); for (Application app : applications) { map.put(app.getId(), app.getImage()); } From d9be3e9e1faf7f5f0fabaf0a1a79e13ee3701d9d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20N=C3=BCsse?= Date: Mon, 1 Jun 2020 20:36:27 +0200 Subject: [PATCH 07/13] fix formatting and changed wrong gplv3 with proper mit license --- .../com/github/gotify/PicassoHandler.java | 76 ++++++++----------- .../gotify/messages/MessagesActivity.java | 19 +++-- .../gotify/service/WebSocketService.java | 20 ++--- 3 files changed, 51 insertions(+), 64 deletions(-) diff --git a/app/src/main/java/com/github/gotify/PicassoHandler.java b/app/src/main/java/com/github/gotify/PicassoHandler.java index 26a0f0bf..30397c51 100644 --- a/app/src/main/java/com/github/gotify/PicassoHandler.java +++ b/app/src/main/java/com/github/gotify/PicassoHandler.java @@ -3,50 +3,30 @@ import android.content.Context; import android.graphics.Bitmap; import android.graphics.BitmapFactory; - import com.github.gotify.api.CertUtils; import com.github.gotify.api.ClientFactory; import com.github.gotify.client.ApiClient; import com.github.gotify.client.api.ApplicationApi; import com.github.gotify.client.model.Application; -import com.github.gotify.messages.MessagesActivity; import com.github.gotify.messages.provider.MessageImageCombiner; import com.squareup.picasso.OkHttp3Downloader; import com.squareup.picasso.Picasso; - import java.io.File; import java.io.IOException; import java.util.List; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; - import okhttp3.Cache; import okhttp3.OkHttpClient; /** - * Copyright (C) 2019 Felix Nüsse - * Created on 01.06.20 - 20:03 - *

- * Edited by: Felix Nüsse felix.nuesse(at)t-online.de - *

- * gotify-android - *

- * This program is released under the GPLv3 license - *

- *

- * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 3 of the License, or - * (at your option) any later version. - *

- * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - *

- * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * Copyright (C) 2020 Felix Nüsse Created on 01.06.20 - 20:03 + * + *

Edited by: Felix Nüsse felix.nuesse(at)t-online.de + * + *

gotify-android + * + *

This program is released under the MIT License */ public class PicassoHandler { @@ -66,12 +46,14 @@ public PicassoHandler(Context context, Settings settings) { this.settings = settings; picasso = makePicasso(); - } - private void prepareCache(){ - if(picassoCache == null){ - picassoCache = new Cache(new File(context.getCacheDir(), PICASSO_CACHE_SUBFOLDER), PICASSO_CACHE_SIZE); + private void prepareCache() { + if (picassoCache == null) { + picassoCache = + new Cache( + new File(context.getCacheDir(), PICASSO_CACHE_SUBFOLDER), + PICASSO_CACHE_SIZE); } } @@ -84,34 +66,38 @@ private Picasso makePicasso() { return new Picasso.Builder(context).downloader(downloader).build(); } - public Bitmap getIcon(Integer appId) { - if(appId==-1){ + if (appId == -1) { return BitmapFactory.decodeResource(context.getResources(), R.drawable.gotify); } try { - return picasso.load(Utils.resolveAbsoluteUrl(settings.url() + "/", appIdToAppImage.get(appId))).get(); + return picasso.load( + Utils.resolveAbsoluteUrl( + settings.url() + "/", appIdToAppImage.get(appId))) + .get(); } catch (IOException e) { com.github.gotify.log.Log.e("Could not load image for notification", e); } return BitmapFactory.decodeResource(context.getResources(), R.drawable.gotify); } - - public void updateAppIds(){ - Thread thread = new Thread(() -> { - try { - updateAppIds_nonasync(); - } catch (Exception e) { - e.printStackTrace(); - } - }); + public void updateAppIds() { + Thread thread = + new Thread( + () -> { + try { + updateAppIds_nonasync(); + } catch (Exception e) { + e.printStackTrace(); + } + }); thread.start(); } - private void updateAppIds_nonasync(){ - ApiClient client = ClientFactory.clientToken(settings.url(), settings.sslSettings(), settings.token()); + private void updateAppIds_nonasync() { + ApiClient client = + ClientFactory.clientToken(settings.url(), settings.sslSettings(), settings.token()); List applications = null; try { diff --git a/app/src/main/java/com/github/gotify/messages/MessagesActivity.java b/app/src/main/java/com/github/gotify/messages/MessagesActivity.java index 63312224..3fc578c6 100644 --- a/app/src/main/java/com/github/gotify/messages/MessagesActivity.java +++ b/app/src/main/java/com/github/gotify/messages/MessagesActivity.java @@ -43,7 +43,6 @@ import com.github.gotify.Utils; import com.github.gotify.api.Api; import com.github.gotify.api.ApiException; -import com.github.gotify.api.CertUtils; import com.github.gotify.api.ClientFactory; import com.github.gotify.client.ApiClient; import com.github.gotify.client.api.ClientApi; @@ -64,18 +63,12 @@ import com.google.android.material.navigation.NavigationView; import com.google.android.material.snackbar.BaseTransientBottomBar; import com.google.android.material.snackbar.Snackbar; -import com.squareup.picasso.OkHttp3Downloader; -import com.squareup.picasso.Picasso; import com.squareup.picasso.Target; -import java.io.File; import java.io.IOException; import java.util.ArrayList; import java.util.Arrays; import java.util.List; -import okhttp3.Cache; -import okhttp3.OkHttpClient; -import static com.github.gotify.PicassoHandler.PICASSO_CACHE_SIZE; import static java.util.Collections.emptyList; public class MessagesActivity extends AppCompatActivity @@ -122,7 +115,7 @@ public void onReceive(Context context, Intent intent) { private boolean isLoadMore = false; private Integer selectAppIdOnDrawerClose = null; - //private Picasso picasso; + // private Picasso picasso; private PicassoHandler picassoHandler; // we need to keep the target references otherwise they get gc'ed before they can be called. @@ -154,7 +147,11 @@ protected void onCreate(Bundle savedInstanceState) { messagesView.getContext(), layoutManager.getOrientation()); ListMessageAdapter adapter = new ListMessageAdapter( - this, settings, picassoHandler.exposedPicasso(), emptyList(), this::scheduleDeletion); + this, + settings, + picassoHandler.exposedPicasso(), + emptyList(), + this::scheduleDeletion); messagesView.addItemDecoration(dividerItemDecoration); messagesView.setHasFixedSize(true); @@ -231,7 +228,9 @@ protected void onUpdateApps(List applications) { item.setCheckable(true); Target t = Utils.toDrawable(getResources(), item::setIcon); targetReferences.add(t); - picassoHandler.exposedPicasso().load(Utils.resolveAbsoluteUrl(settings.url() + "/", app.getImage())) + picassoHandler + .exposedPicasso() + .load(Utils.resolveAbsoluteUrl(settings.url() + "/", app.getImage())) .error(R.drawable.ic_alarm) .placeholder(R.drawable.ic_placeholder) .resize(100, 100) diff --git a/app/src/main/java/com/github/gotify/service/WebSocketService.java b/app/src/main/java/com/github/gotify/service/WebSocketService.java index 9cb39e81..7b305966 100644 --- a/app/src/main/java/com/github/gotify/service/WebSocketService.java +++ b/app/src/main/java/com/github/gotify/service/WebSocketService.java @@ -30,13 +30,11 @@ import com.github.gotify.log.UncaughtExceptionHandler; import com.github.gotify.messages.Extras; import com.github.gotify.messages.MessagesActivity; - import java.util.List; import java.util.Map; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicInteger; - public class WebSocketService extends Service { public static final String NEW_MESSAGE_BROADCAST = @@ -52,13 +50,13 @@ public class WebSocketService extends Service { private PicassoHandler picassoHandler; - @Override public void onCreate() { super.onCreate(); settings = new Settings(this); - ApiClient client = ClientFactory.clientToken(settings.url(), settings.sslSettings(), settings.token()); - missingMessageUtil = new MissedMessageUtil(client .createService(MessageApi.class)); + ApiClient client = + ClientFactory.clientToken(settings.url(), settings.sslSettings(), settings.token()); + missingMessageUtil = new MissedMessageUtil(client.createService(MessageApi.class)); Log.i("Create " + getClass().getSimpleName()); picassoHandler = new PicassoHandler(this, settings); } @@ -226,12 +224,18 @@ private void foreground(String message) { startForeground(NotificationSupport.ID.FOREGROUND, notification); } - private void showNotification(int id, String title, String message, long priority, Map extras) { + private void showNotification( + int id, String title, String message, long priority, Map extras) { showNotification(id, title, message, priority, extras, -1); } private void showNotification( - int id, String title, String message, long priority, Map extras, Integer appid) { + int id, + String title, + String message, + long priority, + Map extras, + Integer appid) { Intent intent; @@ -314,6 +318,4 @@ public void showNotificationGroup(long priority) { (NotificationManager) this.getSystemService(Context.NOTIFICATION_SERVICE); notificationManager.notify(-5, b.build()); } - - } From 916cfe90b820c3a08316c2d2f9d8cb147a13ba56 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20N=C3=BCsse?= Date: Thu, 4 Jun 2020 22:04:45 +0200 Subject: [PATCH 08/13] cleaned methods and improved performance --- .../com/github/gotify/PicassoHandler.java | 31 +++++++------------ .../gotify/messages/MessagesActivity.java | 6 ++-- 2 files changed, 15 insertions(+), 22 deletions(-) diff --git a/app/src/main/java/com/github/gotify/PicassoHandler.java b/app/src/main/java/com/github/gotify/PicassoHandler.java index 30397c51..b9c6e47c 100644 --- a/app/src/main/java/com/github/gotify/PicassoHandler.java +++ b/app/src/main/java/com/github/gotify/PicassoHandler.java @@ -8,6 +8,7 @@ import com.github.gotify.client.ApiClient; import com.github.gotify.client.api.ApplicationApi; import com.github.gotify.client.model.Application; +import com.github.gotify.log.Log; import com.github.gotify.messages.provider.MessageImageCombiner; import com.squareup.picasso.OkHttp3Downloader; import com.squareup.picasso.Picasso; @@ -45,20 +46,14 @@ public PicassoHandler(Context context, Settings settings) { this.context = context; this.settings = settings; + picassoCache = + new Cache( + new File(context.getCacheDir(), PICASSO_CACHE_SUBFOLDER), + PICASSO_CACHE_SIZE); picasso = makePicasso(); } - private void prepareCache() { - if (picassoCache == null) { - picassoCache = - new Cache( - new File(context.getCacheDir(), PICASSO_CACHE_SUBFOLDER), - PICASSO_CACHE_SIZE); - } - } - private Picasso makePicasso() { - prepareCache(); OkHttpClient.Builder builder = new OkHttpClient.Builder(); builder.cache(picassoCache); CertUtils.applySslSettings(builder, settings.sslSettings()); @@ -77,7 +72,7 @@ public Bitmap getIcon(Integer appId) { settings.url() + "/", appIdToAppImage.get(appId))) .get(); } catch (IOException e) { - com.github.gotify.log.Log.e("Could not load image for notification", e); + Log.e("Could not load image for notification", e); } return BitmapFactory.decodeResource(context.getResources(), R.drawable.gotify); } @@ -96,19 +91,17 @@ public void updateAppIds() { } private void updateAppIds_nonasync() { - ApiClient client = - ClientFactory.clientToken(settings.url(), settings.sslSettings(), settings.token()); - - List applications = null; try { - applications = client.createService(ApplicationApi.class).getApps().execute().body(); - appIdToAppImage = MessageImageCombiner.appIdToImage(applications); + ApiClient client = ClientFactory.clientToken(settings.url(), settings.sslSettings(), settings.token()); + List applications = client.createService(ApplicationApi.class).getApps().execute().body(); + appIdToAppImage.clear(); + appIdToAppImage.putAll(MessageImageCombiner.appIdToImage(applications)); } catch (IOException e) { - e.printStackTrace(); + Log.e("Could not update appids", e); } } - public Picasso exposedPicasso() { + public Picasso get() { return picasso; } diff --git a/app/src/main/java/com/github/gotify/messages/MessagesActivity.java b/app/src/main/java/com/github/gotify/messages/MessagesActivity.java index 3fc578c6..5306e381 100644 --- a/app/src/main/java/com/github/gotify/messages/MessagesActivity.java +++ b/app/src/main/java/com/github/gotify/messages/MessagesActivity.java @@ -149,7 +149,7 @@ protected void onCreate(Bundle savedInstanceState) { new ListMessageAdapter( this, settings, - picassoHandler.exposedPicasso(), + picassoHandler.get(), emptyList(), this::scheduleDeletion); @@ -229,7 +229,7 @@ protected void onUpdateApps(List applications) { Target t = Utils.toDrawable(getResources(), item::setIcon); targetReferences.add(t); picassoHandler - .exposedPicasso() + .get() .load(Utils.resolveAbsoluteUrl(settings.url() + "/", app.getImage())) .error(R.drawable.ic_alarm) .placeholder(R.drawable.ic_placeholder) @@ -350,7 +350,7 @@ protected void onPause() { @Override protected void onDestroy() { super.onDestroy(); - picassoHandler.exposedPicasso().shutdown(); + picassoHandler.get().shutdown(); } private void scheduleDeletion(int position, Message message, boolean listAnimation) { From 5c92b03d0a3e211ed857566fabcdf14e45391bea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20N=C3=BCsse?= Date: Thu, 4 Jun 2020 22:06:26 +0200 Subject: [PATCH 09/13] replace thread with enqueue --- .../com/github/gotify/PicassoHandler.java | 36 ++++++++----------- 1 file changed, 14 insertions(+), 22 deletions(-) diff --git a/app/src/main/java/com/github/gotify/PicassoHandler.java b/app/src/main/java/com/github/gotify/PicassoHandler.java index b9c6e47c..d8630e93 100644 --- a/app/src/main/java/com/github/gotify/PicassoHandler.java +++ b/app/src/main/java/com/github/gotify/PicassoHandler.java @@ -3,6 +3,8 @@ import android.content.Context; import android.graphics.Bitmap; import android.graphics.BitmapFactory; + +import com.github.gotify.api.Callback; import com.github.gotify.api.CertUtils; import com.github.gotify.api.ClientFactory; import com.github.gotify.client.ApiClient; @@ -77,28 +79,18 @@ public Bitmap getIcon(Integer appId) { return BitmapFactory.decodeResource(context.getResources(), R.drawable.gotify); } - public void updateAppIds() { - Thread thread = - new Thread( - () -> { - try { - updateAppIds_nonasync(); - } catch (Exception e) { - e.printStackTrace(); - } - }); - thread.start(); - } - - private void updateAppIds_nonasync() { - try { - ApiClient client = ClientFactory.clientToken(settings.url(), settings.sslSettings(), settings.token()); - List applications = client.createService(ApplicationApi.class).getApps().execute().body(); - appIdToAppImage.clear(); - appIdToAppImage.putAll(MessageImageCombiner.appIdToImage(applications)); - } catch (IOException e) { - Log.e("Could not update appids", e); - } + private void updateAppIds(){ + ClientFactory.clientToken(settings.url(), settings.sslSettings(), settings.token()) + .createService(ApplicationApi.class) + .getApps() + .enqueue(Callback.call( + (apps) -> { + appIdToAppImage.clear(); + appIdToAppImage.putAll(MessageImageCombiner.appIdToImage(apps)); + }, + (t) -> { + appIdToAppImage.clear(); + })); } public Picasso get() { From c1377f4ede5d91883e0c838b2d92f6670d57c84d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20N=C3=BCsse?= Date: Thu, 4 Jun 2020 22:07:18 +0200 Subject: [PATCH 10/13] apply spotless --- .../com/github/gotify/PicassoHandler.java | 23 ++++++++----------- .../gotify/messages/MessagesActivity.java | 6 +---- 2 files changed, 11 insertions(+), 18 deletions(-) diff --git a/app/src/main/java/com/github/gotify/PicassoHandler.java b/app/src/main/java/com/github/gotify/PicassoHandler.java index d8630e93..c2156a77 100644 --- a/app/src/main/java/com/github/gotify/PicassoHandler.java +++ b/app/src/main/java/com/github/gotify/PicassoHandler.java @@ -3,20 +3,16 @@ import android.content.Context; import android.graphics.Bitmap; import android.graphics.BitmapFactory; - import com.github.gotify.api.Callback; import com.github.gotify.api.CertUtils; import com.github.gotify.api.ClientFactory; -import com.github.gotify.client.ApiClient; import com.github.gotify.client.api.ApplicationApi; -import com.github.gotify.client.model.Application; import com.github.gotify.log.Log; import com.github.gotify.messages.provider.MessageImageCombiner; import com.squareup.picasso.OkHttp3Downloader; import com.squareup.picasso.Picasso; import java.io.File; import java.io.IOException; -import java.util.List; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; import okhttp3.Cache; @@ -79,18 +75,19 @@ public Bitmap getIcon(Integer appId) { return BitmapFactory.decodeResource(context.getResources(), R.drawable.gotify); } - private void updateAppIds(){ + private void updateAppIds() { ClientFactory.clientToken(settings.url(), settings.sslSettings(), settings.token()) .createService(ApplicationApi.class) .getApps() - .enqueue(Callback.call( - (apps) -> { - appIdToAppImage.clear(); - appIdToAppImage.putAll(MessageImageCombiner.appIdToImage(apps)); - }, - (t) -> { - appIdToAppImage.clear(); - })); + .enqueue( + Callback.call( + (apps) -> { + appIdToAppImage.clear(); + appIdToAppImage.putAll(MessageImageCombiner.appIdToImage(apps)); + }, + (t) -> { + appIdToAppImage.clear(); + })); } public Picasso get() { diff --git a/app/src/main/java/com/github/gotify/messages/MessagesActivity.java b/app/src/main/java/com/github/gotify/messages/MessagesActivity.java index 5306e381..c61a89ea 100644 --- a/app/src/main/java/com/github/gotify/messages/MessagesActivity.java +++ b/app/src/main/java/com/github/gotify/messages/MessagesActivity.java @@ -147,11 +147,7 @@ protected void onCreate(Bundle savedInstanceState) { messagesView.getContext(), layoutManager.getOrientation()); ListMessageAdapter adapter = new ListMessageAdapter( - this, - settings, - picassoHandler.get(), - emptyList(), - this::scheduleDeletion); + this, settings, picassoHandler.get(), emptyList(), this::scheduleDeletion); messagesView.addItemDecoration(dividerItemDecoration); messagesView.setHasFixedSize(true); From 362fd721ddc00562c7dfad46766d657a70ede3bf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20N=C3=BCsse?= Date: Thu, 4 Jun 2020 22:14:05 +0200 Subject: [PATCH 11/13] fix private access of public method --- app/src/main/java/com/github/gotify/PicassoHandler.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/java/com/github/gotify/PicassoHandler.java b/app/src/main/java/com/github/gotify/PicassoHandler.java index c2156a77..e72e7be7 100644 --- a/app/src/main/java/com/github/gotify/PicassoHandler.java +++ b/app/src/main/java/com/github/gotify/PicassoHandler.java @@ -75,7 +75,7 @@ public Bitmap getIcon(Integer appId) { return BitmapFactory.decodeResource(context.getResources(), R.drawable.gotify); } - private void updateAppIds() { + public void updateAppIds() { ClientFactory.clientToken(settings.url(), settings.sslSettings(), settings.token()) .createService(ApplicationApi.class) .getApps() From bab098d4e217513f02a8c0c8f50f301165738edf Mon Sep 17 00:00:00 2001 From: Jannis Mattheis Date: Sat, 13 Jun 2020 13:40:00 +0200 Subject: [PATCH 12/13] Move picasso and misc fixes --- .../com/github/gotify/messages/MessagesActivity.java | 4 +--- .../com/github/gotify/{ => picasso}/PicassoHandler.java | 9 ++++++--- .../java/com/github/gotify/service/WebSocketService.java | 2 +- 3 files changed, 8 insertions(+), 7 deletions(-) rename app/src/main/java/com/github/gotify/{ => picasso}/PicassoHandler.java (91%) diff --git a/app/src/main/java/com/github/gotify/messages/MessagesActivity.java b/app/src/main/java/com/github/gotify/messages/MessagesActivity.java index feb8f5b9..107f0dce 100644 --- a/app/src/main/java/com/github/gotify/messages/MessagesActivity.java +++ b/app/src/main/java/com/github/gotify/messages/MessagesActivity.java @@ -38,7 +38,6 @@ import butterknife.OnClick; import com.github.gotify.BuildConfig; import com.github.gotify.MissedMessageUtil; -import com.github.gotify.PicassoHandler; import com.github.gotify.R; import com.github.gotify.Settings; import com.github.gotify.Utils; @@ -60,7 +59,7 @@ import com.github.gotify.messages.provider.MessageFacade; import com.github.gotify.messages.provider.MessageState; import com.github.gotify.messages.provider.MessageWithImage; -import com.github.gotify.picasso.PicassoDataRequestHandler; +import com.github.gotify.picasso.PicassoHandler; import com.github.gotify.service.WebSocketService; import com.github.gotify.settings.SettingsActivity; import com.google.android.material.navigation.NavigationView; @@ -118,7 +117,6 @@ public void onReceive(Context context, Intent intent) { private boolean isLoadMore = false; private Integer selectAppIdOnDrawerClose = null; - // private Picasso picasso; private PicassoHandler picassoHandler; // we need to keep the target references otherwise they get gc'ed before they can be called. diff --git a/app/src/main/java/com/github/gotify/PicassoHandler.java b/app/src/main/java/com/github/gotify/picasso/PicassoHandler.java similarity index 91% rename from app/src/main/java/com/github/gotify/PicassoHandler.java rename to app/src/main/java/com/github/gotify/picasso/PicassoHandler.java index e72e7be7..12a65661 100644 --- a/app/src/main/java/com/github/gotify/PicassoHandler.java +++ b/app/src/main/java/com/github/gotify/picasso/PicassoHandler.java @@ -1,8 +1,11 @@ -package com.github.gotify; +package com.github.gotify.picasso; import android.content.Context; import android.graphics.Bitmap; import android.graphics.BitmapFactory; +import com.github.gotify.R; +import com.github.gotify.Settings; +import com.github.gotify.Utils; import com.github.gotify.api.Callback; import com.github.gotify.api.CertUtils; import com.github.gotify.api.ClientFactory; @@ -29,8 +32,8 @@ */ public class PicassoHandler { - public static int PICASSO_CACHE_SIZE = 50 * 1024 * 1024; // 50 MB - public static String PICASSO_CACHE_SUBFOLDER = "picasso-cache"; + private static final int PICASSO_CACHE_SIZE = 50 * 1024 * 1024; // 50 MB + private static final String PICASSO_CACHE_SUBFOLDER = "picasso-cache"; private Context context; private Settings settings; diff --git a/app/src/main/java/com/github/gotify/service/WebSocketService.java b/app/src/main/java/com/github/gotify/service/WebSocketService.java index 7b305966..5ebbf1d5 100644 --- a/app/src/main/java/com/github/gotify/service/WebSocketService.java +++ b/app/src/main/java/com/github/gotify/service/WebSocketService.java @@ -18,7 +18,6 @@ import androidx.core.content.ContextCompat; import com.github.gotify.MissedMessageUtil; import com.github.gotify.NotificationSupport; -import com.github.gotify.PicassoHandler; import com.github.gotify.R; import com.github.gotify.Settings; import com.github.gotify.Utils; @@ -30,6 +29,7 @@ import com.github.gotify.log.UncaughtExceptionHandler; import com.github.gotify.messages.Extras; import com.github.gotify.messages.MessagesActivity; +import com.github.gotify.picasso.PicassoHandler; import java.util.List; import java.util.Map; import java.util.concurrent.TimeUnit; From 70082fe526404266cdf3b05df51a682e554554c0 Mon Sep 17 00:00:00 2001 From: fn Date: Sun, 14 Jun 2020 00:07:07 +0200 Subject: [PATCH 13/13] Remove license-header --- .../java/com/github/gotify/picasso/PicassoHandler.java | 9 --------- 1 file changed, 9 deletions(-) diff --git a/app/src/main/java/com/github/gotify/picasso/PicassoHandler.java b/app/src/main/java/com/github/gotify/picasso/PicassoHandler.java index 12a65661..c2f07174 100644 --- a/app/src/main/java/com/github/gotify/picasso/PicassoHandler.java +++ b/app/src/main/java/com/github/gotify/picasso/PicassoHandler.java @@ -21,15 +21,6 @@ import okhttp3.Cache; import okhttp3.OkHttpClient; -/** - * Copyright (C) 2020 Felix Nüsse Created on 01.06.20 - 20:03 - * - *

Edited by: Felix Nüsse felix.nuesse(at)t-online.de - * - *

gotify-android - * - *

This program is released under the MIT License - */ public class PicassoHandler { private static final int PICASSO_CACHE_SIZE = 50 * 1024 * 1024; // 50 MB