From b083c85378831337e45fa28f0f6b13d0daad3146 Mon Sep 17 00:00:00 2001 From: Page Asgardius Date: Thu, 6 Oct 2022 10:01:00 -0700 Subject: [PATCH] save settings --- .../asgardius/page/s3manager/Settings.java | 37 +++++++++++++++---- 1 file changed, 30 insertions(+), 7 deletions(-) diff --git a/app/src/main/java/asgardius/page/s3manager/Settings.java b/app/src/main/java/asgardius/page/s3manager/Settings.java index fbc09eb..942d6d3 100644 --- a/app/src/main/java/asgardius/page/s3manager/Settings.java +++ b/app/src/main/java/asgardius/page/s3manager/Settings.java @@ -20,7 +20,7 @@ public class Settings extends AppCompatActivity { private ActivitySettingsBinding binding; MyDbHelper dbHelper; SQLiteDatabase db; - int videocache, videotime; + String videocache, videotime; EditText vcachepick, vtimepick; @Override @@ -43,12 +43,12 @@ public class Settings extends AppCompatActivity { String query = "SELECT value FROM preferences where setting='videocache'"; Cursor cursor = db.rawQuery(query,null); while (cursor.moveToNext()){ - videocache = (Integer.parseInt(cursor.getString(0))); + videocache = (cursor.getString(0)); } query = "SELECT value FROM preferences where setting='videotime'"; cursor = db.rawQuery(query,null); while (cursor.moveToNext()){ - videotime = (Integer.parseInt(cursor.getString(0))); + videotime = (cursor.getString(0)); } db.close(); runOnUiThread(new Runnable() { @@ -56,12 +56,10 @@ public class Settings extends AppCompatActivity { @SuppressLint("SetTextI18n") @Override public void run() { - vcachepick.setText(Integer.toString(videocache)); - vtimepick.setText(Integer.toString(videotime)); + vcachepick.setText(videocache); + vtimepick.setText(videotime); } }); - System.out.println("videocache " + videocache); - System.out.println("videotime " + videotime); } catch (Exception e) { e.printStackTrace(); runOnUiThread(new Runnable() { @@ -84,6 +82,22 @@ public class Settings extends AppCompatActivity { @Override public void onClick(View view) { //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 //addaccount(false); } @@ -108,4 +122,13 @@ public class Settings extends AppCompatActivity { 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); + + } } \ No newline at end of file