Skip to content

Commit

Permalink
hide all channel option
Browse files Browse the repository at this point in the history
  • Loading branch information
lizongying committed Aug 5, 2024
1 parent be53488 commit a819b61
Show file tree
Hide file tree
Showing 20 changed files with 671 additions and 402 deletions.
6 changes: 6 additions & 0 deletions HISTORY.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
## 更新日志

### v1.3.2

* 固定遠程配置端口為34567
* 優化配置樣式
* 可配置是否顯示全部頻道

### v1.3.1

* 恢復默認後,立即更新視頻源
Expand Down
2 changes: 0 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,6 @@ adb install my-tv-0.apk
* 支持回看
* 詳細EPG
* 淺色菜單
* 是否顯示全部頻道
* 固定網絡配置端口
* 無效的頻道?

## 讚賞
Expand Down
8 changes: 8 additions & 0 deletions app/src/main/java/com/lizongying/mytv0/Ext.kt
Original file line number Diff line number Diff line change
Expand Up @@ -86,4 +86,12 @@ private fun hashSignature(signature: Signature): String {

fun String.showToast(duration: Int = Toast.LENGTH_SHORT) {
MyTVApplication.getInstance().toast(this, duration)
}

fun Int.getString(): String {
return MyTVApplication.getInstance().getString(this)
}

fun Int.showToast(duration: Int = Toast.LENGTH_SHORT) {
this.getString().showToast(duration)
}
5 changes: 2 additions & 3 deletions app/src/main/java/com/lizongying/mytv0/GroupAdapter.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import android.view.KeyEvent
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.Toast
import androidx.core.content.ContextCompat
import androidx.core.view.marginBottom
import androidx.core.view.marginStart
Expand Down Expand Up @@ -103,9 +102,9 @@ class GroupAdapter(
val oldLikeMode = tvGroupModel.isInLikeMode;
tvGroupModel.isInLikeMode = position == 0
if (tvGroupModel.isInLikeMode) {
Toast.makeText(context, "收藏模式", Toast.LENGTH_SHORT).show()
R.string.favorite_mode.showToast()
} else if (oldLikeMode) {
Toast.makeText(context, "标准模式", Toast.LENGTH_SHORT).show()
R.string.standard_mode.showToast()
}
}, 500)
}
Expand Down
34 changes: 34 additions & 0 deletions app/src/main/java/com/lizongying/mytv0/LocaleContextWrapper.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package com.lizongying.mytv0

import android.content.Context
import android.content.ContextWrapper
import android.os.Build
import android.os.LocaleList
import java.util.Locale

class LocaleContextWrapper(base: Context) : ContextWrapper(base) {
companion object {
fun wrap(context: Context, newLocale: Locale): ContextWrapper {
val resources = context.resources
val configuration = resources.configuration

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
configuration.setLocale(newLocale)
val localeList = LocaleList(newLocale)
LocaleList.setDefault(localeList)
configuration.setLocales(localeList)
} else {
configuration.locale = newLocale
}

val updatedContext = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N_MR1) {
context.createConfigurationContext(configuration)
} else {
resources.updateConfiguration(configuration, resources.displayMetrics)
context
}

return LocaleContextWrapper(updatedContext)
}
}
}
55 changes: 37 additions & 18 deletions app/src/main/java/com/lizongying/mytv0/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ import androidx.core.view.WindowInsetsCompat
import androidx.core.view.WindowInsetsControllerCompat
import androidx.fragment.app.Fragment
import androidx.fragment.app.FragmentActivity
import com.lizongying.mytv0.models.TVGroupModel
import com.lizongying.mytv0.models.TVList
import java.util.Locale


