Skip to content

Commit

Permalink
fix some crash bug
Browse files Browse the repository at this point in the history
  • Loading branch information
lizongying committed Apr 8, 2024
1 parent a977f1d commit 48d08e5
Show file tree
Hide file tree
Showing 14 changed files with 153 additions and 48 deletions.
9 changes: 6 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,6 @@
]
```

注意:
配置地址更新后,如遇到之前节目还存在的情况,可能需要重启软件后生效,后面会进行优化

下载安装 [releases](https://github.com/lizongying/my-tv-0/releases/)

更多地址 [my-tv](https://lyrics.run/my-tv-0.html)
Expand All @@ -44,6 +41,12 @@

## 更新日志

### v1.0.5

* 修复频道配置错误时可能崩溃的问题
* 修复更新频道配置时可能不生效的问题
* 修复图标为空时可能崩溃的问题

### v1.0.4

* 在触屏设备上双击打开节目列表
Expand Down
Binary file removed Screenshot_20240324_100541.png
Binary file not shown.
19 changes: 10 additions & 9 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,24 +1,25 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">
<manifest xmlns:android="http://schemas.android.com/apk/res/android">

<application
android:name=".MyApplication"
android:allowBackup="true"
android:largeHeap="true"
android:icon="@drawable/logo0"
android:logo="@drawable/logo0"
android:banner="@drawable/banner0"
android:icon="@drawable/logo0"
android:label="@string/app_name"
android:supportsRtl="true"
android:largeHeap="true"
android:logo="@drawable/logo0"
android:networkSecurityConfig="@xml/network"
android:usesCleartextTraffic="true"
android:theme="@style/Theme.MyTV0">
android:supportsRtl="true"
android:theme="@style/Theme.MyTV0"
android:usesCleartextTraffic="true">
<activity
android:name=".MainActivity"
android:exported="true"
android:screenOrientation="landscape">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LEANBACK_LAUNCHER" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
Expand Down Expand Up @@ -46,7 +47,7 @@
android:required="false" />

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />

</manifest>
17 changes: 11 additions & 6 deletions app/src/main/java/com/lizongying/mytv0/GroupAdapter.kt
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import com.lizongying.mytv0.models.TVListModel
class GroupAdapter(
private val context: Context,
private val recyclerView: RecyclerView,
private var tvgroupModel: TVGroupModel,
private var tvGroupModel: TVGroupModel,
) :
RecyclerView.Adapter<GroupAdapter.ViewHolder>() {

Expand Down Expand Up @@ -51,7 +51,7 @@ class GroupAdapter(
}

override fun onBindViewHolder(viewHolder: ViewHolder, position: Int) {
val tvListModel = tvgroupModel.getTVListModel(position)!!
val tvListModel = tvGroupModel.getTVListModel(position)!!
val view = viewHolder.itemView
view.tag = position

Expand All @@ -67,8 +67,8 @@ class GroupAdapter(
viewHolder.focus(true)
focused = view
if (visiable) {
if (position != tvgroupModel.position.value) {
tvgroupModel.setPosition(position)
if (position != tvGroupModel.position.value) {
tvGroupModel.setPosition(position)
}
} else {
visiable = true
Expand All @@ -84,7 +84,7 @@ class GroupAdapter(
listener?.onItemClicked(tvListModel)
}

view.setOnKeyListener { v, keyCode, event: KeyEvent? ->
view.setOnKeyListener { _, keyCode, event: KeyEvent? ->
if (event?.action == KeyEvent.ACTION_DOWN) {
if (keyCode == KeyEvent.KEYCODE_DPAD_UP && position == 0) {
recyclerView.smoothScrollToPosition(getItemCount() - 1)
Expand All @@ -102,7 +102,7 @@ class GroupAdapter(
viewHolder.bind(tvListModel.getName())
}

override fun getItemCount() = tvgroupModel.size()
override fun getItemCount() = tvGroupModel.size()

class ViewHolder(private val context: Context, private val binding: GroupItemBinding) :
RecyclerView.ViewHolder(binding.root) {
Expand Down Expand Up @@ -143,6 +143,11 @@ class GroupAdapter(
this.listener = listener
}

fun update(tvGroupModel: TVGroupModel) {
this.tvGroupModel = tvGroupModel
notifyDataSetChanged()
}

companion object {
private const val TAG = "CategoryAdapter"
}
Expand Down
8 changes: 5 additions & 3 deletions app/src/main/java/com/lizongying/mytv0/ListAdapter.kt
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
package com.lizongying.mytv0

import android.content.Context
import android.util.Log
import android.view.KeyEvent
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.view.ViewGroup.FOCUS_BEFORE_DESCENDANTS
import android.view.ViewGroup.FOCUS_BLOCK_DESCENDANTS
import android.view.animation.ScaleAnimation
import androidx.core.content.ContextCompat
import androidx.lifecycle.LifecycleOwner
import androidx.recyclerview.widget.RecyclerView
import com.bumptech.glide.Glide
import com.lizongying.mytv0.databinding.ListItemBinding
Expand Down Expand Up @@ -112,7 +111,10 @@ class ListAdapter(

viewHolder.bindText(tvModel.tv.title)

viewHolder.bindImage(tvModel.tv.logo)
// maybe null
if (!tvModel.tv.logo.isNullOrBlank()) {
viewHolder.bindImage(tvModel.tv.logo)
}
}

override fun getItemCount() = tvListModel.size()
Expand Down
4 changes: 3 additions & 1 deletion app/src/main/java/com/lizongying/mytv0/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,9 @@ class MainActivity : FragmentActivity() {
}
}

TVList.setPosition(SP.position)
if (!TVList.setPosition(SP.position)) {
TVList.setPosition(0)
}
}

override fun onTouchEvent(event: MotionEvent?): Boolean {
Expand Down
18 changes: 17 additions & 1 deletion app/src/main/java/com/lizongying/mytv0/MenuFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -45,16 +45,32 @@ class MenuFragment : Fragment(), GroupAdapter.ItemListener, ListAdapter.ItemList
LinearLayoutManager(context)
groupAdapter.setItemListener(this)

var tvListModel = TVList.groupModel.getTVListModel(TVList.groupModel.position.value!!)
if (tvListModel == null) {
TVList.groupModel.setPosition(0)
}

tvListModel = TVList.groupModel.getTVListModel(TVList.groupModel.position.value!!)

listAdapter = ListAdapter(
context!!,
binding.list,
TVList.groupModel.getTVListModel(TVList.groupModel.position.value!!)!!,
tvListModel!!,
)
binding.list.adapter = listAdapter
binding.list.layoutManager =
LinearLayoutManager(context)
listAdapter.focusable(false)
listAdapter.setItemListener(this)

TVList.groupModel.tvGroupModel.observe(viewLifecycleOwner) { _ ->

// not first time
if (TVList.groupModel.tvGroupModel.value != null) {
groupAdapter.update(TVList.groupModel)
}
}

return binding.root
}

Expand Down
32 changes: 32 additions & 0 deletions app/src/main/java/com/lizongying/mytv0/MyApplication.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package com.lizongying.mytv0

import android.app.Application
import android.os.Handler
import android.os.Looper
import android.widget.Toast

class MyApplication : Application() {

companion object {
private lateinit var instance: MyApplication

fun getInstance(): MyApplication {
return instance
}
}

override fun onCreate() {
super.onCreate()
instance = this
}

fun toast(message: CharSequence = "", duration: Int = Toast.LENGTH_SHORT) {
Handler(Looper.getMainLooper()).post {
Toast.makeText(applicationContext, message, duration).show()
}
}
}

fun String.showToast(duration: Int = Toast.LENGTH_SHORT) {
MyApplication.getInstance().toast(this, duration)
}
2 changes: 2 additions & 0 deletions app/src/main/java/com/lizongying/mytv0/SettingFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import android.util.Log
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.Toast
import androidx.fragment.app.Fragment
import com.lizongying.mytv0.databinding.SettingBinding
import com.lizongying.mytv0.models.TVList
Expand Down Expand Up @@ -54,6 +55,7 @@ class SettingFragment: Fragment() {
binding.checkVersion.setOnClickListener(OnClickListenerCheckVersion(updateManager))

binding.confirmButton.setOnClickListener {

val uriEditText = binding.myEditText
var uri = uriEditText.text.toString()

Expand Down
22 changes: 17 additions & 5 deletions app/src/main/java/com/lizongying/mytv0/models/TVGroupModel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import androidx.lifecycle.ViewModel
import com.lizongying.mytv0.SP

class TVGroupModel : ViewModel() {
private val _tvGroupModel = MutableLiveData<MutableList<TVListModel>>()
val tvGroupModel: LiveData<MutableList<TVListModel>>
private val _tvGroupModel = MutableLiveData<List<TVListModel>>()
val tvGroupModel: LiveData<List<TVListModel>>
get() = _tvGroupModel

private val _position = MutableLiveData<Int>()
Expand All @@ -18,19 +18,31 @@ class TVGroupModel : ViewModel() {
_position.value = position
}

fun setTVListModelList(tvTVListModelList: MutableList<TVListModel>) {
_tvGroupModel.value = tvTVListModelList
fun setTVListModelList(tvListModelList: List<TVListModel>) {
_tvGroupModel.value = tvListModelList
}

fun addTVListModel(tvListModel: TVListModel) {
if (_tvGroupModel.value == null) {
_tvGroupModel.value = mutableListOf(tvListModel)
return
}
_tvGroupModel.value?.add(tvListModel)

val newList = _tvGroupModel.value!!.toMutableList()
newList.add(tvListModel)
_tvGroupModel.value = newList
}

fun clear() {
_tvGroupModel.value = mutableListOf(getTVListModel(0)!!, getTVListModel(1)!!)
setPosition(0)
getTVListModel(1)?.clear()
}

fun getTVListModel(idx: Int): TVListModel? {
if (idx >= size()) {
return null
}
return _tvGroupModel.value?.get(idx)
}

Expand Down
Loading

0 comments on commit 48d08e5

Please sign in to comment.