Advertisement
rizkirchm

TestContinuation

Sep 7th, 2022
1,486
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Kotlin 3.03 KB | None | 0 0
  1. ...
  2. ...
  3.  
  4. CoroutineScope(Dispatchers.Main).launch {
  5.                                 newTask.forEach { valueTask ->
  6.                                     masterQuestionRepository.getMasterQuestionByFormCode(
  7.                                         valueTask.FORM_CODE
  8.                                     ).observeOnce(androidx.lifecycle.Observer { valueGetTask ->
  9.                                         valueGetTask.forEach {
  10.                                             if ((it.ANSWER_TYPE_ID == AnswerTypeEnum.CAMERA.code
  11.                                                         || it.ANSWER_TYPE_ID == AnswerTypeEnum.SELFIE.code)
  12.                                                 && it.DEFAULT_VALUE_Q?.isNotEmpty() == true
  13.                                             ) {
  14.                                                 val splitingValue =
  15.                                                     it.DEFAULT_VALUE_Q?.split(
  16.                                                         "|"
  17.                                                     )
  18.  
  19.                                                 CoroutineScope(Dispatchers.IO).launch{
  20.                                                     splitingValue?.forEach { dsa ->
  21.                                                         getValue(dsa, valueTask.APPLICATION_ID)
  22.                                                     }
  23.                                                 }
  24.  
  25.  
  26.                                             }
  27.                                         }
  28.  
  29.                                     })
  30.                                 }
  31.                             }
  32.  
  33.  
  34.  
  35. // CONTINUATION
  36. suspend fun getValue(flag: String, appId: String?): String = suspendCoroutine { cont ->
  37.  
  38.         HttpRequest(application.applicationContext).httpHandler(
  39.             Request.Method.GET,
  40.             "${ServiceUrl.URL_GET_PHOTO}/$appId/$flag",
  41.             JSONObject(),
  42.             object : HttpRequest.Callback {
  43.                 override fun onHttpPostSuccess(result: String) {
  44.                     val type = object :
  45.                         TypeToken<ResponseModel<String>>() {}.type
  46.                     val data: ResponseModel<String> =
  47.                         Gson().fromJson(result, type)
  48.  
  49.                     if (data.isSuccess()) {
  50.                         if (data.contents?.isNotEmpty() == true) {
  51.                             Log.d(
  52.                                 "GetPhotoSuccess",
  53.                                 cont.resume(data.contents).toString()
  54.                             )
  55.                             return
  56.                         }
  57.                     } else {
  58.                         Log.d("GetPhotoFailed",
  59.                             cont.resume(data.contents.toString()).toString()
  60.                         )
  61.                     }
  62.                 }
  63.  
  64.                 override fun onHttpPostError(error: String) {
  65.                     Log.d("GetPhotoError",
  66.                         error
  67.                     )
  68.                     cont.resume(error)
  69.  
  70.                 }
  71.  
  72.             }
  73.         )
  74.  
  75.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement