Skip to content

Commit

Permalink
fix crash
Browse files Browse the repository at this point in the history
  • Loading branch information
lizongying committed May 14, 2024
1 parent 8cefa9a commit 31330f2
Show file tree
Hide file tree
Showing 23 changed files with 74 additions and 66 deletions.
5 changes: 4 additions & 1 deletion HISTORY.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@

### v1.2.0

* 修复网络地址获取错误的问题
* 修复部分设备网络地址获取错误的问题
* 恢复默认的时候会清除收藏
* 修复一些崩溃问题
* 手机支持收藏功能

### v1.1.9

Expand Down
2 changes: 0 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,6 @@ adb install my-tv-0.apk
* 插件商城
* UI
* 视频解码
* 频道更新时删除收藏
* 手机上的收藏功能

## 赞赏

Expand Down
34 changes: 24 additions & 10 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ android {
targetSdk = 34
versionCode = getVersionCode()
versionName = getVersionName()
multiDexEnabled = true
}

buildFeatures {
Expand All @@ -31,6 +32,11 @@ android {
}
}
compileOptions {
// Flag to enable support for the new language APIs

// For AGP 4.1+
isCoreLibraryDesugaringEnabled = true

sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}
Expand All @@ -49,23 +55,29 @@ fun getVersionCode(): Int {
arr[0].toInt() * 16777216 + arr[1].toInt() * 65536 + arr[2].toInt() * 256 + arr[3].toInt()
versionCode
} catch (ignored: Exception) {
0
1
}
}

fun getVersionName(): String {
return try {
val process = Runtime.getRuntime().exec("git describe --tags --always")
process.waitFor()
process.inputStream.bufferedReader().use(BufferedReader::readText).trim().removePrefix("v")
val versionName = process.inputStream.bufferedReader().use(BufferedReader::readText).trim().removePrefix("v")
versionName.ifEmpty {
"1.0.0"
}
} catch (ignored: Exception) {
"1.0.0"
}
}

