Skip to content

refactor: replace GuardedResultAsyncTask with AsyncTask #340

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ import android.graphics.BitmapFactory
import android.media.MediaMetadataRetriever
import android.net.Uri
import android.os.Build
import android.os.AsyncTask
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as far as I know... AsyncTask is deprecated in Java.
is there any alternative way?

import android.text.TextUtils
import android.webkit.URLUtil
import com.facebook.react.bridge.Arguments
import com.facebook.react.bridge.GuardedResultAsyncTask
import com.facebook.react.bridge.Promise
import com.facebook.react.bridge.ReactApplicationContext
import com.facebook.react.bridge.ReactContext
Expand All @@ -31,14 +31,14 @@ class CreateVideoThumbnailClass(private val reactContext: ReactApplicationContex
ProcessDataTask(reactContext,fileUrl, promise, options).execute()
}

private class ProcessDataTask(reactContext: ReactContext,private val filePath:String, private val promise: Promise, private val options: ReadableMap) : GuardedResultAsyncTask<ReadableMap?>(reactContext.exceptionHandler) {
private class ProcessDataTask(reactContext: ReactContext,private val filePath:String, private val promise: Promise, private val options: ReadableMap) : AsyncTask<Void, Void, ReadableMap?>() {
private val weakContext: WeakReference<Context>

init {
weakContext = WeakReference(reactContext.applicationContext)
}

override fun doInBackgroundGuarded(): ReadableMap? {
override fun doInBackground(vararg params: Void?): ReadableMap? {
val format = "jpeg"
val cacheName = if (options.hasKey("cacheName")) options.getString("cacheName") else ""
val thumbnailDir = weakContext.get()!!.applicationContext.cacheDir.absolutePath + "/thumbnails"
Expand Down Expand Up @@ -84,8 +84,8 @@ class CreateVideoThumbnailClass(private val reactContext: ReactApplicationContex
return null
}

override fun onPostExecuteGuarded(readableArray: ReadableMap?) {
promise.resolve(readableArray)
override fun onPostExecute(result: ReadableMap?) {
promise.resolve(result)
}
}

Expand Down