Skip to content

Commit

Permalink
remove LocaleContextWrapper
Browse files Browse the repository at this point in the history
  • Loading branch information
lizongying committed Oct 15, 2024
1 parent 72e35dd commit 458d314
Show file tree
Hide file tree
Showing 13 changed files with 51 additions and 28 deletions.
2 changes: 1 addition & 1 deletion HISTORY.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
## 更新日誌

### v1.3.7.17
### v1.3.7.18

* 這是一個測試,嘗試解決一個ClassCastException

Expand Down
6 changes: 3 additions & 3 deletions app/src/main/java/com/lizongying/mytv0/MainViewModel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ import com.google.gson.JsonSyntaxException
import com.lizongying.mytv0.R
import com.lizongying.mytv0.SP
import com.lizongying.mytv0.Utils.getDateFormat
import com.lizongying.mytv0.models.EPGXmlParser
import com.lizongying.mytv0.data.SourceType
import com.lizongying.mytv0.data.TV
import com.lizongying.mytv0.models.EPGXmlParser
import com.lizongying.mytv0.models.TVGroupModel
import com.lizongying.mytv0.models.TVListModel
import com.lizongying.mytv0.models.TVModel
Expand Down Expand Up @@ -115,8 +115,8 @@ class MainViewModel : ViewModel() {
}
}
} catch (e: Exception) {
e.printStackTrace()
R.string.epg_request_err.showToast()
Log.i(TAG, "EPG request error:", e)
// R.string.epg_request_err.showToast()
}
}

Expand Down
19 changes: 19 additions & 0 deletions app/src/main/java/com/lizongying/mytv0/MyTVApplication.kt
Original file line number Diff line number Diff line change
Expand Up @@ -102,4 +102,23 @@ class MyTVApplication : Application() {
fun sp2Px(sp: Float): Float {
return (sp * ratio * scale).toFloat()
}

override fun attachBaseContext(base: Context) {
try {
val locale = Locale.TRADITIONAL_CHINESE
val config = Configuration()
config.setLocale(locale)
super.attachBaseContext(
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N_MR1) {
base.createConfigurationContext(config)
} else {
val resources = base.resources
resources.updateConfiguration(config, resources.displayMetrics)
base
}
)
} catch (_: Exception) {
super.attachBaseContext(base)
}
}
}
5 changes: 3 additions & 2 deletions app/src/main/java/com/lizongying/mytv0/PlayerFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ import androidx.media3.exoplayer.DefaultRenderersFactory
import androidx.media3.exoplayer.ExoPlayer
import androidx.media3.exoplayer.mediacodec.MediaCodecSelector
import androidx.media3.exoplayer.mediacodec.MediaCodecUtil
import com.lizongying.mytv0.databinding.PlayerBinding
import com.lizongying.mytv0.data.SourceType
import com.lizongying.mytv0.databinding.PlayerBinding
import com.lizongying.mytv0.models.TVModel


