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
9ed39b84
Commit
9ed39b84
authored
Apr 01, 2020
by
Vladislav
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
titled sub model for settings
parent
1b404678
Changes
8
Show whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
86 additions
and
39 deletions
+86
-39
EstateRepository.kt
...to/visual/roompark/data/data_provider/EstateRepository.kt
+1
-1
settings.kt
...com/biganto/visual/roompark/domain/interactor/settings.kt
+1
-2
subscription.kt
.../com/biganto/visual/roompark/domain/model/subscription.kt
+23
-0
subscriptionUseCase.kt
...to/visual/roompark/domain/use_case/subscriptionUseCase.kt
+22
-5
ScreenController.kt
...roompark/presentation/screen/settings/ScreenController.kt
+13
-2
ScreenPresenter.kt
.../roompark/presentation/screen/settings/ScreenPresenter.kt
+18
-21
ScreenViewState.kt
.../roompark/presentation/screen/settings/ScreenViewState.kt
+3
-3
Adapter.kt
...ual/roompark/presentation/screen/settings/util/Adapter.kt
+5
-5
No files found.
app/src/main/java/com/biganto/visual/roompark/data/data_provider/EstateRepository.kt
View file @
9ed39b84
app/src/main/java/com/biganto/visual/roompark/domain/interactor/settings.kt
View file @
9ed39b84
...
...
@@ -2,7 +2,6 @@ package com.biganto.visual.roompark.domain.interactor
import
android.content.Context
import
com.biganto.visual.roompark.R
import
com.biganto.visual.roompark.data.repository.db.requrey.model.Subscription
import
com.biganto.visual.roompark.domain.model.CachedDataModel
import
com.biganto.visual.roompark.domain.model.PushSwitchModel
import
com.biganto.visual.roompark.domain.model.SettingsModel
...
...
@@ -27,7 +26,7 @@ class SettingsInteractor @Inject constructor(
){
fun
getSubscriptions
()
:
Observable
<
List
<
Subscription
>?>
=
fun
getSubscriptions
()
=
subUc
.
getCurrentUserSubscriptions
()
fun
switchSubscription
(
model
:
SubscriptionModel
,
newState
:
Boolean
):
Completable
=
...
...
app/src/main/java/com/biganto/visual/roompark/domain/model/subscription.kt
View file @
9ed39b84
...
...
@@ -13,6 +13,13 @@ data class SubscriptionModel(
val
state
:
Boolean
)
data class
TitledSubscriptionModel
(
var
title
:
String
?=
null
,
val
subModel
:
SubscriptionModel
)
sealed
class
SubscriptionTopic
(
val
topicName
:
String
,
val
topicId
:
String
?
=
null
)
{
class
Deals
(
topicName
:
String
=
TOPIC_API_NAME_DEALS
,
dealId
:
String
?)
:
SubscriptionTopic
(
topicName
,
dealId
)
...
...
@@ -26,6 +33,22 @@ sealed class SubscriptionTopic(val topicName:String,val topicId:String? = null)
class
Blog
(
topicName
:
String
=
TOPIC_API_NAME_BLOG
)
:
SubscriptionTopic
(
topicName
)
class
Construction
(
topicName
:
String
=
TOPIC_API_NAME_CONSCTRUCTION
)
:
SubscriptionTopic
(
topicName
)
companion
object
{
fun
titleByTopic
(
topic
:
SubscriptionTopic
)
=
when
(
topic
){
is
Deals
->
"Сделка"
is
Progress_1
->
"Ход строительства Дом №1"
is
Progress_2
->
"Ход строительства Дом №2"
is
Progress_3
->
"Ход строительства Дом №3"
is
Progress_kindergarden
->
"Ход строительства \nДетский сад"
is
Progress_school
->
"Ход строительства \nШкола"
is
Progress_landscaping
->
"Ход строительства \nЛандшафт"
is
News
->
"Новости"
is
Blog
->
"Блоги"
is
Construction
->
"Строительный блог"
}
}
}
private
const
val
TOPIC_API_NAME_DEALS
=
"deals"
...
...
app/src/main/java/com/biganto/visual/roompark/domain/use_case/subscriptionUseCase.kt
View file @
9ed39b84
package
com.biganto.visual.roompark.domain.use_case
//import io.reactivex.Observable
import
com.biganto.visual.roompark.data.repository.db.requrey.model.DealEntity
import
com.biganto.visual.roompark.data.repository.db.requrey.model.SubscriptionEntity
import
com.biganto.visual.roompark.data.repository.db.requrey.model.UserEntity
import
com.biganto.visual.roompark.domain.contract.AuthContract
...
...
@@ -8,6 +9,7 @@ import com.biganto.visual.roompark.domain.contract.DeviceUtilsContract
import
com.biganto.visual.roompark.domain.contract.SubscriptionContract
import
com.biganto.visual.roompark.domain.model.SubscriptionModel
import
com.biganto.visual.roompark.domain.model.SubscriptionTopic
import
com.biganto.visual.roompark.domain.model.TitledSubscriptionModel
import
com.biganto.visual.roompark.domain.model.fromEntity
import
io.reactivex.Completable
import
io.reactivex.Observable
...
...
@@ -58,18 +60,33 @@ class SubscriptionUseCase @Inject constructor(
).
subscribeOn
(
Schedulers
.
io
())
}
fun
getCurrentUserSubscriptions
()
=
auth
.
currentUser
().
map
{
it
.
subscriptions
}
fun
getCurrentUserSubscriptions
():
Observable
<
List
<
TitledSubscriptionModel
>>
=
auth
.
currentUser
()
.
map
{
user
->
val
subList
=
user
.
subscriptions
?:
arrayListOf
()
val
list
=
List
<
TitledSubscriptionModel
>(
subList
.
size
){
i
->
val
sub
:
SubscriptionModel
=
fromEntity
(
subList
[
i
]
as
SubscriptionEntity
)
var
title
=
SubscriptionTopic
.
titleByTopic
(
sub
.
topic
)
if
(
sub
.
topic
is
SubscriptionTopic
.
Deals
){
val
deal
=
user
.
deals
?.
firstOrNull
{
d
->
d
.
id
==
sub
.
topic
.
topicId
}
as
DealEntity
title
=
"$title № ${deal.estate.number}"
}
TitledSubscriptionModel
(
title
,
sub
)
}
list
}
fun
getSubscriptions
(
topic
:
SubscriptionTopic
):
Observable
<
SubscriptionModel
>
=
auth
.
currentUser
()
.
map
{
Timber
.
w
(
"user is : $
it
"
)
var
sub
=
it
.
subscriptions
.
map
{
user
->
Timber
.
w
(
"user is : $
user
"
)
var
sub
=
user
.
subscriptions
?.
firstOrNull
{
it
.
topic
==
topic
.
topicName
&&
it
.
number
==
topic
.
topicId
}
if
(
sub
==
null
)
{
sub
=
SubscriptionEntity
()
sub
.
setOwner
(
it
)
sub
.
setOwner
(
user
)
sub
.
setTopic
(
topic
.
topicName
)
sub
.
setNumber
(
topic
.
topicId
)
sub
.
setState
(
false
)
...
...
app/src/main/java/com/biganto/visual/roompark/presentation/screen/settings/ScreenController.kt
View file @
9ed39b84
...
...
@@ -131,6 +131,8 @@ class SettingsScreenController :
is
SettingsScreenViewState
.
SomeError
->
render
(
viewState
)
is
SettingsScreenViewState
.
SignOut
->
render
(
viewState
)
is
SettingsScreenViewState
.
OnCacheDeleting
->
render
(
viewState
)
is
SettingsScreenViewState
.
LoadCachInfo
->
render
(
viewState
)
is
SettingsScreenViewState
.
LoadSubscriptions
->
render
(
viewState
)
}
}
...
...
@@ -142,6 +144,15 @@ class SettingsScreenController :
clearCacheButton
.
setGone
(
false
)
}
private
fun
render
(
viewState
:
SettingsScreenViewState
.
LoadSubscriptions
){
(
pushRecycler
.
adapter
as
PushListAdapter
).
setItems
(
viewState
.
list
)
}
private
fun
render
(
viewState
:
SettingsScreenViewState
.
LoadCachInfo
){
(
cachedRecycler
.
adapter
as
CahcedListAdapter
).
setItems
(
viewState
.
list
)
}
private
fun
render
(
viewState
:
SettingsScreenViewState
.
OnCacheDeleting
){
val
isProgressed
=
viewState
.
progress
>=
1f
...
...
@@ -160,12 +171,12 @@ class SettingsScreenController :
@SuppressLint
(
"SetTextI18n"
)
private
fun
render
(
viewState
:
SettingsScreenViewState
.
LoadSettingsList
){
(
pushRecycler
.
adapter
as
PushListAdapter
).
setItems
(
viewState
.
settings
.
pushItems
)
toursDownloaderTitle
.
text
=
viewState
.
settings
.
offlineStoreData
[
0
].
title
+
"(${viewState.settings.offlineStoreData[0].amountBytes.bytesToSize()})"
flatDownloaderTitle
.
text
=
viewState
.
settings
.
offlineStoreData
[
1
].
title
+
"(${viewState.settings.offlineStoreData[1].amountBytes.bytesToSize()})"
(
cachedRecycler
.
adapter
as
CahcedListAdapter
).
setItems
(
viewState
.
settings
.
cachedData
)
}
private
fun
getComponent
()
=
DaggerSettingsScreenComponent
.
factory
()
...
...
app/src/main/java/com/biganto/visual/roompark/presentation/screen/settings/ScreenPresenter.kt
View file @
9ed39b84
...
...
@@ -22,27 +22,19 @@ class SettingsScreenPresenter @Inject constructor(
:
BigantoBasePresenter
<
SettingsScreen
,
SettingsScreenViewState
>()
{
override
fun
defaultErrorViewStateHandler
()
=
{
e
:
ExceptionString
->
SettingsScreenViewState
.
SomeError
(
e
)
}
{
e
:
ExceptionString
->
SettingsScreenViewState
.
SomeError
(
e
)
}
override
fun
bindIntents
()
{
val
fetchSettings
=
interactor
.
fetchSettings
()
.
flatMap
{
settings
->
interactor
.
getCacheInfo
()
.
doOnNext
{
cached
->
cached
.
sortBy
{
it
.
id
}
}
.
doOnNext
{
settings
.
cachedData
=
it
}
.
map
{
settings
}}
.
map
{
SettingsScreenViewState
.
LoadSettingsList
(
it
)}
.
map
{
SettingsScreenViewState
.
LoadSettingsList
(
it
)
}
val
fetchCache
=
interactor
.
getCacheInfo
()
.
doOnNext
{
cached
->
cached
.
sortBy
{
it
.
id
}
}
.
map
{
SettingsScreenViewState
.
LoadCachInfo
(
it
)
}
val
fetchSubscriptions
=
interactor
.
getSubscriptions
()
.
doOnNext
{
cached
->
cached
.
sortBy
{
it
.
id
}
}
.
map
{
SettingsScreenViewState
.
LoadCachInfo
(
it
)
}
.
map
{
SettingsScreenViewState
.
LoadSubscriptions
(
it
)
}
val
onSignOut
=
intent
(
SettingsScreen
::
signOut
)
.
flatMap
{
...
...
@@ -53,14 +45,14 @@ class SettingsScreenPresenter @Inject constructor(
val
refreshInfo
=
intent
(
SettingsScreen
::
refreshCacheInfo
)
.
flatMap
{
fetchSettings
}
.
flatMap
{
fetchSettings
}
val
onClearCache
=
intent
(
SettingsScreen
::
clearCache
)
.
flatMap
{
interactor
.
deleteCacheFiles
()
.
map
<
SettingsScreenViewState
>{
.
map
<
SettingsScreenViewState
>
{
SettingsScreenViewState
.
OnCacheDeleting
(
it
.
first
/
it
.
second
.
toFloat
()
it
.
first
/
it
.
second
.
toFloat
()
)
}
.
startWith
(
SettingsScreenViewState
.
OnCacheDeleting
(
0f
))
...
...
@@ -68,13 +60,18 @@ class SettingsScreenPresenter @Inject constructor(
}
val
state
=
restoreStateObservable
.
mergeWith
(
fetchSettings
)
.
mergeWith
(
onSignOut
)
.
mergeWith
(
onClearCache
)
.
mergeWith
(
refreshInfo
)
.
doOnError
{
Timber
.
e
(
it
)}
val
state
=
Observable
.
mergeDelayError
(
arrayListOf
(
restoreStateObservable
,
fetchSettings
,
fetchSettings
,
onSignOut
,
onClearCache
,
refreshInfo
,
fetchSubscriptions
)
)
.
doOnError
{
Timber
.
e
(
it
)
}
.
subscribeOn
(
Schedulers
.
io
())
.
onErrorReturn
(
::
parseError
)
.
observeOn
(
AndroidSchedulers
.
mainThread
())
...
...
app/src/main/java/com/biganto/visual/roompark/presentation/screen/settings/ScreenViewState.kt
View file @
9ed39b84
...
...
@@ -3,7 +3,7 @@ package com.biganto.visual.roompark.presentation.screen.settings
import
com.biganto.visual.roompark.conductor.BigantoBaseViewState
import
com.biganto.visual.roompark.domain.model.CachedDataModel
import
com.biganto.visual.roompark.domain.model.SettingsModel
import
com.biganto.visual.roompark.domain.model.SubscriptionModel
import
com.biganto.visual.roompark.domain.model.
Titled
SubscriptionModel
import
com.biganto.visual.roompark.util.monades.ExceptionString
/**
...
...
@@ -18,6 +18,6 @@ sealed class SettingsScreenViewState : BigantoBaseViewState() {
class
SomeError
(
val
exception
:
ExceptionString
)
:
SettingsScreenViewState
()
class
SignOut
()
:
SettingsScreenViewState
()
class
OnCacheDeleting
(
val
progress
:
Float
)
:
SettingsScreenViewState
()
class
LoadSubscriptions
(
val
list
:
List
<
SubscriptionModel
>)
:
SettingsScreenViewState
()
class
LoadCachInfo
(
val
list
:
List
<
CachedDataModel
>)
class
LoadSubscriptions
(
val
list
:
List
<
Titled
SubscriptionModel
>)
:
SettingsScreenViewState
()
class
LoadCachInfo
(
val
list
:
List
<
CachedDataModel
>)
:
SettingsScreenViewState
()
}
app/src/main/java/com/biganto/visual/roompark/presentation/screen/settings/util/Adapter.kt
View file @
9ed39b84
...
...
@@ -9,7 +9,7 @@ import butterknife.BindView
import
butterknife.ButterKnife
import
com.biganto.visual.roompark.R
import
com.biganto.visual.roompark.domain.model.CachedDataModel
import
com.biganto.visual.roompark.domain.model.
PushSwitch
Model
import
com.biganto.visual.roompark.domain.model.
TitledSubscription
Model
import
com.biganto.visual.roompark.util.extensions.bytesToSize
import
com.google.android.material.switchmaterial.SwitchMaterial
import
com.google.android.material.textview.MaterialTextView
...
...
@@ -92,7 +92,7 @@ abstract class CommonViewHolder<M:Any>(itemView: View): RecyclerView.ViewHolder(
class
PushListAdapter
:
CommonRecyclerAdapter
<
PushViewHolder
,
PushSwitch
Model
>()
{
class
PushListAdapter
:
CommonRecyclerAdapter
<
PushViewHolder
,
TitledSubscription
Model
>()
{
override
val
vhKlazz
:
KClass
<
PushViewHolder
>
get
()
=
PushViewHolder
::
class
...
...
@@ -100,7 +100,7 @@ class PushListAdapter : CommonRecyclerAdapter<PushViewHolder,PushSwitchModel>()
}
class
PushViewHolder
(
itemView
:
View
)
:
CommonViewHolder
<
PushSwitch
Model
>(
itemView
)
{
class
PushViewHolder
(
itemView
:
View
)
:
CommonViewHolder
<
TitledSubscription
Model
>(
itemView
)
{
@BindView
(
R
.
id
.
bellSwitcherTitle
)
lateinit
var
bellTitle
:
MaterialTextView
...
...
@@ -108,10 +108,10 @@ class PushViewHolder(itemView: View) : CommonViewHolder<PushSwitchModel>(itemVie
@BindView
(
R
.
id
.
bellSwitch
)
lateinit
var
switcher
:
ViewGroup
override
fun
onViewBound
(
model
:
PushSwitch
Model
)
{
override
fun
onViewBound
(
model
:
TitledSubscription
Model
)
{
Timber
.
d
(
"model is : $model"
)
bellTitle
.
text
=
model
.
title
switcher
.
findViewById
<
SwitchMaterial
>(
R
.
id
.
switch1
).
isChecked
=
model
.
s
witchS
tate
switcher
.
findViewById
<
SwitchMaterial
>(
R
.
id
.
switch1
).
isChecked
=
model
.
s
ubModel
.
s
tate
}
}
...
...
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