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

#91/feature/jsp/app enhancement3 #143

Merged
merged 10 commits into from
Jun 8, 2023
Merged
Show file tree
Hide file tree
Changes from 9 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
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">
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Edittext κ΄€λ ¨ μ½”λ“œλ§žμ£ ?!

<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>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

인터넷 μ—°κ²° λ‘œμ§λ„ ν•˜μ…¨λ‚˜μš” γ…Žγ„·γ„·

</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 @@ -19,7 +19,7 @@ class TokenServerImpl @Inject constructor() : TokenServer {
*/
override val currentTokens: EndpointTokenState
get() {
val token = tokens.replayCache.firstOrNull()
val token = tokens.replayCache.lastOrNull()
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