From 4ef2c7aa5056b3c60013ff99cb0dd1c24c01b25d Mon Sep 17 00:00:00 2001 From: YigitSekerci Date: Tue, 12 Dec 2023 15:47:46 +0300 Subject: [PATCH 01/13] implement moderation screen list page ui --- .../bounswe/predictionpolls/MainActivity.kt | 3 +- .../ui/moderation/ModerationScreen.kt | 117 ++++++++++++++++++ .../ui/moderation/ModerationScreenEvent.kt | 3 + .../moderation/ModerationScreenNavigation.kt | 22 ++++ .../ui/moderation/ModerationScreenState.kt | 114 +++++++++++++++++ .../moderation/ModerationScreenViewModel.kt | 22 ++++ 6 files changed, 280 insertions(+), 1 deletion(-) create mode 100644 prediction-polls/android/app/src/main/java/com/bounswe/predictionpolls/ui/moderation/ModerationScreen.kt create mode 100644 prediction-polls/android/app/src/main/java/com/bounswe/predictionpolls/ui/moderation/ModerationScreenEvent.kt create mode 100644 prediction-polls/android/app/src/main/java/com/bounswe/predictionpolls/ui/moderation/ModerationScreenNavigation.kt create mode 100644 prediction-polls/android/app/src/main/java/com/bounswe/predictionpolls/ui/moderation/ModerationScreenState.kt create mode 100644 prediction-polls/android/app/src/main/java/com/bounswe/predictionpolls/ui/moderation/ModerationScreenViewModel.kt diff --git a/prediction-polls/android/app/src/main/java/com/bounswe/predictionpolls/MainActivity.kt b/prediction-polls/android/app/src/main/java/com/bounswe/predictionpolls/MainActivity.kt index f0e39fa8..090516ab 100644 --- a/prediction-polls/android/app/src/main/java/com/bounswe/predictionpolls/MainActivity.kt +++ b/prediction-polls/android/app/src/main/java/com/bounswe/predictionpolls/MainActivity.kt @@ -29,6 +29,7 @@ import com.bounswe.predictionpolls.ui.main.MAIN_ROUTE import com.bounswe.predictionpolls.ui.main.mainScreen import com.bounswe.predictionpolls.ui.main.navigateToMainScreen import com.bounswe.predictionpolls.ui.profile.myProfileScreen +import com.bounswe.predictionpolls.ui.moderation.moderationScreen import com.bounswe.predictionpolls.ui.profile.profileScreen import com.bounswe.predictionpolls.ui.signup.signupScreen import com.bounswe.predictionpolls.ui.theme.PredictionPollsTheme @@ -104,11 +105,11 @@ class MainActivity : ComponentActivity() { myProfileScreen(navController) editProfileScreen(navController) forgotPasswordScreen(navController) + moderationScreen(navController) // TODO: Remove placeholders composable("settings") { Text(text = "Settings Page WIP") } composable("notifications") { Text(text = "Notifications Page WIP") } - composable("moderation") { Text(text = "Moderation Page WIP") } } } diff --git a/prediction-polls/android/app/src/main/java/com/bounswe/predictionpolls/ui/moderation/ModerationScreen.kt b/prediction-polls/android/app/src/main/java/com/bounswe/predictionpolls/ui/moderation/ModerationScreen.kt new file mode 100644 index 00000000..20281228 --- /dev/null +++ b/prediction-polls/android/app/src/main/java/com/bounswe/predictionpolls/ui/moderation/ModerationScreen.kt @@ -0,0 +1,117 @@ +package com.bounswe.predictionpolls.ui.moderation + +import androidx.compose.foundation.background +import androidx.compose.foundation.border +import androidx.compose.foundation.layout.Arrangement +import androidx.compose.foundation.layout.Box +import androidx.compose.foundation.layout.Column +import androidx.compose.foundation.layout.Row +import androidx.compose.foundation.layout.Spacer +import androidx.compose.foundation.layout.fillMaxSize +import androidx.compose.foundation.layout.fillMaxWidth +import androidx.compose.foundation.layout.padding +import androidx.compose.foundation.lazy.LazyColumn +import androidx.compose.foundation.lazy.items +import androidx.compose.foundation.shape.RoundedCornerShape +import androidx.compose.material3.Button +import androidx.compose.material3.ButtonDefaults +import androidx.compose.material3.MaterialTheme +import androidx.compose.material3.Text +import androidx.compose.runtime.Composable +import androidx.compose.ui.Alignment +import androidx.compose.ui.Modifier +import androidx.compose.ui.graphics.Color +import androidx.compose.ui.text.style.TextAlign +import androidx.compose.ui.unit.dp +import androidx.hilt.navigation.compose.hiltViewModel +import androidx.navigation.NavController + +@Composable +fun ModerationScreen( + navController: NavController, + viewModel: ModerationScreenViewModel = hiltViewModel() +) { + ModerationScreenUI( + tags = viewModel.screenState.tags, + requestedPolls = viewModel.screenState.requestedPolls + ) +} + +@Composable +private fun ModerationScreenUI( + tags: List = listOf(), + requestedPolls: List = listOf() +) { + LazyColumn( + modifier = Modifier + .fillMaxSize() + .padding(horizontal = 12.dp), + verticalArrangement = Arrangement.spacedBy(16.dp) + ) { + items (requestedPolls) { requestedPoll -> + RequestedPoll(requestedPoll = requestedPoll) + } + } +} + +@Composable +private fun RequestedPoll( + requestedPoll: ModerationScreenState.RequestedPoll +) { + Column( + modifier = Modifier + .border(1.dp, Color.Black, RoundedCornerShape(8.dp)) + .padding(vertical = 16.dp, horizontal = 12.dp), + horizontalAlignment = Alignment.CenterHorizontally, + verticalArrangement = Arrangement.spacedBy(12.dp) + ) { + when (requestedPoll.type) { + ModerationScreenState.RequestedPollType.REPORT -> Text( + text = "Would you like to be on the jury to resolve a report about following poll?", + textAlign = TextAlign.Center + ) + ModerationScreenState.RequestedPollType.END -> Text( + text = "Would you like to be on the jury to end the following poll?", + textAlign = TextAlign.Center + ) + } + Row( + modifier = Modifier.fillMaxWidth(), + horizontalArrangement = Arrangement.spacedBy(6.dp) + ){ + requestedPoll.tags.forEach { tag -> + Box( + modifier = Modifier + .background(MaterialTheme.colorScheme.secondary, RoundedCornerShape(8.dp)) + .padding(vertical = 8.dp, horizontal = 12.dp) + ) { + Text(text = tag, color = Color.White) + } + } + Spacer(modifier = Modifier.weight(1f)) + } + Text(text = requestedPoll.question, textAlign = TextAlign.Center) + Row( + modifier = Modifier + .fillMaxWidth() + .padding(horizontal = 12.dp), + horizontalArrangement = Arrangement.SpaceBetween + ) { + Button( + onClick = { + } + ) { + Text(text = "Accept") + } + Button( + onClick = { + }, + colors = ButtonDefaults.buttonColors( + containerColor = MaterialTheme.colorScheme.error + ) + ) { + Text(text = "Decline") + } + } + } +} \ No newline at end of file diff --git a/prediction-polls/android/app/src/main/java/com/bounswe/predictionpolls/ui/moderation/ModerationScreenEvent.kt b/prediction-polls/android/app/src/main/java/com/bounswe/predictionpolls/ui/moderation/ModerationScreenEvent.kt new file mode 100644 index 00000000..8dc99db8 --- /dev/null +++ b/prediction-polls/android/app/src/main/java/com/bounswe/predictionpolls/ui/moderation/ModerationScreenEvent.kt @@ -0,0 +1,3 @@ +package com.bounswe.predictionpolls.ui.moderation + +sealed class ModerationScreenEvent {} diff --git a/prediction-polls/android/app/src/main/java/com/bounswe/predictionpolls/ui/moderation/ModerationScreenNavigation.kt b/prediction-polls/android/app/src/main/java/com/bounswe/predictionpolls/ui/moderation/ModerationScreenNavigation.kt new file mode 100644 index 00000000..784778c5 --- /dev/null +++ b/prediction-polls/android/app/src/main/java/com/bounswe/predictionpolls/ui/moderation/ModerationScreenNavigation.kt @@ -0,0 +1,22 @@ +package com.bounswe.predictionpolls.ui.moderation + +import androidx.navigation.NavController +import androidx.navigation.NavGraphBuilder +import androidx.navigation.NavOptions +import androidx.navigation.Navigator +import androidx.navigation.compose.composable + +const val MODERATION_ROUTE = "moderation" + +fun NavGraphBuilder.moderationScreen(navController: NavController) { + composable(MODERATION_ROUTE) { + ModerationScreen(navController) + } +} + +fun NavController.navigateToModerationScreen( + navOptions: NavOptions? = null, + block: Navigator.Extras? = null +) { + navigate(MODERATION_ROUTE, navOptions, block) +} \ No newline at end of file diff --git a/prediction-polls/android/app/src/main/java/com/bounswe/predictionpolls/ui/moderation/ModerationScreenState.kt b/prediction-polls/android/app/src/main/java/com/bounswe/predictionpolls/ui/moderation/ModerationScreenState.kt new file mode 100644 index 00000000..973321ce --- /dev/null +++ b/prediction-polls/android/app/src/main/java/com/bounswe/predictionpolls/ui/moderation/ModerationScreenState.kt @@ -0,0 +1,114 @@ +package com.bounswe.predictionpolls.ui.moderation + +data class ModerationScreenState( + val tags: List = emptyList(), + val requestedPolls: List = emptyList(), +) { + companion object { + val DUMMY = ModerationScreenState( + tags = listOf("tag1", "tag2", "tag3"), + requestedPolls = listOf( + RequestedPoll( + type = RequestedPollType.REPORT, + question = "Question 1", + tags = listOf("tag1", "tag2") + ), + RequestedPoll( + type = RequestedPollType.END, + question = "Question 2", + tags = listOf("tag1", "tag2") + ), + RequestedPoll( + type = RequestedPollType.REPORT, + question = "Question 3" + ), + RequestedPoll( + type = RequestedPollType.END, + question = "Question 4", + tags = listOf("tag1", "tag2") + ), + RequestedPoll( + type = RequestedPollType.REPORT, + question = "Question 5" + ), + RequestedPoll( + type = RequestedPollType.END, + question = "Question 6" + ), + RequestedPoll( + type = RequestedPollType.REPORT, + question = "Question 7" + ), + RequestedPoll( + type = RequestedPollType.END, + question = "Question 8" + ), + RequestedPoll( + type = RequestedPollType.REPORT, + question = "Question 9" + ), + RequestedPoll( + type = RequestedPollType.END, + question = "Question 10" + ), + RequestedPoll( + type = RequestedPollType.REPORT, + question = "Question 11" + ), + RequestedPoll( + type = RequestedPollType.END, + question = "Question 12" + ), + RequestedPoll( + type = RequestedPollType.REPORT, + question = "Question 13" + ), + RequestedPoll( + type = RequestedPollType.END, + question = "Question 14" + ), + RequestedPoll( + type = RequestedPollType.REPORT, + question = "Question 15" + ), + RequestedPoll( + type = RequestedPollType.END, + question = "Question 16" + ), + RequestedPoll( + type = RequestedPollType.REPORT, + question = "Question 17" + ), + RequestedPoll( + type = RequestedPollType.END, + question = "Question 18" + ), + RequestedPoll( + type = RequestedPollType.REPORT, + question = "Question 19" + ), + RequestedPoll( + type = RequestedPollType.END, + question = "Question 20" + ), + ) + ) + } + + data class RequestedPoll( + val type: RequestedPollType, + val question: String, + val tags: List = emptyList() + ) + + enum class RequestedPollType { + REPORT, + END + } + + fun reduce(event: ModerationScreenEvent): ModerationScreenState { + return when (event) { + else -> this + } + } +} diff --git a/prediction-polls/android/app/src/main/java/com/bounswe/predictionpolls/ui/moderation/ModerationScreenViewModel.kt b/prediction-polls/android/app/src/main/java/com/bounswe/predictionpolls/ui/moderation/ModerationScreenViewModel.kt new file mode 100644 index 00000000..1d0f14ce --- /dev/null +++ b/prediction-polls/android/app/src/main/java/com/bounswe/predictionpolls/ui/moderation/ModerationScreenViewModel.kt @@ -0,0 +1,22 @@ +package com.bounswe.predictionpolls.ui.moderation + +import androidx.compose.runtime.getValue +import androidx.compose.runtime.mutableStateOf +import androidx.compose.runtime.setValue +import com.bounswe.predictionpolls.core.BaseViewModel +import dagger.hilt.android.lifecycle.HiltViewModel +import javax.inject.Inject + +@HiltViewModel +class ModerationScreenViewModel @Inject constructor() : BaseViewModel() { + var screenState by mutableStateOf(ModerationScreenState.DUMMY) + private set + + fun onEvent(event: ModerationScreenEvent) { + screenState = screenState.reduce(event) + + when (event) { + else -> {} + } + } +} \ No newline at end of file From d76a381265b69d09fab137382d4ed8d35535dd2e Mon Sep 17 00:00:00 2001 From: YigitSekerci Date: Tue, 19 Dec 2023 15:57:59 +0300 Subject: [PATCH 02/13] move moderation list screen to new package --- .../src/main/java/com/bounswe/predictionpolls/MainActivity.kt | 1 + .../predictionpolls/ui/moderation/ModerationScreenEvent.kt | 3 --- .../ui/moderation/{ => list}/ModerationScreen.kt | 2 +- .../ui/moderation/list/ModerationScreenEvent.kt | 3 +++ .../ui/moderation/{ => list}/ModerationScreenNavigation.kt | 2 +- .../ui/moderation/{ => list}/ModerationScreenState.kt | 2 +- .../ui/moderation/{ => list}/ModerationScreenViewModel.kt | 2 +- 7 files changed, 8 insertions(+), 7 deletions(-) delete mode 100644 prediction-polls/android/app/src/main/java/com/bounswe/predictionpolls/ui/moderation/ModerationScreenEvent.kt rename prediction-polls/android/app/src/main/java/com/bounswe/predictionpolls/ui/moderation/{ => list}/ModerationScreen.kt (98%) create mode 100644 prediction-polls/android/app/src/main/java/com/bounswe/predictionpolls/ui/moderation/list/ModerationScreenEvent.kt rename prediction-polls/android/app/src/main/java/com/bounswe/predictionpolls/ui/moderation/{ => list}/ModerationScreenNavigation.kt (91%) rename prediction-polls/android/app/src/main/java/com/bounswe/predictionpolls/ui/moderation/{ => list}/ModerationScreenState.kt (98%) rename prediction-polls/android/app/src/main/java/com/bounswe/predictionpolls/ui/moderation/{ => list}/ModerationScreenViewModel.kt (91%) diff --git a/prediction-polls/android/app/src/main/java/com/bounswe/predictionpolls/MainActivity.kt b/prediction-polls/android/app/src/main/java/com/bounswe/predictionpolls/MainActivity.kt index 090516ab..fcc1299b 100644 --- a/prediction-polls/android/app/src/main/java/com/bounswe/predictionpolls/MainActivity.kt +++ b/prediction-polls/android/app/src/main/java/com/bounswe/predictionpolls/MainActivity.kt @@ -30,6 +30,7 @@ import com.bounswe.predictionpolls.ui.main.mainScreen import com.bounswe.predictionpolls.ui.main.navigateToMainScreen import com.bounswe.predictionpolls.ui.profile.myProfileScreen import com.bounswe.predictionpolls.ui.moderation.moderationScreen +import com.bounswe.predictionpolls.ui.moderation.list.moderationScreen import com.bounswe.predictionpolls.ui.profile.profileScreen import com.bounswe.predictionpolls.ui.signup.signupScreen import com.bounswe.predictionpolls.ui.theme.PredictionPollsTheme diff --git a/prediction-polls/android/app/src/main/java/com/bounswe/predictionpolls/ui/moderation/ModerationScreenEvent.kt b/prediction-polls/android/app/src/main/java/com/bounswe/predictionpolls/ui/moderation/ModerationScreenEvent.kt deleted file mode 100644 index 8dc99db8..00000000 --- a/prediction-polls/android/app/src/main/java/com/bounswe/predictionpolls/ui/moderation/ModerationScreenEvent.kt +++ /dev/null @@ -1,3 +0,0 @@ -package com.bounswe.predictionpolls.ui.moderation - -sealed class ModerationScreenEvent {} diff --git a/prediction-polls/android/app/src/main/java/com/bounswe/predictionpolls/ui/moderation/ModerationScreen.kt b/prediction-polls/android/app/src/main/java/com/bounswe/predictionpolls/ui/moderation/list/ModerationScreen.kt similarity index 98% rename from prediction-polls/android/app/src/main/java/com/bounswe/predictionpolls/ui/moderation/ModerationScreen.kt rename to prediction-polls/android/app/src/main/java/com/bounswe/predictionpolls/ui/moderation/list/ModerationScreen.kt index 20281228..0bda784d 100644 --- a/prediction-polls/android/app/src/main/java/com/bounswe/predictionpolls/ui/moderation/ModerationScreen.kt +++ b/prediction-polls/android/app/src/main/java/com/bounswe/predictionpolls/ui/moderation/list/ModerationScreen.kt @@ -1,4 +1,4 @@ -package com.bounswe.predictionpolls.ui.moderation +package com.bounswe.predictionpolls.ui.moderation.list import androidx.compose.foundation.background import androidx.compose.foundation.border diff --git a/prediction-polls/android/app/src/main/java/com/bounswe/predictionpolls/ui/moderation/list/ModerationScreenEvent.kt b/prediction-polls/android/app/src/main/java/com/bounswe/predictionpolls/ui/moderation/list/ModerationScreenEvent.kt new file mode 100644 index 00000000..4df42b54 --- /dev/null +++ b/prediction-polls/android/app/src/main/java/com/bounswe/predictionpolls/ui/moderation/list/ModerationScreenEvent.kt @@ -0,0 +1,3 @@ +package com.bounswe.predictionpolls.ui.moderation.list + +sealed class ModerationScreenEvent {} diff --git a/prediction-polls/android/app/src/main/java/com/bounswe/predictionpolls/ui/moderation/ModerationScreenNavigation.kt b/prediction-polls/android/app/src/main/java/com/bounswe/predictionpolls/ui/moderation/list/ModerationScreenNavigation.kt similarity index 91% rename from prediction-polls/android/app/src/main/java/com/bounswe/predictionpolls/ui/moderation/ModerationScreenNavigation.kt rename to prediction-polls/android/app/src/main/java/com/bounswe/predictionpolls/ui/moderation/list/ModerationScreenNavigation.kt index 784778c5..70e8c0d7 100644 --- a/prediction-polls/android/app/src/main/java/com/bounswe/predictionpolls/ui/moderation/ModerationScreenNavigation.kt +++ b/prediction-polls/android/app/src/main/java/com/bounswe/predictionpolls/ui/moderation/list/ModerationScreenNavigation.kt @@ -1,4 +1,4 @@ -package com.bounswe.predictionpolls.ui.moderation +package com.bounswe.predictionpolls.ui.moderation.list import androidx.navigation.NavController import androidx.navigation.NavGraphBuilder diff --git a/prediction-polls/android/app/src/main/java/com/bounswe/predictionpolls/ui/moderation/ModerationScreenState.kt b/prediction-polls/android/app/src/main/java/com/bounswe/predictionpolls/ui/moderation/list/ModerationScreenState.kt similarity index 98% rename from prediction-polls/android/app/src/main/java/com/bounswe/predictionpolls/ui/moderation/ModerationScreenState.kt rename to prediction-polls/android/app/src/main/java/com/bounswe/predictionpolls/ui/moderation/list/ModerationScreenState.kt index 973321ce..39148176 100644 --- a/prediction-polls/android/app/src/main/java/com/bounswe/predictionpolls/ui/moderation/ModerationScreenState.kt +++ b/prediction-polls/android/app/src/main/java/com/bounswe/predictionpolls/ui/moderation/list/ModerationScreenState.kt @@ -1,4 +1,4 @@ -package com.bounswe.predictionpolls.ui.moderation +package com.bounswe.predictionpolls.ui.moderation.list data class ModerationScreenState( val tags: List = emptyList(), diff --git a/prediction-polls/android/app/src/main/java/com/bounswe/predictionpolls/ui/moderation/ModerationScreenViewModel.kt b/prediction-polls/android/app/src/main/java/com/bounswe/predictionpolls/ui/moderation/list/ModerationScreenViewModel.kt similarity index 91% rename from prediction-polls/android/app/src/main/java/com/bounswe/predictionpolls/ui/moderation/ModerationScreenViewModel.kt rename to prediction-polls/android/app/src/main/java/com/bounswe/predictionpolls/ui/moderation/list/ModerationScreenViewModel.kt index 1d0f14ce..075744df 100644 --- a/prediction-polls/android/app/src/main/java/com/bounswe/predictionpolls/ui/moderation/ModerationScreenViewModel.kt +++ b/prediction-polls/android/app/src/main/java/com/bounswe/predictionpolls/ui/moderation/list/ModerationScreenViewModel.kt @@ -1,4 +1,4 @@ -package com.bounswe.predictionpolls.ui.moderation +package com.bounswe.predictionpolls.ui.moderation.list import androidx.compose.runtime.getValue import androidx.compose.runtime.mutableStateOf From da704c756814fb3200fe7132b1bc2d59b8fa0618 Mon Sep 17 00:00:00 2001 From: YigitSekerci Date: Tue, 19 Dec 2023 16:48:37 +0300 Subject: [PATCH 03/13] implement moderation apply screen --- .../bounswe/predictionpolls/MainActivity.kt | 2 + .../moderation/apply/ModerationApplyScreen.kt | 98 +++++++++++++++++++ .../apply/ModerationApplyScreenNavigation.kt | 22 +++++ .../ui/moderation/list/ModerationScreen.kt | 6 +- .../bounswe/predictionpolls/utils/NavItem.kt | 2 +- 5 files changed, 128 insertions(+), 2 deletions(-) create mode 100644 prediction-polls/android/app/src/main/java/com/bounswe/predictionpolls/ui/moderation/apply/ModerationApplyScreen.kt create mode 100644 prediction-polls/android/app/src/main/java/com/bounswe/predictionpolls/ui/moderation/apply/ModerationApplyScreenNavigation.kt diff --git a/prediction-polls/android/app/src/main/java/com/bounswe/predictionpolls/MainActivity.kt b/prediction-polls/android/app/src/main/java/com/bounswe/predictionpolls/MainActivity.kt index fcc1299b..0817797c 100644 --- a/prediction-polls/android/app/src/main/java/com/bounswe/predictionpolls/MainActivity.kt +++ b/prediction-polls/android/app/src/main/java/com/bounswe/predictionpolls/MainActivity.kt @@ -30,6 +30,7 @@ import com.bounswe.predictionpolls.ui.main.mainScreen import com.bounswe.predictionpolls.ui.main.navigateToMainScreen import com.bounswe.predictionpolls.ui.profile.myProfileScreen import com.bounswe.predictionpolls.ui.moderation.moderationScreen +import com.bounswe.predictionpolls.ui.moderation.apply.moderationApplyScreen import com.bounswe.predictionpolls.ui.moderation.list.moderationScreen import com.bounswe.predictionpolls.ui.profile.profileScreen import com.bounswe.predictionpolls.ui.signup.signupScreen @@ -106,6 +107,7 @@ class MainActivity : ComponentActivity() { myProfileScreen(navController) editProfileScreen(navController) forgotPasswordScreen(navController) + moderationApplyScreen(navController) moderationScreen(navController) // TODO: Remove placeholders diff --git a/prediction-polls/android/app/src/main/java/com/bounswe/predictionpolls/ui/moderation/apply/ModerationApplyScreen.kt b/prediction-polls/android/app/src/main/java/com/bounswe/predictionpolls/ui/moderation/apply/ModerationApplyScreen.kt new file mode 100644 index 00000000..05db7a05 --- /dev/null +++ b/prediction-polls/android/app/src/main/java/com/bounswe/predictionpolls/ui/moderation/apply/ModerationApplyScreen.kt @@ -0,0 +1,98 @@ +package com.bounswe.predictionpolls.ui.moderation.apply + +import androidx.compose.foundation.border +import androidx.compose.foundation.layout.Arrangement +import androidx.compose.foundation.layout.Box +import androidx.compose.foundation.layout.Column +import androidx.compose.foundation.layout.Row +import androidx.compose.foundation.layout.fillMaxSize +import androidx.compose.foundation.layout.fillMaxWidth +import androidx.compose.foundation.layout.padding +import androidx.compose.material3.Button +import androidx.compose.material3.ButtonDefaults +import androidx.compose.material3.MaterialTheme +import androidx.compose.material3.Text +import androidx.compose.runtime.Composable +import androidx.compose.ui.Modifier +import androidx.compose.ui.text.style.TextAlign +import androidx.compose.ui.tooling.preview.Preview +import androidx.compose.ui.unit.dp +import androidx.navigation.NavController +import com.bounswe.predictionpolls.ui.moderation.list.navigateToModerationScreen +import com.bounswe.predictionpolls.ui.theme.PredictionPollsTheme + +@Composable +fun ModerationApplyScreen( + navController: NavController +) { + ModerationApplyScreenUI( + navigateToModerationScreen = { + navController.navigateToModerationScreen() + }, + onBackClick = { + navController.popBackStack() + } + ) +} + +@Composable +private fun ModerationApplyScreenUI( + navigateToModerationScreen: () -> Unit = {}, + onBackClick: () -> Unit = {} +) { + Column( + modifier = Modifier + .fillMaxSize() + .padding(horizontal = 12.dp, vertical = 16.dp), + verticalArrangement = Arrangement.spacedBy(16.dp), + ) { + Box( + modifier = Modifier + .border( + width = 1.dp, + color = MaterialTheme.colorScheme.onSurface.copy(alpha = 0.25f), + shape = MaterialTheme.shapes.medium + ) + .padding(horizontal = 16.dp, vertical = 32.dp) + ) { + Text( + text = "Moderation request is now open. Would you like to apply to become a moderator?", + textAlign = TextAlign.Center, + ) + } + Row( + modifier = Modifier + .fillMaxWidth() + .padding(horizontal = 12.dp), + horizontalArrangement = Arrangement.SpaceBetween + ) { + Button( + onClick = { + navigateToModerationScreen() + } + ) { + Text(text = "Apply") + } + Button( + onClick = { + onBackClick() + }, + colors = ButtonDefaults.buttonColors( + containerColor = MaterialTheme.colorScheme.error + ) + ) { + Text(text = "Cancel") + } + } + } +} + +@Preview(showBackground = true) +@Composable +private fun ModerationApplyScreenUIPreview() { + PredictionPollsTheme { + ModerationApplyScreenUI() + } +} + + diff --git a/prediction-polls/android/app/src/main/java/com/bounswe/predictionpolls/ui/moderation/apply/ModerationApplyScreenNavigation.kt b/prediction-polls/android/app/src/main/java/com/bounswe/predictionpolls/ui/moderation/apply/ModerationApplyScreenNavigation.kt new file mode 100644 index 00000000..b5bc9de2 --- /dev/null +++ b/prediction-polls/android/app/src/main/java/com/bounswe/predictionpolls/ui/moderation/apply/ModerationApplyScreenNavigation.kt @@ -0,0 +1,22 @@ +package com.bounswe.predictionpolls.ui.moderation.apply + +import androidx.navigation.NavController +import androidx.navigation.NavGraphBuilder +import androidx.navigation.NavOptions +import androidx.navigation.Navigator +import androidx.navigation.compose.composable + +const val MODERATION_APPLY_ROUTE = "moderation_apply" + +fun NavGraphBuilder.moderationApplyScreen(navController: NavController) { + composable(MODERATION_APPLY_ROUTE) { + ModerationApplyScreen(navController) + } +} + +fun NavController.navigateToModerationApplyScreen( + navOptions: NavOptions? = null, + block: Navigator.Extras? = null +) { + navigate(MODERATION_APPLY_ROUTE, navOptions, block) +} \ No newline at end of file diff --git a/prediction-polls/android/app/src/main/java/com/bounswe/predictionpolls/ui/moderation/list/ModerationScreen.kt b/prediction-polls/android/app/src/main/java/com/bounswe/predictionpolls/ui/moderation/list/ModerationScreen.kt index 0bda784d..6ed9b424 100644 --- a/prediction-polls/android/app/src/main/java/com/bounswe/predictionpolls/ui/moderation/list/ModerationScreen.kt +++ b/prediction-polls/android/app/src/main/java/com/bounswe/predictionpolls/ui/moderation/list/ModerationScreen.kt @@ -60,7 +60,11 @@ private fun RequestedPoll( ) { Column( modifier = Modifier - .border(1.dp, Color.Black, RoundedCornerShape(8.dp)) + .border( + width = 1.dp, + color = MaterialTheme.colorScheme.onSurface.copy(alpha = 0.25f), + shape = MaterialTheme.shapes.medium + ) .padding(vertical = 16.dp, horizontal = 12.dp), horizontalAlignment = Alignment.CenterHorizontally, verticalArrangement = Arrangement.spacedBy(12.dp) diff --git a/prediction-polls/android/app/src/main/java/com/bounswe/predictionpolls/utils/NavItem.kt b/prediction-polls/android/app/src/main/java/com/bounswe/predictionpolls/utils/NavItem.kt index 7cbb94b0..030144fa 100644 --- a/prediction-polls/android/app/src/main/java/com/bounswe/predictionpolls/utils/NavItem.kt +++ b/prediction-polls/android/app/src/main/java/com/bounswe/predictionpolls/utils/NavItem.kt @@ -33,7 +33,7 @@ enum class NavItem( requiresAuth = true ), MODERATION( - route = "moderation", // TODO: change this route with the actual route + route = "moderation_apply", titleId = R.string.nav_drawer_moderation, iconId = R.drawable.ic_moderation, requiresAuth = true From c75d073b50dfd25831fc232607c58b5a1d039eaf Mon Sep 17 00:00:00 2001 From: YigitSekerci Date: Fri, 22 Dec 2023 21:51:56 +0300 Subject: [PATCH 04/13] add moderation vote screen navigation --- .../bounswe/predictionpolls/MainActivity.kt | 2 + .../moderation/vote/ModerationVoteScreen.kt | 83 +++++++++++++++++++ .../vote/ModerationVoteScreenNavigation.kt | 22 +++++ 3 files changed, 107 insertions(+) create mode 100644 prediction-polls/android/app/src/main/java/com/bounswe/predictionpolls/ui/moderation/vote/ModerationVoteScreen.kt create mode 100644 prediction-polls/android/app/src/main/java/com/bounswe/predictionpolls/ui/moderation/vote/ModerationVoteScreenNavigation.kt diff --git a/prediction-polls/android/app/src/main/java/com/bounswe/predictionpolls/MainActivity.kt b/prediction-polls/android/app/src/main/java/com/bounswe/predictionpolls/MainActivity.kt index 0817797c..a70ac64b 100644 --- a/prediction-polls/android/app/src/main/java/com/bounswe/predictionpolls/MainActivity.kt +++ b/prediction-polls/android/app/src/main/java/com/bounswe/predictionpolls/MainActivity.kt @@ -32,6 +32,7 @@ import com.bounswe.predictionpolls.ui.profile.myProfileScreen import com.bounswe.predictionpolls.ui.moderation.moderationScreen import com.bounswe.predictionpolls.ui.moderation.apply.moderationApplyScreen import com.bounswe.predictionpolls.ui.moderation.list.moderationScreen +import com.bounswe.predictionpolls.ui.moderation.vote.moderationVoteScreen import com.bounswe.predictionpolls.ui.profile.profileScreen import com.bounswe.predictionpolls.ui.signup.signupScreen import com.bounswe.predictionpolls.ui.theme.PredictionPollsTheme @@ -109,6 +110,7 @@ class MainActivity : ComponentActivity() { forgotPasswordScreen(navController) moderationApplyScreen(navController) moderationScreen(navController) + moderationVoteScreen(navController) // TODO: Remove placeholders composable("settings") { Text(text = "Settings Page WIP") } diff --git a/prediction-polls/android/app/src/main/java/com/bounswe/predictionpolls/ui/moderation/vote/ModerationVoteScreen.kt b/prediction-polls/android/app/src/main/java/com/bounswe/predictionpolls/ui/moderation/vote/ModerationVoteScreen.kt new file mode 100644 index 00000000..93bb2378 --- /dev/null +++ b/prediction-polls/android/app/src/main/java/com/bounswe/predictionpolls/ui/moderation/vote/ModerationVoteScreen.kt @@ -0,0 +1,83 @@ +package com.bounswe.predictionpolls.ui.moderation.vote + +import androidx.compose.foundation.background +import androidx.compose.foundation.border +import androidx.compose.foundation.layout.Arrangement +import androidx.compose.foundation.layout.Box +import androidx.compose.foundation.layout.Column +import androidx.compose.foundation.layout.Row +import androidx.compose.foundation.layout.Spacer +import androidx.compose.foundation.layout.fillMaxWidth +import androidx.compose.foundation.layout.padding +import androidx.compose.foundation.shape.RoundedCornerShape +import androidx.compose.material3.MaterialTheme +import androidx.compose.material3.Text +import androidx.compose.runtime.Composable +import androidx.compose.ui.Alignment +import androidx.compose.ui.Modifier +import androidx.compose.ui.graphics.Color +import androidx.compose.ui.tooling.preview.Preview +import androidx.compose.ui.unit.dp +import androidx.navigation.NavController + +@Composable +fun ModerationVoteScreen( + navController: NavController +) { + ModerationVoteScreenUI( + tags = listOf("tag1", "tag2", "tag3"), + title = "Question 1", + choices = listOf("Choice 1", "Choice 2", "Choice 3") + ) +} + +@Composable +private fun ModerationVoteScreenUI( + tags: List = emptyList(), + title: String = "", + choices: List = emptyList(), +) { + Column( + modifier = Modifier + .padding(horizontal = 12.dp, vertical = 16.dp) + .border( + width = 1.dp, + color = MaterialTheme.colorScheme.onSurface.copy(alpha = 0.25f), + shape = MaterialTheme.shapes.medium + ) + .padding(vertical = 32.dp, horizontal = 16.dp), + verticalArrangement = Arrangement.spacedBy(12.dp) + ) { + Row( + modifier = Modifier.fillMaxWidth(), + horizontalArrangement = Arrangement.spacedBy(6.dp) + ){ + tags.forEach { tag -> + Box( + modifier = Modifier + .background(MaterialTheme.colorScheme.secondary, RoundedCornerShape(8.dp)) + .padding(vertical = 8.dp, horizontal = 12.dp) + ) { + Text(text = tag, color = Color.White) + } + } + Spacer(modifier = Modifier.weight(1f)) + } + Text(text = title) + Column( + horizontalAlignment = Alignment.CenterHorizontally, + modifier = Modifier.fillMaxWidth(), + verticalArrangement = Arrangement.spacedBy(12.dp) + ) { + choices.forEach { + Text(text = it) + } + } + } +} + +@Preview +@Composable +private fun ModerationVoteScreenUIPreview() { + ModerationVoteScreenUI() +} \ No newline at end of file diff --git a/prediction-polls/android/app/src/main/java/com/bounswe/predictionpolls/ui/moderation/vote/ModerationVoteScreenNavigation.kt b/prediction-polls/android/app/src/main/java/com/bounswe/predictionpolls/ui/moderation/vote/ModerationVoteScreenNavigation.kt new file mode 100644 index 00000000..e5efe6f4 --- /dev/null +++ b/prediction-polls/android/app/src/main/java/com/bounswe/predictionpolls/ui/moderation/vote/ModerationVoteScreenNavigation.kt @@ -0,0 +1,22 @@ +package com.bounswe.predictionpolls.ui.moderation.vote + +import androidx.navigation.NavController +import androidx.navigation.NavGraphBuilder +import androidx.navigation.NavOptions +import androidx.navigation.Navigator +import androidx.navigation.compose.composable + +const val MODERATION_VOTE_ROUTE = "moderation_vote" + +fun NavGraphBuilder.moderationVoteScreen(navController: NavController) { + composable(MODERATION_VOTE_ROUTE) { + ModerationVoteScreen(navController) + } +} + +fun NavController.navigateToModerationApplyScreen( + navOptions: NavOptions? = null, + block: Navigator.Extras? = null +) { + navigate(MODERATION_VOTE_ROUTE, navOptions, block) +} \ No newline at end of file From 46c446e16721c6c6c271c31f24f0c304e597405a Mon Sep 17 00:00:00 2001 From: YigitSekerci Date: Fri, 22 Dec 2023 23:33:37 +0300 Subject: [PATCH 05/13] add moderation end points --- .../model/request/ModeratorAppointRequest.kt | 5 + .../remote/model/request/ModeratorRequest.kt | 9 ++ .../model/request/ModeratorTagRequest.kt | 6 ++ .../response/ModeratorRequestResponse.kt | 102 ++++++++++++++++++ .../model/response/ModeratorTagResponse.kt | 15 +++ .../repositories/ModerationRepository.kt | 48 +++++++++ .../ModerationRepositoryInterface.kt | 12 +++ .../data/remote/services/ModerationService.kt | 36 +++++++ .../predictionpolls/di/RepositoryModule.kt | 11 ++ .../predictionpolls/di/ServiceModule.kt | 9 ++ .../domain/moderation/ModeratorPoll.kt | 35 ++++++ .../domain/moderation/ModeratorTag.kt | 6 ++ 12 files changed, 294 insertions(+) create mode 100644 prediction-polls/android/app/src/main/java/com/bounswe/predictionpolls/data/remote/model/request/ModeratorAppointRequest.kt create mode 100644 prediction-polls/android/app/src/main/java/com/bounswe/predictionpolls/data/remote/model/request/ModeratorRequest.kt create mode 100644 prediction-polls/android/app/src/main/java/com/bounswe/predictionpolls/data/remote/model/request/ModeratorTagRequest.kt create mode 100644 prediction-polls/android/app/src/main/java/com/bounswe/predictionpolls/data/remote/model/response/ModeratorRequestResponse.kt create mode 100644 prediction-polls/android/app/src/main/java/com/bounswe/predictionpolls/data/remote/model/response/ModeratorTagResponse.kt create mode 100644 prediction-polls/android/app/src/main/java/com/bounswe/predictionpolls/data/remote/repositories/ModerationRepository.kt create mode 100644 prediction-polls/android/app/src/main/java/com/bounswe/predictionpolls/data/remote/repositories/ModerationRepositoryInterface.kt create mode 100644 prediction-polls/android/app/src/main/java/com/bounswe/predictionpolls/data/remote/services/ModerationService.kt create mode 100644 prediction-polls/android/app/src/main/java/com/bounswe/predictionpolls/domain/moderation/ModeratorPoll.kt create mode 100644 prediction-polls/android/app/src/main/java/com/bounswe/predictionpolls/domain/moderation/ModeratorTag.kt diff --git a/prediction-polls/android/app/src/main/java/com/bounswe/predictionpolls/data/remote/model/request/ModeratorAppointRequest.kt b/prediction-polls/android/app/src/main/java/com/bounswe/predictionpolls/data/remote/model/request/ModeratorAppointRequest.kt new file mode 100644 index 00000000..27f75821 --- /dev/null +++ b/prediction-polls/android/app/src/main/java/com/bounswe/predictionpolls/data/remote/model/request/ModeratorAppointRequest.kt @@ -0,0 +1,5 @@ +package com.bounswe.predictionpolls.data.remote.model.request + +data class ModeratorAppointRequest( + val userId: Int +) diff --git a/prediction-polls/android/app/src/main/java/com/bounswe/predictionpolls/data/remote/model/request/ModeratorRequest.kt b/prediction-polls/android/app/src/main/java/com/bounswe/predictionpolls/data/remote/model/request/ModeratorRequest.kt new file mode 100644 index 00000000..7c7cb816 --- /dev/null +++ b/prediction-polls/android/app/src/main/java/com/bounswe/predictionpolls/data/remote/model/request/ModeratorRequest.kt @@ -0,0 +1,9 @@ +package com.bounswe.predictionpolls.data.remote.model.request + +import com.google.gson.annotations.SerializedName + +data class ModeratorRequest( + @SerializedName("request_id") + val requestId: Int, + val choice: Any +) \ No newline at end of file diff --git a/prediction-polls/android/app/src/main/java/com/bounswe/predictionpolls/data/remote/model/request/ModeratorTagRequest.kt b/prediction-polls/android/app/src/main/java/com/bounswe/predictionpolls/data/remote/model/request/ModeratorTagRequest.kt new file mode 100644 index 00000000..a43d49c7 --- /dev/null +++ b/prediction-polls/android/app/src/main/java/com/bounswe/predictionpolls/data/remote/model/request/ModeratorTagRequest.kt @@ -0,0 +1,6 @@ +package com.bounswe.predictionpolls.data.remote.model.request + +data class ModeratorTagRequest( + val topic: String, + val isSelected: Boolean +) diff --git a/prediction-polls/android/app/src/main/java/com/bounswe/predictionpolls/data/remote/model/response/ModeratorRequestResponse.kt b/prediction-polls/android/app/src/main/java/com/bounswe/predictionpolls/data/remote/model/response/ModeratorRequestResponse.kt new file mode 100644 index 00000000..092288dd --- /dev/null +++ b/prediction-polls/android/app/src/main/java/com/bounswe/predictionpolls/data/remote/model/response/ModeratorRequestResponse.kt @@ -0,0 +1,102 @@ +package com.bounswe.predictionpolls.data.remote.model.response + +import com.bounswe.predictionpolls.domain.moderation.ModeratorPoll +import com.google.gson.annotations.SerializedName + +data class ModeratorRequestResponse( + @SerializedName("request_id") + val requestId: Int, + @SerializedName("request_type") + val requestType: String, + @SerializedName("poll") + val poll: Poll +) { + data class Poll( + @SerializedName("id") + val id: Int, + @SerializedName("question") + val question: String, + @SerializedName("tags") + val tags: List, + @SerializedName("creatorName") + val creatorName: String, + @SerializedName("creatorUsername") + val creatorUsername: String, + @SerializedName("creatorImage") + val creatorImage: String, + @SerializedName("pollType") + val pollType: String, + @SerializedName("closingDate") + val closingDate: String, + @SerializedName("rejectVotes") + val rejectVotes: String, + @SerializedName("isOpen") + val isOpen: Boolean, + @SerializedName("cont_poll_type") + val contPollType: String, + @SerializedName("comments") + val comments: List, + @SerializedName("options") + val options: List