Skip to content

Commit

Permalink
menu style
Browse files Browse the repository at this point in the history
lizongying committed Mar 16, 2024

Verified

This commit was signed with the committer’s verified signature.
kayabaNerve Luke Parker
1 parent d03de91 commit 9450de2
Showing 10 changed files with 73 additions and 26 deletions.
2 changes: 1 addition & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
@@ -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) {
3 changes: 2 additions & 1 deletion app/src/main/java/com/lizongying/mytv/CardAdapter.kt
Original file line number Diff line number Diff line change
@@ -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)
}

2 changes: 1 addition & 1 deletion app/src/main/java/com/lizongying/mytv/Ext.kt
Original file line number Diff line number Diff line change
@@ -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() {
21 changes: 12 additions & 9 deletions app/src/main/java/com/lizongying/mytv/GrayOverlayItemDecoration.kt
Original file line number Diff line number Diff line change
@@ -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
}
}
41 changes: 28 additions & 13 deletions app/src/main/java/com/lizongying/mytv/MainFragment.kt
Original file line number Diff line number Diff line change
@@ -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)
}

13 changes: 12 additions & 1 deletion app/src/main/java/com/lizongying/mytv/SP.kt
Original file line number Diff line number Diff line change
@@ -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()
}
8 changes: 8 additions & 0 deletions app/src/main/java/com/lizongying/mytv/SettingFragment.kt
Original file line number Diff line number Diff line change
@@ -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))

6 changes: 6 additions & 0 deletions app/src/main/res/layout/dialog.xml
Original file line number Diff line number Diff line change
@@ -70,6 +70,12 @@
android:layout_marginTop="10dp"
android:layout_width="match_parent"
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>
<ImageView
android:layout_width="300dp"
2 changes: 2 additions & 0 deletions app/src/main/res/values/colors.xml
Original file line number Diff line number Diff line change
@@ -3,4 +3,6 @@
<color name="black">#000</color>
<color name="white">#FFF</color>
<color name="gray_overlay">#7F000000</color>
<color name="focus">#0096a6</color>
<color name="blur">#FF263238</color>
</resources>
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
@@ -4,4 +4,5 @@
<string name="title_channel_num">数字选台</string>
<string name="check_version">检查更新</string>
<string name="title_boot_startup">开机自启</string>
<string name="title_grid">网格样式</string>
</resources>

0 comments on commit 9450de2

Please sign in to comment.