Skip to content

Commit

Permalink
fix a problem that can not import source file
Browse files Browse the repository at this point in the history
  • Loading branch information
lizongying committed Dec 23, 2024
1 parent 9fcd1ba commit b52b2d0
Show file tree
Hide file tree
Showing 16 changed files with 76 additions and 98 deletions.
12 changes: 12 additions & 0 deletions HISTORY.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
## 更新日誌

### v1.3.8.11-kitkat

* 新增視頻源後默認選中
* 優化頻道列表文字超長顯示
* 解決無法導入視頻源文件的問題

### v1.3.8.11

* 新增視頻源後默認選中
* 優化頻道列表文字超長顯示
* 解決無法導入視頻源文件的問題

### v1.3.8.10-kitkat

* 修復新增視頻源時的錯誤
Expand Down
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
注意:

* 遇到問題可以先考慮重啟/恢復默認/清除數據/重新安裝等方式自助解決
* 如果APP運行在手機上,建議在其他設備上進行遠程配置
* 視頻源可以設置為本地文件,格式如:file:///mnt/sdcard/tmp/channels.m3u
/channels.m3u

Expand Down Expand Up @@ -85,8 +86,9 @@ adb install my-tv-0.apk
* 淺色菜單
* 無效的頻道?
* 如果上次播放頻道不在收藏?
* 當list為空,顯示group
* 當list為空,顯示group/空group不顯示?
* 默認頻道菜單顯示
* 遠程配置使用webView

## 讚賞

