Compare commits

...

3 commits

Author SHA1 Message Date
dfb6cb969e
Updated .drone.yml
Some checks reported errors
continuous-integration/drone/push Build was killed
2021-11-23 10:44:12 +01:00
f35295824c
Added ProgressBar for playback duration 2021-11-23 10:43:23 +01:00
dcac6e7801
Switched to LiveData as stated in the specification 2021-11-23 09:02:45 +01:00
6 changed files with 193 additions and 113 deletions

View file

@ -29,6 +29,9 @@ steps:
rm: true
target: /home/fdroid-builder/unsigned
source: "*.apk"
when:
branch:
- main
- name: update fdroid repo
image: appleboy/drone-ssh
settings:
@ -43,3 +46,6 @@ steps:
- fdroid publish
- fdroid update
- fdroid deploy
when:
branch:
- main

View file

@ -8,7 +8,24 @@
<entry key="../../../../../layout/compose-model-1633594045878.xml" value="1.0" />
<entry key="../../../../../layout/compose-model-1633596772266.xml" value="0.18285472972972974" />
<entry key="../../../../../layout/compose-model-1633601146222.xml" value="0.18285472972972974" />
<entry key="../../../../../layout/compose-model-1634022040984.xml" value="0.3037037037037037" />
<entry key="../../../../../layout/compose-model-1633617799626.xml" value="0.3095439189189189" />
<entry key="../../../../../layout/compose-model-1633617944748.xml" value="0.4962962962962963" />
<entry key="../../../../../layout/compose-model-1633767363997.xml" value="0.17905405405405406" />
<entry key="../../../../../layout/compose-model-1634889935306.xml" value="0.3095439189189189" />
<entry key="../../../../../layout/compose-model-1634890564069.xml" value="0.4861111111111111" />
<entry key="../../../../../layout/compose-model-1634891321942.xml" value="0.33" />
<entry key="../../../../../layout/compose-model-1634891753898.xml" value="1.0" />
<entry key="../../../../../layout/compose-model-1634893431951.xml" value="0.3095439189189189" />
<entry key="../../../../../layout/compose-model-1634898066813.xml" value="0.3095439189189189" />
<entry key="../../../../../layout/compose-model-1634898107086.xml" value="0.4759259259259259" />
<entry key="../../../../../layout/compose-model-1634990577157.xml" value="0.4703703703703704" />
<entry key="../../../../../layout/compose-model-1637651431048.xml" value="0.3611111111111111" />
<entry key="../../../../../layout/compose-model-1637651867699.xml" value="0.3095439189189189" />
<entry key="../../../../../layout/compose-model-1637652867578.xml" value="0.36018518518518516" />
<entry key="../../../../../layout/compose-model-1637653004789.xml" value="0.45740740740740743" />
<entry key="../../../../../layout/compose-model-1637654654111.xml" value="0.33" />
<entry key="../../../../../layout/compose-model-1637655458616.xml" value="0.45740740740740743" />
<entry key="../../../../../layout/compose-model-1637656156044.xml" value="0.25" />
</map>
</option>
</component>
@ -19,7 +36,7 @@
<option name="HEAP_SIZE" value="256" />
<option name="LOCALE" value="en" />
</component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_11" project-jdk-name="JDK" project-jdk-type="JavaSDK">
<component name="ProjectRootManager" version="2" languageLevel="JDK_11" default="true" project-jdk-name="11" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/build/classes" />
</component>
<component name="ProjectType">

View file

