This is an example repository to demonstrate the good practices of using ViewModel and how usage of AndroidViewModel can make things worst in a codebase

Overview

ViewModel Good Practices 🦸‍♂️

This is a example repository to demonstrate the good practices of using ViewModel and how usage of AndroidViewModel can make things worst in a codebase. This repository have both the implementation (good and bad).

📄 Read more about the approaches: https://blog.shreyaspatil.dev/dont-let-viewmodel-knew-about-framework-level-dependencies

👨‍💻 Implementation

If you are just interested in the diff of both the approaches then refer to this Pull Request

📱 What's this app about?

This is a simple app which demonstrates the user session management (login/logout actions).

Android.Emulator.-.Pixel_API_29_5554.2021-09-16.22-48-33.mp4
You might also like...
This is a template repository intended to get a quick up and running project for demonstration purposes.

Android App Template This is a GitHub template repository intended to kickstart development on an Android application. This project comes set with a h

This is an example implementation of android accessibility services with 5 Sample Actions
This is an example implementation of android accessibility services with 5 Sample Actions

Android Accessibility Services Example This is an example implementation of android accessibility services with 5 Sample Actions such as: Simulate Pow

📌This repo contains the kotlin implementation of TensorflowLite Example Android Apps🚀

TensorflowLite Examples Kotlin This repo contains the kotlin implementation of TensorflowLite Example Apps here, which are mostly implemented in java

Example Android library project that works with jitpack.io

android-example Example Android library project that works with jitpack.io. See this Tutorial on how to publish an Android Library with JitPack. For m

This example was built for lecturing proposes, it shows how to consume data from an API.

Android Kotlin NewsMobEDJDCM2122 Example - EDJD 2021/2022 This example was wirten during the Mobile Computing lectures in the course 'Lincentura em En

An example to show how a proper plugin for Lambda Client is set up

Lambda Plugin SDK This project in an example to show how a proper plugin for Lambda Client is set up. The advantage of plugins for a utility mod is th

An example Android Application to test out Kotlin development in Adndroid

AndroidDiceGenerator This is an example Android Application to test out Kotlin development in Adndroid. On pressing a button, the application generate

Its a small example with Custom Employee object is sent from one Fragment to another.
Its a small example with Custom Employee object is sent from one Fragment to another.

Kotlin-SafeArgs-Custom-Object Its a small example with Custom Employee object is sent from one Fragment to another. Dependencies used // Navigation

ROOM Database Example with MVVM in Kotlin[Fragments,Navigation]

RoomDatabase_SampleApp Room Database Sample App Overview Of This Room Database Application In this app, we can do operation on room database | Insert,

Comments
  • Hilt Singleton annotations in repository

    Hilt Singleton annotations in repository

    Hi,
    I'm wondering why you repeated the Hilt Singleton annotations in the UserRepository Class?

    They are already explicit declared in DI module?

    @Module
    @InstallIn(SingletonComponent::class)
    interface RepositoryModule {
    	@Singleton
    	@Binds
    	fun userRepository(repository: InMemoryUserRepository): UserRepository
    

    So you don't need to add hilt references in the UserRepository

    @Singleton //not necessary?
    interface UserRepository {
    	suspend fun findById(id: Int): User
    	suspend fun add(name: String, email: String): User
    }
    
    @Singleton  //not necessary?
    class InMemoryUserRepository @Inject constructor() : UserRepository { 
    

    What do you think?

    thanks Roberto

    opened by roby222 1
  • Refactor UserViewModel and add unit tests

    Refactor UserViewModel and add unit tests

    Summary

    • Refactored UserViewModel: Removed inheritance of AndroidViewModel and inherited core ViewModel
    • Added unit tests for UserViewModel
    • Create a separate interface SessionManager for handling all session-related business.
    opened by PatilShreyas 0
Owner
Shreyas Patil
👨‍💻Google Developer Expert for Android ❤️Android, Kotlin 🌎Web Developer ⚙️Open Source Enthusiast 👨‍🚀Organizer @KotlinMumbai
Shreyas Patil
PolitcalPreparedness is an example application built to demonstrate core Android Development skills recommended by Google.

PolitcalPreparedness is an example application built to demonstrate core Android Development skills recommended by Google.

Pranav Patel 1 Apr 13, 2022
📚 Sample Android Components Architecture on a modular word focused on the scalability, testability and maintainability written in Kotlin, following best practices using Jetpack.

Android Components Architecture in a Modular Word Android Components Architecture in a Modular Word is a sample project that presents modern, 2020 app

Madalin Valceleanu 2.3k Dec 30, 2022
A sample app that demonstrate how to build an Android application using the Uncle Bob's Clean Architecture approach

A sample app that demonstrate how to build an Android application using the Uncle Bob's Clean Architecture approach

Ahmed Shaban  Elhdad 2 Apr 8, 2022
FTUE sample using Jetpack Navigation's Navigation-Compose, ViewModel, SavedStateHandle, Hilt

Jetpack Navigation's Navigation-Compose + Jetpack Compose + NavGraphs + SavedStateHandle + Dagger-Hilt + EventEmitter (toasts / navigation commands) T

Gabor Varadi 15 Dec 8, 2022
Multiple samples demonstrating Search API usage in Android.

Search Samples Repository This repository contains a set of individual Android Studio projects to help you get started writing apps that take advantag

Android 43 Dec 16, 2022
The simple app is to demonstrate how the modern Enterprise Android App Architecture should be

Weather Forecast App The simple app is to demonstrate how the modern Enterprise Android App Architecture should be. Clean Architecture (Mr Uncle Bob)

null 2 Nov 12, 2021
ViewModel and ViewModelFactory Starter Code

ViewModel and ViewModelFactory - Starter Code Use as starter code for the ViewModel codelab. Introduction This starter app is a two player game, Guess

Reskita Amelia 0 Nov 17, 2021
Starter code for Android Basics codelab - Store the data in a ViewModel

Unscramble App Starter code for Android Basics codelab - Store the data in a ViewModel Unscramble is a single player game app that displays scrambled

null 0 Nov 1, 2021
Use as starter code for the ViewModel codelab.

ViewModel and ViewModelFactory - Starter Code Use as starter code for the ViewModel codelab. Introduction This starter app is a two player game, Guess

null 0 Nov 24, 2021
ListView Example with custom Adapter Using Kotlin in Android Studio

Kotlin-ListView ListView Example with custom Adapter Using Kotlin in Android Studio Steps to follow : Build ListView with Custom Adapter in Kotlin Add

null 0 Nov 5, 2021