-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #17 from CaZaIt/feature/16-home-ui
[#16] home UI
- Loading branch information
Showing
49 changed files
with
1,118 additions
and
25 deletions.
There are no files selected for viewing
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
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
47 changes: 47 additions & 0 deletions
47
...stem/src/main/kotlin/org/cazait/cazaitandroid/core/designsystem/component/NetworkImage.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,47 @@ | ||
package org.cazait.cazaitandroid.core.designsystem.component | ||
|
||
import androidx.compose.runtime.Composable | ||
import androidx.compose.ui.Alignment | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.graphics.Color | ||
import androidx.compose.ui.graphics.painter.Painter | ||
import androidx.compose.ui.graphics.toArgb | ||
import androidx.compose.ui.layout.ContentScale | ||
import androidx.compose.ui.res.painterResource | ||
import androidx.compose.ui.tooling.preview.Preview | ||
import com.skydoves.landscapist.ImageOptions | ||
import com.skydoves.landscapist.coil.CoilImage | ||
import com.skydoves.landscapist.components.rememberImageComponent | ||
import com.skydoves.landscapist.placeholder.placeholder.PlaceholderPlugin | ||
|
||
@Composable | ||
fun NetworkImage( | ||
imageUrl: String?, | ||
modifier: Modifier = Modifier, | ||
placeholder: Painter? = null, | ||
contentScale: ContentScale = ContentScale.Crop, | ||
contentDescription: String? = null, | ||
) { | ||
CoilImage( | ||
imageModel = { imageUrl }, | ||
modifier = modifier, | ||
component = rememberImageComponent { | ||
+PlaceholderPlugin.Loading(placeholder) | ||
+PlaceholderPlugin.Failure(placeholder) | ||
}, | ||
imageOptions = ImageOptions( | ||
contentScale = contentScale, | ||
alignment = Alignment.Center, | ||
contentDescription = contentDescription, | ||
) | ||
) | ||
} | ||
|
||
@Preview | ||
@Composable | ||
private fun PreviewNetworkImage() { | ||
NetworkImage( | ||
imageUrl = "", | ||
placeholder = painterResource(id = Color(0xFFFFFFFF).toArgb()) | ||
) | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
plugins { | ||
id("cazait.android.library") | ||
id("cazait.android.hilt") | ||
id("kotlinx-serialization") | ||
} | ||
|
||
android { | ||
namespace = "org.cazait.cazaitandroid.core.location" | ||
defaultConfig { | ||
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" | ||
} | ||
} | ||
|
||
dependencies { | ||
implementation(libs.play.services.location) | ||
|
||
androidTestImplementation(libs.androidx.test.ext) | ||
androidTestImplementation(libs.androidx.test.espresso.core) | ||
androidTestImplementation(libs.coroutines.test) | ||
} |
3 changes: 3 additions & 0 deletions
3
core/location/src/main/kotlin/org/cazait/cazaitandroid/core/location/LocationDetails.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,3 @@ | ||
package org.cazait.cazaitandroid.core.location | ||
|
||
data class LocationDetails(val latitude: Double, val longitude: Double) |
55 changes: 55 additions & 0 deletions
55
core/location/src/main/kotlin/org/cazait/cazaitandroid/core/location/LocationService.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,55 @@ | ||
package org.cazait.cazaitandroid.core.location | ||
|
||
import android.annotation.SuppressLint | ||
import android.content.Context | ||
import android.os.Looper | ||
import com.google.android.gms.location.FusedLocationProviderClient | ||
import com.google.android.gms.location.LocationCallback | ||
import com.google.android.gms.location.LocationRequest | ||
import com.google.android.gms.location.LocationResult | ||
import com.google.android.gms.location.Priority | ||
import kotlinx.coroutines.channels.awaitClose | ||
import kotlinx.coroutines.flow.Flow | ||
import kotlinx.coroutines.flow.callbackFlow | ||
import org.cazait.cazaitandroid.core.location.extension.hasLocationPermission | ||
import javax.inject.Inject | ||
|
||
interface LocationService { | ||
fun requestLocationUpdates(): Flow<LocationDetails?> | ||
} | ||
|
||
internal class LocationServiceImpl @Inject constructor( | ||
private val context: Context, | ||
private val locationClient: FusedLocationProviderClient, | ||
) : LocationService { | ||
@SuppressLint("MissingPermission") | ||
override fun requestLocationUpdates(): Flow<LocationDetails?> = callbackFlow { | ||
if (!context.hasLocationPermission()) { | ||
trySend(null) | ||
return@callbackFlow | ||
} | ||
|
||
val request = LocationRequest.Builder(10000L) | ||
.setIntervalMillis(10000L) | ||
.setPriority(Priority.PRIORITY_HIGH_ACCURACY) | ||
.build() | ||
|
||
val locationCallback = object : LocationCallback() { | ||
override fun onLocationResult(locationResult: LocationResult) { | ||
locationResult.locations.lastOrNull()?.let { | ||
trySend(LocationDetails(latitude = it.latitude, longitude = it.longitude)) | ||
} | ||
} | ||
} | ||
|
||
locationClient.requestLocationUpdates( | ||
request, | ||
locationCallback, | ||
Looper.getMainLooper() | ||
) | ||
|
||
awaitClose { | ||
locationClient.removeLocationUpdates(locationCallback) | ||
} | ||
} | ||
} |
40 changes: 40 additions & 0 deletions
40
core/location/src/main/kotlin/org/cazait/cazaitandroid/core/location/di/LocationModule.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,40 @@ | ||
package org.cazait.cazaitandroid.core.location.di | ||
|
||
import android.content.Context | ||
import com.google.android.gms.location.LocationServices | ||
import dagger.Binds | ||
import dagger.Module | ||
import dagger.Provides | ||
import dagger.hilt.InstallIn | ||
import dagger.hilt.android.components.ViewModelComponent | ||
import dagger.hilt.android.qualifiers.ApplicationContext | ||
import dagger.hilt.android.scopes.ViewModelScoped | ||
import dagger.hilt.components.SingletonComponent | ||
import org.cazait.cazaitandroid.core.location.LocationService | ||
import org.cazait.cazaitandroid.core.location.LocationServiceImpl | ||
import org.cazait.cazaitandroid.core.location.usecase.GetLocationUseCase | ||
import org.cazait.cazaitandroid.core.location.usecase.GetLocationUseCaseImpl | ||
import javax.inject.Singleton | ||
|
||
@Module | ||
@InstallIn(SingletonComponent::class) | ||
internal object LocationModule { | ||
@Singleton | ||
@Provides | ||
fun provideLocationClient( | ||
@ApplicationContext context: Context, | ||
): LocationService = LocationServiceImpl( | ||
context = context, | ||
locationClient = LocationServices.getFusedLocationProviderClient(context) | ||
) | ||
} | ||
|
||
@Module | ||
@InstallIn(ViewModelComponent::class) | ||
internal abstract class UseCaseBindModule { | ||
@Binds | ||
@ViewModelScoped | ||
abstract fun bindGetLocationUseCase( | ||
dataSource: GetLocationUseCaseImpl, | ||
): GetLocationUseCase | ||
} |
19 changes: 19 additions & 0 deletions
19
...src/main/kotlin/org/cazait/cazaitandroid/core/location/extension/hasLocationPermission.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,19 @@ | ||
package org.cazait.cazaitandroid.core.location.extension | ||
|
||
import android.Manifest | ||
import android.content.Context | ||
import android.content.pm.PackageManager | ||
import androidx.core.content.ContextCompat | ||
|
||
fun Context.hasLocationPermission(): Boolean { | ||
val fineLocationGranted = ContextCompat.checkSelfPermission( | ||
this, | ||
Manifest.permission.ACCESS_FINE_LOCATION | ||
) == PackageManager.PERMISSION_GRANTED | ||
val coarseLocationGranted = ContextCompat.checkSelfPermission( | ||
this, | ||
Manifest.permission.ACCESS_COARSE_LOCATION | ||
) == PackageManager.PERMISSION_GRANTED | ||
|
||
return fineLocationGranted && coarseLocationGranted | ||
} |
16 changes: 16 additions & 0 deletions
16
...tion/src/main/kotlin/org/cazait/cazaitandroid/core/location/usecase/GetLocationUseCase.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,16 @@ | ||
package org.cazait.cazaitandroid.core.location.usecase | ||
|
||
import kotlinx.coroutines.flow.Flow | ||
import org.cazait.cazaitandroid.core.location.LocationDetails | ||
import org.cazait.cazaitandroid.core.location.LocationService | ||
import javax.inject.Inject | ||
|
||
interface GetLocationUseCase { | ||
operator fun invoke(): Flow<LocationDetails?> | ||
} | ||
|
||
internal class GetLocationUseCaseImpl @Inject constructor( | ||
private val locationService: LocationService, | ||
) : GetLocationUseCase { | ||
override fun invoke(): Flow<LocationDetails?> = locationService.requestLocationUpdates() | ||
} |
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 @@ | ||
plugins { | ||
id("cazait.coroutine.library") | ||
id("kotlinx-serialization") | ||
} | ||
|
||
dependencies { | ||
api(libs.kotlinx.datetime) | ||
implementation(libs.kotlinx.serialization.json) | ||
} |
16 changes: 16 additions & 0 deletions
16
...po/home/api/src/main/kotlin/org/cazait/cazaitandroid/core/repo/home/api/HomeRepository.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,16 @@ | ||
package org.cazait.cazaitandroid.core.repo.home.api | ||
|
||
import org.cazait.cazaitandroid.core.repo.home.api.model.CongestionCafes | ||
import org.cazait.cazaitandroid.core.repo.home.api.model.DistanceLimit | ||
import org.cazait.cazaitandroid.core.repo.home.api.model.Latitude | ||
import org.cazait.cazaitandroid.core.repo.home.api.model.Longitude | ||
import org.cazait.cazaitandroid.core.repo.home.api.model.SortBy | ||
|
||
interface HomeRepository { | ||
suspend fun getAllCongestionCafes( | ||
latitude: Latitude, | ||
longitude: Longitude, | ||
sort: SortBy, | ||
limit: DistanceLimit, | ||
): CongestionCafes | ||
} |
15 changes: 15 additions & 0 deletions
15
core/repo/home/api/src/main/kotlin/org/cazait/cazaitandroid/core/repo/home/api/model/Cafe.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,15 @@ | ||
package org.cazait.cazaitandroid.core.repo.home.api.model | ||
|
||
data class Cafe( | ||
val id: CafeId, | ||
val name: CafeName, | ||
val address: CafeAddress, | ||
val cafeImages: CafeImages, | ||
val latitude: Latitude, | ||
val longitude: Longitude, | ||
) | ||
|
||
@JvmInline | ||
value class Cafes(private val values: List<Cafe>) { | ||
fun asList(): List<Cafe> = values | ||
} |
6 changes: 6 additions & 0 deletions
6
...home/api/src/main/kotlin/org/cazait/cazaitandroid/core/repo/home/api/model/CafeAddress.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,6 @@ | ||
package org.cazait.cazaitandroid.core.repo.home.api.model | ||
|
||
@JvmInline | ||
value class CafeAddress(private val address: String) { | ||
fun asString(): String = address | ||
} |
8 changes: 8 additions & 0 deletions
8
...repo/home/api/src/main/kotlin/org/cazait/cazaitandroid/core/repo/home/api/model/CafeId.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,8 @@ | ||
package org.cazait.cazaitandroid.core.repo.home.api.model | ||
|
||
import java.util.UUID | ||
|
||
@JvmInline | ||
value class CafeId(private val id: UUID) { | ||
fun asUUID(): UUID = id | ||
} |
6 changes: 6 additions & 0 deletions
6
...o/home/api/src/main/kotlin/org/cazait/cazaitandroid/core/repo/home/api/model/CafeImage.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,6 @@ | ||
package org.cazait.cazaitandroid.core.repo.home.api.model | ||
|
||
@JvmInline | ||
value class CafeImage(private val url: String) { | ||
fun asString(): String = url | ||
} |
6 changes: 6 additions & 0 deletions
6
.../home/api/src/main/kotlin/org/cazait/cazaitandroid/core/repo/home/api/model/CafeImages.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,6 @@ | ||
package org.cazait.cazaitandroid.core.repo.home.api.model | ||
|
||
@JvmInline | ||
value class CafeImages(private val images: List<CafeImage>) { | ||
fun asList(): List<CafeImage> = images | ||
} |
6 changes: 6 additions & 0 deletions
6
...po/home/api/src/main/kotlin/org/cazait/cazaitandroid/core/repo/home/api/model/CafeName.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,6 @@ | ||
package org.cazait.cazaitandroid.core.repo.home.api.model | ||
|
||
@JvmInline | ||
value class CafeName(private val name: String) { | ||
fun asString(): String = name | ||
} |
13 changes: 13 additions & 0 deletions
13
...e/api/src/main/kotlin/org/cazait/cazaitandroid/core/repo/home/api/model/CongestionCafe.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 org.cazait.cazaitandroid.core.repo.home.api.model | ||
|
||
data class CongestionCafe( | ||
val cafe: Cafe, | ||
val congestion: Congestion, | ||
) | ||
|
||
@JvmInline | ||
value class CongestionCafes(private val values: List<CongestionCafe>) { | ||
fun asList(): List<CongestionCafe> = values | ||
} | ||
|
||
enum class Congestion { FREE, NORMAL, CLOSE, CROWDED, VERY_CROWDED } |
Oops, something went wrong.