@ -14,6 +14,8 @@ import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import androidx.lifecycle.ViewModelProvider
import androidx.lifecycle.lifecycleScope
import eu.toldi.balazs.caster.ui.theme.CasterTheme
import kotlinx.coroutines.Dispatchers.IO
import kotlinx.coroutines.GlobalScope
@ -26,6 +28,9 @@ import com.yausername.youtubedl_android.YoutubeDL
import com.yausername.youtubedl_android.YoutubeDLRequest
import com.yausername.youtubedl_android.YoutubeDLException
import com.yausername.youtubedl_android.mapper.VideoInfo
import eu.toldi.balazs.caster.model.ChromecastManageViewmodel
import kotlinx.coroutines.withContext
import su.litvak.chromecast.api.v2.Media
import su.litvak.chromecast.api.v2.MediaStatus
@ -33,13 +38,13 @@ class ChromecastManagerActivity : ComponentActivity() {
companion object {
var chromeCast_: ChromeCast? = null
fun castLink(chromeCast: ChromeCast,link : String, callBack : () -> Unit = {}) : Boolean{
suspend fun castLink(chromeCast: ChromeCast,link : String, callBack : () -> Unit = {}) : Boolean{
var exitStatus = true
if(link.startsWith("https://").not() && link.startsWith("http://").not()) {
callBack.invoke()
return false
}
GlobalScope.launch(IO) {
withContext(IO){
val request =
YoutubeDLRequest(link)
request.addOption("-f", "best")
@ -94,9 +99,12 @@ class ChromecastManagerActivity : ComponentActivity() {
}
setContent {
CasterTheme {
val viewModel = ViewModelProvider(this).get(ChromecastManageViewmodel::class.java)
viewModel.chromeCast = chromeCast
// A surface container using the 'background' color from the theme
Surface(color = MaterialTheme.colors.background) {
Column {
viewModel.fetchMediaStatus()
MenuBar()
Column(
modifier = Modifier
@ -120,8 +128,10 @@ class ChromecastManagerActivity : ComponentActivity() {
enabled = castEnabled,
onClick = {
castEnabled = false
castLink(chromeCast,text) {
castEnabled = true
lifecycleScope.launch {
castLink(chromeCast, text) {
castEnabled = true
}
}
},
@ -132,7 +142,21 @@ class ChromecastManagerActivity : ComponentActivity() {
if(castEnabled.not()){
CircularProgressIndicator()
}
playBackControl()
playBackControl(viewmodel = viewModel)
val mediaStatus = viewModel.mediaStatus.value
if(mediaStatus != null) {
val nowPlaying = mediaStatus.media.metadata[Media.METADATA_TITLE]
Text(text = "Now playing: $nowPlaying")
val progress = mediaStatus.currentTime/ mediaStatus.media.duration
Row(Modifier.fillMaxWidth(),horizontalArrangement = Arrangement.SpaceBetween) {
Text(text = String.format("%02d:%02d",((mediaStatus.currentTime % 3600) / 60).toInt(), (mediaStatus.currentTime % 60).toInt()))
Text(text = String.format("%02d:%02d",((mediaStatus.media.duration % 3600) / 60).toInt(),(mediaStatus.media.duration % 60).toInt()))
}
Slider(value = progress.toFloat(), onValueChange = {
viewModel.seek(it.toDouble())
})
}
}
}
}
@ -164,63 +188,67 @@ class ChromecastManagerActivity : ComponentActivity() {
}
@Composable
fun playBackControl(){
fun playBackControl(viewmodel: ChromecastManageViewmodel){
val mediaStatus = viewmodel.mediaStatus.value
Row {
IconButton(onClick = {
GlobalScope.launch(IO) {
if(chromeCast.mediaStatus != null) {
chromeCast.seek(chromeCast.mediaStatus.currentTime - 10)
if(mediaStatus != null) {
lifecycleScope.launch(IO) {
chromeCast.seek(chromeCast.mediaStatus.currentTime - 10)
viewmodel.fetchMediaStatus()
}
}
}
}) {
},enabled = mediaStatus != null) {
Icon(
Icons.Filled.FastRewind,
contentDescription = "FastRewind"
)
}
/*
var playBackState by remember { mutableStateOf(MediaStatus.PlayerState.IDLE) }
GlobalScope.launch(IO) {
lifecycleScope.launch(IO) {
if(chromeCast.mediaStatus != null)
playBackState = chromeCast.mediaStatus.playerState
}
}*/
IconButton(onClick = {
GlobalScope.launch(IO) {
if(chromeCast.mediaStatus != null)
playBackState = chromeCast.mediaStatus.playerState
if(playBackState == MediaStatus.PlayerState.PLAYING) {
chromeCast.pause()
lifecycleScope.launch(IO) {
if(mediaStatus != null) {
if (mediaStatus.playerState == MediaStatus.PlayerState.PLAYING) {
chromeCast.pause()
}
if (mediaStatus.playerState == MediaStatus.PlayerState.PAUSED) {
chromeCast.play()
}
viewmodel.fetchMediaStatus()
}
if(playBackState == MediaStatus.PlayerState.PAUSED) {
chromeCast.play()
}
if(chromeCast.mediaStatus != null)
playBackState = chromeCast.mediaStatus.playerState
}
}) {
when(playBackState) {
MediaStatus.PlayerState.PLAYING -> Icon(
Icons.Filled.Pause,
contentDescription = "Pause"
)
MediaStatus.PlayerState.PAUSED -> Icon(
},enabled = mediaStatus != null) {
when {
mediaStatus == null || mediaStatus.playerState == MediaStatus.PlayerState.PAUSED -> Icon(
Icons.Filled.PlayArrow,
contentDescription = "Resume"
)
mediaStatus.playerState == MediaStatus.PlayerState.PLAYING -> Icon(
Icons.Filled.Pause,
contentDescription = "Pause"
)
else -> Icon(
Icons.Filled.PlayArrow,
contentDescription = "Resume"
)
}
}
IconButton(onClick = {
GlobalScope.launch(IO) {
if(chromeCast.runningApp != null)
lifecycleScope.launch(IO) {
if(chromeCast.runningApp != null) {
chromeCast.stopApp()
viewmodel.fetchMediaStatus()
}
}
}) {
},enabled = mediaStatus != null) {
Icon(
Icons.Filled.Stop,
contentDescription = "Stop"
@ -228,12 +256,13 @@ class ChromecastManagerActivity : ComponentActivity() {
}
IconButton(onClick = {
GlobalScope.launch(IO) {
lifecycleScope.launch(IO) {
if(chromeCast.mediaStatus != null) {
chromeCast.seek(chromeCast.mediaStatus.currentTime + 10)
viewmodel.fetchMediaStatus()
}
}
}) {
},enabled = mediaStatus != null) {
Icon(
Icons.Filled.FastForward,
contentDescription = "FastForward"
@ -292,7 +321,11 @@ class ChromecastManagerActivity : ComponentActivity() {
) {
Text(text = "Cast")
}
playBackControl()
// val viewModel = ViewModelProvider(this).get(ChromecastManageViewmodel::class.java)
//playBackControl(viewModel)
Text(text = "Now playing: Some video")
var sliderPosition by remember { mutableStateOf(0f) }
Slider(value = sliderPosition, onValueChange = { sliderPosition = it })
}
}
}

View file

@ -7,23 +7,19 @@ import android.util.Log
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.activity.viewModels
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.*
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.material.*
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Menu
import androidx.compose.material.icons.filled.Refresh
import androidx.compose.material.icons.filled.Settings
import androidx.compose.material.icons.filled.Share
import androidx.compose.material.icons.filled.*
import androidx.compose.runtime.*
import androidx.compose.runtime.livedata.observeAsState
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import androidx.lifecycle.ViewModelProvider
import androidx.lifecycle.lifecycleScope
import eu.toldi.balazs.caster.model.ChromeCastViewModel
import eu.toldi.balazs.caster.ui.theme.CasterTheme
import kotlinx.coroutines.*
@ -44,27 +40,33 @@ class MainActivity : ComponentActivity() {
setContent {
CasterTheme {
val viewModel = ViewModelProvider(this).get(ChromeCastViewModel::class.java)
GlobalScope.launch(IO) {
ChromeCasts.startDiscovery(getIPv4Address())
}
viewModel.startScanning()
val chromeCasts = viewModel.chromeCasts.value
val chromeCastState = viewModel.chromeCasts.observeAsState(initial = emptyList())
val chromeCasts = chromeCastState.value
Log.e(null,chromeCasts.toString())
// A surface container using the 'background' color from the theme
Surface(color = MaterialTheme.colors.background) {
Column {
MenuBar() {
viewModel.chromeCasts.value = emptyList()
GlobalScope.launch(IO) {
ChromeCasts.restartDiscovery(getIPv4Address())
}
MenuBar {
viewModel.refresh()
}
LazyColumn(modifier = Modifier
.padding(all = 4.dp)
.fillMaxWidth(),
horizontalAlignment = Alignment.CenterHorizontally) {
item {
if (chromeCasts.size > 0)
if (chromeCasts.isNotEmpty())
Text(text = "Available chromecasts:")
else {
Column(
modifier = Modifier.fillMaxSize() ,
horizontalAlignment = Alignment.CenterHorizontally
){
Text("Looking for Chromecasts on your network...")
CircularProgressIndicator()
}
}
}
items(chromeCasts.size) { index ->
showChromeCastButton(chromeCast = chromeCasts[index])
@ -90,17 +92,6 @@ class MainActivity : ComponentActivity() {
}
}
fun getIPv4Address(): InetAddress? {
NetworkInterface.getNetworkInterfaces().toList().forEach { interf ->
interf.inetAddresses.toList().forEach { inetAddress ->
if (!inetAddress.isLoopbackAddress && inetAddress.hostAddress.indexOf(':') < 0) {
return inetAddress
}
}
}
return null
}
@Composable
fun MenuBar(refresh: () -> Unit) {
TopAppBar(
@ -115,6 +106,15 @@ class MainActivity : ComponentActivity() {
contentDescription = "Refresh"
)
}
IconButton(onClick = {
}) {
Icon(
Icons.Filled.Add,
contentDescription = "Add"
)
}
}
}
)

View file

@ -13,16 +13,16 @@ import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.material.*
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Menu
import androidx.compose.material.icons.filled.Settings
import androidx.compose.material.icons.filled.Share
import androidx.compose.material.icons.filled.*
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.stringResource
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import androidx.lifecycle.ViewModelProvider
import androidx.lifecycle.lifecycleScope
import com.yausername.youtubedl_android.YoutubeDL
import com.yausername.youtubedl_android.YoutubeDLException
import eu.toldi.balazs.caster.model.ChromeCastViewModel
@ -53,15 +53,15 @@ class ShareRecieverActivity : ComponentActivity() {
setContent {
CasterTheme {
val viewModel = ViewModelProvider(this).get(ChromeCastViewModel::class.java)
GlobalScope.launch(IO) {
ChromeCasts.startDiscovery(getIPv4Address())
}
val chromeCasts = viewModel.chromeCasts.value
viewModel.startScanning()
val chromeCastState = viewModel.chromeCasts.observeAsState(emptyList())
val chromeCasts = chromeCastState.value
// A surface container using the 'background' color from the theme
Surface(color = MaterialTheme.colors.background) {
Column {
MenuBar()
MenuBar{
viewModel.refresh()
}
var enabled by remember {
mutableStateOf(true)
}
@ -72,7 +72,7 @@ class ShareRecieverActivity : ComponentActivity() {
horizontalAlignment = Alignment.CenterHorizontally
) {
item {
if (chromeCasts.size > 0)
if (chromeCasts.isNotEmpty())
Text(text = "Available chromecasts:")
}
items(chromeCasts.size) { index ->
@ -106,8 +106,10 @@ class ShareRecieverActivity : ComponentActivity() {
Button(
onClick = {
onEnableChanged(false)
ChromecastManagerActivity.castLink(chromeCast, link) {
finish()
lifecycleScope.launch {
ChromecastManagerActivity.castLink(chromeCast, link) {
finish()
}
}
},
modifier = Modifier.padding(5.dp),
@ -117,37 +119,27 @@ class ShareRecieverActivity : ComponentActivity() {
}
}
fun getIPv4Address(): InetAddress? {
NetworkInterface.getNetworkInterfaces().toList().forEach { interf ->
interf.inetAddresses.toList().forEach { inetAddress ->
if (!inetAddress.isLoopbackAddress && inetAddress.hostAddress.indexOf(':') < 0) {
return inetAddress
}
}
}
return null
}
@Composable
fun MenuBar() {
fun MenuBar(refresh: () -> Unit) {
TopAppBar(
title = {
Text(stringResource(id = R.string.title_activity_share_reciever))
},
navigationIcon = {
IconButton(onClick = { }) {
Icon(
Icons.Filled.Menu,
contentDescription = "Menu Hamburger"
)
}
},
actions = {
Row {
IconButton(onClick = {}) {
IconButton(onClick = refresh) {
Icon(
Icons.Filled.Share,
contentDescription = "Search Article"
Icons.Filled.Refresh,
contentDescription = "Refresh"
)
}
IconButton(onClick = {
}) {
Icon(
Icons.Filled.Add,
contentDescription = "Add"
)
}
}
@ -160,7 +152,7 @@ class ShareRecieverActivity : ComponentActivity() {
@Composable
fun DefaultPreview() {
CasterTheme {
MenuBar()
MenuBar {}
}
}
}

View file

@ -1,5 +1,6 @@
package eu.toldi.balazs.caster.model
import android.util.Log
import androidx.compose.runtime.MutableState
import androidx.compose.runtime.getValue
import androidx.compose.runtime.setValue
@ -8,28 +9,59 @@ import androidx.compose.runtime.remember
import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel
import su.litvak.chromecast.api.v2.ChromeCast
import su.litvak.chromecast.api.v2.ChromeCasts
import su.litvak.chromecast.api.v2.ChromeCastsListener
import androidx.lifecycle.viewModelScope
import kotlinx.coroutines.Dispatchers.IO
import kotlinx.coroutines.launch
import su.litvak.chromecast.api.v2.*
import java.net.InetAddress
import java.net.NetworkInterface
import javax.jmdns.ServiceEvent
import javax.jmdns.ServiceListener
class ChromeCastViewModel : ViewModel(),ChromeCastsListener {
val chromeCasts : MutableState<List<ChromeCast>> = mutableStateOf(ChromeCasts.get())
private val _chromecasts : MutableLiveData<List<ChromeCast>> = MutableLiveData<List<ChromeCast>>(listOf())
val chromeCasts : LiveData<List<ChromeCast>>
get() = _chromecasts
init {
ChromeCasts.registerListener(this)
}
override fun newChromeCastDiscovered(chromeCast: ChromeCast?) {
if(chromeCast != null)
chromeCasts.value += chromeCast
if(chromeCast != null) {
Log.i(null,"Found ${chromeCast.title}")
_chromecasts.postValue(_chromecasts.value!!.plus(chromeCast))
}
}
override fun chromeCastRemoved(chromeCast: ChromeCast?) {
if(chromeCast != null)
chromeCasts.value -= chromeCast
if(chromeCast != null) {
Log.i(null,"Lost ${chromeCast.title}")
_chromecasts.postValue(_chromecasts.value!!.minus(chromeCast))
}
}
fun refresh() {
_chromecasts.value = emptyList()
viewModelScope.launch(IO) {
ChromeCasts.restartDiscovery(getIPv4Address())
}
}
fun startScanning() {
viewModelScope.launch(IO) {
ChromeCasts.startDiscovery(getIPv4Address())
}
}
fun getIPv4Address(): InetAddress? {
NetworkInterface.getNetworkInterfaces().toList().forEach { interf ->
interf.inetAddresses.toList().forEach { inetAddress ->
if (!inetAddress.isLoopbackAddress && inetAddress.hostAddress.indexOf(':') < 0) {
return inetAddress
}
}
}
return null
}
}