From fc908199f136acd2a5030e5085f024857cd2cfb5 Mon Sep 17 00:00:00 2001 From: Bryson Steck Date: Sat, 8 May 2021 14:58:18 -0600 Subject: changed api and package name --- .../viewmodel/FriendCodeViewModel.java | 80 ---------------------- 1 file changed, 80 deletions(-) delete mode 100644 app/src/main/java/com/example/wiimmterfaceandroid/viewmodel/FriendCodeViewModel.java (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 deleted file mode 100644 index c7bbe7d..0000000 --- a/app/src/main/java/com/example/wiimmterfaceandroid/viewmodel/FriendCodeViewModel.java +++ /dev/null @@ -1,80 +0,0 @@ -package com.example.wiimmterfaceandroid.viewmodel; - -import android.app.Application; - -import androidx.lifecycle.AndroidViewModel; -import androidx.lifecycle.MutableLiveData; - -import com.example.wiimmterfaceandroid.database.AppDatabase; -import com.example.wiimmterfaceandroid.model.FriendCode; - -import androidx.databinding.ObservableArrayList; -import androidx.lifecycle.AndroidViewModel; -import androidx.lifecycle.MutableLiveData; -import androidx.lifecycle.ViewModel; -import androidx.room.Room; -import androidx.room.RoomDatabase; - -import androidx.databinding.ObservableArrayList; - -import java.util.LinkedHashSet; - -public class FriendCodeViewModel extends AndroidViewModel { - ObservableArrayList entries = new ObservableArrayList<>(); - MutableLiveData saving = new MutableLiveData<>(); - MutableLiveData currentEntry = new MutableLiveData<>(); - AppDatabase db; - public FriendCodeViewModel(Application app) { - super(app); - saving.setValue(false); - db = Room.databaseBuilder(app, AppDatabase.class, "friend-codes-db").build(); - new Thread(() -> { - try { - Thread.sleep(1000); - } catch (InterruptedException e) { - e.printStackTrace(); - } - entries.addAll(db.getFriendCodeDao().getAll()); - }).start(); - } - - public void setCurrentEntry(FriendCode entry) { - currentEntry.postValue(entry); - } - - public MutableLiveData getCurrentEntry() { - return currentEntry; - } - - public MutableLiveData getSaving() { - return saving; - } - - public ObservableArrayList getEntries() { - return entries; - } - - public void saveFriendCode(String name, String friendCode) { - saving.setValue(true); - new Thread(() -> { - if (currentEntry.getValue() != null) { - - } else { - FriendCode newEntry = new FriendCode(); - newEntry.name = name; - newEntry.friendCode = friendCode; - db.getFriendCodeDao().insert(newEntry); - entries.add(newEntry); - } - - saving.postValue(false); - }).start(); - } - - public void deleteEntry(FriendCode entry) { - new Thread(() -> { - db.getFriendCodeDao().delete(entry); - entries.remove(entry); - }).start(); - } - } -- cgit v1.2.3