Skip to content

Commit

Permalink
update source after the reset
Browse files Browse the repository at this point in the history
  • Loading branch information
lizongying committed Aug 4, 2024
1 parent cbbaf81 commit be53488
Show file tree
Hide file tree
Showing 7 changed files with 58 additions and 53 deletions.
4 changes: 4 additions & 0 deletions HISTORY.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
## 更新日志

### v1.3.1

* 恢復默認後,立即更新視頻源

### v1.3.0

* 修復收藏BUG
Expand Down
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,9 @@ adb install my-tv-0.apk
* 支持回看
* 詳細EPG
* 淺色菜單
* 是否顯示全部頻道
* 固定網絡配置端口
* 無效的頻道?

## 讚賞

Expand Down
8 changes: 5 additions & 3 deletions app/src/main/java/com/lizongying/mytv0/SP.kt
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ object SP {

private const val KEY_EPG = "epg"

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

private lateinit var sp: SharedPreferences

/**
Expand Down Expand Up @@ -84,16 +87,15 @@ object SP {
set(value) = sp.edit().putBoolean(KEY_REPEAT_INFO, value).apply()

var config: String?
get() = sp.getString(KEY_CONFIG,
"")
get() = sp.getString(KEY_CONFIG, DEFAULT_CONFIG_URL)
set(value) = sp.edit().putString(KEY_CONFIG, value).apply()

var configAutoLoad: Boolean
get() = sp.getBoolean(KEY_CONFIG_AUTO_LOAD, false)
set(value) = sp.edit().putBoolean(KEY_CONFIG_AUTO_LOAD, value).apply()

var channel: Int
get() = sp.getInt(KEY_CHANNEL, 0)
get() = sp.getInt(KEY_CHANNEL, DEFAULT_CHANNEL)
set(value) = sp.edit().putInt(KEY_CHANNEL, value).apply()

var defaultLike: Boolean
Expand Down
88 changes: 44 additions & 44 deletions app/src/main/java/com/lizongying/mytv0/SettingFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import android.net.Uri
import android.os.Build
import android.os.Bundle
import android.text.Editable
import android.util.Log
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
Expand All @@ -18,6 +17,8 @@ import androidx.core.view.marginTop
import androidx.fragment.app.Fragment
import com.lizongying.mytv0.databinding.SettingBinding
import com.lizongying.mytv0.models.TVList
import kotlin.math.max
import kotlin.math.min


class SettingFragment : Fragment() {
Expand Down Expand Up @@ -107,49 +108,14 @@ class SettingFragment : Fragment() {
(activity as MainActivity).settingActive()
}

val config = binding.config
config.text = SP.config?.let { Editable.Factory.getInstance().newEditable(it) }
?: Editable.Factory.getInstance().newEditable("")
confirmConfig()
binding.confirmConfig.setOnClickListener {
var url = config.text.toString().trim()
url = Utils.formatUrl(url)
uri = Uri.parse(url)
Log.i(TAG, "uri.scheme ${uri.scheme}")
if (uri.scheme == "") {
uri = uri.buildUpon().scheme("http").build()
}
Log.i(TAG, "Uri $uri")
if (uri.isAbsolute) {
Log.i(TAG, "Uri ok")
if (uri.scheme == "file") {
requestReadPermissions()
} else {
TVList.parseUri(uri)
}
} else {
config.error = "无效的地址"
}
(activity as MainActivity).settingActive()
confirmConfig()
}

val defaultChannel = binding.channel
defaultChannel.text =
SP.channel.let { Editable.Factory.getInstance().newEditable(it.toString()) }
?: Editable.Factory.getInstance().newEditable("")
confirmChannel()
binding.confirmChannel.setOnClickListener {
val c = defaultChannel.text.toString().trim()
var channel = 0
try {
channel = c.toInt()
} catch (e: NumberFormatException) {
println(e)
}
if (channel > 0 && channel <= TVList.listModel.size) {
SP.channel = channel
} else {
defaultChannel.error = "无效的频道"
}
(activity as MainActivity).settingActive()
confirmChannel()
}

val defaultProxy = binding.proxy
Expand All @@ -174,10 +140,10 @@ class SettingFragment : Fragment() {
}

binding.clear.setOnClickListener {
SP.config = ""
config.text = Editable.Factory.getInstance().newEditable("")
SP.channel = 0
defaultChannel.text = Editable.Factory.getInstance().newEditable("")
SP.config = SP.DEFAULT_CONFIG_URL
confirmConfig()
SP.channel = SP.DEFAULT_CHANNEL
confirmChannel()
context.deleteFile(TVList.FILE_NAME)
SP.deleteLike()
SP.position = 0
Expand Down Expand Up @@ -324,6 +290,40 @@ class SettingFragment : Fragment() {
return binding.root
}

private fun confirmConfig() {
val config = binding.config
config.text = SP.config?.let { Editable.Factory.getInstance().newEditable(it) }
?: Editable.Factory.getInstance().newEditable(SP.DEFAULT_CONFIG_URL)

var url = config.text.toString().trim()
url = Utils.formatUrl(url)
uri = Uri.parse(url)
if (uri.scheme == "") {
uri = uri.buildUpon().scheme("http").build()
}
if (uri.isAbsolute) {
if (uri.scheme == "file") {
requestReadPermissions()
} else {
TVList.parseUri(uri)
}
} else {
config.error = "无效的地址"
}
(activity as MainActivity).settingActive()
}

private fun confirmChannel() {
val defaultChannel = binding.channel
SP.channel = min(max(SP.channel, 1), TVList.listModel.size)

defaultChannel.text =
Editable.Factory.getInstance()
.newEditable(SP.channel.toString())

(activity as MainActivity).settingActive()
}

fun setServer(server: String) {
binding.server.text = "http://$server"
}
Expand Down
4 changes: 0 additions & 4 deletions app/src/main/java/com/lizongying/mytv0/models/TVList.kt
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,6 @@ object TVList {
Toast.makeText(context, "读取频道失败,请在菜单中进行设置", Toast.LENGTH_LONG).show()
}

if (SP.config.isNullOrEmpty()) {
SP.config = "https://live.fanmingming.com/tv/m3u/itv.m3u"
}

if (SP.configAutoLoad) {
SP.config?.let {
update(it)
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/raw/channels.txt

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion version.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"version_code": 16973824, "version_name": "v1.3.0"}
{"version_code": 16974080, "version_name": "v1.3.1"}

0 comments on commit be53488

Please sign in to comment.