Skip to content

Commit

Permalink
auto load config
Browse files Browse the repository at this point in the history
  • Loading branch information
lizongying committed Apr 28, 2024
1 parent b6db917 commit 006f2aa
Show file tree
Hide file tree
Showing 39 changed files with 941 additions and 265 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,12 @@

## 更新日志

### v1.1.2

* 保存配置地址
* 启动后自动更新配置
* 样式优化

### v1.1.1

* 优化频道号选台
Expand Down
2 changes: 1 addition & 1 deletion 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=".MyApplication"
android:name=".MyTvApplication"
android:allowBackup="true"
android:banner="@drawable/banner0"
android:icon="@drawable/logo0"
Expand Down
32 changes: 25 additions & 7 deletions app/src/main/java/com/lizongying/mytv0/ChannelFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import android.os.Handler
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.core.view.marginEnd
import androidx.core.view.marginTop
import androidx.fragment.app.Fragment
import com.lizongying.mytv0.databinding.ChannelBinding
import com.lizongying.mytv0.models.TVModel
Expand All @@ -23,30 +25,46 @@ class ChannelFragment : Fragment() {
): View {
_binding = ChannelBinding.inflate(inflater, container, false)
_binding!!.root.visibility = View.GONE

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)

val layoutParams = binding.channel.layoutParams as ViewGroup.MarginLayoutParams
layoutParams.topMargin = application.px2Px(binding.channel.marginTop)
layoutParams.marginEnd = application.px2Px(binding.channel.marginEnd)
binding.channel.layoutParams = layoutParams

binding.content.textSize = application.px2PxFont(binding.content.textSize)

binding.main.layoutParams.width = application.shouldWidthPx()
binding.main.layoutParams.height = application.shouldHeightPx()

return binding.root
}

fun show(tvViewModel: TVModel) {
handler.removeCallbacks(hideRunnable)
handler.removeCallbacks(playRunnable)
binding.channelContent.text = (tvViewModel.tv.id.plus(1)).toString()
binding.content.text = (tvViewModel.tv.id.plus(1)).toString()
view?.visibility = View.VISIBLE
handler.postDelayed(hideRunnable, delay)
}

fun show(channel: String) {
if (binding.channelContent.text.length > 1) {
if (binding.content.text.length > 1) {
return
}
this.channel = "${binding.channelContent.text}$channel".toInt()
this.channel = "${binding.content.text}$channel".toInt()
handler.removeCallbacks(hideRunnable)
handler.removeCallbacks(playRunnable)
if (binding.channelContent.text == "") {
binding.channelContent.text = channel
if (binding.content.text == "") {
binding.content.text = channel
view?.visibility = View.VISIBLE
handler.postDelayed(playRunnable, delay)
} else {
binding.channelContent.text = "${binding.channelContent.text}$channel"
binding.content.text = "${binding.content.text}$channel"
handler.postDelayed(playRunnable, 0)
}
}
Expand All @@ -65,7 +83,7 @@ class ChannelFragment : Fragment() {
}

private val hideRunnable = Runnable {
binding.channelContent.text = ""
binding.content.text = ""
view?.visibility = View.GONE
}

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

import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.core.view.marginTop
import androidx.fragment.app.Fragment
import com.lizongying.mytv0.databinding.ErrorBinding

class ErrorFragment : Fragment() {
private var _binding: ErrorBinding? = null
private val binding get() = _binding!!

override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?
): View {
_binding = ErrorBinding.inflate(inflater, container, false)

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)

val layoutParams = binding.msg.layoutParams as ViewGroup.MarginLayoutParams
layoutParams.topMargin = application.px2Px(binding.msg.marginTop)
binding.msg.layoutParams = layoutParams

binding.msg.textSize = application.px2PxFont(binding.msg.textSize)

(activity as MainActivity).ready(TAG)
return binding.root
}

fun show(msg: String) {
binding.msg.text = msg
}

override fun onDestroyView() {
super.onDestroyView()
_binding = null
}

companion object {
private const val TAG = "ErrorFragment"
}
}
44 changes: 38 additions & 6 deletions app/src/main/java/com/lizongying/mytv0/InfoFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package com.lizongying.mytv0

