Skip to content

Commit

Permalink
optimize style
Browse files Browse the repository at this point in the history
  • Loading branch information
lizongying committed Apr 29, 2024
1 parent 013b819 commit 233e01f
Show file tree
Hide file tree
Showing 12 changed files with 122 additions and 71 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@
## 更新日志
### v1.1.4
* 默认使用上次缓存视频源
* 样式优化
### v1.1.3
* 修复m3u解析错误
Expand Down
22 changes: 17 additions & 5 deletions app/src/main/java/com/lizongying/mytv0/GroupAdapter.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ 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.recyclerview.widget.RecyclerView
import com.lizongying.mytv0.databinding.GroupItemBinding
import com.lizongying.mytv0.models.TVGroupModel
Expand All @@ -27,9 +29,19 @@ class GroupAdapter(

var visiable = false

val application = context.applicationContext as MyTvApplication

override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
val inflater = LayoutInflater.from(context)
val binding = GroupItemBinding.inflate(inflater, parent, false)

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

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

binding.root.isFocusable = true
binding.root.isFocusableInTouchMode = true
return ViewHolder(context, binding)
Expand Down Expand Up @@ -99,22 +111,22 @@ class GroupAdapter(
false
}

viewHolder.bind(tvListModel.getName())
viewHolder.bindTitle(tvListModel.getName())
}

override fun getItemCount() = tvGroupModel.size()

class ViewHolder(private val context: Context, private val binding: GroupItemBinding) :
RecyclerView.ViewHolder(binding.root) {
fun bind(text: String) {
binding.textView.text = text
fun bindTitle(text: String) {
binding.title.text = text
}

fun focus(hasFocus: Boolean) {
if (hasFocus) {
binding.textView.setTextColor(ContextCompat.getColor(context, R.color.white))
binding.title.setTextColor(ContextCompat.getColor(context, R.color.white))
} else {
binding.textView.setTextColor(
binding.title.setTextColor(
ContextCompat.getColor(
context,
R.color.description_blur
Expand Down
38 changes: 31 additions & 7 deletions app/src/main/java/com/lizongying/mytv0/ListAdapter.kt
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import android.view.ViewGroup
import android.view.ViewGroup.FOCUS_BEFORE_DESCENDANTS
import android.view.ViewGroup.FOCUS_BLOCK_DESCENDANTS
import androidx.core.content.ContextCompat
import androidx.core.view.marginStart
import androidx.core.view.setPadding
import androidx.recyclerview.widget.RecyclerView
import com.bumptech.glide.Glide
import com.lizongying.mytv0.databinding.ListItemBinding
Expand All @@ -33,9 +35,31 @@ class ListAdapter(

var visiable = false

val application = context.applicationContext as MyTvApplication

override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
val inflater = LayoutInflater.from(context)
val binding = ListItemBinding.inflate(inflater, parent, false)

binding.icon.layoutParams.width = application.px2Px(binding.icon.layoutParams.width)
binding.icon.layoutParams.height = application.px2Px(binding.icon.layoutParams.height)
binding.icon.setPadding(application.px2Px(binding.icon.paddingTop))

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

binding.heart.layoutParams.width = application.px2Px(binding.heart.layoutParams.width)
binding.heart.layoutParams.height = application.px2Px(binding.heart.layoutParams.height)

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

val layoutParamsHeart = binding.heart.layoutParams as ViewGroup.MarginLayoutParams
layoutParamsHeart.marginStart = application.px2Px(binding.heart.marginStart)
binding.heart.layoutParams = layoutParamsHeart

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

return ViewHolder(context, binding)
}

Expand Down Expand Up @@ -113,7 +137,7 @@ class ListAdapter(
false
}

viewHolder.bindText(tvModel.tv.title)
viewHolder.bindTitle(tvModel.tv.title)

viewHolder.bindImage(tvModel.tv.logo, tvModel.tv.id)
}
Expand All @@ -122,8 +146,8 @@ class ListAdapter(

class ViewHolder(private val context: Context, private val binding: ListItemBinding) :
RecyclerView.ViewHolder(binding.root) {
fun bindText(text: String) {
binding.textView.text = text
fun bindTitle(text: String) {
binding.title.text = text
}

fun bindImage(url: String?, id: Int) {
Expand All @@ -145,25 +169,25 @@ class ListAdapter(
Glide.with(context)
.load(BitmapDrawable(context.resources, bitmap))
.centerInside()
.into(binding.imageView)
.into(binding.icon)
// binding.imageView.setImageDrawable(null)
} else {
Glide.with(context)
.load(url)
.centerInside()
// .error(BitmapDrawable(context.resources, bitmap))
.into(binding.imageView)
.into(binding.icon)
}
}

fun focus(hasFocus: Boolean) {
if (hasFocus) {
binding.textView.setTextColor(ContextCompat.getColor(context, R.color.white))
binding.title.setTextColor(ContextCompat.getColor(context, R.color.white))
binding.description.setTextColor(ContextCompat.getColor(context, R.color.white))
// binding.root.alpha = 1.0F
binding.root.setBackgroundResource(R.color.focus)
} else {
binding.textView.setTextColor(ContextCompat.getColor(context, R.color.title_blur))
binding.title.setTextColor(ContextCompat.getColor(context, R.color.title_blur))
binding.description.setTextColor(
ContextCompat.getColor(
context,
Expand Down
35 changes: 22 additions & 13 deletions app/src/main/java/com/lizongying/mytv0/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.lizongying.mytv0

import android.content.Context
import android.media.AudioManager
import android.os.Build
import android.os.Bundle
import android.os.Handler
import android.os.Looper
Expand Down Expand Up @@ -40,10 +41,26 @@ class MainActivity : FragmentActivity() {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
val lp = window.attributes
lp.layoutInDisplayCutoutMode =
WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES
window.setAttributes(lp)
}

window.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON)
window.addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN)
window.decorView.systemUiVisibility = View.SYSTEM_UI_FLAG_HIDE_NAVIGATION

window.decorView.apply {
systemUiVisibility =
View.SYSTEM_UI_FLAG_FULLSCREEN or
View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN or
View.SYSTEM_UI_FLAG_LAYOUT_STABLE or
View.SYSTEM_UI_FLAG_HIDE_NAVIGATION or
View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
}

if (savedInstanceState == null) {
supportFragmentManager.beginTransaction()
.add(R.id.main_browse_fragment, playerFragment)
Expand All @@ -64,10 +81,6 @@ class MainActivity : FragmentActivity() {

gestureDetector = GestureDetector(this, GestureListener(this))

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

showTime()
}

Expand All @@ -82,6 +95,11 @@ class MainActivity : FragmentActivity() {
menuFragment.update()
}
}

if (!TVList.setPosition(SP.position)) {
Log.i(TAG, "setPosition 0")
TVList.setPosition(0)
}
}
}

Expand Down Expand Up @@ -618,15 +636,6 @@ class MainActivity : FragmentActivity() {
return super.onKeyDown(keyCode, event)
}

override fun onResume() {
super.onResume()
showTime()
}

override fun onStop() {
super.onStop()
}

companion object {
private const val TAG = "MainActivity"
}
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/java/com/lizongying/mytv0/SettingFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ class SettingFragment : Fragment() {
uriEditText.text = SP.config?.let { Editable.Factory.getInstance().newEditable(it) }
?: Editable.Factory.getInstance().newEditable("")
binding.confirmButton.setOnClickListener {
var uri = uriEditText.text.toString()
var uri = uriEditText.text.toString().trim()
uri = Utils.formatUrl(uri)
if (Uri.parse(uri).isAbsolute) {
TVList.update(uri)
Expand Down
41 changes: 20 additions & 21 deletions app/src/main/java/com/lizongying/mytv0/models/TVList.kt
Original file line number Diff line number Diff line change
Expand Up @@ -30,35 +30,34 @@ object TVList {
get() = _position

fun init(context: Context) {
appDirectory = context.filesDir
_position.value = 0

groupModel.addTVListModel(TVListModel("我的收藏"))

groupModel.addTVListModel(TVListModel("全部频道"))

appDirectory = context.filesDir
val file = File(appDirectory, FILE_NAME)
val str = if (file.exists()) {
Log.i(TAG, "local file")
file.readText()
} else {
Log.i(TAG, "read resource")
context.resources.openRawResource(R.raw.channels).bufferedReader()
.use { it.readText() }
}

try {
str2List(str)
} catch (e: Exception) {
Log.e("", "error $e")
file.deleteOnExit()
Toast.makeText(context, "读取频道失败,请在菜单中进行设置", Toast.LENGTH_LONG).show()
}

if (SP.configAutoLoad && !SP.config.isNullOrEmpty()) {
SP.config?.let {
update(it)
}
} else {
val file = File(appDirectory, FILE_NAME)
val str = if (file.exists()) {
Log.i(TAG, "local file")
file.readText()
} else {
Log.i(TAG, "read resource")
context.resources.openRawResource(R.raw.channels).bufferedReader()
.use { it.readText() }
}

try {
str2List(str)
} catch (e: Exception) {
Log.e("", "error $e")
file.deleteOnExit()
Toast.makeText(context, "读取频道失败,请在菜单中进行设置", Toast.LENGTH_LONG).show()
}
}
}

Expand Down Expand Up @@ -196,7 +195,6 @@ object TVList {
listModel = list.map { tv ->
TVModel(tv)
}
setPosition(0)

groupModel.clear()

Expand Down Expand Up @@ -230,6 +228,7 @@ object TVList {
}

fun setPosition(position: Int): Boolean {
Log.i(TAG, "size $position ${size()} ${listModel.size}")
if (position >= size()) {
return false
}
Expand Down
3 changes: 1 addition & 2 deletions app/src/main/res/layout/group_item.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,10 @@
android:orientation="vertical">

<TextView
android:id="@+id/textView"
android:id="@+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="start"
android:layout_marginTop="0dp"
android:layout_marginStart="10dp"
android:layout_marginBottom="5dp"
android:gravity="start"
Expand Down
19 changes: 9 additions & 10 deletions app/src/main/res/layout/list_item.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,28 +8,27 @@
android:background="#FF263238">

<ImageView
android:id="@+id/imageView"
android:id="@+id/icon"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_margin="5dp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
android:layout_marginEnd="0dp"
android:padding="5dp" />

<TextView
android:id="@+id/textView"
android:id="@+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintStart_toEndOf="@id/imageView"
app:layout_constraintStart_toEndOf="@id/icon"
app:layout_constraintTop_toTopOf="parent"
android:layout_marginStart="10dp"
android:textColor="#FFEEEEEE"
android:textSize="18sp" />

<ImageView
android:id="@+id/heart_icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/heart"
android:layout_width="30dp"
android:layout_height="30dp"
android:src="@drawable/ic_heart_empty_light"
android:contentDescription="Heart Icon"
app:layout_constraintEnd_toEndOf="parent"
Expand All @@ -41,8 +40,8 @@
android:id="@+id/description"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintStart_toEndOf="@id/imageView"
app:layout_constraintTop_toBottomOf="@id/textView"
app:layout_constraintStart_toEndOf="@id/icon"
app:layout_constraintTop_toBottomOf="@id/title"
android:text=""
android:textColor="#B3EEEEEE"
android:textSize="14sp" />
Expand Down
2 changes: 0 additions & 2 deletions app/src/main/res/layout/menu.xml
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/menu"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:background="@android:color/transparent"
android:clickable="true"
android:focusable="false"
>
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/layout/player.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
android:id="@+id/player_fragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/black"
android:background="@color/black"
android:keepScreenOn="true">

<SurfaceView
Expand Down
Loading

0 comments on commit 233e01f

Please sign in to comment.