From 50dfc57c61a01dc20a42129246b458bf90e26154 Mon Sep 17 00:00:00 2001 From: Bryson Steck Date: Tue, 4 May 2021 20:18:17 -0600 Subject: getting closer to implementing the recycler view --- .../wiimmterfaceandroid/viewmodel/FriendCodeViewModel.java | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) (limited to 'app/src/main/java/com/example/wiimmterfaceandroid/viewmodel') diff --git a/app/src/main/java/com/example/wiimmterfaceandroid/viewmodel/FriendCodeViewModel.java b/app/src/main/java/com/example/wiimmterfaceandroid/viewmodel/FriendCodeViewModel.java index cf31868..ac039ff 100644 --- a/app/src/main/java/com/example/wiimmterfaceandroid/viewmodel/FriendCodeViewModel.java +++ b/app/src/main/java/com/example/wiimmterfaceandroid/viewmodel/FriendCodeViewModel.java @@ -25,7 +25,7 @@ public class FriendCodeViewModel extends AndroidViewModel { public FriendCodeViewModel(Application app) { super(app); saving.setValue(false); - db = Room.databaseBuilder(app, AppDatabase.class, "fc-database").build(); + db = Room.databaseBuilder(app, AppDatabase.class, "friend-codes-db").build(); new Thread(() -> { try { Thread.sleep(1000); @@ -56,17 +56,12 @@ public class FriendCodeViewModel extends AndroidViewModel { saving.setValue(true); new Thread(() -> { if (currentEntry.getValue() != null) { - FriendCode current = currentEntry.getValue(); - current.name = name; - current.friendCode = friendCode; - db.getFriendCodeDao().update(current); - int index = entries.indexOf(current); - entries.set(index, current); + } else { FriendCode newEntry = new FriendCode(); newEntry.name = name; newEntry.friendCode = friendCode; - entries.add(newEntry); + db.getFriendCodeDao().insert(newEntry); } saving.postValue(false); -- cgit v1.2.3