mvvmtodo's People
Forkers
itsamankrsingh subhendra-p abhishekgowdaks ahmed002177 sourabhsnath ganderson04 lokaimoma shivram12 ercanduman sourav992v sphinx373 maimohamedmahmoud arzumanyasha shivamgarg1528 tammamkhalaf iamkishansharma toravipatel ghiblibli43 smjonas ericgao96uw jbrown400 christopp oskarlasota hamurcuabi morristech ashokmani1 atuti nageshks thesonofashephard sidfc jmquint00 maxben26727 imamonster1905 domidosz chanakarobo armagancivelek iaaboy rahat14 wangilisasi ftm-amani ivandsky pravinmudaliyar comye1 sefakerem ayoubjamouhi dreablin rajatsubhra shreyas25 seankotlin osamamg seanwolfgang austinepass swstii jon-ross abhinav-root lexneo elelan shashankdaima dennisdeng2002 arahman0709 armnem ifahimkhan chally-lang andreikud rav-ctrl 4pranshu pratyagarwal rvscript iamganeshhegde cabyambo rubaomar adrianrusu16 shukkuro royaallam raktim-bhuyan alvindizon terranova4697 jaysharma8-mca rexuses javabbt sangtran01 saptaksengupta yashgiradkar pawanchauhan043 raviavanigadda jhlee3629 ironmanyg anisha-24 samueldacostaaraujonunes kyawsoew1n ramipa adulegendary easyhooon karinacostamachado shiviand om22r toolsforfun ndricca aashishace captwhitebeardmvvmtodo's Issues
@ViewModelInject has deprecated
Hi,
@ViewModelInject has deprecated. I change to the following and I still got an error.
"java.lang.RuntimeException: Cannot create an instance of class com.example.room_test.ui.tasks.TasksViewModel"
Is there a way I can solve the problem? Many thanks.
KC
@HiltViewModel
class TasksViewModel @Inject constructor(
private val taskDao: TaskDao
) : ViewModel() {
val tasks = taskDao.getTasks().asLiveData()
}
Giving error when compiling
Unresolved reference: actionGlobalDeleteAllCompletedDialogFragment
Any ideas what could be wrong ?
I have changed the package name and project could that be a issue?
databinding not generating
Hello!
Due to changes in newer versions of databinding the binding classes are not generating correctly
To fix this issue we need to wrap each layout file with tag like following:
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
// ... layout markup here
</layout>
More info: https://developer.android.com/topic/libraries/data-binding/expressions
error: [Dagger/MissingBinding] @com.calamity.weather.di.ApplicationScope kotlinx.coroutines.CoroutineScope cannot be provided without an @Provides-annotated method.
I was following along the tutorial and ran into a build error.
Complete error log:
C:\Users\semyo\AndroidStudioProjects\Weather\app\build\generated\source\kapt\debug\com\calamity\weather\utils\WeatherApplication_HiltComponents.java:135: error: [Dagger/MissingBinding] @com.calamity.weather.di.ApplicationScope kotlinx.coroutines.CoroutineScope cannot be provided without an @Provides-annotated method.
public abstract static class SingletonC implements WeatherApplication_GeneratedInjector,
^
@com.calamity.weather.di.ApplicationScope kotlinx.coroutines.CoroutineScope is injected at
com.calamity.weather.data.database.WeatherDatabase.Callback(�, applicationScope)
com.calamity.weather.data.database.WeatherDatabase.Callback is injected at
com.calamity.weather.di.AppModule.provideDatabase(�, callback)
com.calamity.weather.data.database.WeatherDatabase is injected at
com.calamity.weather.di.AppModule.provideWeatherDao(db)
javax.inject.Provider<com.calamity.weather.data.dao.WeatherDao> is injected at
com.calamity.weather.ui.detailedweather.WeatherViewModel_AssistedFactory(weatherDao)
com.calamity.weather.ui.detailedweather.WeatherViewModel_AssistedFactory is injected at
com.calamity.weather.ui.detailedweather.WeatherViewModel_HiltModule.bind(factory)
java.util.Map<java.lang.String,javax.inject.Provider<androidx.hilt.lifecycle.ViewModelAssistedFactory<? extends androidx.lifecycle.ViewModel>>> is injected at
androidx.hilt.lifecycle.ViewModelFactoryModules.ActivityModule.provideFactory(�, viewModelFactories)
@dagger.hilt.android.internal.lifecycle.DefaultActivityViewModelFactory java.util.Set<androidx.lifecycle.ViewModelProvider.Factory> is injected at
dagger.hilt.android.internal.lifecycle.DefaultViewModelFactories.InternalFactoryFactory(�, defaultActivityFactorySet, �)
dagger.hilt.android.internal.lifecycle.DefaultViewModelFactories.InternalFactoryFactory is requested at
dagger.hilt.android.internal.lifecycle.DefaultViewModelFactories.ActivityEntryPoint.getHiltInternalFactoryFactory() [com.calamity.weather.utils.WeatherApplication_HiltComponents.SingletonC ? com.calamity.weather.utils.WeatherApplication_HiltComponents.ActivityRetainedC ? com.calamity.weather.utils.WeatherApplication_HiltComponents.ActivityC]
The following other entry points also depend on it:
dagger.hilt.android.internal.lifecycle.DefaultViewModelFactories.FragmentEntryPoint.getHiltInternalFactoryFactory() [com.calamity.weather.utils.WeatherApplication_HiltComponents.SingletonC ? com.calamity.weather.utils.WeatherApplication_HiltComponents.ActivityRetainedC ? com.calamity.weather.utils.WeatherApplication_HiltComponents.ActivityC ? com.calamity.weather.utils.WeatherApplication_HiltComponents.FragmentC][WARN] Incremental annotation processing requested, but support is disabled because the following processors are not incremental: androidx.room.RoomProcessor (DYNAMIC).
My application does something different from that of the tutorial, but I was just trying to build a structure for it.
My AppModule
(I'm using SingletonComponent::class
because ApplicationComponent::class
was deprecated. I tried an earlier version of Hilt, but it doesn't work anyway):
package com.calamity.weather.di
import android.app.Application
import androidx.room.Room
import com.calamity.weather.data.database.WeatherDatabase
import dagger.Module
import dagger.Provides
import dagger.hilt.InstallIn
import dagger.hilt.components.SingletonComponent
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.SupervisorJob
import javax.inject.Qualifier
import javax.inject.Singleton
@Module
@InstallIn(SingletonComponent::class)
object AppModule {
@Provides
@Singleton
fun provideDatabase(
app: Application,
callback: WeatherDatabase.Callback
) = Room.databaseBuilder(app, WeatherDatabase::class.java, "weather_database")
.fallbackToDestructiveMigration()
.addCallback(callback)
.build()
@Provides
fun provideWeatherDao(db: WeatherDatabase) = db.weatherDao()
@Provides
fun provideCurrentWeatherDao(db: WeatherDatabase) = db.currentWeatherDao()
@Provides
@Singleton
fun providesApplicationScope() = CoroutineScope(SupervisorJob())
}
@Retention(AnnotationRetention.RUNTIME)
@Qualifier
annotation class ApplicationScope
My Database
:
package com.calamity.weather.data.database
import androidx.room.Database
import androidx.room.RoomDatabase
import androidx.room.TypeConverters
import androidx.sqlite.db.SupportSQLiteDatabase
import com.calamity.weather.data.api.CurrentWeather
import com.calamity.weather.data.api.Weather
import com.calamity.weather.data.api.subclasses.*
import com.calamity.weather.data.dao.CurrentWeatherDao
import com.calamity.weather.data.dao.WeatherDao
import com.calamity.weather.di.ApplicationScope
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.launch
import javax.inject.Inject
import javax.inject.Provider
@Database(entities = [CurrentWeather::class, Weather::class], version = 1)
@TypeConverters(Converters::class)
abstract class WeatherDatabase : RoomDatabase() {
abstract fun weatherDao(): WeatherDao
abstract fun currentWeatherDao(): CurrentWeatherDao
class Callback @Inject constructor(
private val database: Provider<WeatherDatabase>,
@ApplicationScope private val applicationScope: CoroutineScope
) : RoomDatabase.Callback() {
// First db initialization, todo: implement gps
override fun onCreate(db: SupportSQLiteDatabase) {
super.onCreate(db)
val dao = database.get().currentWeatherDao()
applicationScope.launch {
dao.insert(/* */)
}
}
}
}
What might be the case here and how can I fix it?
Thanks for series ! 👨🏻💻 here is quick suggestion
Hi, @codinginflow Nice tutorial series,
Just a suggestion you can reduce some nesting using this with
than apply
class TasksViewHolder(private val binding: ItemTaskBinding) : RecyclerView.ViewHolder(binding.root) {
fun bind(task: Task) {
binding.apply {
checkBoxCompleted.isChecked = task.completed
textViewName.text = task.name
textViewName.paint.isStrikeThruText = task.completed
labelPriority.isVisible = task.important
}
}
}
class TasksViewHolder(private val binding: ItemTaskBinding) : RecyclerView.ViewHolder(binding.root) {
fun bind(task: Task) = with(binding) {
checkBoxCompleted.isChecked = task.completed
textViewName.text = task.name
textViewName.paint.isStrikeThruText = task.completed
labelPriority.isVisible = task.important
}
}
[Edit1]
Nested scoped extension chaining is are considered not a good practice, checkout some awesome kotlin tips be from Huyen
talk KotlinConf 2019
youtube.com/watch?v=YeqGfKmJM_g
//TaskFragment
binding.apply {
recyclerViewTasks.apply {
adapter = taskAdapter
layoutManager = LinearLayoutManager(requireContext())
setHasFixedSize(true)
}
}
to
//TaskFragment
binding.recyclerViewTasks.apply {
adapter = taskAdapter
layoutManager = LinearLayoutManager(requireContext())
setHasFixedSize(true)
}
Updating code with Context.dataStore
So I'm trying to follow this tutorial with the latest libraries and have hit a snag.
DataStore
is now created with private val Context.dataStore: DataStore<Preferences> by preferencesDataStore("user_preferences")
. There are 2 functions in the PreferencesManager.kt
file that require access to the dataStore, which in turn requires a context. I've updated them to this (added a context input):
suspend fun updateSortOrder(context: Context, sortOrder: SortOrder) { context.dataStore.edit { preferences -> preferences[PreferencesKeys.SORT_ORDER] = sortOrder.name } }
However when this function is accessed from the TasksViewModel
, the following code gives an error:
fun onSortOrderSelected(sortOrder: SortOrder) = viewModelScope.launch { preferencesManager.updateSortOrder(this, sortOrder) }
It refuses to accept the context from the coroutine scope. What do I do?
Gradle issue, project build not completing
here is the stackTrace -
is:issue is:open Unable to start the daemon process.
This problem might be caused by incorrect configuration of the daemon.
For example, an unrecognized jvm option is used.
Please refer to the User Manual chapter on the daemon at https://docs.gradle.org/6.5/userguide/gradle_daemon.html Process command line: C:\Users\mdashraful.maruf.jdks\corretto-1.8.0_322\bin\java.exe -Xmx1024m -Dfile.encoding=UTF-8 -Duser.country=US -Duser.language=en -Duser.variant -cp C:\Users\mdashraful.maruf.gradle\wrapper\dists\gradle-6.5-all\2oz4ud9k3tuxjg84bbf55q0tn\gradle-6.5\lib\gradle-launcher-6.5.jar org.gradle.launcher.daemon.bootstrap.GradleDaemon 6.5 Please read the following process output to find out more:
Error occurred during initialization of VM Unable to allocate 32768KB bitmaps for parallel garbage collection for the requested 1048576KB heap. Error: Could not create the Java Virtual Machine. Error: A fatal exception has occurred. Program will exit.
Check the JVM arguments defined for the gradle process in:
- gradle.properties in project root directory
We never save the searchQuery data with SavedStateHandle
No real issue here, it's just that we never actually save query data into state (SavedStateHandle).
All I did was add:
init {
searchQuery.map { state.set("searchQuery", it) }
}
Or maybe I'm just dumb and missed something
typo in build.grade
// Lifecycle + ViewModel & LiveData
implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:$lifecycleVersion"
implementation "androidx.lifecycle:lifecycle-livedata-ktx:$lifecycleVersion"
implementation "android.lifecycle:lifecycle-common-java8:$lifecycleVersion"
Should be androidx in the last line?
I have compile time error without it:
Execution failed for task ':app:dataBindingMergeDependencyArtifactsDebug'.
Could not resolve all files for configuration ':app:debugCompileClasspath'.
Could not find android.lifecycle:lifecycle-common-java8:2.3.1.
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.