Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Room Park Android
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Vladislav Bogdashkin
Room Park Android
Commits
54b1a51a
Commit
54b1a51a
authored
Nov 20, 2019
by
Vladislav Bogdashkin
🎣
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fetch articles for feed_id == 1
parent
09ccdde3
Changes
13
Show whitespace changes
Inline
Side-by-side
Showing
13 changed files
with
143 additions
and
37 deletions
+143
-37
FeedsRepository.kt
...nto/visual/roompark/data/data_provider/FeedsRepository.kt
+46
-16
IApi.kt
...a/com/biganto/visual/roompark/data/repository/api/IApi.kt
+1
-1
RetrofitRepository.kt
...ompark/data/repository/api/retrofit/RetrofitRepository.kt
+1
-1
IDb.kt
...ava/com/biganto/visual/roompark/data/repository/db/IDb.kt
+3
-0
RequeryRepository.kt
.../roompark/data/repository/db/requrey/RequeryRepository.kt
+18
-0
Article.kt
...sual/roompark/data/repository/db/requrey/model/Article.kt
+2
-2
Feed.kt
.../visual/roompark/data/repository/db/requrey/model/Feed.kt
+1
-1
raw2entity.kt
...anto/visual/roompark/data/repository/mapper/raw2entity.kt
+34
-0
FeedsContract.kt
.../biganto/visual/roompark/domain/contract/FeedsContract.kt
+3
-4
feeds.kt
...va/com/biganto/visual/roompark/domain/interactor/feeds.kt
+12
-11
feeds.kt
...in/java/com/biganto/visual/roompark/domain/model/feeds.kt
+16
-0
feedUseCase.kt
...om/biganto/visual/roompark/domain/use_case/feedUseCase.kt
+5
-0
ScreenPresenter.kt
...ual/roompark/presentation/screen/feeds/ScreenPresenter.kt
+1
-1
No files found.
app/src/main/java/com/biganto/visual/roompark/data/data_provider/FeedsRepository.kt
View file @
54b1a51a
package
com.biganto.visual.roompark.data.data_provider
package
com.biganto.visual.roompark.data.data_provider
import
com.biganto.visual.androidplayer.data.repository.local.ILocalStore
import
com.biganto.visual.roompark.data.repository.api.IRoomParkApi
import
com.biganto.visual.roompark.data.repository.api.IRoomParkApi
import
com.biganto.visual.roompark.data.repository.db.IDb
import
com.biganto.visual.roompark.data.repository.db.IDb
import
com.biganto.visual.roompark.data.repository.db.requrey.model.ArticleEntity
import
com.biganto.visual.roompark.data.repository.mapper.fromRaw
import
com.biganto.visual.roompark.data.repository.mapper.fromRaw
import
com.biganto.visual.roompark.data.service.user_session.IUserSession
import
com.biganto.visual.roompark.domain.contract.FeedsContract
import
com.biganto.visual.roompark.domain.contract.FeedsContract
import
com.biganto.visual.roompark.domain.custom_exception.CustomApiException
import
com.biganto.visual.roompark.domain.model.ArticlePreviewModel
import
com.biganto.visual.roompark.domain.model.ArticlesPreviewModel
import
com.biganto.visual.roompark.domain.model.ArticlesPreviewModel
import
com.biganto.visual.roompark.domain.model.FeedModel
import
com.biganto.visual.roompark.domain.model.FeedModel
import
com.biganto.visual.roompark.domain.model.fromEntity
import
com.biganto.visual.roompark.domain.model.fromEntity
import
io.reactivex.Observable
import
io.reactivex.Observable
import
io.reactivex.Single
import
io.reactivex.schedulers.Schedulers
import
io.reactivex.schedulers.Schedulers
import
timber.log.Timber
import
timber.log.Timber
import
timber.log.Timber.e
import
timber.log.Timber.e
...
@@ -23,23 +23,19 @@ import javax.inject.Inject
...
@@ -23,23 +23,19 @@ import javax.inject.Inject
//@Singleton
//@Singleton
class
FeedsContractModule
@Inject
constructor
(
class
FeedsContractModule
@Inject
constructor
(
private
val
api
:
IRoomParkApi
,
private
val
api
:
IRoomParkApi
,
private
val
db
:
IDb
,
private
val
db
:
IDb
private
val
local
:
ILocalStore
,
private
val
session
:
IUserSession
):
FeedsContract
{
):
FeedsContract
{
override
fun
fetchFeeds
():
Observable
<
List
<
FeedModel
>>
=
override
fun
fetchFeeds
():
Observable
<
List
<
FeedModel
>>
=
fetchAllFeeds
(
session
.
token
)
fetchAllFeeds
().
doOnError
(
::
e
)
.
doOnError
(
::
e
)
override
fun
fetchFeedObservable
(
id
:
Int
):
Observable
<
ArticlesPreviewModel
>
{
override
fun
fetchFeedObservable
(
id
:
Int
):
Observable
<
ArticlesPreviewModel
>
=
TODO
(
"not implemented"
)
//To change body of created functions use File | Settings | File Templates.
fetchArticles
(
id
)
}
override
fun
getArticle
(
id
:
Int
):
Single
<
Articles
PreviewModel
>
{
override
fun
getArticle
(
id
:
Int
):
Observable
<
Article
PreviewModel
>
{
TODO
(
"not implemented"
)
//To change body of created functions use File | Settings | File Templates.
TODO
(
"not implemented"
)
//To change body of created functions use File | Settings | File Templates.
}
}
...
@@ -48,8 +44,42 @@ class FeedsContractModule @Inject constructor(
...
@@ -48,8 +44,42 @@ class FeedsContractModule @Inject constructor(
}
}
private
fun
fetchFeedsApi
(
token
:
String
)
=
private
fun
fetchArticlessApi
(
feedId
:
Int
):
Observable
<
List
<
ArticleEntity
>>?
{
api
.
getFeeds
(
token
)
val
feed
=
db
.
getFeed
(
feedId
)
?.
firstOrNull
()
if
(
feed
==
null
)
{
e
(
"Unknown feedId: $feedId - cann't resolve feed_alias!"
)
throw
CustomApiException
.
UnknownCustomApiException
(-
1
,
null
,
"Unknown Feed!"
)
}
else
{
return
api
.
getArticlesPage
(
feed
.
alias
,
11
,
1
)
.
doOnNext
{
Timber
.
d
(
"raw0 $it"
)
}
.
map
{
it
.
items
}
.
map
{
fromRaw
(
it
,
feedId
,
feed
.
alias
)
}
.
doOnNext
(
db
::
blockingUpsert
)
.
subscribeOn
(
Schedulers
.
io
())
}
}
private
fun
fetchArticlesDb
(
feedId
:
Int
):
Observable
<
MutableList
<
ArticleEntity
>>?
{
val
feed
=
db
.
getFeed
(
feedId
)
?.
firstOrNull
()
if
(
feed
==
null
)
{
e
(
"Unknown feedId: $feedId - cann't resolve feed_alias!"
)
throw
CustomApiException
.
UnknownCustomApiException
(-
1
,
null
,
"Unknown Feed!"
)
}
else
return
db
.
fetchArticles
(
feed
.
alias
,
11
,
1
)
.
toList
()
.
toObservable
()
.
subscribeOn
(
Schedulers
.
io
())
}
private
fun
fetchArticles
(
feedId
:
Int
):
Observable
<
ArticlesPreviewModel
>
=
Observable
.
mergeDelayError
(
arrayListOf
(
fetchArticlessApi
(
feedId
),
fetchArticlesDb
(
feedId
))
).
map
{
fromEntity
(
feedId
,
it
)
}
private
fun
fetchFeedsApi
()
=
api
.
getFeeds
()
.
doOnNext
{
Timber
.
d
(
"raw0 $it"
)
}
.
doOnNext
{
Timber
.
d
(
"raw0 $it"
)
}
.
map
(
::
fromRaw
)
.
map
(
::
fromRaw
)
.
doOnNext
(
db
::
blockingUpsert
)
.
doOnNext
(
db
::
blockingUpsert
)
...
@@ -61,9 +91,9 @@ class FeedsContractModule @Inject constructor(
...
@@ -61,9 +91,9 @@ class FeedsContractModule @Inject constructor(
.
toObservable
()
.
toObservable
()
.
subscribeOn
(
Schedulers
.
io
())
.
subscribeOn
(
Schedulers
.
io
())
fun
fetchAllFeeds
(
userToken
:
String
):
Observable
<
List
<
FeedModel
>>
=
fun
fetchAllFeeds
():
Observable
<
List
<
FeedModel
>>
=
Observable
.
mergeDelayError
(
Observable
.
mergeDelayError
(
arrayListOf
(
fetchFeedsApi
(
userToken
),
fetchFeedsDb
)
arrayListOf
(
fetchFeedsApi
(),
fetchFeedsDb
)
).
map
{
fromEntity
(
it
,
::
fromEntity
)
}
).
map
{
fromEntity
(
it
,
::
fromEntity
)
}
}
}
...
...
app/src/main/java/com/biganto/visual/roompark/data/repository/api/IApi.kt
View file @
54b1a51a
...
@@ -27,7 +27,7 @@ interface IRoomParkApi {
...
@@ -27,7 +27,7 @@ interface IRoomParkApi {
fun
getDeals
(
userToken
:
String
):
Observable
<
List
<
DealRaw
>>
fun
getDeals
(
userToken
:
String
):
Observable
<
List
<
DealRaw
>>
fun
getFavorites
(
userToken
:
String
):
Observable
<
List
<
EstateRaw
>>
fun
getFavorites
(
userToken
:
String
):
Observable
<
List
<
EstateRaw
>>
fun
getFeeds
(
userToken
:
String
):
Observable
<
List
<
FeedRaw
>>
fun
getFeeds
():
Observable
<
List
<
FeedRaw
>>
fun
getArticle
(
id
:
Int
):
Observable
<
ArticleRaw
>
fun
getArticle
(
id
:
Int
):
Observable
<
ArticleRaw
>
fun
getPhotos
(
parentId
:
Int
):
Observable
<
List
<
NewsPhotoRaw
>>
fun
getPhotos
(
parentId
:
Int
):
Observable
<
List
<
NewsPhotoRaw
>>
fun
getEstatePlanTypes
(
estateId
:
Int
):
Observable
<
List
<
PlanTypeRaw
>>
fun
getEstatePlanTypes
(
estateId
:
Int
):
Observable
<
List
<
PlanTypeRaw
>>
...
...
app/src/main/java/com/biganto/visual/roompark/data/repository/api/retrofit/RetrofitRepository.kt
View file @
54b1a51a
...
@@ -53,7 +53,7 @@ class RetrofitRepository @Inject constructor(retrofit: Retrofit) : IRoomParkApi
...
@@ -53,7 +53,7 @@ class RetrofitRepository @Inject constructor(retrofit: Retrofit) : IRoomParkApi
api
.
getFavorites
(
token
=
userToken
)
api
.
getFavorites
(
token
=
userToken
)
.
compose
(
RetrofitResponseValidation
())
.
compose
(
RetrofitResponseValidation
())
override
fun
getFeeds
(
userToken
:
String
):
Observable
<
List
<
FeedRaw
>>
=
override
fun
getFeeds
():
Observable
<
List
<
FeedRaw
>>
=
api
.
getFeeds
()
api
.
getFeeds
()
.
compose
(
RetrofitResponseValidation
())
.
compose
(
RetrofitResponseValidation
())
...
...
app/src/main/java/com/biganto/visual/roompark/data/repository/db/IDb.kt
View file @
54b1a51a
package
com.biganto.visual.roompark.data.repository.db
package
com.biganto.visual.roompark.data.repository.db
import
com.biganto.visual.roompark.data.repository.db.requrey.model.ArticleEntity
import
com.biganto.visual.roompark.data.repository.db.requrey.model.FeedEntity
import
com.biganto.visual.roompark.data.repository.db.requrey.model.FeedEntity
import
com.biganto.visual.roompark.data.repository.db.requrey.model.UserEntity
import
com.biganto.visual.roompark.data.repository.db.requrey.model.UserEntity
import
io.reactivex.Observable
import
io.reactivex.Observable
...
@@ -18,4 +19,6 @@ interface IDb {
...
@@ -18,4 +19,6 @@ interface IDb {
fun
fetchUser
(
uuid
:
Int
):
Observable
<
UserEntity
>
fun
fetchUser
(
uuid
:
Int
):
Observable
<
UserEntity
>
fun
<
T
:
List
<
Persistable
>
>
blockingUpsert
(
entity
:
T
)
fun
<
T
:
List
<
Persistable
>
>
blockingUpsert
(
entity
:
T
)
fun
userObservableResult
(
uuid
:
Int
):
Observable
<
ReactiveResult
<
UserEntity
>>?
fun
userObservableResult
(
uuid
:
Int
):
Observable
<
ReactiveResult
<
UserEntity
>>?
fun
fetchArticles
(
feedAlias
:
String
,
pageSize
:
Int
,
startIndex
:
Int
):
Observable
<
ArticleEntity
>
fun
getFeed
(
feedId
:
Int
):
ReactiveResult
<
FeedEntity
>?
}
}
\ No newline at end of file
app/src/main/java/com/biganto/visual/roompark/data/repository/db/requrey/RequeryRepository.kt
View file @
54b1a51a
...
@@ -2,6 +2,7 @@ package com.biganto.visual.roompark.data.repository.db.requrey
...
@@ -2,6 +2,7 @@ package com.biganto.visual.roompark.data.repository.db.requrey
import
android.content.Context
import
android.content.Context
import
com.biganto.visual.roompark.data.repository.db.IDb
import
com.biganto.visual.roompark.data.repository.db.IDb
import
com.biganto.visual.roompark.data.repository.db.requrey.model.ArticleEntity
import
com.biganto.visual.roompark.data.repository.db.requrey.model.FeedEntity
import
com.biganto.visual.roompark.data.repository.db.requrey.model.FeedEntity
import
com.biganto.visual.roompark.data.repository.db.requrey.model.Models
import
com.biganto.visual.roompark.data.repository.db.requrey.model.Models
import
com.biganto.visual.roompark.data.repository.db.requrey.model.UserEntity
import
com.biganto.visual.roompark.data.repository.db.requrey.model.UserEntity
...
@@ -13,7 +14,9 @@ import io.reactivex.Single
...
@@ -13,7 +14,9 @@ import io.reactivex.Single
import
io.requery.Persistable
import
io.requery.Persistable
import
io.requery.android.sqlite.DatabaseSource
import
io.requery.android.sqlite.DatabaseSource
import
io.requery.reactivex.KotlinReactiveEntityStore
import
io.requery.reactivex.KotlinReactiveEntityStore
import
io.requery.reactivex.ReactiveResult
import
io.requery.sql.KotlinEntityDataStore
import
io.requery.sql.KotlinEntityDataStore
import
io.requery.sql.TableCreationMode
import
timber.log.Timber
import
timber.log.Timber
import
javax.inject.Inject
import
javax.inject.Inject
...
@@ -31,6 +34,8 @@ class DbModule{
...
@@ -31,6 +34,8 @@ class DbModule{
val
source
=
DatabaseSource
(
context
,
Models
.
DEFAULT
,
"BigantoPerfect"
,
DATABASE_VERSION
)
val
source
=
DatabaseSource
(
context
,
Models
.
DEFAULT
,
"BigantoPerfect"
,
DATABASE_VERSION
)
source
.
setLoggingEnabled
(
true
)
source
.
setLoggingEnabled
(
true
)
source
.
setWriteAheadLoggingEnabled
(
true
)
source
.
setTableCreationMode
(
TableCreationMode
.
DROP_CREATE
)
val
store
=
KotlinEntityDataStore
<
Persistable
>(
source
.
configuration
)
val
store
=
KotlinEntityDataStore
<
Persistable
>(
source
.
configuration
)
Timber
.
d
(
"Kotlin store %s"
,
source
)
Timber
.
d
(
"Kotlin store %s"
,
source
)
...
@@ -61,6 +66,19 @@ class RequeryRepository @Inject constructor(
...
@@ -61,6 +66,19 @@ class RequeryRepository @Inject constructor(
override
fun
fetchFeeds
():
Observable
<
FeedEntity
>
=
override
fun
fetchFeeds
():
Observable
<
FeedEntity
>
=
fetchAll
<
FeedEntity
>().
get
().
observable
()
fetchAll
<
FeedEntity
>().
get
().
observable
()
override
fun
getFeed
(
feedId
:
Int
):
ReactiveResult
<
FeedEntity
>?
=
fetchAll
<
FeedEntity
>().
where
(
FeedEntity
.
ID
.
eq
(
feedId
))
.
get
()
override
fun
fetchArticles
(
feedAlias
:
String
,
pageSize
:
Int
,
startIndex
:
Int
)
:
Observable
<
ArticleEntity
>
=
fetchAll
<
ArticleEntity
>()
.
where
(
ArticleEntity
.
FEED_ID
.
eq
(
1
))
.
orderBy
(
ArticleEntity
.
PUBLISHED
.
desc
())
.
limit
(
pageSize
)
.
offset
(
startIndex
)
.
get
().
observable
()
override
fun
fetchUser
(
uuid
:
Int
):
Observable
<
UserEntity
>
=
override
fun
fetchUser
(
uuid
:
Int
):
Observable
<
UserEntity
>
=
fetchAll
<
UserEntity
>().
where
(
UserEntity
.
UUID
.
eq
(
uuid
)).
get
().
observable
()
fetchAll
<
UserEntity
>().
where
(
UserEntity
.
UUID
.
eq
(
uuid
)).
get
().
observable
()
...
...
app/src/main/java/com/biganto/visual/roompark/data/repository/db/requrey/model/Article.kt
View file @
54b1a51a
...
@@ -22,8 +22,8 @@ interface Article : Persistable {
...
@@ -22,8 +22,8 @@ interface Article : Persistable {
val
preview
:
String
?
val
preview
:
String
?
@get
:
Nullable
@get
:
Nullable
val
body
:
String
?
val
body
:
String
?
// @get:ForeignKey(references = Feed::class, referencedColumn = "alias
")
@get
:
ForeignKey
(
references
=
Feed
::
class
,
referencedColumn
=
"id
"
)
@get
:
ManyToOne
@get
:
ManyToOne
(
cascade
=
[
CascadeAction
.
NONE
])
val
feed
:
Feed
?
val
feed
:
Feed
?
@get
:
Convert
(
TitledPhotoListConverter
::
class
)
@get
:
Convert
(
TitledPhotoListConverter
::
class
)
val
photo
:
List
<
TitledPhoto
>?
val
photo
:
List
<
TitledPhoto
>?
...
...
app/src/main/java/com/biganto/visual/roompark/data/repository/db/requrey/model/Feed.kt
View file @
54b1a51a
...
@@ -13,7 +13,7 @@ interface Feed : Persistable {
...
@@ -13,7 +13,7 @@ interface Feed : Persistable {
@get
:
Key
@get
:
Key
val
id
:
Int
val
id
:
Int
val
title
:
String
val
title
:
String
//
@get:Key
@get
:
Key
val
alias
:
String
val
alias
:
String
@get
:
JunctionTable
(
name
=
"FeedArticlesRule"
)
@get
:
JunctionTable
(
name
=
"FeedArticlesRule"
)
@get
:
OneToMany
(
cascade
=
arrayOf
(
CascadeAction
.
DELETE
))
@get
:
OneToMany
(
cascade
=
arrayOf
(
CascadeAction
.
DELETE
))
...
...
app/src/main/java/com/biganto/visual/roompark/data/repository/mapper/raw2entity.kt
View file @
54b1a51a
package
com.biganto.visual.roompark.data.repository.mapper
package
com.biganto.visual.roompark.data.repository.mapper
import
android.content.res.Resources
import
android.content.res.Resources
import
com.biganto.visual.roompark.data.repository.api.retrofit.raw.ArticleRaw
import
com.biganto.visual.roompark.data.repository.api.retrofit.raw.AuthRaw
import
com.biganto.visual.roompark.data.repository.api.retrofit.raw.AuthRaw
import
com.biganto.visual.roompark.data.repository.api.retrofit.raw.FeedRaw
import
com.biganto.visual.roompark.data.repository.api.retrofit.raw.FeedRaw
import
com.biganto.visual.roompark.data.repository.api.retrofit.raw.NewsArticleRaw
import
com.biganto.visual.roompark.data.repository.db.requrey.model.ArticleEntity
import
com.biganto.visual.roompark.data.repository.db.requrey.model.FeedEntity
import
com.biganto.visual.roompark.data.repository.db.requrey.model.FeedEntity
import
com.biganto.visual.roompark.data.repository.db.requrey.model.UserEntity
import
com.biganto.visual.roompark.data.repository.db.requrey.model.UserEntity
import
kotlin.math.max
import
kotlin.math.max
...
@@ -31,8 +34,39 @@ fun fromRaw(raw:FeedRaw) : FeedEntity {
...
@@ -31,8 +34,39 @@ fun fromRaw(raw:FeedRaw) : FeedEntity {
return
entity
return
entity
}
}
fun
fromRaw
(
raw
:
ArticleRaw
)
:
ArticleEntity
{
val
entity
=
ArticleEntity
()
entity
.
setId
(
raw
.
id
)
entity
.
setTitle
(
raw
.
title
)
entity
.
setBody
(
raw
.
body
)
entity
.
setPreview
(
raw
.
feed_alias
)
val
feed
=
FeedEntity
()
feed
.
setAlias
(
raw
.
feed_alias
)
entity
.
setFeed
(
feed
)
return
entity
}
fun
fromRaw
(
raw
:
NewsArticleRaw
,
feedId
:
Int
,
feedAlias
:
String
):
ArticleEntity
{
val
entity
=
ArticleEntity
()
entity
.
setId
(
raw
.
id
)
entity
.
setPreview
(
"https://room-park.ru${raw.preview}"
)
entity
.
setAnnounce
(
raw
.
announce
)
entity
.
setPublished
(
raw
.
published
)
entity
.
setTitle
(
raw
.
title
)
val
feed
=
FeedEntity
()
feed
.
setId
(
feedId
)
// feed.setAlias(feedAlias)
entity
.
setFeed
(
feed
)
return
entity
}
fun
fromRaw
(
raw
:
List
<
FeedRaw
>):
List
<
FeedEntity
>
=
List
(
raw
.
size
)
{
index
->
fromRaw
(
raw
[
index
])
}
fun
fromRaw
(
raw
:
List
<
FeedRaw
>):
List
<
FeedEntity
>
=
List
(
raw
.
size
)
{
index
->
fromRaw
(
raw
[
index
])
}
fun
fromRaw
(
raw
:
List
<
NewsArticleRaw
>,
feedId
:
Int
,
feedAlias
:
String
):
List
<
ArticleEntity
>
=
List
(
raw
.
size
)
{
index
->
fromRaw
(
raw
[
index
],
feedId
,
feedAlias
)
}
val
calcTargetResolution
=
max
(
display
.
widthPixels
,
display
.
heightPixels
)
val
calcTargetResolution
=
max
(
display
.
widthPixels
,
display
.
heightPixels
)
app/src/main/java/com/biganto/visual/roompark/domain/contract/FeedsContract.kt
View file @
54b1a51a
package
com.biganto.visual.roompark.domain.contract
package
com.biganto.visual.roompark.domain.contract
import
com.biganto.visual.roompark.domain.model.ArticlePreviewModel
import
com.biganto.visual.roompark.domain.model.ArticlesPreviewModel
import
com.biganto.visual.roompark.domain.model.ArticlesPreviewModel
import
com.biganto.visual.roompark.domain.model.FeedModel
import
com.biganto.visual.roompark.domain.model.FeedModel
import
com.biganto.visual.roompark.domain.model.FeedsHeaderModel
import
io.reactivex.Observable
import
io.reactivex.Observable
import
io.reactivex.Single
/**
/**
* Created by Vladislav Bogdashkin on 24.09.2019.
* Created by Vladislav Bogdashkin on 24.09.2019.
...
@@ -13,6 +12,6 @@ import io.reactivex.Single
...
@@ -13,6 +12,6 @@ import io.reactivex.Single
interface
FeedsContract
{
interface
FeedsContract
{
fun
fetchFeeds
():
Observable
<
List
<
FeedModel
>>
fun
fetchFeeds
():
Observable
<
List
<
FeedModel
>>
fun
fetchFeedObservable
(
id
:
Int
):
Observable
<
Articles
PreviewModel
>
fun
getArticle
(
id
:
Int
):
Observable
<
Article
PreviewModel
>
fun
getArticle
(
id
:
Int
):
Sing
le
<
ArticlesPreviewModel
>
fun
fetchFeedObservable
(
id
:
Int
):
Observab
le
<
ArticlesPreviewModel
>
}
}
\ No newline at end of file
app/src/main/java/com/biganto/visual/roompark/domain/interactor/feeds.kt
View file @
54b1a51a
...
@@ -16,19 +16,20 @@ class FeedsInteractor @Inject constructor(
...
@@ -16,19 +16,20 @@ class FeedsInteractor @Inject constructor(
)
{
)
{
fun
fetchTopFeeds
():
Observable
<
FeedsHeaderModel
>
=
fun
fetchTopFeeds
():
Observable
<
FeedsHeaderModel
>
=
feedsUseCase
.
getFeeds
().
map
{
feedsUseCase
.
getFeeds
().
map
{
FeedsHeaderModel
(
it
)}
FeedsHeaderModel
(
it
)
}
//Single.just(testFeeds)
//Single.just(testFeeds)
fun
fetchArticles
(
feedId
:
Int
):
Single
<
ArticlesPreviewModel
>
=
Single
.
just
(
fun
fetchArticles
(
feedId
:
Int
):
Observable
<
ArticlesPreviewModel
>
=
when
(
feedId
)
{
feedsUseCase
.
getArticles
(
feedId
)
1
->
testNewsArticles
// Single.just(
2
->
testBlogsArticles
// when (feedId) {
3
->
testDevArticles
// 1 -> testNewsArticles
else
->
error
(
"unknown feedId"
)
// 2 -> testBlogsArticles
}
// 3 -> testDevArticles
)
// else -> error("unknown feedId")
// }
// )
fun
fetchAlbums
():
Single
<
List
<
AlbumPreviewModel
>>
=
Single
.
just
(
albumsPreviews
)
fun
fetchAlbums
():
Single
<
List
<
AlbumPreviewModel
>>
=
Single
.
just
(
albumsPreviews
)
...
...
app/src/main/java/com/biganto/visual/roompark/domain/model/feeds.kt
View file @
54b1a51a
package
com.biganto.visual.roompark.domain.model
package
com.biganto.visual.roompark.domain.model
import
com.biganto.visual.roompark.data.repository.db.requrey.model.ArticleEntity
import
com.biganto.visual.roompark.data.repository.db.requrey.model.FeedEntity
import
com.biganto.visual.roompark.data.repository.db.requrey.model.FeedEntity
import
java.util.*
import
java.util.*
...
@@ -39,4 +40,19 @@ fun fromEntity(entity: FeedEntity):FeedModel = FeedModel(
...
@@ -39,4 +40,19 @@ fun fromEntity(entity: FeedEntity):FeedModel = FeedModel(
alias
=
entity
.
alias
alias
=
entity
.
alias
)
)
fun
fromEntity
(
entity
:
ArticleEntity
):
ArticlePreviewModel
=
ArticlePreviewModel
(
articleId
=
entity
.
id
,
published
=
entity
.
published
,
title
=
entity
.
title
,
announce
=
entity
.
announce
?:
""
,
previewUrl
=
entity
.
preview
?:
""
,
isRead
=
false
)
fun
fromEntity
(
parentId
:
Int
,
entity
:
List
<
ArticleEntity
>):
ArticlesPreviewModel
=
ArticlesPreviewModel
(
parentFeedId
=
parentId
,
articles
=
fromEntity
(
entity
,
::
fromEntity
)
)
fun
<
E
,
M
>
fromEntity
(
raw
:
List
<
E
>,
block
:(
E
)->
M
):
List
<
M
>
=
List
(
raw
.
size
)
{
index
->
block
(
raw
[
index
])
}
fun
<
E
,
M
>
fromEntity
(
raw
:
List
<
E
>,
block
:(
E
)->
M
):
List
<
M
>
=
List
(
raw
.
size
)
{
index
->
block
(
raw
[
index
])
}
app/src/main/java/com/biganto/visual/roompark/domain/use_case/feedUseCase.kt
View file @
54b1a51a
...
@@ -13,4 +13,9 @@ class FeedUseCase @Inject constructor(
...
@@ -13,4 +13,9 @@ class FeedUseCase @Inject constructor(
fun
getFeeds
()
=
contract
.
fetchFeeds
()
fun
getFeeds
()
=
contract
.
fetchFeeds
()
fun
getArticles
(
feedId
:
Int
)
=
contract
.
fetchFeedObservable
(
feedId
)
}
}
\ No newline at end of file
app/src/main/java/com/biganto/visual/roompark/presentation/screen/feeds/ScreenPresenter.kt
View file @
54b1a51a
...
@@ -56,7 +56,7 @@ class FeedsScreenPresenter @Inject constructor(
...
@@ -56,7 +56,7 @@ class FeedsScreenPresenter @Inject constructor(
}
}
val
getFeedArticlesPreview
=
intent
(
FeedsScreen
::
feedsTabSelected
)
val
getFeedArticlesPreview
=
intent
(
FeedsScreen
::
feedsTabSelected
)
.
flatMap
Single
{
interactor
.
fetchArticles
(
it
)
}
.
flatMap
{
interactor
.
fetchArticles
(
it
)
}
.
map
{
.
map
{
restoreModel
.
articles
=
it
.
articles
restoreModel
.
articles
=
it
.
articles
FeedsScreenViewState
.
GetFeedArticlesPreview
(
it
.
articles
.
toList
())
FeedsScreenViewState
.
GetFeedArticlesPreview
(
it
.
articles
.
toList
())
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment