Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(app): androidtv support #1592

Draft
wants to merge 6 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions app/src/debug/res/drawable/ic_banner_foreground.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:width="56dp"
android:height="56dp"
android:gravity="center_vertical"
android:left="41dp"
android:drawable="@drawable/ic_ani"/>
<item>
<vector
android:width="320dp"
android:height="180dp"
android:viewportWidth="320.0"
android:viewportHeight="180.0">
<path
android:pathData="m 124.21216,110.56 -2.072,-9.632 h -8.904 l -2.072,9.632 h -8.232 l 9.688,-39.984002 h 9.912 l 9.856,39.984002 z m -5.432,-26.880002 q -0.672,-3.976 -1.12,-7.168 -0.28,3.136 -1.12,7.056 l -2.128,10.696 h 6.552 z m 30.52005,-4.312 q 3.864,0 5.936,2.8 2.128,2.8 2.128,8.12 V 110.56 h -7.28 V 92.415998 q 0,-3.248 -0.672,-4.872 -0.672,-1.68 -2.464,-1.68 -2.296,0 -3.248,2.24 -0.896,2.24 -0.896,7.728 V 110.56 h -7.28 V 79.927998 h 5.768 l 0.784,3.92 h 0.448 q 2.072,-4.48 6.776,-4.48 z m 17.97597,-11.48 q 3.976,0 3.976,4.2 0,4.088 -3.976,4.088 -3.976,0 -3.976,-4.088 0,-4.2 3.976,-4.2 z m 3.64,12.04 V 110.56 h -7.28 V 79.927998 Z m 3.35997,0 h 7.616 l 3.584,14.84 q 0.784,3.192 1.064,5.824002 h 0.224 q 0.112,-1.120002 0.392,-2.520002 0.336,-1.456 0.728,-3.248 l 3.36,-14.896 h 7.56 l -9.128,33.600002 q -1.568,5.656 -3.92,8.064 -2.296,2.408 -6.104,2.408 -0.896,0 -1.792,-0.112 -0.84,-0.112 -1.68,-0.336 v -6.44 q 0.56,0.168 1.12,0.28 0.56,0.112 1.064,0.112 1.12,0 1.792,-0.448 0.728,-0.448 1.288,-1.624 0.56,-1.176 1.176,-3.36 l 0.448,-1.848 z m 50.00802,15.232 q 0,4.256 -1.176,7.896002 -1.12,3.64 -3.696,5.88 -2.576,2.184 -6.832,2.184 -3.976,0 -6.552,-2.184 -2.576,-2.184 -3.808,-5.824 -1.232,-3.640002 -1.232,-7.952002 0,-4.648 1.176,-8.176 1.232,-3.584 3.808,-5.6 2.632,-2.016 6.72,-2.016 5.32,0 8.456,4.088 3.136,4.032 3.136,11.704 z m -15.904,0.112 q 0,4.760002 1.008,7.224002 1.008,2.464 3.248,2.464 2.296,0 3.248,-2.408 0.952,-2.464 0.952,-7.392002 0,-4.816 -0.952,-7.224 -0.952,-2.408 -3.248,-2.408 -2.24,0 -3.248,2.408 -1.008,2.352 -1.008,7.336 z m 48.94405,-15.904 q 7.784,0 7.784,11.032 V 110.56 h -7.28 V 92.527998 q 0,-6.664 -3.024,-6.664 -2.184,0 -3.024,2.296 -0.84,2.24 -0.84,6.888 V 110.56 h -7.336 V 92.471998 q 0,-3.416 -0.728,-4.984 -0.672,-1.624 -2.184,-1.624 -2.352,0 -3.192,2.576 -0.784,2.52 -0.784,7.504 V 110.56 h -7.28 V 79.927998 h 5.768 l 0.784,3.92 h 0.448 q 1.792,-4.48 7.112,-4.48 2.632,0 4.2,1.232 1.568,1.232 2.24,3.136 h 0.504 q 1.064,-2.128 2.688,-3.248 1.68,-1.12 4.144,-1.12 z m 17.63998,-11.48 q 3.976,0 3.976,4.2 0,4.088 -3.976,4.088 -3.976,0 -3.976,-4.088 0,-4.2 3.976,-4.2 z m 3.64,12.04 V 110.56 h -7.28 V 79.927998 Z"
android:fillColor="#FFFFFF"/>
<path
android:pathData="m 204.59333,123.98062 q 2.05334,0 3.17334,1.97333 1.12,1.97334 1.12,5.62668 0,3.52 -1.12,5.52 -1.09334,2.00001 -3.06667,2.00001 -0.98667,0 -1.81334,-0.53334 -0.82667,-0.53333 -1.38667,-1.65333 h -0.13333 q 0.0533,0.82666 0.08,1.46667 0.0267,0.61333 0.0267,1.01333 v 5.84001 h -3.46667 v -20.9867 h 2.8 l 0.50667,1.92001 h 0.18666 q 0.66667,-1.28001 1.38667,-1.73334 0.72,-0.45333 1.70667,-0.45333 z M 203.5,126.91395 q -1.06667,0 -1.54667,1.01334 -0.48,1.01333 -0.48,3.25334 v 0.72 q 0,2.18667 0.48,3.2 0.50667,0.98667 1.54667,0.98667 1.86667,0 1.86667,-4.48001 0,-4.69334 -1.86667,-4.69334 z m 14.18668,-2.93333 q 0.53334,0 1.2,0.18666 l -0.32,3.70668 q -0.48,-0.18667 -1.22667,-0.18667 -1.22666,0 -1.86667,1.01333 -0.64,0.98667 -0.64,2.69334 v 7.44001 h -3.46667 v -14.58669 h 2.66667 l 0.50667,2.40001 h 0.16 q 0.42667,-1.04 1.17334,-1.84001 0.77333,-0.82666 1.81333,-0.82666 z m 7.33337,0.0267 q 2.45334,0 3.76001,1.78667 1.33333,1.78667 1.33333,4.80001 v 1.94667 h -6.96001 q 0.0267,1.92 0.69334,2.82667 0.69333,0.90667 2.08,0.90667 0.93333,0 1.76,-0.24 0.82667,-0.24 1.76,-0.82667 v 2.88 q -1.70667,1.01334 -4,1.01334 -3.01334,0 -4.37334,-2.00001 -1.33334,-2 -1.33334,-5.46667 0,-3.68 1.33334,-5.65334 1.33333,-1.97334 3.94667,-1.97334 z m 0.08,2.72001 q -0.85333,0 -1.36,0.77333 -0.50667,0.77334 -0.56,2.53334 h 3.70667 q 0,-1.54667 -0.48,-2.42667 -0.45333,-0.88 -1.30667,-0.88 z m 9.57339,12.10668 -3.94667,-14.58669 h 3.6 l 1.65334,7.70668 q 0.34666,1.46667 0.50666,3.14667 h 0.10667 q 0.0267,-0.61333 0.13333,-1.33333 0.13334,-0.74667 0.32,-1.60001 l 1.76001,-7.92001 h 3.6 l -3.97334,14.58669 z m 11.06668,-20.32003 q 1.89334,0 1.89334,2.00001 0,1.94667 -1.89334,1.94667 -1.89333,0 -1.89333,-1.94667 0,-2.00001 1.89333,-2.00001 z m 1.73334,5.73334 v 14.58669 h -3.46667 v -14.58669 z m 7.76,-0.24 q 2.45333,0 3.76,1.78667 1.33334,1.78667 1.33334,4.80001 v 1.94667 h -6.96001 q 0.0267,1.92 0.69333,2.82667 0.69334,0.90667 2.08001,0.90667 0.93333,0 1.76,-0.24 0.82667,-0.24 1.76,-0.82667 v 2.88 q -1.70667,1.01334 -4,1.01334 -3.01334,0 -4.37334,-2.00001 -1.33334,-2 -1.33334,-5.46667 0,-3.68 1.33334,-5.65334 1.33333,-1.97334 3.94667,-1.97334 z m 0.08,2.72001 q -0.85334,0 -1.36,0.77333 -0.50667,0.77334 -0.56,2.53334 h 3.70667 q 0,-1.54667 -0.48,-2.42667 -0.45334,-0.88 -1.30667,-0.88 z m 15.20006,4.77334 q -0.13333,-0.90667 -0.26667,-1.92001 -0.13333,-1.04 -0.24,-1.89333 h -0.08 q -0.13333,0.96 -0.26666,2 -0.13334,1.01334 -0.26667,1.78667 l -1.36,7.36001 h -3.94667 l -3.06667,-14.58669 h 3.46667 l 1.04,5.60001 q 0.21333,1.09334 0.34667,2.4 0.16,1.28001 0.26666,2.50667 h 0.08 q 0.10667,-1.01333 0.24,-2.16 0.16,-1.14667 0.42667,-2.53334 l 1.12,-5.81334 h 3.97334 l 1.09333,5.89334 q 0.18667,1.14667 0.34667,2.34667 0.18667,1.20001 0.29334,2.26667 h 0.10666 q 0.0533,-0.96 0.18667,-2.08 0.13333,-1.12 0.32,-2.24 l 1.2,-6.18668 h 3.41334 l -3.12001,14.58669 h -4 z"
android:fillColor="#FFFFFF"/>
</vector>
</item>
</layer-list>
9 changes: 9 additions & 0 deletions app/src/debug/res/mipmap/ic_ani_banner.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
<background>
<color android:color="#455A64"/>
</background>
<foreground>
<inset android:inset="15%" android:drawable="@drawable/ic_banner_foreground"/>
</foreground>
</adaptive-icon>
6 changes: 6 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,17 @@

