aboutsummaryrefslogtreecommitdiff
path: root/app/src/main/java/Account/AccountViewModel.java
diff options
context:
space:
mode:
authorAlex Ning <chineseperson5@gmail.com>2019-08-07 02:54:47 +0000
committerAlex Ning <chineseperson5@gmail.com>2019-08-07 02:54:47 +0000
commit7f2bc01180c284154fb69976122016c4638e9973 (patch)
treeb009b9cfab924cce98c25ae5b6355af4f18c311c /app/src/main/java/Account/AccountViewModel.java
parent77d83654aa8063b0c4d9f95ba91bd3d77be84ad9 (diff)
downloadinfinity-for-reddit-7f2bc01180c284154fb69976122016c4638e9973.tar
infinity-for-reddit-7f2bc01180c284154fb69976122016c4638e9973.tar.gz
infinity-for-reddit-7f2bc01180c284154fb69976122016c4638e9973.tar.bz2
infinity-for-reddit-7f2bc01180c284154fb69976122016c4638e9973.tar.lz
infinity-for-reddit-7f2bc01180c284154fb69976122016c4638e9973.tar.xz
infinity-for-reddit-7f2bc01180c284154fb69976122016c4638e9973.tar.zst
infinity-for-reddit-7f2bc01180c284154fb69976122016c4638e9973.zip
Preparing to support multi user. Use the database to store accounts' info. LoginActivity is successfully refactored. Any other features are unavailable for now.
Diffstat (limited to 'app/src/main/java/Account/AccountViewModel.java')
-rw-r--r--app/src/main/java/Account/AccountViewModel.java47
1 files changed, 47 insertions, 0 deletions
diff --git a/app/src/main/java/Account/AccountViewModel.java b/app/src/main/java/Account/AccountViewModel.java
new file mode 100644
index 00000000..b649d9a7
--- /dev/null
+++ b/app/src/main/java/Account/AccountViewModel.java
@@ -0,0 +1,47 @@
+package Account;
+
+import android.app.Application;
+
+import androidx.annotation.NonNull;
+import androidx.lifecycle.AndroidViewModel;
+import androidx.lifecycle.LiveData;
+import androidx.lifecycle.ViewModel;
+import androidx.lifecycle.ViewModelProvider;
+
+public class AccountViewModel extends AndroidViewModel {
+ private AccountRepository mAccountRepository;
+ private LiveData<Account> mAccountLiveData;
+
+ public AccountViewModel(Application application, String id) {
+ super(application);
+ mAccountRepository = new AccountRepository(application, id);
+ mAccountLiveData = mAccountRepository.getAccountLiveData();
+ }
+
+ public LiveData<Account> getAccountLiveData() {
+ return mAccountLiveData;
+ }
+
+ public void insert(Account userData) {
+ mAccountRepository.insert(userData);
+ }
+
+ public static class Factory extends ViewModelProvider.NewInstanceFactory {
+
+ @NonNull
+ private final Application mApplication;
+
+ private final String userName;
+
+ public Factory(@NonNull Application application, String userName) {
+ mApplication = application;
+ this.userName = userName;
+ }
+
+ @Override
+ public <T extends ViewModel> T create(Class<T> modelClass) {
+ //noinspection unchecked
+ return (T) new AccountViewModel(mApplication, userName);
+ }
+ }
+}