diff --git a/app/src/main/java/com/example/citrusclient/views/MainActivity.java b/app/src/main/java/com/example/citrusclient/views/MainActivity.java index 02b7179..366d24f 100644 --- a/app/src/main/java/com/example/citrusclient/views/MainActivity.java +++ b/app/src/main/java/com/example/citrusclient/views/MainActivity.java @@ -10,13 +10,25 @@ import androidx.core.view.ViewCompat; import androidx.core.view.WindowInsetsCompat; import androidx.fragment.app.Fragment; +import androidx.lifecycle.Observer; +import androidx.lifecycle.ViewModelProvider; +import com.example.citrusclient.Citrus; import com.example.citrusclient.R; +import com.example.citrusclient.models.Book; +import com.example.citrusclient.viewmodels.BooksViewModel; import com.google.android.material.bottomnavigation.BottomNavigationView; import com.google.android.material.navigation.NavigationBarView; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; + public class MainActivity extends AppCompatActivity { + BooksViewModel booksViewModel; + Citrus citrus; + @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); @@ -28,6 +40,17 @@ return insets; }); + + + citrus = (Citrus) getApplication(); + booksViewModel = new ViewModelProvider(this).get(BooksViewModel.class); + booksViewModel.getBookLiveData().observe(this, new Observer>() { + @Override + public void onChanged(HashMap integerBookHashMap) { + citrus.setBook(new ArrayList<>(integerBookHashMap.values())); + } + }); + showFragment(new MyBookshelfFragment()); setNavViewEvent();