keep screen on

This commit is contained in:
Li ZongYing 2023-12-16 15:09:09 +08:00
parent d8fffbb402
commit 434915fd3d
12 changed files with 45 additions and 15 deletions

2
app/.gitignore vendored
View File

@ -3,4 +3,4 @@
/cmake_install.cmake /cmake_install.cmake
/CMakeFiles/ /CMakeFiles/
/Makefile /Makefile
/src/main/cpp/native-lib.c /src/main/cpp/native.c

View File

@ -15,17 +15,17 @@ if (IS_SO_BUILD)
# and CMake builds them for you. When you build your app, Gradle # and CMake builds them for you. When you build your app, Gradle
# automatically packages shared libraries with your APK. # automatically packages shared libraries with your APK.
add_library( # Specifies the name of the library. add_library( # Specifies the name of the library.
native-lib native
# Sets the library as a shared library. # Sets the library as a shared library.
SHARED SHARED
# Provides a relative path to your source file(s). # Provides a relative path to your source file(s).
src/main/cpp/native-lib.c) src/main/cpp/native.c)
# #
set_target_properties( set_target_properties(
native-lib native
PROPERTIES PROPERTIES
LIBRARY_OUTPUT_DIRECTORY LIBRARY_OUTPUT_DIRECTORY
${CMAKE_SOURCE_DIR}/src/main/cpp/${ANDROID_ABI} ${CMAKE_SOURCE_DIR}/src/main/cpp/${ANDROID_ABI}
@ -36,18 +36,18 @@ else ()
SHARED SHARED
src/main/cpp/nothing.c) src/main/cpp/nothing.c)
add_library(native-lib add_library(native
SHARED SHARED
IMPORTED) IMPORTED)
set_target_properties( # Specifies the target library. set_target_properties( # Specifies the target library.
native-lib native
# Specifies the parameter you want to define. # Specifies the parameter you want to define.
PROPERTIES IMPORTED_LOCATION PROPERTIES IMPORTED_LOCATION
# Provides the path to the library you want to import. # Provides the path to the library you want to import.
${CMAKE_SOURCE_DIR}/src/main/cpp/${ANDROID_ABI}/libnative-lib.so) ${CMAKE_SOURCE_DIR}/src/main/cpp/${ANDROID_ABI}/libnative.so)
endif () endif ()
add_library(libssl add_library(libssl
@ -87,7 +87,7 @@ find_library( # Defines the name of the path variable that stores the
if (IS_SO_BUILD) if (IS_SO_BUILD)
# Links your native library against one or more other native libraries. # Links your native library against one or more other native libraries.
target_link_libraries( # Specifies the target library. target_link_libraries( # Specifies the target library.
native-lib native
libssl libssl
libcrypto libcrypto
${log-lib}) ${log-lib})
@ -96,6 +96,6 @@ else ()
nothing nothing
libssl libssl
libcrypto libcrypto
native-lib native
${log-lib}) ${log-lib})
endif () endif ()

View File

@ -104,7 +104,7 @@ dependencies {
implementation 'com.squareup.retrofit2:retrofit:2.9.0' implementation 'com.squareup.retrofit2:retrofit:2.9.0'
implementation "org.jetbrains.kotlinx:kotlinx-serialization-json:1.6.2" implementation "org.jetbrains.kotlinx:kotlinx-serialization-json:1.6.2"
implementation 'androidx.core:core-ktx:1.11.0-beta02' implementation 'androidx.core:core-ktx:1.11.0-beta02'
implementation 'androidx.leanback:leanback:1.0.0' implementation 'androidx.leanback:leanback:1.2.0-alpha02'
implementation 'com.github.bumptech.glide:glide:4.11.0' implementation 'com.github.bumptech.glide:glide:4.11.0'
implementation "androidx.lifecycle:lifecycle-runtime-ktx:2.6.2" implementation "androidx.lifecycle:lifecycle-runtime-ktx:2.6.2"
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-android:1.8.0-RC") implementation("org.jetbrains.kotlinx:kotlinx-coroutines-android:1.8.0-RC")

View File

@ -14,6 +14,7 @@
android:supportsRtl="true" android:supportsRtl="true"
android:theme="@style/Theme.MyTV"> android:theme="@style/Theme.MyTV">
<activity <activity
android:keepScreenOn="true"
android:name=".MainActivity" android:name=".MainActivity"
android:banner="@drawable/tv" android:banner="@drawable/tv"
android:exported="true" android:exported="true"

View File

@ -11,7 +11,7 @@ class Encryptor {
companion object { companion object {
init { init {
System.loadLibrary("native-lib") System.loadLibrary("native")
} }
} }
} }

View File