dependencies {
// 19
val media3Version = "1.3.0"
// For AGP 7.4+
coreLibraryDesugaring("com.android.tools:desugar_jdk_libs:2.0.4")

// 19 java8
val media3Version = "1.3.1"
implementation("androidx.media3:media3-ui:$media3Version")

// For media playback using ExoPlayer
Expand All @@ -75,14 +87,16 @@ dependencies {
implementation("androidx.media3:media3-exoplayer-dash:$media3Version")
implementation("androidx.media3:media3-exoplayer-rtsp:$media3Version")

implementation("androidx.core:core-ktx:1.12.0")
implementation("androidx.leanback:leanback:1.0.0")
implementation("com.github.bumptech.glide:glide:4.11.0")
implementation("androidx.core:core-ktx:1.13.1")
implementation("androidx.multidex:multidex:2.0.1")
implementation("androidx.recyclerview:recyclerview:1.3.2")

//java7
implementation("com.github.bumptech.glide:glide:4.16.0")

// 21:2.11.0 17:2.6.4
val retrofit2Version = "2.11.0"
implementation("com.squareup.retrofit2:converter-gson:$retrofit2Version")
implementation ("com.squareup.retrofit2:converter-protobuf:$retrofit2Version")
implementation ("com.squareup.retrofit2:retrofit:$retrofit2Version")

// For yunos
Expand All @@ -92,11 +106,11 @@ dependencies {
implementation("com.google.android.exoplayer:exoplayer-hls:$exoplayerVersion")

implementation("androidx.constraintlayout:constraintlayout:2.1.4")
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-android:1.8.0-RC")
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-android:1.8.1")

implementation(files("libs/lib-decoder-ffmpeg-release.aar"))

implementation("io.github.lizongying:gua64:1.4.3")
implementation("io.github.lizongying:gua64:1.4.4")

implementation("org.nanohttpd:nanohttpd:2.3.1")

Expand Down
3 changes: 1 addition & 2 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android">

<application
android:name=".MyTvApplication"
android:name=".MyTVApplication"
android:allowBackup="true"
android:banner="@drawable/banner0"
android:icon="@drawable/logo0"
Expand All @@ -11,7 +11,6 @@
android:logo="@drawable/logo0"
android:networkSecurityConfig="@xml/network"
android:supportsRtl="true"
android:theme="@style/Theme.MyTV0"
android:usesCleartextTraffic="true">
<activity
android:name=".MainActivity"
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/java/com/lizongying/mytv0/ChannelFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class ChannelFragment : Fragment() {
_binding = ChannelBinding.inflate(inflater, container, false)
_binding!!.root.visibility = View.GONE

val application = requireActivity().applicationContext as MyTvApplication
val application = requireActivity().applicationContext as MyTVApplication

binding.channel.layoutParams.width = application.px2Px(binding.channel.layoutParams.width)
binding.channel.layoutParams.height = application.px2Px(binding.channel.layoutParams.height)
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/java/com/lizongying/mytv0/ErrorFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class ErrorFragment : Fragment() {
): View {
_binding = ErrorBinding.inflate(inflater, container, false)

val application = requireActivity().applicationContext as MyTvApplication
val application = requireActivity().applicationContext as MyTVApplication

binding.logo.layoutParams.width = application.px2Px(binding.logo.layoutParams.width)
binding.logo.layoutParams.height = application.px2Px(binding.logo.layoutParams.height)
Expand Down
5 changes: 5 additions & 0 deletions app/src/main/java/com/lizongying/mytv0/Ext.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import android.content.pm.Signature
import android.content.pm.SigningInfo
import android.os.Build
import android.util.Log
import android.widget.Toast
import java.security.MessageDigest

private const val TAG = "Extensions"
Expand Down Expand Up @@ -81,4 +82,8 @@ private fun hashSignature(signature: Signature): String {
Log.e(TAG, "Error hashing signature", e)
""
}
}

fun String.showToast(duration: Int = Toast.LENGTH_SHORT) {
MyTVApplication.getInstance().toast(this, duration)
}
2 changes: 1 addition & 1 deletion app/src/main/java/com/lizongying/mytv0/GroupAdapter.kt
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class GroupAdapter(

var visiable = false

val application = context.applicationContext as MyTvApplication
val application = context.applicationContext as MyTVApplication

override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
val inflater = LayoutInflater.from(context)
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/java/com/lizongying/mytv0/InfoFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class InfoFragment : Fragment() {
_binding = InfoBinding.inflate(inflater, container, false)


val application = requireActivity().applicationContext as MyTvApplication
val application = requireActivity().applicationContext as MyTVApplication

binding.info.layoutParams.width = application.px2Px(binding.info.layoutParams.width)
binding.info.layoutParams.height = application.px2Px(binding.info.layoutParams.height)
Expand Down
9 changes: 7 additions & 2 deletions app/src/main/java/com/lizongying/mytv0/ListAdapter.kt
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class ListAdapter(

var visiable = false

val application = context.applicationContext as MyTvApplication
val application = context.applicationContext as MyTVApplication

override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
val inflater = LayoutInflater.from(context)
Expand Down Expand Up @@ -96,6 +96,11 @@ class ListAdapter(

viewHolder.like(tvModel.like.value as Boolean)

viewHolder.binding.heart.setOnClickListener {
tvModel.setLike(!(tvModel.like.value as Boolean))
viewHolder.like(tvModel.like.value as Boolean)
}

if (!defaultFocused && position == defaultFocus) {
view.requestFocus()
defaultFocused = true
Expand Down Expand Up @@ -174,7 +179,7 @@ class ListAdapter(

override fun getItemCount() = tvListModel.size()

class ViewHolder(private val context: Context, private val binding: ListItemBinding) :
class ViewHolder(private val context: Context, val binding: ListItemBinding) :
RecyclerView.ViewHolder(binding.root) {
fun bindTitle(text: String) {
binding.title.text = text
Expand Down
14 changes: 0 additions & 14 deletions app/src/main/java/com/lizongying/mytv0/LiveDataExtensions.kt

This file was deleted.

2 changes: 1 addition & 1 deletion app/src/main/java/com/lizongying/mytv0/LoadingFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class LoadingFragment : Fragment() {
): View {
_binding = LoadingBinding.inflate(inflater, container, false)

val application = requireActivity().applicationContext as MyTvApplication
val application = requireActivity().applicationContext as MyTVApplication

binding.bar.layoutParams.width = application.px2Px(binding.bar.layoutParams.width)
binding.bar.layoutParams.height = application.px2Px(binding.bar.layoutParams.height)
Expand Down
6 changes: 3 additions & 3 deletions app/src/main/java/com/lizongying/mytv0/ModalFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ import android.view.ViewGroup
import android.view.WindowManager
import androidx.fragment.app.DialogFragment
import com.bumptech.glide.Glide
import com.lizongying.mytv0.databinding.AppreciateBinding
import com.lizongying.mytv0.databinding.ModalBinding


class ModalFragment : DialogFragment() {

private var _binding: AppreciateBinding? = null
private var _binding: ModalBinding? = null
private val binding get() = _binding!!

private val handler = Handler(Looper.myLooper()!!)
Expand All @@ -34,7 +34,7 @@ class ModalFragment : DialogFragment() {
container: ViewGroup?,
savedInstanceState: Bundle?
): View {
_binding = AppreciateBinding.inflate(inflater, container, false)
_binding = ModalBinding.inflate(inflater, container, false)
return binding.root
}

Expand Down
19 changes: 11 additions & 8 deletions app/src/main/java/com/lizongying/mytv0/MyTVApplication.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,19 @@ import android.content.res.Resources
import android.os.Handler
import android.os.Looper
import android.util.DisplayMetrics
import android.util.Log
import android.view.WindowManager
import android.widget.Toast
import androidx.multidex.MultiDex
import androidx.multidex.MultiDexApplication

class MyTvApplication : Application() {
class MyTVApplication : MultiDexApplication() {

companion object {
private const val TAG = "MyTvApplication"
private lateinit var instance: MyTvApplication
private const val TAG = "MyTVApplication"
private lateinit var instance: MyTVApplication

fun getInstance(): MyTvApplication {
@JvmStatic
fun getInstance(): MyTVApplication {
return instance
}
}
Expand Down Expand Up @@ -97,8 +99,9 @@ class MyTvApplication : Application() {
fun sp2Px(sp: Float): Float {
return (sp * ratio * scale).toFloat()
}
}

fun String.showToast(duration: Int = Toast.LENGTH_SHORT) {
MyTvApplication.getInstance().toast(this, duration)
override fun attachBaseContext(base: Context?) {
super.attachBaseContext(base)
MultiDex.install(this)
}
}
4 changes: 4 additions & 0 deletions app/src/main/java/com/lizongying/mytv0/SP.kt
Original file line number Diff line number Diff line change
Expand Up @@ -104,4 +104,8 @@ object SP {

sp.edit().putStringSet(KEY_LIKE, stringSet).apply()
}

fun deleteLike() {
sp.edit().remove(KEY_LIKE).apply()
}
}
3 changes: 2 additions & 1 deletion app/src/main/java/com/lizongying/mytv0/SettingFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ class SettingFragment : Fragment() {
SP.channel = 0
defaultChannel.text = Editable.Factory.getInstance().newEditable("")
context.deleteFile(TVList.FILE_NAME)
SP.deleteLike()
SP.position = 0
TVList.setPosition(0)
}
Expand All @@ -172,7 +173,7 @@ class SettingFragment : Fragment() {
requireActivity().finishAffinity()
}

val application = requireActivity().applicationContext as MyTvApplication
val application = requireActivity().applicationContext as MyTVApplication

binding.content.layoutParams.width =
application.px2Px(binding.content.layoutParams.width)
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/java/com/lizongying/mytv0/TimeFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class TimeFragment : Fragment() {
): View {
_binding = TimeBinding.inflate(inflater, container, false)

val application = requireActivity().applicationContext as MyTvApplication
val application = requireActivity().applicationContext as MyTVApplication

binding.time.layoutParams.width = application.px2Px(binding.time.layoutParams.width)
binding.time.layoutParams.height = application.px2Px(binding.time.layoutParams.height)
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/layout/menu.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
android:id="@+id/group"
android:layout_width="150dp"
android:layout_height="match_parent"
android:layout_marginEnd="1dp"
android:layout_marginEnd="2dp"
android:padding="10dp"
android:background="#FF263238">
</androidx.recyclerview.widget.RecyclerView>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
android:layout_width="wrap_content"
android:layout_height="wrap_content"
>

<ImageView
android:id="@+id/modal_image"
android:layout_width="200dp"
android:layout_height="200dp"
android:background="@color/white"
android:contentDescription="@string/appreciate"
android:contentDescription="@string/app_name"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/values/dimens.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<dimen name="space_between_items">1dp</dimen>
<dimen name="space_between_items">2dp</dimen>
</resources>
8 changes: 0 additions & 8 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
@@ -1,13 +1,5 @@
<resources>
<string name="app_name">我的電視·〇</string>
<string name="error_fragment">Error Fragment</string>
<string name="personal_settings">Personal Settings</string>
<string name="movie">Movie</string>

<!-- Error messages -->
<string name="error_fragment_message">An error occurred</string>
<string name="dismiss_error">Dismiss</string>

<string name="title_channel_reversal">换台反转</string>
<string name="title_channel_num">换台时显示频道号</string>
<string name="check_version">更新应用</string>
Expand Down
3 changes: 0 additions & 3 deletions app/src/main/res/values/themes.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,2 @@
<resources>

<style name="Theme.MyTV0" parent="@style/Theme.Leanback">
</style>
</resources>
2 changes: 1 addition & 1 deletion version.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"version_code": 16844800, "version_name": "v1.1.8"}
{"version_code": 16908288, "version_name": "v1.2.0"}

0 comments on commit 31330f2

Please sign in to comment.