Skip to content

Commit

Permalink
fix java7 string length bug
Browse files Browse the repository at this point in the history
  • Loading branch information
lizongying committed May 18, 2024
1 parent 59904d6 commit ced56ad
Show file tree
Hide file tree
Showing 16 changed files with 187 additions and 35 deletions.
7 changes: 7 additions & 0 deletions HISTORY.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
## 更新日志

### v1.0.5

* 增加频道
* 修复部分电视设备无法播放的问题
* 优化频道列表样式
* 遥控器左键不再退出频道列表

### v1.0.4

* 增加频道
Expand Down
2 changes: 1 addition & 1 deletion app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ dependencies {
implementation("androidx.constraintlayout:constraintlayout:2.1.4")
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-android:1.8.1")

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

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

Expand Down
38 changes: 37 additions & 1 deletion app/src/main/java/com/lizongying/mytv1/ListAdapter.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@ import android.graphics.Canvas
import android.graphics.Color
import android.graphics.Paint
import android.graphics.drawable.BitmapDrawable
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 androidx.constraintlayout.widget.ConstraintSet
import androidx.core.content.ContextCompat
import androidx.core.view.marginStart
import androidx.core.view.setPadding
Expand Down Expand Up @@ -180,7 +182,12 @@ class ListAdapter(
override fun getItemCount() = tvListModel.size()

class ViewHolder(private val context: Context, val binding: ListItemBinding) :
RecyclerView.ViewHolder(binding.root) {
RecyclerView.ViewHolder(binding.root), OnSharedPreferenceChangeListener {

init {
SP.setOnSharedPreferenceChangeListener(this)
}

fun bindTitle(text: String) {
binding.title.text = text
}
Expand Down Expand Up @@ -251,6 +258,35 @@ class ListAdapter(
)
}
}

override fun onSharedPreferenceChanged(key: String) {
Log.i(TAG, "$key changed")
when (key) {
SP.KEY_EPG -> {
if (SP.epg.isNullOrEmpty()) {
val constraintSet = ConstraintSet()
constraintSet.clone(binding.root)

constraintSet.connect(binding.title.id, ConstraintSet.BOTTOM, ConstraintSet.PARENT_ID, ConstraintSet.BOTTOM)
constraintSet.connect(binding.heart.id, ConstraintSet.BOTTOM, ConstraintSet.PARENT_ID, ConstraintSet.BOTTOM)

constraintSet.applyTo(binding.root)

binding.description.visibility = View.GONE
} else {
val constraintSet = ConstraintSet()
constraintSet.clone(binding.root)

constraintSet.clear(binding.title.id, ConstraintSet.BOTTOM)
constraintSet.clear(binding.heart.id, ConstraintSet.BOTTOM)

constraintSet.applyTo(binding.root)

binding.description.visibility = View.VISIBLE
}
}
}
}
}

fun toPosition(position: Int) {
Expand Down
16 changes: 8 additions & 8 deletions app/src/main/java/com/lizongying/mytv1/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ class MainActivity : FragmentActivity() {
}

fun onPlayEnd() {
val tvModel = TVList.getTVModel()
val tvModel = TVList.getTVModel()!!
if (SP.repeatInfo) {
infoFragment.show(tvModel)
if (SP.channelNum) {
Expand All @@ -300,10 +300,10 @@ class MainActivity : FragmentActivity() {
}

fun play(position: Int) {
val prevGroup = TVList.getTVModel().groupIndex
val prevGroup = TVList.getTVModel()!!.groupIndex
if (position > -1 && position < TVList.size()) {
TVList.setPosition(position)
val currentGroup = TVList.getTVModel().groupIndex
val currentGroup = TVList.getTVModel()!!.groupIndex
if (currentGroup != prevGroup) {
Log.i(TAG, "group change")
menuFragment.updateList(currentGroup)
Expand All @@ -314,27 +314,27 @@ class MainActivity : FragmentActivity() {
}

fun prev() {
val prevGroup = TVList.getTVModel().groupIndex
val prevGroup = TVList.getTVModel()!!.groupIndex
var position = TVList.position.value?.dec() ?: 0
if (position == -1) {
position = TVList.size() - 1
}
TVList.setPosition(position)
val currentGroup = TVList.getTVModel().groupIndex
val currentGroup = TVList.getTVModel()!!.groupIndex
if (currentGroup != prevGroup) {
Log.i(TAG, "group change")
menuFragment.updateList(currentGroup)
}
}

fun next() {
val prevGroup = TVList.getTVModel().groupIndex
val prevGroup = TVList.getTVModel()!!.groupIndex
var position = TVList.position.value?.inc() ?: 0
if (position == TVList.size()) {
position = 0
}
TVList.setPosition(position)
val currentGroup = TVList.getTVModel().groupIndex
val currentGroup = TVList.getTVModel()!!.groupIndex
if (currentGroup != prevGroup) {
Log.i(TAG, "group change")
menuFragment.updateList(currentGroup)
Expand Down Expand Up @@ -570,7 +570,7 @@ class MainActivity : FragmentActivity() {
}

KeyEvent.KEYCODE_UNKNOWN -> {
showSetting()
// showSetting()
return true
}

Expand Down
18 changes: 9 additions & 9 deletions app/src/main/java/com/lizongying/mytv1/MenuFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -132,23 +132,23 @@ class MenuFragment : Fragment(), GroupAdapter.ItemListener, ListAdapter.ItemList
binding.group.visibility = GONE
groupAdapter.focusable(false)
listAdapter.focusable(true)
listAdapter.toPosition(TVList.getTVModel().listIndex)
listAdapter.toPosition(TVList.getTVModel()!!.listIndex)


if (TVList.getTVModel().groupIndex == TVList.groupModel.position.value!!) {
if (TVList.getTVModel()!!.groupIndex == TVList.groupModel.position.value!!) {
Log.i(
TAG,
"list on show toPosition ${TVList.getTVModel().tv.title} ${TVList.getTVModel().listIndex}/${listAdapter.tvListModel.size()}"
"list on show toPosition ${TVList.getTVModel()!!.tv.title} ${TVList.getTVModel()!!.listIndex}/${listAdapter.tvListModel.size()}"
)
listAdapter.toPosition(TVList.getTVModel().listIndex)
listAdapter.toPosition(TVList.getTVModel()!!.listIndex)
} else {
listAdapter.toPosition(0)
}
return true
}

KeyEvent.KEYCODE_DPAD_LEFT -> {
(activity as MainActivity).hideMenuFragment()
// (activity as MainActivity).hideMenuFragment()
return true
}
}
Expand Down Expand Up @@ -191,22 +191,22 @@ class MenuFragment : Fragment(), GroupAdapter.ItemListener, ListAdapter.ItemList
// listAdapter.focusable(true)
// }

val groupIndex = TVList.getTVModel().groupIndex
val groupIndex = TVList.getTVModel()!!.groupIndex
Log.i(
TAG,
"groupIndex $groupIndex ${TVList.groupModel.position.value!!}"
)

if (groupIndex == TVList.groupModel.position.value!!) {
if (listAdapter.tvListModel.getIndex() != TVList.getTVModel().groupIndex) {
if (listAdapter.tvListModel.getIndex() != TVList.getTVModel()!!.groupIndex) {
updateList(groupIndex)
}

Log.i(
TAG,
"list on show toPosition ${TVList.getTVModel().tv.title} ${TVList.getTVModel().listIndex}/${listAdapter.tvListModel.size()}"
"list on show toPosition ${TVList.getTVModel()!!.tv.title} ${TVList.getTVModel()!!.listIndex}/${listAdapter.tvListModel.size()}"
)
listAdapter.toPosition(TVList.getTVModel().listIndex)
listAdapter.toPosition(TVList.getTVModel()!!.listIndex)
} else {
listAdapter.toPosition(0)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package com.lizongying.mytv1


interface OnSharedPreferenceChangeListener {
fun onSharedPreferenceChanged(key: String)
}
17 changes: 17 additions & 0 deletions app/src/main/java/com/lizongying/mytv1/SP.kt
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,12 @@ object SP {

private const val KEY_LIKE = "like"

const val KEY_EPG = "epg"

private lateinit var sp: SharedPreferences

private var listener: OnSharedPreferenceChangeListener? = null

/**
* The method must be invoked as early as possible(At least before using the keys)
*/
Expand All @@ -45,6 +49,10 @@ object SP {
)
}

fun setOnSharedPreferenceChangeListener(listener: OnSharedPreferenceChangeListener) {
this.listener = listener
}

var channelReversal: Boolean
get() = sp.getBoolean(KEY_CHANNEL_REVERSAL, false)
set(value) = sp.edit().putBoolean(KEY_CHANNEL_REVERSAL, value).apply()
Expand Down Expand Up @@ -108,4 +116,13 @@ object SP {
fun deleteLike() {
sp.edit().remove(KEY_LIKE).apply()
}

var epg: String?
get() = sp.getString(KEY_EPG, "")
set(value) {
if (value != this.epg) {
sp.edit().putString(KEY_EPG, value).apply()
listener?.onSharedPreferenceChanged(KEY_EPG)
}
}
}
89 changes: 82 additions & 7 deletions app/src/main/java/com/lizongying/mytv1/WebFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,7 @@ class WebFragment : Fragment() {
}
}
}

"www.jlntv.cn" -> {
webView.evaluateJavascript(context.resources.openRawResource(R.raw.ahtv)
.bufferedReader()
Expand All @@ -333,6 +334,86 @@ class WebFragment : Fragment() {
}
}
}

"v.iqilu.com" -> {
webView.evaluateJavascript(context.resources.openRawResource(R.raw.ahtv)
.bufferedReader()
.use { it.readText() }) { value ->
if (value == "success") {
Log.e(TAG, "success")
}
}
}

"www.qhbtv.com" -> {
webView.evaluateJavascript(context.resources.openRawResource(R.raw.ahtv)
.bufferedReader()
.use { it.readText() }) { value ->
if (value == "success") {
Log.e(TAG, "success")
}
}
}

"www.qhtb.cn" -> {
webView.evaluateJavascript(context.resources.openRawResource(R.raw.ahtv)
.bufferedReader()
.use { it.readText() }) { value ->
if (value == "success") {
Log.e(TAG, "success")
}
}
}

"www.hljtv.com" -> {
webView.evaluateJavascript(context.resources.openRawResource(R.raw.ahtv)
.bufferedReader()
.use { it.readText() }) { value ->
if (value == "success") {
Log.e(TAG, "success")
}
}
}

"static.hntv.tv" -> {
webView.evaluateJavascript(context.resources.openRawResource(R.raw.ahtv)
.bufferedReader()
.use { it.readText() }) { value ->
if (value == "success") {
Log.e(TAG, "success")
}
}
}

"www.btzx.com.cn" -> {
webView.evaluateJavascript(context.resources.openRawResource(R.raw.ahtv)
.bufferedReader()
.use { it.readText() }) { value ->
if (value == "success") {
Log.e(TAG, "success")
}
}
}

"live.snrtv.com" -> {
webView.evaluateJavascript(context.resources.openRawResource(R.raw.ahtv)
.bufferedReader()
.use { it.readText() }) { value ->
if (value == "success") {
Log.e(TAG, "success")
}
}
}

"www.snrtv.com" -> {
webView.evaluateJavascript(context.resources.openRawResource(R.raw.ahtv)
.bufferedReader()
.use { it.readText() }) { value ->
if (value == "success") {
Log.e(TAG, "success")
}
}
}
}
}
}
Expand All @@ -356,14 +437,8 @@ class WebFragment : Fragment() {
null
)
}

"www.gdtv.cn" -> {
}

"www.yangshipin.cn" -> {
}
}
// url = "https://news.hbtv.com.cn/app/tv/434"
// url = "http://live.snrtv.com/star"
webView.loadUrl(url)
}

Expand Down
11 changes: 7 additions & 4 deletions app/src/main/java/com/lizongying/mytv1/models/TVList.kt
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ object TVList {
file.readText()
} else {
Log.i(TAG, "read resource")
context.resources.openRawResource(R.raw.channels).bufferedReader()
context.resources.openRawResource(R.raw.channels).bufferedReader(Charsets.UTF_8)
.use { it.readText() }
}

Expand Down Expand Up @@ -196,11 +196,14 @@ object TVList {
return true
}

fun getTVModel(): TVModel {
fun getTVModel(): TVModel? {
return getTVModel(position.value!!)
}

private fun getTVModel(idx: Int): TVModel {
fun getTVModel(idx: Int): TVModel? {
if (idx >= size()) {
return null
}
return listModel[idx]
}

Expand All @@ -217,7 +220,7 @@ object TVList {
val tvModel = getTVModel(position)

// set a new position or retry when position same
tvModel.setReady()
tvModel!!.setReady()

groupModel.setPosition(tvModel.groupIndex)

Expand Down
Loading

0 comments on commit ced56ad

Please sign in to comment.