Skip to content

Commit

Permalink
Merge pull request #17 from MozillaFoundation/damo
Browse files Browse the repository at this point in the history
damo updates
  • Loading branch information
RazvanMocanuTW committed Feb 12, 2024
2 parents 794d6e9 + 8cda613 commit edca694
Show file tree
Hide file tree
Showing 24 changed files with 770 additions and 712 deletions.
2 changes: 2 additions & 0 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -126,4 +126,6 @@ dependencies {
androidTestImplementation(libs.compose.ui.test.junit4)
debugImplementation(libs.compose.ui.tooling)
debugImplementation(libs.compose.ui.test.manifest)

implementation(libs.compose.markdown)
}
2 changes: 0 additions & 2 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"
android:maxSdkVersion="29" />

<uses-permission android:name="android.permission.RECORD_AUDIO" />

<application
android:name=".TikTokReporterApp"
android:allowBackup="true"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,8 @@ class ScreenRecorderManager @Inject constructor(
mediaRecorder?.apply {

setVideoSource(MediaRecorder.VideoSource.SURFACE)
setAudioSource(MediaRecorder.AudioSource.DEFAULT)
setOutputFormat(MediaRecorder.OutputFormat.MPEG_4)
setVideoEncoder(MediaRecorder.VideoEncoder.H264)
setAudioEncoder(MediaRecorder.AudioEncoder.DEFAULT)
setVideoSize(recordingInfo.width, recordingInfo.height)
setVideoFrameRate(recordingInfo.frameRate)
setVideoEncodingBitRate(8 * 1000 * 1000)
Expand All @@ -72,13 +70,17 @@ class ScreenRecorderManager @Inject constructor(

videoUri = context.contentResolver.insert(videosCollection, contentValues) ?: return

context.contentResolver.openFileDescriptor(videoUri!!, "w").use {
it?.let {
mediaRecorder?.apply {
setOutputFile(it.fileDescriptor)
prepare()
try {
context.contentResolver.openFileDescriptor(videoUri!!, "w").use {
it?.let {
mediaRecorder?.apply {
setOutputFile(it.fileDescriptor)
prepare()
}
}
}
} catch (e: Exception) {
throw e
}

mediaProjection!!.registerCallback(mediaProjectionCallback, Handler(Looper.getMainLooper()))
Expand All @@ -103,7 +105,11 @@ class ScreenRecorderManager @Inject constructor(
) {
val recordingInfo = getRecordingInfo()
if (mediaProjection == null || mediaRecorder == null)
setupMediaProjectionAndRecorder(code, data, recordingInfo)
try {
setupMediaProjectionAndRecorder(code, data, recordingInfo)
} catch (e: Exception) {
throw e
}

setupVirtualDisplay(recordingInfo)
mediaRecorder?.start()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@ import android.content.Intent
import android.content.pm.PackageManager
import android.content.pm.ServiceInfo
import android.os.Build
import android.os.Handler
import android.os.IBinder
import android.os.Looper
import android.widget.Toast
import androidx.activity.result.ActivityResult
import androidx.core.app.ActivityCompat
import androidx.core.app.NotificationCompat
Expand Down Expand Up @@ -67,13 +70,29 @@ class ScreenRecorderService : Service() {


scope.launch {
screenRecorderManager.startRecording(
code = activityResult.resultCode,
data = activityResult.data ?: Intent()
)
this@ScreenRecorderService.dataStore.edit {
it[Common.DATASTORE_KEY_IS_RECORDING] = true
try {
screenRecorderManager.startRecording(
code = activityResult.resultCode,
data = activityResult.data ?: Intent()
)
this@ScreenRecorderService.dataStore.edit {
it[Common.DATASTORE_KEY_IS_RECORDING] = true
}
} catch (e: Exception) {
Handler(Looper.getMainLooper()).post {
Toast.makeText(
applicationContext,
"Device incompatible for screen recording. Please send the TikTok link!",
Toast.LENGTH_LONG
).show()
}
this@ScreenRecorderService.dataStore.edit {
it[Common.DATASTORE_KEY_REDIRECT_FIRST_TAB] = true
it[Common.DATASTORE_KEY_IS_RECORDING] = false
}
this@ScreenRecorderService.stopSelf()
}

}
}
}
Expand Down Expand Up @@ -115,6 +134,7 @@ class ScreenRecorderService : Service() {
},
PendingIntent.FLAG_IMMUTABLE
)

private fun getStopRecordingIntent() = PendingIntent.getService(
applicationContext,
2,
Expand All @@ -123,6 +143,7 @@ class ScreenRecorderService : Service() {
},
PendingIntent.FLAG_IMMUTABLE
)

private fun createNotification() = NotificationCompat.Builder(this, "screen_recording_channel")
.setSmallIcon(R.drawable.ic_launcher_foreground)
.setContentTitle("Screen recording...")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ class TikTokReporterApp: Application() {
)
)

Glean.setDebugViewTag("tiktokreport-and")
Glean.setLogPings(true)
Glean.registerPings(Pings)
Glean.initialize(
applicationContext = applicationContext,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.ArrowBack
import androidx.compose.material3.Icon
import androidx.compose.material3.IconButton
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.derivedStateOf
import androidx.compose.runtime.getValue
Expand All @@ -22,6 +21,7 @@ import androidx.compose.ui.Modifier
import androidx.compose.ui.res.stringResource
import androidx.hilt.navigation.compose.hiltViewModel
import androidx.lifecycle.compose.collectAsStateWithLifecycle
import dev.jeziellago.compose.markdowntext.MarkdownText
import org.mozilla.tiktokreporter.R
import org.mozilla.tiktokreporter.TikTokReporterError
import org.mozilla.tiktokreporter.ui.components.LoadingScreen
Expand Down Expand Up @@ -88,7 +88,19 @@ fun AppPolicyScreen(

when (action.error) {
// internet connection / server unresponsive / server error
is TikTokReporterError.NetworkError, is TikTokReporterError.ServerError -> {
is TikTokReporterError.NetworkError -> {
dialogState.value = DialogState.ErrorDialog(
title = UiText.StringResource(R.string.error_title_internet),
drawable = R.drawable.error_cat,
actionText = UiText.StringResource(R.string.button_refresh),
action = {
viewModel.refresh()
dialogState.value = DialogState.Nothing
}
)
}

is TikTokReporterError.ServerError -> {
dialogState.value = DialogState.ErrorDialog(
title = UiText.StringResource(R.string.error_title_general),
message = UiText.StringResource(R.string.error_message_general),
Expand All @@ -110,6 +122,7 @@ fun AppPolicyScreen(
}
}
}

AppPolicyScreenViewModel.UiAction.ShowNoPolicyFound -> Unit
}
}
Expand Down Expand Up @@ -170,22 +183,22 @@ private fun AppPolicyScreenContent(
state = scrollState
) {
item {
Text(
text = state.title,
MarkdownText(
markdown = state.title,
style = MozillaTypography.H3
)
Spacer(modifier = Modifier.height(MozillaDimension.L))
}
item {
Text(
text = state.subtitle,
MarkdownText(
markdown = state.subtitle,
style = MozillaTypography.H5
)
Spacer(modifier = Modifier.height(MozillaDimension.M))
}
item {
Text(
text = state.content,
MarkdownText(
markdown = state.content,
style = MozillaTypography.Body2
)
Spacer(modifier = Modifier.height(MozillaDimension.L))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ sealed class FormFieldUiComponent<T>(
open val readOnly: Boolean,
open val description: String,
open val label: String,
open val error: FormFieldError? = null
open val error: FormFieldError? = null,
open val edited: Boolean? = false
) {
data class TextField(
override val id: String,
Expand All @@ -24,9 +25,11 @@ sealed class FormFieldUiComponent<T>(
override val description: String,
override val label: String,
override val error: FormFieldError? = null,
override val edited: Boolean? = false,
val placeholder: String,
val multiline: Boolean,
val maxLines: Int,
val isTikTokLink: Boolean? = false
) : FormFieldUiComponent<String>(id, value, isVisible, isRequired, readOnly, description, label)

data class DropDown(
Expand All @@ -38,6 +41,7 @@ sealed class FormFieldUiComponent<T>(
override val description: String,
override val label: String,
override val error: FormFieldError? = null,
override val edited: Boolean? = false,
val options: List<OptionComponent>,
val placeholder: String,
) : FormFieldUiComponent<String>(id, value, isVisible, isRequired, readOnly, description, label)
Expand All @@ -51,6 +55,7 @@ sealed class FormFieldUiComponent<T>(
override val description: String,
override val label: String,
override val error: FormFieldError? = null,
override val edited: Boolean? = false,
val max: Int,
val step: Int,
val leftLabel: String,
Expand All @@ -59,13 +64,13 @@ sealed class FormFieldUiComponent<T>(
}

data class OptionComponent(
val id: String,
val title: String
val id: String, val title: String
)

sealed class FormFieldError {
data object Empty: FormFieldError()
data object EmptyCategory: FormFieldError()
data object Empty : FormFieldError()
data object EmptyCategory : FormFieldError()
data object NoTikTokLink : FormFieldError()
}

fun FormField.toFormFieldComponent(): List<FormFieldUiComponent<*>>? {
Expand All @@ -81,13 +86,13 @@ fun FormField.toFormFieldComponent(): List<FormFieldUiComponent<*>>? {
label = label,
placeholder = placeholder,
multiline = multiline,
maxLines = maxLines
maxLines = maxLines,
isTikTokLink = isTikTokLink
)
)

is FormField.DropDown -> {
val initialValue =
this.options.firstOrNull { it.id == this.selectedOptionId }?.title.orEmpty()
val initialValue = this.options.firstOrNull { it.id == this.selectedOptionId }?.title.orEmpty()

val dropDown = FormFieldUiComponent.DropDown(
id = id,
Expand All @@ -98,15 +103,12 @@ fun FormField.toFormFieldComponent(): List<FormFieldUiComponent<*>>? {
description = description,
label = label,
options = buildList {
addAll(
options.map {
OptionComponent(it.id, it.title)
}
addAll(options.map {
OptionComponent(it.id, it.title)
})
if (this@toFormFieldComponent.hasOtherOption) add(
OptionComponent(OTHER_DROP_DOWN_OPTION_ID, "Other")
)
if (this@toFormFieldComponent.hasOtherOption)
add(
OptionComponent(OTHER_DROP_DOWN_OPTION_ID, "Other")
)
},
placeholder = placeholder,
)
Expand Down Expand Up @@ -166,8 +168,7 @@ fun List<FormField>.toUiComponents(
textField as FormFieldUiComponent.TextField

textField.copy(
readOnly = true,
value = tikTokUrl
readOnly = true, value = tikTokUrl
)
}
} else {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,44 +1,32 @@
package org.mozilla.tiktokreporter.common.formcomponents

import androidx.compose.foundation.lazy.LazyListScope
import androidx.compose.foundation.lazy.items
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import org.mozilla.tiktokreporter.common.FormFieldUiComponent

fun LazyListScope.formComponentsItems(
formFields: List<FormFieldUiComponent<*>>,
onFormFieldValueChanged: (formFieldId: String, value: Any) -> Unit
@Composable
fun formComponentsItems(
formFields: List<FormFieldUiComponent<*>>, onFormFieldValueChanged: (formFieldId: String, value: Any) -> Unit
) {
items(formFields.filter { it.isVisible }) { field ->
formFields.filter { it.isVisible }.forEach { field ->
when (field) {
is FormFieldUiComponent.TextField -> {
FormTextField(
modifier = Modifier.fillParentMaxWidth(),
field = field,
onTextChanged = {
onFormFieldValueChanged(field.id, it)
}
)
FormTextField(modifier = Modifier.fillMaxWidth(), field = field, onTextChanged = {
onFormFieldValueChanged(field.id, it)
})
}

is FormFieldUiComponent.DropDown -> {
FormDropDown(
modifier = Modifier.fillParentMaxWidth(),
field = field,
onOptionChanged = {
onFormFieldValueChanged(field.id, it)
}
)
FormDropDown(modifier = Modifier.fillMaxWidth(), field = field, onOptionChanged = {
onFormFieldValueChanged(field.id, it)
})
}

is FormFieldUiComponent.Slider -> {
FormSlider(
modifier = Modifier.fillParentMaxWidth(),
field = field,
onValueChanged = {
onFormFieldValueChanged(field.id, it)
}
)
FormSlider(modifier = Modifier.fillMaxWidth(), field = field, onValueChanged = {
onFormFieldValueChanged(field.id, it)
})
}
}
}
Expand Down
Loading

0 comments on commit edca694

Please sign in to comment.