LG U+ MobileManager

회사파인원커뮤니케이션즈
진행 기간
담당 Skills & 사용 LibrariesDataStoreFlowKotlinMVVMWebView
팀구성Android 1명 JavaScript 개발자 5명 (react)
U+모바일매니저 - Apps on Google Play
The beginning of a new communication life! U+ call convenience additional service settings/change/inquiry service app
https://play.google.com/store/apps/details?id=lgt.call

📱 담당한 기능

🛠️ 상세 내용

data class BaseData<T>(
    val header: Header,
    val param : T
)

internal inline fun <reified T> String.fromString(): T {
    val type = object : TypeToken<T>(){}.type
    return Gson().fromJson(this, type)
}

internal inline fun <reified T> JSONObject.fromJson(): T {
    return this.toString().fromString()
}

/**
 * result
 */
internal val JSONObject.result: JSONObject? get() {
    return optJSONObject(RESULT)
}

internal val JSONObject.code: String get() {
    return optString(ResultCode.CODE) ?: ResultCode.FAIL.code
}

suspend fun CustomTriple<JSONObject, (String) -> Unit, JSONObject?>.sendResult(resultCode : ResultCode, dispatcher: CoroutineDispatcher, result : Any? = null ) = withContext(dispatcher){
    val header = [email protected]
    val callback = [email protected]
    val resultWrap  = ResultWrapper(header.fromJson(),resultCode.code, result).toJsonString()
    LogUtil.d(LogUtil.DEBUG_LEVEL_2,"post data : result = $resultWrap")
    callback.invoke(resultWrap)
}

 open val coroutineExceptionHandler: CoroutineExceptionHandler
        get() = CoroutineExceptionHandler { _, _ -> }

override suspend fun testProcess(triple: CustomTriple<JSONObject, (String) -> Unit, JSONObject?>) {
        triple.params?.fromJson<UserInfo>()?.run {
            triple.sendResultProcess(testRepository.testSetUser(this), ioDispatcher)
        }?:triple.sendResult(ResultCode.NO_PARAMETER ,ioDispatcher)
    }

 private suspend fun CustomTriple<JSONObject, (String) -> Unit, JSONObject?>.requestProcess(type: HeaderType?) = withContext(ioDispatcher) {
        LogUtil.i(LogUtil.DEBUG_LEVEL_2, "requestProcess : $type")
        when (type) {
            ..생략..
            HeaderType.LAUNCH_OEM_CONTACT -> { launchOEMContactProcess(this@requestProcess) }
            HeaderType.GET_CONTACT_NAME_LIST -> { getContactNameListProcess(this@requestProcess) }
            HeaderType.TYPE_ERROR -> { LogUtil.e(LogUtil.DEBUG_LEVEL_2, "requestProcess : ${HeaderType.TYPE_ERROR}") }
            HeaderType.SEND_WEB_VERSION->{sendWebVersionProcess(this@requestProcess)}
            else -> {
                LogUtil.e(LogUtil.DEBUG_LEVEL_2, "requestProcess : ${HeaderType.TYPE_ERROR}")
            }
        }
    }

suspend fun readData(data: DataStoreParam): CustomPair<ResultCode,Any?> {
        var result: String? = null
        val code = setRunCatching {
            result = getDataStore(createKey(data.dataName))
        }
        result?.let { return CustomPair(ResultCode.SUCCESS, result) } ?: return CustomPair(code, null)
    }

enum class ResultCode(val code: String) {
    SUCCESS("200"), // 성공
		..실패 사항 생략 ..
    FAIL("9999"); //실패

    val isSuccess : Boolean
        get() = SUCCESS_STATES.contains(this)

    companion object{
        @JvmStatic
        fun fromCode(code: String?): ResultCode = values().firstOrNull { it.code == code }?: FAIL
        const val CODE = "code"
        private val SUCCESS_STATES = setOf(SUCCESS)

        @JvmStatic
        suspend fun setRunCatching(dispatcher: CoroutineContext = Dispatchers.IO ,block : suspend ()->Unit ) : ResultCode = withContext(dispatcher){
            return@withContext try {
                block()
                SUCCESS
            }
            ..생략 ..
            }catch (e : JsonSyntaxException){
                LogUtil.e(LogUtil.DEBUG_LEVEL_2,"JsonSyntaxException : ${e.message}")
                JSON_PARSE_ERROR
          }catch (e : Exception){
                LogUtil.e(LogUtil.DEBUG_LEVEL_2,"Exception : ${e.message}")
                LogUtil.e(LogUtil.DEBUG_LEVEL_2,"Exception : ${e}")
                FAIL
            }
        }
    }
}