Skip to content

Commit

Permalink
Merge pull request #107 from TeamPhotoSurfer/feat/detail_image
Browse files Browse the repository at this point in the history
[feat] detail_image / 시연으로 인한 중간 pull request (#90)
  • Loading branch information
2chang5 authored Jul 23, 2022
2 parents d629757 + 2ad90d1 commit 688851b
Show file tree
Hide file tree
Showing 26 changed files with 786 additions and 9 deletions.
4 changes: 4 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -84,5 +84,9 @@
<activity
android:name=".alarm_list.eachinfo.AlarmSpecificImageActivity"
android:exported="false" />

<activity
android:name=".search_result.detailimage.DetailImageActivity"
android:exported="false" />
</application>
</manifest>
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,8 @@ interface RemoteDataSourceModule {
@Binds
@Singleton
fun bindsRemoteSearchResultDataSource(source: RemoteSearchTagResultDataSourceImpl): RemoteSearchTagResultDataSource

@Binds
@Singleton
fun bindsRemoteImageDataSource(source: RemoteImageDataSourceImpl): RemoteImageDataSource
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ interface RepositoryModule {
@Singleton
fun bindsTagListRepository(repository: TagListRepositoryImpl): TagListRepository

@Binds
@Singleton
fun bindsImageRepository(repository: ImageRepositoryImpl): ImageRepository

@Binds
@Singleton
fun bindsSearchResultRepository(repository: PhotoRepositoryImpl): PhotoRepository
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,15 @@ object RetrofitServiceModule {

@Provides
@Singleton
fun providesDetailImageService(retrofit: Retrofit): DetailImageService =
retrofit.create(DetailImageService::class.java)

@Provides
@Singleton
fun providesDeleteImageService(retrofit: Retrofit): DeleteImageService =
retrofit.create(DeleteImageService::class.java)
@Provides
@Singleton
fun providesSearchTagResultService(retrofit: Retrofit): SearchTagResultService =
retrofit.create(SearchTagResultService::class.java)

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.photosurfer.android.data.remote.datasource

import com.photosurfer.android.data.remote.calladapter.NetworkState
import com.photosurfer.android.data.remote.model.response.BaseResponse
import com.photosurfer.android.data.remote.model.response.DetailImageResponse
import com.photosurfer.android.data.remote.model.response.NoDataResponse

interface RemoteImageDataSource {

suspend fun getDetailImageInfo(photoId: Int): NetworkState<BaseResponse<DetailImageResponse>>

suspend fun deleteImage(options: Map<String, Int>): NetworkState<NoDataResponse>
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.photosurfer.android.data.remote.datasource

import com.photosurfer.android.data.remote.calladapter.NetworkState
import com.photosurfer.android.data.remote.model.response.BaseResponse
import com.photosurfer.android.data.remote.model.response.DetailImageResponse
import com.photosurfer.android.data.remote.model.response.NoDataResponse
import com.photosurfer.android.data.remote.service.DeleteImageService
import com.photosurfer.android.data.remote.service.DetailImageService
import javax.inject.Inject

class RemoteImageDataSourceImpl @Inject constructor(
private val detailImageService: DetailImageService,
private val deleteImageService: DeleteImageService
) : RemoteImageDataSource {

override suspend fun getDetailImageInfo(photoId: Int): NetworkState<BaseResponse<DetailImageResponse>> =
detailImageService.getDetailImageInfo(photoId)

override suspend fun deleteImage(options: Map<String, Int>): NetworkState<NoDataResponse> =
deleteImageService.deleteImage(options)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.photosurfer.android.data.remote.mapper

import com.photosurfer.android.data.remote.model.response.DetailImageResponse
import com.photosurfer.android.domain.entity.DetailImageInfo
import javax.inject.Inject

class ImageMapper @Inject constructor() {

fun toDetailImageInfo(detailImageResponse: DetailImageResponse): DetailImageInfo =
DetailImageInfo(
photoId = detailImageResponse.id,
imageUrl = detailImageResponse.imageUrl,
tagList = detailImageResponse.tags
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.photosurfer.android.data.remote.model.response

import com.google.gson.annotations.SerializedName
import com.photosurfer.android.domain.entity.TagInfo

data class DetailImageResponse(
@SerializedName("id")
val id: Int,
@SerializedName("imageUrl")
val imageUrl: String,
@SerializedName("push")
val push: Int,
@SerializedName("tags")
val tags: List<TagInfo>
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.photosurfer.android.data.remote.model.response


import com.google.gson.annotations.SerializedName

data class NoDataResponse(
@SerializedName("message")
val message: String,
@SerializedName("status")
val status: Int,
@SerializedName("success")
val success: Boolean
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.photosurfer.android.data.remote.service

import com.photosurfer.android.data.remote.calladapter.NetworkState
import com.photosurfer.android.data.remote.model.response.BaseResponse
import com.photosurfer.android.data.remote.model.response.NoDataResponse
import retrofit2.http.PUT
import retrofit2.http.QueryMap

interface DeleteImageService {
@PUT("photo")
suspend fun deleteImage(
@QueryMap options: Map<String, Int>
): NetworkState<NoDataResponse>
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.photosurfer.android.data.remote.service

import com.photosurfer.android.data.remote.calladapter.NetworkState
import com.photosurfer.android.data.remote.model.response.BaseResponse
import com.photosurfer.android.data.remote.model.response.DetailImageResponse
import retrofit2.http.GET
import retrofit2.http.Path

interface DetailImageService {
@GET("photo/detail/{photoId}")
suspend fun getDetailImageInfo(
@Path("photoId") photoId: Int
): NetworkState<BaseResponse<DetailImageResponse>>
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
package com.photosurfer.android.data.repository

import com.photosurfer.android.core.exception.RetrofitFailureStateException
import com.photosurfer.android.data.remote.calladapter.NetworkState
import com.photosurfer.android.data.remote.datasource.RemoteImageDataSource
import com.photosurfer.android.data.remote.mapper.ImageMapper
import com.photosurfer.android.data.remote.model.request.ChooseTagRequest
import com.photosurfer.android.domain.entity.DetailImageInfo
import com.photosurfer.android.domain.repository.ImageRepository
import timber.log.Timber
import javax.inject.Inject

class ImageRepositoryImpl @Inject constructor(
private val remoteImageDataSource: RemoteImageDataSource,
private val imageMapper: ImageMapper
) : ImageRepository {

override suspend fun getDetailImageInfo(photoId: Int): Result<DetailImageInfo> {
when (
val response = remoteImageDataSource.getDetailImageInfo(photoId)
) {
is NetworkState.Success -> return Result.success(
imageMapper.toDetailImageInfo(response.body.data)
)
is NetworkState.Failure -> return Result.failure(
RetrofitFailureStateException(
response.error,
response.code
)
)
is NetworkState.NetworkError -> Timber.d(
response.error,
"${this.javaClass.name}_getDetailImageInfo"
)
is NetworkState.UnknownError -> Timber.d(
response.t,
"${this.javaClass.name}_getDetailImageInfo"
)
}
return Result.failure(IllegalStateException("NetworkError or UnKnownError please check timber"))
}

override suspend fun deleteImage(options: Map<String, Int>): Result<String> {
when (
val response = remoteImageDataSource.deleteImage(options)
) {
is NetworkState.Success -> return Result.success(
response.body.message
)
is NetworkState.Failure -> return Result.failure(
RetrofitFailureStateException(
response.error,
response.code
)
)
is NetworkState.NetworkError -> Timber.d(
response.error,
"${this.javaClass.name}_deleteImage"
)
is NetworkState.UnknownError -> Timber.d(
response.t,
"${this.javaClass.name}_deleteImage"
)
}
return Result.failure(IllegalStateException("NetworkError or UnKnownError please check timber"))
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.photosurfer.android.domain.entity

data class DetailImageInfo(
val photoId: Int,
val imageUrl: String,
val tagList: List<TagInfo>
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.photosurfer.android.domain.repository

import com.photosurfer.android.domain.entity.DetailImageInfo

interface ImageRepository {

suspend fun getDetailImageInfo(photoId: Int): Result<DetailImageInfo>

suspend fun deleteImage(options: Map<String, Int>): Result<String>
}
Original file line number Diff line number Diff line change
Expand Up @@ -223,9 +223,9 @@
android:layout_height="48dp"
android:layout_marginTop="8dp"
android:background="@drawable/shape_rect_sub_fill_8"
android:stateListAnimator="@null"
android:text="@string/empty_view_button"
android:textColor="@color/main"
android:stateListAnimator="@null"
android:visibility="@{urgentAlarm == 0 ? View.VISIBLE : View.GONE}"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="@+id/tv_empty_text"
Expand All @@ -239,6 +239,7 @@
android:layout_height="0dp"
android:clipToPadding="false"
android:paddingBottom="32dp"
android:visibility="@{urgentAlarm == 0 ? View.GONE : View.VISIBLE}"
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintTop_toBottomOf="@+id/layout_gradient_background"
Expand Down
3 changes: 3 additions & 0 deletions feature/search-result/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<manifest>
<application></application>
</manifest>
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
package com.photosurfer.android.search_result

import android.content.ContentValues.TAG
import android.content.Context
import android.content.Intent
import android.os.Bundle
import android.util.Log
import android.view.Gravity
import android.widget.PopupMenu
import androidx.activity.viewModels
Expand All @@ -17,6 +16,7 @@ import com.photosurfer.android.domain.entity.SerializeTagInfoList
import com.photosurfer.android.domain.entity.TagInfo
import com.photosurfer.android.domain.entity.ThumbnailInfo
import com.photosurfer.android.search_result.databinding.ActivitySearchResultBinding
import com.photosurfer.android.search_result.detailimage.DetailImageActivity
import com.photosurfer.android.search_result.viewModel.SearchResultViewModel
import com.photosurfer.android.shared.R.style
import dagger.hilt.android.AndroidEntryPoint
Expand Down Expand Up @@ -160,11 +160,12 @@ class SearchResultActivity :
private fun onItemClick(thumbnail: ThumbnailInfo, position: Int) {
when (binding.currentViewType ?: TagResultViewType.DEFAULT) {
TagResultViewType.DEFAULT -> {
// TODO 창환~~ 미정이뷰 Navigate 로직 넣어조
val thumbnailId: Int =
viewModel.thumbnailList.value?.get(position)?.id
?: throw IllegalStateException()
Log.d(TAG, "onItemClick: $thumbnailId")
viewModel.thumbnail.value?.get(position)?.id ?: throw IllegalStateException()
val intent = Intent(this, DetailImageActivity::class.java).apply {
putExtra(PHOTO_ID, thumbnailId)
}
startActivity(intent)
}
TagResultViewType.SELECT -> {
thumbnail.isChecked = !thumbnail.isChecked
Expand Down Expand Up @@ -202,11 +203,16 @@ class SearchResultActivity :
popupMenu.show()
}
}

override fun onBackPressed() {
val viewType = binding.currentViewType
if (viewType == TagResultViewType.DEFAULT)
super.onBackPressed()
else doOnCancelClicked()
}
}

companion object {
const val PHOTO_ID = "PHOTO_ID"
}

}
Loading

0 comments on commit 688851b

Please sign in to comment.