-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
*.iml | ||
.gradle | ||
/local.properties | ||
/.idea/caches | ||
/.idea/libraries | ||
/.idea/modules.xml | ||
/.idea/workspace.xml | ||
/.idea/navEditor.xml | ||
/.idea/assetWizardSettings.xml | ||
.DS_Store | ||
/build | ||
/captures | ||
.externalNativeBuild | ||
.cxx | ||
local.properties |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/build |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
plugins { | ||
id 'com.android.application' | ||
id 'org.jetbrains.kotlin.android' | ||
} | ||
|
||
android { | ||
namespace 'com.lizongying.mytv' | ||
compileSdk 33 | ||
|
||
defaultConfig { | ||
applicationId "com.lizongying.mytv" | ||
minSdk 23 | ||
targetSdk 33 | ||
versionCode 1 | ||
versionName "1.0" | ||
|
||
} | ||
|
||
buildTypes { | ||
release { | ||
minifyEnabled false | ||
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' | ||
} | ||
} | ||
|
||
compileOptions { | ||
sourceCompatibility JavaVersion.VERSION_17 | ||
targetCompatibility JavaVersion.VERSION_17 | ||
} | ||
|
||
kotlinOptions { | ||
jvmTarget=17 | ||
} | ||
} | ||
|
||
dependencies { | ||
|
||
implementation 'androidx.core:core-ktx:1.11.0-beta02' | ||
implementation 'androidx.leanback:leanback:1.0.0' | ||
implementation 'com.github.bumptech.glide:glide:4.11.0' | ||
implementation "androidx.lifecycle:lifecycle-runtime-ktx:2.6.2" | ||
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-android:1.8.0-RC") | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# Add project specific ProGuard rules here. | ||
# You can control the set of applied configuration files using the | ||
# proguardFiles setting in build.gradle. | ||
# | ||
# For more details, see | ||
# http://developer.android.com/guide/developing/tools/proguard.html | ||
|
||
# If your project uses WebView with JS, uncomment the following | ||
# and specify the fully qualified class name to the JavaScript interface | ||
# class: | ||
#-keepclassmembers class fqcn.of.javascript.interface.for.webview { | ||
# public *; | ||
#} | ||
|
||
# Uncomment this to preserve the line number information for | ||
# debugging stack traces. | ||
#-keepattributes SourceFile,LineNumberTable | ||
|
||
# If you keep the line number information, uncomment this to | ||
# hide the original source file name. | ||
#-renamesourcefileattribute SourceFile |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" | ||
xmlns:tools="http://schemas.android.com/tools"> | ||
|
||
<application | ||
android:allowBackup="true" | ||
android:icon="@mipmap/ic_launcher" | ||
android:label="@string/app_name" | ||
android:supportsRtl="true" | ||
android:theme="@style/Theme.MyTV"> | ||
<activity | ||
android:name=".MainActivity" | ||
android:banner="@drawable/tv" | ||
android:exported="true" | ||
android:icon="@drawable/tv" | ||
android:label="@string/app_name" | ||
android:logo="@drawable/tv" | ||
android:screenOrientation="landscape"> | ||
<intent-filter> | ||
<action android:name="android.intent.action.MAIN" /> | ||
|
||
<category android:name="android.intent.category.LEANBACK_LAUNCHER" /> | ||
</intent-filter> | ||
</activity> | ||
</application> | ||
|
||
<uses-feature | ||
android:name="android.software.leanback" | ||
android:required="true" /> | ||
<uses-feature | ||
android:name="android.hardware.touchscreen" | ||
android:required="false" /> | ||
|
||
<uses-permission android:name="android.permission.INTERNET" /> | ||
|
||
</manifest> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
package com.lizongying.mytv | ||
|
||
import android.graphics.Bitmap | ||
import android.media.MediaMetadataRetriever | ||
import android.util.Log | ||
import android.view.ContextThemeWrapper | ||
import android.view.ViewGroup | ||
import androidx.core.content.ContextCompat | ||
import androidx.leanback.widget.ImageCardView | ||
import androidx.leanback.widget.Presenter | ||
import androidx.lifecycle.LifecycleCoroutineScope | ||
import kotlinx.coroutines.Dispatchers | ||
import kotlinx.coroutines.delay | ||
import kotlinx.coroutines.launch | ||
import kotlinx.coroutines.withContext | ||
import kotlin.properties.Delegates | ||
|
||
|
||
/** | ||
* A CardPresenter is used to generate Views and bind Objects to them on demand. | ||
* It contains an ImageCardView. | ||
*/ | ||
class CardPresenter(private val lifecycleScope: LifecycleCoroutineScope) : Presenter() { | ||
|
||
override fun onCreateViewHolder(parent: ViewGroup): ViewHolder { | ||
Log.d(TAG, "onCreateViewHolder") | ||
|
||
val cardView = object : | ||
ImageCardView(ContextThemeWrapper(parent.context, R.style.CustomImageCardTheme)) { | ||
override fun setSelected(selected: Boolean) { | ||
// updateCardBackgroundColor(this) | ||
super.setSelected(selected) | ||
} | ||
} | ||
|
||
cardView.isFocusable = true | ||
cardView.isFocusableInTouchMode = true | ||
return ViewHolder(cardView) | ||
} | ||
|
||
override fun onBindViewHolder(viewHolder: ViewHolder, item: Any) { | ||
val tv = item as TV | ||
val cardView = viewHolder.view as ImageCardView | ||
|
||
Log.d(TAG, "onBindViewHolder") | ||
if (tv.videoUrl != null) { | ||
cardView.titleText = tv.title | ||
cardView.setMainImageDimensions(CARD_WIDTH, CARD_HEIGHT) | ||
cardView.tag = tv.videoUrl | ||
|
||
// lifecycleScope.launch(Dispatchers.IO) { | ||
// val videoThumbnail = tv.videoUrl?.let { getVideoThumbnail(it) } | ||
// | ||
// withContext(Dispatchers.Main) { | ||
// cardView.mainImageView.setImageBitmap(videoThumbnail) | ||
// } | ||
// } | ||
} | ||
} | ||
|
||
override fun onUnbindViewHolder(viewHolder: ViewHolder) { | ||
Log.d(TAG, "onUnbindViewHolder") | ||
val cardView = viewHolder.view as ImageCardView | ||
// Remove references to images so that the garbage collector can free up memory | ||
cardView.badgeImage = null | ||
cardView.mainImage = null | ||
} | ||
|
||
private fun updateCardBackgroundColor(view: ImageCardView) { | ||
val currentTag = view.tag | ||
lifecycleScope.launch(Dispatchers.IO) { | ||
delay(1000) | ||
if (view.isSelected && view.tag != null && currentTag == view.tag) { | ||
val videoThumbnail = view.tag.toString().let { getVideoThumbnail(it) } | ||
withContext(Dispatchers.Main) { | ||
if (view.isSelected && currentTag == view.tag) { | ||
view.mainImageView.setImageBitmap(videoThumbnail) | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
private fun getVideoThumbnail(url: String): Bitmap? { | ||
val mediaMetadataRetriever = MediaMetadataRetriever() | ||
try { | ||
val map = HashMap<String, String>() | ||
mediaMetadataRetriever.setDataSource(url, map) | ||
return mediaMetadataRetriever.frameAtTime | ||
} catch (e: Exception) { | ||
e.printStackTrace() | ||
} finally { | ||
mediaMetadataRetriever.release() | ||
} | ||
return null | ||
} | ||
|
||
companion object { | ||
private const val TAG = "CardPresenter" | ||
|
||
private const val CARD_WIDTH = 313 | ||
|
||
private const val CARD_HEIGHT = 176 | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package com.lizongying.mytv | ||
|
||
import java.io.Serializable | ||
|
||
|
||
data class Info( | ||
var rowPosition: Int = 0, | ||
var itemPosition: Int = 0, | ||
var item: TV? = null, | ||
) : Serializable |