Move extensions out
This commit is contained in:
30
app/src/main/java/com/aurora/extensions/Collection.kt
Normal file
30
app/src/main/java/com/aurora/extensions/Collection.kt
Normal file
@@ -0,0 +1,30 @@
|
||||
/*
|
||||
* Aurora Store
|
||||
* Copyright (C) 2021, Rahul Kumar Patel <whyorean@gmail.com>
|
||||
*
|
||||
* Aurora Store is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Aurora Store is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Aurora Store. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
package com.aurora.extensions
|
||||
|
||||
fun <T> MutableList<T>.flushAndAdd(list: List<T>) {
|
||||
clear()
|
||||
addAll(list)
|
||||
}
|
||||
|
||||
fun <T> MutableSet<T>.flushAndAdd(list: Set<T>) {
|
||||
clear()
|
||||
addAll(list)
|
||||
}
|
||||
29
app/src/main/java/com/aurora/extensions/Commons.kt
Normal file
29
app/src/main/java/com/aurora/extensions/Commons.kt
Normal file
@@ -0,0 +1,29 @@
|
||||
/*
|
||||
* Aurora Store
|
||||
* Copyright (C) 2021, Rahul Kumar Patel <whyorean@gmail.com>
|
||||
*
|
||||
* Aurora Store is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Aurora Store is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Aurora Store. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
package com.aurora.extensions
|
||||
|
||||
import android.text.format.DateFormat
|
||||
import java.util.*
|
||||
|
||||
fun Long.toDate(): String {
|
||||
val calendar = Calendar.getInstance(Locale.getDefault())
|
||||
calendar.timeInMillis = this
|
||||
return DateFormat.format("dd/MM/yy", calendar).toString()
|
||||
}
|
||||
32
app/src/main/java/com/aurora/extensions/Conditional.kt
Normal file
32
app/src/main/java/com/aurora/extensions/Conditional.kt
Normal file
@@ -0,0 +1,32 @@
|
||||
/*
|
||||
* Aurora Store
|
||||
* Copyright (C) 2021, Rahul Kumar Patel <whyorean@gmail.com>
|
||||
*
|
||||
* Aurora Store is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Aurora Store is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Aurora Store. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
package com.aurora.extensions
|
||||
|
||||
inline fun doIf(condition: Boolean?, action: () -> Unit) {
|
||||
if (condition == true) action()
|
||||
}
|
||||
|
||||
inline fun doIf(condition: () -> Boolean?, action: () -> Unit) {
|
||||
if (condition() == true) action()
|
||||
}
|
||||
|
||||
inline fun doIf(any: Any?, action: () -> Unit) {
|
||||
if (any != null) action()
|
||||
}
|
||||
114
app/src/main/java/com/aurora/extensions/Context.kt
Normal file
114
app/src/main/java/com/aurora/extensions/Context.kt
Normal file
@@ -0,0 +1,114 @@
|
||||
/*
|
||||
* Aurora Store
|
||||
* Copyright (C) 2021, Rahul Kumar Patel <whyorean@gmail.com>
|
||||
*
|
||||
* Aurora Store is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Aurora Store is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Aurora Store. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
package com.aurora.extensions
|
||||
|
||||
import android.app.AlarmManager
|
||||
import android.app.PendingIntent
|
||||
import android.content.ClipData
|
||||
import android.content.ClipboardManager
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.net.Uri
|
||||
import android.os.Build
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import androidx.core.app.ShareCompat
|
||||
import com.aurora.Constants
|
||||
import com.aurora.gplayapi.data.models.App
|
||||
import com.aurora.store.MainActivity
|
||||
import com.aurora.store.R
|
||||
import com.aurora.store.util.Log
|
||||
import com.aurora.store.util.ViewUtil
|
||||
import kotlin.system.exitProcess
|
||||
|
||||
|
||||
fun Context.browse(url: String) {
|
||||
try {
|
||||
startActivity(
|
||||
Intent(
|
||||
Intent.ACTION_VIEW,
|
||||
Uri.parse(url)
|
||||
)
|
||||
)
|
||||
} catch (e: Exception) {
|
||||
Log.e(e.message)
|
||||
}
|
||||
}
|
||||
|
||||
fun Context.share(app: App) {
|
||||
try {
|
||||
ShareCompat.IntentBuilder.from(this as AppCompatActivity)
|
||||
.setType("text/plain")
|
||||
.setChooserTitle(getString(R.string.action_share))
|
||||
.setSubject(app.displayName)
|
||||
.setText(Constants.SHARE_URL + app.packageName)
|
||||
.startChooser()
|
||||
} catch (e: Exception) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
fun Context.openInfo(packageName: String) {
|
||||
try {
|
||||
val intent = Intent(
|
||||
"android.settings.APPLICATION_DETAILS_SETTINGS",
|
||||
Uri.parse("package:$packageName")
|
||||
)
|
||||
startActivity(intent)
|
||||
} catch (e: Exception) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
fun <T> Context.open(className: Class<T>, newTask: Boolean = false) {
|
||||
val intent = Intent(this, className)
|
||||
if (newTask)
|
||||
intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TASK
|
||||
startActivity(
|
||||
intent,
|
||||
ViewUtil.getEmptyActivityBundle(this)
|
||||
)
|
||||
}
|
||||
|
||||
fun AppCompatActivity.close() {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
|
||||
finishAfterTransition()
|
||||
} else {
|
||||
finish()
|
||||
}
|
||||
}
|
||||
|
||||
fun Context.restartApp() {
|
||||
val pendingIntent = PendingIntent.getActivity(
|
||||
this,
|
||||
1337,
|
||||
Intent(this, MainActivity::class.java),
|
||||
PendingIntent.FLAG_CANCEL_CURRENT
|
||||
)
|
||||
|
||||
val alarmManager = getSystemService(Context.ALARM_SERVICE) as AlarmManager
|
||||
alarmManager.set(AlarmManager.RTC, System.currentTimeMillis() + 100, pendingIntent)
|
||||
exitProcess(0)
|
||||
}
|
||||
|
||||
fun Context.copyToClipBoard(data: String?) {
|
||||
val clipboard = getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager
|
||||
val clip = ClipData.newPlainText("Download Url", data)
|
||||
clipboard.setPrimaryClip(clip)
|
||||
}
|
||||
165
app/src/main/java/com/aurora/extensions/Glide.kt
Normal file
165
app/src/main/java/com/aurora/extensions/Glide.kt
Normal file
@@ -0,0 +1,165 @@
|
||||
/*
|
||||
* Aurora Store
|
||||
* Copyright (C) 2021, Rahul Kumar Patel <whyorean@gmail.com>
|
||||
*
|
||||
* Aurora Store is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Aurora Store is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Aurora Store. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
package com.aurora.extensions
|
||||
|
||||
import android.graphics.Bitmap
|
||||
import android.graphics.drawable.Drawable
|
||||
import android.net.Uri
|
||||
import android.widget.ImageView
|
||||
import androidx.annotation.DrawableRes
|
||||
import androidx.annotation.RawRes
|
||||
import com.bumptech.glide.Glide
|
||||
import com.bumptech.glide.TransitionOptions
|
||||
import com.bumptech.glide.load.resource.drawable.DrawableTransitionOptions.withCrossFade
|
||||
import com.bumptech.glide.request.RequestOptions
|
||||
import com.bumptech.glide.request.target.ViewTarget
|
||||
import com.bumptech.glide.request.transition.DrawableCrossFadeFactory
|
||||
import java.io.File
|
||||
|
||||
fun ImageView.load(
|
||||
bitmap: Bitmap?,
|
||||
transitionOptions: TransitionOptions<*, Drawable>? = null,
|
||||
requestOptions: RequestOptions? = null
|
||||
): ViewTarget<ImageView, Drawable> = loadAny(bitmap, transitionOptions, requestOptions)
|
||||
|
||||
@JvmSynthetic
|
||||
fun ImageView.load(
|
||||
byteArray: ByteArray?,
|
||||
transitionOptions: TransitionOptions<*, Drawable>? = null,
|
||||
requestOptions: RequestOptions? = null
|
||||
): ViewTarget<ImageView, Drawable> = loadAny(byteArray, transitionOptions, requestOptions)
|
||||
|
||||
@JvmSynthetic
|
||||
fun ImageView.load(
|
||||
drawable: Drawable?,
|
||||
transitionOptions: TransitionOptions<*, Drawable>? = null,
|
||||
requestOptions: RequestOptions? = null
|
||||
): ViewTarget<ImageView, Drawable> = loadAny(drawable, transitionOptions, requestOptions)
|
||||
|
||||
@JvmSynthetic
|
||||
fun ImageView.load(
|
||||
@RawRes @DrawableRes resourceId: Int?,
|
||||
transitionOptions: TransitionOptions<*, Drawable>? = null,
|
||||
requestOptions: RequestOptions? = null
|
||||
): ViewTarget<ImageView, Drawable> = loadAny(resourceId, transitionOptions, requestOptions)
|
||||
|
||||
@JvmSynthetic
|
||||
fun ImageView.load(
|
||||
uri: Uri?,
|
||||
transitionOptions: TransitionOptions<*, Drawable>? = null,
|
||||
requestOptions: RequestOptions? = null
|
||||
): ViewTarget<ImageView, Drawable> = loadAny(uri, transitionOptions, requestOptions)
|
||||
|
||||
@JvmSynthetic
|
||||
fun ImageView.load(
|
||||
string: String?,
|
||||
transitionOptions: TransitionOptions<*, Drawable>? = null,
|
||||
requestOptions: RequestOptions? = null
|
||||
): ViewTarget<ImageView, Drawable> = loadAny(string, transitionOptions, requestOptions)
|
||||
|
||||
@JvmSynthetic
|
||||
fun ImageView.load(
|
||||
file: File?,
|
||||
transitionOptions: TransitionOptions<*, Drawable>? = null,
|
||||
requestOptions: RequestOptions? = null
|
||||
): ViewTarget<ImageView, Drawable> = loadAny(file, transitionOptions, requestOptions)
|
||||
|
||||
@JvmSynthetic
|
||||
inline fun ImageView.load(
|
||||
bitmap: Bitmap?,
|
||||
transitionOptions: TransitionOptions<*, Drawable>? = null,
|
||||
requestOptions: RequestOptions.() -> Unit
|
||||
): ViewTarget<ImageView, Drawable> = loadAny(bitmap, transitionOptions, requestOptions)
|
||||
|
||||
@JvmSynthetic
|
||||
inline fun ImageView.load(
|
||||
byteArray: ByteArray?,
|
||||
transitionOptions: TransitionOptions<*, Drawable>? = null,
|
||||
requestOptions: RequestOptions.() -> Unit
|
||||
): ViewTarget<ImageView, Drawable> = loadAny(byteArray, transitionOptions, requestOptions)
|
||||
|
||||
@JvmSynthetic
|
||||
inline fun ImageView.load(
|
||||
drawable: Drawable?,
|
||||
transitionOptions: TransitionOptions<*, Drawable>? = null,
|
||||
requestOptions: RequestOptions.() -> Unit
|
||||
): ViewTarget<ImageView, Drawable> = loadAny(drawable, transitionOptions, requestOptions)
|
||||
|
||||
@JvmSynthetic
|
||||
inline fun ImageView.load(
|
||||
@RawRes @DrawableRes resourceId: Int?,
|
||||
transitionOptions: TransitionOptions<*, Drawable>? = null,
|
||||
requestOptions: RequestOptions.() -> Unit
|
||||
): ViewTarget<ImageView, Drawable> = loadAny(resourceId, transitionOptions, requestOptions)
|
||||
|
||||
@JvmSynthetic
|
||||
inline fun ImageView.load(
|
||||
uri: Uri?,
|
||||
transitionOptions: TransitionOptions<*, Drawable>? = null,
|
||||
requestOptions: RequestOptions.() -> Unit
|
||||
): ViewTarget<ImageView, Drawable> = loadAny(uri, transitionOptions, requestOptions)
|
||||
|
||||
@JvmSynthetic
|
||||
inline fun ImageView.load(
|
||||
string: String?,
|
||||
transitionOptions: TransitionOptions<*, Drawable>? = null,
|
||||
requestOptions: RequestOptions.() -> Unit
|
||||
): ViewTarget<ImageView, Drawable> = loadAny(string, transitionOptions, requestOptions)
|
||||
|
||||
@JvmSynthetic
|
||||
inline fun ImageView.load(
|
||||
file: File?,
|
||||
transitionOptions: TransitionOptions<*, Drawable>? = null,
|
||||
requestOptions: RequestOptions.() -> Unit
|
||||
): ViewTarget<ImageView, Drawable> = loadAny(file, transitionOptions, requestOptions)
|
||||
|
||||
@JvmSynthetic
|
||||
fun ImageView.loadAny(
|
||||
data: Any?,
|
||||
transitionOptions: TransitionOptions<*, Drawable>? = null,
|
||||
requestOptions: RequestOptions? = null
|
||||
): ViewTarget<ImageView, Drawable> {
|
||||
return Glide.with(this)
|
||||
.load(data)
|
||||
.apply {
|
||||
transitionOptions?.let { transition(it) }
|
||||
requestOptions?.let { apply(it) }
|
||||
}
|
||||
.into(this)
|
||||
}
|
||||
|
||||
@JvmSynthetic
|
||||
inline fun ImageView.loadAny(
|
||||
data: Any?,
|
||||
transitionOptions: TransitionOptions<*, Drawable>? = null,
|
||||
requestOptions: RequestOptions.() -> Unit
|
||||
): ViewTarget<ImageView, Drawable> {
|
||||
val factory = DrawableCrossFadeFactory.Builder().setCrossFadeEnabled(true).build()
|
||||
return Glide.with(this)
|
||||
.load(data)
|
||||
.transition(withCrossFade(factory))
|
||||
.apply(RequestOptions().apply(requestOptions))
|
||||
.into(this)
|
||||
}
|
||||
|
||||
@JvmSynthetic
|
||||
fun ImageView.clear() {
|
||||
//Glide.with(this).clear(this)
|
||||
}
|
||||
28
app/src/main/java/com/aurora/extensions/Number.kt
Normal file
28
app/src/main/java/com/aurora/extensions/Number.kt
Normal file
@@ -0,0 +1,28 @@
|
||||
/*
|
||||
* Aurora Store
|
||||
* Copyright (C) 2021, Rahul Kumar Patel <whyorean@gmail.com>
|
||||
*
|
||||
* Aurora Store is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Aurora Store is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Aurora Store. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
package com.aurora.extensions
|
||||
|
||||
import android.content.res.Resources
|
||||
|
||||
val Number.dp: Number
|
||||
get() = (this.toFloat() / Resources.getSystem().displayMetrics.density).toInt()
|
||||
|
||||
val Number.px: Number
|
||||
get() = (this.toFloat() * Resources.getSystem().displayMetrics.density).toInt()
|
||||
51
app/src/main/java/com/aurora/extensions/Platform.kt
Normal file
51
app/src/main/java/com/aurora/extensions/Platform.kt
Normal file
@@ -0,0 +1,51 @@
|
||||
/*
|
||||
* Aurora Store
|
||||
* Copyright (C) 2021, Rahul Kumar Patel <whyorean@gmail.com>
|
||||
*
|
||||
* Aurora Store is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Aurora Store is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Aurora Store. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
package com.aurora.extensions
|
||||
|
||||
import android.os.Build
|
||||
|
||||
|
||||
fun isLAndAbove(): Boolean {
|
||||
return Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP
|
||||
}
|
||||
|
||||
fun isMAndAbove(): Boolean {
|
||||
return Build.VERSION.SDK_INT >= Build.VERSION_CODES.M
|
||||
}
|
||||
|
||||
fun isNAndAbove(): Boolean {
|
||||
return Build.VERSION.SDK_INT >= Build.VERSION_CODES.N
|
||||
}
|
||||
|
||||
fun isOAndAbove(): Boolean {
|
||||
return Build.VERSION.SDK_INT >= Build.VERSION_CODES.O
|
||||
}
|
||||
|
||||
fun isPAndAbove(): Boolean {
|
||||
return Build.VERSION.SDK_INT >= Build.VERSION_CODES.P
|
||||
}
|
||||
|
||||
fun isQAndAbove(): Boolean {
|
||||
return Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q
|
||||
}
|
||||
|
||||
fun isRAndAbove(): Boolean {
|
||||
return Build.VERSION.SDK_INT >= Build.VERSION_CODES.R
|
||||
}
|
||||
148
app/src/main/java/com/aurora/extensions/ThemeEngine.kt
Normal file
148
app/src/main/java/com/aurora/extensions/ThemeEngine.kt
Normal file
@@ -0,0 +1,148 @@
|
||||
/*
|
||||
* Aurora Store
|
||||
* Copyright (C) 2021, Rahul Kumar Patel <whyorean@gmail.com>
|
||||
*
|
||||
* Aurora Store is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Aurora Store is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Aurora Store. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
package com.aurora.extensions
|
||||
|
||||
import android.content.Intent
|
||||
import android.content.res.Configuration
|
||||
import android.graphics.Color
|
||||
import android.os.Build
|
||||
import android.view.View
|
||||
import android.view.WindowInsetsController
|
||||
import androidx.annotation.RequiresApi
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import androidx.appcompat.app.AppCompatDelegate
|
||||
import androidx.core.graphics.ColorUtils
|
||||
import androidx.fragment.app.Fragment
|
||||
import com.aurora.Constants
|
||||
import com.aurora.store.R
|
||||
import com.aurora.store.util.CommonUtil
|
||||
import com.aurora.store.util.ViewUtil
|
||||
|
||||
|
||||
fun Fragment.applyTheme(
|
||||
themeId: Int,
|
||||
accentId: Int = 1,
|
||||
shouldApplyTransition: Boolean = true,
|
||||
position: Int = 2
|
||||
) {
|
||||
val themeStyle = CommonUtil.getThemeStyleById(themeId)
|
||||
|
||||
if (themeId == 0) {
|
||||
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM)
|
||||
(requireActivity() as AppCompatActivity).applyDayNightMask()
|
||||
} else {
|
||||
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES)
|
||||
}
|
||||
|
||||
/*Apply Theme*/
|
||||
requireContext().theme.applyStyle(themeStyle, true)
|
||||
|
||||
/*Apply transition only on AppCompatActivity*/
|
||||
if (shouldApplyTransition)
|
||||
(requireActivity() as AppCompatActivity).transitionRecreate(position)
|
||||
else
|
||||
(requireActivity() as AppCompatActivity).recreate()
|
||||
|
||||
if (themeId == 1) {
|
||||
(requireActivity() as AppCompatActivity).setLightConfiguration()
|
||||
}
|
||||
}
|
||||
|
||||
fun AppCompatActivity.transitionRecreate(position: Int = 2) {
|
||||
val intent = Intent(this, javaClass)
|
||||
intent.putExtra(Constants.INT_EXTRA, position)
|
||||
//intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)
|
||||
startActivity(intent)
|
||||
overridePendingTransition(R.anim.fade_in, R.anim.fade_out)
|
||||
}
|
||||
|
||||
fun AppCompatActivity.applyTheme(themeId: Int, accentId: Int = 1) {
|
||||
val themeStyle = CommonUtil.getThemeStyleById(themeId)
|
||||
val accentStyle = CommonUtil.getAccentStyleById(accentId)
|
||||
|
||||
if (themeId == 0) {
|
||||
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM)
|
||||
applyDayNightMask()
|
||||
} else {
|
||||
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES)
|
||||
}
|
||||
|
||||
/*Apply Theme*/
|
||||
setTheme(themeStyle)
|
||||
|
||||
/*Apply Accent*/
|
||||
theme.applyStyle(accentStyle, true)
|
||||
|
||||
/*Apply Light Configuration*/
|
||||
if (themeId == 1) {
|
||||
setLightConfiguration()
|
||||
}
|
||||
}
|
||||
|
||||
fun AppCompatActivity.applyDayNightMask() {
|
||||
val currentNightMode = resources.configuration.uiMode and Configuration.UI_MODE_NIGHT_MASK
|
||||
if (currentNightMode == Configuration.UI_MODE_NIGHT_NO) {
|
||||
setLightConfiguration()
|
||||
}
|
||||
}
|
||||
|
||||
fun AppCompatActivity.setLightConfiguration() {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
|
||||
setLightConfigurationO()
|
||||
} else {
|
||||
setLightConfigurationO()
|
||||
}
|
||||
}
|
||||
|
||||
@RequiresApi(Build.VERSION_CODES.R)
|
||||
private fun AppCompatActivity.setLightConfigurationR() {
|
||||
window?.insetsController?.setSystemBarsAppearance(
|
||||
WindowInsetsController.APPEARANCE_LIGHT_STATUS_BARS
|
||||
or WindowInsetsController.APPEARANCE_LIGHT_NAVIGATION_BARS,
|
||||
WindowInsetsController.APPEARANCE_LIGHT_STATUS_BARS
|
||||
)
|
||||
}
|
||||
|
||||
private fun AppCompatActivity.setLightConfigurationO() {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
||||
setLightStatusBar()
|
||||
setLightNavigationBar()
|
||||
} else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
|
||||
window.statusBarColor = ColorUtils.setAlphaComponent(Color.BLACK, 120)
|
||||
}
|
||||
}
|
||||
|
||||
private fun AppCompatActivity.setLightStatusBar() {
|
||||
var flags = window.decorView.systemUiVisibility
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
||||
flags = flags or View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR
|
||||
}
|
||||
window.decorView.systemUiVisibility = flags
|
||||
}
|
||||
|
||||
private fun AppCompatActivity.setLightNavigationBar() {
|
||||
var flags = window.decorView.systemUiVisibility
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||
window.navigationBarColor =
|
||||
ViewUtil.getStyledAttribute(this, android.R.attr.colorBackground)
|
||||
flags = flags or View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR
|
||||
}
|
||||
window.decorView.systemUiVisibility = flags
|
||||
}
|
||||
41
app/src/main/java/com/aurora/extensions/Threading.kt
Normal file
41
app/src/main/java/com/aurora/extensions/Threading.kt
Normal file
@@ -0,0 +1,41 @@
|
||||
/*
|
||||
* Aurora Store
|
||||
* Copyright (C) 2021, Rahul Kumar Patel <whyorean@gmail.com>
|
||||
*
|
||||
* Aurora Store is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Aurora Store is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Aurora Store. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
package com.aurora.extensions
|
||||
|
||||
import android.os.Handler
|
||||
import android.os.Looper
|
||||
|
||||
fun runAsync(action: () -> Unit) = Thread(Runnable(action)).start()
|
||||
|
||||
fun runOnUiThread(action: () -> Unit) {
|
||||
if (isMainLooperAlive()) {
|
||||
action()
|
||||
} else {
|
||||
Handler(Looper.getMainLooper()).post(Runnable(action))
|
||||
}
|
||||
}
|
||||
|
||||
fun runDelayed(delayMillis: Long, action: () -> Unit) =
|
||||
Handler().postDelayed(Runnable(action), delayMillis)
|
||||
|
||||
fun runDelayedOnUiThread(delayMillis: Long, action: () -> Unit) =
|
||||
Handler(Looper.getMainLooper()).postDelayed(Runnable(action), delayMillis)
|
||||
|
||||
private fun isMainLooperAlive() = Looper.myLooper() == Looper.getMainLooper()
|
||||
36
app/src/main/java/com/aurora/extensions/Toast.kt
Normal file
36
app/src/main/java/com/aurora/extensions/Toast.kt
Normal file
@@ -0,0 +1,36 @@
|
||||
/*
|
||||
* Aurora Store
|
||||
* Copyright (C) 2021, Rahul Kumar Patel <whyorean@gmail.com>
|
||||
*
|
||||
* Aurora Store is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Aurora Store is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Aurora Store. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
package com.aurora.extensions
|
||||
|
||||
import android.content.Context
|
||||
import android.widget.Toast
|
||||
import androidx.annotation.StringRes
|
||||
|
||||
fun Context.toast(text: CharSequence): Toast =
|
||||
Toast.makeText(this, text, Toast.LENGTH_SHORT).apply { show() }
|
||||
|
||||
fun Context.longToast(text: CharSequence): Toast =
|
||||
Toast.makeText(this, text, Toast.LENGTH_LONG).apply { show() }
|
||||
|
||||
fun Context.toast(@StringRes resId: Int): Toast =
|
||||
Toast.makeText(this, resId, Toast.LENGTH_SHORT).apply { show() }
|
||||
|
||||
fun Context.longToast(@StringRes resId: Int): Toast =
|
||||
Toast.makeText(this, resId, Toast.LENGTH_LONG).apply { show() }
|
||||
81
app/src/main/java/com/aurora/extensions/View.kt
Normal file
81
app/src/main/java/com/aurora/extensions/View.kt
Normal file
@@ -0,0 +1,81 @@
|
||||
/*
|
||||
* Aurora Store
|
||||
* Copyright (C) 2021, Rahul Kumar Patel <whyorean@gmail.com>
|
||||
*
|
||||
* Aurora Store is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Aurora Store is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Aurora Store. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
package com.aurora.extensions
|
||||
|
||||
import android.content.Context
|
||||
import android.view.View
|
||||
import android.view.inputmethod.InputMethodManager
|
||||
|
||||
fun View.isVisible() = visibility == View.VISIBLE
|
||||
|
||||
fun View.isGone() = visibility == View.GONE
|
||||
|
||||
fun View.isInvisible() = visibility == View.INVISIBLE
|
||||
|
||||
fun View.show() {
|
||||
visibility = View.VISIBLE
|
||||
}
|
||||
|
||||
fun View.hide() {
|
||||
visibility = View.GONE
|
||||
}
|
||||
|
||||
fun View.showKeyboard() {
|
||||
val imm = context.getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager
|
||||
this.requestFocus()
|
||||
imm.showSoftInput(this, 0)
|
||||
}
|
||||
|
||||
fun View.hideKeyboard(): Boolean {
|
||||
try {
|
||||
val imm = context.getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager
|
||||
return imm.hideSoftInputFromWindow(windowToken, 0)
|
||||
} catch (ignored: RuntimeException) {
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
fun View.setOnSingleClickListener(tolerance: Long = 500, onClick: (v: View) -> Unit) {
|
||||
var lastClicked = 0L
|
||||
val currentTimeMillis = System.currentTimeMillis()
|
||||
setOnClickListener {
|
||||
if (currentTimeMillis - lastClicked > tolerance) {
|
||||
onClick(it)
|
||||
lastClicked = currentTimeMillis
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun View.rotate(resetToZero: Boolean = true, duration: Long = 400) {
|
||||
if (resetToZero)
|
||||
rotation = 0f
|
||||
animate().rotation(360f).setDuration(duration).start()
|
||||
}
|
||||
|
||||
fun View.flip(resetToZero: Boolean = true, duration: Long = 400) {
|
||||
if (resetToZero)
|
||||
rotation = 0f
|
||||
animate().rotation(180f).setDuration(duration).start()
|
||||
}
|
||||
|
||||
fun View.getString(resourceId: Int): String {
|
||||
return context.getString(resourceId)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user