mirror of
https://github.com/SchildiChat/SchildiChat-android.git
synced 2025-01-27 09:31:20 +01:00
Fix bug reporter progress.
This commit is contained in:
parent
23623b8895
commit
fa311f4ce2
@ -102,7 +102,7 @@ class BugReporter @Inject constructor(
|
||||
var screenshot: Bitmap? = null
|
||||
private set
|
||||
|
||||
private val coroutineScope = CoroutineScope(SupervisorJob())
|
||||
private val coroutineScope = CoroutineScope(SupervisorJob() + Dispatchers.Main)
|
||||
|
||||
private val LOGCAT_CMD_ERROR = arrayOf("logcat", // /< Run 'logcat' command
|
||||
"-d", // /< Dump the log rather than continue outputting it
|
||||
@ -169,13 +169,10 @@ class BugReporter @Inject constructor(
|
||||
// enumerate files to delete
|
||||
val mBugReportFiles: MutableList<File> = ArrayList()
|
||||
|
||||
coroutineScope.executeAsyncTask(
|
||||
onPreExecute = {
|
||||
// NOOP
|
||||
},
|
||||
doInBackground = { publishProgress: suspend (progress: Int) -> Unit ->
|
||||
var bugDescription = theBugDescription
|
||||
coroutineScope.launch {
|
||||
var serverError: String? = null
|
||||
withContext(Dispatchers.IO) {
|
||||
var bugDescription = theBugDescription
|
||||
val crashCallStack = getCrashDescription(context)
|
||||
|
||||
if (null != crashCallStack) {
|
||||
@ -351,7 +348,11 @@ class BugReporter @Inject constructor(
|
||||
}
|
||||
|
||||
Timber.v("## onWrite() : $percentage%")
|
||||
suspend { publishProgress(percentage) }
|
||||
try {
|
||||
listener?.onProgress(percentage)
|
||||
} catch (e: Exception) {
|
||||
Timber.e(e, "## onProgress() : failed")
|
||||
}
|
||||
}
|
||||
|
||||
// build the request
|
||||
@ -395,12 +396,14 @@ class BugReporter @Inject constructor(
|
||||
}
|
||||
|
||||
// check if the error message
|
||||
serverError?.let {
|
||||
try {
|
||||
val responseJSON = JSONObject(serverError)
|
||||
val responseJSON = JSONObject(it)
|
||||
serverError = responseJSON.getString("error")
|
||||
} catch (e: JSONException) {
|
||||
Timber.e(e, "doInBackground ; Json conversion failed")
|
||||
}
|
||||
}
|
||||
|
||||
// should never happen
|
||||
if (null == serverError) {
|
||||
@ -412,19 +415,9 @@ class BugReporter @Inject constructor(
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
serverError
|
||||
},
|
||||
onProgressUpdate = { progress ->
|
||||
if (null != listener) {
|
||||
try {
|
||||
listener.onProgress(progress)
|
||||
} catch (e: Exception) {
|
||||
Timber.e(e, "## onProgress() : failed")
|
||||
}
|
||||
}
|
||||
},
|
||||
onPostExecute = { reason: String? ->
|
||||
withContext(Dispatchers.Main) {
|
||||
mBugReportCall = null
|
||||
|
||||
// delete when the bug report has been successfully sent
|
||||
@ -436,17 +429,17 @@ class BugReporter @Inject constructor(
|
||||
try {
|
||||
if (mIsCancelled) {
|
||||
listener.onUploadCancelled()
|
||||
} else if (null == reason) {
|
||||
} else if (null == serverError) {
|
||||
listener.onUploadSucceed()
|
||||
} else {
|
||||
listener.onUploadFailed(reason)
|
||||
listener.onUploadFailed(serverError)
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
Timber.e(e, "## onPostExecute() : failed")
|
||||
}
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -703,21 +696,4 @@ class BugReporter @Inject constructor(
|
||||
|
||||
return null
|
||||
}
|
||||
|
||||
fun <P, R> CoroutineScope.executeAsyncTask(
|
||||
onPreExecute: () -> Unit,
|
||||
doInBackground: suspend (suspend (P) -> Unit) -> R,
|
||||
onPostExecute: (R) -> Unit,
|
||||
onProgressUpdate: (P) -> Unit
|
||||
) = launch {
|
||||
onPreExecute()
|
||||
|
||||
val result = withContext(Dispatchers.IO) {
|
||||
doInBackground {
|
||||
withContext(Dispatchers.Main) { onProgressUpdate(it) }
|
||||
}
|
||||
}
|
||||
|
||||
onPostExecute(result)
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user