This repository has been archived by the owner on Oct 20, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
📖 감정 별 일기 조회 & Custom Number Picker (Only Year and Month) (#48)
* [feat] 감정 비활성 이미지 추가 * [feat] 감정 별 일기 목록 조회 API 추가 * [feat] 감정 별 일기 목록 조회 UseCase 추가 * [feat] Add Context Extension | AlertDialog Resize * [feat] Add Custom NumberPicker | Year and Month * [feat] Add Restore Data Feature * [feat] 감정 별 일기 조회 페이지 구현
- Loading branch information
Showing
23 changed files
with
700 additions
and
12 deletions.
There are no files selected for viewing
9 changes: 9 additions & 0 deletions
9
Nabi/data/src/main/java/com/nabi/data/datasource/EmotionRemoteDataSource.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 |
---|---|---|
@@ -1,10 +1,19 @@ | ||
package com.nabi.data.datasource | ||
|
||
import com.nabi.data.model.BaseResponse | ||
import com.nabi.data.model.PageableResponse | ||
import com.nabi.data.model.emotion.DiaryStatisticsResponseDTO | ||
import com.nabi.data.model.emotion.SearchEmotionResponseDTO | ||
|
||
interface EmotionRemoteDataSource { | ||
|
||
suspend fun getDiaryStatistics(accessToken: String, startDate: String, endDate: String): Result<BaseResponse<DiaryStatisticsResponseDTO>> | ||
|
||
suspend fun searchDiaryByEmotion( | ||
accessToken: String, | ||
emotion: String, | ||
page: Int, | ||
size: Int, | ||
sort: String | ||
): Result<BaseResponse<PageableResponse<SearchEmotionResponseDTO>>> | ||
} |
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
9 changes: 9 additions & 0 deletions
9
Nabi/data/src/main/java/com/nabi/data/model/emotion/SearchEmotionResponseDTO.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,9 @@ | ||
package com.nabi.data.model.emotion | ||
|
||
import com.google.gson.annotations.SerializedName | ||
|
||
data class SearchEmotionResponseDTO( | ||
@SerializedName("diaryEntryDate") val diaryEntryDate: String, | ||
@SerializedName("content") val content: String, | ||
@SerializedName("diaryId") val diaryId: Int | ||
) |
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
10 changes: 10 additions & 0 deletions
10
Nabi/domain/src/main/java/com/nabi/domain/repository/EmotionRepository.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 |
---|---|---|
@@ -1,9 +1,19 @@ | ||
package com.nabi.domain.repository | ||
|
||
import com.nabi.domain.model.PageableInfo | ||
import com.nabi.domain.model.diary.SearchDiary | ||
import com.nabi.domain.model.emotion.EmotionStatistics | ||
|
||
interface EmotionRepository { | ||
|
||
suspend fun getDiaryStatistics(accessToken: String, startDate: String, endDate: String): Result<EmotionStatistics> | ||
|
||
suspend fun searchDiaryByEmotion( | ||
accessToken: String, | ||
emotion: String, | ||
page: Int, | ||
size: Int, | ||
sort: String | ||
): Result<Pair<PageableInfo, List<SearchDiary>>> | ||
|
||
} |
13 changes: 13 additions & 0 deletions
13
Nabi/domain/src/main/java/com/nabi/domain/usecase/emotion/SearchEmotionUseCase.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.nabi.domain.usecase.emotion | ||
|
||
import com.nabi.domain.model.PageableInfo | ||
import com.nabi.domain.model.diary.DiaryInfo | ||
import com.nabi.domain.model.diary.SearchDiary | ||
import com.nabi.domain.model.emotion.EmotionStatistics | ||
import com.nabi.domain.repository.EmotionRepository | ||
|
||
class SearchEmotionUseCase(private val repository: EmotionRepository) { | ||
suspend operator fun invoke(accessToken: String, emotion: String, page: Int, size: Int, sort: String): Result<Pair<PageableInfo, List<SearchDiary>>>{ | ||
return repository.searchDiaryByEmotion("Bearer $accessToken", emotion, page, size, sort) | ||
} | ||
} |
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
34 changes: 34 additions & 0 deletions
34
Nabi/presentation/src/main/java/com/nabi/nabi/extension/ContextExtension.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,34 @@ | ||
package com.nabi.nabi.extension | ||
|
||
import android.app.Dialog | ||
import android.content.Context | ||
import android.graphics.Point | ||
import android.os.Build | ||
import android.view.WindowManager | ||
|
||
fun Context.dialogResize(dialog: Dialog, width: Float, height: Float){ | ||
val windowManager = getSystemService(Context.WINDOW_SERVICE) as WindowManager | ||
|
||
if (Build.VERSION.SDK_INT < 30){ | ||
val display = windowManager.defaultDisplay | ||
val size = Point() | ||
|
||
display.getSize(size) | ||
|
||
val window = dialog.window | ||
|
||
val x = (size.x * width).toInt() | ||
val y = (size.y * height).toInt() | ||
|
||
window?.setLayout(x, y) | ||
|
||
} else{ | ||
val rect = windowManager.currentWindowMetrics.bounds | ||
|
||
val window = dialog.window | ||
val x = (rect.width() * width).toInt() | ||
val y = (rect.height() * height).toInt() | ||
|
||
window?.setLayout(x, y) | ||
} | ||
} |
56 changes: 56 additions & 0 deletions
56
Nabi/presentation/src/main/java/com/nabi/nabi/views/diary/emotion/EmotionSearchAdapter.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,56 @@ | ||
package com.nabi.nabi.views.diary.emotion | ||
|
||
import android.view.LayoutInflater | ||
import android.view.ViewGroup | ||
import androidx.recyclerview.widget.DiffUtil | ||
import androidx.recyclerview.widget.ListAdapter | ||
import androidx.recyclerview.widget.RecyclerView | ||
import com.nabi.domain.model.diary.SearchDiary | ||
import com.nabi.nabi.databinding.ItemSearchDiaryBinding | ||
import com.nabi.nabi.views.OnRvItemClickListener | ||
|
||
class EmotionSearchAdapter : ListAdapter<SearchDiary, EmotionSearchAdapter.SearchResultViewHolder>(diaryDiffUtil) { | ||
|
||
companion object { | ||
private val diaryDiffUtil = object : DiffUtil.ItemCallback<SearchDiary>() { | ||
override fun areItemsTheSame(oldItem: SearchDiary, newItem: SearchDiary): Boolean = | ||
oldItem.diaryId == newItem.diaryId | ||
|
||
override fun areContentsTheSame(oldItem: SearchDiary, newItem: SearchDiary): Boolean = | ||
oldItem == newItem | ||
} | ||
} | ||
|
||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): SearchResultViewHolder { | ||
val binding = ItemSearchDiaryBinding.inflate(LayoutInflater.from(parent.context), parent, false) | ||
return SearchResultViewHolder(binding) | ||
} | ||
|
||
override fun onBindViewHolder(holder: SearchResultViewHolder, position: Int) { | ||
holder.bind(getItem(position)) | ||
} | ||
|
||
inner class SearchResultViewHolder(val binding: ItemSearchDiaryBinding) : RecyclerView.ViewHolder(binding.root) { | ||
fun bind(item: SearchDiary) { | ||
binding.tvSearchDiaryDate.text = item.diaryEntryDate | ||
binding.tvContent.text = item.previewContent | ||
|
||
itemView.setOnClickListener { | ||
rvItemClickListener.onClick(item.diaryId) | ||
} | ||
} | ||
} | ||
|
||
private lateinit var rvItemClickListener: OnRvItemClickListener<Int> | ||
|
||
fun setRvItemClickListener(rvItemClickListener: OnRvItemClickListener<Int>){ | ||
this.rvItemClickListener = rvItemClickListener | ||
} | ||
|
||
override fun submitList(list: List<SearchDiary>?) { | ||
list?.let { | ||
val filteredList = it.distinctBy { diary -> diary.diaryId } | ||
super.submitList(filteredList) | ||
} ?: super.submitList(null) | ||
} | ||
} |
Oops, something went wrong.