diff --git a/app/build.gradle b/app/build.gradle
index 29d718fe..dbdb1e27 100644
--- a/app/build.gradle
+++ b/app/build.gradle
@@ -81,7 +81,7 @@ static def VersionCode() {
static def VersionName() {
try {
- def process = 'git describe --tags --always'.execute()
+ def process = "git describe --tags --always | sed 's/v/ /g' | sed 's/\\./ /g' | sed 's/-/ /g' | awk '{print \$1*16777216+\$2*65536+\$3*256+\$4}'".execute()
process.waitFor()
return process.text.trim() - "v"
} catch (ignored) {
diff --git a/app/src/main/java/com/lizongying/mytv/CardAdapter.kt b/app/src/main/java/com/lizongying/mytv/CardAdapter.kt
index 80ca6225..f6c2226a 100644
--- a/app/src/main/java/com/lizongying/mytv/CardAdapter.kt
+++ b/app/src/main/java/com/lizongying/mytv/CardAdapter.kt
@@ -7,8 +7,8 @@ import android.view.View
import android.view.ViewGroup
import android.view.animation.ScaleAnimation
import android.widget.ImageView
+import androidx.core.view.updatePadding
import androidx.leanback.widget.ImageCardView
-import androidx.lifecycle.LifecycleOwner
import androidx.recyclerview.widget.RecyclerView
import com.bumptech.glide.Glide
import com.lizongying.mytv.models.TVListViewModel
@@ -32,6 +32,7 @@ class CardAdapter(
ImageCardView(ContextThemeWrapper(parent.context, R.style.CustomImageCardTheme)) {}
cardView.isFocusable = true
cardView.isFocusableInTouchMode = true
+ cardView.updatePadding(1, 1, 1, 1)
return ViewHolder(cardView)
}
diff --git a/app/src/main/java/com/lizongying/mytv/Ext.kt b/app/src/main/java/com/lizongying/mytv/Ext.kt
index 1ba934d9..3a2d0bba 100644
--- a/app/src/main/java/com/lizongying/mytv/Ext.kt
+++ b/app/src/main/java/com/lizongying/mytv/Ext.kt
@@ -48,7 +48,7 @@ val Context.appVersionCode: Long
* Return the version name of the app which is defined in build.gradle.
* eg:1.0.0
*/
-val Context.appVersionName: String get() = packageInfo.versionName
+val Context.appVersionName: String get() = packageInfo.versionName ?: ""
val Context.appSignature: String
get() {
diff --git a/app/src/main/java/com/lizongying/mytv/GrayOverlayItemDecoration.kt b/app/src/main/java/com/lizongying/mytv/GrayOverlayItemDecoration.kt
index 859fb7e6..e2a1a2e5 100644
--- a/app/src/main/java/com/lizongying/mytv/GrayOverlayItemDecoration.kt
+++ b/app/src/main/java/com/lizongying/mytv/GrayOverlayItemDecoration.kt
@@ -6,6 +6,7 @@ import android.graphics.Paint
import android.graphics.Rect
import android.view.View
import androidx.core.content.ContextCompat
+import androidx.leanback.widget.ImageCardView
import androidx.recyclerview.widget.RecyclerView
class GrayOverlayItemDecoration(private val context: Context) : RecyclerView.ItemDecoration() {
@@ -22,17 +23,19 @@ class GrayOverlayItemDecoration(private val context: Context) : RecyclerView.Ite
for (i in 0 until childCount) {
val child = parent.getChildAt(i)
if (!child.hasFocus()) {
-// child.alpha = 0.7f
+ (child as ImageCardView).setInfoAreaBackgroundColor(ContextCompat.getColor(context, R.color.blur))
+// child.alpha = 0.5f
// 计算遮罩层的大小
- val overlayRect = Rect(
- child.left,
- child.top,
- child.right,
- child.bottom
- )
- // 绘制灰色遮罩层
- c.drawRect(overlayRect, grayOverlayPaint)
+// val overlayRect = Rect(
+// child.left,
+// child.top,
+// child.right,
+// child.bottom
+// )
+// // 绘制灰色遮罩层
+// c.drawRect(overlayRect, grayOverlayPaint)
} else {
+ (child as ImageCardView).setInfoAreaBackgroundColor(ContextCompat.getColor(context, R.color.focus))
// child.alpha = 1f
}
}
diff --git a/app/src/main/java/com/lizongying/mytv/MainFragment.kt b/app/src/main/java/com/lizongying/mytv/MainFragment.kt
index 17af6ab2..4f2c50ee 100644
--- a/app/src/main/java/com/lizongying/mytv/MainFragment.kt
+++ b/app/src/main/java/com/lizongying/mytv/MainFragment.kt
@@ -10,6 +10,7 @@ import android.widget.Toast
import androidx.fragment.app.Fragment
import androidx.lifecycle.lifecycleScope
import androidx.recyclerview.widget.GridLayoutManager
+import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.lizongying.mytv.Utils.dpToPx
import com.lizongying.mytv.api.YSP
@@ -82,10 +83,6 @@ class MainFragment : Fragment(), CardAdapter.ItemListener {
itemBinding.rowHeader.text = k
itemBinding.rowItems.tag = idx.toInt()
itemBinding.rowItems.adapter = adapter
- itemBinding.rowItems.layoutManager =
- GridLayoutManager(context, 6)
- itemBinding.rowItems.layoutParams.height =
- dpToPx(92 * ((tvListViewModelCurrent.size() + 6 - 1) / 6))
itemBinding.rowItems.addOnScrollListener(object : RecyclerView.OnScrollListener() {
override fun onScrolled(recyclerView: RecyclerView, dx: Int, dy: Int) {
@@ -99,6 +96,16 @@ class MainFragment : Fragment(), CardAdapter.ItemListener {
itemBinding.rowItems.addItemDecoration(itemDecoration)
}
+ if (SP.grid) {
+ itemBinding.rowItems.layoutManager =
+ GridLayoutManager(context, 6)
+ itemBinding.rowItems.layoutParams.height =
+ dpToPx(92 * ((tvListViewModelCurrent.size() + 6 - 1) / 6))
+ } else {
+ itemBinding.rowItems.layoutManager =
+ LinearLayoutManager(context, LinearLayoutManager.HORIZONTAL, false)
+ }
+
val layoutParams = itemBinding.row.layoutParams as ViewGroup.MarginLayoutParams
layoutParams.topMargin = dpToPx(11F)
itemBinding.row.layoutParams = layoutParams
@@ -214,18 +221,26 @@ class MainFragment : Fragment(), CardAdapter.ItemListener {
fun setPosition() {
val tvViewModel = tvListViewModel.getTVViewModel(itemPosition)
- rowList[tvViewModel!!.getRowPosition()].post {
- ((rowList[tvViewModel.getRowPosition()] as RecyclerView).layoutManager as GridLayoutManager).findViewByPosition(
- tvViewModel.getItemPosition()
- )?.requestFocus()
- }
+ val rowPosition = tvViewModel!!.getRowPosition()
+ val itemPosition = tvViewModel.getItemPosition()
+ setPosition(rowPosition, itemPosition)
}
fun setPosition(rowPosition: Int, itemPosition: Int) {
rowList[rowPosition].post {
- ((rowList[rowPosition] as RecyclerView).layoutManager as GridLayoutManager).findViewByPosition(
- itemPosition
- )?.requestFocus()
+ when (val layoutManager = (rowList[rowPosition] as RecyclerView).layoutManager) {
+ is GridLayoutManager -> {
+ layoutManager.findViewByPosition(
+ itemPosition
+ )?.requestFocus()
+ }
+
+ is LinearLayoutManager -> {
+ layoutManager.findViewByPosition(
+ itemPosition
+ )?.requestFocus()
+ }
+ }
}
}
@@ -292,7 +307,7 @@ class MainFragment : Fragment(), CardAdapter.ItemListener {
}
}
- fun shouldHasFocus(tvModel: TVViewModel):Boolean {
+ fun shouldHasFocus(tvModel: TVViewModel): Boolean {
return tvModel == tvListViewModel.getTVViewModel(itemPosition)
}
diff --git a/app/src/main/java/com/lizongying/mytv/SP.kt b/app/src/main/java/com/lizongying/mytv/SP.kt
index 583bd5fc..d967b8a9 100644
--- a/app/src/main/java/com/lizongying/mytv/SP.kt
+++ b/app/src/main/java/com/lizongying/mytv/SP.kt
@@ -6,14 +6,21 @@ import android.content.SharedPreferences
object SP {
// Name of the sp file TODO Should use a meaningful name and do migrations
private const val SP_FILE_NAME = "MainActivity"
+
// If Change channel with up and down in reversed order or not
private const val KEY_CHANNEL_REVERSAL = "channel_reversal"
+
// If use channel num to select channel or not
private const val KEY_CHANNEL_NUM = "channel_num"
+
// If start app on device boot or not
private const val KEY_BOOT_STARTUP = "boot_startup"
+
+ private const val KEY_GRID = "grid"
+
// Position in list of the selected channel item
private const val KEY_POSITION = "position"
+
// guid
private const val KEY_GUID = "guid"
@@ -38,11 +45,15 @@ object SP {
get() = sp.getBoolean(KEY_BOOT_STARTUP, false)
set(value) = sp.edit().putBoolean(KEY_BOOT_STARTUP, value).apply()
+ var grid: Boolean
+ get() = sp.getBoolean(KEY_GRID, false)
+ set(value) = sp.edit().putBoolean(KEY_GRID, value).apply()
+
var itemPosition: Int
get() = sp.getInt(KEY_POSITION, 0)
set(value) = sp.edit().putInt(KEY_POSITION, value).apply()
var guid: String
- get() = sp.getString(KEY_GUID, "") ?: ""
+ get() = sp.getString(KEY_GUID, "") ?: ""
set(value) = sp.edit().putString(KEY_GUID, value).apply()
}
\ No newline at end of file
diff --git a/app/src/main/java/com/lizongying/mytv/SettingFragment.kt b/app/src/main/java/com/lizongying/mytv/SettingFragment.kt
index dbf63b52..ef2e271d 100644
--- a/app/src/main/java/com/lizongying/mytv/SettingFragment.kt
+++ b/app/src/main/java/com/lizongying/mytv/SettingFragment.kt
@@ -54,6 +54,14 @@ class SettingFragment : DialogFragment() {
}
}
+ binding.switchGrid.run {
+ isChecked = SP.grid
+ setOnCheckedChangeListener { _, isChecked ->
+ SP.grid = isChecked
+ (activity as MainActivity).settingActive()
+ }
+ }
+
updateManager = UpdateManager(context, this, context.appVersionCode)
binding.checkVersion.setOnClickListener(OnClickListenerCheckVersion(updateManager))
diff --git a/app/src/main/res/layout/dialog.xml b/app/src/main/res/layout/dialog.xml
index bb69502c..932f650f 100644
--- a/app/src/main/res/layout/dialog.xml
+++ b/app/src/main/res/layout/dialog.xml
@@ -70,6 +70,12 @@
android:layout_marginTop="10dp"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
+
#000
#FFF
#7F000000
+ #0096a6
+ #FF263238
\ No newline at end of file
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index 36adfb65..c70c4f78 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -4,4 +4,5 @@
数字选台
检查更新
开机自启
+ 网格样式
\ No newline at end of file