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
323bf812
Commit
323bf812
authored
Nov 06, 2019
by
Vladislav Bogdashkin
🎣
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added user seession
parent
b12f7c40
Changes
9
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
135 additions
and
10 deletions
+135
-10
build.gradle
app/build.gradle
+3
-0
ILocalStore.kt
...ava/com/biganto/visual/roompark/data/local/ILocalStore.kt
+15
-0
UserHolder.kt
...java/com/biganto/visual/roompark/data/local/UserHolder.kt
+58
-0
IDb.kt
...ava/com/biganto/visual/roompark/data/repository/db/IDb.kt
+4
-0
RequeryRepository.kt
.../roompark/data/repository/db/requrey/RequeryRepository.kt
+3
-1
User.kt
.../visual/roompark/data/repository/db/requrey/model/User.kt
+2
-1
raw2entity.kt
...anto/visual/roompark/data/repository/mapper/raw2entity.kt
+24
-0
ContextModule.kt
...va/com/biganto/visual/roompark/di/dagger/ContextModule.kt
+17
-8
auth.kt
...ain/java/com/biganto/visual/roompark/domain/model/auth.kt
+9
-0
No files found.
app/build.gradle
View file @
323bf812
...
@@ -140,6 +140,9 @@ dependencies {
...
@@ -140,6 +140,9 @@ dependencies {
implementation
"io.requery:requery-kotlin:$requeryVersion"
implementation
"io.requery:requery-kotlin:$requeryVersion"
kapt
"io.requery:requery-processor:$requeryVersion"
kapt
"io.requery:requery-processor:$requeryVersion"
//RxSharedPreferences
implementation
"com.afollestad:rxkprefs:1.2.5"
//Tests
//Tests
testImplementation
'junit:junit:4.12'
testImplementation
'junit:junit:4.12'
androidTestImplementation
'androidx.test:runner:1.2.0'
androidTestImplementation
'androidx.test:runner:1.2.0'
...
...
app/src/main/java/com/biganto/visual/roompark/data/local/ILocalStore.kt
0 → 100644
View file @
323bf812
package
com.biganto.visual.androidplayer.data.repository.local
import
com.biganto.visual.roompark.data.local.UserState
import
io.reactivex.Completable
import
io.reactivex.Observable
/**
* Created by Vladislav Bogdashkin on 14.06.2018.
*/
interface
ILocalStore
{
fun
setRecentUser
(
uuid
:
String
?):
Completable
fun
recentUser
():
Observable
<
in
UserState
>
fun
setDownloadListDestinationTourId
(
tourId
:
String
):
Observable
<
String
>?
fun
getDownloadListDestinationTourId
():
Observable
<
String
>?
}
\ No newline at end of file
app/src/main/java/com/biganto/visual/roompark/data/local/UserHolder.kt
0 → 100644
View file @
323bf812
package
com.biganto.visual.roompark.data.local
import
android.content.Context
import
com.afollestad.rxkprefs.rxkPrefs
import
com.biganto.visual.androidplayer.data.repository.local.ILocalStore
import
io.reactivex.Completable
import
io.reactivex.Observable
import
javax.inject.Inject
import
javax.inject.Singleton
/**
* Created by Vladislav Bogdashkin on 14.06.2018.
*/
@Singleton
class
UserHolder
@Inject
constructor
(
val
context
:
Context
)
:
ILocalStore
{
private
val
prefs
=
rxkPrefs
(
context
)
companion
object
{
const
val
RECENT_UUID_KEY
=
"com.biganto.visual.androidplayer.LAST_USER_UUD"
const
val
EMPTY_PREF_VALUE_KEY
=
"NO_ACTIVE_SESSION"
const
val
SCROLL_LIST_TO_TOUR_KEY
=
"SCROLL_LIST_TO_TOUR_ID"
}
override
fun
setDownloadListDestinationTourId
(
tourId
:
String
)
=
prefs
.
string
(
SCROLL_LIST_TO_TOUR_KEY
,
tourId
)
.
observe
()
override
fun
getDownloadListDestinationTourId
()
=
prefs
.
string
(
SCROLL_LIST_TO_TOUR_KEY
,
""
)
.
observe
()
override
fun
recentUser
():
Observable
<
in
UserState
>
=
prefs
.
string
(
RECENT_UUID_KEY
,
EMPTY_PREF_VALUE_KEY
)
.
observe
()
.
map
{
if
(
it
==
EMPTY_PREF_VALUE_KEY
)
return
@map
UserState
.
NotAuthenticated
()
else
return
@map
UserState
.
Authenticated
(
it
)
}
override
fun
setRecentUser
(
uuid
:
String
?)
=
Completable
.
fromObservable
(
prefs
.
string
(
RECENT_UUID_KEY
,
uuid
?:
EMPTY_PREF_VALUE_KEY
).
observe
())
}
sealed
class
UserState
{
class
NotAuthenticated
data class
Authenticated
(
val
uuid
:
String
)
}
data class
UserPrefModel
(
val
uuid
:
String
,
val
name
:
String
,
val
email
:
String
,
val
timeZone
:
String
)
app/src/main/java/com/biganto/visual/roompark/data/repository/db/IDb.kt
View file @
323bf812
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.UserEntity
import
io.reactivex.Observable
/**
/**
* Created by Vladislav Bogdashkin on 29.10.2019.
* Created by Vladislav Bogdashkin on 29.10.2019.
*/
*/
interface
IDb
{
interface
IDb
{
fun
upsertUser
(
entity
:
UserEntity
):
Observable
<
UserEntity
>?
}
}
\ No newline at end of file
app/src/main/java/com/biganto/visual/roompark/data/repository/db/requrey/RequeryRepository.kt
View file @
323bf812
package
com.biganto.visual.roompark.data.repository.db.requrey
package
com.biganto.visual.roompark.data.repository.db.requrey
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.UserEntity
import
io.requery.Persistable
import
io.requery.Persistable
import
io.requery.reactivex.KotlinReactiveEntityStore
import
io.requery.reactivex.KotlinReactiveEntityStore
import
timber.log.Timber
import
javax.inject.Inject
import
javax.inject.Inject
import
javax.inject.Singleton
import
javax.inject.Singleton
...
@@ -17,4 +17,6 @@ class RequeryRepository @Inject constructor(
...
@@ -17,4 +17,6 @@ class RequeryRepository @Inject constructor(
)
)
:
IDb
{
:
IDb
{
override
fun
upsertUser
(
entity
:
UserEntity
)
=
store
.
upsert
(
entity
).
toObservable
()
}
}
\ No newline at end of file
app/src/main/java/com/biganto/visual/roompark/data/repository/db/requrey/model/User.kt
View file @
323bf812
...
@@ -21,4 +21,5 @@ interface User : Persistable {
...
@@ -21,4 +21,5 @@ interface User : Persistable {
val
authToken
:
String
val
authToken
:
String
val
targetResolution
:
Int
val
targetResolution
:
Int
}
}
\ No newline at end of file
app/src/main/java/com/biganto/visual/roompark/data/repository/mapper/raw2entity.kt
0 → 100644
View file @
323bf812
package
com.biganto.visual.roompark.data.repository.mapper
import
android.content.res.Resources
import
com.biganto.visual.roompark.data.repository.api.retrofit.raw.AuthRaw
import
com.biganto.visual.roompark.data.repository.db.requrey.model.UserEntity
import
kotlin.math.max
/**
* Created by Vladislav Bogdashkin on 06.11.2019.
*/
private
val
display
=
Resources
.
getSystem
().
displayMetrics
fun
fromRaw
(
raw
:
AuthRaw
)
:
UserEntity
{
val
user
=
UserEntity
()
user
.
setEmail
(
raw
.
email
)
user
.
setUuid
(
raw
.
id
)
user
.
setAuthToken
(
raw
.
token
)
user
.
setName
(
raw
.
name
)
user
.
setTargetResolution
(
calcTargetResolution
)
return
user
}
val
calcTargetResolution
=
max
(
display
.
widthPixels
,
display
.
heightPixels
)
app/src/main/java/com/biganto/visual/roompark/di/dagger/ContextModule.kt
View file @
323bf812
package
com.biganto.visual.roompark.di.dagger
package
com.biganto.visual.roompark.di.dagger
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.db.IDb
import
com.biganto.visual.roompark.data.repository.mapper.fromRaw
import
com.biganto.visual.roompark.domain.contract.AuthContract
import
com.biganto.visual.roompark.domain.contract.AuthContract
import
com.biganto.visual.roompark.domain.model.AuthInfoModel
import
com.biganto.visual.roompark.domain.model.AuthInfoModel
import
com.biganto.visual.roompark.domain.model.fromEntity
import
dagger.Module
import
dagger.Module
import
dagger.Provides
import
dagger.Provides
import
io.reactivex.Completable
import
io.reactivex.Completable
...
@@ -33,20 +38,24 @@ class AppModule() {
...
@@ -33,20 +38,24 @@ class AppModule() {
}
}
class
AuthContractModule
@Inject
constructor
():
AuthContract
{
class
AuthContractModule
@Inject
constructor
(
val
local
:
ILocalStore
,
val
api
:
IRoomParkApi
,
val
db
:
IDb
):
AuthContract
{
init
{
init
{
Timber
.
d
(
"Auth Repository Created"
)
Timber
.
d
(
"Auth Repository Created"
)
}
}
override
fun
signOut
():
Completable
=
Completable
.
complete
()
override
fun
sign
In
(
email
:
String
,
password
:
String
):
Observable
<
AuthInfoModel
>
{
override
fun
sign
Out
():
Completable
=
local
.
setRecentUser
(
null
)
Timber
.
d
(
"Gonna signIIn"
)
override
fun
signIn
(
email
:
String
,
password
:
String
):
Observable
<
AuthInfoModel
>
=
return
Observable
.
just
(
AuthInfoModel
(
"some tokan zzaza"
,
1488
,
"hi4"
,
"biganto@demo.ru"
))
api
.
authenticate
(
email
,
password
)
}
.
map
(
::
fromRaw
)
.
flatMap
{
db
.
upsertUser
(
it
)
}
fun
validateAuthState
():
Observable
<
Boolean
>
=
Observable
.
just
(
false
)
.
doOnNext
{
local
.
setRecentUser
(
it
.
uuid
.
toString
())
}
.
map
(
::
fromEntity
)
}
}
@Module
()
@Module
()
...
...
app/src/main/java/com/biganto/visual/roompark/domain/model/auth.kt
View file @
323bf812
package
com.biganto.visual.roompark.domain.model
package
com.biganto.visual.roompark.domain.model
import
com.biganto.visual.roompark.data.repository.db.requrey.model.UserEntity
/**
/**
* Created by Vladislav Bogdashkin on 24.09.2019.
* Created by Vladislav Bogdashkin on 24.09.2019.
*/
*/
...
@@ -9,4 +11,11 @@ data class AuthInfoModel(
...
@@ -9,4 +11,11 @@ data class AuthInfoModel(
val
id
:
Int
,
val
id
:
Int
,
val
name
:
String
,
val
name
:
String
,
val
email
:
String
val
email
:
String
)
fun
fromEntity
(
entity
:
UserEntity
)
=
AuthInfoModel
(
entity
.
authToken
,
entity
.
uuid
,
entity
.
name
,
entity
.
email
)
)
\ No newline at end of file
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