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
b3851231
Commit
b3851231
authored
Oct 29, 2019
by
Vladislav Bogdashkin
🎣
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added roompark api impl
parent
05020569
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
360 additions
and
0 deletions
+360
-0
AndroidManifest.xml
app/src/main/AndroidManifest.xml
+1
-0
AuthRepository.kt
...anto/visual/roompark/data/data_provider/AuthRepository.kt
+24
-0
IApi.kt
...a/com/biganto/visual/roompark/data/repository/api/IApi.kt
+53
-0
RetrofitRepository.kt
...ompark/data/repository/api/retrofit/RetrofitRepository.kt
+129
-0
RetrofitModule.kt
...oompark/data/repository/api/retrofit/di/RetrofitModule.kt
+108
-0
INetworkMonitor.kt
...o/visual/roompark/data/service/network/INetworkMonitor.kt
+13
-0
LiveNetworkMonitor.kt
...isual/roompark/data/service/network/LiveNetworkMonitor.kt
+30
-0
ext.kt
...n/java/com/biganto/visual/roompark/util/extensions/ext.kt
+2
-0
No files found.
app/src/main/AndroidManifest.xml
View file @
b3851231
...
...
@@ -2,6 +2,7 @@
<manifest
xmlns:android=
"http://schemas.android.com/apk/res/android"
package=
"com.biganto.visual.roompark"
>
<uses-permission
android:name=
"android.permission.ACCESS_NETWORK_STATE"
/>
<application
android:name=
".base.RoomParkApplication"
android:allowBackup=
"true"
...
...
app/src/main/java/com/biganto/visual/roompark/data/data_provider/AuthRepository.kt
0 → 100644
View file @
b3851231
package
com.biganto.visual.roompark.data.data_provider
import
com.biganto.visual.roompark.data.repository.api.IRoomParkApi
import
com.biganto.visual.roompark.domain.contract.AuthContract
import
com.biganto.visual.roompark.domain.model.AuthInfoModel
import
io.reactivex.Completable
import
io.reactivex.Observable
import
javax.inject.Inject
/**
* Created by Vladislav Bogdashkin on 29.10.2019.
*/
class
AuthRepository
@Inject
constructor
(
val
roomparkApi
:
IRoomParkApi
)
:
AuthContract
{
override
fun
signIn
(
email
:
String
,
password
:
String
):
Observable
<
AuthInfoModel
>
=
{}
override
fun
signOut
():
Completable
{
TODO
(
"not implemented"
)
//To change body of created functions use File | Settings | File Templates.
}
}
\ No newline at end of file
app/src/main/java/com/biganto/visual/roompark/data/repository/api/IApi.kt
0 → 100644
View file @
b3851231
package
com.biganto.visual.roompark.data.repository.api
import
com.biganto.visual.roompark.data.repository.api.retrofit.DEFAULT_ARTICLE_PAGE_SIZE
import
com.biganto.visual.roompark.data.repository.api.retrofit.PlanTypeCatalog
import
com.biganto.visual.roompark.data.repository.api.retrofit.raw.*
import
io.reactivex.Observable
/**
* Created by Vladislav Bogdashkin on 29.10.2019.
*/
interface
IRoomParkApi
{
fun
authenticate
(
login
:
String
,
pwd
:
String
):
Observable
<
AuthRaw
>
fun
subscribeTopic
(
userToken
:
String
,
deviceToken
:
String
,
topicName
:
String
):
Observable
<
StatusResponse
>
fun
unSuubscribeTopic
(
userToken
:
String
,
deviceToken
:
String
,
topicName
:
String
):
Observable
<
StatusResponse
>
fun
getDeals
(
userToken
:
String
):
Observable
<
List
<
DealRaw
>>
fun
getFavorites
(
userToken
:
String
):
Observable
<
List
<
EstateRaw
>>
fun
getFeeds
(
userToken
:
String
):
Observable
<
List
<
FeedRaw
>>
fun
getArticle
(
id
:
Int
):
Observable
<
ArticleRaw
>
fun
getPhotos
(
parentId
:
Int
):
Observable
<
List
<
NewsPhotoRaw
>>
fun
getEstatePlanTypes
(
estateId
:
Int
):
Observable
<
List
<
PlanTypeRaw
>>
fun
getDirectPlan
(
estateId
:
Int
,
planType
:
PlanTypeCatalog
,
showFurniture
:
Boolean
,
showSizes
:
Boolean
,
showWalls
:
Boolean
,
showElectric
:
Boolean
):
Observable
<
List
<
PlanRaw
>>?
fun
getMultiTour
(
building
:
Int
,
flat
:
Int
):
Observable
<
List
<
PlanRaw
>>
fun
getArticlesPage
(
feedName
:
String
,
pageSize
:
Int
=
DEFAULT_ARTICLE_PAGE_SIZE
,
page
:
Int
):
Observable
<
ArticlesListPaginationRaw
>
fun
getAlbums
(
parentId
:
Int
?
=
null
):
Observable
<
List
<
ImageAlbumRaw
>>
}
interface
IBigantoApi
{
}
\ No newline at end of file
app/src/main/java/com/biganto/visual/roompark/data/repository/api/retrofit/RetrofitRepository.kt
0 → 100644
View file @
b3851231
package
com.biganto.visual.roompark.data.repository.api.retrofit
import
com.biganto.visual.roompark.data.repository.api.IRoomParkApi
import
com.biganto.visual.roompark.data.repository.api.retrofit.raw.*
import
com.biganto.visual.roompark.util.extensions.asInt
import
io.reactivex.Completable
import
io.reactivex.Observable
import
io.reactivex.ObservableSource
import
io.reactivex.ObservableTransformer
import
retrofit2.Response
import
retrofit2.Retrofit
import
timber.log.Timber
import
javax.inject.Singleton
/**
* Created by Vladislav Bogdashkin on 29.10.2019.
*/
const
val
DEFAULT_ARTICLE_PAGE_SIZE
=
10
@Singleton
class
RetrofitRepository
(
retrofit
:
Retrofit
)
:
IRoomParkApi
{
private
val
api
=
retrofit
.
create
(
IRoomParkMobileApi
::
class
.
java
)
override
fun
authenticate
(
login
:
String
,
pwd
:
String
):
Observable
<
AuthRaw
>
=
api
.
authoriz
(
email
=
login
,
pwd
=
pwd
)
.
compose
(
RetrofitResponseValidation
())
override
fun
subscribeTopic
(
userToken
:
String
,
deviceToken
:
String
,
topicName
:
String
):
Observable
<
StatusResponse
>
=
api
.
subscribe
(
token
=
userToken
,
deviceToken
=
deviceToken
,
topic
=
topicName
)
.
compose
(
RetrofitResponseValidation
())
override
fun
unSuubscribeTopic
(
userToken
:
String
,
deviceToken
:
String
,
topicName
:
String
):
Observable
<
StatusResponse
>
=
api
.
unsubscribe
(
token
=
userToken
,
deviceToken
=
deviceToken
,
topic
=
topicName
)
.
compose
(
RetrofitResponseValidation
())
override
fun
getDeals
(
userToken
:
String
):
Observable
<
List
<
DealRaw
>>
=
api
.
getDeals
(
token
=
userToken
)
.
compose
(
RetrofitResponseValidation
())
override
fun
getFavorites
(
userToken
:
String
):
Observable
<
List
<
EstateRaw
>>
=
api
.
getFavorites
(
token
=
userToken
)
.
compose
(
RetrofitResponseValidation
())
override
fun
getFeeds
(
userToken
:
String
):
Observable
<
List
<
FeedRaw
>>
=
api
.
getFeeds
()
.
compose
(
RetrofitResponseValidation
())
override
fun
getArticlesPage
(
feedName
:
String
,
pageSize
:
Int
,
page
:
Int
):
Observable
<
ArticlesListPaginationRaw
>
=
api
.
getArticlesPage
(
alias
=
feedName
,
pageSize
=
pageSize
,
page
=
page
)
.
compose
(
RetrofitResponseValidation
())
override
fun
getArticle
(
id
:
Int
):
Observable
<
ArticleRaw
>
=
api
.
getArticle
(
id
=
id
)
.
compose
(
RetrofitResponseValidation
())
override
fun
getAlbums
(
parentId
:
Int
?):
Observable
<
List
<
ImageAlbumRaw
>>
=
api
.
getAlbums
(
id
=
parentId
)
.
compose
(
RetrofitResponseValidation
())
override
fun
getPhotos
(
parentId
:
Int
):
Observable
<
List
<
NewsPhotoRaw
>>
=
api
.
getPhotos
(
id
=
parentId
)
.
compose
(
RetrofitResponseValidation
())
override
fun
getEstatePlanTypes
(
estateId
:
Int
):
Observable
<
List
<
PlanTypeRaw
>>
=
api
.
getPlanTypes
(
estateId
=
estateId
)
.
compose
(
RetrofitResponseValidation
())
override
fun
getDirectPlan
(
estateId
:
Int
,
planType
:
PlanTypeCatalog
,
showFurniture
:
Boolean
,
showSizes
:
Boolean
,
showWalls
:
Boolean
,
showElectric
:
Boolean
):
Observable
<
List
<
PlanRaw
>>
=
api
.
getPlan
(
estate_id
=
estateId
,
planType
=
planType
.
planId
,
furniture
=
showFurniture
.
asInt
,
sizes
=
showSizes
.
asInt
,
walls
=
showWalls
.
asInt
,
electric
=
showElectric
.
asInt
)
.
compose
(
RetrofitResponseValidation
())
override
fun
getMultiTour
(
building
:
Int
,
flat
:
Int
):
Observable
<
List
<
PlanRaw
>>
=
api
.
getMultiTourId
(
building
=
building
,
flatNumber
=
flat
)
.
compose
(
RetrofitResponseValidation
())
}
enum
class
PlanTypeCatalog
(
val
planId
:
Int
,
val
planName
:
String
){
PROJECT
(
0
,
"проектная планировка"
),
PROJECT_PLAN_1
(
1
,
"перепланировка №1"
),
PROJECT_PLAN_2
(
2
,
"перепланировка №2"
),
}
internal
class
RetrofitResponseValidation
<
T
>
:
ObservableTransformer
<
Response
<
T
>,
T
>
{
override
fun
apply
(
responseObservable
:
Observable
<
Response
<
T
>>):
ObservableSource
<
T
>
{
return
responseObservable
.
switchMap
{
resp
->
// Timber.d("reutrned code: %s",resp.code())
if
(
resp
.
code
()
==
200
||
resp
.
code
()
==
206
)
if
(
resp
.
body
()
==
null
)
return
@switchMap
Completable
.
complete
().
toObservable
<
T
>().
doOnNext
{
Timber
.
d
(
"Completed responseBody"
)}
else
return
@switchMap
Observable
.
just
(
resp
.
body
())
Timber
.
d
(
"Returning Exception!"
)
return
@switchMap
Observable
.
error
<
T
>(
retrofit2
.
HttpException
(
resp
))
}
}
}
\ No newline at end of file
app/src/main/java/com/biganto/visual/roompark/data/repository/api/retrofit/di/RetrofitModule.kt
0 → 100644
View file @
b3851231
package
com.biganto.visual.roompark.data.repository.api.retrofit.di
import
android.app.Application
import
com.biganto.visual.roompark.data.repository.api.retrofit.IRoomParkMobileApi
import
com.biganto.visual.roompark.data.repository.api.retrofit.raw.ErrorRaw
import
com.biganto.visual.roompark.data.repository.api.retrofit.util.DateSerializer
import
com.biganto.visual.roompark.data.repository.api.retrofit.util.ErrorsListDeserializer
import
com.biganto.visual.roompark.data.repository.api.retrofit.util.NullOnEmptyConverterFactory
import
com.biganto.visual.roompark.data.repository.api.retrofit.util.VersionValidationInterceptor
import
com.biganto.visual.roompark.data.service.network.INetworkMonitor
import
com.biganto.visual.roompark.data.service.network.LiveNetworkMonitor
import
com.biganto.visual.roompark.data.service.network.NoNetworkException
import
com.biganto.visual.roompark.data.service.version_control.AppVersionManager
import
com.biganto.visual.roompark.data.service.version_control.IAppVersionControl
import
com.google.gson.GsonBuilder
import
com.google.gson.reflect.TypeToken
import
dagger.Module
import
dagger.Provides
import
okhttp3.OkHttpClient
import
okhttp3.logging.HttpLoggingInterceptor
import
retrofit2.Retrofit
import
retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory
import
retrofit2.converter.gson.GsonConverterFactory
import
timber.log.Timber
import
java.util.*
import
java.util.concurrent.TimeUnit
import
javax.inject.Named
import
javax.inject.Singleton
/**
* Created by Vladislav Bogdashkin on 29.10.2019.
*/
private
const
val
TIMEOUT_SECONDS
=
120L
private
const
val
WRITE_SECONDS
=
120L
private
const
val
READ_SECONDS
=
120L
@Module
()
class
RetrofitModule
{
// var networkMonitor = LiveNetworkMonitor(context)
//
// var versionControl = AppVersionManager(context)
private
inline
fun
<
reified
T
>
genericType
()
=
object
:
TypeToken
<
T
>()
{}.
type
private
fun
gsonConverterFactory
()
=
GsonConverterFactory
.
create
(
GsonBuilder
()
.
registerTypeAdapter
(
genericType
<
MutableList
<
ErrorRaw
>>(),
ErrorsListDeserializer
())
.
registerTypeAdapter
(
Date
::
class
.
java
,
DateSerializer
())
.
setLenient
()
.
create
())
private
fun
client
(
appVersionManager
:
IAppVersionControl
,
networkMonitor
:
INetworkMonitor
)
=
OkHttpClient
.
Builder
()
.
hostnameVerifier
{
hostname
,
session
->
true
}
.
connectTimeout
(
TIMEOUT_SECONDS
,
TimeUnit
.
SECONDS
)
.
writeTimeout
(
WRITE_SECONDS
,
TimeUnit
.
SECONDS
)
.
readTimeout
(
READ_SECONDS
,
TimeUnit
.
SECONDS
)
.
addInterceptor
{
if
(
networkMonitor
.
isConnected
)
{
it
.
proceed
(
it
.
request
())
}
else
{
throw
NoNetworkException
(
"No Network"
)
}
}
.
addInterceptor
(
VersionValidationInterceptor
(
appVersionManager
))
.
addInterceptor
(
HttpLoggingInterceptor
{
Timber
.
tag
(
"OkHttp"
).
d
(
"RetroLogger: $it"
)
}
.
setLevel
(
HttpLoggingInterceptor
.
Level
.
NONE
)
)
.
addInterceptor
{
it
.
proceed
(
it
.
request
()
.
newBuilder
()
.
header
(
"Content-Type"
,
"application/json"
)
.
build
())
}
.
build
()
// @Provides
// @Singleton
// @Named("bigantoApi")
// fun provideRetrofitBigantoApi(context: Application): Retrofit =
// Retrofit.Builder()
// .baseUrl(IBigantoMobileApi.BASE_URL)
// .client(client(AppVersionManager(context),LiveNetworkMonitor(context)))
// .addConverterFactory(NullOnEmptyConverterFactory.create())
// .addConverterFactory(gsonConverterFactory())
// .addCallAdapterFactory(RxJava2CallAdapterFactory.create())
// .build()
@Provides
@Singleton
@Named
(
"roomParkApi"
)
fun
provideRetrofitRoomParkApi
(
context
:
Application
):
Retrofit
=
Retrofit
.
Builder
()
.
baseUrl
(
IRoomParkMobileApi
.
BASE_URL
)
.
client
(
client
(
AppVersionManager
(
context
),
LiveNetworkMonitor
(
context
)))
.
addConverterFactory
(
NullOnEmptyConverterFactory
.
create
())
.
addConverterFactory
(
gsonConverterFactory
())
.
addCallAdapterFactory
(
RxJava2CallAdapterFactory
.
create
())
.
build
()
}
\ No newline at end of file
app/src/main/java/com/biganto/visual/roompark/data/service/network/INetworkMonitor.kt
0 → 100644
View file @
b3851231
package
com.biganto.visual.roompark.data.service.network
/**
* Created by Vladislav Bogdashkin on 12.10.2018.
*/
public
interface
INetworkMonitor
{
val
isConnected
:
Boolean
val
isWifiConnected
:
Boolean
}
app/src/main/java/com/biganto/visual/roompark/data/service/network/LiveNetworkMonitor.kt
0 → 100644
View file @
b3851231
package
com.biganto.visual.roompark.data.service.network
import
android.content.Context
import
android.net.ConnectivityManager
import
javax.inject.Singleton
/**
* Created by Vladislav Bogdashkin on 12.10.2018.
*/
@Singleton
class
LiveNetworkMonitor
(
val
context
:
Context
)
:
INetworkMonitor
{
override
val
isConnected
:
Boolean
get
()
{
val
cm
=
context
.
getSystemService
(
Context
.
CONNECTIVITY_SERVICE
)
as
ConnectivityManager
val
activeNetwork
=
cm
.
activeNetworkInfo
return
activeNetwork
!=
null
&&
activeNetwork
.
isConnectedOrConnecting
}
override
val
isWifiConnected
:
Boolean
get
()
{
val
cm
=
context
.
getSystemService
(
Context
.
CONNECTIVITY_SERVICE
)
as
ConnectivityManager
return
cm
.
activeNetworkInfo
!=
null
&&
(
cm
.
activeNetworkInfo
.
type
==
ConnectivityManager
.
TYPE_WIFI
);
}
}
class
NoNetworkException
(
override
var
message
:
String
):
Exception
(
message
)
app/src/main/java/com/biganto/visual/roompark/util/extensions/ext.kt
View file @
b3851231
...
...
@@ -7,6 +7,8 @@ import java.text.DecimalFormat
* Created by Vladislav Bogdashkin on 23.10.2019.
*/
val
Boolean
?.
asInt
get
()
=
if
(
this
!=
null
&&
this
)
1
else
0
fun
Int
.
toRubly
()
=
String
.
format
(
"%,d \u20BD"
,
this
).
replace
(
','
,
' '
)
...
...
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