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

Extract ImageDetail, VideoDetail to core:model #80

Merged
merged 1 commit into from
Jan 17, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
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