This repository has been archived by the owner on Aug 20, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Aayush Gupta <[email protected]>
- Loading branch information
1 parent
53c901f
commit 829d009
Showing
11 changed files
with
227 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 6 additions & 0 deletions
6
app/src/main/java/io/aayush/relabs/network/data/post/PostReply.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package io.aayush.relabs.network.data.post | ||
|
||
data class PostReply( | ||
val success: Boolean = false, | ||
val post: Post = Post() | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
112 changes: 112 additions & 0 deletions
112
app/src/main/java/io/aayush/relabs/ui/screens/reply/ReplyScreen.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
package io.aayush.relabs.ui.screens.reply | ||
|
||
import androidx.compose.foundation.Image | ||
import androidx.compose.foundation.layout.Column | ||
import androidx.compose.foundation.layout.fillMaxHeight | ||
import androidx.compose.foundation.layout.fillMaxSize | ||
import androidx.compose.foundation.layout.fillMaxWidth | ||
import androidx.compose.foundation.layout.padding | ||
import androidx.compose.material.icons.Icons | ||
import androidx.compose.material.icons.filled.ArrowBack | ||
import androidx.compose.material3.CircularProgressIndicator | ||
import androidx.compose.material3.ExperimentalMaterial3Api | ||
import androidx.compose.material3.ExtendedFloatingActionButton | ||
import androidx.compose.material3.Icon | ||
import androidx.compose.material3.IconButton | ||
import androidx.compose.material3.OutlinedTextField | ||
import androidx.compose.material3.Scaffold | ||
import androidx.compose.material3.Text | ||
import androidx.compose.material3.TopAppBar | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.runtime.LaunchedEffect | ||
import androidx.compose.runtime.getValue | ||
import androidx.compose.runtime.mutableStateOf | ||
import androidx.compose.runtime.remember | ||
import androidx.compose.runtime.setValue | ||
import androidx.compose.runtime.snapshotFlow | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.res.painterResource | ||
import androidx.compose.ui.res.stringResource | ||
import androidx.compose.ui.unit.dp | ||
import androidx.hilt.navigation.compose.hiltViewModel | ||
import androidx.lifecycle.compose.collectAsStateWithLifecycle | ||
import androidx.navigation.NavHostController | ||
import io.aayush.relabs.network.data.post.PostReply | ||
import io.aayush.relabs.ui.navigation.Screen | ||
import kotlinx.coroutines.flow.collectLatest | ||
|
||
@Composable | ||
@OptIn(ExperimentalMaterial3Api::class) | ||
fun ReplyScreen( | ||
navHostController: NavHostController, | ||
threadID: Int, | ||
viewModel: ReplyViewModel = hiltViewModel() | ||
) { | ||
var text by remember { mutableStateOf("") } | ||
var posting by remember { mutableStateOf(false) } | ||
|
||
val postReply: PostReply? by viewModel.postReply.collectAsStateWithLifecycle() | ||
|
||
LaunchedEffect(key1 = postReply) { | ||
snapshotFlow { postReply }.collectLatest { | ||
if (it != null && it.success) { | ||
navHostController.navigateUp() | ||
} else { | ||
posting = false | ||
} | ||
} | ||
} | ||
|
||
Scaffold( | ||
topBar = { | ||
TopAppBar( | ||
title = { Text(text = stringResource(id = Screen.Reply.title)) }, | ||
navigationIcon = { | ||
IconButton(onClick = { navHostController.navigateUp() }) { | ||
Icon( | ||
imageVector = Icons.Filled.ArrowBack, | ||
contentDescription = "" | ||
) | ||
} | ||
} | ||
) | ||
}, | ||
floatingActionButton = { | ||
ExtendedFloatingActionButton( | ||
text = { Text(text = stringResource(id = Screen.Reply.title)) }, | ||
icon = { | ||
if (posting) { | ||
CircularProgressIndicator() | ||
} else { | ||
Image( | ||
painter = painterResource(id = Screen.Reply.icon), | ||
contentDescription = "" | ||
) | ||
} | ||
}, | ||
onClick = { | ||
if (!posting && text.isNotBlank()) { | ||
posting = true | ||
viewModel.postReply(threadID, text) | ||
} | ||
} | ||
) | ||
} | ||
) { | ||
Column( | ||
modifier = Modifier | ||
.padding(it) | ||
.fillMaxSize() | ||
) { | ||
OutlinedTextField( | ||
modifier = Modifier | ||
.fillMaxWidth() | ||
.fillMaxHeight(0.5f) | ||
.padding(20.dp), | ||
value = text, | ||
onValueChange = { newText -> text = newText }, | ||
enabled = !posting | ||
) | ||
} | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
app/src/main/java/io/aayush/relabs/ui/screens/reply/ReplyViewModel.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package io.aayush.relabs.ui.screens.reply | ||
|
||
import androidx.lifecycle.ViewModel | ||
import androidx.lifecycle.viewModelScope | ||
import dagger.hilt.android.lifecycle.HiltViewModel | ||
import io.aayush.relabs.network.XenforoRepository | ||
import io.aayush.relabs.network.data.post.PostReply | ||
import kotlinx.coroutines.Dispatchers | ||
import kotlinx.coroutines.flow.MutableStateFlow | ||
import kotlinx.coroutines.flow.asStateFlow | ||
import kotlinx.coroutines.launch | ||
import javax.inject.Inject | ||
|
||
@HiltViewModel | ||
class ReplyViewModel @Inject constructor( | ||
private val xenforoRepository: XenforoRepository | ||
) : ViewModel() { | ||
|
||
private val _postReply = MutableStateFlow<PostReply?>(PostReply()) | ||
val postReply = _postReply.asStateFlow() | ||
|
||
fun postReply(threadID: Int, message: String) { | ||
viewModelScope.launch(Dispatchers.IO) { | ||
_postReply.value = xenforoRepository.postReply(threadID, message) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<vector xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:width="24dp" | ||
android:height="24dp" | ||
android:viewportWidth="960" | ||
android:viewportHeight="960" | ||
android:tint="?attr/colorControlNormal"> | ||
<path | ||
android:fillColor="@android:color/white" | ||
android:pathData="M80,880L80,160Q80,127 103.5,103.5Q127,80 160,80L800,80Q833,80 856.5,103.5Q880,127 880,160L880,400L800,400L800,160Q800,160 800,160Q800,160 800,160L160,160Q160,160 160,160Q160,160 160,160L160,685L206,640L600,640L600,720L240,720L80,880ZM160,640L160,640L160,640L160,160Q160,160 160,160Q160,160 160,160L160,160Q160,160 160,160Q160,160 160,160L160,160L160,160L160,640ZM760,920L760,720L680,720L680,480L880,480L812,640L900,640L760,920Z"/> | ||
</vector> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters