-
Notifications
You must be signed in to change notification settings - Fork 231
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added additional Android TV UI similar to 2.x UI.
Apks are streamed directly to SessionInstaller instead of being saved to disk first.
- Loading branch information
Showing
21 changed files
with
355 additions
and
75 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package com.apkupdater.ui.component | ||
|
||
import android.content.res.Configuration | ||
import androidx.compose.foundation.layout.Arrangement | ||
import androidx.compose.foundation.layout.PaddingValues | ||
import androidx.compose.foundation.lazy.grid.GridCells | ||
import androidx.compose.foundation.lazy.grid.LazyGridScope | ||
import androidx.compose.foundation.lazy.grid.LazyVerticalGrid | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.ui.platform.LocalConfiguration | ||
import androidx.compose.ui.unit.dp | ||
import androidx.tv.foundation.lazy.grid.TvGridCells | ||
import androidx.tv.foundation.lazy.grid.TvLazyGridScope | ||
import androidx.tv.foundation.lazy.grid.TvLazyVerticalGrid | ||
import com.apkupdater.prefs.Prefs | ||
import org.koin.androidx.compose.get | ||
|
||
@Composable | ||
fun InstalledGrid(content: LazyGridScope.() -> Unit) = LazyVerticalGrid( | ||
columns = GridCells.Fixed(getNumColumns(LocalConfiguration.current.orientation)), | ||
contentPadding = PaddingValues(horizontal = 8.dp, vertical = 8.dp), | ||
verticalArrangement = Arrangement.spacedBy(8.dp), | ||
horizontalArrangement = Arrangement.spacedBy(8.dp), | ||
content = content | ||
) | ||
|
||
@Composable | ||
fun TvInstalledGrid(content: TvLazyGridScope.() -> Unit) = TvLazyVerticalGrid( | ||
columns = TvGridCells.Fixed(getTvNumColumns()), | ||
contentPadding = PaddingValues(horizontal = 8.dp, vertical = 8.dp), | ||
verticalArrangement = Arrangement.spacedBy(8.dp), | ||
horizontalArrangement = Arrangement.spacedBy(8.dp), | ||
content = content | ||
) | ||
|
||
@Composable | ||
fun getNumColumns(orientation: Int): Int { | ||
val prefs = get<Prefs>() | ||
return if(orientation == Configuration.ORIENTATION_PORTRAIT) | ||
prefs.portraitColumns.get() | ||
else | ||
prefs.landscapeColumns.get() | ||
} | ||
|
||
@Composable | ||
fun getTvNumColumns(): Int { | ||
return if(LocalConfiguration.current.orientation == Configuration.ORIENTATION_PORTRAIT) | ||
1 | ||
else | ||
2 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
129 changes: 129 additions & 0 deletions
129
app/src/main/java/com/apkupdater/ui/component/TvComponents.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,129 @@ | ||
package com.apkupdater.ui.component | ||
|
||
import android.net.Uri | ||
import androidx.compose.foundation.layout.Arrangement | ||
import androidx.compose.foundation.layout.Box | ||
import androidx.compose.foundation.layout.BoxScope | ||
import androidx.compose.foundation.layout.Column | ||
import androidx.compose.foundation.layout.Row | ||
import androidx.compose.foundation.layout.fillMaxSize | ||
import androidx.compose.foundation.layout.height | ||
import androidx.compose.foundation.layout.padding | ||
import androidx.compose.foundation.layout.size | ||
import androidx.compose.foundation.layout.width | ||
import androidx.compose.material3.Card | ||
import androidx.compose.material3.CircularProgressIndicator | ||
import androidx.compose.material3.ElevatedButton | ||
import androidx.compose.material3.Text | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.ui.Alignment | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.draw.alpha | ||
import androidx.compose.ui.res.stringResource | ||
import androidx.compose.ui.unit.dp | ||
import com.apkupdater.R | ||
import com.apkupdater.data.ui.AppInstalled | ||
import com.apkupdater.data.ui.AppUpdate | ||
|
||
@Composable | ||
fun TvCommonItem( | ||
packageName: String, | ||
name: String, | ||
version: String, | ||
versionCode: Long, | ||
uri: Uri? = null | ||
) = Row { | ||
if (uri == null) { | ||
LoadingImageApp( | ||
packageName, | ||
Modifier | ||
.height(90.dp) | ||
.align(Alignment.CenterVertically) | ||
) | ||
} else { | ||
LoadingImage( | ||
uri, | ||
Modifier | ||
.height(90.dp) | ||
.align(Alignment.CenterVertically) | ||
) | ||
} | ||
Column( | ||
Modifier | ||
.align(Alignment.CenterVertically) | ||
.padding(horizontal = 8.dp) | ||
) { | ||
LargeTitle(name) | ||
MediumText(version) | ||
MediumText(versionCode.toString()) | ||
} | ||
} | ||
|
||
@Composable | ||
fun TvInstallButton( | ||
app: AppUpdate, | ||
onInstall: (String) -> Unit | ||
) = ElevatedButton( | ||
modifier = Modifier | ||
.padding(top = 0.dp, bottom = 8.dp, start = 8.dp, end = 8.dp) | ||
.width(120.dp), | ||
onClick = { onInstall(app.packageName) } | ||
) { | ||
if (app.isInstalling) { | ||
CircularProgressIndicator(Modifier.size(24.dp)) | ||
} else { | ||
Text(stringResource(R.string.install_cd)) | ||
} | ||
} | ||
|
||
@Composable | ||
fun BoxScope.TvSourceIcon(app: AppUpdate) = SourceIcon( | ||
app.source, | ||
Modifier | ||
.align(Alignment.CenterStart) | ||
.padding(top = 0.dp, bottom = 8.dp, start = 8.dp, end = 8.dp) | ||
.size(32.dp) | ||
) | ||
|
||
@Composable | ||
fun TvInstalledItem(app: AppInstalled, onIgnore: (String) -> Unit = {}) = Card( | ||
modifier = Modifier.alpha(if (app.ignored) 0.5f else 1f) | ||
) { | ||
Column { | ||
TvCommonItem(app.packageName, app.name, app.version, app.versionCode) | ||
Row(modifier = Modifier.fillMaxSize(), horizontalArrangement = Arrangement.End) { | ||
ElevatedButton( | ||
modifier = Modifier.padding(top = 0.dp, bottom = 8.dp, start = 8.dp, end = 8.dp), | ||
onClick = { onIgnore(app.packageName) } | ||
) { | ||
Text(stringResource(R.string.ignore_cd)) | ||
} | ||
} | ||
} | ||
} | ||
|
||
@Composable | ||
fun TvUpdateItem(app: AppUpdate, onInstall: (String) -> Unit = {}) = Card { | ||
Column { | ||
TvCommonItem(app.packageName, app.name, app.version, app.versionCode) | ||
Box { | ||
TvSourceIcon(app) | ||
Row(modifier = Modifier.fillMaxSize(), horizontalArrangement = Arrangement.End) { | ||
TvInstallButton(app, onInstall) | ||
} | ||
} | ||
} | ||
} | ||
|
||
@Composable | ||
fun TvSearchItem(app: AppUpdate, onInstall: (String) -> Unit = {}) = Card { | ||
Column { | ||
TvCommonItem(app.packageName, app.name, app.version, app.versionCode, app.iconUri) | ||
Box { | ||
TvSourceIcon(app) | ||
Row(modifier = Modifier.fillMaxSize(), horizontalArrangement = Arrangement.End) { | ||
TvInstallButton(app, onInstall) | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.