Skip to content

Commit a7cc125

Browse files
committed
refactor Android mobile
1 parent 88e915c commit a7cc125

File tree

7 files changed

+73
-79
lines changed

7 files changed

+73
-79
lines changed

.run/android-mobile.run.xml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<component name="ProjectRunConfigurationManager">
2-
<configuration default="false" name="android-mobile" type="AndroidRunConfigurationType" factoryName="Android App">
2+
<configuration default="false" name="android-mobile" type="AndroidRunConfigurationType" factoryName="Android App" activateToolWindowBeforeRun="false">
33
<module name="Hyperion.android.mobile.main" />
44
<option name="DEPLOY" value="true" />
55
<option name="DEPLOY_APK_FROM_BUNDLE" value="false" />
@@ -12,6 +12,8 @@
1212
<option name="DYNAMIC_FEATURES_DISABLED_LIST" value="" />
1313
<option name="ACTIVITY_EXTRA_FLAGS" value="" />
1414
<option name="MODE" value="default_activity" />
15+
<option name="RESTORE_ENABLED" value="false" />
16+
<option name="RESTORE_FILE" value="" />
1517
<option name="CLEAR_LOGCAT" value="false" />
1618
<option name="SHOW_LOGCAT_AUTOMATICALLY" value="false" />
1719
<option name="TARGET_SELECTION_MODE" value="DEVICE_AND_SNAPSHOT_COMBO_BOX" />
@@ -53,7 +55,7 @@
5355
<option name="ADVANCED_PROFILING_ENABLED" value="false" />
5456
<option name="STARTUP_PROFILING_ENABLED" value="false" />
5557
<option name="STARTUP_CPU_PROFILING_ENABLED" value="false" />
56-
<option name="STARTUP_CPU_PROFILING_CONFIGURATION_NAME" value="Java/Kotlin Method Sample (legacy)" />
58+
<option name="STARTUP_CPU_PROFILING_CONFIGURATION_NAME" value="Callstack Sample" />
5759
<option name="STARTUP_NATIVE_MEMORY_PROFILING_ENABLED" value="false" />
5860
<option name="NATIVE_MEMORY_SAMPLE_RATE_BYTES" value="2048" />
5961
</Profilers>

