From 4a571d9326c3ce7dfed890bbde7089619bd6c5a2 Mon Sep 17 00:00:00 2001 From: Page Asgardius Date: Thu, 6 Oct 2022 07:51:20 -0700 Subject: [PATCH] first step --- .../page/s3manager/MainActivity.java | 91 ++++++++++++++++--- .../asgardius/page/s3manager/MyDbHelper.java | 10 +- 2 files changed, 86 insertions(+), 15 deletions(-) diff --git a/app/src/main/java/asgardius/page/s3manager/MainActivity.java b/app/src/main/java/asgardius/page/s3manager/MainActivity.java index f2fe71f..4cebd8d 100644 --- a/app/src/main/java/asgardius/page/s3manager/MainActivity.java +++ b/app/src/main/java/asgardius/page/s3manager/MainActivity.java @@ -27,6 +27,7 @@ public class MainActivity extends AppCompatActivity { ArrayList Name; ArrayList Img; MyDbHelper dbHelper; + int videocache, videotime; @Override protected void onCreate(Bundle savedInstanceState) { @@ -40,6 +41,73 @@ public class MainActivity extends AppCompatActivity { recyclerView.setLayoutManager(linearLayoutManager); dbHelper = new MyDbHelper(this); + Thread getprefs = new Thread(new Runnable() { + + @Override + public void run() { + try { + //Your code goes here + // Database Queries + try { + db = dbHelper.getWritableDatabase(); + String query = "SELECT value FROM preferences where setting='videocache'"; + Cursor cursor = db.rawQuery(query,null); + while (cursor.moveToNext()){ + videocache = (Integer.parseInt(cursor.getString(0))); + } + db.close(); + } catch (Exception e) { + try { + db = dbHelper.getWritableDatabase(); + db.execSQL("INSERT INTO preferences VALUES ('videocache', '300')"); + videocache = 300; + db.close(); + } catch (Exception f) { + db = dbHelper.getWritableDatabase(); + db.execSQL("CREATE TABLE IF NOT EXISTS preferences(setting text UNIQUE, value text)"); + db.execSQL("INSERT INTO preferences VALUES ('videocache', '300')"); + db.execSQL("INSERT INTO preferences VALUES ('videotime', '3')"); + videocache = 300; + //videotime = 3; + db.close(); + } + } + try { + db = dbHelper.getWritableDatabase(); + String query = "SELECT value FROM preferences where setting='videotime'"; + Cursor cursor = db.rawQuery(query,null); + while (cursor.moveToNext()){ + videotime = (Integer.parseInt(cursor.getString(0))); + } + db.close(); + } catch (Exception e) { + try { + db = dbHelper.getWritableDatabase(); + db.execSQL("INSERT INTO preferences VALUES ('videotime', '3')"); + videotime = 3; + db.close(); + } catch (Exception f) { + db = dbHelper.getWritableDatabase(); + db.execSQL("CREATE TABLE IF NOT EXISTS preferences(setting text UNIQUE, value text)"); + db.close(); + } + } + System.out.println("videocache " + videocache); + System.out.println("videotime " + videotime); + } catch (Exception e) { + e.printStackTrace(); + runOnUiThread(new Runnable() { + + @Override + public void run() { + 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(); + finish(); + } + } + }); Thread listaccount = new Thread(new Runnable() { @Override @@ -47,20 +115,17 @@ public class MainActivity extends AppCompatActivity { try { //Your code goes here db = dbHelper.getWritableDatabase(); - if (db != null) { - // Database Queries - Name = new ArrayList(); - Img = new ArrayList(); - String query = "SELECT id FROM account"; - Cursor cursor = db.rawQuery(query,null); - while (cursor.moveToNext()){ - Name.add(cursor.getString(0)); - Img.add(R.drawable.account); - } - db.close(); - } else { - Toast.makeText(getApplicationContext(),getResources().getString(R.string.broken_database), Toast.LENGTH_SHORT).show(); + // Database Queries + Name = new ArrayList(); + Img = new ArrayList(); + String query = "SELECT id FROM account"; + Cursor cursor = db.rawQuery(query,null); + while (cursor.moveToNext()){ + Name.add(cursor.getString(0)); + Img.add(R.drawable.account); } + db.close(); + getprefs.start(); runOnUiThread(new Runnable() { @Override diff --git a/app/src/main/java/asgardius/page/s3manager/MyDbHelper.java b/app/src/main/java/asgardius/page/s3manager/MyDbHelper.java index c215b7a..e2f9928 100644 --- a/app/src/main/java/asgardius/page/s3manager/MyDbHelper.java +++ b/app/src/main/java/asgardius/page/s3manager/MyDbHelper.java @@ -5,7 +5,10 @@ import android.database.sqlite.SQLiteDatabase; import android.database.sqlite.SQLiteOpenHelper; public class MyDbHelper extends SQLiteOpenHelper { - private static final String atcreate = "CREATE TABLE IF NOT EXISTS account(id text UNIQUE, endpoint text, username text, password text, region text, pdfendpoint text)"; + private static final String usertable = "CREATE TABLE IF NOT EXISTS account(id text UNIQUE, endpoint text, username text, password text, region text, pdfendpoint text)"; + private static final String preftable = "CREATE TABLE IF NOT EXISTS preferences(setting text UNIQUE, value text)"; + private static final String setvideocache = "INSERT INTO preferences VALUES ('videocache', '300')"; + private static final String setvideotime = "INSERT INTO preferences VALUES ('videotime', '3')"; //private static final String upgrade = "ALTER TABLE account add column pdfendpoint text"; private static final int DATABASE_VERSION = 1; private static final String dbname = "accounts.sqlite3"; @@ -15,7 +18,10 @@ public class MyDbHelper extends SQLiteOpenHelper { } @Override public void onCreate(SQLiteDatabase db) { - db.execSQL(atcreate); + db.execSQL(usertable); + db.execSQL(preftable); + db.execSQL(setvideocache); + db.execSQL(setvideotime); } @Override public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {