diff --git a/README.md b/README.md index 348d5081..57e897d8 100644 --- a/README.md +++ b/README.md @@ -50,6 +50,11 @@ ## 更新日志 +### v1.1.4 + +* 默认使用上次缓存视频源 +* 样式优化 + ### v1.1.3 * 修复m3u解析错误 diff --git a/app/src/main/java/com/lizongying/mytv0/GroupAdapter.kt b/app/src/main/java/com/lizongying/mytv0/GroupAdapter.kt index e429f16e..5b01ad2b 100644 --- a/app/src/main/java/com/lizongying/mytv0/GroupAdapter.kt +++ b/app/src/main/java/com/lizongying/mytv0/GroupAdapter.kt @@ -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 @@ -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) @@ -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 diff --git a/app/src/main/java/com/lizongying/mytv0/ListAdapter.kt b/app/src/main/java/com/lizongying/mytv0/ListAdapter.kt index 76419d35..4c02247f 100644 --- a/app/src/main/java/com/lizongying/mytv0/ListAdapter.kt +++ b/app/src/main/java/com/lizongying/mytv0/ListAdapter.kt @@ -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 @@ -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) } @@ -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) } @@ -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) { @@ -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, diff --git a/app/src/main/java/com/lizongying/mytv0/MainActivity.kt b/app/src/main/java/com/lizongying/mytv0/MainActivity.kt index 3cd200a3..cee1027a 100644 --- a/app/src/main/java/com/lizongying/mytv0/MainActivity.kt +++ b/app/src/main/java/com/lizongying/mytv0/MainActivity.kt @@ -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 @@ -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) @@ -64,10 +81,6 @@ class MainActivity : FragmentActivity() { gestureDetector = GestureDetector(this, GestureListener(this)) - if (!TVList.setPosition(SP.position)) { - TVList.setPosition(0) - } - showTime() } @@ -82,6 +95,11 @@ class MainActivity : FragmentActivity() { menuFragment.update() } } + + if (!TVList.setPosition(SP.position)) { + Log.i(TAG, "setPosition 0") + TVList.setPosition(0) + } } } @@ -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" } diff --git a/app/src/main/java/com/lizongying/mytv0/SettingFragment.kt b/app/src/main/java/com/lizongying/mytv0/SettingFragment.kt index ba778e9a..ccd2734d 100644 --- a/app/src/main/java/com/lizongying/mytv0/SettingFragment.kt +++ b/app/src/main/java/com/lizongying/mytv0/SettingFragment.kt @@ -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) diff --git a/app/src/main/java/com/lizongying/mytv0/models/TVList.kt b/app/src/main/java/com/lizongying/mytv0/models/TVList.kt index 9653d3e4..854047d3 100644 --- a/app/src/main/java/com/lizongying/mytv0/models/TVList.kt +++ b/app/src/main/java/com/lizongying/mytv0/models/TVList.kt @@ -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() - } } } @@ -196,7 +195,6 @@ object TVList { listModel = list.map { tv -> TVModel(tv) } - setPosition(0) groupModel.clear() @@ -230,6 +228,7 @@ object TVList { } fun setPosition(position: Int): Boolean { + Log.i(TAG, "size $position ${size()} ${listModel.size}") if (position >= size()) { return false } diff --git a/app/src/main/res/layout/group_item.xml b/app/src/main/res/layout/group_item.xml index d7a31f26..f7b3be14 100644 --- a/app/src/main/res/layout/group_item.xml +++ b/app/src/main/res/layout/group_item.xml @@ -6,11 +6,10 @@ android:orientation="vertical"> diff --git a/app/src/main/res/layout/menu.xml b/app/src/main/res/layout/menu.xml index f92b699c..78f2f49e 100644 --- a/app/src/main/res/layout/menu.xml +++ b/app/src/main/res/layout/menu.xml @@ -1,11 +1,9 @@ diff --git a/app/src/main/res/layout/player.xml b/app/src/main/res/layout/player.xml index 0c57668a..ef52f4d1 100644 --- a/app/src/main/res/layout/player.xml +++ b/app/src/main/res/layout/player.xml @@ -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"> - + @@ -66,12 +70,12 @@ android:id="@+id/confirm_button" android:layout_width="100dp" android:layout_height="45dp" - android:layout_marginEnd="10dp" + android:layout_marginEnd="5dp" android:textSize="14sp" android:text="@string/confirm" /> + \ No newline at end of file diff --git a/app/src/main/res/values/themes.xml b/app/src/main/res/values/themes.xml index 05b5474e..343565fb 100644 --- a/app/src/main/res/values/themes.xml +++ b/app/src/main/res/values/themes.xml @@ -1,4 +1,5 @@ - \ No newline at end of file