delete confirmation

This commit is contained in:
Page Asgardius 2022-09-07 10:44:34 -07:00
parent a73b514552
commit 4bdc78a229
2 changed files with 34 additions and 11 deletions

View file

@ -1,5 +1,6 @@
package asgardius.page.s3manager; package asgardius.page.s3manager;
import android.content.DialogInterface;
import android.content.Intent; import android.content.Intent;
import android.database.Cursor; import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase; import android.database.sqlite.SQLiteDatabase;
@ -10,6 +11,7 @@ import android.widget.Button;
import android.widget.PopupMenu; import android.widget.PopupMenu;
import android.widget.Toast; import android.widget.Toast;
import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity; import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.LinearLayoutManager; import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView; import androidx.recyclerview.widget.RecyclerView;
@ -49,7 +51,7 @@ public class MainActivity extends AppCompatActivity {
Img.add(R.drawable.account); Img.add(R.drawable.account);
} }
} else { } else {
System.out.println("Database Missing"); Toast.makeText(getApplicationContext(),getResources().getString(R.string.broken_database), Toast.LENGTH_SHORT).show();
} }
Thread listaccount = new Thread(new Runnable() { Thread listaccount = new Thread(new Runnable() {
@ -79,7 +81,7 @@ public class MainActivity extends AppCompatActivity {
@Override @Override
public void run() { public void run() {
Toast.makeText(getApplicationContext(),getResources().getString(R.string.media_list_fail), Toast.LENGTH_SHORT).show(); Toast.makeText(getApplicationContext(),getResources().getString(R.string.broken_database), Toast.LENGTH_SHORT).show();
} }
}); });
//Toast.makeText(getApplicationContext(),getResources().getString(R.string.media_list_fail), Toast.LENGTH_SHORT).show(); //Toast.makeText(getApplicationContext(),getResources().getString(R.string.media_list_fail), Toast.LENGTH_SHORT).show();
@ -145,16 +147,35 @@ public class MainActivity extends AppCompatActivity {
} }
} }
else if (menuItem.getTitle() == getResources().getString(R.string.accountdel_button)) { else if (menuItem.getTitle() == getResources().getString(R.string.accountdel_button)) {
if (db != null) { AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this);
// Database Queries builder.setCancelable(true);
try { builder.setTitle(getResources().getString(R.string.accountdel_button));
db.execSQL("DELETE FROM account where id=\""+ Name.get(position).toString()+ "\""); builder.setMessage(getResources().getString(R.string.accountdel_confirm));
Toast.makeText(getApplicationContext(),getResources().getString(R.string.accountdel_success), Toast.LENGTH_SHORT).show(); builder.setPositiveButton(android.R.string.ok,
mainmenu(); new DialogInterface.OnClickListener() {
} catch (Exception e) { @Override
Toast.makeText(getApplicationContext(),getResources().getString(R.string.accountadd_fail), Toast.LENGTH_SHORT).show(); public void onClick(DialogInterface dialog, int which) {
if (db != null) {
// Database Queries
try {
db.execSQL("DELETE FROM account where id=\""+ Name.get(position).toString()+ "\"");
Toast.makeText(getApplicationContext(),getResources().getString(R.string.accountdel_success), Toast.LENGTH_SHORT).show();
mainmenu();
} catch (Exception e) {
Toast.makeText(getApplicationContext(),getResources().getString(R.string.broken_database), Toast.LENGTH_SHORT).show();
}
}
}
});
builder.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
} }
} });
AlertDialog dialog = builder.create();
dialog.show();
/**/
//Toast.makeText(MainActivity.this, "Delete Account", Toast.LENGTH_SHORT).show(); //Toast.makeText(MainActivity.this, "Delete Account", Toast.LENGTH_SHORT).show();
} }
return true; return true;

View file

@ -1,6 +1,7 @@
<resources> <resources>
<string name="app_name">Asgardius S3 Manager</string> <string name="app_name">Asgardius S3 Manager</string>
<string name="title_activity_video_player">VideoPlayer</string> <string name="title_activity_video_player">VideoPlayer</string>
<string name="broken_database">Local database is corrupted. Please reinstall this app</string>
<string name="accountselect">Please choose an account</string> <string name="accountselect">Please choose an account</string>
<string name="accountadd_button">Add Account</string> <string name="accountadd_button">Add Account</string>
<string name="accounttest_button">Test credentials</string> <string name="accounttest_button">Test credentials</string>
@ -14,6 +15,7 @@
<string name="accountadd_null">All fields are required</string> <string name="accountadd_null">All fields are required</string>
<string name="accountdel_button">Remove Account</string> <string name="accountdel_button">Remove Account</string>
<string name="accountdel_success">Account removed successfully</string> <string name="accountdel_success">Account removed successfully</string>
<string name="accountdel_confirm">Do you want to remove this accunt?</string>
<string name="accountedit_button">Edit Account</string> <string name="accountedit_button">Edit Account</string>
<string name="accountsave_button">Save Changes</string> <string name="accountsave_button">Save Changes</string>
<string name="accountsave_success">Account edited successfully</string> <string name="accountsave_success">Account edited successfully</string>