diff --git a/.gitignore b/.gitignore index e050e2f..e9fadbe 100644 --- a/.gitignore +++ b/.gitignore @@ -10,3 +10,4 @@ local.properties .idea/gradle.xml .idea/vcs.xml +.idea diff --git a/.idea/compiler.xml b/.idea/compiler.xml index 61a9130..fb7f4a8 100644 --- a/.idea/compiler.xml +++ b/.idea/compiler.xml @@ -1,6 +1,6 @@ - + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml index d5d35ec..860da66 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -1,6 +1,6 @@ - + diff --git a/README.md b/README.md index 18b4138..9a0897f 100644 --- a/README.md +++ b/README.md @@ -29,7 +29,6 @@ You can hear sounds that can help you study, concentrate, and sleep. - Architecture - MVVM Architecture (View - DataBinding - ViewModel - Model) - Repository pattern - - [Dagger 2](https://dagger.dev/dev-guide) - dependency injection. - [Dagger Hilt](https://dagger.dev/hilt/) - dependency injection. - Firebase - FireStore, Storage - [Glide](https://github.com/bumptech/glide) - loading images. diff --git a/app/build.gradle b/app/build.gradle index ed6ba0b..019d389 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -5,6 +5,37 @@ plugins { id 'com.google.gms.google-services' id 'kotlin-parcelize' id 'com.google.firebase.crashlytics' + id 'scabbard.gradle' + id 'dagger.hilt.android.plugin' +} + +class Version { + static final String FILE_NAME = 'version.properties' + int code + String name +} + +def loadConfigFile(String fileName) { + String projPath = getProjectDir().getPath() + "/config" + Properties prop = new Properties() + FileInputStream fis + try { + fis = new FileInputStream(projPath + "/" + fileName) + prop.load(fis) + } catch (IOException e) { + System.out.println(e.toString()) + } + return prop +} + +def getVersionProperty() { + Properties prop = loadConfigFile(Version.FILE_NAME) + + Version version = new Version() + version.code = prop.getProperty("version.code", "1").toInteger() + version.name = prop.getProperty("version.name", "1") + + return version } android { @@ -16,15 +47,18 @@ android { storeFile file('../keystore/upload-key.jks') } } + compileSdkVersion versions.compile_sdk_version buildToolsVersion versions.build_tool_version + Version version = getVersionProperty() + defaultConfig { applicationId "com.beomjo.whitenoise" minSdkVersion versions.min_sdk_version targetSdkVersion versions.target_sdk_version - versionCode 1 - versionName "1.0.0" + versionCode version.code + versionName version.name testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" } @@ -46,6 +80,11 @@ android { buildFeatures { dataBinding true } + scabbard { + enabled true + failOnError true + fullBindingGraphValidation true + } } dependencies { @@ -59,17 +98,17 @@ dependencies { implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-play-services:1.4.3' implementation 'com.google.firebase:firebase-crashlytics' - implementation deps.dagger2.android - kapt deps.dagger2.compiler + implementation deps.hilt.android + kapt deps.hilt.compiler implementation "com.github.skydoves:bindables:1.0.5" implementation 'com.facebook.shimmer:shimmer:0.5.0' - implementation 'androidx.media:media:1.2.1' + implementation 'androidx.media:media:1.3.1' testImplementation deps.test.arch.core testImplementation deps.test.androidx_test_core testImplementation deps.test.coroutine_test testImplementation deps.test.mockk - testImplementation "org.jetbrains.kotlin:kotlin-reflect:1.4.31" + testImplementation "org.jetbrains.kotlin:kotlin-reflect:1.5.10" } \ No newline at end of file diff --git a/app/config/version.properties b/app/config/version.properties new file mode 100644 index 0000000..a0e2c5d --- /dev/null +++ b/app/config/version.properties @@ -0,0 +1,2 @@ +version.code=2021070901 +version.name=1.0.1 diff --git a/app/release_note.txt b/app/release_note.txt new file mode 100644 index 0000000..8c5f9ae --- /dev/null +++ b/app/release_note.txt @@ -0,0 +1,26 @@ +# Features + * + + + + +# Changes + * + + + +# Bug Fixes + * [#31] 트랙 재생, 멈춤시 진동, 알림 오는현상 수정 + * 알림채널 우선순위 LOW로 변경 + * [#32] 홈화면 Pull to Refersh시 shimmer가 뒤쪽에 표시되는 현상 수정 + * [#26] 디바이스 가로회전 막음처리 + + + +# Add + * + + + +# Deprecations + * \ No newline at end of file diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 5e0f94b..47a756a 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -14,18 +14,25 @@ android:roundIcon="@mipmap/ic_launcher" android:supportsRtl="true" android:theme="@style/Theme.WhiteNoisePlayer"> - + - - + + + android:launchMode="singleTop" + android:screenOrientation="portrait" /> ( @LayoutRes contentLayoutId: Int, - private vararg var viewModels: KClass, ) : BindingActivity(contentLayoutId), LifecycleOwner { - @Inject - lateinit var viewModelFactory: ViewModelFactory - - val viewModelImpl: MutableList = mutableListOf() - protected var progressDialog: ProgressDialogFragment? = null - protected inline fun getViewModel(): Lazy { + inline fun getViewModel(): Lazy { return lazy { - viewModelImpl.find { it is T }?.let { it as T } - ?: kotlin.run { throw IllegalStateException("Can't find [${T::class.java.simpleName}] type ViewModel") } - } - } - - protected fun setStatusBarColor(color: Int) { - if (!isFinishing) { - val window = window - window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS) - window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS) - window.statusBarColor = color + ViewModelProvider(this) + .get(T::class.java) + .apply { observeViewModel(this) } } } - @SuppressLint("MissingSuperCall") override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) - inject() - createViewModels() bindingLifeCycleOwner() - observeViewModel() - } - - abstract fun inject() - - private fun createViewModels() { - for (vm in viewModels) { - viewModelImpl.add(ViewModelProvider(this, viewModelFactory).get(vm.javaObjectType)) - } } private fun bindingLifeCycleOwner() { @@ -65,13 +35,20 @@ abstract class BaseActivity( } } - private fun observeViewModel() { - for (vm in viewModelImpl) { - observeToast(vm) - observeProgress(vm) + protected fun setStatusBarColor(color: Int) { + if (!isFinishing) { + val window = window + window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS) + window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS) + window.statusBarColor = color } } + fun observeViewModel(viewModel: BaseViewModel) { + observeToast(viewModel) + observeProgress(viewModel) + } + private fun observeToast(vm: BaseViewModel) { vm.toast.observe(this) { event -> event.getContentIfNotHandled()?.let { msg -> diff --git a/app/src/main/java/com/beomjo/whitenoise/base/BaseDialogFragment.kt b/app/src/main/java/com/beomjo/whitenoise/base/BaseDialogFragment.kt index 28b0933..c819419 100644 --- a/app/src/main/java/com/beomjo/whitenoise/base/BaseDialogFragment.kt +++ b/app/src/main/java/com/beomjo/whitenoise/base/BaseDialogFragment.kt @@ -10,46 +10,30 @@ import androidx.databinding.ViewDataBinding import androidx.fragment.app.FragmentManager import androidx.lifecycle.LifecycleOwner import androidx.lifecycle.ViewModelProvider -import com.beomjo.whitenoise.factory.ViewModelFactory +import androidx.lifecycle.ViewModelStoreOwner import com.skydoves.bindables.BindingDialogFragment -import javax.inject.Inject -import kotlin.reflect.KClass abstract class BaseDialogFragment( @LayoutRes private val contentLayoutId: Int, - private vararg var viewModels: KClass, ) : BindingDialogFragment(contentLayoutId), LifecycleOwner { - @Inject - lateinit var viewModelFactory: ViewModelFactory + abstract val viewModelProvideOwner: ViewModelStoreOwner - val viewModelImpl: MutableList = mutableListOf() - - protected inline fun getViewModel(): Lazy { + inline fun getViewModel(): Lazy { return lazy { - viewModelImpl.find { it is T }?.let { it as T } - ?: kotlin.run { throw IllegalStateException("Can't find [${T::class.java.simpleName}] type ViewModel") } + ViewModelProvider(viewModelProvideOwner) + .get(T::class.java) + .apply { observeViewModel(this) } } } override fun onCreateView( inflater: LayoutInflater, container: ViewGroup?, - savedInstanceState: Bundle? + savedInstanceState: Bundle?, ): View { return super.onCreateView(inflater, container, savedInstanceState).apply { - inject() - createViewModels() bindingLifeCycleOwner() - bindingToast() - } - } - - abstract fun inject() - - private fun createViewModels() { - for (vm in viewModels) { - viewModelImpl.add(ViewModelProvider(this, viewModelFactory).get(vm.javaObjectType)) } } @@ -59,12 +43,14 @@ abstract class BaseDialogFragment( } } - private fun bindingToast() { - for (vm in viewModelImpl) { - vm.toast.observe(this) { event -> - event.getContentIfNotHandled()?.let { msg -> - Toast.makeText(context, msg, Toast.LENGTH_SHORT).show() - } + fun observeViewModel(viewModel: BaseViewModel) { + observeToast(viewModel) + } + + private fun observeToast(vm: BaseViewModel) { + vm.toast.observe(viewLifecycleOwner) { event -> + event.getContentIfNotHandled()?.let { msg -> + Toast.makeText(context, msg, Toast.LENGTH_SHORT).show() } } } diff --git a/app/src/main/java/com/beomjo/whitenoise/base/BaseFragment.kt b/app/src/main/java/com/beomjo/whitenoise/base/BaseFragment.kt index b1c3650..3fcd0c3 100644 --- a/app/src/main/java/com/beomjo/whitenoise/base/BaseFragment.kt +++ b/app/src/main/java/com/beomjo/whitenoise/base/BaseFragment.kt @@ -8,33 +8,26 @@ import android.view.WindowManager import android.widget.Toast import androidx.annotation.LayoutRes import androidx.databinding.ViewDataBinding +import androidx.fragment.app.viewModels import androidx.lifecycle.LifecycleOwner import androidx.lifecycle.ViewModelProvider import androidx.lifecycle.ViewModelStoreOwner -import com.beomjo.whitenoise.factory.ViewModelFactory import com.beomjo.whitenoise.ui.common.ProgressDialogFragment import com.skydoves.bindables.BindingFragment -import javax.inject.Inject -import kotlin.reflect.KClass abstract class BaseFragment( @LayoutRes contentLayoutId: Int, - private vararg var viewModels: KClass, ) : BindingFragment(contentLayoutId), LifecycleOwner { - @Inject - lateinit var viewModelFactory: ViewModelFactory - - val viewModelImpl: MutableList = mutableListOf() - protected var progressDialog: ProgressDialogFragment? = null abstract val viewModelProvideOwner: ViewModelStoreOwner - protected inline fun getViewModel(): Lazy { + inline fun getViewModel(): Lazy { return lazy { - viewModelImpl.find { it is T }?.let { it as T } - ?: kotlin.run { throw IllegalStateException("Can't find [${T::class.java.simpleName}] type ViewModel") } + ViewModelProvider(viewModelProvideOwner) + .get(T::class.java) + .apply { observeViewModel(this) } } } @@ -54,26 +47,10 @@ abstract class BaseFragment( override fun onCreateView( inflater: LayoutInflater, container: ViewGroup?, - savedInstanceState: Bundle? + savedInstanceState: Bundle?, ): View { return super.onCreateView(inflater, container, savedInstanceState).apply { - inject() - createViewModels() bindingLifeCycleOwner() - observeViewModel() - } - } - - abstract fun inject() - - private fun createViewModels() { - for (vm in viewModels) { - viewModelImpl.add( - ViewModelProvider( - viewModelProvideOwner, - viewModelFactory - ).get(vm.javaObjectType) - ) } } @@ -83,11 +60,9 @@ abstract class BaseFragment( } } - private fun observeViewModel() { - for (vm in viewModelImpl) { - observeToast(vm) - observeProgress(vm) - } + fun observeViewModel(viewModel: BaseViewModel) { + observeToast(viewModel) + observeProgress(viewModel) } private fun observeToast(vm: BaseViewModel) { diff --git a/app/src/main/java/com/beomjo/whitenoise/base/BaseSingleBindActivity.kt b/app/src/main/java/com/beomjo/whitenoise/base/BaseSingleBindActivity.kt deleted file mode 100644 index d7168d0..0000000 --- a/app/src/main/java/com/beomjo/whitenoise/base/BaseSingleBindActivity.kt +++ /dev/null @@ -1,46 +0,0 @@ -package com.beomjo.whitenoise.base - -import android.annotation.SuppressLint -import android.os.Bundle -import androidx.annotation.LayoutRes -import androidx.databinding.ViewDataBinding -import androidx.lifecycle.LifecycleOwner -import androidx.lifecycle.ViewModelProvider -import com.beomjo.whitenoise.factory.ViewModelFactory -import com.skydoves.bindables.BindingActivity -import java.lang.reflect.ParameterizedType -import javax.inject.Inject - -@Deprecated(message = "Use BaseActivity") -abstract class BaseSingleBindActivity constructor( - @LayoutRes private val contentLayoutId: Int -) : BindingActivity(contentLayoutId), LifecycleOwner { - - @Inject - lateinit var viewModelFactory: ViewModelFactory - - lateinit var viewModel: VM - - @SuppressLint("MissingSuperCall") - override fun onCreate(savedInstanceState: Bundle?) { - super.onCreate(savedInstanceState) - inject() - createViewModel() - bindingLifeCycleOwner() - } - - private fun createViewModel() { - val clazz = ((javaClass.genericSuperclass as ParameterizedType?) - ?.actualTypeArguments - ?.get(1) as Class) - viewModel = ViewModelProvider(this, viewModelFactory).get(clazz) - } - - abstract fun inject() - - private fun bindingLifeCycleOwner() { - binding { - lifecycleOwner = this@BaseSingleBindActivity - } - } -} \ No newline at end of file diff --git a/app/src/main/java/com/beomjo/whitenoise/di/AppComponent.kt b/app/src/main/java/com/beomjo/whitenoise/di/AppComponent.kt deleted file mode 100644 index 96c1ef4..0000000 --- a/app/src/main/java/com/beomjo/whitenoise/di/AppComponent.kt +++ /dev/null @@ -1,48 +0,0 @@ -package com.beomjo.whitenoise.di - -import android.content.Context -import android.media.MediaPlayer -import com.beomjo.whitenoise.di.auth.AuthComponent -import com.beomjo.whitenoise.di.common.CommonComponent -import com.beomjo.whitenoise.di.main.HomeComponent -import com.beomjo.whitenoise.di.main.MainComponent -import com.beomjo.whitenoise.di.player.PlayerComponent -import com.beomjo.whitenoise.di.track.TrackListComponent -import com.beomjo.whitenoise.ui.player.PlayerManager -import dagger.BindsInstance -import dagger.Component -import javax.inject.Singleton - -@Singleton -@Component( - modules = [ - FirebaseModule::class, - ViewModelFactoryModule::class, - ViewModelModule::class, - RepositoryModule::class, - MediaPlayerModule::class, - ] -) -interface AppComponent { - - @Component.Factory - interface Factory { - fun create(@BindsInstance context: Context): AppComponent - } - - fun commonComponent(): CommonComponent.Factory - - fun authComponent(): AuthComponent.Factory - - fun mainComponent(): MainComponent.Factory - - fun homeComponent(): HomeComponent.Factory - - fun trackListComponent(): TrackListComponent.Factory - - fun playerComponent(): PlayerComponent.Factory - - fun playerManager(): PlayerManager - - fun mediaPlayer(): MediaPlayer -} diff --git a/app/src/main/java/com/beomjo/whitenoise/di/FirebaseModule.kt b/app/src/main/java/com/beomjo/whitenoise/di/FirebaseModule.kt index a15e379..9060fd7 100644 --- a/app/src/main/java/com/beomjo/whitenoise/di/FirebaseModule.kt +++ b/app/src/main/java/com/beomjo/whitenoise/di/FirebaseModule.kt @@ -10,7 +10,11 @@ import com.google.firebase.firestore.FirebaseFirestore import com.google.firebase.storage.FirebaseStorage import dagger.Module import dagger.Provides +import dagger.hilt.InstallIn +import dagger.hilt.android.qualifiers.ApplicationContext +import dagger.hilt.components.SingletonComponent +@InstallIn(SingletonComponent::class) @Module object FirebaseModule { @@ -20,7 +24,7 @@ object FirebaseModule { } @Provides - fun provideGoogleSignInOption(context: Context): GoogleSignInOptions { + fun provideGoogleSignInOption(@ApplicationContext context: Context): GoogleSignInOptions { return GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN) .requestIdToken(context.getString(R.string.default_web_client_id)) .requestEmail() @@ -28,7 +32,7 @@ object FirebaseModule { } @Provides - fun provideGoogleSignInClient(context: Context, gso: GoogleSignInOptions): GoogleSignInClient { + fun provideGoogleSignInClient(@ApplicationContext context: Context, gso: GoogleSignInOptions): GoogleSignInClient { return GoogleSignIn.getClient(context, gso) } diff --git a/app/src/main/java/com/beomjo/whitenoise/di/MediaPlayerModule.kt b/app/src/main/java/com/beomjo/whitenoise/di/MediaPlayerModule.kt index 9945244..cec0a9b 100644 --- a/app/src/main/java/com/beomjo/whitenoise/di/MediaPlayerModule.kt +++ b/app/src/main/java/com/beomjo/whitenoise/di/MediaPlayerModule.kt @@ -3,11 +3,18 @@ package com.beomjo.whitenoise.di import android.content.ComponentName import android.content.Context import android.media.MediaPlayer +import com.beomjo.whitenoise.repositories.player.PlayerRepository +import com.beomjo.whitenoise.ui.player.PlayerManager import com.beomjo.whitenoise.ui.player.PlayerService import com.beomjo.whitenoise.ui.player.PlayerServiceConnection import dagger.Module import dagger.Provides +import dagger.hilt.InstallIn +import dagger.hilt.android.qualifiers.ApplicationContext +import dagger.hilt.components.SingletonComponent +import javax.inject.Singleton +@InstallIn(SingletonComponent::class) @Module object MediaPlayerModule { @@ -16,8 +23,17 @@ object MediaPlayerModule { return MediaPlayer() } + @Singleton @Provides - fun providePlayerServiceConnection(context: Context): PlayerServiceConnection { + fun providePlayerManager( + repository: PlayerRepository, + connection: PlayerServiceConnection + ): PlayerManager { + return PlayerManager(repository, connection) + } + + @Provides + fun providePlayerServiceConnection(@ApplicationContext context: Context): PlayerServiceConnection { return PlayerServiceConnection(context, ComponentName(context, PlayerService::class.java)) } } \ No newline at end of file diff --git a/app/src/main/java/com/beomjo/whitenoise/di/RepositoryModule.kt b/app/src/main/java/com/beomjo/whitenoise/di/RepositoryModule.kt index a65e302..290d87e 100644 --- a/app/src/main/java/com/beomjo/whitenoise/di/RepositoryModule.kt +++ b/app/src/main/java/com/beomjo/whitenoise/di/RepositoryModule.kt @@ -10,7 +10,10 @@ import com.beomjo.whitenoise.repositories.track.TrackListRepository import com.beomjo.whitenoise.repositories.track.TrackListRepositoryImpl import dagger.Binds import dagger.Module +import dagger.hilt.InstallIn +import dagger.hilt.components.SingletonComponent +@InstallIn(SingletonComponent::class) @Module abstract class RepositoryModule { diff --git a/app/src/main/java/com/beomjo/whitenoise/di/SubComponents.kt b/app/src/main/java/com/beomjo/whitenoise/di/SubComponents.kt deleted file mode 100644 index 26d9fda..0000000 --- a/app/src/main/java/com/beomjo/whitenoise/di/SubComponents.kt +++ /dev/null @@ -1,7 +0,0 @@ -package com.beomjo.whitenoise.di - -import com.beomjo.whitenoise.di.auth.AuthComponent -import dagger.Module - -@Module(subcomponents = [AuthComponent::class]) -class SubComponents \ No newline at end of file diff --git a/app/src/main/java/com/beomjo/whitenoise/di/ViewModelFactoryModule.kt b/app/src/main/java/com/beomjo/whitenoise/di/ViewModelFactoryModule.kt deleted file mode 100644 index b2fba56..0000000 --- a/app/src/main/java/com/beomjo/whitenoise/di/ViewModelFactoryModule.kt +++ /dev/null @@ -1,14 +0,0 @@ -package com.beomjo.whitenoise.di - -import androidx.lifecycle.ViewModelProvider -import com.beomjo.whitenoise.factory.ViewModelFactory -import dagger.Binds -import dagger.Module - -@Module -abstract class ViewModelFactoryModule { - - @Binds - abstract fun bindViewModelFactory(viewModelFactory: ViewModelFactory): ViewModelProvider.Factory - -} \ No newline at end of file diff --git a/app/src/main/java/com/beomjo/whitenoise/di/ViewModelKey.kt b/app/src/main/java/com/beomjo/whitenoise/di/ViewModelKey.kt deleted file mode 100644 index e791967..0000000 --- a/app/src/main/java/com/beomjo/whitenoise/di/ViewModelKey.kt +++ /dev/null @@ -1,14 +0,0 @@ -package com.beomjo.whitenoise.di - -import androidx.lifecycle.ViewModel -import dagger.MapKey -import kotlin.reflect.KClass - -@MapKey -@Target( - AnnotationTarget.FUNCTION, - AnnotationTarget.PROPERTY_GETTER, - AnnotationTarget.PROPERTY_SETTER -) -annotation class ViewModelKey(val value: KClass) - diff --git a/app/src/main/java/com/beomjo/whitenoise/di/ViewModelModule.kt b/app/src/main/java/com/beomjo/whitenoise/di/ViewModelModule.kt deleted file mode 100644 index 215a234..0000000 --- a/app/src/main/java/com/beomjo/whitenoise/di/ViewModelModule.kt +++ /dev/null @@ -1,46 +0,0 @@ -package com.beomjo.whitenoise.di - -import androidx.lifecycle.ViewModel -import com.beomjo.whitenoise.ui.auth.LoginViewModel -import com.beomjo.whitenoise.ui.common.ProgressDialogViewModel -import com.beomjo.whitenoise.ui.main.MainViewModel -import com.beomjo.whitenoise.ui.main.home.HomeViewModel -import com.beomjo.whitenoise.ui.main.track.TrackListViewModel -import com.beomjo.whitenoise.ui.splash.SplashViewModel -import dagger.Binds -import dagger.Module -import dagger.multibindings.IntoMap - -@Module -abstract class ViewModelModule { - - @Binds - @IntoMap - @ViewModelKey(SplashViewModel::class) - abstract fun provideSplashViewModel(splashViewModel: SplashViewModel): ViewModel - - @Binds - @IntoMap - @ViewModelKey(LoginViewModel::class) - abstract fun provideLoginViewModel(loginViewModel: LoginViewModel): ViewModel - - @Binds - @IntoMap - @ViewModelKey(MainViewModel::class) - abstract fun provideMainViewModel(mainViewModel: MainViewModel): ViewModel - - @Binds - @IntoMap - @ViewModelKey(HomeViewModel::class) - abstract fun provideHomeViewModel(homeViewModel: HomeViewModel): ViewModel - - @Binds - @IntoMap - @ViewModelKey(TrackListViewModel::class) - abstract fun provideTrackListViewModel(trackViewModel: TrackListViewModel): ViewModel - - @Binds - @IntoMap - @ViewModelKey(ProgressDialogViewModel::class) - abstract fun provideProgressDialogViewModel(progressDialogViewModel: ProgressDialogViewModel): ViewModel -} \ No newline at end of file diff --git a/app/src/main/java/com/beomjo/whitenoise/di/auth/AuthComponent.kt b/app/src/main/java/com/beomjo/whitenoise/di/auth/AuthComponent.kt deleted file mode 100644 index 8e373a7..0000000 --- a/app/src/main/java/com/beomjo/whitenoise/di/auth/AuthComponent.kt +++ /dev/null @@ -1,18 +0,0 @@ -package com.beomjo.whitenoise.di.auth - -import com.beomjo.whitenoise.ui.auth.LoginActivity -import com.beomjo.whitenoise.ui.splash.SplashActivity -import dagger.Subcomponent - -@Subcomponent() -interface AuthComponent { - - @Subcomponent.Factory - interface Factory { - fun create(): AuthComponent - } - - fun inject(activity: SplashActivity) - - fun inject(activity: LoginActivity) -} \ No newline at end of file diff --git a/app/src/main/java/com/beomjo/whitenoise/di/common/CommonComponent.kt b/app/src/main/java/com/beomjo/whitenoise/di/common/CommonComponent.kt deleted file mode 100644 index fa37e64..0000000 --- a/app/src/main/java/com/beomjo/whitenoise/di/common/CommonComponent.kt +++ /dev/null @@ -1,15 +0,0 @@ -package com.beomjo.whitenoise.di.common - -import com.beomjo.whitenoise.ui.common.ProgressDialogFragment -import dagger.Subcomponent - -@Subcomponent -interface CommonComponent { - - @Subcomponent.Factory - interface Factory { - fun create(): CommonComponent - } - - fun inject(fragment: ProgressDialogFragment) -} \ No newline at end of file diff --git a/app/src/main/java/com/beomjo/whitenoise/di/main/HomeComponent.kt b/app/src/main/java/com/beomjo/whitenoise/di/main/HomeComponent.kt deleted file mode 100644 index 59f2727..0000000 --- a/app/src/main/java/com/beomjo/whitenoise/di/main/HomeComponent.kt +++ /dev/null @@ -1,15 +0,0 @@ -package com.beomjo.whitenoise.di.main - -import com.beomjo.whitenoise.ui.main.home.HomeFragment -import dagger.Subcomponent - -@Subcomponent -interface HomeComponent { - - @Subcomponent.Factory - interface Factory { - fun create(): HomeComponent - } - - fun inject(fragment: HomeFragment) -} \ No newline at end of file diff --git a/app/src/main/java/com/beomjo/whitenoise/di/main/MainComponent.kt b/app/src/main/java/com/beomjo/whitenoise/di/main/MainComponent.kt deleted file mode 100644 index e055d1d..0000000 --- a/app/src/main/java/com/beomjo/whitenoise/di/main/MainComponent.kt +++ /dev/null @@ -1,15 +0,0 @@ -package com.beomjo.whitenoise.di.main - -import com.beomjo.whitenoise.ui.main.MainActivity -import dagger.Subcomponent - -@Subcomponent -interface MainComponent { - - @Subcomponent.Factory - interface Factory { - fun create(): MainComponent - } - - fun inject(mainActivity: MainActivity) -} \ No newline at end of file diff --git a/app/src/main/java/com/beomjo/whitenoise/di/player/PlayerComponent.kt b/app/src/main/java/com/beomjo/whitenoise/di/player/PlayerComponent.kt deleted file mode 100644 index fc20496..0000000 --- a/app/src/main/java/com/beomjo/whitenoise/di/player/PlayerComponent.kt +++ /dev/null @@ -1,15 +0,0 @@ -package com.beomjo.whitenoise.di.player - -import com.beomjo.whitenoise.ui.player.PlayerActivity -import dagger.Subcomponent - -@Subcomponent -interface PlayerComponent { - - @Subcomponent.Factory - interface Factory { - fun create(): PlayerComponent - } - - fun inject(playerActivity: PlayerActivity) -} \ No newline at end of file diff --git a/app/src/main/java/com/beomjo/whitenoise/di/track/TrackListComponent.kt b/app/src/main/java/com/beomjo/whitenoise/di/track/TrackListComponent.kt deleted file mode 100644 index 44b88a0..0000000 --- a/app/src/main/java/com/beomjo/whitenoise/di/track/TrackListComponent.kt +++ /dev/null @@ -1,15 +0,0 @@ -package com.beomjo.whitenoise.di.track - -import com.beomjo.whitenoise.ui.main.track.TrackListFragment -import dagger.Subcomponent - -@Subcomponent -interface TrackListComponent { - - @Subcomponent.Factory - interface Factory { - fun create(): TrackListComponent - } - - fun inject(fragment: TrackListFragment) -} \ No newline at end of file diff --git a/app/src/main/java/com/beomjo/whitenoise/factory/ViewModelFactory.kt b/app/src/main/java/com/beomjo/whitenoise/factory/ViewModelFactory.kt deleted file mode 100644 index 93d4a4c..0000000 --- a/app/src/main/java/com/beomjo/whitenoise/factory/ViewModelFactory.kt +++ /dev/null @@ -1,14 +0,0 @@ -package com.beomjo.whitenoise.factory - -import androidx.lifecycle.ViewModel -import androidx.lifecycle.ViewModelProvider -import javax.inject.Inject -import javax.inject.Provider - -class ViewModelFactory @Inject constructor(val viewModelMap: Map, @JvmSuppressWildcards Provider>) : - ViewModelProvider.Factory { - override fun create(modelClass: Class): T { - return viewModelMap[modelClass]?.get() as T - } -} - diff --git a/app/src/main/java/com/beomjo/whitenoise/repositories/auth/AuthRepositoryImpl.kt b/app/src/main/java/com/beomjo/whitenoise/repositories/auth/AuthRepositoryImpl.kt index acb1240..509146e 100644 --- a/app/src/main/java/com/beomjo/whitenoise/repositories/auth/AuthRepositoryImpl.kt +++ b/app/src/main/java/com/beomjo/whitenoise/repositories/auth/AuthRepositoryImpl.kt @@ -12,6 +12,7 @@ import com.google.firebase.auth.AuthCredential import com.google.firebase.auth.AuthResult import com.google.firebase.auth.FirebaseAuth import com.google.firebase.auth.GoogleAuthProvider +import dagger.hilt.android.qualifiers.ApplicationContext import kotlinx.coroutines.ExperimentalCoroutinesApi import kotlinx.coroutines.channels.awaitClose import kotlinx.coroutines.flow.Flow @@ -20,7 +21,7 @@ import kotlinx.coroutines.flow.flow import javax.inject.Inject class AuthRepositoryImpl @Inject constructor( - private val context: Context, + @ApplicationContext private val context: Context, private val firebaseAuth: FirebaseAuth, private val googleSignInClient: GoogleSignInClient ) : AuthRepository { diff --git a/app/src/main/java/com/beomjo/whitenoise/ui/auth/LoginActivity.kt b/app/src/main/java/com/beomjo/whitenoise/ui/auth/LoginActivity.kt index 2798381..ea6b070 100644 --- a/app/src/main/java/com/beomjo/whitenoise/ui/auth/LoginActivity.kt +++ b/app/src/main/java/com/beomjo/whitenoise/ui/auth/LoginActivity.kt @@ -5,16 +5,17 @@ import android.content.Intent import android.os.Bundle import androidx.activity.result.ActivityResultLauncher import androidx.activity.result.contract.ActivityResultContracts +import androidx.activity.viewModels import com.beomjo.whitenoise.R import com.beomjo.whitenoise.base.BaseActivity import com.beomjo.whitenoise.databinding.ActivityLoginBinding import com.beomjo.whitenoise.ui.main.MainActivity -import com.beomjo.whitenoise.utilities.ext.getComponent +import dagger.hilt.android.AndroidEntryPoint import kotlinx.coroutines.FlowPreview +@AndroidEntryPoint class LoginActivity : BaseActivity( R.layout.activity_login, - LoginViewModel::class ) { private val viewModel: LoginViewModel by getViewModel() @@ -30,10 +31,6 @@ class LoginActivity : BaseActivity( bindingViewModel() } - override fun inject() { - application.getComponent().authComponent().create().inject(this@LoginActivity) - } - private fun bindingViewModel() { binding { vm = viewModel.apply { diff --git a/app/src/main/java/com/beomjo/whitenoise/ui/auth/LoginViewModel.kt b/app/src/main/java/com/beomjo/whitenoise/ui/auth/LoginViewModel.kt index 45e0a76..3526591 100644 --- a/app/src/main/java/com/beomjo/whitenoise/ui/auth/LoginViewModel.kt +++ b/app/src/main/java/com/beomjo/whitenoise/ui/auth/LoginViewModel.kt @@ -7,6 +7,7 @@ import androidx.lifecycle.viewModelScope import com.beomjo.compilation.util.Event import com.beomjo.whitenoise.base.BaseViewModel import com.beomjo.whitenoise.repositories.auth.AuthRepository +import dagger.hilt.android.lifecycle.HiltViewModel import kotlinx.coroutines.FlowPreview import kotlinx.coroutines.flow.catch import kotlinx.coroutines.flow.flatMapConcat @@ -14,6 +15,7 @@ import kotlinx.coroutines.flow.launchIn import kotlinx.coroutines.flow.onEach import javax.inject.Inject +@HiltViewModel class LoginViewModel @Inject constructor( private val authRepository: AuthRepository ) : BaseViewModel() { diff --git a/app/src/main/java/com/beomjo/whitenoise/ui/common/ProgressDialogFragment.kt b/app/src/main/java/com/beomjo/whitenoise/ui/common/ProgressDialogFragment.kt index c2a8036..9c0bc51 100644 --- a/app/src/main/java/com/beomjo/whitenoise/ui/common/ProgressDialogFragment.kt +++ b/app/src/main/java/com/beomjo/whitenoise/ui/common/ProgressDialogFragment.kt @@ -4,16 +4,20 @@ import android.os.Bundle import android.view.LayoutInflater import android.view.View import android.view.ViewGroup +import androidx.lifecycle.ViewModelStoreOwner import com.beomjo.whitenoise.R import com.beomjo.whitenoise.base.BaseDialogFragment import com.beomjo.whitenoise.databinding.FragmentProgressDialogBinding -import com.beomjo.whitenoise.utilities.ext.getComponent +import dagger.hilt.android.AndroidEntryPoint +@AndroidEntryPoint class ProgressDialogFragment : BaseDialogFragment( R.layout.fragment_progress_dialog, - ProgressDialogViewModel::class ) { + override val viewModelProvideOwner: ViewModelStoreOwner + get() = this + override fun onCreateView( inflater: LayoutInflater, container: ViewGroup?, @@ -24,14 +28,9 @@ class ProgressDialogFragment : BaseDialogFragment return super.onCreateView(inflater, container, savedInstanceState) } - override fun inject() { - activity?.application?.let { - it.getComponent().commonComponent().create().inject(this) - } ?: kotlin.run { dismiss() } - } - companion object { @JvmStatic fun newInstance() = ProgressDialogFragment() } + } \ No newline at end of file diff --git a/app/src/main/java/com/beomjo/whitenoise/ui/main/MainActivity.kt b/app/src/main/java/com/beomjo/whitenoise/ui/main/MainActivity.kt index 2061ef0..b54f45e 100644 --- a/app/src/main/java/com/beomjo/whitenoise/ui/main/MainActivity.kt +++ b/app/src/main/java/com/beomjo/whitenoise/ui/main/MainActivity.kt @@ -7,12 +7,12 @@ import com.beomjo.whitenoise.databinding.ActivityMainBinding import com.beomjo.whitenoise.ui.player.PlayerActivity import com.beomjo.whitenoise.ui.player.PlayerManager import com.beomjo.whitenoise.utilities.ext.applyExitMaterialTransform -import com.beomjo.whitenoise.utilities.ext.getComponent +import dagger.hilt.android.AndroidEntryPoint import javax.inject.Inject +@AndroidEntryPoint class MainActivity : BaseActivity( R.layout.activity_main, - MainViewModel::class ) { @Inject @@ -20,10 +20,6 @@ class MainActivity : BaseActivity( private val mainViewModel: MainViewModel by getViewModel() - override fun inject() { - application.getComponent().mainComponent().create().inject(this) - } - override fun onCreate(savedInstanceState: Bundle?) { applyExitMaterialTransform() super.onCreate(savedInstanceState) diff --git a/app/src/main/java/com/beomjo/whitenoise/ui/main/MainViewModel.kt b/app/src/main/java/com/beomjo/whitenoise/ui/main/MainViewModel.kt index 252daf0..0ad89cb 100644 --- a/app/src/main/java/com/beomjo/whitenoise/ui/main/MainViewModel.kt +++ b/app/src/main/java/com/beomjo/whitenoise/ui/main/MainViewModel.kt @@ -1,7 +1,8 @@ package com.beomjo.whitenoise.ui.main import com.beomjo.whitenoise.base.BaseViewModel +import dagger.hilt.android.lifecycle.HiltViewModel import javax.inject.Inject -class MainViewModel @Inject constructor() : BaseViewModel() { -} \ No newline at end of file +@HiltViewModel +class MainViewModel @Inject constructor() : BaseViewModel() \ No newline at end of file diff --git a/app/src/main/java/com/beomjo/whitenoise/ui/main/home/HomeFragment.kt b/app/src/main/java/com/beomjo/whitenoise/ui/main/home/HomeFragment.kt index 9b97473..d516f2f 100644 --- a/app/src/main/java/com/beomjo/whitenoise/ui/main/home/HomeFragment.kt +++ b/app/src/main/java/com/beomjo/whitenoise/ui/main/home/HomeFragment.kt @@ -15,22 +15,17 @@ import com.beomjo.whitenoise.model.Category import com.beomjo.whitenoise.ui.adapters.HomeAdapter import com.beomjo.whitenoise.ui.main.setting.SettingFragment import com.beomjo.whitenoise.ui.main.track.TrackListFragment -import com.beomjo.whitenoise.utilities.ext.getApplicationComponent +import dagger.hilt.android.AndroidEntryPoint +@AndroidEntryPoint class HomeFragment : BaseFragment( R.layout.fragment_home, - HomeViewModel::class, ) { - private val homeViewModel: HomeViewModel by getViewModel() override val viewModelProvideOwner: ViewModelStoreOwner get() = activity as ViewModelStoreOwner - override fun inject() { - getApplicationComponent().homeComponent().create().inject(this) - } - override fun onStart() { super.onStart() setStatusBarColor(Color.WHITE) @@ -39,7 +34,7 @@ class HomeFragment : BaseFragment( override fun onCreateView( inflater: LayoutInflater, container: ViewGroup?, - savedInstanceState: Bundle? + savedInstanceState: Bundle?, ): View { super.onCreateView(inflater, container, savedInstanceState) return binding { bindingViewModel() }.root @@ -53,10 +48,11 @@ class HomeFragment : BaseFragment( parentFragmentManager.commit { setReorderingAllowed(true) addSharedElement(view, item.id.toString()) - replace( + add( R.id.fragment_container_layout, TrackListFragment.newInstance(item) ) + hide(this@HomeFragment) addToBackStack(null) } } @@ -71,10 +67,11 @@ class HomeFragment : BaseFragment( fun moveToSettingFragment() { parentFragmentManager.commit { - replace( + add( R.id.fragment_container_layout, SettingFragment.newInstance() ) + hide(this@HomeFragment) addToBackStack(null) } } diff --git a/app/src/main/java/com/beomjo/whitenoise/ui/main/home/HomeViewModel.kt b/app/src/main/java/com/beomjo/whitenoise/ui/main/home/HomeViewModel.kt index f6f821c..6aa1308 100644 --- a/app/src/main/java/com/beomjo/whitenoise/ui/main/home/HomeViewModel.kt +++ b/app/src/main/java/com/beomjo/whitenoise/ui/main/home/HomeViewModel.kt @@ -7,8 +7,10 @@ import com.beomjo.whitenoise.model.Category import com.beomjo.whitenoise.model.User import com.beomjo.whitenoise.repositories.auth.AuthRepository import com.beomjo.whitenoise.repositories.home.HomeRepository +import dagger.hilt.android.lifecycle.HiltViewModel import javax.inject.Inject +@HiltViewModel class HomeViewModel @Inject constructor( private val authRepository: AuthRepository, private val homeRepository: HomeRepository, @@ -20,9 +22,6 @@ class HomeViewModel @Inject constructor( private val _user = MutableLiveData() val user: LiveData get() = _user - private val _isRefreshing = MutableLiveData() - val isRefreshing: LiveData get() = _isRefreshing - private val _isLoading = MutableLiveData() val isLoading: LiveData get() = _isLoading @@ -39,13 +38,11 @@ class HomeViewModel @Inject constructor( launch { _isLoading.value = true _categories.value = homeRepository.getHomeCategoryList() - _isRefreshing.value = false _isLoading.value = false } } fun onRefresh() { - _isRefreshing.value = true loadHomeCategoryList() } } \ No newline at end of file diff --git a/app/src/main/java/com/beomjo/whitenoise/ui/main/setting/SettingFragment.kt b/app/src/main/java/com/beomjo/whitenoise/ui/main/setting/SettingFragment.kt index 22cc51c..db76ee6 100644 --- a/app/src/main/java/com/beomjo/whitenoise/ui/main/setting/SettingFragment.kt +++ b/app/src/main/java/com/beomjo/whitenoise/ui/main/setting/SettingFragment.kt @@ -13,15 +13,15 @@ import com.beomjo.whitenoise.BuildConfig import com.beomjo.whitenoise.R import com.beomjo.whitenoise.base.BaseFragment import com.beomjo.whitenoise.databinding.FragmentSettingBinding +import dagger.hilt.android.AndroidEntryPoint +@AndroidEntryPoint class SettingFragment : BaseFragment( R.layout.fragment_setting ) { override val viewModelProvideOwner: ViewModelStoreOwner get() = activity as ViewModelStoreOwner - override fun inject() {} - override fun onCreateView( inflater: LayoutInflater, container: ViewGroup?, diff --git a/app/src/main/java/com/beomjo/whitenoise/ui/main/track/TrackListFragment.kt b/app/src/main/java/com/beomjo/whitenoise/ui/main/track/TrackListFragment.kt index c826d84..4fef26d 100644 --- a/app/src/main/java/com/beomjo/whitenoise/ui/main/track/TrackListFragment.kt +++ b/app/src/main/java/com/beomjo/whitenoise/ui/main/track/TrackListFragment.kt @@ -17,12 +17,12 @@ import com.beomjo.whitenoise.ui.adapters.TrackListAdapter import com.beomjo.whitenoise.ui.player.PlayerActivity import com.beomjo.whitenoise.ui.player.PlayerManager import com.beomjo.whitenoise.utilities.ext.applyMaterialTransform -import com.beomjo.whitenoise.utilities.ext.getApplicationComponent +import dagger.hilt.android.AndroidEntryPoint import javax.inject.Inject +@AndroidEntryPoint class TrackListFragment : BaseFragment( R.layout.fragment_track_list, - TrackListViewModel::class ) { @Inject @@ -34,10 +34,6 @@ class TrackListFragment : BaseFragment( private val category: Category by lazy { arguments?.getParcelable(KEY_HOME_CATEGORY)!! } - override fun inject() { - getApplicationComponent().trackListComponent().create().inject(this) - } - override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { diff --git a/app/src/main/java/com/beomjo/whitenoise/ui/main/track/TrackListViewModel.kt b/app/src/main/java/com/beomjo/whitenoise/ui/main/track/TrackListViewModel.kt index 299dcd1..72a933c 100644 --- a/app/src/main/java/com/beomjo/whitenoise/ui/main/track/TrackListViewModel.kt +++ b/app/src/main/java/com/beomjo/whitenoise/ui/main/track/TrackListViewModel.kt @@ -5,8 +5,10 @@ import androidx.lifecycle.MutableLiveData import com.beomjo.whitenoise.base.BaseViewModel import com.beomjo.whitenoise.model.Track import com.beomjo.whitenoise.repositories.track.TrackListRepository +import dagger.hilt.android.lifecycle.HiltViewModel import javax.inject.Inject +@HiltViewModel class TrackListViewModel @Inject constructor( private val trackListRepository: TrackListRepository ) : BaseViewModel() { diff --git a/app/src/main/java/com/beomjo/whitenoise/ui/player/NotificationManager.kt b/app/src/main/java/com/beomjo/whitenoise/ui/player/NotificationManager.kt index 8529702..2f9027e 100644 --- a/app/src/main/java/com/beomjo/whitenoise/ui/player/NotificationManager.kt +++ b/app/src/main/java/com/beomjo/whitenoise/ui/player/NotificationManager.kt @@ -114,7 +114,7 @@ object NotificationManager { fun createNotificationChannel(context: Context) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { val appName = context.getString(R.string.app_name) - val importance = android.app.NotificationManager.IMPORTANCE_DEFAULT + val importance = android.app.NotificationManager.IMPORTANCE_LOW val channel = NotificationChannel(CHANNEL_ID, appName, importance) val notificationManager = context.getSystemService(AppCompatActivity.NOTIFICATION_SERVICE) as SystemNotificationManager diff --git a/app/src/main/java/com/beomjo/whitenoise/ui/player/PlayerActivity.kt b/app/src/main/java/com/beomjo/whitenoise/ui/player/PlayerActivity.kt index 7c7699c..b380e7b 100644 --- a/app/src/main/java/com/beomjo/whitenoise/ui/player/PlayerActivity.kt +++ b/app/src/main/java/com/beomjo/whitenoise/ui/player/PlayerActivity.kt @@ -14,9 +14,10 @@ import com.beomjo.whitenoise.base.BaseActivity import com.beomjo.whitenoise.databinding.ActivityPlayerBinding import com.beomjo.whitenoise.model.Track import com.beomjo.whitenoise.utilities.ext.applyMaterialTransform -import com.beomjo.whitenoise.utilities.ext.getComponent +import dagger.hilt.android.AndroidEntryPoint import javax.inject.Inject +@AndroidEntryPoint class PlayerActivity : BaseActivity( R.layout.activity_player ) { @@ -28,10 +29,6 @@ class PlayerActivity : BaseActivity( private val isEnterFromBottomPlayer: Boolean by lazy { intent.getBooleanExtra(KEY_BOTTOM_PLAYER_CLICK, false) } - override fun inject() { - application.getComponent().playerComponent().create().inject(this) - } - override fun onStart() { super.onStart() if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { diff --git a/app/src/main/java/com/beomjo/whitenoise/ui/player/PlayerManager.kt b/app/src/main/java/com/beomjo/whitenoise/ui/player/PlayerManager.kt index 94184b2..c4113a8 100644 --- a/app/src/main/java/com/beomjo/whitenoise/ui/player/PlayerManager.kt +++ b/app/src/main/java/com/beomjo/whitenoise/ui/player/PlayerManager.kt @@ -9,9 +9,7 @@ import com.beomjo.whitenoise.repositories.player.PlayerRepository import com.beomjo.whitenoise.utilities.ext.isPlay import kotlinx.coroutines.* import javax.inject.Inject -import javax.inject.Singleton -@Singleton class PlayerManager @Inject constructor( private val playerRepository: PlayerRepository, private val playerServiceConnection: PlayerServiceConnection diff --git a/app/src/main/java/com/beomjo/whitenoise/ui/splash/SplashActivity.kt b/app/src/main/java/com/beomjo/whitenoise/ui/splash/SplashActivity.kt index e0949b0..705c379 100644 --- a/app/src/main/java/com/beomjo/whitenoise/ui/splash/SplashActivity.kt +++ b/app/src/main/java/com/beomjo/whitenoise/ui/splash/SplashActivity.kt @@ -7,11 +7,11 @@ import com.beomjo.whitenoise.base.BaseActivity import com.beomjo.whitenoise.databinding.ActivitySplashBinding import com.beomjo.whitenoise.ui.auth.LoginActivity import com.beomjo.whitenoise.ui.main.MainActivity -import com.beomjo.whitenoise.utilities.ext.getComponent +import dagger.hilt.android.AndroidEntryPoint +@AndroidEntryPoint class SplashActivity : BaseActivity( R.layout.activity_splash, - SplashViewModel::class, ) { private val viewModel: SplashViewModel by getViewModel() @@ -22,10 +22,6 @@ class SplashActivity : BaseActivity( viewModel.init() } - override fun inject() { - application.getComponent().authComponent().create().inject(this) - } - private fun bindingViewModel() { binding { vm = viewModel diff --git a/app/src/main/java/com/beomjo/whitenoise/ui/splash/SplashViewModel.kt b/app/src/main/java/com/beomjo/whitenoise/ui/splash/SplashViewModel.kt index f20e39a..77d98a2 100644 --- a/app/src/main/java/com/beomjo/whitenoise/ui/splash/SplashViewModel.kt +++ b/app/src/main/java/com/beomjo/whitenoise/ui/splash/SplashViewModel.kt @@ -5,12 +5,15 @@ import androidx.lifecycle.MutableLiveData import androidx.lifecycle.viewModelScope import com.beomjo.whitenoise.base.BaseViewModel import com.beomjo.whitenoise.repositories.auth.AuthRepository +import dagger.hilt.android.lifecycle.HiltViewModel import kotlinx.coroutines.delay import kotlinx.coroutines.launch import javax.inject.Inject -class SplashViewModel @Inject constructor(private val authRepository: AuthRepository) : - BaseViewModel() { +@HiltViewModel +class SplashViewModel @Inject constructor( + private val authRepository: AuthRepository, +) : BaseViewModel() { private val _loginState = MutableLiveData() val loginState: LiveData get() = _loginState diff --git a/app/src/main/java/com/beomjo/whitenoise/utilities/ext/ActivityEx.kt b/app/src/main/java/com/beomjo/whitenoise/utilities/ext/ActivityEx.kt index 7f84e25..5b240ec 100644 --- a/app/src/main/java/com/beomjo/whitenoise/utilities/ext/ActivityEx.kt +++ b/app/src/main/java/com/beomjo/whitenoise/utilities/ext/ActivityEx.kt @@ -1,6 +1,5 @@ package com.beomjo.whitenoise.utilities.ext -import android.graphics.Color import android.view.View import android.view.Window import androidx.appcompat.app.AppCompatActivity diff --git a/app/src/main/java/com/beomjo/whitenoise/utilities/ext/ApplicationEx.kt b/app/src/main/java/com/beomjo/whitenoise/utilities/ext/ApplicationEx.kt deleted file mode 100644 index 82b7d57..0000000 --- a/app/src/main/java/com/beomjo/whitenoise/utilities/ext/ApplicationEx.kt +++ /dev/null @@ -1,14 +0,0 @@ -package com.beomjo.whitenoise.utilities.ext - -import android.app.Application -import androidx.fragment.app.Fragment -import com.beomjo.whitenoise.WhiteNoiseApp -import com.beomjo.whitenoise.di.AppComponent - -fun Application.getComponent(): AppComponent { - return (applicationContext as WhiteNoiseApp).appComponent -} - -fun Fragment.getApplicationComponent(): AppComponent { - return (requireActivity().application as WhiteNoiseApp).appComponent -} \ No newline at end of file diff --git a/app/src/main/res/layout/fragment_home.xml b/app/src/main/res/layout/fragment_home.xml index 0120ce1..6ea46ff 100644 --- a/app/src/main/res/layout/fragment_home.xml +++ b/app/src/main/res/layout/fragment_home.xml @@ -89,7 +89,7 @@ android:layout_height="match_parent" app:layout_behavior="@string/appbar_scrolling_view_behavior" app:onRefreshListener="@{() -> homeVM.onRefresh()}" - app:refreshing="@{homeVM.isRefreshing}"> + app:refreshing="@{homeVM.isLoading}"> + android:layout_height="match_parent" + android:visibility="@{homeVM.isLoading ? View.VISIBLE : View.GONE}"> + - \ No newline at end of file diff --git a/app/src/test/java/com/beomjo/whitenoise/viewmodel/HomeViewModelTest.kt b/app/src/test/java/com/beomjo/whitenoise/viewmodel/HomeViewModelTest.kt index 38a95b5..8f33bbe 100644 --- a/app/src/test/java/com/beomjo/whitenoise/viewmodel/HomeViewModelTest.kt +++ b/app/src/test/java/com/beomjo/whitenoise/viewmodel/HomeViewModelTest.kt @@ -91,14 +91,10 @@ class HomeViewModelTest : BaseTest() { val homeCategory = mockk() val homeCategories = listOf(homeCategory) coEvery { homeRepository.getHomeCategoryList() } returns homeCategories - val refreshObserver = mockk> { - every { onChanged(false) } just Runs - } val loadingObserver = mockk> { every { onChanged(true) } just Runs every { onChanged(false) } just Runs } - viewModel.isRefreshing.observeForever(refreshObserver) viewModel.isLoading.observeForever(loadingObserver) //when @@ -108,7 +104,6 @@ class HomeViewModelTest : BaseTest() { coVerifyOrder { loadingObserver.onChanged(true) homeRepository.getHomeCategoryList() - refreshObserver.onChanged(eq(false)) loadingObserver.onChanged(false) } } @@ -120,9 +115,6 @@ class HomeViewModelTest : BaseTest() { val errorMsg = "Fail" every { exception.message } returns errorMsg coEvery { homeRepository.getHomeCategoryList() } throws exception - val refreshObserver = mockk> { - every { onChanged(false) } just Runs - } val loadingObserver = mockk> { every { onChanged(true) } just Runs every { onChanged(false) } just Runs @@ -130,7 +122,6 @@ class HomeViewModelTest : BaseTest() { val toastObserver = mockk>> { every { onChanged(Event(errorMsg)) } just Runs } - viewModel.isRefreshing.observeForever(refreshObserver) viewModel.toast.observeForever(toastObserver) viewModel.isLoading.observeForever(loadingObserver) @@ -149,16 +140,11 @@ class HomeViewModelTest : BaseTest() { fun `Refresh 하여 재로딩`() { //given justRun { viewModel invokeNoArgs "loadHomeCategoryList" } - val refreshObserver = mockk> { - every { onChanged(true) } just Runs - } - viewModel.isRefreshing.observeForever(refreshObserver) //when viewModel.onRefresh() //then - verify { refreshObserver.onChanged(eq(true)) } verify { viewModel invokeNoArgs "loadHomeCategoryList" } } } \ No newline at end of file diff --git a/build.gradle b/build.gradle index 036e6a4..05cecdc 100644 --- a/build.gradle +++ b/build.gradle @@ -3,12 +3,17 @@ buildscript { repositories { google() jcenter() + maven { + url "https://plugins.gradle.org/m2/" + } } dependencies { classpath "com.android.tools.build:gradle:${versions.gradle}" classpath deps.classpath.kotlin classpath 'com.google.gms:google-services:4.3.5' classpath 'com.google.firebase:firebase-crashlytics-gradle:2.5.2' + classpath "com.google.dagger:hilt-android-gradle-plugin:${versions.hilt.core}" + classpath "gradle.plugin.dev.arunkumar:scabbard-gradle-plugin:0.4.0" } }