<uses-permission android:name="android.permission.FOREGROUND_SERVICE_DATA_SYNC" />

<!-- Android TV -->
<uses-feature android:name="android.software.leanback" android:required="false" />
<uses-feature android:name="android.hardware.touchscreen" android:required="false" />

<application
android:name=".App"
android:allowBackup="false"
android:enableOnBackInvokedCallback="true"
android:hardwareAccelerated="true"
android:icon="@mipmap/ic_launcher"
android:banner="@mipmap/ic_ani_banner"
android:label="@string/app_name"
android:largeHeap="true"
android:localeConfig="@xml/locales_config"
Expand All @@ -58,6 +63,7 @@
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
<category android:name="android.intent.category.LEANBACK_LAUNCHER" />
</intent-filter>

<!-- Deep link to add manga repos -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.runtime.Composable
import androidx.compose.runtime.State
import androidx.compose.ui.Modifier
import androidx.compose.ui.focus.FocusRequester
import androidx.compose.ui.focus.focusProperties
import androidx.compose.ui.focus.focusRequester
import eu.kanade.presentation.browse.GlobalSearchErrorResultItem
import eu.kanade.presentation.browse.GlobalSearchLoadingResultItem
import eu.kanade.presentation.browse.GlobalSearchResultItem
Expand All @@ -30,6 +34,7 @@ fun GlobalAnimeSearchScreen(
onClickItem: (Anime) -> Unit,
onLongClickItem: (Anime) -> Unit,
) {
val contentFocus = FocusRequester()
Scaffold(
topBar = { scrollBehavior ->
GlobalAnimeSearchToolbar(
Expand All @@ -44,6 +49,10 @@ fun GlobalAnimeSearchScreen(
onlyShowHasResults = state.onlyShowHasResults,
onToggleResults = onToggleResults,
scrollBehavior = scrollBehavior,
modifier = Modifier
.focusProperties {
down = contentFocus
},
)
},
) { paddingValues ->
Expand All @@ -54,6 +63,7 @@ fun GlobalAnimeSearchScreen(
onClickSource = onClickSource,
onClickItem = onClickItem,
onLongClickItem = onLongClickItem,
modifier = Modifier.focusRequester(contentFocus),
)
}
}
Expand All @@ -66,10 +76,12 @@ internal fun GlobalSearchContent(
onClickSource: (AnimeCatalogueSource) -> Unit,
onClickItem: (Anime) -> Unit,
onLongClickItem: (Anime) -> Unit,
modifier: Modifier = Modifier,
fromSourceId: Long? = null,
) {
LazyColumn(
contentPadding = contentPadding,
modifier = modifier,
) {
items.forEach { (source, result) ->
item(key = source.id) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ fun GlobalAnimeSearchToolbar(
onlyShowHasResults: Boolean,
onToggleResults: () -> Unit,
scrollBehavior: TopAppBarScrollBehavior,
modifier: Modifier = Modifier,
) {
Column(modifier = Modifier.background(MaterialTheme.colorScheme.surface)) {
Box {
Expand All @@ -67,7 +68,7 @@ fun GlobalAnimeSearchToolbar(
}

Row(
modifier = Modifier
modifier = modifier
.horizontalScroll(rememberScrollState())
.padding(horizontal = MaterialTheme.padding.small),
horizontalArrangement = Arrangement.spacedBy(MaterialTheme.padding.small),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ internal fun BasePreferenceWidget(
modifier = modifier
.highlightBackground(highlighted)
.sizeIn(minHeight = minHeight)
.clickable(enabled = onClick != null, onClick = { onClick?.invoke() })
.then(if (onClick != null) Modifier.clickable(onClick = onClick) else Modifier)
.fillMaxWidth(),
verticalAlignment = Alignment.CenterVertically,
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ fun Context.prepareTabletUiContext(): Context {
val configuration = resources.configuration
val expected = when (Injekt.get<UiPreferences>().tabletUiMode().get()) {
TabletUiMode.AUTOMATIC ->
isTvBox(this) ||
configuration.smallestScreenWidthDp >= when (configuration.orientation) {
Configuration.ORIENTATION_PORTRAIT -> TABLET_UI_MIN_SCREEN_WIDTH_PORTRAIT_DP
else -> TABLET_UI_MIN_SCREEN_WIDTH_LANDSCAPE_DP
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ fun isTvBox(context: Context): Boolean {

// TV for sure
if (
pm.hasSystemFeature(PackageManager.FEATURE_LEANBACK) ||
context.getSystemService(UiModeManager::class.java)
.getCurrentModeType() == Configuration.UI_MODE_TYPE_TELEVISION
) {
Expand Down
20 changes: 20 additions & 0 deletions app/src/main/res/drawable/ic_banner_foreground.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:width="56dp"
android:height="56dp"
android:gravity="center_vertical"
android:left="41dp"
android:drawable="@drawable/ic_ani"/>
<item>
<vector
android:width="320dp"
android:height="180dp"
android:viewportWidth="320.0"
android:viewportHeight="180.0">
<path
android:pathData="m 124.21216,110.56 -2.072,-9.632 h -8.904 l -2.072,9.632 h -8.232 l 9.688,-39.984002 h 9.912 l 9.856,39.984002 z m -5.432,-26.880002 q -0.672,-3.976 -1.12,-7.168 -0.28,3.136 -1.12,7.056 l -2.128,10.696 h 6.552 z m 30.52005,-4.312 q 3.864,0 5.936,2.8 2.128,2.8 2.128,8.12 V 110.56 h -7.28 V 92.415998 q 0,-3.248 -0.672,-4.872 -0.672,-1.68 -2.464,-1.68 -2.296,0 -3.248,2.24 -0.896,2.24 -0.896,7.728 V 110.56 h -7.28 V 79.927998 h 5.768 l 0.784,3.92 h 0.448 q 2.072,-4.48 6.776,-4.48 z m 17.97597,-11.48 q 3.976,0 3.976,4.2 0,4.088 -3.976,4.088 -3.976,0 -3.976,-4.088 0,-4.2 3.976,-4.2 z m 3.64,12.04 V 110.56 h -7.28 V 79.927998 Z m 3.35997,0 h 7.616 l 3.584,14.84 q 0.784,3.192 1.064,5.824002 h 0.224 q 0.112,-1.120002 0.392,-2.520002 0.336,-1.456 0.728,-3.248 l 3.36,-14.896 h 7.56 l -9.128,33.600002 q -1.568,5.656 -3.92,8.064 -2.296,2.408 -6.104,2.408 -0.896,0 -1.792,-0.112 -0.84,-0.112 -1.68,-0.336 v -6.44 q 0.56,0.168 1.12,0.28 0.56,0.112 1.064,0.112 1.12,0 1.792,-0.448 0.728,-0.448 1.288,-1.624 0.56,-1.176 1.176,-3.36 l 0.448,-1.848 z m 50.00802,15.232 q 0,4.256 -1.176,7.896002 -1.12,3.64 -3.696,5.88 -2.576,2.184 -6.832,2.184 -3.976,0 -6.552,-2.184 -2.576,-2.184 -3.808,-5.824 -1.232,-3.640002 -1.232,-7.952002 0,-4.648 1.176,-8.176 1.232,-3.584 3.808,-5.6 2.632,-2.016 6.72,-2.016 5.32,0 8.456,4.088 3.136,4.032 3.136,11.704 z m -15.904,0.112 q 0,4.760002 1.008,7.224002 1.008,2.464 3.248,2.464 2.296,0 3.248,-2.408 0.952,-2.464 0.952,-7.392002 0,-4.816 -0.952,-7.224 -0.952,-2.408 -3.248,-2.408 -2.24,0 -3.248,2.408 -1.008,2.352 -1.008,7.336 z m 48.94405,-15.904 q 7.784,0 7.784,11.032 V 110.56 h -7.28 V 92.527998 q 0,-6.664 -3.024,-6.664 -2.184,0 -3.024,2.296 -0.84,2.24 -0.84,6.888 V 110.56 h -7.336 V 92.471998 q 0,-3.416 -0.728,-4.984 -0.672,-1.624 -2.184,-1.624 -2.352,0 -3.192,2.576 -0.784,2.52 -0.784,7.504 V 110.56 h -7.28 V 79.927998 h 5.768 l 0.784,3.92 h 0.448 q 1.792,-4.48 7.112,-4.48 2.632,0 4.2,1.232 1.568,1.232 2.24,3.136 h 0.504 q 1.064,-2.128 2.688,-3.248 1.68,-1.12 4.144,-1.12 z m 17.63998,-11.48 q 3.976,0 3.976,4.2 0,4.088 -3.976,4.088 -3.976,0 -3.976,-4.088 0,-4.2 3.976,-4.2 z m 3.64,12.04 V 110.56 h -7.28 V 79.927998 Z"
android:fillColor="#FFFFFF"/>
</vector>
</item>
</layer-list>
9 changes: 9 additions & 0 deletions app/src/main/res/mipmap/ic_ani_banner.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
<background>
<color android:color="#2E84BF"/>
</background>
<foreground>
<inset android:inset="15%" android:drawable="@drawable/ic_banner_foreground"/>
</foreground>
</adaptive-icon>
Loading