Skip to content

Commit 7c7f29b

Browse files
committed
fix a problem that can not import source file
1 parent cb7c942 commit 7c7f29b

File tree

15 files changed

+74
-96
lines changed

15 files changed

+74
-96
lines changed

HISTORY.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,17 @@
11
## 更新日誌
22

3+
### v1.3.8.11-kitkat
4+
5+
* 新增視頻源後默認選中
6+
* 優化頻道列表文字超長顯示
7+
* 解決無法導入視頻源文件的問題
8+
9+
### v1.3.8.11
10+
11+
* 新增視頻源後默認選中
12+
* 優化頻道列表文字超長顯示
13+
* 解決無法導入視頻源文件的問題
14+
315
### v1.3.8.10-kitkat
416

517
* 修復新增視頻源時的錯誤

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
注意:
1818

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

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

9193
## 讚賞
9294

app/src/main/java/com/lizongying/mytv0/ListAdapter.kt

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -49,20 +49,13 @@ class ListAdapter(
4949
binding.icon.layoutParams.height = application.px2Px(binding.icon.layoutParams.height)
5050
binding.icon.setPadding(application.px2Px(binding.icon.paddingTop))
5151

52-
val layoutParams = binding.title.layoutParams as ViewGroup.MarginLayoutParams
53-
layoutParams.marginStart = application.px2Px(binding.title.marginStart)
54-
binding.title.layoutParams = layoutParams
52+
binding.title.layoutParams.width = application.px2Px(binding.title.layoutParams.width)
53+
binding.title.layoutParams.height = application.px2Px(binding.title.layoutParams.height)
54+
binding.title.textSize = application.px2PxFont(binding.title.textSize)
5555

5656
binding.heart.layoutParams.width = application.px2Px(binding.heart.layoutParams.width)
5757
binding.heart.layoutParams.height = application.px2Px(binding.heart.layoutParams.height)
58-
59-
binding.title.textSize = application.px2PxFont(binding.title.textSize)
60-
61-
val layoutParamsHeart = binding.heart.layoutParams as ViewGroup.MarginLayoutParams
62-
layoutParamsHeart.marginStart = application.px2Px(binding.heart.marginStart)
63-
binding.heart.layoutParams = layoutParamsHeart
64-
65-
binding.description.textSize = application.px2PxFont(binding.description.textSize)
58+
binding.heart.setPadding(application.px2Px(binding.heart.paddingTop))
6659

6760
return ViewHolder(context, binding)
6861
}
@@ -223,16 +216,9 @@ class ListAdapter(
223216
fun focus(hasFocus: Boolean) {
224217
if (hasFocus) {
225218
binding.title.setTextColor(ContextCompat.getColor(context, R.color.white))
226-
binding.description.setTextColor(ContextCompat.getColor(context, R.color.white))
227219
binding.root.setBackgroundResource(R.color.focus)
228220
} else {
229221
binding.title.setTextColor(ContextCompat.getColor(context, R.color.title_blur))
230-
binding.description.setTextColor(
231-
ContextCompat.getColor(
232-
context,
233-
R.color.description_blur
234-
)
235-
)
236222
binding.root.setBackgroundResource(R.color.blur)
237223
}
238224
}

app/src/main/java/com/lizongying/mytv0/MainViewModel.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -398,6 +398,9 @@ class MainViewModel : ViewModel() {
398398
if (trimmedLine.contains("#genre#")) {
399399
group = trimmedLine.split(',', limit = 2)[0].trim()
400400
} else {
401+
if (!trimmedLine.contains(",")) {
402+
continue
403+
}
401404
val arr = trimmedLine.split(',').map { it.trim() }
402405
val title = arr.first().trim()
403406
val uris = arr.drop(1)

app/src/main/java/com/lizongying/mytv0/ModalFragment.kt

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import android.view.ViewGroup
1111
import android.view.WindowManager
1212
import androidx.fragment.app.DialogFragment
1313
import com.bumptech.glide.Glide
14+
import com.lizongying.mytv0.Utils.getDateTimestamp
1415
import com.lizongying.mytv0.databinding.ModalBinding
1516

1617

@@ -45,15 +46,16 @@ class ModalFragment : DialogFragment() {
4546
val url = arguments?.getString(KEY_URL)
4647
if (!url.isNullOrEmpty()) {
4748
val size = Utils.dpToPx(200)
48-
val img = QrCodeUtil().createQRCodeBitmap(url, size, size)
49+
val u = "$url?${getDateTimestamp()}"
50+
val img = QrCodeUtil().createQRCodeBitmap(u, size, size)
4951

5052
Glide.with(requireContext())
5153
.load(img)
5254
.into(binding.modalImage)
53-
binding.modalText.text = url.removePrefix("http://")
55+
binding.modalText.text = u.removePrefix("http://")
5456
binding.modalText.visibility = View.VISIBLE
5557
binding.modal.setOnClickListener {
56-
val intent = Intent(Intent.ACTION_VIEW, Uri.parse(url))
58+
val intent = Intent(Intent.ACTION_VIEW, Uri.parse(u))
5759
try {
5860
startActivity(intent)
5961
} catch (e: Exception) {

app/src/main/java/com/lizongying/mytv0/SimpleServer.kt

Lines changed: 20 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import android.os.Looper
1111
import android.util.Log
1212
import com.google.gson.Gson
1313
import com.google.gson.reflect.TypeToken
14+
import com.lizongying.mytv0.Utils.getUrls
1415
import com.lizongying.mytv0.data.ReqSettings
1516
import com.lizongying.mytv0.data.ReqSourceAdd
1617
import com.lizongying.mytv0.data.ReqSources
@@ -23,19 +24,19 @@ import kotlinx.coroutines.Dispatchers
2324
import kotlinx.coroutines.runBlocking
2425
import kotlinx.coroutines.withContext
2526
import java.io.File
26-
import java.io.IOException
2727
import java.nio.charset.StandardCharsets
2828

2929

3030
class SimpleServer(private val context: Context, private val viewModel: MainViewModel) :
3131
NanoHTTPD(PORT) {
3232
private val handler = Handler(Looper.getMainLooper())
33+
private val gson = Gson()
3334

3435
init {
3536
try {
3637
start()
3738
} catch (e: Exception) {
38-
e.printStackTrace()
39+
Log.e(TAG, "init", e)
3940
}
4041
}
4142

@@ -72,7 +73,7 @@ class SimpleServer(private val context: Context, private val viewModel: MainView
7273
if (!SP.sources.isNullOrEmpty()) {
7374
try {
7475
val type = object : TypeToken<List<Source>>() {}.type
75-
val sources: List<Source> = Gson().fromJson(SP.sources!!, type)
76+
val sources: List<Source> = gson.fromJson(SP.sources!!, type)
7677
history = sources.toMutableList()
7778
} catch (e: Exception) {
7879
e.printStackTrace()
@@ -88,9 +89,9 @@ class SimpleServer(private val context: Context, private val viewModel: MainView
8889
epg = SP.epg ?: "",
8990
history = history
9091
)
91-
response = Gson().toJson(respSettings) ?: ""
92+
response = gson.toJson(respSettings) ?: ""
9293
} catch (e: Exception) {
93-
e.printStackTrace()
94+
Log.e(TAG, "handleSettings", e)
9495
return newFixedLengthResponse(
9596
Response.Status.INTERNAL_ERROR,
9697
MIME_PLAINTEXT,
@@ -102,31 +103,11 @@ class SimpleServer(private val context: Context, private val viewModel: MainView
102103
}
103104

104105
private suspend fun fetchSources(url: String): String {
105-
val urls =
106-
if (url.startsWith("https://raw.githubusercontent.com") || url.startsWith("https://github.com")) {
107-
listOf(
108-
"https://ghp.ci/",
109-
"https://gh.llkk.cc/",
110-
"https://github.moeyy.xyz/",
111-
"https://mirror.ghproxy.com/",
112-
"https://ghproxy.cn/",
113-
"https://ghproxy.net/",
114-
"https://ghproxy.click/",
115-
"https://ghproxy.com/",
116-
"https://github.moeyy.cn/",
117-
"https://gh-proxy.llyke.com/",
118-
"https://www.ghproxy.cc/",
119-
"https://cf.ghproxy.cc/"
120-
).map {
121-
Pair("$it$url", url)
122-
}
123-
} else {
124-
listOf(Pair(url, url))
125-
}
106+
val urls = getUrls(url)
126107

127108
var sources = ""
128109
var success = false
129-
for ((a, b) in urls) {
110+
for (a in urls) {
130111
Log.i(TAG, "request $a")
131112
try {
132113
withContext(Dispatchers.IO) {
@@ -141,7 +122,6 @@ class SimpleServer(private val context: Context, private val viewModel: MainView
141122
}
142123
}
143124
} catch (e: Exception) {
144-
e.printStackTrace()
145125
Log.e(TAG, "fetchSources", e)
146126
}
147127

@@ -173,7 +153,7 @@ class SimpleServer(private val context: Context, private val viewModel: MainView
173153
}
174154
}
175155
} catch (e: Exception) {
176-
e.printStackTrace()
156+
Log.e(TAG, "handleImportFromText", e)
177157
return newFixedLengthResponse(
178158
Response.Status.INTERNAL_ERROR,
179159
MIME_PLAINTEXT,
@@ -188,13 +168,14 @@ class SimpleServer(private val context: Context, private val viewModel: MainView
188168
val response = ""
189169
try {
190170
readBody(session)?.let {
191-
val req = Gson().fromJson(it, ReqSourceAdd::class.java)
171+
val req = gson.fromJson(it, ReqSourceAdd::class.java)
192172
val uri = Uri.parse(req.uri)
193173
handler.post {
194174
viewModel.importFromUri(uri, req.id)
195175
}
196176
}
197-
} catch (e: IOException) {
177+
} catch (e: Exception) {
178+
Log.e(TAG, "handleImportFromUri", e)
198179
return newFixedLengthResponse(
199180
Response.Status.INTERNAL_ERROR,
200181
MIME_PLAINTEXT,
@@ -208,7 +189,7 @@ class SimpleServer(private val context: Context, private val viewModel: MainView
208189
try {
209190
readBody(session)?.let {
210191
handler.post {
211-
val req = Gson().fromJson(it, ReqSettings::class.java)
192+
val req = gson.fromJson(it, ReqSettings::class.java)
212193
if (req.proxy != null) {
213194
SP.proxy = req.proxy
214195
R.string.default_proxy_set_success.showToast()
@@ -218,7 +199,7 @@ class SimpleServer(private val context: Context, private val viewModel: MainView
218199
}
219200
}
220201
} catch (e: Exception) {
221-
e.printStackTrace()
202+
Log.e(TAG, "handleProxy", e)
222203
return newFixedLengthResponse(
223204
Response.Status.INTERNAL_ERROR,
224205
MIME_PLAINTEXT,
@@ -233,7 +214,7 @@ class SimpleServer(private val context: Context, private val viewModel: MainView
233214
try {
234215
readBody(session)?.let {
235216
handler.post {
236-
val req = Gson().fromJson(it, ReqSettings::class.java)
217+
val req = gson.fromJson(it, ReqSettings::class.java)
237218
if (req.epg != null) {
238219
SP.epg = req.epg
239220
viewModel.updateEPG()
@@ -244,7 +225,7 @@ class SimpleServer(private val context: Context, private val viewModel: MainView
244225
}
245226
}
246227
} catch (e: Exception) {
247-
e.printStackTrace()
228+
Log.e(TAG, "handleEPG", e)
248229
return newFixedLengthResponse(
249230
Response.Status.INTERNAL_ERROR,
250231
MIME_PLAINTEXT,
@@ -261,7 +242,7 @@ class SimpleServer(private val context: Context, private val viewModel: MainView
261242
try {
262243
readBody(session)?.let {
263244
handler.post {
264-
val req = Gson().fromJson(it, ReqSettings::class.java)
245+
val req = gson.fromJson(it, ReqSettings::class.java)
265246
if (req.channel != null && req.channel > -1) {
266247
SP.channel = req.channel
267248
R.string.default_channel_set_success.showToast()
@@ -271,7 +252,7 @@ class SimpleServer(private val context: Context, private val viewModel: MainView
271252
}
272253
}
273254
} catch (e: Exception) {
274-
e.printStackTrace()
255+
Log.e(TAG, "handleDefaultChannel", e)
275256
return newFixedLengthResponse(
276257
Response.Status.INTERNAL_ERROR,
277258
MIME_PLAINTEXT,
@@ -286,7 +267,7 @@ class SimpleServer(private val context: Context, private val viewModel: MainView
286267
try {
287268
readBody(session)?.let {
288269
handler.post {
289-
val req = Gson().fromJson(it, ReqSources::class.java)
270+
val req = gson.fromJson(it, ReqSources::class.java)
290271
Log.i(TAG, "req $req")
291272
if (req.sourceId.isNotEmpty()) {
292273
val res = viewModel.sources.removeSource(req.sourceId)
@@ -301,7 +282,7 @@ class SimpleServer(private val context: Context, private val viewModel: MainView
301282
}
302283
}
303284
} catch (e: Exception) {
304-
e.printStackTrace()
285+
Log.e(TAG, "handleRemoveSource", e)
305286
return newFixedLengthResponse(
306287
Response.Status.INTERNAL_ERROR,
307288
MIME_PLAINTEXT,

app/src/main/java/com/lizongying/mytv0/SourcesAdapter.kt

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,6 @@ class SourcesAdapter(
3636

3737
binding.title.layoutParams.width = application.px2Px(binding.title.layoutParams.width)
3838
binding.title.layoutParams.height = application.px2Px(binding.title.layoutParams.height)
39-
val layoutParams = binding.title.layoutParams as ViewGroup.MarginLayoutParams
40-
layoutParams.marginStart = application.px2Px(binding.title.marginStart)
41-
layoutParams.marginEnd = application.px2Px(binding.title.marginEnd)
42-
binding.title.layoutParams = layoutParams
4339
binding.title.textSize = application.px2PxFont(binding.title.textSize)
4440

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

app/src/main/java/com/lizongying/mytv0/models/Sources.kt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,12 +65,17 @@ class Sources {
6565
fun addSource(source: Source) {
6666
val index = sourcesValue.indexOfFirst { it.uri == source.uri }
6767
if (index == -1) {
68+
setSourceChecked(checkedValue, false)
69+
6870
_sources.value = sourcesValue.toMutableList().apply {
6971
add(0, source)
7072
}
73+
74+
_checked.value = 0
75+
setSourceChecked(checkedValue, true)
7176
SP.sources = gson.toJson(sourcesValue, type) ?: ""
7277

73-
_added.value = Pair(sourcesValue.size - 1, version)
78+
_changed.value = version
7479
version++
7580
}
7681
}

0 commit comments

Comments
 (0)