Pārlūkot izejas kodu

add new feature - auth

MrOzOn 5 gadi atpakaļ
vecāks
revīzija
55459e0a4c

+ 1 - 0
app/build.gradle

@@ -63,4 +63,5 @@ dependencies {
     androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
     implementation project(':utils')
     implementation project(':feature_splash')
+    implementation project(':feature_auth')
 }

+ 10 - 1
app/src/main/res/navigation/nav_graph.xml

@@ -9,5 +9,14 @@
         android:id="@+id/splashFragment"
         android:name="com.mrozon.feature_splash.presentation.SplashFragment"
         android:label="SplashFragment"
-        tools:layout="@layout/fragment_splash" />
+        tools:layout="@layout/fragment_splash" >
+        <action
+            android:id="@+id/action_splashFragment_to_loginFragment"
+            app:destination="@id/loginFragment" />
+    </fragment>
+    <fragment
+        android:id="@+id/loginFragment"
+        android:name="com.mrozon.feature_auth.presentation.LoginFragment"
+        tools:layout="@layout/fragment_login"
+        android:label="LoginFragment" />
 </navigation>

+ 1 - 0
feature_auth/.gitignore

@@ -0,0 +1 @@
+/build

+ 61 - 0
feature_auth/build.gradle

@@ -0,0 +1,61 @@
+apply plugin: 'com.android.library'
+apply plugin: 'kotlin-android'
+apply plugin: 'kotlin-android-extensions'
+apply plugin: 'kotlin-kapt'
+
+android {
+    compileSdkVersion rootProject.compileSdkVersion
+    buildToolsVersion "29.0.3"
+
+    defaultConfig {
+        minSdkVersion rootProject.minSdkVersion
+        targetSdkVersion rootProject.targetSdkVersion
+        versionCode 1
+        versionName "1.0"
+
+        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
+        consumerProguardFiles "consumer-rules.pro"
+    }
+
+    buildTypes {
+        release {
+            minifyEnabled false
+            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
+        }
+    }
+    dataBinding {
+        enabled = true
+    }
+    compileOptions {
+        sourceCompatibility JavaVersion.VERSION_1_8
+        targetCompatibility JavaVersion.VERSION_1_8
+    }
+    kotlinOptions {
+        jvmTarget = '1.8'
+    }
+}
+
+apply from: "$project.rootDir/scripts/deps_versions.gradle"
+
+dependencies {
+    api project(':core_api')
+    implementation project(':core')
+    //DAGGER
+    implementation dagger
+    implementation 'androidx.legacy:legacy-support-v4:1.0.0'
+    kapt daggerCompiler
+    implementation project(':utils')
+    implementation constraintlayout
+    //Timber
+    implementation timber
+    implementation navigationFragment
+
+    implementation fileTree(dir: "libs", include: ["*.jar"])
+    implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
+    implementation 'androidx.core:core-ktx:1.3.1'
+    implementation 'androidx.appcompat:appcompat:1.2.0'
+    testImplementation 'junit:junit:4.12'
+    androidTestImplementation 'androidx.test.ext:junit:1.1.1'
+    androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
+
+}

+ 0 - 0
feature_auth/consumer-rules.pro


+ 21 - 0
feature_auth/proguard-rules.pro

@@ -0,0 +1,21 @@
+# Add project specific ProGuard rules here.
+# You can control the set of applied configuration files using the
+# proguardFiles setting in build.gradle.
+#
+# For more details, see
+#   http://developer.android.com/guide/developing/tools/proguard.html
+
+# If your project uses WebView with JS, uncomment the following
+# and specify the fully qualified class name to the JavaScript interface
+# class:
+#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
+#   public *;
+#}
+
+# Uncomment this to preserve the line number information for
+# debugging stack traces.
+#-keepattributes SourceFile,LineNumberTable
+
+# If you keep the line number information, uncomment this to
+# hide the original source file name.
+#-renamesourcefileattribute SourceFile

+ 24 - 0
feature_auth/src/androidTest/java/com/mrozon/feature_auth/ExampleInstrumentedTest.kt