import android.graphics.Bitmap
import android.graphics.Canvas
import android.graphics.Color
import android.graphics.Paint
import android.graphics.drawable.BitmapDrawable
import android.os.Bundle
Expand All @@ -11,6 +10,9 @@ import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.core.content.ContextCompat
import androidx.core.view.marginBottom
import androidx.core.view.marginStart
import androidx.core.view.marginTop
import androidx.fragment.app.Fragment
import com.bumptech.glide.Glide
import com.lizongying.mytv0.databinding.InfoBinding
Expand All @@ -29,12 +31,44 @@ class InfoFragment : Fragment() {
savedInstanceState: Bundle?
): View {
_binding = InfoBinding.inflate(inflater, container, false)


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)

val layoutParams = binding.info.layoutParams as ViewGroup.MarginLayoutParams
layoutParams.bottomMargin = application.px2Px(binding.info.marginBottom)
binding.info.layoutParams = layoutParams

binding.logo.layoutParams.width = application.px2Px(binding.logo.layoutParams.width)
var padding = application.px2Px(binding.logo.paddingTop)
binding.logo.setPadding(padding, padding, padding, padding)
binding.main.layoutParams.width = application.px2Px(binding.main.layoutParams.width)
padding = application.px2Px(binding.main.paddingTop)
binding.main.setPadding(padding, padding, padding, padding)

val layoutParamsMain = binding.main.layoutParams as ViewGroup.MarginLayoutParams
layoutParamsMain.marginStart = application.px2Px(binding.main.marginStart)
binding.main.layoutParams = layoutParamsMain

val layoutParamsDesc = binding.desc.layoutParams as ViewGroup.MarginLayoutParams
layoutParamsDesc.topMargin = application.px2Px(binding.desc.marginTop)
binding.desc.layoutParams = layoutParamsDesc

binding.title.textSize = application.px2PxFont(binding.title.textSize)
binding.desc.textSize = application.px2PxFont(binding.desc.textSize)

binding.container.layoutParams.width = application.shouldWidthPx()
binding.container.layoutParams.height = application.shouldHeightPx()

_binding!!.root.visibility = View.GONE
return binding.root
}

fun show(tvViewModel: TVModel) {
binding.textView.text = tvViewModel.tv.title
binding.title.text = tvViewModel.tv.title

when (tvViewModel.tv.title) {
else -> {
Expand All @@ -57,15 +91,13 @@ class InfoFragment : Fragment() {
Glide.with(this)
.load(BitmapDrawable(context?.resources, bitmap))
// .centerInside()
.into(binding.infoLogo)
.into(binding.logo)
} else {
Glide.with(this)
.load(tvViewModel.tv.logo)
// .centerInside()
.into(binding.infoLogo)
.into(binding.logo)
}


}
}

Expand Down
2 changes: 1 addition & 1 deletion app/src/main/java/com/lizongying/mytv0/ListAdapter.kt
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ class ListAdapter(
textSize = 32f
textAlign = Paint.Align.CENTER
}
val text = "${id + 1}"
val text = String.format("%3d", id + 1)
val x = width / 2f
val y = height / 2f - (paint.descent() + paint.ascent()) / 2
canvas.drawText(text, x, y, paint)
Expand Down
14 changes: 14 additions & 0 deletions app/src/main/java/com/lizongying/mytv0/LiveDataExtensions.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.lizongying.mytv0

import androidx.lifecycle.LifecycleOwner
import androidx.lifecycle.LiveData
import androidx.lifecycle.Observer

fun <T> LiveData<T>.observeOnce(owner: LifecycleOwner, observer: (T) -> Unit) {
observe(owner, object : Observer<T> {
override fun onChanged(value: T) {
removeObserver(this)
observer(value)
}
})
}
37 changes: 37 additions & 0 deletions app/src/main/java/com/lizongying/mytv0/LoadingFragment.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package com.lizongying.mytv0

import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.Fragment
import com.lizongying.mytv0.databinding.LoadingBinding

class LoadingFragment : Fragment() {
private var _binding: LoadingBinding? = null
private val binding get() = _binding!!

override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?
): View {
_binding = LoadingBinding.inflate(inflater, container, false)

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)

(activity as MainActivity).ready(TAG)
return binding.root
}

override fun onDestroyView() {
super.onDestroyView()
_binding = null
}

companion object {
private const val TAG = "LoadingFragment"
}
}
Loading

0 comments on commit 006f2aa

Please sign in to comment.