Skip to content

Commit

Permalink
init feed module
Browse files Browse the repository at this point in the history
  • Loading branch information
Guillaume M committed Jun 18, 2019
1 parent 145fed1 commit fd544d5
Show file tree
Hide file tree
Showing 12 changed files with 229 additions and 0 deletions.
1 change: 1 addition & 0 deletions feed/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
24 changes: 24 additions & 0 deletions feed/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
apply plugin: 'com.android.dynamic-feature'

apply plugin: 'kotlin-platform-android'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-kapt'
apply plugin: 'kotlin-android-extensions'

apply from: '../config_module.gradle'
apply from: '../base_dependencies.gradle'
apply from: '../test_dependencies.gradle'

android {
lintOptions {
lintConfig file(project.rootDir.path + "/feed/lint-rules.xml")
}
}

dependencies {
implementation project(':app')
implementation project(':core')

kapt "com.google.dagger:dagger-compiler:$dagger_version"
kapt "com.squareup.moshi:moshi-kotlin-codegen:$moshi_version"
}
4 changes: 4 additions & 0 deletions feed/lint-rules.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<lint>

</lint>
22 changes: 22 additions & 0 deletions feed/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:dist="http://schemas.android.com/apk/distribution"
package="io.freshdroid.mymonzo.feed">

<dist:module
dist:onDemand="false"
dist:instant="false"
dist:title="@string/feature_name_feed">
<dist:fusing dist:include="true"/>
</dist:module>

<application
android:name="io.freshdroid.mymonzo.MyMonzoApplication"
android:supportsRtl="true"
tools:ignore="AllowBackup,GoogleAppIndexingWarning,MissingApplicationIcon">


</application>

</manifest>

Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package io.freshdroid.mymonzo.feed

import io.freshdroid.core.user.CurrentUserType
import io.reactivex.Scheduler

data class FeedEnvironment(
val currentUser: CurrentUserType,
val scheduler: Scheduler
)
16 changes: 16 additions & 0 deletions feed/src/main/java/io/freshdroid/mymonzo/feed/di/FeedComponent.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package io.freshdroid.mymonzo.feed.di

import dagger.Component
import io.freshdroid.core.di.CoreComponent
import io.freshdroid.mymonzo.feed.FeedEnvironment

@FeedScope
@Component(
dependencies = [CoreComponent::class],
modules = [FeedModule::class]
)
interface FeedComponent {

fun environment(): FeedEnvironment

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package io.freshdroid.mymonzo.feed.di

import io.freshdroid.core.di.CoreComponent
import javax.inject.Singleton

@Singleton
object FeedComponentManager {

private var splashScreenComponent: FeedComponent? = null

fun feedComponent(coreComponent: CoreComponent): FeedComponent {
if (splashScreenComponent == null)
splashScreenComponent = DaggerFeedComponent.builder().coreComponent(coreComponent).build()
return splashScreenComponent as FeedComponent
}

fun destroyFeedComponent() {
splashScreenComponent = null
}


}
24 changes: 24 additions & 0 deletions feed/src/main/java/io/freshdroid/mymonzo/feed/di/FeedModule.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package io.freshdroid.mymonzo.feed.di

import dagger.Module
import dagger.Provides
import io.freshdroid.core.user.CurrentUserType
import io.freshdroid.mymonzo.feed.FeedEnvironment
import io.reactivex.Scheduler

@Module
class FeedModule {

@Provides
@FeedScope
fun provideFeedEnvironment(
currentUser: CurrentUserType,
scheduler: Scheduler
): FeedEnvironment {
return FeedEnvironment(
currentUser,
scheduler
)
}

}
7 changes: 7 additions & 0 deletions feed/src/main/java/io/freshdroid/mymonzo/feed/di/FeedScope.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package io.freshdroid.mymonzo.feed.di

import javax.inject.Scope

@Scope
@Retention(AnnotationRetention.RUNTIME)
annotation class FeedScope
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package io.freshdroid.mymonzo.feed.viewmodels

import androidx.lifecycle.ViewModel
import androidx.lifecycle.ViewModelProvider
import com.uber.autodispose.android.lifecycle.AndroidLifecycleScopeProvider
import io.freshdroid.core.viewmodel.FragmentViewModel
import io.freshdroid.mymonzo.feed.FeedEnvironment

class FeedFragmentViewModel(
environment: FeedEnvironment,
scopeProvider: AndroidLifecycleScopeProvider
) : FragmentViewModel() {

init {

}

@Suppress("UNCHECKED_CAST")
class Factory(
private val environment: FeedEnvironment,
private val scopeProvider: AndroidLifecycleScopeProvider
) : ViewModelProvider.Factory {
override fun <T : ViewModel?> create(modelClass: Class<T>): T {
return FeedFragmentViewModel(environment, scopeProvider) as T
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package io.freshdroid.mymonzo.feed.views

import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.lifecycle.ViewModelProviders
import io.freshdroid.core.ui.BaseFragment
import io.freshdroid.mymonzo.coreComponent
import io.freshdroid.mymonzo.feed.R
import io.freshdroid.mymonzo.feed.di.FeedComponentManager
import io.freshdroid.mymonzo.feed.viewmodels.FeedFragmentViewModel

class FeedFragment : BaseFragment() {

private val component by lazy {
FeedComponentManager.feedComponent(coreComponent())
}
private val viewModelFactory by lazy {
FeedFragmentViewModel.Factory(component.environment(), scopeProvider)
}
private val viewModel by lazy {
ViewModelProviders.of(this, viewModelFactory).get(FeedFragmentViewModel::class.java)
}

override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
super.onCreateView(inflater, container, savedInstanceState)
return inflater.inflate(R.layout.fragment_feed, container, false)
}

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)



viewModel.arguments(arguments)
}

}
33 changes: 33 additions & 0 deletions feed/src/main/res/layout/fragment_feed.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">

<TextView android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:layout_marginTop="@dimen/margin_regular_x2"
android:layout_marginStart="@dimen/margin_regular"
android:layout_marginEnd="@dimen/margin_regular"
android:text="£2058.99"
android:textAppearance="@style/TextAppearance.MaterialComponents.Headline4"
android:textStyle="bold"
android:textColor="@color/colorPrimary"/>

<TextView android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/margin_tiny"
android:layout_marginEnd="@dimen/margin_regular"
android:layout_marginStart="@dimen/margin_regular"
android:gravity="center"
android:textAppearance="@style/TextAppearance.MaterialComponents.Caption"
android:textColor="@color/colorPrimaryLight"
android:text="Balance now"/>

<androidx.recyclerview.widget.RecyclerView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="@dimen/margin_regular_x2"/>

</LinearLayout>

0 comments on commit fd544d5

Please sign in to comment.