first step

This commit is contained in:
Page Asgardius 2022-10-06 07:51:20 -07:00
parent 66d5796269
commit 4a571d9326
2 changed files with 86 additions and 15 deletions

View file

@ -27,6 +27,7 @@ public class MainActivity extends AppCompatActivity {
ArrayList Name; ArrayList Name;
ArrayList Img; ArrayList Img;
MyDbHelper dbHelper; MyDbHelper dbHelper;
int videocache, videotime;
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
@ -40,6 +41,73 @@ public class MainActivity extends AppCompatActivity {
recyclerView.setLayoutManager(linearLayoutManager); recyclerView.setLayoutManager(linearLayoutManager);
dbHelper = new MyDbHelper(this); 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() { Thread listaccount = new Thread(new Runnable() {
@Override @Override
@ -47,7 +115,6 @@ public class MainActivity extends AppCompatActivity {
try { try {
//Your code goes here //Your code goes here
db = dbHelper.getWritableDatabase(); db = dbHelper.getWritableDatabase();
if (db != null) {
// Database Queries // Database Queries
Name = new ArrayList<String>(); Name = new ArrayList<String>();
Img = new ArrayList<String>(); Img = new ArrayList<String>();
@ -58,9 +125,7 @@ public class MainActivity extends AppCompatActivity {
Img.add(R.drawable.account); Img.add(R.drawable.account);
} }
db.close(); db.close();
} else { getprefs.start();
Toast.makeText(getApplicationContext(),getResources().getString(R.string.broken_database), Toast.LENGTH_SHORT).show();
}
runOnUiThread(new Runnable() { runOnUiThread(new Runnable() {
@Override @Override

View file

@ -5,7 +5,10 @@ import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper; import android.database.sqlite.SQLiteOpenHelper;
public class MyDbHelper extends 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 String upgrade = "ALTER TABLE account add column pdfendpoint text";
private static final int DATABASE_VERSION = 1; private static final int DATABASE_VERSION = 1;
private static final String dbname = "accounts.sqlite3"; private static final String dbname = "accounts.sqlite3";
@ -15,7 +18,10 @@ public class MyDbHelper extends SQLiteOpenHelper {
} }
@Override @Override
public void onCreate(SQLiteDatabase db) { public void onCreate(SQLiteDatabase db) {
db.execSQL(atcreate); db.execSQL(usertable);
db.execSQL(preftable);
db.execSQL(setvideocache);
db.execSQL(setvideotime);
} }
@Override @Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {