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 aba0f031..b20b514d 100644 --- a/app/src/main/java/ru/yourok/torrserve/ad/ADManager.kt +++ b/app/src/main/java/ru/yourok/torrserve/ad/ADManager.kt @@ -5,6 +5,7 @@ import com.google.gson.Gson import org.jsoup.Jsoup import ru.yourok.torrserve.ad.model.ADData import ru.yourok.torrserve.app.Consts +import ru.yourok.torrserve.atv.Utils import ru.yourok.torrserve.utils.Net import java.text.SimpleDateFormat import java.util.* @@ -17,7 +18,7 @@ object ADManager { fun expired(): Boolean { get()?.let { if (it.expired != "0") { - val formatter = SimpleDateFormat("dd.MM.yyyy") + val formatter = SimpleDateFormat("dd.MM.yyyy", Locale.US) val date = formatter.parse(it.expired) as Date return System.currentTimeMillis() > date.time } @@ -49,20 +50,24 @@ object ADManager { } HttpsURLConnection.setDefaultHostnameVerifier(trustAllHostnames) } - val response = Jsoup.connect(url) + val conn = Jsoup.connect(url) .ignoreHttpErrors(true) .ignoreContentType(true) - .sslSocketFactory(Net.insecureTlsSocketFactory()) .timeout(3000) - .execute() + if (!Utils.isBrokenTCL) + conn.sslSocketFactory(Net.insecureTlsSocketFactory()) + + val response = conn.execute() return when (response.statusCode()) { 200 -> { response.body() } + 302 -> { "" } + else -> { throw Exception(response.statusMessage()) } diff --git a/app/src/main/java/ru/yourok/torrserve/atv/Utils.kt b/app/src/main/java/ru/yourok/torrserve/atv/Utils.kt index b0b3e41f..d710cf46 100644 --- a/app/src/main/java/ru/yourok/torrserve/atv/Utils.kt +++ b/app/src/main/java/ru/yourok/torrserve/atv/Utils.kt @@ -60,13 +60,24 @@ object Utils { return intent.resolveActivity(pm!!) != null } - fun isGoogleTV(): Boolean { - return App.context.packageManager.hasSystemFeature("android.software.leanback") && Build.VERSION.SDK_INT >= Build.VERSION_CODES.O - } + val isGoogleTV: Boolean + get() { + return App.context.packageManager.hasSystemFeature("android.software.leanback") && Build.VERSION.SDK_INT >= Build.VERSION_CODES.O + } - fun isAmazonTV(): Boolean { - return App.context.packageManager.hasSystemFeature(FEATURE_FIRE_TV) - } + val isAmazonTV: Boolean + get() { + return App.context.packageManager.hasSystemFeature(FEATURE_FIRE_TV) + } + + private val deviceName: String + get() = String.format("%s (%s)", Build.MODEL, Build.PRODUCT) + + val isBrokenTCL: Boolean + get() { + val deviceName = deviceName + return deviceName.contains("(tcl_m7642)") + } fun buildPendingIntent(torr: Torrent): Intent { val vintent = Intent(App.context, PlayActivity::class.java) @@ -85,7 +96,7 @@ object Utils { private var lock = Any() fun updateAtvCards() { - if (isGoogleTV()) { + if (isGoogleTV) { synchronized(lock) { if (lock == true) return diff --git a/app/src/main/java/ru/yourok/torrserve/atv/channels/UpdaterCards.kt b/app/src/main/java/ru/yourok/torrserve/atv/channels/UpdaterCards.kt index aaf45a81..8aef37c1 100644 --- a/app/src/main/java/ru/yourok/torrserve/atv/channels/UpdaterCards.kt +++ b/app/src/main/java/ru/yourok/torrserve/atv/channels/UpdaterCards.kt @@ -10,7 +10,7 @@ object UpdaterCards { fun updateCards() { thread { - if (!Utils.isGoogleTV()) + if (!Utils.isGoogleTV) return@thread synchronized(lock) { diff --git a/app/src/main/java/ru/yourok/torrserve/server/local/services/HomeWatch.kt b/app/src/main/java/ru/yourok/torrserve/server/local/services/HomeWatch.kt index 3fe169d1..d14bbdaa 100644 --- a/app/src/main/java/ru/yourok/torrserve/server/local/services/HomeWatch.kt +++ b/app/src/main/java/ru/yourok/torrserve/server/local/services/HomeWatch.kt @@ -23,7 +23,7 @@ import ru.yourok.torrserve.server.api.Api class HomeWatch : BroadcastReceiver() { override fun onReceive(context: Context, intent: Intent) { val action = intent.action - if (action == null || !Utils.isGoogleTV()) return + if (action == null || !Utils.isGoogleTV) return val previewProgramId = intent.getLongExtra(TvContractCompat.EXTRA_PREVIEW_PROGRAM_ID, -1L) val watchNextInternalId = intent.getLongExtra(TvContractCompat.EXTRA_WATCH_NEXT_PROGRAM_ID, -1L) diff --git a/app/src/main/java/ru/yourok/torrserve/server/local/services/Notification.kt b/app/src/main/java/ru/yourok/torrserve/server/local/services/Notification.kt index 995d3ef3..065ed3b1 100644 --- a/app/src/main/java/ru/yourok/torrserve/server/local/services/Notification.kt +++ b/app/src/main/java/ru/yourok/torrserve/server/local/services/Notification.kt @@ -98,7 +98,7 @@ class Notification : Service() { else builder?.setStyle(NotificationCompat.BigTextStyle().bigText("")) - if (Utils.isAmazonTV()) + if (Utils.isAmazonTV) builder?.setLargeIcon(BitmapFactory.decodeResource(resources, R.drawable.ic_notification)) builder?.let { diff --git a/app/src/main/java/ru/yourok/torrserve/ui/dialogs/DirectoryAdapter.kt b/app/src/main/java/ru/yourok/torrserve/ui/dialogs/DirectoryAdapter.kt index f66dd66b..d49f9197 100644 --- a/app/src/main/java/ru/yourok/torrserve/ui/dialogs/DirectoryAdapter.kt +++ b/app/src/main/java/ru/yourok/torrserve/ui/dialogs/DirectoryAdapter.kt @@ -37,15 +37,20 @@ class DirectoryAdapter : RecyclerView.Adapter() { @Suppress("DEPRECATION") fun getSize(): String { - val stat = StatFs(path) - val bytesAvailable = if (Build.VERSION.SDK_INT >= - Build.VERSION_CODES.JELLY_BEAN_MR2 - ) { - stat.blockSizeLong * stat.availableBlocksLong - } else { - stat.blockSize.toLong() * stat.availableBlocks.toLong() + val size = try { + val stat = StatFs(path) + val bytesAvailable = if (Build.VERSION.SDK_INT >= + Build.VERSION_CODES.JELLY_BEAN_MR2 + ) { + stat.blockSizeLong * stat.availableBlocksLong + } else { + stat.blockSize.toLong() * stat.availableBlocks.toLong() + } + Format.byteFmt(bytesAvailable) + } catch (_: Exception) { + "N/A" } - return Format.byteFmt(bytesAvailable) + return size } fun dirUp() { diff --git a/app/src/main/java/ru/yourok/torrserve/ui/fragments/main/settings/SettingsFragment.kt b/app/src/main/java/ru/yourok/torrserve/ui/fragments/main/settings/SettingsFragment.kt index 46032c1b..bc053c5f 100644 --- a/app/src/main/java/ru/yourok/torrserve/ui/fragments/main/settings/SettingsFragment.kt +++ b/app/src/main/java/ru/yourok/torrserve/ui/fragments/main/settings/SettingsFragment.kt @@ -160,7 +160,7 @@ class SettingsFragment : PreferenceFragmentCompat() { setOnPreferenceClickListener { //showPowerRequest(context) try { - if (Utils.isGoogleTV()) { // open Power Settings + if (Utils.isGoogleTV) { // open Power Settings if (Accessibility.isPackageInstalled(context, "com.android.settings")) { intent.`package` = "com.android.settings" requireActivity().startActivity(intent) diff --git a/app/src/main/java/ru/yourok/torrserve/utils/Net.kt b/app/src/main/java/ru/yourok/torrserve/utils/Net.kt index 2b1b4c56..b0b59963 100644 --- a/app/src/main/java/ru/yourok/torrserve/utils/Net.kt +++ b/app/src/main/java/ru/yourok/torrserve/utils/Net.kt @@ -5,6 +5,7 @@ import android.net.Uri import info.guardianproject.netcipher.client.TlsOnlySocketFactory import org.jsoup.Connection import org.jsoup.Jsoup +import ru.yourok.torrserve.atv.Utils.isBrokenTCL import ru.yourok.torrserve.settings.Settings import java.io.InputStream import java.net.Inet4Address @@ -42,9 +43,9 @@ object Net { .data("file1", "filename", file) .ignoreHttpErrors(true) .ignoreContentType(true) - .sslSocketFactory(insecureTlsSocketFactory()) .method(Connection.Method.POST) - + if (!isBrokenTCL) + req.sslSocketFactory(insecureTlsSocketFactory()) if (save) req.data("save", "true") req.data("title", title) @@ -55,8 +56,8 @@ object Net { if (auth.isNotEmpty()) req.header("Authorization", auth) - val resp = req.execute() - return resp.body() + val response = req.execute() + return response.body() } fun postAuth(url: String, req: String): String { @@ -64,9 +65,10 @@ object Net { .requestBody(req) .ignoreHttpErrors(true) .ignoreContentType(true) - .sslSocketFactory(insecureTlsSocketFactory()) .method(Connection.Method.POST) .maxBodySize(0) // The default maximum is 2MB, 0 = unlimited body + if (!isBrokenTCL) + conn.sslSocketFactory(insecureTlsSocketFactory()) val auth = getAuthB64() if (auth.isNotEmpty()) @@ -93,8 +95,9 @@ object Net { val conn = Jsoup.connect(url) .ignoreHttpErrors(true) .ignoreContentType(true) - .sslSocketFactory(insecureTlsSocketFactory()) .timeout(duration) + if (!isBrokenTCL) + conn.sslSocketFactory(insecureTlsSocketFactory()) val auth = getAuthB64() if (auth.isNotEmpty()) @@ -125,12 +128,14 @@ object Net { } HttpsURLConnection.setDefaultHostnameVerifier(trustAllHostnames) } - val response = Jsoup.connect(url) + val conn = Jsoup.connect(url) .ignoreHttpErrors(true) .ignoreContentType(true) - .sslSocketFactory(insecureTlsSocketFactory()) .timeout(duration) - .execute() + if (!isBrokenTCL) + conn.sslSocketFactory(insecureTlsSocketFactory()) + + val response = conn.execute() return when (response.statusCode()) { 200 -> {