Skip to content

Commit

Permalink
Merge pull request #80 from azrael8576/refactor/core-data
Browse files Browse the repository at this point in the history
Extract ImageDetail, VideoDetail to core:model
  • Loading branch information
azrael8576 authored Jan 17, 2024
2 parents 3f3138a + 0fdff19 commit 17eaf50
Show file tree
Hide file tree
Showing 13 changed files with 74 additions and 68 deletions.
Original file line number Diff line number Diff line change
@@ -1,33 +1,8 @@
package com.wei.picquest.core.data.model

import com.wei.picquest.core.model.data.ImageDetail
import com.wei.picquest.core.network.model.NetworkImageDetail

data class ImageDetail(
val id: Int,
val pageURL: String,
val type: String,
val tags: String,
val previewURL: String,
val previewWidth: Int,
val previewHeight: Int,
val webformatURL: String,
val webformatWidth: Int,
val webformatHeight: Int,
val largeImageURL: String,
val imageWidth: Int,
val imageHeight: Int,
val imageSize: Long,
val views: Int,
val downloads: Int,
val likes: Int,
val comments: Int,
val userId: Int,
val user: String,
val userImageURL: String,
) {
val aspectRatio get() = imageWidth.toFloat() / imageHeight.toFloat()
}

fun NetworkImageDetail.asExternalModel() = ImageDetail(
id = this.id,
pageURL = this.pageURL,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,40 +1,12 @@
package com.wei.picquest.core.data.model

import com.wei.picquest.core.model.data.VideoDetail
import com.wei.picquest.core.model.data.VideoDetailSize
import com.wei.picquest.core.model.data.VideoStreams
import com.wei.picquest.core.network.model.NetworkVideoDetail
import com.wei.picquest.core.network.model.NetworkVideoDetailSize
import com.wei.picquest.core.network.model.NetworkVideoStreams

data class VideoDetail(
val id: Int,
val pageURL: String,
val type: String,
val tags: String,
val duration: Int,
val pictureId: String,
val videos: VideoStreams,
val views: Int,
val downloads: Int,
val likes: Int,
val comments: Int,
val userId: Int,
val user: String,
val userImageURL: String,
)

data class VideoStreams(
val large: VideoDetailSize,
val medium: VideoDetailSize,
val small: VideoDetailSize,
val tiny: VideoDetailSize,
)

data class VideoDetailSize(
val url: String,
val width: Int,
val height: Int,
val size: Long,
)

fun NetworkVideoDetail.asExternalModel() = VideoDetail(
id = this.id,
pageURL = this.pageURL,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import androidx.paging.Pager
import androidx.paging.PagingConfig
import androidx.paging.PagingData
import androidx.paging.map
import com.wei.picquest.core.data.model.ImageDetail
import com.wei.picquest.core.data.model.asExternalModel
import com.wei.picquest.core.model.data.ImageDetail
import com.wei.picquest.core.network.PqNetworkDataSource
import com.wei.picquest.core.network.pagingsource.PixabayImagePagingSource
import kotlinx.coroutines.flow.Flow
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import androidx.paging.Pager
import androidx.paging.PagingConfig
import androidx.paging.PagingData
import androidx.paging.map
import com.wei.picquest.core.data.model.VideoDetail
import com.wei.picquest.core.data.model.asExternalModel
import com.wei.picquest.core.model.data.VideoDetail
import com.wei.picquest.core.network.PqNetworkDataSource
import com.wei.picquest.core.network.pagingsource.PixabayVideoPagingSource
import kotlinx.coroutines.flow.Flow
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.wei.picquest.core.data.repository

import androidx.paging.PagingData
import com.wei.picquest.core.data.model.ImageDetail
import com.wei.picquest.core.model.data.ImageDetail
import kotlinx.coroutines.flow.Flow

interface SearchImagesRepository {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.wei.picquest.core.data.repository

import androidx.paging.PagingData
import com.wei.picquest.core.data.model.VideoDetail
import com.wei.picquest.core.model.data.VideoDetail
import kotlinx.coroutines.flow.Flow

interface SearchVideosRepository {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package com.wei.picquest.core.model.data

data class ImageDetail(
val id: Int,
val pageURL: String,
val type: String,
val tags: String,
val previewURL: String,
val previewWidth: Int,
val previewHeight: Int,
val webformatURL: String,
val webformatWidth: Int,
val webformatHeight: Int,
val largeImageURL: String,
val imageWidth: Int,
val imageHeight: Int,
val imageSize: Long,
val views: Int,
val downloads: Int,
val likes: Int,
val comments: Int,
val userId: Int,
val user: String,
val userImageURL: String,
) {
val aspectRatio get() = imageWidth.toFloat() / imageHeight.toFloat()
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package com.wei.picquest.core.model.data

data class VideoDetail(
val id: Int,
val pageURL: String,
val type: String,
val tags: String,
val duration: Int,
val pictureId: String,
val videos: VideoStreams,
val views: Int,
val downloads: Int,
val likes: Int,
val comments: Int,
val userId: Int,
val user: String,
val userImageURL: String,
)

data class VideoStreams(
val large: VideoDetailSize,
val medium: VideoDetailSize,
val small: VideoDetailSize,
val tiny: VideoDetailSize,
)

data class VideoDetailSize(
val url: String,
val width: Int,
val height: Int,
val size: Long,
)
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,13 @@ import androidx.paging.compose.collectAsLazyPagingItems
import coil.compose.AsyncImagePainter
import coil.compose.SubcomposeAsyncImage
import coil.compose.SubcomposeAsyncImageContent
import com.wei.picquest.core.data.model.ImageDetail
import com.wei.picquest.core.designsystem.component.coilImagePainter
import com.wei.picquest.core.designsystem.icon.PqIcons
import com.wei.picquest.core.designsystem.theme.PqTheme
import com.wei.picquest.core.designsystem.theme.SPACING_LARGE
import com.wei.picquest.core.designsystem.theme.SPACING_MEDIUM
import com.wei.picquest.core.designsystem.theme.SPACING_SMALL
import com.wei.picquest.core.model.data.ImageDetail
import com.wei.picquest.feature.photo.R
import com.wei.picquest.feature.photo.photolibrary.component.LayoutSwitchWarningDialog
import com.wei.picquest.feature.photo.photolibrary.data.fake.fakeImageDetails
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import androidx.lifecycle.viewModelScope
import androidx.paging.PagingData
import androidx.paging.cachedIn
import com.wei.picquest.core.base.BaseViewModel
import com.wei.picquest.core.data.model.ImageDetail
import com.wei.picquest.core.data.repository.SearchImagesRepository
import com.wei.picquest.core.model.data.ImageDetail
import com.wei.picquest.feature.photo.photolibrary.navigation.PhotoLibraryArgs
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.flow.MutableStateFlow
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.wei.picquest.feature.photo.photolibrary.data.fake

import com.wei.picquest.core.data.model.ImageDetail
import com.wei.picquest.core.model.data.ImageDetail

val fakeImageDetails = listOf(
ImageDetail(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,15 +63,15 @@ import androidx.paging.compose.LazyPagingItems
import androidx.paging.compose.collectAsLazyPagingItems
import coil.compose.AsyncImage
import coil.request.ImageRequest
import com.wei.picquest.core.data.model.VideoDetail
import com.wei.picquest.core.data.model.VideoDetailSize
import com.wei.picquest.core.data.model.VideoStreams
import com.wei.picquest.core.designsystem.component.ThemePreviews
import com.wei.picquest.core.designsystem.component.coilImagePainter
import com.wei.picquest.core.designsystem.icon.PqIcons
import com.wei.picquest.core.designsystem.theme.PqTheme
import com.wei.picquest.core.designsystem.theme.SPACING_MEDIUM
import com.wei.picquest.core.designsystem.theme.SPACING_SMALL
import com.wei.picquest.core.model.data.VideoDetail
import com.wei.picquest.core.model.data.VideoDetailSize
import com.wei.picquest.core.model.data.VideoStreams
import com.wei.picquest.core.pip.enterPictureInPicture
import com.wei.picquest.core.pip.isInPictureInPictureMode
import com.wei.picquest.core.pip.updatedPipParams
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import androidx.lifecycle.viewModelScope
import androidx.paging.PagingData
import androidx.paging.cachedIn
import com.wei.picquest.core.base.BaseViewModel
import com.wei.picquest.core.data.model.VideoDetail
import com.wei.picquest.core.data.repository.SearchVideosRepository
import com.wei.picquest.core.model.data.VideoDetail
import com.wei.picquest.feature.video.videolibrary.navigation.VideoLibraryArgs
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.flow.MutableStateFlow
Expand Down

0 comments on commit 17eaf50

Please sign in to comment.