Skip to content

Commit

Permalink
fix broken TCL and cosmetics
Browse files Browse the repository at this point in the history
  • Loading branch information
tsynik committed Jan 11, 2024
1 parent b3d689a commit 1785ecb
Show file tree
Hide file tree
Showing 8 changed files with 58 additions and 32 deletions.
13 changes: 9 additions & 4 deletions app/src/main/java/ru/yourok/torrserve/ad/ADManager.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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.*
Expand All @@ -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
}
Expand Down Expand Up @@ -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())
}
Expand Down
25 changes: 18 additions & 7 deletions app/src/main/java/ru/yourok/torrserve/atv/Utils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -85,7 +96,7 @@ object Utils {
private var lock = Any()
fun updateAtvCards() {

if (isGoogleTV()) {
if (isGoogleTV) {
synchronized(lock) {
if (lock == true)
return
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ object UpdaterCards {

fun updateCards() {
thread {
if (!Utils.isGoogleTV())
if (!Utils.isGoogleTV)
return@thread

synchronized(lock) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,20 @@ class DirectoryAdapter : RecyclerView.Adapter<DirectoryAdapter.ViewHolder>() {

@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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
23 changes: 14 additions & 9 deletions app/src/main/java/ru/yourok/torrserve/utils/Net.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -55,18 +56,19 @@ 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 {
val conn = Jsoup.connect(url)
.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())
Expand All @@ -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())
Expand Down Expand Up @@ -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 -> {
Expand Down

0 comments on commit 1785ecb

Please sign in to comment.