android/build.gradle.kts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import org.jetbrains.kotlin.gradle.dsl.kotlinExtension
88
plugins {
99
id("hyperion.android-application") apply false
1010
}
11+
1112
subprojects {
1213
val libs = rootProject.libs
1314

@@ -32,11 +33,8 @@ subprojects {
3233

3334
configure<ApplicationExtension> {
3435
namespace = "dev.zt64.hyperion"
35-
compileSdk = 35
3636

3737
defaultConfig {
38-
minSdk = 21
39-
targetSdk = 35
4038
versionCode = 1
4139
versionName = version.toString()
4240
}

android/mobile/src/main/kotlin/dev/zt64/hyperion/ui/PlayerActivity.kt

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,23 @@
11
package dev.zt64.hyperion.ui
22

3+
import android.app.PictureInPictureParams
4+
import android.content.Context
5+
import android.content.ContextWrapper
6+
import android.os.Build
37
import android.os.Bundle
48
import androidx.activity.ComponentActivity
9+
import androidx.activity.compose.setContent
10+
import androidx.compose.foundation.background
11+
import androidx.compose.foundation.layout.Box
12+
import androidx.compose.foundation.layout.fillMaxSize
13+
import androidx.compose.ui.Alignment
14+
import androidx.compose.ui.Modifier
15+
import androidx.compose.ui.graphics.Color
16+
import androidx.compose.ui.graphics.toAndroidRectF
17+
import androidx.compose.ui.layout.boundsInWindow
18+
import androidx.compose.ui.layout.onGloballyPositioned
19+
import androidx.compose.ui.platform.LocalContext
20+
import androidx.core.graphics.toRect
521

622
/**
723
* Potential alternative to mini-player UI component
@@ -12,5 +28,48 @@ import androidx.activity.ComponentActivity
1228
class PlayerActivity : ComponentActivity() {
1329
override fun onCreate(savedInstanceState: Bundle?) {
1430
super.onCreate(savedInstanceState)
31+
32+
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) {
33+
finish()
34+
return
35+
}
36+
37+
enterPictureInPictureMode(PictureInPictureParams.Builder().build())
38+
39+
setContent {
40+
val context = LocalContext.current
41+
42+
Box(
43+
modifier = Modifier
44+
.fillMaxSize()
45+
.onGloballyPositioned {
46+
val builder = PictureInPictureParams.Builder()
47+
val sourceRect = it
48+
.boundsInWindow()
49+
.toAndroidRectF()
50+
.toRect()
51+
builder.setSourceRectHint(sourceRect)
52+
53+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
54+
builder.setAutoEnterEnabled(true)
55+
}
56+
context
57+
.findActivity()
58+
.setPictureInPictureParams(builder.build())
59+
}
60+
.background(Color.Black),
61+
contentAlignment = Alignment.Center
62+
) {
63+
}
64+
}
65+
}
66+
}
67+
68+
internal fun Context.findActivity(): ComponentActivity {
69+
var context = this
70+
while (context is ContextWrapper) {
71+
if (context is ComponentActivity) return context
72+
context = context.baseContext
1573
}
74+
throw IllegalStateException("Picture in picture should be called in the context of an Activity")
1675
}

android/mobile/src/main/kotlin/dev/zt64/hyperion/ui/screen/settings/GesturesScreen.kt

Lines changed: 0 additions & 54 deletions
This file was deleted.

android/mobile/src/main/kotlin/dev/zt64/hyperion/ui/sheet/CommentsSheet.kt

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,11 @@ import androidx.compose.ui.text.style.TextOverflow
2929
import androidx.compose.ui.tooling.preview.Preview
3030
import androidx.compose.ui.unit.dp
3131
import dev.icerock.moko.resources.compose.stringResource
32+
import dev.zt64.hyperion.api.domain.model.DomainChannelPartial
33+
import dev.zt64.hyperion.api.domain.model.DomainComment
3234
import dev.zt64.hyperion.resources.MR
3335
import dev.zt64.hyperion.ui.component.ShimmerImage
3436
import dev.zt64.hyperion.ui.tooling.HyperionPreview
35-
import dev.zt64.innertube.domain.model.DomainChannelPartial
36-
import dev.zt64.innertube.domain.model.DomainComment
3737

3838
@Composable
3939
fun CommentsSheet(onDismissRequest: () -> Unit) {
@@ -49,7 +49,8 @@ private fun SheetContent() {
4949
Comment(
5050
comment = DomainComment(
5151
id = "1",
52-
content = "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.",
52+
content = "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do " +
53+
"eiusmod tempor incididunt ut labore et dolore magna aliqua.",
5354
datePosted = "1 day ago",
5455
author = DomainChannelPartial(
5556
id = "1",
@@ -68,12 +69,7 @@ private fun SheetContent() {
6869
}
6970

7071
@Composable
71-
private fun Comment(
72-
comment: DomainComment,
73-
onClickLike: () -> Unit,
74-
onClickDislike: () -> Unit,
75-
onClickReply: () -> Unit
76-
) {
72+
private fun Comment(comment: DomainComment, onClickLike: () -> Unit, onClickDislike: () -> Unit, onClickReply: () -> Unit) {
7773
var expanded by rememberSaveable { mutableStateOf(false) }
7874

7975
Surface(
@@ -154,7 +150,8 @@ private fun CommentCardPreview() {
154150
Comment(
155151
comment = DomainComment(
156152
id = "1",
157-
content = "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.",
153+
content = "Lorem ipsum dolor sit amet, consectetur adipiscing elit, " +
154+
"sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.",
158155
datePosted = "1 day ago",
159156
author = DomainChannelPartial(
160157
id = "1",

android/mobile/src/main/kotlin/dev/zt64/hyperion/ui/sheet/DownloadSheet.kt

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -63,11 +63,7 @@ fun DownloadSheet(onDismissRequest: () -> Unit) {
6363

6464
@OptIn(ExperimentalLayoutApi::class)
6565
@Composable
66-
private fun SheetContent(
67-
uiState: UiState,
68-
onDismissRequest: () -> Unit,
69-
onClickDownload: () -> Unit
70-
) {
66+
private fun SheetContent(uiState: UiState, onDismissRequest: () -> Unit, onClickDownload: () -> Unit) {
7167
Column(
7268
modifier = Modifier
7369
.navigationBarsPadding() // workaround bug

android/mobile/src/main/kotlin/dev/zt64/hyperion/ui/sheet/PlayerSheet.kt

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -227,11 +227,7 @@ private fun MappingTrackSelector.MappedTrackInfo.isSupportedFormat(rendererIndex
227227
}
228228

229229
@UnstableApi
230-
private fun TrackGroup.generateThing(
231-
renderTrack: MappingTrackSelector.MappedTrackInfo,
232-
rendererIndex: Int,
233-
groupIndex: Int
234-
) = buildList {
230+
private fun TrackGroup.generateThing(renderTrack: MappingTrackSelector.MappedTrackInfo, rendererIndex: Int, groupIndex: Int) = buildList {
235231
repeat(length) { trackIndex ->
236232
if (
237233
renderTrack.getTrackSupport(

0 commit comments

Comments
 (0)