Skip to content

Commit

Permalink
cosmetics
Browse files Browse the repository at this point in the history
  • Loading branch information
tsynik committed Apr 27, 2024
1 parent a071da6 commit e134d85
Show file tree
Hide file tree
Showing 13 changed files with 33 additions and 33 deletions.
3 changes: 1 addition & 2 deletions app/src/main/java/ru/yourok/torrserve/ad/AD.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/java/ru/yourok/torrserve/ad/ADManager.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
19 changes: 10 additions & 9 deletions app/src/main/java/ru/yourok/torrserve/app/App.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand All @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/java/ru/yourok/torrserve/app/AppToast.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 5 additions & 5 deletions app/src/main/java/ru/yourok/torrserve/app/AppToastView.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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<ImageView?>(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()
}

Expand Down Expand Up @@ -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
}
}
8 changes: 4 additions & 4 deletions app/src/main/java/ru/yourok/torrserve/app/Consts.kt
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<TextView>(R.id.info_title)?.setText(R.string.install_server)
Expand All @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/java/ru/yourok/torrserve/utils/Accessibility.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
}
}

Expand Down

0 comments on commit e134d85

Please sign in to comment.