From e134d857cd1b1f0c89e79a232d20e042fdbb0ed5 Mon Sep 17 00:00:00 2001 From: nikk gitanes Date: Sat, 27 Apr 2024 03:37:48 +0300 Subject: [PATCH] cosmetics --- .../main/java/ru/yourok/torrserve/ad/AD.kt | 3 +-- .../java/ru/yourok/torrserve/ad/ADManager.kt | 2 +- .../main/java/ru/yourok/torrserve/app/App.kt | 19 ++++++++++--------- .../java/ru/yourok/torrserve/app/AppToast.kt | 4 ++-- .../ru/yourok/torrserve/app/AppToastView.kt | 10 +++++----- .../java/ru/yourok/torrserve/app/Consts.kt | 8 ++++---- .../torrserve/ui/activities/play/Helper.kt | 2 +- .../torrserve/ui/activities/play/Play.kt | 2 +- .../ui/activities/play/PlayActivity.kt | 4 ++-- .../ui/fragments/donate/DonateFragment.kt | 4 ++-- .../fragments/main/update/apk/UpdaterApk.kt | 2 +- .../main/update/server/UpdaterServer.kt | 2 +- .../yourok/torrserve/utils/Accessibility.kt | 4 ++-- 13 files changed, 33 insertions(+), 33 deletions(-) diff --git a/app/src/main/java/ru/yourok/torrserve/ad/AD.kt b/app/src/main/java/ru/yourok/torrserve/ad/AD.kt index 34f349ce..f2b00de3 100644 --- a/app/src/main/java/ru/yourok/torrserve/ad/AD.kt +++ b/app/src/main/java/ru/yourok/torrserve/ad/AD.kt @@ -12,7 +12,6 @@ import kotlinx.coroutines.* import ru.yourok.torrserve.ad.model.Image import ru.yourok.torrserve.app.Consts import ru.yourok.torrserve.settings.Settings -import java.util.* class AD(private val iv: ImageView, private val activity: AppCompatActivity) { private val lock = Any() @@ -86,7 +85,7 @@ class AD(private val iv: ImageView, private val activity: AppCompatActivity) { private fun loadImg(linkImg: String) { var link = linkImg if (!link.startsWith("http")) - link = Consts.ad_link + link + link = Consts.AD_LINK + link Glide.with(activity) .asBitmap() diff --git a/app/src/main/java/ru/yourok/torrserve/ad/ADManager.kt b/app/src/main/java/ru/yourok/torrserve/ad/ADManager.kt index e7a1a357..8947303d 100644 --- a/app/src/main/java/ru/yourok/torrserve/ad/ADManager.kt +++ b/app/src/main/java/ru/yourok/torrserve/ad/ADManager.kt @@ -27,7 +27,7 @@ object ADManager { return it } try { - val link = Consts.ad_link + "/ad.json" + val link = Consts.AD_LINK + "/ad.json" val buf = Net.get(link) val data = Gson().fromJson(buf, ADData::class.java) addata = data diff --git a/app/src/main/java/ru/yourok/torrserve/app/App.kt b/app/src/main/java/ru/yourok/torrserve/app/App.kt index 2114f52b..c9016dd1 100644 --- a/app/src/main/java/ru/yourok/torrserve/app/App.kt +++ b/app/src/main/java/ru/yourok/torrserve/app/App.kt @@ -27,8 +27,8 @@ class App : MultiDexApplication() { private var instance: App? = null private lateinit var appContext: Context var inForeground: Boolean = false - const val shortToastDuration: Int = 1200 - const val longToastDuration: Int = 3000 + const val SHORT_TOAST_DURATION: Int = 1200 + const val LONG_TOAST_DURATION: Int = 3000 private lateinit var wakeLock: PowerManager.WakeLock val context: Context @@ -44,17 +44,18 @@ class App : MultiDexApplication() { } } - fun currentActivity(): Activity? { - return instance?.mActivityLifecycleCallbacks?.currentActivity - } + val currentActivity: Activity? + get() { + return instance?.mActivityLifecycleCallbacks?.currentActivity + } @SuppressLint("RestrictedApi") fun toast(txt: String, long: Boolean = false) { Handler(Looper.getMainLooper()).post { - val dur = if (long) longToastDuration else shortToastDuration + val dur = if (long) LONG_TOAST_DURATION else SHORT_TOAST_DURATION // this view overlap the system navigation bar, better use android.R.id.content //val view = currentActivity()?.window?.decorView?.rootView ?: return@post - val view: View = currentActivity()?.findViewById(android.R.id.content) ?: return@post + val view: View = currentActivity?.findViewById(android.R.id.content) ?: return@post AppToast .make(view as ViewGroup, txt) .setDuration(dur) @@ -65,10 +66,10 @@ class App : MultiDexApplication() { @SuppressLint("RestrictedApi") fun toast(txt: Int, long: Boolean = false) { Handler(Looper.getMainLooper()).post { - val dur = if (long) longToastDuration else shortToastDuration + val dur = if (long) LONG_TOAST_DURATION else SHORT_TOAST_DURATION // this view overlap the system navigation bar, better use android.R.id.content //val view = currentActivity()?.window?.decorView?.rootView ?: return@post - val view: View = currentActivity()?.findViewById(android.R.id.content) ?: return@post + val view: View = currentActivity?.findViewById(android.R.id.content) ?: return@post AppToast .make(view as ViewGroup, context.getString(txt)) .setDuration(dur) diff --git a/app/src/main/java/ru/yourok/torrserve/app/AppToast.kt b/app/src/main/java/ru/yourok/torrserve/app/AppToast.kt index 8d5db2c6..baecfdb3 100644 --- a/app/src/main/java/ru/yourok/torrserve/app/AppToast.kt +++ b/app/src/main/java/ru/yourok/torrserve/app/AppToast.kt @@ -27,8 +27,8 @@ class AppToast( val padding = Format.dp2px(10f) getView().setPadding(padding, padding, padding, padding) - val width = App.currentActivity()?.window?.decorView?.rootView?.width ?: 0 - val height = App.currentActivity()?.window?.decorView?.rootView?.height ?: 0 + val width = App.currentActivity?.window?.decorView?.rootView?.width ?: 0 + val height = App.currentActivity?.window?.decorView?.rootView?.height ?: 0 var hmargin = Format.dp2px(12f) if (width > height) // landscape hmargin = width / 6 diff --git a/app/src/main/java/ru/yourok/torrserve/app/AppToastView.kt b/app/src/main/java/ru/yourok/torrserve/app/AppToastView.kt index c18cfe61..7010e01b 100644 --- a/app/src/main/java/ru/yourok/torrserve/app/AppToastView.kt +++ b/app/src/main/java/ru/yourok/torrserve/app/AppToastView.kt @@ -24,17 +24,17 @@ class AppToastView @JvmOverloads constructor( content.alpha = 0f content.animate().apply { alpha(1.0f) - setDuration(animateInDuration) + setDuration(ANIM_IN_DURATION) startDelay = delay.toLong() } val logo = content.findViewById(R.id.ivLogo) - breathFadeAnimation(logo, App.longToastDuration.toLong()) + breathFadeAnimation(logo, App.LONG_TOAST_DURATION.toLong()) } override fun animateContentOut(delay: Int, duration: Int) { content.animate().apply { alpha(0f) - setDuration(animateOutDuration) + setDuration(ANIM_OUT_DURATION) startDelay = delay.toLong() } @@ -73,7 +73,7 @@ class AppToastView @JvmOverloads constructor( companion object { - private const val animateInDuration = 500L - private const val animateOutDuration = 150L + private const val ANIM_IN_DURATION = 500L + private const val ANIM_OUT_DURATION = 150L } } \ No newline at end of file diff --git a/app/src/main/java/ru/yourok/torrserve/app/Consts.kt b/app/src/main/java/ru/yourok/torrserve/app/Consts.kt index 613b7031..29c2aa0e 100644 --- a/app/src/main/java/ru/yourok/torrserve/app/Consts.kt +++ b/app/src/main/java/ru/yourok/torrserve/app/Consts.kt @@ -1,10 +1,10 @@ package ru.yourok.torrserve.app object Consts { - private const val releaseHost = "https://releases.yourok.ru/torr" - const val ad_link = "$releaseHost/ad" - const val updateApkPath = "$releaseHost/apk_release.json" - const val updateServerPath = "$releaseHost/server_release.json" + private const val REL_HOST = "https://releases.yourok.ru/torr" + const val AD_LINK = "$REL_HOST/ad" + const val UPDATE_APK_PATH = "$REL_HOST/apk_release.json" + const val UPDATE_SERVER_PATH = "$REL_HOST/server_release.json" val excludedApps = hashSetOf( "com.android.gallery3d", "com.android.tv.frameworkpackagestubs", diff --git a/app/src/main/java/ru/yourok/torrserve/ui/activities/play/Helper.kt b/app/src/main/java/ru/yourok/torrserve/ui/activities/play/Helper.kt index 92cad272..3f46b52b 100644 --- a/app/src/main/java/ru/yourok/torrserve/ui/activities/play/Helper.kt +++ b/app/src/main/java/ru/yourok/torrserve/ui/activities/play/Helper.kt @@ -51,7 +51,7 @@ fun PlayActivity.error(err: ReturnError) { ret.putExtra("errMessage", err.errMessage) setResult(AppCompatActivity.RESULT_CANCELED, ret) App.toast(err.errMessage, true) - delay(App.longToastDuration.toLong()) // as in toast duration + delay(App.LONG_TOAST_DURATION.toLong()) // as in toast duration if (err != ErrTorrServerNotResponding) finish() } diff --git a/app/src/main/java/ru/yourok/torrserve/ui/activities/play/Play.kt b/app/src/main/java/ru/yourok/torrserve/ui/activities/play/Play.kt index dd17926e..2520e0d2 100644 --- a/app/src/main/java/ru/yourok/torrserve/ui/activities/play/Play.kt +++ b/app/src/main/java/ru/yourok/torrserve/ui/activities/play/Play.kt @@ -40,7 +40,7 @@ object Play { } } catch (e: Exception) { e.message?.let { App.toast(it, true) } - delay(App.longToastDuration.toLong()) + delay(App.LONG_TOAST_DURATION.toLong()) return@launch } diff --git a/app/src/main/java/ru/yourok/torrserve/ui/activities/play/PlayActivity.kt b/app/src/main/java/ru/yourok/torrserve/ui/activities/play/PlayActivity.kt index 9037c9eb..2537b842 100644 --- a/app/src/main/java/ru/yourok/torrserve/ui/activities/play/PlayActivity.kt +++ b/app/src/main/java/ru/yourok/torrserve/ui/activities/play/PlayActivity.kt @@ -93,7 +93,7 @@ class PlayActivity : AppCompatActivity() { lifecycleScope.launch(Dispatchers.IO) { if (!TorrService.wait(5)) { error(ErrTorrServerNotResponding) - delay(App.longToastDuration.toLong()) + delay(App.LONG_TOAST_DURATION.toLong()) if (TorrService.isLocal() && !TorrService.isInstalled()) { withContext(Dispatchers.Main) { findViewById(R.id.info_title)?.setText(R.string.install_server) @@ -111,7 +111,7 @@ class PlayActivity : AppCompatActivity() { } else { //server is not local, change ServerFinderFragment().apply { - show(App.currentActivity() as? FragmentActivity?, R.id.bottom_container, true) + show(App.currentActivity as? FragmentActivity?, R.id.bottom_container, true) onResult = { withContext(Dispatchers.Main) { processIntent() diff --git a/app/src/main/java/ru/yourok/torrserve/ui/fragments/donate/DonateFragment.kt b/app/src/main/java/ru/yourok/torrserve/ui/fragments/donate/DonateFragment.kt index e6d22663..b489f354 100644 --- a/app/src/main/java/ru/yourok/torrserve/ui/fragments/donate/DonateFragment.kt +++ b/app/src/main/java/ru/yourok/torrserve/ui/fragments/donate/DonateFragment.kt @@ -137,8 +137,8 @@ object DonateMessage { textView?.textSize = 18.0f textView?.setTextColor(ContextCompat.getColor(App.context, tc)) val layoutParams = snackbarLayout?.layoutParams as ViewGroup.MarginLayoutParams - val width = App.currentActivity()?.window?.decorView?.rootView?.width ?: 0 - val height = App.currentActivity()?.window?.decorView?.rootView?.height ?: 0 + val width = App.currentActivity?.window?.decorView?.rootView?.width ?: 0 + val height = App.currentActivity?.window?.decorView?.rootView?.height ?: 0 var hmargin = Format.dp2px(12f) if (width > height) // landscape hmargin = width / 6 diff --git a/app/src/main/java/ru/yourok/torrserve/ui/fragments/main/update/apk/UpdaterApk.kt b/app/src/main/java/ru/yourok/torrserve/ui/fragments/main/update/apk/UpdaterApk.kt index 8be92614..8c939e28 100644 --- a/app/src/main/java/ru/yourok/torrserve/ui/fragments/main/update/apk/UpdaterApk.kt +++ b/app/src/main/java/ru/yourok/torrserve/ui/fragments/main/update/apk/UpdaterApk.kt @@ -22,7 +22,7 @@ object UpdaterApk { fun check(): Boolean { try { - val body = Net.get(Consts.updateApkPath) + val body = Net.get(Consts.UPDATE_APK_PATH) val gson = Gson() versions = gson.fromJson(body, ApkVersions::class.java) versions?.let { diff --git a/app/src/main/java/ru/yourok/torrserve/ui/fragments/main/update/server/UpdaterServer.kt b/app/src/main/java/ru/yourok/torrserve/ui/fragments/main/update/server/UpdaterServer.kt index 5ca15770..4478e8f3 100644 --- a/app/src/main/java/ru/yourok/torrserve/ui/fragments/main/update/server/UpdaterServer.kt +++ b/app/src/main/java/ru/yourok/torrserve/ui/fragments/main/update/server/UpdaterServer.kt @@ -136,7 +136,7 @@ object UpdaterServer { fun check(): Boolean { return try { - val body = Net.get(Consts.updateServerPath) + val body = Net.get(Consts.UPDATE_SERVER_PATH) val gson = Gson() version = gson.fromJson(body, ServVersion::class.java) true diff --git a/app/src/main/java/ru/yourok/torrserve/utils/Accessibility.kt b/app/src/main/java/ru/yourok/torrserve/utils/Accessibility.kt index 75e7c131..82945969 100644 --- a/app/src/main/java/ru/yourok/torrserve/utils/Accessibility.kt +++ b/app/src/main/java/ru/yourok/torrserve/utils/Accessibility.kt @@ -92,7 +92,7 @@ object Accessibility { e.message?.let { App.toast(it) } Handler(Looper.getMainLooper()).postDelayed({ showAccessibilitySettings(requireContext) - }, App.shortToastDuration.toLong()) // as in toast duration + }, App.SHORT_TOAST_DURATION.toLong()) // as in toast duration } } else { val appName = App.context.getString(R.string.app_name) @@ -102,7 +102,7 @@ object Accessibility { App.toast(App.context.getString(R.string.accessibility_manual_off, appName), true) Handler(Looper.getMainLooper()).postDelayed({ showAccessibilitySettings(requireContext) - }, App.longToastDuration.toLong()) // as in toast duration + }, App.LONG_TOAST_DURATION.toLong()) // as in toast duration } }