Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[develop] 그룹 생성 #70

Open
wants to merge 13 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@
</intent-filter>
</activity>

<activity
android:name="com.cheocharm.presentation.ui.group.GroupCreateActivity"
android:exported="true" />

</application>

</manifest>
1 change: 1 addition & 0 deletions data/src/main/java/com/cheocharm/data/error/ErrorData.kt
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,5 @@ sealed class ErrorData(
data class RefreshAccessTokenUnavailable(override val message: String) : ErrorData(message)
data class SearchGroupUnavailable(override val message: String) : ErrorData(message)
data class JoinGroupUnavailable(override val message: String) : ErrorData(message)
data class GroupCreateUnavailable(override val message: String) : ErrorData(message)
}
1 change: 1 addition & 0 deletions data/src/main/java/com/cheocharm/data/error/ErrorMapper.kt
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@ internal fun ErrorData.toDomain(): Error = when (this) {
is ErrorData.RefreshAccessTokenUnavailable -> Error.RefreshAccessTokenUnavailable(message)
is ErrorData.SearchGroupUnavailable -> Error.SearchGroupUnavailable(message)
is ErrorData.JoinGroupUnavailable -> Error.JoinGroupUnavailable(message)
is ErrorData.GroupCreateUnavailable -> Error.GroupCreateUnavailable(message)
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import com.cheocharm.data.error.ErrorData
import com.cheocharm.data.error.toDomain
import com.cheocharm.data.source.GroupRemoteDataSource
import com.cheocharm.domain.model.Group
import com.cheocharm.domain.model.GroupJoin
import com.cheocharm.domain.model.group.GroupCreateRequest
import com.cheocharm.domain.repository.GroupRepository
import kotlinx.coroutines.flow.Flow
import javax.inject.Inject
Expand All @@ -17,12 +19,21 @@ class GroupRepositoryImpl @Inject constructor(
return groupRemoteDataSource.fetchGroupSearchList(searchGroupName)
}

override suspend fun joinGroup(groupName: String): Result<Unit> {
override suspend fun joinGroup(groupName: String): Result<GroupJoin> {
val result = groupRemoteDataSource.joinGroup(groupName)
return when (val exception = result.exceptionOrNull()) {
is ErrorData -> Result.failure(exception.toDomain())
null -> result
else -> Result.failure(exception)
}
}

override suspend fun createGroup(groupCreateRequest: GroupCreateRequest): Result<String> {
val result = groupRemoteDataSource.createGroup(groupCreateRequest)
return when (val exception = result.exceptionOrNull()) {
is ErrorData -> Result.failure(exception.toDomain())
null -> result
else -> Result.failure(exception)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,15 @@ package com.cheocharm.data.source

import androidx.paging.PagingData
import com.cheocharm.domain.model.Group
import com.cheocharm.domain.model.GroupJoin
import com.cheocharm.domain.model.group.GroupCreateRequest
import kotlinx.coroutines.flow.Flow

interface GroupRemoteDataSource {

fun fetchGroupSearchList(searchGroupName: String): Flow<PagingData<Group>>

suspend fun joinGroup(groupName: String): Result<Unit>
suspend fun joinGroup(groupName: String): Result<GroupJoin>

suspend fun createGroup(groupCreateRequest: GroupCreateRequest): Result<String>
}
1 change: 1 addition & 0 deletions domain/src/main/java/com/cheocharm/domain/model/Error.kt
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,5 @@ sealed class Error(
data class RefreshAccessTokenUnavailable(override val message: String) : Error()
data class SearchGroupUnavailable(override val message: String) : Error()
data class JoinGroupUnavailable(override val message: String) : Error()
data class GroupCreateUnavailable(override val message: String) : Error()
}
6 changes: 6 additions & 0 deletions domain/src/main/java/com/cheocharm/domain/model/GroupJoin.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package com.cheocharm.domain.model

data class GroupJoin(
val alreadyJoin: Boolean,
val status: String
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.cheocharm.domain.model.group

import java.io.File

data class GroupCreateRequest(
val groupImage: File,
val groupName: String,
val groupBio: String,
val changeStatus: Boolean
)
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,15 @@ package com.cheocharm.domain.repository

import androidx.paging.PagingData
import com.cheocharm.domain.model.Group
import com.cheocharm.domain.model.GroupJoin
import com.cheocharm.domain.model.group.GroupCreateRequest
import kotlinx.coroutines.flow.Flow

interface GroupRepository {

fun searchGroup(searchGroupName: String): Flow<PagingData<Group>>

suspend fun joinGroup(groupName: String): Result<Unit>
suspend fun joinGroup(groupName: String): Result<GroupJoin>

suspend fun createGroup(groupCreateRequest: GroupCreateRequest): Result<String>
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.cheocharm.domain.usecase.group

import com.cheocharm.domain.model.group.GroupCreateRequest
import com.cheocharm.domain.repository.GroupRepository
import javax.inject.Inject

class GroupCreateUseCase @Inject constructor(
private val groupRepository: GroupRepository
) {
suspend operator fun invoke(groupCreateRequest: GroupCreateRequest): Result<String> {
return groupRepository.createGroup(groupCreateRequest)
}
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
package com.cheocharm.domain.usecase.group

import com.cheocharm.domain.model.GroupJoin
import com.cheocharm.domain.repository.GroupRepository
import javax.inject.Inject

class JoinGroupUseCase @Inject constructor(
private val groupRepository: GroupRepository
) {
suspend operator fun invoke(groupName: String): Result<Unit> {
suspend operator fun invoke(groupName: String): Result<GroupJoin> {
return groupRepository.joinGroup(groupName)
}
}
3 changes: 3 additions & 0 deletions presentation/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -80,4 +80,7 @@ dependencies {

// paging
implementation "androidx.paging:paging-runtime:$pagingVersion"

// circle imageview
implementation 'de.hdodenhof:circleimageview:3.1.0'
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package com.cheocharm.presentation.ui.group

import android.content.Context
import android.graphics.Rect
import android.view.MotionEvent
import android.view.inputmethod.InputMethodManager
import android.widget.EditText
import com.cheocharm.presentation.R
import com.cheocharm.presentation.base.BaseActivity
import com.cheocharm.presentation.databinding.ActivityGroupCreateBinding
import dagger.hilt.android.AndroidEntryPoint

@AndroidEntryPoint
class GroupCreateActivity :
BaseActivity<ActivityGroupCreateBinding>(R.layout.activity_group_create) {

override fun dispatchTouchEvent(ev: MotionEvent?): Boolean {
hideKeyboardWhenOutsideTouched(ev)
return super.dispatchTouchEvent(ev)
}

private fun hideKeyboardWhenOutsideTouched(ev: MotionEvent?) {
if (ev?.action == MotionEvent.ACTION_DOWN) {
val v = currentFocus
if (v is EditText) {
val rect = Rect()
v.getGlobalVisibleRect(rect)
if (!rect.contains(ev.rawX.toInt(), ev.rawY.toInt())) {
v.clearFocus()
val imm = getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager
imm.hideSoftInputFromWindow(v.windowToken, 0)
}
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
package com.cheocharm.presentation.ui.group

import android.app.Activity
import android.content.Intent
import android.graphics.ImageDecoder
import android.os.Build
import android.os.Bundle
import android.provider.MediaStore
import android.util.Log
import android.view.View
import android.widget.Toast
import androidx.activity.result.ActivityResultLauncher
import androidx.activity.result.contract.ActivityResultContracts
import androidx.core.view.isVisible
import androidx.core.widget.doOnTextChanged
import androidx.fragment.app.activityViewModels
import androidx.navigation.fragment.findNavController
import com.cheocharm.presentation.R
import com.cheocharm.presentation.base.BaseFragment
import com.cheocharm.presentation.common.EventObserver
import com.cheocharm.presentation.databinding.FragmentGroupCreateBinding
import com.cheocharm.presentation.util.UriUtil
import dagger.hilt.android.AndroidEntryPoint

@AndroidEntryPoint
class GroupCreateFragment :
BaseFragment<FragmentGroupCreateBinding>(R.layout.fragment_group_create) {

private val groupCreateViewModel: GroupCreateViewModel by activityViewModels()
private lateinit var galleryImageLauncher: ActivityResultLauncher<Intent>

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)

binding.viewmodel = groupCreateViewModel

initButtons()
initObservers()
initGalleryLauncher()
}

private fun initButtons() {
binding.toolbarGroupCreate.setOnMenuItemClickListener {
when (it.itemId) {
R.id.location_confirm -> {
if (groupCreateViewModel.isGroupEnabled.value == true)
groupCreateViewModel.requestGroupCreate()
true
}
else -> {
false
}
}
}
binding.toolbarGroupCreate.setNavigationOnClickListener {
requireActivity().finish()
}
binding.ivGroupCreateGroup.setOnClickListener {
selectGroupImage()
}
binding.etGroupCreateName.doOnTextChanged { text, start, before, count ->
groupCreateViewModel.setGroupName(text.toString())
groupCreateViewModel.checkGroupNameVerified()
groupCreateViewModel.checkGroupEnabled()
}
binding.etGroupCreateBio.doOnTextChanged { text, start, before, count ->
groupCreateViewModel.setGroupBio(text.toString())
groupCreateViewModel.checkGroupEnabled()
}
}

private fun initObservers() {
groupCreateViewModel.isGoToSearchEnabled.observe(viewLifecycleOwner, EventObserver {
//TODO: 검색화면으로 넘어가기
// findNavController().navigate(R.id.action_groupCreateFragment_to_groupCreateSearchFragment)
})
}

private fun initGalleryLauncher() {
galleryImageLauncher =
registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { activityResult ->
if (activityResult.resultCode == Activity.RESULT_OK && activityResult.data != null) {
val imageUri = activityResult.data?.data
runCatching {
imageUri?.let { uri ->
val bitmap = if (Build.VERSION.SDK_INT < 28) {
MediaStore.Images.Media.getBitmap(
requireActivity().contentResolver, uri
)
} else {
val source = ImageDecoder.createSource(
requireActivity().contentResolver,
uri
)
ImageDecoder.decodeBitmap(source)
}
val file = UriUtil.getFileFromUri(requireActivity(), uri)
groupCreateViewModel.setGroupImage(file)
binding.ivGroupCreateGroup.setImageBitmap(bitmap)
binding.tvGroupCreateImage.isVisible = false
binding.ivGroupCreateImage.isVisible = false
}
}.onFailure {
Log.e("SignUpProfileFragment", "${it.message}")
}
} else if (activityResult.resultCode == Activity.RESULT_CANCELED) {
Toast.makeText(requireActivity(), "사진 선택 취소", Toast.LENGTH_SHORT).show()
}
}
}

private fun selectGroupImage() {
val intent = Intent(Intent.ACTION_PICK).apply {
type = "image/*"
}
galleryImageLauncher.launch(intent)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.cheocharm.presentation.ui.group

import androidx.fragment.app.activityViewModels
import com.cheocharm.presentation.R
import com.cheocharm.presentation.base.BaseFragment
import com.cheocharm.presentation.databinding.FragmentGroupCreateSearchBinding
import dagger.hilt.android.AndroidEntryPoint

@AndroidEntryPoint
class GroupCreateSearchFragment :
BaseFragment<FragmentGroupCreateSearchBinding>(R.layout.fragment_group_create_search) {

private val groupCreateViewModel by activityViewModels<GroupCreateViewModel>()

}
Loading