Expand Down
22 changes: 4 additions & 18 deletions app/src/main/java/com/lizongying/mytv0/ListAdapter.kt
Original file line number Diff line number Diff line change
Expand Up @@ -48,20 +48,13 @@ class ListAdapter(
binding.icon.layoutParams.height = application.px2Px(binding.icon.layoutParams.height)
binding.icon.setPadding(application.px2Px(binding.icon.paddingTop))

val layoutParams = binding.title.layoutParams as ViewGroup.MarginLayoutParams
layoutParams.marginStart = application.px2Px(binding.title.marginStart)
binding.title.layoutParams = layoutParams
binding.title.layoutParams.width = application.px2Px(binding.title.layoutParams.width)
binding.title.layoutParams.height = application.px2Px(binding.title.layoutParams.height)
binding.title.textSize = application.px2PxFont(binding.title.textSize)

binding.heart.layoutParams.width = application.px2Px(binding.heart.layoutParams.width)
binding.heart.layoutParams.height = application.px2Px(binding.heart.layoutParams.height)

binding.title.textSize = application.px2PxFont(binding.title.textSize)

val layoutParamsHeart = binding.heart.layoutParams as ViewGroup.MarginLayoutParams
layoutParamsHeart.marginStart = application.px2Px(binding.heart.marginStart)
binding.heart.layoutParams = layoutParamsHeart

binding.description.textSize = application.px2PxFont(binding.description.textSize)
binding.heart.setPadding(application.px2Px(binding.heart.paddingTop))

return ViewHolder(context, binding)
}
Expand Down Expand Up @@ -222,16 +215,9 @@ class ListAdapter(
fun focus(hasFocus: Boolean) {
if (hasFocus) {
binding.title.setTextColor(ContextCompat.getColor(context, R.color.white))
binding.description.setTextColor(ContextCompat.getColor(context, R.color.white))
binding.root.setBackgroundResource(R.color.focus)
} else {
binding.title.setTextColor(ContextCompat.getColor(context, R.color.title_blur))
binding.description.setTextColor(
ContextCompat.getColor(
context,
R.color.description_blur
)
)
binding.root.setBackgroundResource(R.color.blur)
}
}
Expand Down
3 changes: 3 additions & 0 deletions app/src/main/java/com/lizongying/mytv0/MainViewModel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,9 @@ class MainViewModel : ViewModel() {
if (trimmedLine.contains("#genre#")) {
group = trimmedLine.split(',', limit = 2)[0].trim()
} else {
if (!trimmedLine.contains(",")) {
continue
}
val arr = trimmedLine.split(',').map { it.trim() }
val title = arr.first().trim()
val uris = arr.drop(1)
Expand Down
8 changes: 5 additions & 3 deletions app/src/main/java/com/lizongying/mytv0/ModalFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import android.view.ViewGroup
import android.view.WindowManager
import androidx.fragment.app.DialogFragment
import com.bumptech.glide.Glide
import com.lizongying.mytv0.Utils.getDateTimestamp
import com.lizongying.mytv0.databinding.ModalBinding


Expand Down Expand Up @@ -45,15 +46,16 @@ class ModalFragment : DialogFragment() {
val url = arguments?.getString(KEY_URL)
if (!url.isNullOrEmpty()) {
val size = Utils.dpToPx(200)
val img = QrCodeUtil().createQRCodeBitmap(url, size, size)
val u = "$url?${getDateTimestamp()}"
val img = QrCodeUtil().createQRCodeBitmap(u, size, size)

Glide.with(requireContext())
.load(img)
.into(binding.modalImage)
binding.modalText.text = url.removePrefix("http://")
binding.modalText.text = u.removePrefix("http://")
binding.modalText.visibility = View.VISIBLE
binding.modal.setOnClickListener {
val intent = Intent(Intent.ACTION_VIEW, Uri.parse(url))
val intent = Intent(Intent.ACTION_VIEW, Uri.parse(u))
try {
startActivity(intent)
} catch (e: Exception) {
Expand Down
59 changes: 20 additions & 39 deletions app/src/main/java/com/lizongying/mytv0/SimpleServer.kt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import android.os.Looper
import android.util.Log
import com.google.gson.Gson
import com.google.gson.reflect.TypeToken
import com.lizongying.mytv0.Utils.getUrls
import com.lizongying.mytv0.data.ReqSettings
import com.lizongying.mytv0.data.ReqSourceAdd
import com.lizongying.mytv0.data.ReqSources
Expand All @@ -23,19 +24,19 @@ import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.runBlocking
import kotlinx.coroutines.withContext
import java.io.File
import java.io.IOException
import java.nio.charset.StandardCharsets


class SimpleServer(private val context: Context, private val viewModel: MainViewModel) :
NanoHTTPD(PORT) {
private val handler = Handler(Looper.getMainLooper())
private val gson = Gson()

init {
try {
start()
} catch (e: Exception) {
e.printStackTrace()
Log.e(TAG, "init", e)
}
}

Expand Down Expand Up @@ -72,7 +73,7 @@ class SimpleServer(private val context: Context, private val viewModel: MainView
if (!SP.sources.isNullOrEmpty()) {
try {
val type = object : TypeToken<List<Source>>() {}.type
val sources: List<Source> = Gson().fromJson(SP.sources!!, type)
val sources: List<Source> = gson.fromJson(SP.sources!!, type)
history = sources.toMutableList()
} catch (e: Exception) {
e.printStackTrace()
Expand All @@ -88,9 +89,9 @@ class SimpleServer(private val context: Context, private val viewModel: MainView
epg = SP.epg ?: "",
history = history
)
response = Gson().toJson(respSettings) ?: ""
response = gson.toJson(respSettings) ?: ""
} catch (e: Exception) {
e.printStackTrace()
Log.e(TAG, "handleSettings", e)
return newFixedLengthResponse(
Response.Status.INTERNAL_ERROR,
MIME_PLAINTEXT,
Expand All @@ -102,31 +103,11 @@ class SimpleServer(private val context: Context, private val viewModel: MainView
}

private suspend fun fetchSources(url: String): String {
val urls =
if (url.startsWith("https://raw.githubusercontent.com") || url.startsWith("https://github.com")) {
listOf(
"https://ghp.ci/",
"https://gh.llkk.cc/",
"https://github.moeyy.xyz/",
"https://mirror.ghproxy.com/",
"https://ghproxy.cn/",
"https://ghproxy.net/",
"https://ghproxy.click/",
"https://ghproxy.com/",
"https://github.moeyy.cn/",
"https://gh-proxy.llyke.com/",
"https://www.ghproxy.cc/",
"https://cf.ghproxy.cc/"
).map {
Pair("$it$url", url)
}
} else {
listOf(Pair(url, url))
}
val urls = getUrls(url)

var sources = ""
var success = false
for ((a, b) in urls) {
for (a in urls) {
Log.i(TAG, "request $a")
try {
withContext(Dispatchers.IO) {
Expand All @@ -141,7 +122,6 @@ class SimpleServer(private val context: Context, private val viewModel: MainView
}
}
} catch (e: Exception) {
e.printStackTrace()
Log.e(TAG, "fetchSources", e)
}

Expand Down Expand Up @@ -173,7 +153,7 @@ class SimpleServer(private val context: Context, private val viewModel: MainView
}
}
} catch (e: Exception) {
e.printStackTrace()
Log.e(TAG, "handleImportFromText", e)
return newFixedLengthResponse(
Response.Status.INTERNAL_ERROR,
MIME_PLAINTEXT,
Expand All @@ -188,13 +168,14 @@ class SimpleServer(private val context: Context, private val viewModel: MainView
val response = ""
try {
readBody(session)?.let {
val req = Gson().fromJson(it, ReqSourceAdd::class.java)
val req = gson.fromJson(it, ReqSourceAdd::class.java)
val uri = Uri.parse(req.uri)
handler.post {
viewModel.importFromUri(uri, req.id)
}
}
} catch (e: IOException) {
} catch (e: Exception) {
Log.e(TAG, "handleImportFromUri", e)
return newFixedLengthResponse(
Response.Status.INTERNAL_ERROR,
MIME_PLAINTEXT,
Expand All @@ -208,7 +189,7 @@ class SimpleServer(private val context: Context, private val viewModel: MainView
try {
readBody(session)?.let {
handler.post {
val req = Gson().fromJson(it, ReqSettings::class.java)
val req = gson.fromJson(it, ReqSettings::class.java)
if (req.proxy != null) {
SP.proxy = req.proxy
R.string.default_proxy_set_success.showToast()
Expand All @@ -218,7 +199,7 @@ class SimpleServer(private val context: Context, private val viewModel: MainView
}
}
} catch (e: Exception) {
e.printStackTrace()
Log.e(TAG, "handleProxy", e)
return newFixedLengthResponse(
Response.Status.INTERNAL_ERROR,
MIME_PLAINTEXT,
Expand All @@ -233,7 +214,7 @@ class SimpleServer(private val context: Context, private val viewModel: MainView
try {
readBody(session)?.let {
handler.post {
val req = Gson().fromJson(it, ReqSettings::class.java)
val req = gson.fromJson(it, ReqSettings::class.java)
if (req.epg != null) {
SP.epg = req.epg
viewModel.updateEPG()
Expand All @@ -244,7 +225,7 @@ class SimpleServer(private val context: Context, private val viewModel: MainView
}
}
} catch (e: Exception) {
e.printStackTrace()
Log.e(TAG, "handleEPG", e)
return newFixedLengthResponse(
Response.Status.INTERNAL_ERROR,
MIME_PLAINTEXT,
Expand All @@ -261,7 +242,7 @@ class SimpleServer(private val context: Context, private val viewModel: MainView
try {
readBody(session)?.let {
handler.post {
val req = Gson().fromJson(it, ReqSettings::class.java)
val req = gson.fromJson(it, ReqSettings::class.java)
if (req.channel != null && req.channel > -1) {
SP.channel = req.channel
R.string.default_channel_set_success.showToast()
Expand All @@ -271,7 +252,7 @@ class SimpleServer(private val context: Context, private val viewModel: MainView
}
}
} catch (e: Exception) {
e.printStackTrace()
Log.e(TAG, "handleDefaultChannel", e)
return newFixedLengthResponse(
Response.Status.INTERNAL_ERROR,
MIME_PLAINTEXT,
Expand All @@ -286,7 +267,7 @@ class SimpleServer(private val context: Context, private val viewModel: MainView
try {
readBody(session)?.let {
handler.post {
val req = Gson().fromJson(it, ReqSources::class.java)
val req = gson.fromJson(it, ReqSources::class.java)
Log.i(TAG, "req $req")
if (req.sourceId.isNotEmpty()) {
val res = viewModel.sources.removeSource(req.sourceId)
Expand All @@ -301,7 +282,7 @@ class SimpleServer(private val context: Context, private val viewModel: MainView
}
}
} catch (e: Exception) {
e.printStackTrace()
Log.e(TAG, "handleRemoveSource", e)
return newFixedLengthResponse(
Response.Status.INTERNAL_ERROR,
MIME_PLAINTEXT,
Expand Down
4 changes: 0 additions & 4 deletions app/src/main/java/com/lizongying/mytv0/SourcesAdapter.kt
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,6 @@ class SourcesAdapter(

binding.title.layoutParams.width = application.px2Px(binding.title.layoutParams.width)
binding.title.layoutParams.height = application.px2Px(binding.title.layoutParams.height)
val layoutParams = binding.title.layoutParams as ViewGroup.MarginLayoutParams
layoutParams.marginStart = application.px2Px(binding.title.marginStart)
layoutParams.marginEnd = application.px2Px(binding.title.marginEnd)
binding.title.layoutParams = layoutParams
binding.title.textSize = application.px2PxFont(binding.title.textSize)

binding.heart.layoutParams.width = application.px2Px(binding.heart.layoutParams.width)
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/java/com/lizongying/mytv0/UpdateManager.kt
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,13 @@ class UpdateManager(

private fun startDownload(release: ReleaseResponse) {
val apkName = "my-tv-0"
val apkFileName = "$apkName-${release.version_name}${APK_SUFFIX}.apk"
val v = release.version_name?.removePrefix("v")
val apkFileName = "$apkName.${v}${APK_SUFFIX}.apk"
val url =
"${HttpClient.DOWNLOAD_HOST}${release.version_name}${APK_SUFFIX}/$apkName.${v}${APK_SUFFIX}.apk"
Log.i(
TAG,
"url ${url}"
"url $url"
)
var downloadDir = context.getExternalFilesDir(Environment.DIRECTORY_DOWNLOADS)
if (downloadDir == null) {
Expand Down
7 changes: 6 additions & 1 deletion app/src/main/java/com/lizongying/mytv0/models/Sources.kt
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,17 @@ class Sources {
fun addSource(source: Source) {
val index = sourcesValue.indexOfFirst { it.uri == source.uri }
if (index == -1) {
setSourceChecked(checkedValue, false)

_sources.value = sourcesValue.toMutableList().apply {
add(0, source)
}

_checked.value = 0
setSourceChecked(checkedValue, true)
SP.sources = gson.toJson(sourcesValue, type) ?: ""

_added.value = Pair(sourcesValue.size - 1, version)
_changed.value = version
version++
}
}
Expand Down
Loading

0 comments on commit b52b2d0

Please sign in to comment.