Skip to content

Commit

Permalink
Merge pull request #5 from dbof10/cleanup
Browse files Browse the repository at this point in the history
cleanup, rename
  • Loading branch information
dbof10 committed Jan 29, 2018
2 parents a75ab76 + bead0ad commit bb11fde
Show file tree
Hide file tree
Showing 62 changed files with 367 additions and 493 deletions.
2 changes: 1 addition & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@
android:theme="@style/AppTheme.NoStatusBar" />

<activity
android:name=".ui.topiclist.view.TopicListActivity"
android:name=".ui.topicdetail.view.TopicDetailActivity"
android:screenOrientation="portrait"
android:theme="@style/AppTheme" />

Expand Down
18 changes: 10 additions & 8 deletions app/src/main/java/com/ctech/eaty/di/ActivityBindingModule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import com.ctech.eaty.ui.follow.view.FollowActivity
import com.ctech.eaty.ui.gallery.di.GalleryFragmentBuilderModule
import com.ctech.eaty.ui.gallery.di.GalleryModule
import com.ctech.eaty.ui.gallery.view.GalleryActivity
import com.ctech.eaty.ui.video.view.YoutubeActivity
import com.ctech.eaty.ui.home.di.HomeFragmentBuilderModule
import com.ctech.eaty.ui.home.di.HomeModule
import com.ctech.eaty.ui.home.view.HomeActivity
Expand All @@ -44,21 +43,24 @@ import com.ctech.eaty.ui.profile.view.ProfileActivity
import com.ctech.eaty.ui.radio.di.RadioFragmentBuilderModule
import com.ctech.eaty.ui.radio.di.RadioModule
import com.ctech.eaty.ui.radio.view.RadioActivity
import com.ctech.eaty.ui.search.di.SearchModule
import com.ctech.eaty.ui.search.view.SearchActivity
import com.ctech.eaty.ui.settings.di.SettingsModule
import com.ctech.eaty.ui.settings.view.SettingsActivity
import com.ctech.eaty.ui.splash.view.SplashActivity
import com.ctech.eaty.ui.topic.di.TopicFragmentBuilderModule
import com.ctech.eaty.ui.topic.di.TopicModule
import com.ctech.eaty.ui.topic.view.TopicActivity
import com.ctech.eaty.ui.topiclist.di.TopicListFragmentBuilderModule
import com.ctech.eaty.ui.topiclist.di.TopicListModule
import com.ctech.eaty.ui.topiclist.view.TopicListActivity
import com.ctech.eaty.ui.topicdetail.di.TopicDetailFragmentBuilderModule
import com.ctech.eaty.ui.topicdetail.di.TopicDetailModule
import com.ctech.eaty.ui.topicdetail.view.TopicDetailActivity
import com.ctech.eaty.ui.upcomingdetail.di.UpcomingDetailBuilderModule
import com.ctech.eaty.ui.upcomingdetail.di.UpcomingProductModule
import com.ctech.eaty.ui.upcomingdetail.view.UpcomingProductDetailActivity
import com.ctech.eaty.ui.user.di.UserDetailFragmentBuilderModule
import com.ctech.eaty.ui.user.di.UserDetailModule
import com.ctech.eaty.ui.user.view.UserActivity
import com.ctech.eaty.ui.video.view.YoutubeActivity
import com.ctech.eaty.ui.vote.di.VoteFragmentBuilderModule
import com.ctech.eaty.ui.vote.di.VoteModule
import com.ctech.eaty.ui.vote.view.VoteActivity
Expand Down Expand Up @@ -96,8 +98,8 @@ abstract class ActivityBindingModule {
abstract fun contributeVoteActivity(): VoteActivity

@ActivityScope
@ContributesAndroidInjector(modules = [(TopicListModule::class), (TopicListFragmentBuilderModule::class)])
abstract fun contributeTopicListActivity(): TopicListActivity
@ContributesAndroidInjector(modules = [(TopicDetailModule::class), (TopicDetailFragmentBuilderModule::class)])
abstract fun contributeTopicListActivity(): TopicDetailActivity

@ContributesAndroidInjector()
abstract fun contributeDeepLinkActivity(): UniversalLinkActivity
Expand Down Expand Up @@ -151,8 +153,8 @@ abstract class ActivityBindingModule {
abstract fun contributeJobsActivity(): JobListActivity

@ActivityScope
@ContributesAndroidInjector(modules = [(com.ctech.eaty.ui.search.di.SearchModule::class)])
abstract fun contributeSearchActivity(): com.ctech.eaty.ui.search.view.SearchActivity
@ContributesAndroidInjector(modules = [(SearchModule::class)])
abstract fun contributeSearchActivity(): SearchActivity

@ActivityScope
@ContributesAndroidInjector(modules = [(MeetupModule::class)])
Expand Down
22 changes: 15 additions & 7 deletions app/src/main/java/com/ctech/eaty/di/StoreModule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,21 @@ package com.ctech.eaty.di

import android.content.Context
import com.ctech.eaty.entity.Comments
import com.ctech.eaty.repository.HomePersister
import com.ctech.eaty.network.ProductHuntApi
import com.ctech.eaty.network.SoundCloudApi
import com.ctech.eaty.repository.*
import com.ctech.eaty.response.*
import com.ctech.eaty.repository.HomePersister
import com.ctech.eaty.repository.ProductDetailPersister
import com.ctech.eaty.response.CollectionDetailResponse
import com.ctech.eaty.response.CollectionResponse
import com.ctech.eaty.response.NotificationResponse
import com.ctech.eaty.response.ProductDetailResponse
import com.ctech.eaty.response.ProductResponse
import com.ctech.eaty.response.RadioResponse
import com.ctech.eaty.response.TopicResponse
import com.ctech.eaty.response.UserResponse
import com.ctech.eaty.response.VoteResponse
import com.ctech.eaty.ui.comment.action.CommentBarCode
import com.ctech.eaty.ui.topiclist.action.SearchBarCode
import com.ctech.eaty.ui.topicdetail.action.TopicDetailBarCode
import com.ctech.eaty.ui.user.action.UserProductBarCode
import com.ctech.eaty.ui.vote.action.VoteBarCode
import com.ctech.eaty.util.Constants
Expand Down Expand Up @@ -68,8 +76,8 @@ class StoreModule {

@Provides
fun providePersistedSearchStore(apiClient: ProductHuntApi, gson: Gson)
: Store<ProductResponse, SearchBarCode> {
return StoreBuilder.parsedWithKey<SearchBarCode, BufferedSource, ProductResponse>()
: Store<ProductResponse, TopicDetailBarCode> {
return StoreBuilder.parsedWithKey<TopicDetailBarCode, BufferedSource, ProductResponse>()
.fetcher { barcode -> apiClient.getProductsByTopic(barcode.id, SEARCH_LIMIT, barcode.page).map { it.source() } }
.parser(GsonParserFactory.createSourceParser(gson, ProductResponse::class.java))
.open()
Expand All @@ -79,7 +87,7 @@ class StoreModule {
fun provideProductDetailStore(apiClient: ProductHuntApi, persister: Persister<ProductDetailResponse, BarCode>)
: Store<ProductDetailResponse, BarCode> {
return StoreBuilder.parsedWithKey<BarCode, ProductDetailResponse, ProductDetailResponse>()
.fetcher { barcode -> apiClient.getProductDetail(barcode.key.toInt())}
.fetcher { barcode -> apiClient.getProductDetail(barcode.key.toInt()) }
.persister(persister)
.networkBeforeStale()
.open()
Expand Down
32 changes: 28 additions & 4 deletions app/src/main/java/com/ctech/eaty/repository/BarcodeGenerator.kt
Original file line number Diff line number Diff line change
@@ -1,22 +1,46 @@
package com.ctech.eaty.repository

import com.ctech.eaty.entity.Comments
import com.ctech.eaty.response.CollectionDetailResponse
import com.ctech.eaty.response.CollectionResponse
import com.ctech.eaty.response.ProductDetailResponse
import com.ctech.eaty.response.ProductResponse
import com.ctech.eaty.response.TopicResponse
import com.ctech.eaty.response.UserResponse
import com.ctech.eaty.response.VoteResponse
import com.ctech.eaty.ui.comment.action.CommentBarCode
import com.ctech.eaty.ui.topicdetail.action.TopicDetailBarCode
import com.ctech.eaty.ui.user.action.UserProductBarCode
import com.ctech.eaty.ui.vote.action.VoteBarCode
import com.ctech.eaty.util.DateUtils
import com.nytimes.android.external.store3.base.impl.BarCode
import org.joda.time.DateTime


object BarcodeGenerator {

fun createHomeNextBarCode(dayAgo: Int): BarCode = BarCode(ProductResponse::class.java.simpleName,
DateUtils.getFormattedPastDate(DateTime.now(), dayAgo))
}


fun createProductDetailBarcode(id: Int): BarCode = BarCode(ProductDetailResponse::class.java.simpleName, id.toString())
fun createProductDetailBarCode(id: Int): BarCode = BarCode(ProductDetailResponse::class.java.simpleName, id.toString())

fun createUserProductBarCode(id: Int, page: Int) = UserProductBarCode(ProductResponse::class.java.simpleName, "User $id page $page", id, page)

fun createUserBarCode(id: Int): BarCode = BarCode(UserResponse::class.java.simpleName, id.toString())

fun createCollectionDetailBarCode(id: Int): BarCode = BarCode(CollectionDetailResponse::class.java.simpleName, id.toString())

fun createCollectionListBarCode(page: Int): BarCode = BarCode(CollectionResponse::class.java.simpleName, page.toString())

fun createTopicListBarCode(page: Int): BarCode = BarCode(TopicResponse::class.java.simpleName, page.toString())

fun createTopicDetailBarCode(id: Int, page: Int): TopicDetailBarCode = TopicDetailBarCode(ProductResponse::class.java.simpleName, "Post $id page $page", id, page)

fun createVoteListBarCode(id: Int, page: Int): VoteBarCode = VoteBarCode(VoteResponse::class.java.simpleName, "Post $id page $page", id, page)

fun createCommentListBarCode(id: Int, page: Int): CommentBarCode = CommentBarCode(Comments::class.java.simpleName, "Post $id page $page", id, page)

}

fun createUserProductBarCode(id: Int, page: Int) = UserProductBarCode(ProductResponse::class.java.simpleName, "User $id page $page", id, page)

fun createUserBarCode(id: Int): BarCode = BarCode(UserResponse::class.java.simpleName, id.toString())
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,19 @@ import com.apollographql.apollo.fetcher.ApolloResponseFetchers
import com.apollographql.apollo.rx2.Rx2Apollo
import com.ctech.eaty.CreateUpcomingPageSubscriberMutation
import com.ctech.eaty.HomeCardsQuery
import com.ctech.eaty.UpcomingPagesPageQuery
import com.ctech.eaty.UpcomingShowPageQuery
import com.ctech.eaty.entity.HomeCard
import com.ctech.eaty.entity.HomeCardType
import com.ctech.eaty.entity.Product
import com.ctech.eaty.entity.ProductDetail
import com.ctech.eaty.entity.UpcomingDetail
import com.ctech.eaty.entity.UpcomingProduct
import com.ctech.eaty.network.ProductHuntApi
import com.ctech.eaty.repository.mapper.HomeCardMapper
import com.ctech.eaty.repository.mapper.ProductMapper
import com.ctech.eaty.response.ProductDetailResponse
import com.ctech.eaty.response.ProductResponse
import com.ctech.eaty.type.CreateUpcomingPageSubscriberInput
import com.ctech.eaty.ui.topiclist.action.SearchBarCode
import com.ctech.eaty.ui.topicdetail.action.TopicDetailBarCode
import com.nytimes.android.external.store3.base.impl.BarCode
import com.nytimes.android.external.store3.base.impl.Store
import io.reactivex.Observable
Expand All @@ -30,7 +28,7 @@ import javax.inject.Inject
class ProductRepository @Inject constructor(
private val homeStore: Store<ProductResponse, BarCode>,
private val productStore: Store<ProductDetailResponse, BarCode>,
private val searchStore: Store<ProductResponse, SearchBarCode>,
private val searchStore: Store<ProductResponse, TopicDetailBarCode>,
private val apiClient: ProductHuntApi,
private val apolloClient: ApolloClient,
private val productMapper: ProductMapper,
Expand All @@ -57,7 +55,7 @@ class ProductRepository @Inject constructor(
productStore.clear(barcode)
}

fun getPostsByTopic(barcode: SearchBarCode): Observable<List<Product>> {
fun getPostsByTopic(barcode: TopicDetailBarCode): Observable<List<Product>> {
return searchStore.get(barcode)
.toObservable()
.map { it.products }
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package com.ctech.eaty.ui.collection.di
import com.ctech.eaty.base.redux.Store
import com.ctech.eaty.di.ActivityScope
import com.ctech.eaty.repository.CollectionRepository
import com.ctech.eaty.ui.collection.action.BarCodeGenerator
import com.ctech.eaty.ui.collection.epic.LoadEpic
import com.ctech.eaty.ui.collection.epic.LoadMoreEpic
import com.ctech.eaty.ui.collection.reducer.CollectionReducer
Expand All @@ -18,17 +17,12 @@ import io.reactivex.android.schedulers.AndroidSchedulers
@Module
class CollectionModule {

@Provides
fun provideBarCodeGenerator(): BarCodeGenerator {
return BarCodeGenerator()
}

@ActivityScope
@Provides
fun provideCommentStore(collectionRepository: CollectionRepository, barCodeGenerator: BarCodeGenerator,
fun provideCommentStore(collectionRepository: CollectionRepository,
threadScheduler: ThreadScheduler): Store<CollectionState> {
return Store<CollectionState>(CollectionState(), CollectionReducer(), arrayOf(LoadEpic(collectionRepository, barCodeGenerator, threadScheduler),
LoadMoreEpic(collectionRepository, barCodeGenerator, threadScheduler)))
return Store<CollectionState>(CollectionState(), CollectionReducer(), arrayOf(LoadEpic(collectionRepository, threadScheduler),
LoadMoreEpic(collectionRepository, threadScheduler)))

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ package com.ctech.eaty.ui.collection.epic

import com.ctech.eaty.base.redux.Action
import com.ctech.eaty.base.redux.Epic
import com.ctech.eaty.repository.BarcodeGenerator.createCollectionListBarCode
import com.ctech.eaty.repository.CollectionRepository
import com.ctech.eaty.ui.collection.action.BarCodeGenerator
import com.ctech.eaty.ui.collection.action.CollectionAction
import com.ctech.eaty.ui.collection.result.LoadResult
import com.ctech.eaty.ui.collection.state.CollectionState
Expand All @@ -12,9 +12,8 @@ import io.reactivex.Observable
import io.reactivex.subjects.BehaviorSubject
import io.reactivex.subjects.PublishSubject

class LoadEpic(val collectionRepository: CollectionRepository,
val barCodeGenerator: BarCodeGenerator,
val threadScheduler: ThreadScheduler) : Epic<CollectionState> {
class LoadEpic(private val collectionRepository: CollectionRepository,
private val threadScheduler: ThreadScheduler) : Epic<CollectionState> {
override fun apply(action: PublishSubject<Action>, state: BehaviorSubject<CollectionState>): Observable<LoadResult> {
return action.filter {
it == CollectionAction.LOAD
Expand All @@ -23,7 +22,7 @@ class LoadEpic(val collectionRepository: CollectionRepository,
state.value.content.isEmpty()
}
.flatMap {
collectionRepository.getCollections(barCodeGenerator.get(0))
collectionRepository.getCollections(createCollectionListBarCode(0))
.map {
LoadResult.success(it)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ package com.ctech.eaty.ui.collection.epic

import com.ctech.eaty.base.redux.Action
import com.ctech.eaty.base.redux.Epic
import com.ctech.eaty.repository.BarcodeGenerator.createCollectionListBarCode
import com.ctech.eaty.repository.CollectionRepository
import com.ctech.eaty.ui.collection.action.BarCodeGenerator
import com.ctech.eaty.ui.collection.action.CollectionAction
import com.ctech.eaty.ui.collection.result.LoadMoreResult
import com.ctech.eaty.ui.collection.state.CollectionState
Expand All @@ -12,9 +12,8 @@ import io.reactivex.Observable
import io.reactivex.subjects.BehaviorSubject
import io.reactivex.subjects.PublishSubject

class LoadMoreEpic(val collectionRepository: CollectionRepository,
val barCodeGenerator: BarCodeGenerator,
val threadScheduler: ThreadScheduler) : Epic<CollectionState> {
class LoadMoreEpic(private val collectionRepository: CollectionRepository,
private val threadScheduler: ThreadScheduler) : Epic<CollectionState> {
override fun apply(action: PublishSubject<Action>, state: BehaviorSubject<CollectionState>): Observable<LoadMoreResult> {
return action
.filter {
Expand All @@ -25,7 +24,7 @@ class LoadMoreEpic(val collectionRepository: CollectionRepository,
}
.flatMap {
val page = state.value.page + 1
collectionRepository.getCollections(barCodeGenerator.get(page))
collectionRepository.getCollections(createCollectionListBarCode(page))
.map {
LoadMoreResult.success(page, it)
}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package com.ctech.eaty.ui.collectiondetail.di
import com.ctech.eaty.base.redux.Store
import com.ctech.eaty.di.ActivityScope
import com.ctech.eaty.repository.CollectionRepository
import com.ctech.eaty.ui.collectiondetail.action.BarCodeGenerator
import com.ctech.eaty.ui.collectiondetail.epic.LoadEpic
import com.ctech.eaty.ui.collectiondetail.reducer.CollectionDetailReducer
import com.ctech.eaty.ui.collectiondetail.state.CollectionDetailState
Expand All @@ -17,17 +16,12 @@ import io.reactivex.android.schedulers.AndroidSchedulers
@Module
class CollectionDetailModule {

@Provides
fun provideBarCodeGenerator(): BarCodeGenerator {
return BarCodeGenerator()
}

@ActivityScope
@Provides
fun provideCollectionDetailStore(collectionRepository: CollectionRepository, barCodeGenerator: BarCodeGenerator,
fun provideCollectionDetailStore(collectionRepository: CollectionRepository,
threadScheduler: ThreadScheduler): Store<CollectionDetailState> {
return Store<CollectionDetailState>(CollectionDetailState(), CollectionDetailReducer(),
arrayOf(LoadEpic(collectionRepository, barCodeGenerator, threadScheduler)))
arrayOf(LoadEpic(collectionRepository, threadScheduler)))

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ package com.ctech.eaty.ui.collectiondetail.epic

import com.ctech.eaty.base.redux.Action
import com.ctech.eaty.base.redux.Epic
import com.ctech.eaty.repository.BarcodeGenerator.createCollectionDetailBarCode
import com.ctech.eaty.repository.CollectionRepository
import com.ctech.eaty.ui.collectiondetail.action.BarCodeGenerator
import com.ctech.eaty.ui.collectiondetail.action.CollectionDetailAction
import com.ctech.eaty.ui.collectiondetail.result.LoadResult
import com.ctech.eaty.ui.collectiondetail.state.CollectionDetailState
Expand All @@ -12,13 +12,12 @@ import io.reactivex.Observable
import io.reactivex.subjects.BehaviorSubject
import io.reactivex.subjects.PublishSubject

class LoadEpic(val collectionRepository: CollectionRepository,
val barCodeGenerator: BarCodeGenerator,
val threadScheduler: ThreadScheduler) : Epic<CollectionDetailState> {
class LoadEpic(private val collectionRepository: CollectionRepository,
private val threadScheduler: ThreadScheduler) : Epic<CollectionDetailState> {
override fun apply(action: PublishSubject<Action>, state: BehaviorSubject<CollectionDetailState>): Observable<LoadResult> {
return action.ofType(CollectionDetailAction.Load::class.java)
.flatMap {
collectionRepository.getCollectionDetail(barCodeGenerator.currentBarCode(it.id))
collectionRepository.getCollectionDetail(createCollectionDetailBarCode(it.id))
.map {
LoadResult.success(it)
}
Expand Down

This file was deleted.

Loading

0 comments on commit bb11fde

Please sign in to comment.