-
Notifications
You must be signed in to change notification settings - Fork 1
Added base architecture #5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from 4 commits
9e21f88
e98a2f9
12a9de0
67fd047
dd1287b
e583d88
023cde3
648e55d
1151fd2
3e5bfa0
86c1d15
e781d4a
ace4794
adeb15a
0bde519
fe5f8a0
2001e20
cb2c13c
c17d515
403b106
d0021cb
f44abe9
8631438
0165020
d96746d
1c9e733
9ad0d73
5108341
c70dbb0
6bea088
8b0f8c1
824d903
f4d4a40
19423ee
2d79fac
26028f4
703ffbc
3f480c0
56fddd9
dc8a88f
8f43828
7dacf37
748791f
fa54b51
96a6be1
551598a
2bd42af
88aa448
9301d72
205c58c
9339760
fbb0390
0590288
a97e1a3
4a8a912
90ec8d9
e0a4fb3
8beedd0
51218e0
8da4457
e0421f7
e3b377b
8e92c7a
7d5f289
d152d50
3586d62
5c1b4d3
115e8d0
2d6493e
3869016
8a5a0c3
b1953f1
4e113c4
a05eb76
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| package com.example.mvvmkotlincoroutineretrofitdemo.interfaces | ||
|
|
||
| import com.example.mvvmkotlincoroutineretrofitdemo.model.Rate | ||
| import com.example.mvvmkotlincoroutineretrofitdemo.model.Trade | ||
| import com.example.mvvmkotlincoroutineretrofitdemo.model.Transaction | ||
| import kotlinx.coroutines.Deferred | ||
| import retrofit2.Response | ||
| import retrofit2.http.GET | ||
| import retrofit2.http.Path | ||
| import retrofit2.http.Query | ||
|
|
||
| interface ApiService { | ||
|
|
||
| @GET("/bcv/quotes/bars/{instrument}/{timeFrom}/{timeTo}") | ||
| fun getRatesForTime(@Path("instrument") instrument:String, @Path("timeFrom") timeFrom: Long, @Path("timeTo") timeTo: Long): Deferred<Response<MutableList<Rate>>> | ||
| @GET("/bcv/quotes/bars/{instrument}") | ||
| fun getRate(@Query("instrument") instrument: String): Deferred<Response<MutableList<Rate>>> | ||
| @GET("/bcv/transactions") | ||
| fun getTrans(): Deferred<Response<MutableList<Transaction>>> | ||
| @GET("/bcv/trades") | ||
| fun getTrades(): Deferred<Response<MutableList<Trade>>> | ||
|
|
||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| package com.example.mvvmkotlincoroutineretrofitdemo.manager | ||
|
|
||
| import android.view.GestureDetector | ||
| import android.view.MotionEvent | ||
| import android.view.View | ||
| import kotlin.math.abs | ||
|
|
||
| open class OnSwipeTouchListener : View.OnTouchListener { | ||
|
|
||
| private val gestureDetector = GestureDetector(GestureListener()) | ||
|
|
||
| fun onTouch(event: MotionEvent): Boolean { | ||
| return gestureDetector.onTouchEvent(event) | ||
| } | ||
|
|
||
| private inner class GestureListener : GestureDetector.SimpleOnGestureListener() { | ||
|
|
||
| private val SWIPE_THRESHOLD = 100 | ||
| private val SWIPE_VELOCITY_THRESHOLD = 100 | ||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
| override fun onFling(e1: MotionEvent, e2: MotionEvent, velocityX: Float, velocityY: Float): Boolean { | ||
| val result = false | ||
| try { | ||
| val diffY = e2.y - e1.y | ||
| val diffX = e2.x - e1.x | ||
| if (abs(diffX) > abs(diffY)) { | ||
| if (abs(diffX) > SWIPE_THRESHOLD && abs(velocityX) > SWIPE_VELOCITY_THRESHOLD) { | ||
| if (diffX > 0) { | ||
| onSwipeRight() | ||
| } else { | ||
| onSwipeLeft() | ||
| } | ||
| } | ||
| } else { | ||
| // onTouch(e); | ||
| } | ||
| } catch (exception: Exception) { | ||
| exception.printStackTrace() | ||
| } | ||
|
|
||
| return result | ||
| } | ||
| } | ||
|
|
||
| override fun onTouch(v: View, event: MotionEvent): Boolean { | ||
| return gestureDetector.onTouchEvent(event) | ||
| } | ||
|
|
||
| open fun onSwipeRight() {} | ||
|
|
||
| open fun onSwipeLeft() {} | ||
|
|
||
| open fun onSwipeTop() {} | ||
|
|
||
| open fun onSwipeBottom() {} | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| package com.example.mvvmkotlincoroutineretrofitdemo.manager | ||
|
|
||
| import com.example.mvvmkotlincoroutineretrofitdemo.interfaces.ApiService | ||
| import com.jakewharton.retrofit2.adapter.kotlin.coroutines.CoroutineCallAdapterFactory | ||
| import okhttp3.OkHttpClient | ||
| import retrofit2.Retrofit | ||
| import retrofit2.converter.gson.GsonConverterFactory | ||
|
|
||
| object RetrofitManager { | ||
|
|
||
| val apiRate: ApiService | ||
| init { | ||
| val client = OkHttpClient.Builder().build() | ||
| apiRate = Retrofit.Builder() | ||
| .baseUrl("http://3.248.170.197:8888") | ||
| .addConverterFactory(GsonConverterFactory.create()) | ||
| .addCallAdapterFactory(CoroutineCallAdapterFactory()) | ||
| .client(client) | ||
| .build() | ||
| .create(ApiService::class.java) | ||
| } | ||
|
|
||
| val apiTransTrades: ApiService | ||
| init { | ||
| val client = OkHttpClient.Builder().build() | ||
| apiTransTrades = Retrofit.Builder() | ||
| .baseUrl("http://3.248.170.197:9999") | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Энто в настройки бы вынести
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
не очень понял
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Урлы и порты обычно хочется выносить в настройки, ибо вот возьму, тачку перезагружу на AWS - и код протухнет, и надо пересобирать чтоб заработало, и менять именно в RetrofitManager :) |
||
| .addConverterFactory(GsonConverterFactory.create()) | ||
| .addCallAdapterFactory(CoroutineCallAdapterFactory()) | ||
| .client(client) | ||
| .build() | ||
| .create(ApiService::class.java) | ||
| } | ||
|
|
||
|
|
||
|
|
||
|
|
||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| package com.example.mvvmkotlincoroutineretrofitdemo.model | ||
|
|
||
| import android.system.Int64Ref | ||
| import com.google.gson.annotations.Expose | ||
| import com.google.gson.annotations.SerializedName | ||
| import java.math.BigDecimal | ||
|
|
||
| data class Rate( | ||
| @SerializedName("exchangeRate") | ||
| @Expose | ||
| val exchangeRate: BigDecimal, | ||
| @SerializedName("timestamp") | ||
| @Expose | ||
| val date: Long | ||
| ) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| package com.example.mvvmkotlincoroutineretrofitdemo.model | ||
|
|
||
| import com.google.gson.annotations.Expose | ||
| import com.google.gson.annotations.SerializedName | ||
| import java.math.BigDecimal | ||
|
|
||
| data class Trade( | ||
| @SerializedName("id") | ||
| @Expose | ||
| val id: Int, | ||
| @SerializedName("dateTime") | ||
| @Expose | ||
| val dateTime: String, | ||
| @SerializedName("instrument") | ||
| @Expose | ||
| val instrument: String, | ||
| @SerializedName("tradeType") | ||
| @Expose | ||
| val tradeType: String, | ||
| @SerializedName("tradedQuantity") | ||
| @Expose | ||
| val tradedQuantity: BigDecimal, | ||
| @SerializedName("tradedQuantityCurrency") | ||
| @Expose | ||
| val tradedQuantityCurrency: String, | ||
| @SerializedName("tradedPrice") | ||
| @Expose | ||
| val tradedPrice: BigDecimal, | ||
| @SerializedName("tradedPriceCurrency") | ||
| @Expose | ||
| val tradedPriceCurrency: String, | ||
| @SerializedName("commission") | ||
| @Expose | ||
| val commission: BigDecimal, | ||
| @SerializedName("commissionCurrency") | ||
| @Expose | ||
| val commissionCurrency: String, | ||
| @SerializedName("tradeValueId") | ||
| @Expose | ||
| val tradeValueId: Int | ||
| ) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| package com.example.mvvmkotlincoroutineretrofitdemo.model | ||
|
|
||
| import com.google.gson.annotations.Expose | ||
| import com.google.gson.annotations.SerializedName | ||
| import java.math.BigDecimal | ||
|
|
||
| data class Transaction( | ||
| @SerializedName("id") | ||
| @Expose | ||
| val id: Int, | ||
| @SerializedName("transactionType") | ||
| @Expose | ||
| val transactionType: String, | ||
| @SerializedName("dateTime") | ||
| @Expose | ||
| val dateTime: String, | ||
| @SerializedName("currency") | ||
| @Expose | ||
| val currency: String, | ||
| @SerializedName("amount") | ||
| @Expose | ||
| val amount: BigDecimal, | ||
| @SerializedName("commission") | ||
| @Expose | ||
| val commission: BigDecimal, | ||
| @SerializedName("transactionStatus") | ||
| @Expose | ||
| val transactionStatus: String, | ||
| @SerializedName("transactionValueId") | ||
| @Expose | ||
| val transactionValueId: Int | ||
| ) |
Uh oh!
There was an error while loading. Please reload this page.