diff --git a/HISTORY.md b/HISTORY.md
index 0f804087..3d36febb 100644
--- a/HISTORY.md
+++ b/HISTORY.md
@@ -1,5 +1,9 @@
## 更新日志
+### v1.8.8(通用)
+
+* 样式优化
+
### v1.8.6(通用)
* 增加错误显示
diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml
index 4866ff51..3914f7d6 100644
--- a/app/src/main/AndroidManifest.xml
+++ b/app/src/main/AndroidManifest.xml
@@ -36,6 +36,9 @@
+
+
+
\ No newline at end of file
diff --git a/app/src/main/java/com/lizongying/mytv/ChannelFragment.kt b/app/src/main/java/com/lizongying/mytv/ChannelFragment.kt
index 9a47525c..0a8fb7ac 100644
--- a/app/src/main/java/com/lizongying/mytv/ChannelFragment.kt
+++ b/app/src/main/java/com/lizongying/mytv/ChannelFragment.kt
@@ -30,37 +30,19 @@ class ChannelFragment : Fragment() {
val application = requireActivity().applicationContext as MyTvApplication
- val width = application.getWidth()
- val height = application.getHeight()
-
- val ratio = 16f / 9f
-
- if (width.toFloat() / height > ratio) {
- val x =
- ((Resources.getSystem().displayMetrics.widthPixels - height * ratio) / 2).toInt()
- val originalLayoutParams =
- binding.channel.layoutParams as ViewGroup.MarginLayoutParams
- originalLayoutParams.marginEnd += x
- binding.channel.layoutParams = originalLayoutParams
- }
-
- if (width.toFloat() / height < ratio) {
- val y =
- ((height - Resources.getSystem().displayMetrics.widthPixels / ratio) / 2).toInt()
- val originalLayoutParams =
- binding.channel.layoutParams as ViewGroup.MarginLayoutParams
- originalLayoutParams.topMargin += y
- binding.channel.layoutParams = originalLayoutParams
- }
-
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()
+
(activity as MainActivity).fragmentReady("ChannelFragment")
return binding.root
}
diff --git a/app/src/main/java/com/lizongying/mytv/InfoFragment.kt b/app/src/main/java/com/lizongying/mytv/InfoFragment.kt
index 6873e70f..5d3c9527 100644
--- a/app/src/main/java/com/lizongying/mytv/InfoFragment.kt
+++ b/app/src/main/java/com/lizongying/mytv/InfoFragment.kt
@@ -30,24 +30,14 @@ class InfoFragment : Fragment() {
_binding = InfoBinding.inflate(inflater, container, false)
val application = requireActivity().applicationContext as MyTvApplication
- val width = application.getWidth()
- val height = application.getHeight()
-
- val ratio = 16f / 9f
-
- if (width.toFloat() / height < ratio) {
- val y =
- ((height - Resources.getSystem().displayMetrics.widthPixels / ratio) / 2).toInt()
- val originalLayoutParams = binding.info.layoutParams as ViewGroup.MarginLayoutParams
- originalLayoutParams.bottomMargin += y
- binding.info.layoutParams = originalLayoutParams
- }
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)
binding.logo.setPadding(application.px2Px(binding.logo.paddingTop))
binding.main.layoutParams.width = application.px2Px(binding.main.layoutParams.width)
@@ -64,6 +54,9 @@ class InfoFragment : Fragment() {
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
(activity as MainActivity).fragmentReady("InfoFragment")
@@ -71,6 +64,9 @@ class InfoFragment : Fragment() {
}
fun show(tvViewModel: TVViewModel) {
+ if (_binding == null) {
+ return
+ }
binding.title.text = tvViewModel.getTV().title
Glide.with(this)
diff --git a/app/src/main/java/com/lizongying/mytv/LoadingFragment.kt b/app/src/main/java/com/lizongying/mytv/LoadingFragment.kt
new file mode 100644
index 00000000..11420947
--- /dev/null
+++ b/app/src/main/java/com/lizongying/mytv/LoadingFragment.kt
@@ -0,0 +1,37 @@
+package com.lizongying.mytv
+
+import android.os.Bundle
+import android.view.LayoutInflater
+import android.view.View
+import android.view.ViewGroup
+import androidx.fragment.app.Fragment
+import com.lizongying.mytv.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).fragmentReady(TAG)
+ return binding.root
+ }
+
+ override fun onDestroyView() {
+ super.onDestroyView()
+ _binding = null
+ }
+
+ companion object {
+ private const val TAG = "LoadingFragment"
+ }
+}
\ No newline at end of file
diff --git a/app/src/main/java/com/lizongying/mytv/MainActivity.kt b/app/src/main/java/com/lizongying/mytv/MainActivity.kt
index 9c626db3..1f433a32 100644
--- a/app/src/main/java/com/lizongying/mytv/MainActivity.kt
+++ b/app/src/main/java/com/lizongying/mytv/MainActivity.kt
@@ -11,7 +11,10 @@ import android.util.Log
import android.view.GestureDetector
import android.view.KeyEvent
import android.view.MotionEvent
+import android.view.View.SYSTEM_UI_FLAG_FULLSCREEN
import android.view.View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
+import android.view.View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
+import android.view.View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
import android.view.WindowManager
import android.widget.Toast
import androidx.fragment.app.FragmentActivity
@@ -29,6 +32,8 @@ class MainActivity : FragmentActivity(), Request.RequestListener {
private var ready = 0
private val playerFragment = PlayerFragment()
private val errorFragment = ErrorFragment()
+
+ // private val loadingFragment = LoadingFragment()
private val mainFragment = MainFragment()
private val infoFragment = InfoFragment()
private val channelFragment = ChannelFragment()
@@ -56,25 +61,34 @@ class MainActivity : FragmentActivity(), Request.RequestListener {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
-
setContentView(R.layout.activity_main)
Request.setRequestListener(this)
window.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON)
window.addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN)
- window.decorView.systemUiVisibility = SYSTEM_UI_FLAG_HIDE_NAVIGATION
+ window.decorView.systemUiVisibility =
+ SYSTEM_UI_FLAG_FULLSCREEN or
+ SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN or SYSTEM_UI_FLAG_HIDE_NAVIGATION or
+ SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
+// if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
+// window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS)
+// window.statusBarColor = Color.TRANSPARENT
+// window.navigationBarColor = Color.TRANSPARENT
+// }
if (savedInstanceState == null) {
supportFragmentManager.beginTransaction()
.add(R.id.main_browse_fragment, playerFragment)
.add(R.id.main_browse_fragment, errorFragment)
+// .add(R.id.main_browse_fragment, loadingFragment)
.add(R.id.main_browse_fragment, timeFragment)
.add(R.id.main_browse_fragment, infoFragment)
.add(R.id.main_browse_fragment, channelFragment)
.add(R.id.main_browse_fragment, mainFragment)
.hide(mainFragment)
.hide(errorFragment)
+// .hide(loadingFragment)
.commit()
}
gestureDetector = GestureDetector(this, GestureListener())
diff --git a/app/src/main/java/com/lizongying/mytv/MainFragment.kt b/app/src/main/java/com/lizongying/mytv/MainFragment.kt
index 9e32fe22..4d842514 100644
--- a/app/src/main/java/com/lizongying/mytv/MainFragment.kt
+++ b/app/src/main/java/com/lizongying/mytv/MainFragment.kt
@@ -1,6 +1,7 @@
package com.lizongying.mytv
import android.content.res.Resources
+import android.graphics.Color
import android.os.Bundle
import android.util.Log
import android.view.KeyEvent
@@ -51,37 +52,10 @@ class MainFragment : Fragment(), CardAdapter.ItemListener {
application = requireActivity().applicationContext as MyTvApplication
- val width = application.getWidth()
- val height = application.getHeight()
+ binding.menu.layoutParams.width = application.shouldWidthPx()
+ binding.menu.layoutParams.height = application.shouldHeightPx()
- val ratio = 16f / 9f
-
- if (width.toFloat() / height > ratio) {
- val x =
- ((Resources.getSystem().displayMetrics.widthPixels - height * ratio) / 2).toInt()
- val originalLayoutParams =
- binding.scroll.layoutParams as ViewGroup.MarginLayoutParams
- originalLayoutParams.marginStart += x
- originalLayoutParams.marginEnd += x
- binding.scroll.layoutParams = originalLayoutParams
-
- Log.i(
- TAG,
- "binding.scroll ${Resources.getSystem().displayMetrics.widthPixels} ${height * ratio}"
- )
- }
-
- if (width.toFloat() / height < ratio) {
- val y =
- ((height - Resources.getSystem().displayMetrics.widthPixels / ratio) / 2).toInt()
- val originalLayoutParams =
- binding.scroll.layoutParams as ViewGroup.MarginLayoutParams
- originalLayoutParams.topMargin += y
- originalLayoutParams.bottomMargin += y
- binding.scroll.layoutParams = originalLayoutParams
- }
-
- binding.menu.setOnClickListener {
+ binding.container.setOnClickListener {
hideSelf()
}
@@ -278,7 +252,7 @@ class MainFragment : Fragment(), CardAdapter.ItemListener {
for (i in rowList) {
if (i.tag as Int != row) {
((i as RecyclerView).adapter as CardAdapter).focusable = false
- ((i as RecyclerView).adapter as CardAdapter).clear()
+ (i.adapter as CardAdapter).clear()
} else {
((i as RecyclerView).adapter as CardAdapter).focusable = true
}
@@ -435,13 +409,6 @@ class MainFragment : Fragment(), CardAdapter.ItemListener {
super.onResume()
}
- override fun onStop() {
- Log.i(TAG, "onStop")
- super.onStop()
- SP.itemPosition = itemPosition
- Log.i(TAG, "$POSITION $itemPosition saved")
- }
-
override fun onDestroy() {
Log.i(TAG, "onDestroy")
super.onDestroy()
diff --git a/app/src/main/java/com/lizongying/mytv/MyTvApplication.kt b/app/src/main/java/com/lizongying/mytv/MyTvApplication.kt
index 72ea6724..7dc93dc7 100644
--- a/app/src/main/java/com/lizongying/mytv/MyTvApplication.kt
+++ b/app/src/main/java/com/lizongying/mytv/MyTvApplication.kt
@@ -12,8 +12,12 @@ class MyTvApplication : Application() {
private lateinit var displayMetrics: DisplayMetrics
private lateinit var realDisplayMetrics: DisplayMetrics
+ private lateinit var windowManager: WindowManager
+
private var width = 0
private var height = 0
+ private var shouldWidth = 0
+ private var shouldHeight = 0
private var deviation = 0
private var ratio = 1.0
private var density = 2.0f
@@ -24,7 +28,7 @@ class MyTvApplication : Application() {
displayMetrics = DisplayMetrics()
realDisplayMetrics = DisplayMetrics()
- val windowManager = getSystemService(Context.WINDOW_SERVICE) as WindowManager
+ windowManager = getSystemService(Context.WINDOW_SERVICE) as WindowManager
windowManager.defaultDisplay.getMetrics(displayMetrics)
windowManager.defaultDisplay.getRealMetrics(realDisplayMetrics)
@@ -44,6 +48,16 @@ class MyTvApplication : Application() {
height * 2 / 1080.0 / density
}
+ if ((width.toDouble() / height) < (16.0 / 9.0)) {
+ ratio = width * 2 / 1920.0 / density
+ shouldWidth = width
+ shouldHeight = (width * 9.0 / 16.0).toInt()
+ } else {
+ ratio = height * 2 / 1080.0 / density
+ shouldHeight = height
+ shouldWidth = (height * 16.0 / 9.0).toInt()
+ }
+
deviation = width - Resources.getSystem().displayMetrics.widthPixels
scale = Resources.getSystem().displayMetrics.scaledDensity
}
@@ -56,18 +70,26 @@ class MyTvApplication : Application() {
return realDisplayMetrics
}
- fun getWidth(): Int {
- return width
+ fun shouldWidthPx(): Int {
+ return shouldWidth
}
- fun getDeviation(): Int {
- return deviation
+ fun shouldHeightPx(): Int {
+ return shouldHeight
+ }
+
+ fun getWidth(): Int {
+ return width
}
fun getHeight(): Int {
return height
}
+ fun getDeviation(): Int {
+ return deviation
+ }
+
fun getRatio(): Double {
return ratio
}
diff --git a/app/src/main/java/com/lizongying/mytv/SettingFragment.kt b/app/src/main/java/com/lizongying/mytv/SettingFragment.kt
index f52f0043..1fc1a328 100644
--- a/app/src/main/java/com/lizongying/mytv/SettingFragment.kt
+++ b/app/src/main/java/com/lizongying/mytv/SettingFragment.kt
@@ -101,9 +101,9 @@ class SettingFragment : DialogFragment() {
)
binding.name.textSize = application.px2PxFont(binding.name.textSize)
binding.version.textSize = application.px2PxFont(binding.version.textSize)
- val layoutParamsDesc = binding.version.layoutParams as ViewGroup.MarginLayoutParams
- layoutParamsDesc.topMargin = application.px2Px(binding.version.marginTop)
- binding.version.layoutParams = layoutParamsDesc
+ val layoutParamsVersion = binding.version.layoutParams as ViewGroup.MarginLayoutParams
+ layoutParamsVersion.topMargin = application.px2Px(binding.version.marginTop)
+ binding.version.layoutParams = layoutParamsVersion
binding.checkVersion.textSize = application.px2PxFont(binding.checkVersion.textSize)
val layoutParamsCheckVersion =
diff --git a/app/src/main/java/com/lizongying/mytv/TimeFragment.kt b/app/src/main/java/com/lizongying/mytv/TimeFragment.kt
index 0602e6ca..7feca63d 100644
--- a/app/src/main/java/com/lizongying/mytv/TimeFragment.kt
+++ b/app/src/main/java/com/lizongying/mytv/TimeFragment.kt
@@ -27,35 +27,19 @@ class TimeFragment : Fragment() {
val application = requireActivity().applicationContext as MyTvApplication
- val width = application.getWidth()
- val height = application.getHeight()
-
- val ratio = 16f / 9f
-
- if (width.toFloat() / height > ratio) {
- val x =
- ((Resources.getSystem().displayMetrics.widthPixels - height * ratio) / 2).toInt()
- val originalLayoutParams = binding.time.layoutParams as ViewGroup.MarginLayoutParams
- originalLayoutParams.marginEnd += x
- binding.time.layoutParams = originalLayoutParams
- }
-
- if (width.toFloat() / height < ratio) {
- val y =
- ((height - Resources.getSystem().displayMetrics.widthPixels / ratio) / 2).toInt()
- val originalLayoutParams = binding.time.layoutParams as ViewGroup.MarginLayoutParams
- originalLayoutParams.topMargin += y
- binding.time.layoutParams = originalLayoutParams
- }
-
binding.time.layoutParams.width = application.px2Px(binding.time.layoutParams.width)
binding.time.layoutParams.height = application.px2Px(binding.time.layoutParams.height)
+
val layoutParams = binding.time.layoutParams as ViewGroup.MarginLayoutParams
layoutParams.topMargin = application.px2Px(binding.time.marginTop)
layoutParams.marginEnd = application.px2Px(binding.time.marginEnd)
binding.time.layoutParams = layoutParams
+
binding.content.textSize = application.px2PxFont(binding.content.textSize)
+ binding.main.layoutParams.width = application.shouldWidthPx()
+ binding.main.layoutParams.height = application.shouldHeightPx()
+
(activity as MainActivity).fragmentReady("TimeFragment")
return binding.root
}
diff --git a/app/src/main/java/com/lizongying/mytv/models/TVListViewModel.kt b/app/src/main/java/com/lizongying/mytv/models/TVListViewModel.kt
index b44ccf52..e4a3df82 100644
--- a/app/src/main/java/com/lizongying/mytv/models/TVListViewModel.kt
+++ b/app/src/main/java/com/lizongying/mytv/models/TVListViewModel.kt
@@ -3,6 +3,7 @@ package com.lizongying.mytv.models
import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel
+import com.lizongying.mytv.SP
class TVListViewModel : ViewModel() {
@@ -30,6 +31,7 @@ class TVListViewModel : ViewModel() {
fun setItemPosition(position: Int) {
_itemPosition.value = position
+ SP.itemPosition = position
}
fun size(): Int {
diff --git a/app/src/main/java/com/lizongying/mytv/models/TVViewModel.kt b/app/src/main/java/com/lizongying/mytv/models/TVViewModel.kt
index c0e372f4..e144c655 100644
--- a/app/src/main/java/com/lizongying/mytv/models/TVViewModel.kt
+++ b/app/src/main/java/com/lizongying/mytv/models/TVViewModel.kt
@@ -16,6 +16,8 @@ class TVViewModel(private var tv: TV) : ViewModel() {
var retryTimes = 0
var retryMaxTimes = 8
+ var authYSPRetryTimes = 0
+ var authYSPRetryMaxTimes = 3
var tokenYSPRetryTimes = 0
var tokenYSPRetryMaxTimes = 0
var tokenFHRetryTimes = 0
diff --git a/app/src/main/res/drawable/sad_cloud.xml b/app/src/main/res/drawable/sad_cloud.xml
index 37bdf840..0e783c3c 100644
--- a/app/src/main/res/drawable/sad_cloud.xml
+++ b/app/src/main/res/drawable/sad_cloud.xml
@@ -1,4 +1,4 @@
-
-
+
+
-
-
\ No newline at end of file
+
+
+
+
+
+
\ No newline at end of file
diff --git a/app/src/main/res/layout/error.xml b/app/src/main/res/layout/error.xml
index ec0c248f..45cf9120 100644
--- a/app/src/main/res/layout/error.xml
+++ b/app/src/main/res/layout/error.xml
@@ -2,14 +2,14 @@
+ android:layout_height="match_parent"
+ android:background="@color/black" >
-
-
-
+
+ >
-
+
+
+
+
+
-
+
-
-
-
\ No newline at end of file
+
+
+
+
+
\ No newline at end of file
diff --git a/app/src/main/res/layout/loading.xml b/app/src/main/res/layout/loading.xml
new file mode 100644
index 00000000..a0c362bf
--- /dev/null
+++ b/app/src/main/res/layout/loading.xml
@@ -0,0 +1,21 @@
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/app/src/main/res/layout/menu.xml b/app/src/main/res/layout/menu.xml
index 3acdc4c0..176d9787 100644
--- a/app/src/main/res/layout/menu.xml
+++ b/app/src/main/res/layout/menu.xml
@@ -1,21 +1,32 @@
-
-
+
+
-
-
-
-
\ No newline at end of file
+ android:layout_height="match_parent"
+>
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/app/src/main/res/layout/setting.xml b/app/src/main/res/layout/setting.xml
index f88a37db..bb7dabb3 100644
--- a/app/src/main/res/layout/setting.xml
+++ b/app/src/main/res/layout/setting.xml
@@ -13,8 +13,8 @@
android:layout_height="match_parent"
android:orientation="vertical"
android:paddingTop="20dp"
- android:paddingLeft="7dp"
- android:paddingRight="7dp"
+ android:paddingLeft="10dp"
+ android:paddingRight="10dp"
android:background="@drawable/rounded_dark_left"
>
-
+
+
-
-
\ No newline at end of file
+
+
+
+
+
+
+
\ 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 221be7a8..58eaef4a 100644
--- a/app/src/main/res/values/themes.xml
+++ b/app/src/main/res/values/themes.xml
@@ -1,5 +1,6 @@
\ No newline at end of file