From 32e6347d5bedd42ce270c3313e219c026fbfd9f5 Mon Sep 17 00:00:00 2001 From: p1gp1g Date: Sun, 3 Jan 2021 23:28:06 +0100 Subject: [PATCH 1/4] delete app --- .../gotify/messages/MessagesActivity.java | 33 +++++++++++++++++++ app/src/main/res/menu/messages_action.xml | 4 +++ app/src/main/res/values/strings.xml | 1 + 3 files changed, 38 insertions(+) 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 0b680a1b..854fb14e 100644 --- a/app/src/main/java/com/github/gotify/messages/MessagesActivity.java +++ b/app/src/main/java/com/github/gotify/messages/MessagesActivity.java @@ -45,6 +45,7 @@ import com.github.gotify.api.ApiException; 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.ClientApi; import com.github.gotify.client.api.MessageApi; import com.github.gotify.client.model.Application; @@ -171,6 +172,7 @@ public void onDrawerClosed(View drawerView) { new SelectApplicationAndUpdateMessages(true) .execute(selectAppIdOnDrawerClose); selectAppIdOnDrawerClose = null; + invalidateOptionsMenu(); } } }); @@ -192,6 +194,10 @@ public void onDrawerClosed(View drawerView) { } public void onRefreshAll(View view) { + refreshAll(); + } + + public void refreshAll(){ try { picassoHandler.evict(); } catch (IOException e) { @@ -560,6 +566,7 @@ protected void onPostExecute(Boolean update) { @Override public boolean onCreateOptionsMenu(Menu menu) { getMenuInflater().inflate(R.menu.messages_action, menu); + menu.findItem(R.id.action_delete_app).setVisible(appId != MessageState.ALL_MESSAGES); return super.onCreateOptionsMenu(menu); } @@ -568,9 +575,35 @@ public boolean onOptionsItemSelected(MenuItem item) { if (item.getItemId() == R.id.action_delete_all) { new DeleteMessages().execute(appId); } + if (item.getItemId() == R.id.action_delete_app) { + Thread thread = new Thread(new Runnable() { + @Override + public void run() { + deleteApp(appId); + } + }); + thread.start(); + try { + thread.join(); + } catch (InterruptedException e) { + e.printStackTrace(); + } + refreshAll(); + } return super.onContextItemSelected(item); } + + private void deleteApp(Long appId){ + ApiClient client = ClientFactory.clientToken(settings.url(), settings.sslSettings(), settings.token()); + try { + Log.i("Deleting app with appId=" + appId); + Api.execute(client.createService(ApplicationApi.class).deleteApp(appId)); + } catch (ApiException e) { + Log.e("Could not delete app.", e); + } + } + private class LoadMore extends AsyncTask> { @Override diff --git a/app/src/main/res/menu/messages_action.xml b/app/src/main/res/menu/messages_action.xml index 3aa89356..5382c587 100644 --- a/app/src/main/res/menu/messages_action.xml +++ b/app/src/main/res/menu/messages_action.xml @@ -3,4 +3,8 @@ android:title="@string/delete_all" android:id="@+id/action_delete_all" android:orderInCategory="100"/> + \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 39c28489..8bc53a29 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -25,6 +25,7 @@ Connection closed, trying to establish a new one. Received %d messages while being disconnected Delete all + Delete this application Delete logs Copy logs Logs copied From a4cabca414cea19ae193b550ffe7687b26adbbc6 Mon Sep 17 00:00:00 2001 From: p1gp1g Date: Sun, 3 Jan 2021 23:48:03 +0100 Subject: [PATCH 2/4] ack to delete app --- .../gotify/messages/MessagesActivity.java | 45 ++++++++++++------- 1 file changed, 30 insertions(+), 15 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 854fb14e..1c06af32 100644 --- a/app/src/main/java/com/github/gotify/messages/MessagesActivity.java +++ b/app/src/main/java/com/github/gotify/messages/MessagesActivity.java @@ -576,32 +576,47 @@ public boolean onOptionsItemSelected(MenuItem item) { new DeleteMessages().execute(appId); } if (item.getItemId() == R.id.action_delete_app) { - Thread thread = new Thread(new Runnable() { + android.app.AlertDialog.Builder alert = new android.app.AlertDialog.Builder( + this); + alert.setTitle(R.string.delete_app); + alert.setMessage("Are you sure?"); + alert.setPositiveButton("YES", new DialogInterface.OnClickListener() { @Override - public void run() { + public void onClick(DialogInterface dialog, int which) { deleteApp(appId); } }); - thread.start(); - try { - thread.join(); - } catch (InterruptedException e) { - e.printStackTrace(); - } - refreshAll(); + alert.setNegativeButton("NO", new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { + } + }); + alert.show(); } return super.onContextItemSelected(item); } - private void deleteApp(Long appId){ - ApiClient client = ClientFactory.clientToken(settings.url(), settings.sslSettings(), settings.token()); + private void deleteApp(Long appId) { + Thread thread = new Thread(new Runnable() { + @Override + public void run() { + ApiClient client = ClientFactory.clientToken(settings.url(), settings.sslSettings(), settings.token()); + try { + Log.i("Deleting app with appId=" + appId); + Api.execute(client.createService(ApplicationApi.class).deleteApp(appId)); + } catch (ApiException e) { + Log.e("Could not delete app.", e); + } + } + }); + thread.start(); try { - Log.i("Deleting app with appId=" + appId); - Api.execute(client.createService(ApplicationApi.class).deleteApp(appId)); - } catch (ApiException e) { - Log.e("Could not delete app.", e); + thread.join(); + } catch (InterruptedException e) { + e.printStackTrace(); } + refreshAll(); } private class LoadMore extends AsyncTask> { From 94045b4cd555c7a7341166e1eadca28716e85d52 Mon Sep 17 00:00:00 2001 From: p1gp1g Date: Mon, 4 Jan 2021 00:05:52 +0100 Subject: [PATCH 3/4] spotless --- .../gotify/messages/MessagesActivity.java | 63 +++++++++++-------- 1 file changed, 36 insertions(+), 27 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 1c06af32..f461360c 100644 --- a/app/src/main/java/com/github/gotify/messages/MessagesActivity.java +++ b/app/src/main/java/com/github/gotify/messages/MessagesActivity.java @@ -197,7 +197,7 @@ public void onRefreshAll(View view) { refreshAll(); } - public void refreshAll(){ + public void refreshAll() { try { picassoHandler.evict(); } catch (IOException e) { @@ -576,40 +576,49 @@ public boolean onOptionsItemSelected(MenuItem item) { new DeleteMessages().execute(appId); } if (item.getItemId() == R.id.action_delete_app) { - android.app.AlertDialog.Builder alert = new android.app.AlertDialog.Builder( - this); + android.app.AlertDialog.Builder alert = new android.app.AlertDialog.Builder(this); alert.setTitle(R.string.delete_app); alert.setMessage("Are you sure?"); - alert.setPositiveButton("YES", new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialog, int which) { - deleteApp(appId); - } - }); - alert.setNegativeButton("NO", new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialog, int which) { - } - }); + alert.setPositiveButton( + "YES", + new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { + deleteApp(appId); + } + }); + alert.setNegativeButton( + "NO", + new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) {} + }); alert.show(); } return super.onContextItemSelected(item); } - private void deleteApp(Long appId) { - Thread thread = new Thread(new Runnable() { - @Override - public void run() { - ApiClient client = ClientFactory.clientToken(settings.url(), settings.sslSettings(), settings.token()); - try { - Log.i("Deleting app with appId=" + appId); - Api.execute(client.createService(ApplicationApi.class).deleteApp(appId)); - } catch (ApiException e) { - Log.e("Could not delete app.", e); - } - } - }); + Thread thread = + new Thread( + new Runnable() { + @Override + public void run() { + ApiClient client = + ClientFactory.clientToken( + settings.url(), + settings.sslSettings(), + settings.token()); + try { + Log.i("Deleting app with appId=" + appId); + Api.execute( + client.createService(ApplicationApi.class) + .deleteApp(appId)); + } catch (ApiException e) { + Log.e("Could not delete app.", e); + } + } + }); thread.start(); try { thread.join(); From 39c43cb9b155833ee0e610ec3abaddfc0b8cd98b Mon Sep 17 00:00:00 2001 From: p1gp1g Date: Mon, 4 Jan 2021 15:49:47 +0100 Subject: [PATCH 4/4] requested changes --- .../gotify/messages/MessagesActivity.java | 58 +++++-------------- app/src/main/res/values/strings.xml | 3 + 2 files changed, 19 insertions(+), 42 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 f461360c..07ea9a51 100644 --- a/app/src/main/java/com/github/gotify/messages/MessagesActivity.java +++ b/app/src/main/java/com/github/gotify/messages/MessagesActivity.java @@ -43,6 +43,7 @@ import com.github.gotify.Utils; import com.github.gotify.api.Api; import com.github.gotify.api.ApiException; +import com.github.gotify.api.Callback; import com.github.gotify.api.ClientFactory; import com.github.gotify.client.ApiClient; import com.github.gotify.client.api.ApplicationApi; @@ -578,54 +579,27 @@ public boolean onOptionsItemSelected(MenuItem item) { if (item.getItemId() == R.id.action_delete_app) { android.app.AlertDialog.Builder alert = new android.app.AlertDialog.Builder(this); alert.setTitle(R.string.delete_app); - alert.setMessage("Are you sure?"); - alert.setPositiveButton( - "YES", - new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialog, int which) { - deleteApp(appId); - } - }); - alert.setNegativeButton( - "NO", - new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialog, int which) {} - }); + alert.setMessage(R.string.ack); + alert.setPositiveButton(R.string.yes, (dialog, which) -> deleteApp(appId)); + alert.setNegativeButton(R.string.no, (dialog, which) -> dialog.dismiss()); alert.show(); } return super.onContextItemSelected(item); } private void deleteApp(Long appId) { - Thread thread = - new Thread( - new Runnable() { - @Override - public void run() { - ApiClient client = - ClientFactory.clientToken( - settings.url(), - settings.sslSettings(), - settings.token()); - try { - Log.i("Deleting app with appId=" + appId); - Api.execute( - client.createService(ApplicationApi.class) - .deleteApp(appId)); - } catch (ApiException e) { - Log.e("Could not delete app.", e); - } - } - }); - thread.start(); - try { - thread.join(); - } catch (InterruptedException e) { - e.printStackTrace(); - } - refreshAll(); + ApiClient client = + ClientFactory.clientToken(settings.url(), settings.sslSettings(), settings.token()); + + client.createService(ApplicationApi.class) + .deleteApp(appId) + .enqueue( + Callback.callInUI( + this, + (ignored) -> refreshAll(), + (e) -> + Utils.showSnackBar( + this, getString(R.string.error_delete_app)))); } private class LoadMore extends AsyncTask> { diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 8bc53a29..5b07d3d9 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -26,6 +26,7 @@ Received %d messages while being disconnected Delete all Delete this application + Could not delete this app Delete logs Copy logs Logs copied @@ -49,6 +50,8 @@ Refresh all Do you really want to logout? Yes + No + Are you sure? Missed messages New Messages Listening to %s