Функционал механика ч.4

This commit is contained in:
Azat Sagutdinov 2024-05-27 17:32:01 +03:00
parent 67ad9f0f26
commit 0392253128
17 changed files with 213 additions and 72 deletions

View File

@ -335,7 +335,7 @@ interface ApiService {
fun update(
@Path("uniq_id") uuid: String,
@Part("uniq_id") uuidPart: RequestBody,
@Part("data") data: List<CheckupData>?,
@Part("data") data: RequestBody?,
@Header("token") token: String? = "iddqd",
@Header("Authorization") tokenUser: String?
): Single<CheckupShowListResponse>

View File

@ -1 +1 @@
package ru.tele2med.mobile.data.api.entity.response import ru.tele2med.mobile.domain.entity.* data class CheckupShowListResponse( val af: String, val status: String, val message: String, val data: DataCheckupShow )
package ru.tele2med.mobile.data.api.entity.response import ru.tele2med.mobile.domain.entity.* data class CheckupShowListResponse( val af: String, val status: String, val message: String, val data: List<DataCheckupShow> )

View File

@ -1,5 +1,6 @@
package ru.tele2med.mobile.data.repository
import com.google.gson.Gson
import ru.tele2med.mobile.domain.repository.QRRepository
import ru.tele2med.mobile.presentation.util.Prefs
import io.reactivex.Single
@ -109,20 +110,20 @@ class TechRepositoryImpl(
.map(dataConverter::toTechShow)
override fun updateCheckList(
uniq_id: String,
id: String,
data: List<CheckupData>
): Single<CheckupShowList> =
apiService
.update(
uuid = id,
uuid = uniq_id,
uuidPart = RequestBody.create(
MediaType.parse("text/plain"), id
MediaType.parse("text/plain"), uniq_id
),
tokenUser = "Bearer ${prefs.getTokenUser().toString()}",
data = data,
data = RequestBody.create(MediaType.parse("text/plain"), Gson().toJson(data))
)
.map(dataConverter::toCheckupShow)
}

View File

@ -52,6 +52,7 @@ import ru.tele2med.mobile.presentation.ui.menu.items.tech.list.TechListPresenter
import ru.tele2med.mobile.presentation.ui.menu.items.tech.list.techCheckup.TechCheckupPresenter
import ru.tele2med.mobile.presentation.ui.menu.items.tech.list.techCheckup.info.TechCheckupInfoPresenter
import ru.tele2med.mobile.presentation.ui.menu.items.tech.list.techCheckup.tests.TechCheckupTestsPresenter
import ru.tele2med.mobile.presentation.ui.menu.items.tech.list.techCheckup.tests.test.TestPresenter
import ru.tele2med.mobile.presentation.ui.menu.items.tech.park.ParkPresenter
import ru.tele2med.mobile.presentation.ui.models.UiConverter
import ru.tele2med.mobile.presentation.ui.splash.SplashPresenter
@ -72,13 +73,16 @@ fun presenterModule() = Kodein.Module(name = "presenterModule") {
}
bind() from factory { stringId: String ->
TechCheckupTestsPresenter(instance(), instance(), stringId)
TechCheckupTestsPresenter(instance(), instance(), instance())
}
bind() from provider {
ParkPresenter(instance(), instance(), instance())
}
bind() from provider {
TestPresenter(instance(), instance())
}
bind() from provider {
TechPresenter()

View File

@ -4,5 +4,5 @@ data class CheckupShowList(
val af: String,
val status: String,
val message: String,
val data: DataCheckupShow
val data: List<DataCheckupShow>
)

View File

@ -29,9 +29,11 @@ class TechInteractor(
techRepository.showTech(id)
fun updateCheckList(
uniq_id: String,
id: String,
data: List<CheckupData>
): Single<CheckupShowList> =
techRepository.showCheckup(id, data)
techRepository.updateCheckList(uniq_id, id, data)
}

View File

@ -19,6 +19,7 @@ interface TechRepository {
): Single<TechShowList>
fun updateCheckList(
uniq_id: String,
id: String,
data: List<CheckupData>
): Single<CheckupShowList>

View File

@ -124,8 +124,8 @@ class NavRouter : Router() {
navigateTo(NavScreens.getTechCheckup(dataTech))
}
fun openTestCheckupScreen(test: DataShow) {
navigateTo(NavScreens.getTestCheckup(test))
fun openTestCheckupScreen(test: DataShow, uniq_id: String, dataTech: DataTech) {
navigateTo(NavScreens.getTestCheckup(test, uniq_id, dataTech))
}
fun openMedicalCheckupsScreen() {

View File

@ -95,7 +95,7 @@ object NavScreens {
fun getTechCheckup(dataTech: DataTech): TechCheckupScreen = TechCheckupScreen(dataTech)
fun getTestCheckup(test: DataShow): TestScreen = TestScreen(test)
fun getTestCheckup(test: DataShow, uniq_id: String, dataTech: DataTech): TestScreen = TestScreen(test, uniq_id, dataTech)
fun getTechCheckupInfo(dataTech: DataTech): TechCheckupScreen = TechCheckupScreen(dataTech)

View File

@ -76,6 +76,10 @@ class TechCheckupInfoFragment : BaseMenuFragment(), TechCheckupInfoView {
val gson = Gson()
val data = gson.fromJson(dataString, DataTech::class.java)
startTest.setOnClickListener {
presenter.updateTech(, data.uniq_id, data)
}
// tvDriverTitle.focusable
// tvDriverTitle.requestFocus()
@ -110,15 +114,6 @@ class TechCheckupInfoFragment : BaseMenuFragment(), TechCheckupInfoView {
}
startTest.setOnClickListener {
presenter.updateTech(
data.uniq_id,
data.vehicle_id,
data.date_,
data.time_,
data.result_id
)
}
}

View File

@ -9,13 +9,15 @@ import ru.tele2med.mobile.presentation.util.Prefs
import ru.tele2med.mobile.presentation.util.ioToMain
import io.reactivex.rxkotlin.plusAssign
import ru.tele2med.mobile.data.api.entity.exception.ApiException
import ru.tele2med.mobile.domain.entity.DataShow
import ru.tele2med.mobile.domain.entity.DataTech
import ru.tele2med.mobile.domain.interactor.TechInteractor
import ru.tele2med.mobile.presentation.router.NavRouter
@InjectViewState
class TechCheckupInfoPresenter(
private val techInteractor: TechInteractor,
private val prefs: Prefs,
private val navRouter: NavRouter,
private val stringId: String
) : BasePresenter<TechCheckupInfoView>() {
@ -23,39 +25,12 @@ class TechCheckupInfoPresenter(
}
fun updateTech(id: String, vehicleId: String, date: String, time: String, resultId: String) {
Log.v(
"LOG",
"it id = $id, vehicleId = $vehicleId date = $date, time = $time, resultId = $resultId"
)
fun updateTech(test: DataShow, uniq_id: String, dataTech: DataTech) {
navRouter.openTestCheckupScreen(test, uniq_id, dataTech)
disposable += techInteractor
.updateTech(id, vehicleId, date, time, resultId)
.ioToMain()
.doOnSubscribe {
Log.v("LOG", "it 2 = $it")
viewState.showLoading()
}
.doAfterTerminate {
viewState.hideLoading()
}
.subscribe({
Log.v("LOG", "it = $it ${it.message}")
}, {
if (it is ApiException) {
if (it.code == RestApiCodes.NotFound.code) {
} else {
this.handleError(it)
}
} else {
this.handleError(it)
}
})
}
fun showCheckUp() {
val gson = Gson()
val data = gson.fromJson(stringId, DataTech::class.java)

View File

@ -51,7 +51,13 @@ class TechCheckupTestsFragment : BaseMenuFragment(), TechCheckupTestsView {
private val adapter: TestListAdapter by lazy {
TestListAdapter { test ->
presenter.get(test)
val gson = Gson()
presenter.get(
test,
gson.fromJson(DATA_QR, DataTech::class.java).uniq_id,
gson.fromJson(DATA_QR, DataTech::class.java)
)
}
}
@ -87,7 +93,7 @@ class TechCheckupTestsFragment : BaseMenuFragment(), TechCheckupTestsView {
val scrollListener = object : EndlessRecyclerViewScrollListener(layoutManager) {
override fun onLoadMore() {
// presenter.getCheckups()
// presenter.getCheckups()
}
}
recyclerView.addOnScrollListener(scrollListener)
@ -150,7 +156,10 @@ class TechCheckupTestsFragment : BaseMenuFragment(), TechCheckupTestsView {
putString(TechCheckupTestsFragment.DATA_QR, string)
}
Log.v("COMP", "data4 = ${it.requireArguments().getString(TechCheckupTestsFragment.DATA_QR)}")
Log.v(
"COMP",
"data4 = ${it.requireArguments().getString(TechCheckupTestsFragment.DATA_QR)}"
)
}
}

View File

@ -59,9 +59,9 @@ class TechCheckupTestsPresenter(
})
}
fun get(test: DataShow) {
fun get(test: DataShow, uniq_id: String, dataTech: DataTech) {
println("TechCheckupTestsPresenter ${test.uniq_id}")
navRouter.openTestCheckupScreen(test)
navRouter.openTestCheckupScreen(test, uniq_id, dataTech)
}

View File

@ -1,6 +1,8 @@
package ru.tele2med.mobile.presentation.ui.menu.items.tech.list.techCheckup.tests.test
import android.os.Bundle
import android.os.Handler
import android.os.Looper
import android.util.Log
import android.view.View
import com.arellomobile.mvp.presenter.InjectPresenter
@ -8,6 +10,7 @@ import com.arellomobile.mvp.presenter.ProvidePresenter
import com.google.gson.Gson
import kotlinx.android.synthetic.main.fragment_checkup_test.*
import ru.tele2med.mobile.R
import ru.tele2med.mobile.di.module.navigationModule
import ru.tele2med.mobile.domain.entity.Data
import ru.tele2med.mobile.domain.entity.DataShow
import ru.tele2med.mobile.domain.entity.DataTech
@ -18,6 +21,7 @@ import ru.tele2med.mobile.presentation.ui.menu.base.BaseMenuFragment
import ru.tele2med.mobile.presentation.ui.menu.items.result.ResFragment
import ru.tele2med.mobile.presentation.ui.menu.items.tech.list.techCheckup.TechCheckupFragment
import ru.tele2med.mobile.presentation.ui.menu.items.tech.list.techCheckup.info.TechCheckupInfoFragment
import ru.tele2med.mobile.presentation.ui.menu.items.tech.list.techCheckup.tests.TechCheckupTestsFragment
import ru.tele2med.mobile.presentation.util.providePresenter
class TestFragment : BaseMenuFragment(), TestView {
@ -43,36 +47,87 @@ class TestFragment : BaseMenuFragment(), TestView {
title = getString(R.string.test_toolbar)
}
val args = arguments
val data = args?.toString() // getString("data", "")
// val args = arguments
// val data = args?.toString() // getString("data", "")
Log.v("TestFragment", "args = ${arguments?.getString("data")}")
Log.v("TestFragment", "args = ${arguments?.getString(TEST)}")
val gson = Gson()
val dataTest = gson.fromJson(TEST, DataShow::class.java)
fillData(dataTest)
var stringTech = arguments?.getString(TECH)
val dataTech = gson.fromJson(stringTech, DataTech::class.java)
if (arguments?.getString(TEST) == null) {
Handler(Looper.getMainLooper()).post {
presenter.toTech(dataTech)
// interact with ViewPager here
}
// toBack()
} else {
var dataString = arguments?.getString(TEST)
val data = gson.fromJson(dataString, DataShow::class.java)
var uniq_id = arguments?.getString(UNIQ_ID)
// val gson = Gson()
// val dataTest = gson.fromJson(TEST, DataShow::class.java)
fillData(data)
actions(data, uniq_id ?: "", dataTech)
}
}
private fun fillData(data: DataShow) {
Log.v("TestFragment", "data = data.name = ${data.name}")
tvTestName.text = data.name
tvComment.text = data.comment
tvStatusName.text = "Проверка ${data.order}"
}
override fun toBack() {
activity?.onBackPressed()
}
private fun actions(data: DataShow, uniq_id: String, dataTech: DataTech) {
trueBtn.setOnClickListener {
presenter.setValue(uniq_id, data.uniq_id, data, "1", dataTech)
}
falseBtn.setOnClickListener {
presenter.setValue(uniq_id, data.uniq_id, data, "0", dataTech)
}
}
override val layoutId: Int
get() = R.layout.fragment_checkup_test
companion object {
private const val TEST = "TEST"
private var TEST = "TEST"
private var UNIQ_ID = "UNIQ_ID"
private var TECH = "TECH"
fun getInstance(test: DataShow): TestFragment {
fun getInstance(test: DataShow, uniq_id: String, dataTech: DataTech): TestFragment {
val gson = Gson()
val string: String = gson.toJson(test)
this.TEST = string
val stringTech: String = gson.toJson(dataTech)
this.TECH = stringTech
return TestFragment().also {
it.arguments = Bundle().apply {
putString(TEST, string)
putString(UNIQ_ID, uniq_id)
putString(TECH, stringTech)
}
}

View File

@ -1,26 +1,120 @@
package ru.tele2med.mobile.presentation.ui.menu.items.tech.list.techCheckup.tests.test
import android.util.Log
import com.arellomobile.mvp.InjectViewState
import io.reactivex.rxkotlin.plusAssign
import ru.tele2med.mobile.data.api.entity.exception.ApiException
import ru.tele2med.mobile.domain.entity.CheckupData
import ru.tele2med.mobile.domain.entity.DataShow
import ru.tele2med.mobile.domain.entity.DataTech
import ru.tele2med.mobile.domain.entity.Position
import ru.tele2med.mobile.domain.interactor.SosInteractor
import ru.tele2med.mobile.presentation.Changes
import ru.tele2med.mobile.domain.interactor.TechInteractor
import ru.tele2med.mobile.presentation.router.NavRouter
import ru.tele2med.mobile.presentation.ui.base.entity.RestApiCodes
import ru.tele2med.mobile.presentation.ui.menu.base.BaseMenuPresenter
import ru.tele2med.mobile.presentation.ui.menu.items.tech.list.techCheckup.tests.test.TestView
import ru.tele2med.mobile.presentation.util.ioToMain
@InjectViewState
class TestPresenter(
private val sosInteractor: SosInteractor,
private val navRouter: NavRouter,
private val changes: Changes
private val techInteractor: TechInteractor,
private val navRouter: NavRouter
) : BaseMenuPresenter<TestView>() {
private var position: Position? = null
override fun onFirstViewAttach() {
super.onFirstViewAttach()
}
fun toTech(dataTech: DataTech) {
navRouter.openTechCheckupScreen(dataTech)
}
fun setValue(uniq_id: String, id: String, dataShow: DataShow, value: String, dataTech: DataTech) {
var checkup = CheckupData(id, dataShow.name ?: "", value, dataShow.type_id ?: "")
var data: List<CheckupData> = listOf(checkup)
Log.v("LOG", "it checkup = $uniq_id, data = $data")
disposable += techInteractor
.updateCheckList(uniq_id, id, data)
.ioToMain()
.doOnSubscribe {
Log.v("LOG", "it 2 = $it")
viewState.showLoading()
}
.doAfterTerminate {
viewState.hideLoading()
// viewState.toBack()
}
.subscribe({
Log.v("LOG", "it = $it ${it.data}")
showTech(uniq_id, dataTech)
}, {
if (it is ApiException) {
if (it.code == RestApiCodes.NotFound.code) {
} else {
this.handleError(it)
}
} else {
this.handleError(it)
}
})
//router.openPhoneEnterScreen()
}
fun showTech(uniq_id: String, dataTech: DataTech) {
Log.v(
"LOG",
"showTech uniq_id = $uniq_id,"
)
disposable += techInteractor
.showTech(uniq_id)
.ioToMain()
.doOnSubscribe {
Log.v("LOG", "it 2 = $it")
viewState.showLoading()
}
.doAfterTerminate {
viewState.hideLoading()
}
.subscribe({ it ->
Log.v("LOG", "showTech ${it.data.data}")
val newShowTech = mutableListOf<DataShow>()
it.data.data.forEach {
Log.v("LOG", "showTech forEach ${it}")
if ((it.value != "1") && (it.value != "0")) {
newShowTech.add(it)
Log.v("LOG", "showTech openTestCheckupScreen ${newShowTech}")
}
}
if (newShowTech.isNotEmpty()) {
navRouter.openTestCheckupScreen(newShowTech.first(), uniq_id, dataTech)
} else {
viewState.toBack()
}
// viewState.showCheckups(it.data.data)
}, {
if (it is ApiException) {
if (it.code == RestApiCodes.NotFound.code) {
} else {
this.handleError(it)
}
} else {
this.handleError(it)
}
})
}
}

View File

@ -2,12 +2,13 @@ package ru.tele2med.mobile.presentation.ui.menu.items.tech.list.techCheckup.test
import androidx.fragment.app.Fragment
import ru.tele2med.mobile.domain.entity.DataShow
import ru.tele2med.mobile.domain.entity.DataTech
import ru.terrakok.cicerone.android.support.SupportAppScreen
class TestScreen(val test: DataShow) : SupportAppScreen() {
class TestScreen(val test: DataShow, val uniq_id: String, val dataTech: DataTech) : SupportAppScreen() {
override fun getFragment(): Fragment {
return TestFragment.getInstance(test)
return TestFragment.getInstance(test, uniq_id, dataTech)
}
override fun getScreenKey(): String {

View File

@ -1,5 +1,6 @@
package ru.tele2med.mobile.presentation.ui.menu.items.tech.list.techCheckup.tests.test
import com.arellomobile.mvp.viewstate.strategy.OneExecutionStateStrategy
import com.arellomobile.mvp.viewstate.strategy.SkipStrategy
import com.arellomobile.mvp.viewstate.strategy.StateStrategyType
import ru.tele2med.mobile.domain.entity.DataShow
@ -8,7 +9,10 @@ import ru.tele2med.mobile.presentation.ui.base.BaseView
interface TestView : BaseView {
fun bindTest(test: DataShow) {
}
@StateStrategyType(OneExecutionStateStrategy::class)
fun toBack()
}