save settings

This commit is contained in:
Page Asgardius 2022-10-06 10:01:00 -07:00
parent 1c6d43112d
commit b083c85378

View file

@ -20,7 +20,7 @@ public class Settings extends AppCompatActivity {
private ActivitySettingsBinding binding; private ActivitySettingsBinding binding;
MyDbHelper dbHelper; MyDbHelper dbHelper;
SQLiteDatabase db; SQLiteDatabase db;
int videocache, videotime; String videocache, videotime;
EditText vcachepick, vtimepick; EditText vcachepick, vtimepick;
@Override @Override
@ -43,12 +43,12 @@ public class Settings extends AppCompatActivity {
String query = "SELECT value FROM preferences where setting='videocache'"; String query = "SELECT value FROM preferences where setting='videocache'";
Cursor cursor = db.rawQuery(query,null); Cursor cursor = db.rawQuery(query,null);
while (cursor.moveToNext()){ while (cursor.moveToNext()){
videocache = (Integer.parseInt(cursor.getString(0))); videocache = (cursor.getString(0));
} }
query = "SELECT value FROM preferences where setting='videotime'"; query = "SELECT value FROM preferences where setting='videotime'";
cursor = db.rawQuery(query,null); cursor = db.rawQuery(query,null);
while (cursor.moveToNext()){ while (cursor.moveToNext()){
videotime = (Integer.parseInt(cursor.getString(0))); videotime = (cursor.getString(0));
} }
db.close(); db.close();
runOnUiThread(new Runnable() { runOnUiThread(new Runnable() {
@ -56,12 +56,10 @@ public class Settings extends AppCompatActivity {
@SuppressLint("SetTextI18n") @SuppressLint("SetTextI18n")
@Override @Override
public void run() { public void run() {
vcachepick.setText(Integer.toString(videocache)); vcachepick.setText(videocache);
vtimepick.setText(Integer.toString(videotime)); vtimepick.setText(videotime);
} }
}); });
System.out.println("videocache " + videocache);
System.out.println("videotime " + videotime);
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
runOnUiThread(new Runnable() { runOnUiThread(new Runnable() {
@ -84,6 +82,22 @@ public class Settings extends AppCompatActivity {
@Override @Override
public void onClick(View view) { public void onClick(View view) {
//buttonaction //buttonaction
try {
videocache = vcachepick.getText().toString();
videotime = vtimepick.getText().toString();
if (videocache.equals("") || videotime.equals("")) {
Toast.makeText(getApplicationContext(),getResources().getString(R.string.accountadd_null), Toast.LENGTH_SHORT).show();
} else {
db = dbHelper.getWritableDatabase();
db.execSQL("UPDATE preferences SET value='"+videocache+"' where setting='videocache'");
db.execSQL("UPDATE preferences SET value='"+videotime+"' where setting='videotime'");
db.close();
mainmenu();
}
} catch (Exception e) {
e.printStackTrace();
Toast.makeText(getApplicationContext(),getResources().getString(R.string.broken_database), Toast.LENGTH_SHORT).show();
}
//This launch account add screen //This launch account add screen
//addaccount(false); //addaccount(false);
} }
@ -108,4 +122,13 @@ public class Settings extends AppCompatActivity {
startActivity(intent); startActivity(intent);
} }
private void mainmenu() {
Intent intent = new Intent(this, MainActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
intent.putExtra("EXIT", true);
startActivity(intent);
}
} }