Redesigned Main Activity

Signed-off-by: Balazs Toldi <balazs@toldi.eu>
This commit is contained in:
Balazs Toldi 2022-01-02 22:17:46 +01:00
parent f681b7afc9
commit 55ca983cf7
Signed by: Bazsalanszky
GPG key ID: 933820884952BE27
3 changed files with 95 additions and 31 deletions

View file

@ -35,10 +35,13 @@
<entry key="../../../../../layout/compose-model-1638742825833.xml" value="0.1" />
<entry key="../../../../../layout/compose-model-1639485191192.xml" value="0.1" />
<entry key="../../../../../layout/compose-model-1641150442256.xml" value="0.4564814814814815" />
<entry key="../../../../../layout/compose-model-1641153447766.xml" value="0.4537037037037037" />
<entry key="../../../../../layout/compose-model-1641153447766.xml" value="0.33" />
<entry key="../../../../../layout/compose-model-1641153474417.xml" value="0.4537037037037037" />
<entry key="../../../../../layout/compose-model-1641154461708.xml" value="0.30743243243243246" />
<entry key="../../../../../layout/compose-model-1641155483959.xml" value="0.25" />
<entry key="../../../../../layout/compose-model-1641156419059.xml" value="0.5" />
<entry key="../../../../../layout/compose-model-1641157410658.xml" value="1.0" />
<entry key="../../../../../layout/compose-model-1641157605359.xml" value="0.5" />
</map>
</option>
</component>

View file

@ -78,6 +78,7 @@ dependencies {
implementation 'com.fasterxml.jackson.core:jackson-databind:2.10.0'
implementation 'su.litvak.chromecast:api-v2:0.11.3'
implementation("io.coil-kt:coil-compose:1.4.0")
implementation "com.google.accompanist:accompanist-swiperefresh:0.22.0-rc"
implementation 'com.github.yausername.youtubedl-android:library:0.13.+'
implementation 'com.github.yausername.youtubedl-android:ffmpeg:0.13.+'
implementation "androidx.media:media:1.4.3"

View file

@ -8,6 +8,8 @@ import android.os.Bundle
import android.util.Log
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.compose.foundation.Image
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.*
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.material.*
@ -18,10 +20,13 @@ import androidx.compose.runtime.*
import androidx.compose.runtime.livedata.observeAsState
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import androidx.lifecycle.ViewModelProvider
import com.google.accompanist.swiperefresh.SwipeRefresh
import com.google.accompanist.swiperefresh.rememberSwipeRefreshState
import eu.toldi.balazs.caster.model.ChromeCastViewModel
import eu.toldi.balazs.caster.ui.theme.CasterTheme
import su.litvak.chromecast.api.v2.ChromeCast
@ -67,7 +72,9 @@ class MainActivity : ComponentActivity() {
Log.e(null, chromeCasts.toString())
// A surface container using the 'background' color from the theme
Surface(color = MaterialTheme.colors.background) {
Column {
Column(modifier = Modifier
.fillMaxWidth()
.fillMaxHeight()) {
var isAddChromecastDialogOpen by remember {
mutableStateOf(false)
}
@ -90,27 +97,44 @@ class MainActivity : ComponentActivity() {
})
}
}
LazyColumn(
var isRefreshing by remember {
mutableStateOf(false)
}
SwipeRefresh(
state = rememberSwipeRefreshState(isRefreshing),
onRefresh = {
isRefreshing = true
viewModel.refresh()
isRefreshing = false
},
modifier = Modifier
.padding(all = 4.dp)
.fillMaxWidth(),
horizontalAlignment = Alignment.CenterHorizontally
.fillMaxWidth()
.fillMaxHeight()
) {
item {
if (chromeCasts.isNotEmpty())
Text(text = stringResource(id = R.string.available_chromecasts))
else {
Column(
modifier = Modifier.fillMaxSize(),
horizontalAlignment = Alignment.CenterHorizontally
) {
Text(stringResource(id = R.string.looking_for_devices))
CircularProgressIndicator()
LazyColumn(
modifier = Modifier
.padding(all = 4.dp)
.fillMaxWidth()
.fillMaxHeight(),
horizontalAlignment = Alignment.CenterHorizontally
) {
item {
if (chromeCasts.isNotEmpty())
Text(text = stringResource(id = R.string.available_chromecasts))
else {
Column(
modifier = Modifier.fillMaxSize(),
horizontalAlignment = Alignment.CenterHorizontally
) {
Text(stringResource(id = R.string.looking_for_devices))
CircularProgressIndicator()
}
}
}
}
items(chromeCasts.size) { index ->
showChromeCastButton(chromeCast = chromeCasts[index])
items(chromeCasts.size) { index ->
showChromeCastButton(chromeCast = chromeCasts[index])
}
}
}
}
@ -161,20 +185,56 @@ class MainActivity : ComponentActivity() {
@Composable
fun showChromeCastButton(chromeCast: ChromeCast) {
Button(
onClick = {
ChromecastManagerActivity.chromeCast_ = chromeCast
val intent = Intent(this, ChromecastManagerActivity::class.java)
startActivity(intent)
},
modifier = Modifier.padding(5.dp)
Column(
Modifier
.fillMaxWidth()
.padding(all = 5.dp)
) {
when {
chromeCast.title != null -> Text(text = chromeCast.title)
chromeCast.name != null -> Text(text = chromeCast.name)
else -> Text(text = chromeCast.address)
}
Card(modifier = Modifier
.fillMaxWidth()
.clickable {
ChromecastManagerActivity.chromeCast_ = chromeCast
val intent = Intent(applicationContext, ChromecastManagerActivity::class.java)
startActivity(intent)
}) {
Row() {
val image_id = when (chromeCast.model) {
"Chromecast Ultra" -> R.drawable.chromecastultra
else -> R.drawable.chromecastv1
}
Column(
modifier = Modifier
.height(80.dp)
.width(80.dp)
.padding(10.dp)
) {
Image(
painter = painterResource(id = image_id),
contentDescription = chromeCast.model,
Modifier
.fillMaxHeight()
.fillMaxWidth()
)
}
Column() {
Text(
text = "Name: " + when {
chromeCast.title != null -> chromeCast.title
chromeCast.name != null -> chromeCast.name
else -> chromeCast.address
}
)
Text(
text = "Model: " + when {
chromeCast.model != null -> chromeCast.model
else -> "Unknown"
}
)
}
}
}
}
}