@ -11,6 +11,7 @@ import android.os.Handler
import android.os.Looper import android.os.Looper
import android.util.Log import android.util.Log
import android.view.KeyEvent import android.view.KeyEvent
import android.view.WindowManager
import android.widget.ImageView import android.widget.ImageView
import android.widget.LinearLayout import android.widget.LinearLayout
import android.widget.TextView import android.widget.TextView
@ -32,6 +33,8 @@ class MainActivity : FragmentActivity() {
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main) setContentView(R.layout.activity_main)
window.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
if (savedInstanceState == null) { if (savedInstanceState == null) {
supportFragmentManager.beginTransaction() supportFragmentManager.beginTransaction()
.add(R.id.main_browse_fragment, playbackFragment) .add(R.id.main_browse_fragment, playbackFragment)

View File

@ -36,6 +36,16 @@ class MainFragment : BrowseSupportFragment() {
private var sharedPref: SharedPreferences? = null private var sharedPref: SharedPreferences? = null
// override fun onCreateView(
// inflater: LayoutInflater,
// container: ViewGroup?,
// savedInstanceState: Bundle?
// ): View? {
// super.onCreate()
// // 使用自定义的布局文件
// return inflater.inflate(R.layout.custom_browse_fragment, container, false)
// }
override fun onActivityCreated(savedInstanceState: Bundle?) { override fun onActivityCreated(savedInstanceState: Bundle?) {
super.onActivityCreated(savedInstanceState) super.onActivityCreated(savedInstanceState)
@ -66,7 +76,6 @@ class MainFragment : BrowseSupportFragment() {
private fun setupUIElements() { private fun setupUIElements() {
brandColor = ContextCompat.getColor(context!!, R.color.fastlane_background) brandColor = ContextCompat.getColor(context!!, R.color.fastlane_background)
// headersState = HEADERS_DISABLED
} }
private fun updateRows(tv: TV) { private fun updateRows(tv: TV) {
@ -111,17 +120,29 @@ class MainFragment : BrowseSupportFragment() {
adapter = rowsAdapter adapter = rowsAdapter
itemPosition = sharedPref?.getInt("position", 0)!! itemPosition = sharedPref?.getInt("position", 0)!!
if (itemPosition >= tvListViewModel.size()) {
itemPosition = 0
savePosition(0)
}
val tv = list2[itemPosition].item
val tvModel = tvListViewModel.getTVModel(itemPosition) val tvModel = tvListViewModel.getTVModel(itemPosition)
if (tvModel?.ysp() != null) { if (tvModel?.ysp() != null) {
Log.i(TAG, "ysp ${tvModel.getTV()}")
lifecycleScope.launch(Dispatchers.IO) { lifecycleScope.launch(Dispatchers.IO) {
tvModel.let { request?.fetchData(it) } tvModel.let { request?.fetchData(it) }
} }
} else { } else {
(activity as? MainActivity)?.play(list2[itemPosition].item) (activity as? MainActivity)?.play(tv)
// (activity as? MainActivity)?.switchInfoFragment(list2[itemPosition].item) // (activity as? MainActivity)?.switchInfoFragment(tv)
} }
Toast.makeText(
activity,
tv.title,
Toast.LENGTH_SHORT
).show()
(activity as? MainActivity)?.switchMainFragment() (activity as? MainActivity)?.switchMainFragment()
} }

View File

@ -89,6 +89,7 @@ class Request(var context: Context) {
override fun onResponse(call: Call<LiveInfo>, response: Response<LiveInfo>) { override fun onResponse(call: Call<LiveInfo>, response: Response<LiveInfo>) {
if (response.isSuccessful) { if (response.isSuccessful) {
val liveInfo = response.body() val liveInfo = response.body()
Log.i(TAG, "liveInfo $liveInfo")
if (liveInfo?.data?.playurl != null) { if (liveInfo?.data?.playurl != null) {
val chanll = liveInfo.data.chanll val chanll = liveInfo.data.chanll
val decodedBytes = Base64.decode( val decodedBytes = Base64.decode(
@ -117,6 +118,7 @@ class Request(var context: Context) {
} }
override fun onFailure(call: Call<LiveInfo>, t: Throwable) { override fun onFailure(call: Call<LiveInfo>, t: Throwable) {
Log.i(TAG, "get data error")
} }
}) })
} }

View File

@ -1,6 +1,5 @@
package com.lizongying.mytv.models package com.lizongying.mytv.models
import android.util.Log
import androidx.lifecycle.MutableLiveData import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel import androidx.lifecycle.ViewModel
import com.lizongying.mytv.TV import com.lizongying.mytv.TV
@ -41,4 +40,8 @@ class TVListViewModel : ViewModel() {
fun getTVModel(id: Int): TVViewModel? { fun getTVModel(id: Int): TVViewModel? {
return tvModelListLiveData.value?.get(id) return tvModelListLiveData.value?.get(id)
} }
fun size(): Int {
return tvListLiveData.value!!.size
}
} }