From 7f2bc01180c284154fb69976122016c4638e9973 Mon Sep 17 00:00:00 2001 From: Alex Ning Date: Wed, 7 Aug 2019 10:54:47 +0800 Subject: Preparing to support multi user. Use the database to store accounts' info. LoginActivity is successfully refactored. Any other features are unavailable for now. --- app/src/main/java/Account/AccountRoomDatabase.java | 27 ++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 app/src/main/java/Account/AccountRoomDatabase.java (limited to 'app/src/main/java/Account/AccountRoomDatabase.java') diff --git a/app/src/main/java/Account/AccountRoomDatabase.java b/app/src/main/java/Account/AccountRoomDatabase.java new file mode 100644 index 00000000..2f5d0120 --- /dev/null +++ b/app/src/main/java/Account/AccountRoomDatabase.java @@ -0,0 +1,27 @@ +package Account; + +import android.content.Context; + +import androidx.room.Database; +import androidx.room.Room; +import androidx.room.RoomDatabase; + +@Database(entities = {Account.class}, version = 1) +public abstract class AccountRoomDatabase extends RoomDatabase { + private static AccountRoomDatabase INSTANCE; + + public abstract AccountDao accountDao(); + + public static AccountRoomDatabase getDatabase(final Context context) { + if(INSTANCE == null) { + synchronized (AccountRoomDatabase.class) { + if(INSTANCE == null) { + INSTANCE = Room.databaseBuilder(context.getApplicationContext(), + AccountRoomDatabase.class, "accounts") + .build(); + } + } + } + return INSTANCE; + } +} -- cgit v1.2.3