Skip to content
Open
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
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.metacto.catalogapp.di

// MARK: Add imports
import com.metacto.catalogapp.presentation.videoPlayer.videoplayersample.VideoPlayerSampleViewModel
import com.metacto.catalogapp.presentation.audioPlayer.audioplayersample.AudioPlayerSampleViewModel
import com.metacto.catalogapp.presentation.app.app.AppViewModel
import com.metacto.catalogapp.presentation.files.FilesSamplesViewModel
import com.metacto.catalogapp.presentation.imagePicker.ImagePickerSamplesViewModel
Expand All @@ -14,6 +16,8 @@ import org.koin.dsl.module

val viewModelsModule = module {
// MARK: Add view model definitions
commonViewModel { VideoPlayerSampleViewModel() }
commonViewModel { AudioPlayerSampleViewModel() }
commonViewModel { ImagePreloaderViewModel() }
commonViewModel { MediaManagerViewModel() }
commonViewModel { PhoneNumberViewModel() }
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.metacto.catalogapp.presentation.audioPlayer.audioplayersample

import com.metacto.core.ui.base.ViewEvent
import com.metacto.core.ui.base.ViewSideEffect
import com.metacto.core.ui.base.ViewState

class AudioPlayerSampleContract {

data class State(
val isInitialized: Boolean = false
) : ViewState

sealed class Event : ViewEvent {
data object Init : Event()
}

sealed class Effect : ViewSideEffect
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package com.metacto.catalogapp.presentation.audioPlayer.audioplayersample

import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import com.metacto.catalogapp.presentation.audioPlayer.audioplayersample.AudioPlayerSampleContract.Event
import com.metacto.catalogapp.presentation.audioPlayer.audioplayersample.components.AudioPlayerSampleContent
import com.metacto.core.ui.base.BaseScreen
import com.metacto.core.ui.base.SIDE_EFFECTS_KEY
import com.metacto.core.ui.base.rememberViewModel

internal class AudioPlayerSampleScreen : BaseScreen<AudioPlayerSampleViewModel>() {
@Composable
override fun Content() {
// Get the view model
val viewModel = rememberViewModel<AudioPlayerSampleViewModel>()

// Init view model
LaunchedEffect(SIDE_EFFECTS_KEY) {
viewModel.setEvent(Event.Init)
}

// Render content
AudioPlayerSampleContent(
state = viewModel.viewState.value,
onEvent = viewModel::setEvent
)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package com.metacto.catalogapp.presentation.audioPlayer.audioplayersample

import com.metacto.catalogapp.presentation.base.BaseViewModel
import com.metacto.catalogapp.presentation.audioPlayer.audioplayersample.AudioPlayerSampleContract.Effect
import com.metacto.catalogapp.presentation.audioPlayer.audioplayersample.AudioPlayerSampleContract.Event
import com.metacto.catalogapp.presentation.audioPlayer.audioplayersample.AudioPlayerSampleContract.State

class AudioPlayerSampleViewModel : BaseViewModel<State, Event, Effect>() {

override fun setInitialState() = State()

override fun handleEvents(event: Event): Any = when (event) {
Event.Init -> init()
}

private fun init() {
// Validate if already initialized
if (currentState.isInitialized) return

// Init

// Update the flag
setState { copy(isInitialized = true) }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
package com.metacto.catalogapp.presentation.audioPlayer.audioplayersample.components

import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier
import com.metacto.catalogapp.presentation.audioPlayer.audioplayersample.AudioPlayerSampleContract.Event
import com.metacto.catalogapp.presentation.audioPlayer.audioplayersample.AudioPlayerSampleContract.State
import com.metacto.catalogapp.presentation.components.containers.AppScreenColumn
import com.metacto.catalogapp.presentation.theme.spacings
import com.metacto.core.ui.components.inputFields.PrimaryTextInputField
import com.metacto.core.ui.mediaplayers.audioPlayer.AudioPlayer
import com.metacto.core.ui.mediaplayers.audioPlayer.AudioPlayerStatusListener
import com.metacto.core.ui.navigation.NavManager
import org.koin.compose.koinInject

@Composable
internal fun AudioPlayerSampleContent(
state: State,
onEvent: (Event) -> Unit
) {
// audio test link
// https://www.learningcontainer.com/wp-content/uploads/2020/02/Kalimba.mp3

// Di
val navManager = koinInject<NavManager>()

// states
var audioUrl by remember { mutableStateOf("") }

// Container column
AppScreenColumn(
title = "AudioPlayerSample",
isScrollable = true,
showToolbar = true,
showBack = true,
onBackClick = {
navManager.goBack()
},
) {
// Audio url input field
PrimaryTextInputField(
text = audioUrl,
label = "Audio Url",
onValueChange = {
audioUrl = it
},
modifier = Modifier
.fillMaxWidth()
.padding(top = spacings.spacing16)
)

// Audio player
AudioPlayer(
audioUrl = audioUrl,
title = "audio title",
thumbnailUrl = "",
audioPlayerStatusListener = object : AudioPlayerStatusListener {
override fun onAudioPlayed() {
}

override fun onAudioPaused() {

}
},
modifier = Modifier
.fillMaxWidth()
.padding(top = spacings.spacing16)
)

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ package com.metacto.catalogapp.presentation.main.components
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import com.metacto.catalogapp.presentation.audioPlayer.audioplayersample.AudioPlayerSampleScreen
import com.metacto.catalogapp.presentation.files.FilesSamplesScreen
import com.metacto.catalogapp.presentation.imagePicker.ImagePickerSamplesScreen
import com.metacto.catalogapp.presentation.imagePreloader.imagepreloader.ImagePreloaderScreen
Expand All @@ -16,6 +16,7 @@ import com.metacto.catalogapp.presentation.mediaManager.MediaManagerScreen
import com.metacto.catalogapp.presentation.notifications.NotificationsSamplesScreen
import com.metacto.catalogapp.presentation.phoneNumber.PhoneNumberScreen
import com.metacto.catalogapp.presentation.theme.spacings
import com.metacto.catalogapp.presentation.videoPlayer.videoplayersample.VideoPlayerSampleScreen
import com.metacto.core.ui.components.buttons.PrimaryFilledButton
import com.metacto.core.ui.components.containers.ScreenColumn
import com.metacto.core.ui.navigation.NavManager
Expand Down Expand Up @@ -83,5 +84,23 @@ internal fun MainContent(
},
modifier = Modifier.fillMaxWidth()
)

// Audio Player samples
PrimaryFilledButton(
text = "Audio Player samples",
onClick = {
navManage.navigate(AudioPlayerSampleScreen())
},
modifier = Modifier.fillMaxWidth()
)

// Video Player samples
PrimaryFilledButton(
text = "Video Player samples",
onClick = {
navManage.navigate(VideoPlayerSampleScreen())
},
modifier = Modifier.fillMaxWidth()
)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.metacto.catalogapp.presentation.videoPlayer.videoplayersample

import com.metacto.core.ui.base.ViewEvent
import com.metacto.core.ui.base.ViewSideEffect
import com.metacto.core.ui.base.ViewState

class VideoPlayerSampleContract {

data class State(
val isInitialized: Boolean = false
) : ViewState

sealed class Event : ViewEvent {
data object Init : Event()
}

sealed class Effect : ViewSideEffect
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package com.metacto.catalogapp.presentation.videoPlayer.videoplayersample

import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import com.metacto.catalogapp.presentation.videoPlayer.videoplayersample.VideoPlayerSampleContract.Event
import com.metacto.catalogapp.presentation.videoPlayer.videoplayersample.components.VideoPlayerSampleContent
import com.metacto.core.ui.base.BaseScreen
import com.metacto.core.ui.base.SIDE_EFFECTS_KEY
import com.metacto.core.ui.base.rememberViewModel

internal class VideoPlayerSampleScreen : BaseScreen<VideoPlayerSampleViewModel>() {
@Composable
override fun Content() {
// Get the view model
val viewModel = rememberViewModel<VideoPlayerSampleViewModel>()

// Init view model
LaunchedEffect(SIDE_EFFECTS_KEY) {
viewModel.setEvent(Event.Init)
}

// Render content
VideoPlayerSampleContent(
state = viewModel.viewState.value,
onEvent = viewModel::setEvent
)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package com.metacto.catalogapp.presentation.videoPlayer.videoplayersample

import com.metacto.catalogapp.presentation.base.BaseViewModel
import com.metacto.catalogapp.presentation.videoPlayer.videoplayersample.VideoPlayerSampleContract.Effect
import com.metacto.catalogapp.presentation.videoPlayer.videoplayersample.VideoPlayerSampleContract.Event
import com.metacto.catalogapp.presentation.videoPlayer.videoplayersample.VideoPlayerSampleContract.State

class VideoPlayerSampleViewModel : BaseViewModel<State, Event, Effect>() {

override fun setInitialState() = State()

override fun handleEvents(event: Event): Any = when (event) {
Event.Init -> init()
}

private fun init() {
// Validate if already initialized
if (currentState.isInitialized) return

// Init

// Update the flag
setState { copy(isInitialized = true) }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
package com.metacto.catalogapp.presentation.videoPlayer.videoplayersample.components

import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier
import com.metacto.catalogapp.presentation.components.containers.AppScreenColumn
import com.metacto.catalogapp.presentation.theme.spacings
import com.metacto.catalogapp.presentation.videoPlayer.videoplayersample.VideoPlayerSampleContract.Event
import com.metacto.catalogapp.presentation.videoPlayer.videoplayersample.VideoPlayerSampleContract.State
import com.metacto.core.ui.components.inputFields.PrimaryTextInputField
import com.metacto.core.ui.mediaplayers.videoPlayer.VideoPlayer
import com.metacto.core.ui.navigation.NavManager
import org.koin.compose.koinInject

@Composable
internal fun VideoPlayerSampleContent(
state: State,
onEvent: (Event) -> Unit
) {
// test video url
// http://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4

// Di
val navManager = koinInject<NavManager>()

// states
var videoUrl by remember { mutableStateOf("") }

// Container column
AppScreenColumn(
title = "VideoPlayerSample",
isScrollable = true,
showToolbar = true,
showBack = true,
onBackClick = {
navManager.goBack()
},
) {
// Video url input field
PrimaryTextInputField(
text = videoUrl,
label = "Video Url",
onValueChange = {
videoUrl = it
},
modifier = Modifier
.fillMaxWidth()
.padding(top = spacings.spacing16)
)

// Video Player
if (videoUrl.isNotEmpty()) {
VideoPlayer(
videoUrl = videoUrl,
modifier = Modifier
.fillMaxWidth()
.height(spacings.spacing500)
.padding(top = spacings.spacing32)
)
}
}
}