* SDK Android and Desktop *
* Update latest version library *
* Renaming Module : frogocoresdk to core-sdk *
// Add it in your root build.gradle at the end of repositories:
allprojects {
repositories {
...
maven { url 'https://jitpack.io' }
}
}
#### <Option 1> Groovy Gradle
dependencies {
// library frogo-sdk
implementation 'com.github.frogobox:frogo-sdk:2.2.7'
// library frogo-sdk for desktop
implementation 'com.github.frogobox.frogo-sdk:core-sdk:2.2.7'
}
#### <Option 2> Kotlin DSL Gradle
dependencies {
// library frogo-sdk
implementation("com.github.frogobox:frogo-sdk:2.2.7")
// library frogo-sdk for desktop
implementation("com.github.frogobox.frogo-sdk:core-sdk:2.2.7")
}
fun setupDetailActivity(title: String)
fun setupChildFragment(frameId: Int, fragment: Fragment)
fun showToast(message: String)
fun setupEmptyView(view: View, isEmpty: Boolean)
fun setupProgressView(view: View, isProgress: Boolean)
fun checkExtra(extraKey: String): Boolean
fun <Model> FrogoFragmentNewInstance(
fragment: FrogoFragment<*>,
argumentKey: String,
extraDataResult: Model
)
fun isNetworkConnected(): Boolean
fun setupFullScreen()
fun setupHideSystemUI()
fun shareApp(packageName: String, appName: String)
fun rateApp(packageName: String)
// Single Api Request with scheduler
fun <T : Any> Observable<T>.doApiRequest(scheduler: Scheduler, callback: FrogoDataResponse<T>) {
subscribeOn(Schedulers.io())
.doOnSubscribe { callback.onShowProgress() }
.doAfterTerminate { callback.onHideProgress() }
.observeOn(scheduler)
.subscribe(object : FrogoApiObserver<T>() {
override fun onSuccess(data: T) {
callback.onSuccess(data)
}
override fun onFailure(code: Int, errorMessage: String) {
callback.onFailed(code, errorMessage)
}
})
}
// -------------------------------------------------------------------------------------------------
// Single Api Request
fun <T : Any> Observable<T>.doApiRequest(callback: FrogoDataResponse<T>) {
doOnSubscribe { callback.onShowProgress() }
.doAfterTerminate { callback.onHideProgress() }
.subscribe(object : FrogoApiObserver<T>() {
override fun onSuccess(data: T) {
callback.onSuccess(data)
}
override fun onFailure(code: Int, errorMessage: String) {
callback.onFailed(code, errorMessage)
}
})
}
inline fun <reified ClassActivity> Context.singleStartActivity() {
FLog.d("Activity : ${ClassActivity::class.java.simpleName}")
startActivity(Intent(this, ClassActivity::class.java))
}
// -------------------------------------------------------------------------------------------------
inline fun <reified ClassActivity, reified Model> Context.singleStartActivity(
extraKey: String,
data: Model
) {
val intent = Intent(this, ClassActivity::class.java)
val extraData = Gson().toJson(data)
intent.putExtra(extraKey, extraData)
FLog.d("Activity : ${ClassActivity::class.java.simpleName}")
FLog.d("Data : Extra Data (${Model::class.java.simpleName}) : $extraData")
startActivity(intent)
}
// -------------------------------------------------------------------------------------------------
inline fun <reified Model> Activity.singleGetExtraData(extraKey: String): Model {
val extraIntent = intent.getStringExtra(extraKey)
return Gson().fromJson(extraIntent, Model::class.java)
}
// -------------------------------------------------------------------------------------------------
fun Context.singleStartActivityShareApp(subject: String, text: String) {
val intent = Intent(Intent.ACTION_SEND)
intent.type = "text/plain"
intent.putExtra(Intent.EXTRA_SUBJECT, subject)
intent.putExtra(Intent.EXTRA_TEXT, text)
FLog.d("$TAG : Subject Share App : $subject")
FLog.d("$TAG : Message Share App : $text")
startActivity(Intent.createChooser(intent, subject))
}
// -------------------------------------------------------------------------------------------------
fun Context.singleStartActivityOpenApp(url: String) {
FLog.d("$TAG : Url : $url")
startActivity(Intent(Intent.ACTION_VIEW, Uri.parse(url)))
}
fun Context.getAppVersionCode(): Int? {
try {
return packageManager?.getPackageInfo(packageName, 0)
?.let { PackageInfoCompat.getLongVersionCode(it).toInt() }
} catch (ex: Exception) {
FLog.e("$TAG : ${ex.message.orEmpty()}")
}
return null
}
// -------------------------------------------------------------------------------------------------
fun Context.showToast(
message: String,
duration: Int = Toast.LENGTH_SHORT
) {
Toast.makeText(this, message, duration).show()
}
// -------------------------------------------------------------------------------------------------
fun Context.hasCameraPermission(): Boolean =
ContextCompat.checkSelfPermission(
this,
Manifest.permission.CAMERA
) == PackageManager.PERMISSION_GRANTED
// -------------------------------------------------------------------------------------------------
fun Context.hasReadExtStoragePermission(): Boolean {
return ContextCompat.checkSelfPermission(
this,
Manifest.permission.READ_EXTERNAL_STORAGE
) == PackageManager.PERMISSION_GRANTED
}
fun Context.hasWriteExtStoragePermission(): Boolean {
return ContextCompat.checkSelfPermission(
this,
Manifest.permission.WRITE_EXTERNAL_STORAGE
) == PackageManager.PERMISSION_GRANTED
}