Skip to content

Commit

Permalink
Merge pull request #143 from pknu-wap/#91/feature/jsp/app_enhancement3
Browse files Browse the repository at this point in the history
#91/feature/jsp/app enhancement3
  • Loading branch information
pknujsp authored Jun 8, 2023
2 parents ea878c5 + 5db9032 commit d576bea
Show file tree
Hide file tree
Showing 52 changed files with 692 additions and 167 deletions.
2 changes: 1 addition & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ dependencies {
implementation(project(":core:model"))
implementation(project(":core:database"))
implementation(project(":core:domain"))

implementation(project(":core:network"))

implementation(project(":feature:interestedmedicine"))
implementation(project(":feature:home"))
Expand Down
4 changes: 1 addition & 3 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,19 @@
android:name="android.hardware.camera"
android:required="true" />


<application
android:name=".MediApplication"
android:allowBackup="true"
android:icon="@mipmap/ic_medilenz"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/Theme.MediProject"
android:usesCleartextTraffic="true">
<activity
android:name=".MainActivity"
android:exported="true"
android:screenOrientation="portrait"
android:theme="@style/Theme.App.Starting"
android:windowSoftInputMode="adjustResize|adjustPan">
android:windowSoftInputMode="adjustUnspecified">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

Expand Down
11 changes: 11 additions & 0 deletions app/src/main/java/com/android/mediproject/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import androidx.navigation.fragment.NavHostFragment
import androidx.navigation.ui.setupWithNavController
import com.android.mediproject.core.common.uiutil.LayoutController
import com.android.mediproject.core.common.uiutil.SystemBarStyler
import com.android.mediproject.core.network.InternetNetworkListener
import com.android.mediproject.core.ui.WindowViewModel
import com.android.mediproject.core.ui.base.BaseActivity
import com.android.mediproject.databinding.ActivityMainBinding
Expand All @@ -32,6 +33,8 @@ class MainActivity : BaseActivity<ActivityMainBinding, MainViewModel>(ActivityMa

@Inject lateinit var systemBarStyler: SystemBarStyler

@Inject lateinit var internetNetworkListener: InternetNetworkListener

companion object {
const val VISIBLE = 0
const val INVISIBLE = 1
Expand All @@ -44,6 +47,14 @@ class MainActivity : BaseActivity<ActivityMainBinding, MainViewModel>(ActivityMa
systemBarStyler.init(this, window, this::changeFragmentContainerHeight)
systemBarStyler.setStyle(SystemBarStyler.StatusBarColor.WHITE, SystemBarStyler.NavigationBarColor.BLACK)

internetNetworkListener.activityLifeCycle = this.lifecycle
internetNetworkListener.networkStateCallback = InternetNetworkListener.NetworkStateCallback { isConnected ->
if (!isConnected) {
val modalBottomSheet = NetworkStateDialogFragment()
modalBottomSheet.show(supportFragmentManager, NetworkStateDialogFragment::class.java.name)
}
}

//SDK 31이상일 때 Splash가 소소하게 사라지는 이펙트 입니다. 추후 걸리적거리면 삭제해도 됌
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
splashScreen.setOnExitAnimationListener { splashScreenView ->
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package com.android.mediproject

import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import com.android.mediproject.databinding.ViewNetworkStateBinding
import com.google.android.material.bottomsheet.BottomSheetDialogFragment
import dagger.hilt.android.AndroidEntryPoint

@AndroidEntryPoint
class NetworkStateDialogFragment : BottomSheetDialogFragment() {

private var _binding: ViewNetworkStateBinding? = null

private val binding get() = _binding!!

override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?
): View = ViewNetworkStateBinding.inflate(layoutInflater, container, false).also {
_binding = it
}.root

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
binding.okButton.setOnClickListener {
dismiss()
requireActivity().finish()
}
}
}
30 changes: 30 additions & 0 deletions app/src/main/res/layout/view_network_state.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
style="@style/ModalBottomSheetDialog"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:backgroundTint="@color/white"
android:gravity="center"
android:orientation="vertical"
android:paddingHorizontal="24dp"
android:paddingVertical="24dp"
app:layout_behavior="com.google.android.material.bottomsheet.BottomSheetBehavior">

<TextView
android:id="@+id/messageTextView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="16dp"
android:gravity="center"
android:text="@string/noInternetConnection"
android:textSize="22sp" />

<Button
android:id="@+id/okButton"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:backgroundTint="@color/main"
android:text="@string/confirm" />

</LinearLayout>
11 changes: 11 additions & 0 deletions app/src/main/res/values/styles.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>

<style name="ModalBottomSheet" parent="Widget.Material3.BottomSheet.Modal">
<item name="android:backgroundTint">@color/white</item>
<item name="behavior_hideable">false</item>
<item name="behavior_draggable">false</item>
</style>

<style name="ModalBottomSheetDialog" parent="ThemeOverlay.Material3.BottomSheetDialog">
<item name="bottomSheetStyle">@style/ModalBottomSheet</item>
</style>


</resources>
1 change: 1 addition & 0 deletions core/common/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -72,4 +72,5 @@
<string name="efficacyGroupDuplicationCaution">효능군 중복</string>
<string name="divisionCaution">분할 주의</string>
<string name="additiveCaution">첨가제 주의</string>
<string name="noInternetConnection">인터넷 연결이 필요합니다.</string>
</resources>
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package com.android.mediproject.core.data.remote.comments
import androidx.paging.PagingData
import com.android.mediproject.core.model.comments.CommentChangedResponse
import com.android.mediproject.core.model.comments.CommentListResponse
import com.android.mediproject.core.model.comments.LikeResponse
import com.android.mediproject.core.model.comments.MyCommentDto
import com.android.mediproject.core.model.requestparameters.DeleteCommentParameter
import com.android.mediproject.core.model.requestparameters.EditCommentParameter
Expand Down Expand Up @@ -39,5 +40,5 @@ interface CommentsRepository {
/**
* 댓글 좋아요 클릭
*/
fun likeComment(parameter: LikeCommentParameter): Flow<Result<CommentChangedResponse>>
fun likeComment(parameter: LikeCommentParameter): Flow<Result<LikeResponse>>
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import com.android.mediproject.core.common.AWS_LOAD_PAGE_SIZE
import com.android.mediproject.core.data.remote.sign.SignRepository
import com.android.mediproject.core.model.comments.CommentChangedResponse
import com.android.mediproject.core.model.comments.CommentListResponse
import com.android.mediproject.core.model.comments.LikeResponse
import com.android.mediproject.core.model.comments.MyCommentDto
import com.android.mediproject.core.model.remote.token.TokenState
import com.android.mediproject.core.model.requestparameters.DeleteCommentParameter
Expand All @@ -23,7 +24,8 @@ import kotlinx.coroutines.flow.lastOrNull
import javax.inject.Inject

class CommentsRepositoryImpl @Inject constructor(
private val commentsDataSource: CommentsDataSource, private val signRepository: SignRepository) : CommentsRepository {
private val commentsDataSource: CommentsDataSource, private val signRepository: SignRepository
) : CommentsRepository {
override fun getCommentsForAMedicine(medicineId: Long): Flow<PagingData<CommentListResponse.Comment>> =
Pager(config = PagingConfig(pageSize = AWS_LOAD_PAGE_SIZE, prefetchDistance = 5), pagingSourceFactory = {
CommentsListDataSourceImpl(commentsDataSource, medicineId)
Expand Down Expand Up @@ -70,7 +72,7 @@ class CommentsRepositoryImpl @Inject constructor(
}
}

override fun likeComment(parameter: LikeCommentParameter): Flow<Result<CommentChangedResponse>> = channelFlow {
override fun likeComment(parameter: LikeCommentParameter): Flow<Result<LikeResponse>> = channelFlow {
checkToken().collectLatest { tokenState ->
tokenState.onSuccess {
commentsDataSource.likeComment(parameter).collectLatest {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,19 @@
package com.android.mediproject.core.data.remote.interestedmedicine


import com.android.mediproject.core.model.medicine.InterestedMedicine.InterestedMedicineListResponse
import com.android.mediproject.core.model.interestedmedicine.DeleteInterestedMedicineResponse
import com.android.mediproject.core.model.interestedmedicine.InterestedMedicineListResponse
import com.android.mediproject.core.model.interestedmedicine.IsInterestedMedicineResponse
import com.android.mediproject.core.model.interestedmedicine.NewInterestedMedicineResponse
import com.android.mediproject.core.model.requestparameters.AddInterestedMedicineParameter
import kotlinx.coroutines.flow.Flow

interface InterestedMedicineRepository {
suspend fun getInterestedMedicineList() : Flow<Result<List<InterestedMedicineListResponse.Medicine>>>
suspend fun getInterestedMedicineList(): Flow<Result<List<InterestedMedicineListResponse.Medicine>>>

fun addInterestedMedicine(addInterestedMedicineParameter: AddInterestedMedicineParameter): Flow<Result<NewInterestedMedicineResponse>>

fun deleteInterestedMedicine(medicineId: Long): Flow<Result<DeleteInterestedMedicineResponse>>

fun isInterestedMedicine(itemSeq: Long): Flow<Result<IsInterestedMedicineResponse>>
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
package com.android.mediproject.core.data.remote.interestedmedicine

import com.android.mediproject.core.model.medicine.InterestedMedicine.InterestedMedicineListResponse
import com.android.mediproject.core.model.interestedmedicine.DeleteInterestedMedicineResponse
import com.android.mediproject.core.model.interestedmedicine.InterestedMedicineListResponse
import com.android.mediproject.core.model.interestedmedicine.IsInterestedMedicineResponse
import com.android.mediproject.core.model.interestedmedicine.NewInterestedMedicineResponse
import com.android.mediproject.core.model.requestparameters.AddInterestedMedicineParameter
import com.android.mediproject.core.network.datasource.interestedmedicine.InterestedMedicineDataSource
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.channelFlow
Expand All @@ -11,12 +15,18 @@ import javax.inject.Inject

class InterestedMedicineRepositoryImpl @Inject constructor(private val interestedMedicineDataSource: InterestedMedicineDataSource) :
InterestedMedicineRepository {
override suspend fun getInterestedMedicineList(): Flow<Result<List<InterestedMedicineListResponse.Medicine>>> =
channelFlow {
interestedMedicineDataSource.getInterestedMedicineList().map { result ->
result.fold(
onSuccess = { Result.success(it.medicineList) },
onFailure = { Result.failure(it) })
}.collectLatest { trySend(it) }
}
override suspend fun getInterestedMedicineList(): Flow<Result<List<InterestedMedicineListResponse.Medicine>>> = channelFlow {
interestedMedicineDataSource.getInterestedMedicineList().map { result ->
result.fold(onSuccess = { Result.success(it.medicineList) }, onFailure = { Result.failure(it) })
}.collectLatest { trySend(it) }
}

override fun addInterestedMedicine(addInterestedMedicineParameter: AddInterestedMedicineParameter): Flow<Result<NewInterestedMedicineResponse>> =
interestedMedicineDataSource.addInterestedMedicine(addInterestedMedicineParameter)

override fun deleteInterestedMedicine(medicineId: Long): Flow<Result<DeleteInterestedMedicineResponse>> =
interestedMedicineDataSource.deleteInterestedMedicine(medicineId)

override fun isInterestedMedicine(itemSeq: Long): Flow<Result<IsInterestedMedicineResponse>> =
interestedMedicineDataSource.isInterestedMedicine(itemSeq)
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class SignRepositoryImpl @Inject constructor(
signInResult.onSuccess {
// 내 계정 정보 메모리에 저장
userInfoRepository.updateMyAccountInfo(AccountState.SignedIn(it._userId!!.toLong(), it._nickName!!, it._email!!))
saveMyAccountInfo(if (signInParameter.isSavedEmail) it._email!! else "", it._nickName!!, it._userId!!.toLong())
saveMyAccountInfo(it._email!!, it._nickName!!, it._userId!!.toLong())
}
}

Expand Down Expand Up @@ -78,7 +78,7 @@ class SignRepositoryImpl @Inject constructor(
signUpResult.onSuccess {
// 내 계정 정보 메모리에 저장
userInfoRepository.updateMyAccountInfo(AccountState.SignedIn(it._userId!!.toLong(), it._nickName!!, it._email!!))
saveMyAccountInfo("", it._nickName!!, it._userId!!.toLong())
saveMyAccountInfo(it._email!!, it._nickName!!, it._userId!!.toLong())
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ class UserInfoRepositoryImpl @Inject constructor(
private val userInfoDataSource: UserInfoDataSource, private val appDataStore: AppDataStore
) : UserInfoRepository {


private val _myAccountInfo = MutableStateFlow<AccountState>(AccountState.Unknown)

override val myAccountInfo get() = _myAccountInfo as StateFlow<AccountState>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ class TokenServerImpl @Inject constructor() : TokenServer {
override val currentTokens: EndpointTokenState
get() {
val token = tokens.replayCache.lastOrNull()
Log.d("wap","TokenServer currentTokens () : token값 : "+token.toString())
return if (token == null) {
EndpointTokenState.NoToken
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import androidx.paging.flatMap
import com.android.mediproject.core.common.network.Dispatcher
import com.android.mediproject.core.common.network.MediDispatchers
import com.android.mediproject.core.data.remote.comments.CommentsRepository
import com.android.mediproject.core.data.remote.user.UserInfoRepository
import com.android.mediproject.core.model.comments.CommentDto
import com.android.mediproject.core.model.comments.MyCommentDto
import com.android.mediproject.core.model.comments.toDto
Expand All @@ -13,6 +14,8 @@ import com.android.mediproject.core.model.requestparameters.EditCommentParameter
import com.android.mediproject.core.model.requestparameters.LikeCommentParameter
import com.android.mediproject.core.model.requestparameters.NewCommentParameter
import kotlinx.coroutines.CoroutineDispatcher
import kotlinx.coroutines.channels.BufferOverflow
import kotlinx.coroutines.channels.Channel
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.channelFlow
import kotlinx.coroutines.flow.collectLatest
Expand All @@ -21,19 +24,31 @@ import javax.inject.Inject

class CommentsUseCase @Inject constructor(
private val commentsRepository: CommentsRepository,
@Dispatcher(MediDispatchers.Default) private val defaultDispatcher: CoroutineDispatcher) {
private val userInfoRepository: UserInfoRepository,
@Dispatcher(MediDispatchers.Default) private val defaultDispatcher: CoroutineDispatcher
) {

val scrollChannel = Channel<Unit>(capacity = 3, onBufferOverflow = BufferOverflow.DROP_OLDEST)

/**
* 약에 대한 댓글을 가져오는 메서드입니다.
*
* @param medicineId 약의 고유 번호
*/
fun getCommentsForAMedicine(medicineId: Long): Flow<PagingData<CommentDto>> = channelFlow {
fun getCommentsForAMedicine(medicineId: Long, myUserId: Long): Flow<PagingData<CommentDto>> = channelFlow {
commentsRepository.getCommentsForAMedicine(medicineId).collectLatest { pagingData ->
val result = pagingData.flatMap {
(it.replies.map { reply ->
reply.toDto()
}.reversed()) + listOf(it.toDto())
reply.toDto().apply {
reply.likeList.forEach { like ->
if (like.userId == myUserId) this.isLiked = true
}
}
}.reversed()) + listOf(it.toDto().apply {
it.likeList.forEach { like ->
if (like.userId == myUserId) this.isLiked = true
}
})
}
send(result)
}
Expand Down Expand Up @@ -61,7 +76,9 @@ class CommentsUseCase @Inject constructor(
*/
fun applyNewComment(parameter: NewCommentParameter): Flow<Result<Unit>> =
commentsRepository.applyNewComment(parameter).mapLatest { result ->
result.fold(onSuccess = { Result.success(Unit) }, onFailure = { Result.failure(it) })
result.fold(onSuccess = {
Result.success(Unit)
}, onFailure = { Result.failure(it) })
}


Expand Down
Loading

0 comments on commit d576bea

Please sign in to comment.