@@ -0,0 +1,24 @@
+package com.mrozon.feature_auth
+
+import androidx.test.platform.app.InstrumentationRegistry
+import androidx.test.ext.junit.runners.AndroidJUnit4
+
+import org.junit.Test
+import org.junit.runner.RunWith
+
+import org.junit.Assert.*
+
+/**
+ * Instrumented test, which will execute on an Android device.
+ *
+ * See [testing documentation](http://d.android.com/tools/testing).
+ */
+@RunWith(AndroidJUnit4::class)
+class ExampleInstrumentedTest {
+    @Test
+    fun useAppContext() {
+        // Context of the app under test.
+        val appContext = InstrumentationRegistry.getInstrumentation().targetContext
+        assertEquals("com.mrozon.feature_auth.test", appContext.packageName)
+    }
+}

+ 5 - 0
feature_auth/src/main/AndroidManifest.xml

@@ -0,0 +1,5 @@
+<manifest xmlns:android="http://schemas.android.com/apk/res/android"
+    package="com.mrozon.feature_auth">
+
+    /
+</manifest>

+ 31 - 0
feature_auth/src/main/java/com/mrozon/feature_auth/di/DaggerViewModelFactory.kt

@@ -0,0 +1,31 @@
+package com.mrozon.feature_auth.di
+
+import androidx.lifecycle.ViewModel
+import androidx.lifecycle.ViewModelProvider
+import javax.inject.Inject
+import javax.inject.Provider
+
+class DaggerViewModelFactory @Inject constructor(
+    private val creators: @JvmSuppressWildcards Map<Class<out ViewModel>, Provider<ViewModel>>
+) : ViewModelProvider.Factory {
+    override fun <T : ViewModel> create(modelClass: Class<T>): T {
+        var creator: Provider<out ViewModel>? = creators[modelClass]
+        if (creator == null) {
+            for ((key, value) in creators) {
+                if (modelClass.isAssignableFrom(key)) {
+                    creator = value
+                    break
+                }
+            }
+        }
+        if (creator == null) {
+            throw IllegalArgumentException("Unknown model class: $modelClass")
+        }
+        try {
+            @Suppress("UNCHECKED_CAST")
+            return creator.get() as T
+        } catch (e: Exception) {
+            throw RuntimeException(e)
+        }
+    }
+}

+ 34 - 0
feature_auth/src/main/java/com/mrozon/feature_auth/di/LoginFragmentComponent.kt

@@ -0,0 +1,34 @@
+package com.mrozon.feature_auth.di
+
+import com.mrozon.core_api.providers.AppWithFacade
+import com.mrozon.core_api.providers.ProvidersFacade
+import com.mrozon.core_api.viewmodel.ViewModelsFactoryProvider
+import com.mrozon.feature_auth.presentation.LoginFragment
+import dagger.Component
+import javax.inject.Singleton
+
+@Singleton
+@Component(
+    modules = [LoginFragmentModule::class],
+    dependencies = [ProvidersFacade::class]
+)
+interface LoginFragmentComponent: ViewModelsFactoryProvider {
+
+    companion object {
+
+        fun create(providersFacade: ProvidersFacade): LoginFragmentComponent {
+            return DaggerLoginFragmentComponent.builder()
+                .providersFacade(providersFacade)
+                .build()
+        }
+
+        fun injectFragment(fragment: LoginFragment): LoginFragmentComponent  {
+            val component = create((fragment.activity?.application
+                    as AppWithFacade).getFacade())
+            component.inject(fragment)
+            return component
+        }
+    }
+
+    fun inject(fragment: LoginFragment)
+}

+ 22 - 0
feature_auth/src/main/java/com/mrozon/feature_auth/di/LoginFragmentModule.kt

@@ -0,0 +1,22 @@
+package com.mrozon.feature_auth.di
+
+import androidx.lifecycle.ViewModel
+import androidx.lifecycle.ViewModelProvider
+import com.mrozon.core_api.viewmodel.ViewModelKey
+import com.mrozon.feature_auth.presentation.LoginFragmentViewModel
+import dagger.Binds
+import dagger.Module
+import dagger.multibindings.IntoMap
+
+@Module
+interface LoginFragmentModule {
+
+    @Binds
+    @IntoMap
+    @ViewModelKey(LoginFragmentViewModel::class)
+    fun bindViewModel(viewmodel: LoginFragmentViewModel): ViewModel
+
+    @Binds
+    fun viewModelFactory(factory: DaggerViewModelFactory): ViewModelProvider.Factory
+
+}

