Add delete app option

This commit is contained in:
p1gp1g
2021-01-06 18:13:01 +01:00
committed by GitHub
parent b025508772
commit 107810dcb7
3 changed files with 39 additions and 0 deletions

View File

@@ -43,8 +43,10 @@ import com.github.gotify.Settings;
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;
import com.github.gotify.client.api.ClientApi;
import com.github.gotify.client.api.MessageApi;
import com.github.gotify.client.model.Application;
@@ -171,6 +173,7 @@ public class MessagesActivity extends AppCompatActivity
new SelectApplicationAndUpdateMessages(true)
.execute(selectAppIdOnDrawerClose);
selectAppIdOnDrawerClose = null;
invalidateOptionsMenu();
}
}
});
@@ -192,6 +195,10 @@ public class MessagesActivity extends AppCompatActivity
}
public void onRefreshAll(View view) {
refreshAll();
}
public void refreshAll() {
try {
picassoHandler.evict();
} catch (IOException e) {
@@ -560,6 +567,7 @@ public class MessagesActivity extends AppCompatActivity
@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 +576,32 @@ public class MessagesActivity extends AppCompatActivity
if (item.getItemId() == R.id.action_delete_all) {
new DeleteMessages().execute(appId);
}
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(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) {
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<Long, Void, List<MessageWithImage>> {
@Override

View File

@@ -3,4 +3,8 @@
android:title="@string/delete_all"
android:id="@+id/action_delete_all"
android:orderInCategory="100"/>
<item
android:title="@string/delete_app"
android:id="@+id/action_delete_app"
android:orderInCategory="101"/>
</menu>

View File

@@ -25,6 +25,8 @@
<string name="websocket_closed_try_reconnect">Connection closed, trying to establish a new one.</string>
<string name="grouped_message">Received %d messages while being disconnected</string>
<string name="delete_all">Delete all</string>
<string name="delete_app">Delete this application</string>
<string name="error_delete_app">Could not delete this app</string>
<string name="delete_logs">Delete logs</string>
<string name="copy_logs">Copy logs</string>
<string name="logs_copied">Logs copied</string>
@@ -48,6 +50,8 @@
<string name="refresh_all">Refresh all</string>
<string name="logout_confirm">Do you really want to logout?</string>
<string name="yes">Yes</string>
<string name="no">No</string>
<string name="ack">Are you sure?</string>
<string name="missed_messages">Missed messages</string>
<string name="grouped_notification_text">New Messages</string>
<string name="websocket_listening">Listening to %s</string>