Skip to content

Commit

Permalink
optimize remote settings on mobile
Browse files Browse the repository at this point in the history
  • Loading branch information
lizongying committed Feb 10, 2025
1 parent 1a45f38 commit 763eeda
Show file tree
Hide file tree
Showing 9 changed files with 84 additions and 25 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.9.1

* 優化手機上遠程配置

### v1.3.9.0

* 支持socks代理
Expand Down
16 changes: 7 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@
注意:

* 遇到問題可以先考慮重啟/恢復默認/清除數據/重新安裝等方式自助解決
* 如果APP運行在手機上,建議在其他設備上進行遠程配置
* 視頻源可以設置為本地文件,格式如:file:///mnt/sdcard/tmp/channels.m3u
/channels.m3u
* 目前設置代理後,需要重啟生效。代理屬於全局代理,也就是視頻請求及其他請求都會使用代理。

目前支持的配置格式:

Expand All @@ -30,18 +30,20 @@
```
* m3u
```
#EXTM3U
#EXTINF:-1 tvg-name="標準標題" tvg-logo="图标" group-title="組名",標題
#EXTM3U x-tvg-url=""
#EXTINF:-1 tvg-id="" tvg-name="標準標題" tvg-logo="图标" group-title="組名",標題
#EXTVLCOPT:http-user-agent=
#EXTVLCOPT:http-referrer=
視頻地址
```
* json
```json
[
{
"group": "組名",
"logo": "图标",
"name": "標準標題",
"title": "標題",
"logo": "图标",
"uris": [
"視頻地址"
],
Expand Down Expand Up @@ -80,13 +82,9 @@ adb install my-tv-0.apk

## TODO

* 支持回看
* 詳細EPG
* 支持回看
* 淺色菜單
* 無效的頻道?
* 如果上次播放頻道不在收藏?
* 當list為空,顯示group/空group不顯示?
* 遠程配置使用webView

## 讚賞

Expand Down
4 changes: 3 additions & 1 deletion app/src/main/java/com/lizongying/mytv0/ChannelFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,9 @@ class ChannelFragment : Fragment() {
fun show(tvViewModel: TVModel) {
handler.removeCallbacks(hideRunnable)
handler.removeCallbacks(playRunnable)
binding.content.text = (tvViewModel.tv.id.plus(1)).toString()
if (_binding != null) {
binding.content.text = (tvViewModel.tv.id.plus(1)).toString()
}
view?.visibility = View.VISIBLE
handler.postDelayed(hideRunnable, delay)
}
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/java/com/lizongying/mytv0/GroupAdapter.kt
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ class GroupAdapter(
defaultFocused = true
}

val onFocusChangeListener = View.OnFocusChangeListener { _, hasFocus ->
val onFocusChangeListener = View.OnFocusChangeListener { v, hasFocus ->
listener?.onItemFocusChange(listTVModel, hasFocus)

if (hasFocus) {
Expand Down
24 changes: 24 additions & 0 deletions app/src/main/java/com/lizongying/mytv0/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,20 @@ import android.os.Handler
import android.os.Looper
import android.util.Log
import android.view.GestureDetector
import android.view.Gravity
import android.view.KeyEvent
import android.view.MotionEvent
import android.view.View
import android.view.WindowManager
import android.widget.PopupWindow
import android.widget.RelativeLayout
import androidx.appcompat.app.AppCompatActivity
import androidx.core.view.WindowCompat
import androidx.core.view.WindowInsetsCompat
import androidx.core.view.WindowInsetsControllerCompat
import androidx.fragment.app.Fragment
import androidx.lifecycle.ViewModelProvider
import com.lizongying.mytv0.databinding.SettingsWebBinding
import java.util.Locale
import kotlin.math.abs

Expand Down Expand Up @@ -633,6 +637,26 @@ class MainActivity : AppCompatActivity() {
settingActive()
}

fun showWebViewPopup(url: String) {
val binding = SettingsWebBinding.inflate(layoutInflater)

val webView = binding.web
webView.settings.javaScriptEnabled = true
webView.loadUrl(url)

val popupWindow = PopupWindow(
binding.root,
RelativeLayout.LayoutParams.MATCH_PARENT,
RelativeLayout.LayoutParams.MATCH_PARENT
)

popupWindow.showAtLocation(this.window.decorView, Gravity.CENTER, 0, 0)

binding.close.setOnClickListener {
popupWindow.dismiss()
}
}

fun onKey(keyCode: Int): Boolean {
Log.d(TAG, "keyCode $keyCode")
when (keyCode) {
Expand Down
24 changes: 16 additions & 8 deletions app/src/main/java/com/lizongying/mytv0/ModalFragment.kt
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package com.lizongying.mytv0

import android.content.Intent
import android.net.Uri
import android.content.res.Configuration
import android.os.Bundle
import android.os.Handler
import android.os.Looper
import android.util.Log
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
Expand Down Expand Up @@ -54,12 +54,15 @@ class ModalFragment : DialogFragment() {
.into(binding.modalImage)
binding.modalText.text = u.removePrefix("http://")
binding.modalText.visibility = View.VISIBLE
binding.modal.setOnClickListener {
val intent = Intent(Intent.ACTION_VIEW, Uri.parse(u))
try {
startActivity(intent)
} catch (e: Exception) {
e.printStackTrace()
if (!isTV()) {
binding.modal.setOnClickListener {
try {
val mainActivity = (activity as MainActivity)
mainActivity.showWebViewPopup(u)
handler.postDelayed(hideAppreciateModal, 0)
} catch (e: Exception) {
Log.e(TAG, "onViewCreated", e)
}
}
}
} else {
Expand All @@ -78,6 +81,11 @@ class ModalFragment : DialogFragment() {
}
}

private fun isTV(): Boolean {
val uiMode = resources.configuration.uiMode and Configuration.UI_MODE_TYPE_MASK
return uiMode == Configuration.UI_MODE_TYPE_TELEVISION
}

override fun onDestroyView() {
super.onDestroyView()
_binding = null
Expand Down
6 changes: 1 addition & 5 deletions app/src/main/java/com/lizongying/mytv0/models/Sources.kt
Original file line number Diff line number Diff line change
Expand Up @@ -101,11 +101,7 @@ class Sources {
}

fun getSource(idx: Int): Source? {
if (idx >= size()) {
return null
}

if (sourcesValue.isEmpty()) {
if (idx < 0 || idx >= size()) {
return null
}

Expand Down
27 changes: 27 additions & 0 deletions app/src/main/res/layout/settings_web.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/settings_web"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/blur">

<androidx.appcompat.widget.AppCompatButton
android:id="@+id/close"
android:layout_width="60dp"
android:layout_height="50dp"
android:padding="10dp"
android:text="X"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<WebView
android:id="@+id/web"
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintTop_toBottomOf="@id/close"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
/>
</androidx.constraintlayout.widget.ConstraintLayout>
2 changes: 1 addition & 1 deletion version.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"version_code": 16976128, "version_name": "v1.3.9.0"}
{"version_code": 16976129, "version_name": "v1.3.9.1"}

0 comments on commit 763eeda

Please sign in to comment.