Skip to content

Commit

Permalink
fix menu
Browse files Browse the repository at this point in the history
  • Loading branch information
lizongying committed Aug 17, 2024
1 parent 598f6de commit 9a6710e
Show file tree
Hide file tree
Showing 8 changed files with 38 additions and 43 deletions.
3 changes: 2 additions & 1 deletion HISTORY.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
## 更新日誌

### v1.3.7.10
### v1.3.7.11

* 修復閃退問題
* 修復部分設備菜單異常問題

### v1.3.7.6

Expand Down
5 changes: 4 additions & 1 deletion app/src/main/java/com/lizongying/mytv0/ChannelFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,10 @@ class ChannelFragment : Fragment() {
}

private val hideRunnable = Runnable {
binding.content.text = BLANK
if (_binding != null) {
binding.content.text = BLANK
}

view?.visibility = View.GONE
channel = 0
channelCount = 0
Expand Down
16 changes: 6 additions & 10 deletions app/src/main/java/com/lizongying/mytv0/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ class MainActivity : AppCompatActivity() {
viewModel.groupModel.getPosition(position)
} else {
Log.i(TAG, "group ${viewModel.groupModel.positionValue}")
// if (SP.position < 0 || SP.position >= TVList.groupModel.getTVListModelNotFilter(1)!!
// if (SP.position < 0 || SP.position >= TVList.groupModel.getAllList()!!
// .size()
// ) {
// // R.string.last_channel_out_of_range.showToast()
Expand Down Expand Up @@ -257,9 +257,9 @@ class MainActivity : AppCompatActivity() {
if (tvModel.like.value != null && tvModel.tv.id != -1) {
val liked = tvModel.like.value as Boolean
if (liked) {
viewModel.groupModel.getTVListModelNotFilter(0)?.replaceTVModel(tvModel)
viewModel.groupModel.getFavoritesList()?.replaceTVModel(tvModel)
} else {
viewModel.groupModel.getTVListModelNotFilter(0)
viewModel.groupModel.getFavoritesList()
?.removeTVModel(tvModel.tv.id)
}
SP.setLike(tvModel.tv.id, liked)
Expand Down Expand Up @@ -382,7 +382,7 @@ class MainActivity : AppCompatActivity() {
}

fun play(position: Int) {
if (position > -1 && position < viewModel.groupModel.getTVListModelNotFilter(1)!!.size()) {
if (position > -1 && position < viewModel.groupModel.getAllList()!!.size()) {
val prevGroup = viewModel.groupModel.positionValue
val tvModel = viewModel.groupModel.getPosition(position)

Expand All @@ -402,9 +402,7 @@ class MainActivity : AppCompatActivity() {
fun prev() {
val prevGroup = viewModel.groupModel.positionValue
val tvModel =
if (SP.defaultLike && viewModel.groupModel.isInLikeMode && viewModel.groupModel.getTVListModelNotFilter(
0
) != null
if (SP.defaultLike && viewModel.groupModel.isInLikeMode && viewModel.groupModel.getFavoritesList() != null
) {
viewModel.groupModel.getPrev(true)
} else {
Expand All @@ -424,9 +422,7 @@ class MainActivity : AppCompatActivity() {
fun next() {
val prevGroup = viewModel.groupModel.positionValue
val tvModel =
if (SP.defaultLike && viewModel.groupModel.isInLikeMode && viewModel.groupModel.getTVListModelNotFilter(
0
) != null
if (SP.defaultLike && viewModel.groupModel.isInLikeMode && viewModel.groupModel.getFavoritesList() != null
) {
viewModel.groupModel.getNext(true)
} else {
Expand Down
8 changes: 3 additions & 5 deletions app/src/main/java/com/lizongying/mytv0/MenuFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ class MenuFragment : Fragment(), GroupAdapter.ItemListener, ListAdapter.ItemList
viewModel.groupModel.setPosition(position)
SP.positionGroup = position

viewModel.groupModel.getTVListModelNotFilter(position)?.let {
viewModel.groupModel.getCurrentList()?.let {
(binding.list.adapter as ListAdapter).update(it)
}
}
Expand Down Expand Up @@ -243,9 +243,7 @@ class MenuFragment : Fragment(), GroupAdapter.ItemListener, ListAdapter.ItemList
// listAdapter.focusable(true)
// }

if (viewModel.groupModel.tvGroupValue.size < 2 || viewModel.groupModel.getTVListModelNotFilter(
1
)?.size() == 0
if (viewModel.groupModel.tvGroupValue.size < 2 || viewModel.groupModel.getAllList()?.size() == 0
) {
R.string.channel_not_exist.showToast()
return
Expand All @@ -256,7 +254,7 @@ class MenuFragment : Fragment(), GroupAdapter.ItemListener, ListAdapter.ItemList
) {
updateList(position)
}
viewModel.groupModel.getTVListModelNotFilter(position)?.let {
viewModel.groupModel.getCurrentList()?.let {
listAdapter.toPosition(it.positionPlayingValue)
}
}
Expand Down
25 changes: 7 additions & 18 deletions app/src/main/java/com/lizongying/mytv0/SettingFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,9 @@ class SettingFragment : Fragment() {
requireActivity().finishAffinity()
}

val txtTextSize =
application.px2PxFont(binding.versionName.textSize)

binding.content.layoutParams.width =
application.px2Px(binding.content.layoutParams.width)
binding.content.setPadding(
Expand All @@ -162,28 +165,19 @@ class SettingFragment : Fragment() {
)

binding.name.textSize = application.px2PxFont(binding.name.textSize)
binding.version.textSize = application.px2PxFont(binding.version.textSize)
binding.version.textSize = txtTextSize
val layoutParamsVersion = binding.version.layoutParams as ViewGroup.MarginLayoutParams
layoutParamsVersion.topMargin = application.px2Px(binding.version.marginTop)
layoutParamsVersion.bottomMargin = application.px2Px(binding.version.marginBottom)
binding.version.layoutParams = layoutParamsVersion

val btnWidth =
application.px2Px(binding.confirmConfig.layoutParams.width)
val btnHeight =
application.px2Px(binding.confirmConfig.layoutParams.height)
val btnTextSize =
application.px2PxFont(binding.confirmConfig.textSize)

val btnLayoutParams =
binding.confirmConfig.layoutParams as ViewGroup.MarginLayoutParams
btnLayoutParams.marginEnd = application.px2Px(binding.confirmConfig.marginEnd)

val txtWidth =
application.px2Px(binding.versionName.layoutParams.width)
val txtTextSize =
application.px2PxFont(binding.versionName.textSize)

binding.versionName.layoutParams.width = txtWidth
binding.versionName.textSize = txtTextSize

for (i in listOf(
Expand All @@ -195,8 +189,7 @@ class SettingFragment : Fragment() {
binding.appreciate,
)) {
i.layoutParams.width = btnWidth
i.layoutParams.height = btnHeight
i.textSize = btnTextSize
i.textSize = txtTextSize
i.layoutParams = btnLayoutParams
i.setOnFocusChangeListener { _, hasFocus ->
if (hasFocus) {
Expand Down Expand Up @@ -352,7 +345,7 @@ class SettingFragment : Fragment() {

private fun confirmChannel() {
SP.channel =
min(max(SP.channel, 0), viewModel.groupModel.getTVListModelNotFilter(1)!!.size())
min(max(SP.channel, 0), viewModel.groupModel.getAllList()!!.size())

(activity as MainActivity).settingActive()
}
Expand All @@ -361,10 +354,6 @@ class SettingFragment : Fragment() {
this.server = "http://$server"
}

fun setVersionName(versionName: String) {
binding.versionName.text = versionName
}

private fun hideSelf() {
requireActivity().supportFragmentManager.beginTransaction()
.hide(this)
Expand Down
19 changes: 13 additions & 6 deletions app/src/main/java/com/lizongying/mytv0/models/TVGroupModel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ class TVGroupModel : ViewModel() {
val positionValue: Int
get() = _position.value ?: 0


private val _positionPlaying = MutableLiveData<Int>()
val positionPlaying: LiveData<Int>
get() = _positionPlaying
Expand Down Expand Up @@ -91,11 +90,11 @@ class TVGroupModel : ViewModel() {
fun clear() {
if (SP.showAllChannels) {
_tvGroup.value =
mutableListOf(getTVListModelNotFilter(0)!!, getTVListModelNotFilter(1)!!)
mutableListOf(getFavoritesList()!!, getAllList()!!)
setPosition(0)
getTVListModelNotFilter(1)?.clear()
getAllList()?.clear()
} else {
_tvGroup.value = mutableListOf(getTVListModelNotFilter(0)!!)
_tvGroup.value = mutableListOf(getFavoritesList()!!)
setPosition(0)
}
}
Expand Down Expand Up @@ -159,6 +158,14 @@ class TVGroupModel : ViewModel() {
return getTVListModelNotFilter(positionValue)
}

fun getFavoritesList(): TVListModel? {
return getTVListModelNotFilter(0)
}

fun getAllList(): TVListModel? {
return getTVListModelNotFilter(1)
}

// get & set
// keep: In the current list loop
fun getPrev(keep: Boolean = false): TVModel? {
Expand All @@ -170,7 +177,7 @@ class TVGroupModel : ViewModel() {
return null
}

var tvListModel = getTVListModelNotFilter(positionValue)!!
var tvListModel = getCurrentList()!!
if (keep) {
Log.i(TAG, "group position $positionValue")
return tvListModel.getPrev()
Expand Down Expand Up @@ -206,7 +213,7 @@ class TVGroupModel : ViewModel() {
return null
}

var tvListModel = getTVListModelNotFilter(positionValue)!!
var tvListModel = getCurrentList()!!
if (keep) {
return tvListModel.getNext()
}
Expand Down
3 changes: 2 additions & 1 deletion app/src/main/res/layout/setting.xml
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,8 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:orientation="horizontal">
android:orientation="horizontal"
>
<androidx.appcompat.widget.AppCompatButton
android:id="@+id/check_version"
android:layout_width="100dp"
Expand Down
2 changes: 1 addition & 1 deletion version.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"version_code": 16975626, "version_name": "v1.3.7.10"}
{"version_code": 16975627, "version_name": "v1.3.7.11"}

0 comments on commit 9a6710e

Please sign in to comment.