This repository has been archived by the owner on Mar 8, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🔀 :: (#148) 버그 제보 기능 구현
- Loading branch information
Showing
21 changed files
with
288 additions
and
9 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package com.signal.data.api | ||
|
||
import com.signal.data.model.report.ReportBugRequest | ||
import retrofit2.http.Body | ||
import retrofit2.http.POST | ||
|
||
interface ReportApi { | ||
@POST(SignalUrl.Report.ReportBug) | ||
suspend fun reportBug( | ||
@Body reportBugRequest: ReportBugRequest, | ||
) | ||
} |
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
7 changes: 7 additions & 0 deletions
7
data/src/main/kotlin/com/signal/data/datasource/report/ReportDataSource.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,7 @@ | ||
package com.signal.data.datasource.report | ||
|
||
import com.signal.data.model.report.ReportBugRequest | ||
|
||
interface ReportDataSource { | ||
suspend fun reportBug(reportBugRequest: ReportBugRequest) | ||
} |
14 changes: 14 additions & 0 deletions
14
data/src/main/kotlin/com/signal/data/datasource/report/ReportDataSourceImpl.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,14 @@ | ||
package com.signal.data.datasource.report | ||
|
||
import com.signal.data.api.ReportApi | ||
import com.signal.data.model.report.ReportBugRequest | ||
import com.signal.data.util.ExceptionHandler | ||
|
||
class ReportDataSourceImpl( | ||
private val reportApi: ReportApi, | ||
) : ReportDataSource { | ||
override suspend fun reportBug(reportBugRequest: ReportBugRequest) = | ||
ExceptionHandler<Unit>().httpRequest { | ||
reportApi.reportBug(reportBugRequest = reportBugRequest) | ||
}.sendRequest() | ||
} |
8 changes: 8 additions & 0 deletions
8
data/src/main/kotlin/com/signal/data/model/report/ReportBugRequest.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,8 @@ | ||
package com.signal.data.model.report | ||
|
||
import com.google.gson.annotations.SerializedName | ||
|
||
class ReportBugRequest( | ||
@SerializedName("content") val content: String, | ||
@SerializedName("image") val image: String?, | ||
) |
21 changes: 21 additions & 0 deletions
21
data/src/main/kotlin/com/signal/data/repository/ReportRepositoryImpl.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,21 @@ | ||
package com.signal.data.repository | ||
|
||
import com.signal.data.datasource.report.ReportDataSource | ||
import com.signal.data.model.report.ReportBugRequest | ||
import com.signal.domain.repository.ReportRepository | ||
|
||
class ReportRepositoryImpl( | ||
private val reportDataSource: ReportDataSource | ||
) : ReportRepository { | ||
override suspend fun reportBug( | ||
content: String, | ||
image: String?, | ||
) = kotlin.runCatching { | ||
reportDataSource.reportBug( | ||
reportBugRequest = ReportBugRequest( | ||
content = content, | ||
image = image, | ||
), | ||
) | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
domain/src/main/kotlin/com/signal/domain/repository/ReportRepository.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,8 @@ | ||
package com.signal.domain.repository | ||
|
||
interface ReportRepository { | ||
suspend fun reportBug( | ||
content: String, | ||
image: String?, | ||
): Result<Unit> | ||
} |
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
5 changes: 5 additions & 0 deletions
5
presentation/src/main/java/com/signal/signal_android/feature/bug/BugSideEffect.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,5 @@ | ||
package com.signal.signal_android.feature.bug | ||
|
||
sealed interface BugSideEffect { | ||
object Success: BugSideEffect | ||
} |
13 changes: 13 additions & 0 deletions
13
presentation/src/main/java/com/signal/signal_android/feature/bug/BugState.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,13 @@ | ||
package com.signal.signal_android.feature.bug | ||
|
||
internal data class BugState( | ||
val content: String, | ||
val image: String, | ||
) { | ||
companion object { | ||
fun getDefaultState() = BugState( | ||
content = "", | ||
image = "", | ||
) | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
presentation/src/main/java/com/signal/signal_android/feature/bug/BugViewModel.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,35 @@ | ||
package com.signal.signal_android.feature.bug | ||
|
||
import androidx.lifecycle.viewModelScope | ||
import com.signal.domain.repository.ReportRepository | ||
import com.signal.signal_android.BaseViewModel | ||
import kotlinx.coroutines.Dispatchers | ||
import kotlinx.coroutines.launch | ||
|
||
internal class BugViewModel( | ||
private val reportRepository: ReportRepository, | ||
) : BaseViewModel<BugState, BugSideEffect>(BugState.getDefaultState()) { | ||
|
||
internal fun reportBug() { | ||
with(state.value) { | ||
viewModelScope.launch(Dispatchers.IO) { | ||
reportRepository.reportBug( | ||
content = content, | ||
image = image, | ||
).onSuccess { | ||
postSideEffect(BugSideEffect.Success) | ||
}.onFailure { | ||
|
||
} | ||
} | ||
} | ||
} | ||
|
||
internal fun setContent(content: String) { | ||
setState(state.value.copy(content = content)) | ||
} | ||
|
||
internal fun setImage(image: String){ | ||
setState(state.value.copy(image = image)) | ||
} | ||
} |
118 changes: 118 additions & 0 deletions
118
presentation/src/main/java/com/signal/signal_android/feature/bug/ReportBug.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,118 @@ | ||
package com.signal.signal_android.feature.bug | ||
|
||
import android.net.Uri | ||
import androidx.activity.compose.rememberLauncherForActivityResult | ||
import androidx.activity.result.PickVisualMediaRequest | ||
import androidx.activity.result.contract.ActivityResultContracts | ||
import androidx.compose.foundation.layout.Column | ||
import androidx.compose.foundation.layout.Spacer | ||
import androidx.compose.foundation.layout.fillMaxHeight | ||
import androidx.compose.foundation.layout.fillMaxSize | ||
import androidx.compose.foundation.layout.height | ||
import androidx.compose.foundation.layout.padding | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.runtime.LaunchedEffect | ||
import androidx.compose.runtime.collectAsState | ||
import androidx.compose.runtime.getValue | ||
import androidx.compose.runtime.mutableStateOf | ||
import androidx.compose.runtime.remember | ||
import androidx.compose.runtime.setValue | ||
import androidx.compose.ui.Alignment | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.platform.LocalContext | ||
import androidx.compose.ui.platform.LocalFocusManager | ||
import androidx.compose.ui.res.stringResource | ||
import androidx.compose.ui.unit.dp | ||
import com.signal.data.util.FileUtil | ||
import com.signal.signal_android.R | ||
import com.signal.signal_android.designsystem.button.SignalFilledButton | ||
import com.signal.signal_android.designsystem.component.Header | ||
import com.signal.signal_android.designsystem.textfield.SignalTextField | ||
import com.signal.signal_android.feature.file.AttachmentViewModel | ||
import com.signal.signal_android.feature.main.feed.PostImage | ||
import org.koin.androidx.compose.koinViewModel | ||
|
||
@Composable | ||
internal fun ReportBug( | ||
moveToBack: () -> Unit, | ||
bugViewModel: BugViewModel = koinViewModel(), | ||
attachmentViewModel: AttachmentViewModel = koinViewModel(), | ||
) { | ||
val state by bugViewModel.state.collectAsState() | ||
val attachmentState by attachmentViewModel.state.collectAsState() | ||
|
||
LaunchedEffect(Unit) { | ||
bugViewModel.sideEffect.collect { | ||
when (it) { | ||
is BugSideEffect.Success -> moveToBack() | ||
} | ||
} | ||
} | ||
|
||
val context = LocalContext.current | ||
|
||
var imagePreview: Uri? by remember { mutableStateOf(null) } | ||
val imageUrl by remember { mutableStateOf("") } | ||
|
||
val focusManager = LocalFocusManager.current | ||
|
||
val launcher = rememberLauncherForActivityResult(ActivityResultContracts.PickVisualMedia()) { | ||
it?.run { | ||
imagePreview = it | ||
with(attachmentViewModel) { | ||
setFile( | ||
FileUtil.toFile( | ||
context = context, | ||
uri = this@run, | ||
) | ||
) | ||
uploadFile() | ||
} | ||
} | ||
} | ||
|
||
var reason by remember { mutableStateOf("") } | ||
|
||
Column( | ||
modifier = Modifier | ||
.fillMaxSize() | ||
.padding( | ||
start = 16.dp, | ||
end = 16.dp, | ||
bottom = 24.dp, | ||
) | ||
) { | ||
Header( | ||
title = stringResource(id = R.string.report_bug_header_title), | ||
onLeadingClicked = moveToBack, | ||
) | ||
Spacer(modifier = Modifier.height(12.dp)) | ||
SignalTextField( | ||
modifier = Modifier | ||
.fillMaxHeight(0.5f) | ||
.padding(bottom = 28.dp), | ||
value = state.content, | ||
onValueChange = bugViewModel::setContent, | ||
showLength = true, | ||
maxLength = 1000, | ||
hint = stringResource(id = R.string.report_bug_hint_reason), | ||
alignment = Alignment.Top, | ||
) | ||
PostImage( | ||
uri = { imagePreview }, | ||
imageUrl = { imageUrl }, | ||
) { | ||
focusManager.clearFocus() | ||
launcher.launch(PickVisualMediaRequest(ActivityResultContracts.PickVisualMedia.ImageOnly)) | ||
} | ||
Spacer(modifier = Modifier.weight(1f)) | ||
SignalFilledButton( | ||
text = stringResource(id = R.string.my_page_secession_check), | ||
onClick = { | ||
bugViewModel.setImage(image = attachmentState.imageUrl) | ||
bugViewModel.reportBug() | ||
}, | ||
enabled = state.content.isNotEmpty(), | ||
) | ||
} | ||
} |
Oops, something went wrong.