From 2d8df647cf3fca992639eb8346f7b4d18a3ec1c0 Mon Sep 17 00:00:00 2001 From: peet Date: Mon, 30 Nov 2020 15:44:31 +0100 Subject: [PATCH] Added further Database integration --- .../git/wdg/vokabel_trainer/DataHandler.java | 26 ++++++++++++++++++- .../{ => ui}/MainActivity.java | 7 +++++ .../res/layout/fragment_notifications.xml | 11 ++++++++ 3 files changed, 43 insertions(+), 1 deletion(-) rename app/src/main/java/org/ddnss/sfs/git/wdg/vokabel_trainer/{ => ui}/MainActivity.java (91%) diff --git a/app/src/main/java/org/ddnss/sfs/git/wdg/vokabel_trainer/DataHandler.java b/app/src/main/java/org/ddnss/sfs/git/wdg/vokabel_trainer/DataHandler.java index 4874739..784c539 100644 --- a/app/src/main/java/org/ddnss/sfs/git/wdg/vokabel_trainer/DataHandler.java +++ b/app/src/main/java/org/ddnss/sfs/git/wdg/vokabel_trainer/DataHandler.java @@ -2,13 +2,19 @@ package org.ddnss.sfs.git.wdg.vokabel_trainer; import android.content.Context; import android.database.sqlite.SQLiteDatabase; +import android.database.sqlite.SQLiteOpenHelper; +import android.widget.Button; +import android.widget.EditText; +import android.widget.Toast; + +import androidx.annotation.Nullable; public class DataHandler { public static final String DATABASENAME = "vocabDB"; public static final int DATABASE_VERSION = 1; public static final String TABLE_NAME = "vocabTable"; - public static final String DEUTSCH = "deutsch"; + public static final String GERMAN = "german"; public static final String ENGLISH = "english"; private Context ctx; @@ -35,4 +41,22 @@ public class DataHandler { public void addEntry(String voc1, String voc2){ db.execSQL("insert into vocabTable (deutsch, english) values ('vocab1', 'vocab2')"); } + + private static class DataBaseHelper extends SQLiteOpenHelper { + + public DataBaseHelper(@Nullable Context context, @Nullable String name, @Nullable SQLiteDatabase.CursorFactory factory, int version) { + super(context, DATABASENAME, null, DATABASE_VERSION); + } + + @Override + public void onCreate(SQLiteDatabase db) { + String command = "create table if not exists vocTable(german text not null, englisch text not null);"; + db.execSQL(command); + } + + @Override + public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { + + } + } } diff --git a/app/src/main/java/org/ddnss/sfs/git/wdg/vokabel_trainer/MainActivity.java b/app/src/main/java/org/ddnss/sfs/git/wdg/vokabel_trainer/ui/MainActivity.java similarity index 91% rename from app/src/main/java/org/ddnss/sfs/git/wdg/vokabel_trainer/MainActivity.java rename to app/src/main/java/org/ddnss/sfs/git/wdg/vokabel_trainer/ui/MainActivity.java index 52265de..58b7cb5 100644 --- a/app/src/main/java/org/ddnss/sfs/git/wdg/vokabel_trainer/MainActivity.java +++ b/app/src/main/java/org/ddnss/sfs/git/wdg/vokabel_trainer/ui/MainActivity.java @@ -13,6 +13,8 @@ import androidx.navigation.ui.NavigationUI; public class MainActivity extends AppCompatActivity { + private DataHandler dbHandler; + @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); @@ -26,5 +28,10 @@ public class MainActivity extends AppCompatActivity { NavController navController = Navigation.findNavController(this, R.id.nav_host_fragment); NavigationUI.setupActionBarWithNavController(this, navController, appBarConfiguration); NavigationUI.setupWithNavController(navView, navController); + dbHandler = new DataHandler(this); + } + + public void addEntry(){ + } } \ No newline at end of file diff --git a/app/src/main/res/layout/fragment_notifications.xml b/app/src/main/res/layout/fragment_notifications.xml index 18f48ee..efbbd54 100644 --- a/app/src/main/res/layout/fragment_notifications.xml +++ b/app/src/main/res/layout/fragment_notifications.xml @@ -36,4 +36,15 @@ app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toTopOf="parent" app:layout_constraintVertical_bias="0.186" /> + +