class MainActivity : FragmentActivity() {
Expand Down Expand Up @@ -116,6 +116,10 @@ class MainActivity : FragmentActivity() {
showTime()
}

fun update() {
menuFragment.update()
}

fun ready(tag: String) {
Log.i(TAG, "ready $tag")
ok++
Expand All @@ -134,38 +138,37 @@ class MainActivity : FragmentActivity() {
// TVList.groupModel.setPosition(0)
// val tvModel = TVList.listModel.find { it.like.value as Boolean }
// TVList.setPosition(tvModel?.tv?.id ?: 0)
// "播放收藏频道".showToast(Toast.LENGTH_LONG)
// "播放收藏频道".showToast()
// }

if (SP.channel > 0) {
if (SP.channel < TVList.listModel.size) {
TVList.setPosition(SP.channel - 1)
"播放默认频道".showToast(Toast.LENGTH_LONG)
R.string.play_default_channel.showToast()
} else {
SP.channel = 0
TVList.setPosition(0)
"默认频道超出频道列表范围,已自动设置为0".showToast(Toast.LENGTH_LONG)
R.string.default_channel_out_of_range.showToast()
}
} else {
if (!TVList.setPosition(SP.position)) {
TVList.setPosition(0)
"上次频道超出频道列表范围,已自动设置为0".showToast(Toast.LENGTH_LONG)
R.string.last_channel_out_of_range.showToast()
} else {
"播放上次频道".showToast(Toast.LENGTH_LONG)
R.string.play_last_channel.showToast()
}
}

TVList.groupModel.isInLikeMode = SP.defaultLike;
if (TVList.groupModel.isInLikeMode) {
Toast.makeText(this, "收藏模式", Toast.LENGTH_SHORT).show()
R.string.favorite_mode.showToast()
} else {
R.string.standard_mode.showToast()
}

// TODO group position

val port = PortUtil.findFreePort()
if (port != -1) {
server = SimpleServer(this, port)
}
server = SimpleServer(this)
}
}

Expand All @@ -181,7 +184,7 @@ class MainActivity : FragmentActivity() {
) {
hideFragment(loadingFragment)
if (tvModel.errInfo.value == "") {
Log.i(TAG, "${tvModel.tv.title} 播放中")
Log.i(TAG, "${tvModel.tv.title} playing")
hideFragment(errorFragment)
showFragment(playerFragment)
} else {
Expand Down Expand Up @@ -347,7 +350,7 @@ class MainActivity : FragmentActivity() {
menuFragment.updateList(currentGroup)
}
} else {
Toast.makeText(this, "频道不存在", Toast.LENGTH_LONG).show()
R.string.channel_not_exist.showToast()
}
}

Expand All @@ -370,7 +373,7 @@ class MainActivity : FragmentActivity() {
if (oldPositionInList != -1) {
var newPos = oldPositionInList.dec()
if (newPos < 0) {
newPos = likeList.size()-1
newPos = likeList.size() - 1
}
position = likeList.getTVModel(newPos)?.tv?.id ?: 0;
}
Expand Down Expand Up @@ -462,9 +465,17 @@ class MainActivity : FragmentActivity() {
}

private val hideSetting = Runnable {
if (!settingFragment.isHidden) {
supportFragmentManager.beginTransaction().hide(settingFragment).commitNow()
showTime()
if (!isFinishing && !isDestroyed && !supportFragmentManager.isDestroyed) {
if (settingFragment.isAdded && !settingFragment.isHidden) {
try {
supportFragmentManager.beginTransaction()
.hide(settingFragment)
.commitNow()
showTime()
} catch (e: Exception) {
e.printStackTrace()
}
}
}
}

Expand Down Expand Up @@ -529,7 +540,7 @@ class MainActivity : FragmentActivity() {
}

doubleBackToExitPressedOnce = true
Toast.makeText(this, "再按一次退出", Toast.LENGTH_SHORT).show()
R.string.press_again_to_exit.showToast()

Handler(Looper.getMainLooper()).postDelayed({
doubleBackToExitPressedOnce = false
Expand Down Expand Up @@ -699,6 +710,14 @@ class MainActivity : FragmentActivity() {
server?.stop()
}

override fun attachBaseContext(base: Context) {
//Locale.SIMPLIFIED_CHINESE
//Locale.TRADITIONAL_CHINESE
val locale = Locale.TRADITIONAL_CHINESE
val context = LocaleContextWrapper.wrap(base, locale)
super.attachBaseContext(context)
}

companion object {
private const val TAG = "MainActivity"
}
Expand Down
10 changes: 2 additions & 8 deletions app/src/main/java/com/lizongying/mytv0/MenuFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import android.view.View
import android.view.View.GONE
import android.view.View.VISIBLE
import android.view.ViewGroup
import android.widget.Toast
import androidx.core.view.isVisible
import androidx.fragment.app.Fragment
import androidx.recyclerview.widget.LinearLayoutManager
Expand All @@ -24,11 +23,6 @@ class MenuFragment : Fragment(), GroupAdapter.ItemListener, ListAdapter.ItemList
private lateinit var groupAdapter: GroupAdapter
private lateinit var listAdapter: ListAdapter

override fun onActivityCreated(savedInstanceState: Bundle?) {
Log.i(TAG, "onCreate")
super.onActivityCreated(savedInstanceState)
}

override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?
Expand Down Expand Up @@ -129,7 +123,7 @@ class MenuFragment : Fragment(), GroupAdapter.ItemListener, ListAdapter.ItemList
when (keyCode) {
KeyEvent.KEYCODE_DPAD_RIGHT -> {
if (listAdapter.itemCount == 0) {
Toast.makeText(context, "暂无频道", Toast.LENGTH_LONG).show()
R.string.channel_not_exist.showToast()
return true
}
binding.group.visibility = GONE
Expand Down Expand Up @@ -195,7 +189,7 @@ class MenuFragment : Fragment(), GroupAdapter.ItemListener, ListAdapter.ItemList
// }

if (TVList.size() == 0) {
"沒有頻道".showToast()
R.string.channel_not_exist.showToast()
return
}
val groupIndex = TVList.getTVModel().groupIndex
Expand Down
10 changes: 8 additions & 2 deletions app/src/main/java/com/lizongying/mytv0/MyTVApplication.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import android.view.WindowManager
import android.widget.Toast
import androidx.multidex.MultiDex
import androidx.multidex.MultiDexApplication
import java.util.Locale

class MyTVApplication : MultiDexApplication() {

Expand Down Expand Up @@ -99,8 +100,13 @@ class MyTVApplication : MultiDexApplication() {
return (sp * ratio * scale).toFloat()
}

override fun attachBaseContext(base: Context?) {
super.attachBaseContext(base)
override fun attachBaseContext(base: Context) {
//Locale.SIMPLIFIED_CHINESE
//Locale.TRADITIONAL_CHINESE
val locale = Locale.TRADITIONAL_CHINESE
val context = LocaleContextWrapper.wrap(base, locale)
super.attachBaseContext(context)

MultiDex.install(this)
}
}
9 changes: 8 additions & 1 deletion app/src/main/java/com/lizongying/mytv0/SP.kt
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ object SP {

private const val KEY_DEFAULT_LIKE = "default_like"

private const val KEY_SHOW_ALL_CHANNELS = "show all channelS"

private const val KEY_LIKE = "like"

private const val KEY_PROXY = "proxy"
Expand All @@ -41,6 +43,7 @@ object SP {

const val DEFAULT_CONFIG_URL = "https://live.fanmingming.com/tv/m3u/itv.m3u"
const val DEFAULT_CHANNEL = 1
const val DEFAULT_SHOW_ALL_CHANNELS = false

private lateinit var sp: SharedPreferences

Expand All @@ -49,7 +52,7 @@ object SP {
*/
fun init(context: Context) {
sp = context.getSharedPreferences(
context.resources.getString(R.string.app_name),
context.getString(R.string.app_name),
Context.MODE_PRIVATE
)
}
Expand Down Expand Up @@ -98,6 +101,10 @@ object SP {
get() = sp.getInt(KEY_CHANNEL, DEFAULT_CHANNEL)
set(value) = sp.edit().putInt(KEY_CHANNEL, value).apply()

var showAllChannels: Boolean
get() = sp.getBoolean(KEY_SHOW_ALL_CHANNELS, DEFAULT_SHOW_ALL_CHANNELS)
set(value) = sp.edit().putBoolean(KEY_SHOW_ALL_CHANNELS, value).apply()

var defaultLike: Boolean
get() = sp.getBoolean(KEY_DEFAULT_LIKE, false)
set(value) = sp.edit().putBoolean(KEY_DEFAULT_LIKE, value).apply()
Expand Down
Loading

0 comments on commit a819b61

Please sign in to comment.