package app.furmeet.events.system.helper

import android.app.Activity
import android.content.Context
import android.widget.Toast
import androidx.activity.contextaware.ContextAwareHelper
import app.furmeet.events.system.schedule.fragments.FragmentWithSafeActivity
import app.furmeet.events.system.schedule.managers.UpdateChecker
import java.lang.ref.WeakReference
import java.util.concurrent.ExecutorService
import java.util.concurrent.Executors
import java.util.concurrent.Future

class AnkoAsyncContext<T>(val weakRef: WeakReference<T>)

fun doAsync(action: Runnable): Future<*>{
    val threadpool: ExecutorService = Executors.newFixedThreadPool(1)
    return threadpool.submit(action)
}

fun Activity.uiThread(action: Runnable){
    this.runOnUiThread(action)
}

fun FragmentWithSafeActivity.uiThread(action: Runnable){
    this.safeActivity.uiThread(action)
}

fun UpdateChecker.uiThread(action: Runnable){
    action.run()
}

fun Activity.longToast(message: String) = Toast.makeText(this.baseContext, message, Toast.LENGTH_LONG).show()
fun Activity.toast(message: String) = Toast.makeText(this.baseContext, message, Toast.LENGTH_SHORT).show()

fun Context.longToast(message: String) = Toast.makeText(this, message, Toast.LENGTH_LONG).show()
fun Context.toast(message: String) = Toast.makeText(this, message, Toast.LENGTH_SHORT).show()