account delete option

This commit is contained in:
Page Asgardius 2022-09-05 09:50:05 -07:00
parent bc0c91b771
commit c2ff9d7505
4 changed files with 48 additions and 0 deletions

View file

@ -10,6 +10,7 @@
<entry key="app/src/main/res/layout/activity_object_select.xml" value="0.1" />
<entry key="app/src/main/res/layout/activity_video_player.xml" value="0.1" />
<entry key="app/src/main/res/layout/list_buckets.xml" value="0.19610507246376813" />
<entry key="app/src/main/res/menu/popup_menu.xml" value="0.2713541666666667" />
</map>
</option>
</component>

View file

@ -4,8 +4,10 @@ import android.content.Intent;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.PopupMenu;
import android.widget.Toast;
import androidx.appcompat.app.AppCompatActivity;
@ -115,6 +117,36 @@ public class MainActivity extends AppCompatActivity {
@Override
public void onLongClick(View view, int position) {
System.out.println("Long click on "+Name.get(position).toString());
// Initializing the popup menu and giving the reference as current context
PopupMenu popupMenu = new PopupMenu(MainActivity.this, recyclerView);
// Inflating popup menu from popup_menu.xml file
popupMenu.getMenuInflater().inflate(R.menu.popup_menu, popupMenu.getMenu());
popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem menuItem) {
// Toast message on menu item clicked
//Toast.makeText(MainActivity.this, "You Clicked " + menuItem.getTitle(), Toast.LENGTH_SHORT).show();
if (menuItem.getTitle() == getResources().getString(R.string.accountedit_button)) {
Toast.makeText(MainActivity.this, "Edit Account", Toast.LENGTH_SHORT).show();
}
else if (menuItem.getTitle() == getResources().getString(R.string.accountdel_button)) {
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();
} catch (Exception e) {
Toast.makeText(getApplicationContext(),getResources().getString(R.string.accountadd_fail), Toast.LENGTH_SHORT).show();
}
}
//Toast.makeText(MainActivity.this, "Delete Account", Toast.LENGTH_SHORT).show();
}
return true;
}
});
// Showing the popup menu
popupMenu.show();
}
}));

View file

@ -0,0 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:id="@+id/editaccount"
android:title="@string/accountedit_button" />
<item
android:id="@+id/delaccount"
android:title="@string/accountdel_button" />
</menu>

View file

@ -10,6 +10,9 @@
<string name="accountadd_success">Account added successfully</string>
<string name="accountadd_fail">This alias is already in use</string>
<string name="accountadd_null">All fields are required</string>
<string name="accountdel_button">Remove Account</string>
<string name="accountdel_success">Account removed successfully</string>
<string name="accountedit_button">Edit Account</string>
<string name="explorer_test_button">File Explorer Test</string>
<string name="video_test_button">Video Test</string>
<string name="media_conn_fail">Cannot retrieve media file</string>