mirror of
https://github.com/lizongying/my-tv.git
synced 2026-10-26 22:26:29 +08:00
menu style
This commit is contained in:
+1
-1
@@ -81,7 +81,7 @@ static def VersionCode() {
|
|||||||
|
|
||||||
static def VersionName() {
|
static def VersionName() {
|
||||||
try {
|
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()
|
process.waitFor()
|
||||||
return process.text.trim() - "v"
|
return process.text.trim() - "v"
|
||||||
} catch (ignored) {
|
} catch (ignored) {
|
||||||
|
|||||||
@@ -7,8 +7,8 @@ import android.view.View
|
|||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
import android.view.animation.ScaleAnimation
|
import android.view.animation.ScaleAnimation
|
||||||
import android.widget.ImageView
|
import android.widget.ImageView
|
||||||
|
import androidx.core.view.updatePadding
|
||||||
import androidx.leanback.widget.ImageCardView
|
import androidx.leanback.widget.ImageCardView
|
||||||
import androidx.lifecycle.LifecycleOwner
|
|
||||||
import androidx.recyclerview.widget.RecyclerView
|
import androidx.recyclerview.widget.RecyclerView
|
||||||
import com.bumptech.glide.Glide
|
import com.bumptech.glide.Glide
|
||||||
import com.lizongying.mytv.models.TVListViewModel
|
import com.lizongying.mytv.models.TVListViewModel
|
||||||
@@ -32,6 +32,7 @@ class CardAdapter(
|
|||||||
ImageCardView(ContextThemeWrapper(parent.context, R.style.CustomImageCardTheme)) {}
|
ImageCardView(ContextThemeWrapper(parent.context, R.style.CustomImageCardTheme)) {}
|
||||||
cardView.isFocusable = true
|
cardView.isFocusable = true
|
||||||
cardView.isFocusableInTouchMode = true
|
cardView.isFocusableInTouchMode = true
|
||||||
|
cardView.updatePadding(1, 1, 1, 1)
|
||||||
return ViewHolder(cardView)
|
return ViewHolder(cardView)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -48,7 +48,7 @@ val Context.appVersionCode: Long
|
|||||||
* Return the version name of the app which is defined in build.gradle.
|
* Return the version name of the app which is defined in build.gradle.
|
||||||
* eg:1.0.0
|
* eg:1.0.0
|
||||||
*/
|
*/
|
||||||
val Context.appVersionName: String get() = packageInfo.versionName
|
val Context.appVersionName: String get() = packageInfo.versionName ?: ""
|
||||||
|
|
||||||
val Context.appSignature: String
|
val Context.appSignature: String
|
||||||
get() {
|
get() {
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import android.graphics.Paint
|
|||||||
import android.graphics.Rect
|
import android.graphics.Rect
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import androidx.core.content.ContextCompat
|
import androidx.core.content.ContextCompat
|
||||||
|
import androidx.leanback.widget.ImageCardView
|
||||||
import androidx.recyclerview.widget.RecyclerView
|
import androidx.recyclerview.widget.RecyclerView
|
||||||
|
|
||||||
class GrayOverlayItemDecoration(private val context: Context) : RecyclerView.ItemDecoration() {
|
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) {
|
for (i in 0 until childCount) {
|
||||||
val child = parent.getChildAt(i)
|
val child = parent.getChildAt(i)
|
||||||
if (!child.hasFocus()) {
|
if (!child.hasFocus()) {
|
||||||
// child.alpha = 0.7f
|
(child as ImageCardView).setInfoAreaBackgroundColor(ContextCompat.getColor(context, R.color.blur))
|
||||||
|
// child.alpha = 0.5f
|
||||||
// 计算遮罩层的大小
|
// 计算遮罩层的大小
|
||||||
val overlayRect = Rect(
|
// val overlayRect = Rect(
|
||||||
child.left,
|
// child.left,
|
||||||
child.top,
|
// child.top,
|
||||||
child.right,
|
// child.right,
|
||||||
child.bottom
|
// child.bottom
|
||||||
)
|
// )
|
||||||
// 绘制灰色遮罩层
|
// // 绘制灰色遮罩层
|
||||||
c.drawRect(overlayRect, grayOverlayPaint)
|
// c.drawRect(overlayRect, grayOverlayPaint)
|
||||||
} else {
|
} else {
|
||||||
|
(child as ImageCardView).setInfoAreaBackgroundColor(ContextCompat.getColor(context, R.color.focus))
|
||||||
// child.alpha = 1f
|
// child.alpha = 1f
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ import android.widget.Toast
|
|||||||
import androidx.fragment.app.Fragment
|
import androidx.fragment.app.Fragment
|
||||||
import androidx.lifecycle.lifecycleScope
|
import androidx.lifecycle.lifecycleScope
|
||||||
import androidx.recyclerview.widget.GridLayoutManager
|
import androidx.recyclerview.widget.GridLayoutManager
|
||||||
|
import androidx.recyclerview.widget.LinearLayoutManager
|
||||||
import androidx.recyclerview.widget.RecyclerView
|
import androidx.recyclerview.widget.RecyclerView
|
||||||
import com.lizongying.mytv.Utils.dpToPx
|
import com.lizongying.mytv.Utils.dpToPx
|
||||||
import com.lizongying.mytv.api.YSP
|
import com.lizongying.mytv.api.YSP
|
||||||
@@ -82,10 +83,6 @@ class MainFragment : Fragment(), CardAdapter.ItemListener {
|
|||||||
itemBinding.rowHeader.text = k
|
itemBinding.rowHeader.text = k
|
||||||
itemBinding.rowItems.tag = idx.toInt()
|
itemBinding.rowItems.tag = idx.toInt()
|
||||||
itemBinding.rowItems.adapter = adapter
|
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() {
|
itemBinding.rowItems.addOnScrollListener(object : RecyclerView.OnScrollListener() {
|
||||||
override fun onScrolled(recyclerView: RecyclerView, dx: Int, dy: Int) {
|
override fun onScrolled(recyclerView: RecyclerView, dx: Int, dy: Int) {
|
||||||
@@ -99,6 +96,16 @@ class MainFragment : Fragment(), CardAdapter.ItemListener {
|
|||||||
itemBinding.rowItems.addItemDecoration(itemDecoration)
|
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
|
val layoutParams = itemBinding.row.layoutParams as ViewGroup.MarginLayoutParams
|
||||||
layoutParams.topMargin = dpToPx(11F)
|
layoutParams.topMargin = dpToPx(11F)
|
||||||
itemBinding.row.layoutParams = layoutParams
|
itemBinding.row.layoutParams = layoutParams
|
||||||
@@ -214,18 +221,26 @@ class MainFragment : Fragment(), CardAdapter.ItemListener {
|
|||||||
|
|
||||||
fun setPosition() {
|
fun setPosition() {
|
||||||
val tvViewModel = tvListViewModel.getTVViewModel(itemPosition)
|
val tvViewModel = tvListViewModel.getTVViewModel(itemPosition)
|
||||||
rowList[tvViewModel!!.getRowPosition()].post {
|
val rowPosition = tvViewModel!!.getRowPosition()
|
||||||
((rowList[tvViewModel.getRowPosition()] as RecyclerView).layoutManager as GridLayoutManager).findViewByPosition(
|
val itemPosition = tvViewModel.getItemPosition()
|
||||||
tvViewModel.getItemPosition()
|
setPosition(rowPosition, itemPosition)
|
||||||
)?.requestFocus()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fun setPosition(rowPosition: Int, itemPosition: Int) {
|
fun setPosition(rowPosition: Int, itemPosition: Int) {
|
||||||
rowList[rowPosition].post {
|
rowList[rowPosition].post {
|
||||||
((rowList[rowPosition] as RecyclerView).layoutManager as GridLayoutManager).findViewByPosition(
|
when (val layoutManager = (rowList[rowPosition] as RecyclerView).layoutManager) {
|
||||||
itemPosition
|
is GridLayoutManager -> {
|
||||||
)?.requestFocus()
|
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)
|
return tvModel == tvListViewModel.getTVViewModel(itemPosition)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -6,14 +6,21 @@ import android.content.SharedPreferences
|
|||||||
object SP {
|
object SP {
|
||||||
// Name of the sp file TODO Should use a meaningful name and do migrations
|
// Name of the sp file TODO Should use a meaningful name and do migrations
|
||||||
private const val SP_FILE_NAME = "MainActivity"
|
private const val SP_FILE_NAME = "MainActivity"
|
||||||
|
|
||||||
// If Change channel with up and down in reversed order or not
|
// If Change channel with up and down in reversed order or not
|
||||||
private const val KEY_CHANNEL_REVERSAL = "channel_reversal"
|
private const val KEY_CHANNEL_REVERSAL = "channel_reversal"
|
||||||
|
|
||||||
// If use channel num to select channel or not
|
// If use channel num to select channel or not
|
||||||
private const val KEY_CHANNEL_NUM = "channel_num"
|
private const val KEY_CHANNEL_NUM = "channel_num"
|
||||||
|
|
||||||
// If start app on device boot or not
|
// If start app on device boot or not
|
||||||
private const val KEY_BOOT_STARTUP = "boot_startup"
|
private const val KEY_BOOT_STARTUP = "boot_startup"
|
||||||
|
|
||||||
|
private const val KEY_GRID = "grid"
|
||||||
|
|
||||||
// Position in list of the selected channel item
|
// Position in list of the selected channel item
|
||||||
private const val KEY_POSITION = "position"
|
private const val KEY_POSITION = "position"
|
||||||
|
|
||||||
// guid
|
// guid
|
||||||
private const val KEY_GUID = "guid"
|
private const val KEY_GUID = "guid"
|
||||||
|
|
||||||
@@ -38,11 +45,15 @@ object SP {
|
|||||||
get() = sp.getBoolean(KEY_BOOT_STARTUP, false)
|
get() = sp.getBoolean(KEY_BOOT_STARTUP, false)
|
||||||
set(value) = sp.edit().putBoolean(KEY_BOOT_STARTUP, value).apply()
|
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
|
var itemPosition: Int
|
||||||
get() = sp.getInt(KEY_POSITION, 0)
|
get() = sp.getInt(KEY_POSITION, 0)
|
||||||
set(value) = sp.edit().putInt(KEY_POSITION, value).apply()
|
set(value) = sp.edit().putInt(KEY_POSITION, value).apply()
|
||||||
|
|
||||||
var guid: String
|
var guid: String
|
||||||
get() = sp.getString(KEY_GUID, "") ?: ""
|
get() = sp.getString(KEY_GUID, "") ?: ""
|
||||||
set(value) = sp.edit().putString(KEY_GUID, value).apply()
|
set(value) = sp.edit().putString(KEY_GUID, value).apply()
|
||||||
}
|
}
|
||||||
@@ -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)
|
updateManager = UpdateManager(context, this, context.appVersionCode)
|
||||||
binding.checkVersion.setOnClickListener(OnClickListenerCheckVersion(updateManager))
|
binding.checkVersion.setOnClickListener(OnClickListenerCheckVersion(updateManager))
|
||||||
|
|
||||||
|
|||||||
@@ -70,6 +70,12 @@
|
|||||||
android:layout_marginTop="10dp"
|
android:layout_marginTop="10dp"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content" />
|
android:layout_height="wrap_content" />
|
||||||
|
<Switch
|
||||||
|
android:id="@+id/switch_grid"
|
||||||
|
android:text="@string/title_grid"
|
||||||
|
android:layout_marginTop="10dp"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content" />
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
<ImageView
|
<ImageView
|
||||||
android:layout_width="300dp"
|
android:layout_width="300dp"
|
||||||
|
|||||||
@@ -3,4 +3,6 @@
|
|||||||
<color name="black">#000</color>
|
<color name="black">#000</color>
|
||||||
<color name="white">#FFF</color>
|
<color name="white">#FFF</color>
|
||||||
<color name="gray_overlay">#7F000000</color>
|
<color name="gray_overlay">#7F000000</color>
|
||||||
|
<color name="focus">#0096a6</color>
|
||||||
|
<color name="blur">#FF263238</color>
|
||||||
</resources>
|
</resources>
|
||||||
@@ -4,4 +4,5 @@
|
|||||||
<string name="title_channel_num">数字选台</string>
|
<string name="title_channel_num">数字选台</string>
|
||||||
<string name="check_version">检查更新</string>
|
<string name="check_version">检查更新</string>
|
||||||
<string name="title_boot_startup">开机自启</string>
|
<string name="title_boot_startup">开机自启</string>
|
||||||
|
<string name="title_grid">网格样式</string>
|
||||||
</resources>
|
</resources>
|
||||||
Reference in New Issue
Block a user