+ 31 - 0
feature_auth/src/main/java/com/mrozon/feature_auth/presentation/LoginFragment.kt

@@ -0,0 +1,31 @@
+package com.mrozon.feature_auth.presentation
+
+import android.content.Context
+import androidx.fragment.app.Fragment
+import androidx.fragment.app.viewModels
+import androidx.lifecycle.ViewModelProvider
+import com.mrozon.feature_auth.R
+import com.mrozon.feature_auth.databinding.FragmentLoginBinding
+import com.mrozon.feature_auth.di.LoginFragmentComponent
+import com.mrozon.utils.base.BaseFragment
+import javax.inject.Inject
+
+class LoginFragment : BaseFragment<FragmentLoginBinding>() {
+
+    override fun getLayoutId(): Int = R.layout.fragment_login
+
+    @Inject
+    lateinit var viewModelFactory: ViewModelProvider.Factory
+
+    private val viewModel by viewModels<LoginFragmentViewModel> { viewModelFactory }
+
+    override fun onAttach(context: Context) {
+        super.onAttach(context)
+        LoginFragmentComponent.injectFragment(this)
+    }
+
+    override fun subscribeUi() {
+        TODO("Not yet implemented")
+    }
+
+}

+ 9 - 0
feature_auth/src/main/java/com/mrozon/feature_auth/presentation/LoginFragmentViewModel.kt

@@ -0,0 +1,9 @@
+package com.mrozon.feature_auth.presentation
+
+import com.mrozon.utils.base.BaseViewModel
+import javax.inject.Inject
+
+class LoginFragmentViewModel @Inject constructor(
+): BaseViewModel() {
+
+}

+ 28 - 0
feature_auth/src/main/res/layout/fragment_login.xml

@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="utf-8"?>
+<layout xmlns:android="http://schemas.android.com/apk/res/android"
+    xmlns:app="http://schemas.android.com/apk/res-auto"
+    xmlns:tools="http://schemas.android.com/tools">
+
+    <data>
+
+    </data>
+
+    <androidx.constraintlayout.widget.ConstraintLayout
+        android:layout_width="match_parent"
+        android:layout_height="match_parent">
+
+        <TextView
+            android:id="@+id/textView"
+            android:layout_width="wrap_content"
+            android:layout_height="wrap_content"
+            android:layout_marginStart="32dp"
+            android:layout_marginTop="32dp"
+            android:layout_marginEnd="32dp"
+            android:layout_marginBottom="32dp"
+            android:text="TextView"
+            app:layout_constraintBottom_toBottomOf="parent"
+            app:layout_constraintEnd_toEndOf="parent"
+            app:layout_constraintStart_toStartOf="parent"
+            app:layout_constraintTop_toTopOf="parent" />
+    </androidx.constraintlayout.widget.ConstraintLayout>
+</layout>

+ 4 - 0
feature_auth/src/main/res/values/strings.xml

@@ -0,0 +1,4 @@
+<resources>
+    <!-- TODO: Remove or change this placeholder text -->
+    <string name="hello_blank_fragment">Hello blank fragment</string>
+</resources>

+ 17 - 0
feature_auth/src/test/java/com/mrozon/feature_auth/ExampleUnitTest.kt

@@ -0,0 +1,17 @@
+package com.mrozon.feature_auth
+
+import org.junit.Test
+
+import org.junit.Assert.*
+
+/**
+ * Example local unit test, which will execute on the development machine (host).
+ *
+ * See [testing documentation](http://d.android.com/tools/testing).
+ */
+class ExampleUnitTest {
+    @Test
+    fun addition_isCorrect() {
+        assertEquals(4, 2 + 2)
+    }
+}

+ 1 - 0
settings.gradle

@@ -1,3 +1,4 @@
+include ':feature_auth'
 rootProject.name='HealthDiary'
 include ':app'
 include ':utils'