summaryrefslogtreecommitdiffstats
path: root/mobile/android/fenix/app/src/main/java/org/mozilla/fenix/microsurvey/ui/MicroSurveyFooter.kt
blob: e9dd23c97f9e364298789442dad6b900c649010c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

package org.mozilla.fenix.microsurvey.ui

import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material.Button
import androidx.compose.material.ButtonDefaults
import androidx.compose.material.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.style.TextDecoration
import androidx.compose.ui.tooling.preview.PreviewScreenSizes
import androidx.compose.ui.unit.dp
import org.mozilla.fenix.R
import org.mozilla.fenix.compose.LinkText
import org.mozilla.fenix.compose.LinkTextState
import org.mozilla.fenix.compose.annotation.LightDarkPreview
import org.mozilla.fenix.theme.FirefoxTheme

/**
 * The footer UI used for micro-survey.
 *
 * @param isSubmitted Whether the user has "Submitted" the survey or not.
 * @param isContentAnswerSelected Whether the user clicked on one of the answers or not.
 * @param onLinkClick Invoked when the link is clicked.
 * @param onButtonClick Invoked when the "Submit"/"Close" button is clicked.
 */
@Composable
fun MicroSurveyFooter(
    isSubmitted: Boolean,
    isContentAnswerSelected: Boolean,
    onLinkClick: () -> Unit,
    onButtonClick: () -> Unit,
) {
    val buttonText = if (isSubmitted) {
        stringResource(id = R.string.micro_survey_close_button_label)
    } else {
        stringResource(id = R.string.micro_survey_submit_button_label)
    }
    val buttonColor = if (isContentAnswerSelected) {
        FirefoxTheme.colors.actionPrimary
    } else {
        FirefoxTheme.colors.actionPrimaryDisabled
    }

    Row(
        verticalAlignment = Alignment.Bottom,
        modifier = Modifier.fillMaxWidth(),
    ) {
        LinkText(
            text = stringResource(id = R.string.about_privacy_notice),
            linkTextStates = listOf(
                LinkTextState(
                    text = stringResource(id = R.string.micro_survey_privacy_notice),
                    url = "",
                    onClick = {
                        onLinkClick()
                    },
                ),
            ),
            style = FirefoxTheme.typography.caption,
            linkTextDecoration = TextDecoration.Underline,
        )

        Spacer(modifier = Modifier.weight(1f))

        Button(
            onClick = { onButtonClick() },
            enabled = isContentAnswerSelected,
            shape = RoundedCornerShape(size = 4.dp),
            colors = ButtonDefaults.buttonColors(
                backgroundColor = buttonColor,
            ),
            contentPadding = PaddingValues(16.dp, 12.dp),
        ) {
            Text(
                text = buttonText,
                color = FirefoxTheme.colors.textActionPrimary,
                style = FirefoxTheme.typography.button,
            )
        }
    }
}

@PreviewScreenSizes
@LightDarkPreview
@Composable
private fun ReviewQualityCheckFooterPreview() {
    FirefoxTheme {
        MicroSurveyFooter(
            isSubmitted = false,
            isContentAnswerSelected = false,
            onLinkClick = {},
            onButtonClick = {},
        )
    }
}