Expand All @@ -39,6 +39,7 @@ class PlayerFragment : Fragment() {

private lateinit var mainActivity: MainActivity

@Deprecated("Deprecated in Java")
override fun onActivityCreated(savedInstanceState: Bundle?) {
mainActivity = activity as MainActivity
super.onActivityCreated(savedInstanceState)
Expand Down Expand Up @@ -115,7 +116,7 @@ class PlayerFragment : Fragment() {
}

override fun onPlayerError(error: PlaybackException) {
super.onPlayerError(error)
Log.i(TAG, "player: ${error.errorCodeName}")
tvModel?.setErrInfo(R.string.play_error.getString())
if (tvModel?.getSourceType() == SourceType.UNKNOWN) {
tvModel?.nextSource()
Expand Down
1 change: 1 addition & 0 deletions app/src/main/java/com/lizongying/mytv0/SP.kt
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ object SP {
Log.i(TAG, "group position $positionGroup")
Log.i(TAG, "list position $position")
Log.i(TAG, "default channel $channel")
Log.i(TAG, "proxy $proxy")
}

var channelReversal: Boolean
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/java/com/lizongying/mytv0/SimpleServer.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import android.content.Context
import android.net.Uri
import android.os.Handler
import android.os.Looper
import android.util.Log
import com.google.gson.Gson
import com.lizongying.mytv0.data.ReqSettings
import com.lizongying.mytv0.data.RespSettings
Expand Down Expand Up @@ -116,6 +117,7 @@ class SimpleServer(private val context: Context, private val viewModel: MainView
readBody(session)?.let {
handler.post {
val req = Gson().fromJson(it, ReqSettings::class.java)
Log.i(TAG, "req $req")
if (req.proxy != null) {
SP.proxy = req.proxy
R.string.default_proxy_set_success.showToast()
Expand Down
5 changes: 2 additions & 3 deletions app/src/main/java/com/lizongying/mytv0/Utils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import com.lizongying.mytv0.ISP.CHINA_MOBILE
import com.lizongying.mytv0.ISP.CHINA_TELECOM
import com.lizongying.mytv0.ISP.CHINA_UNICOM
import com.lizongying.mytv0.ISP.UNKNOWN
import com.lizongying.mytv0.requests.HttpClient
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
Expand Down Expand Up @@ -93,13 +94,11 @@ object Utils {
*/
private suspend fun getTimestampFromServer(): Long {
return withContext(Dispatchers.IO) {
IgnoreSSLCertificate.ignore()
val client = okhttp3.OkHttpClient.Builder().build()
val request = okhttp3.Request.Builder()
.url("https://ip.ddnspod.com/timestamp")
.build()
try {
client.newCall(request).execute().use { response ->
HttpClient.okHttpClient.newCall(request).execute().use { response ->
if (!response.isSuccessful) return@withContext 0
response.body?.string()?.toLong() ?: 0
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class TVGroupModel : ViewModel() {
}

fun setPosition(position: Int) {
Log.i(TAG, "group setPosition $position")
Log.i(TAG, "選擇組 $position")
_position.value = position
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class TVListModel(private val name: String, private val groupIndex: Int) : ViewM
get() = _positionPlaying.value ?: 0

fun setPosition(position: Int) {
Log.i(TAG, "播放頻道 $position")
Log.i(TAG, "選擇頻道 $position")
_position.value = position
}

Expand Down
16 changes: 11 additions & 5 deletions app/src/main/java/com/lizongying/mytv0/models/TVModel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel
import androidx.media3.common.MediaItem
import androidx.media3.common.util.UnstableApi
import androidx.media3.datasource.DataSource
import androidx.media3.datasource.DefaultHttpDataSource
import androidx.media3.exoplayer.dash.DashMediaSource
import androidx.media3.exoplayer.hls.HlsMediaSource
Expand Down Expand Up @@ -127,7 +128,7 @@ class TVModel(var tv: TV) : ViewModel() {
}
}

private lateinit var httpDataSource: DefaultHttpDataSource.Factory
private lateinit var httpDataSource: DataSource.Factory

init {
_position.value = 0
Expand All @@ -149,11 +150,14 @@ class TVModel(var tv: TV) : ViewModel() {
val path = uri.path ?: return
val scheme = uri.scheme ?: return

httpDataSource = DefaultHttpDataSource.Factory()
httpDataSource.setKeepPostFor302Redirects(true)
httpDataSource.setAllowCrossProtocolRedirects(true)
// val okHttpDataSource = OkHttpDataSource.Factory(HttpClient.okHttpClient)
// httpDataSource = okHttpDataSource

val defaultHttpDataSource = DefaultHttpDataSource.Factory()
defaultHttpDataSource.setKeepPostFor302Redirects(true)
defaultHttpDataSource.setAllowCrossProtocolRedirects(true)
tv.headers?.let {
httpDataSource.setDefaultRequestProperties(it)
defaultHttpDataSource.setDefaultRequestProperties(it)
it.forEach { (key, value) ->
if (key.equals("user-agent", ignoreCase = true)) {
userAgent = value
Expand All @@ -162,6 +166,8 @@ class TVModel(var tv: TV) : ViewModel() {
}
}

httpDataSource = defaultHttpDataSource

_mediaItem = MediaItem.fromUri(uri.toString())

if (path.lowercase().endsWith(".m3u8")) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,6 @@ object HttpClient {
.dns(DnsCache())

if (SP.proxy != "") {
Log.i(TAG, "proxy ${SP.proxy}")
val uri = Uri.parse(SP.proxy)
val proxy = Proxy(Proxy.Type.HTTP, InetSocketAddress(uri.host, uri.port))
builder.proxy(proxy)
Expand Down
16 changes: 6 additions & 10 deletions app/src/main/res/raw/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -197,20 +197,16 @@ <h1 class="title">我的電視·〇</h1>

document.querySelector('#confirm-proxy').onclick = () => {
const proxy = document.querySelector('#proxy').value.trim();
if (proxy.length > 0) {
save('/api/proxy', JSON.stringify({
proxy: proxy
}))
}
save('/api/proxy', JSON.stringify({
proxy: proxy
}))
}

document.querySelector('#confirm-epg').onclick = () => {
const epg = document.querySelector('#epg').value.trim();
if (epg.length > 0) {
save('/api/epg', JSON.stringify({
epg: epg
}))
}
save('/api/epg', JSON.stringify({
epg: epg
}))
}
const save = async (url, body) => {
const response = await fetch(url, {
Expand Down
2 changes: 1 addition & 1 deletion version.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"version_code": 16975633, "version_name": "v1.3.7.17"}
{"version_code": 16975634, "version_name": "v1.3.7.18"}

0 comments on commit 458d314

Please sign in to comment.