Skip to content

Commit

Permalink
Merge pull request #15 from hi-manshu/develop
Browse files Browse the repository at this point in the history
Merge develop in Main
  • Loading branch information
hi-manshu committed Jul 19, 2022
2 parents 1ccbf7c + 887a40a commit b630b4b
Show file tree
Hide file tree
Showing 16 changed files with 139 additions and 128 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

![Pluck](art/pluck.jpg)

This is an image-picker for your jetpack compose project. You can select from Gallery/Camera.
This is an image-picker for your jetpack compose project. You can select from Gallery/Camera. This uses Material you and will be getting support for it in future as well.

_Made with ❤️ for Android Developers by Himanshu_

Expand Down Expand Up @@ -30,7 +30,7 @@ In `build.gradle` of app module, include the following dependency

```gradle
dependencies {
implementation("com.himanshoe:pluck:1.0.0-RC1")
implementation("com.himanshoe:pluck:1.0.0-RC2")
}
```

Expand Down
4 changes: 2 additions & 2 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,10 @@ android {

dependencies {
// implementation(project(":pluck"))
implementation("com.himanshoe:pluck:1.0.0-RC1")
implementation("com.himanshoe:pluck:1.0.0-RC2")

implementation(Deps.Compose.ui)
implementation(Deps.Compose.material)
implementation(Deps.Compose.materialYou)
implementation(Deps.Compose.uiToolingPreview)
implementation(Deps.Compose.activity)

Expand Down
3 changes: 2 additions & 1 deletion app/src/main/java/com/himanshoe/app/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ class MainActivity : ComponentActivity() {
),
goToAppSettings = { goToAppSettings() }
) {
Pluck(pluckConfiguration = PluckConfiguration(true),
Pluck(
pluckConfiguration = PluckConfiguration(true),
onPhotoSelected = {
}
)
Expand Down
2 changes: 2 additions & 0 deletions buildSrc/src/main/kotlin/Dependencies.kt
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ object Deps {
val activity by lazy { "androidx.activity:activity-compose:${Versions.activity}" }
val viewmodel by lazy { "androidx.lifecycle:lifecycle-viewmodel-compose:1.0.0-alpha07" }
val paging by lazy { "androidx.paging:paging-compose:1.0.0-alpha14" }
val materialYou by lazy { "androidx.compose.material3:material3:1.0.0-alpha14" }

}

object Accompanist {
Expand Down
4 changes: 2 additions & 2 deletions buildSrc/src/main/kotlin/ModuleExtension.kt
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
object ModuleExtension {
const val compileSdkVersion = 31
const val compileSdkVersion = 32
const val jvmTarget = "1.8"

object DefaultConfigs {
const val minSdkVersion = 21
const val targetSdkVersion = 31
const val targetSdkVersion = 32
const val testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
const val defaultConsumerProguardFiles = "consumer-rules.pro"
const val proGuardRules = "proguard-rules.pro"
Expand Down
6 changes: 3 additions & 3 deletions buildSrc/src/main/kotlin/Versions.kt
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
object Versions {
const val compose = "1.0.5"
const val compose = "1.1.1"
const val androidGradlePlugin = "7.0.3"
const val vanniktechGradlePlugin = "0.18.0"
const val kotlin = "1.5.31"
const val kotlin = "1.6.10"
const val activity = "1.3.1"
const val material = "1.4.0"
const val material = "1.0.0-alpha14"
const val jUnit = "4.13.2"
const val jUnitExtensions = "1.1.3"
const val espresso = "3.4.0"
Expand Down
2 changes: 1 addition & 1 deletion pluck/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ android {

dependencies {
implementation(Deps.Compose.ui)
implementation(Deps.Compose.material)
implementation(Deps.Compose.materialYou)
implementation(Deps.Compose.uiToolingPreview)
implementation(Deps.Compose.activity)
implementation(Deps.Compose.paging)
Expand Down
2 changes: 1 addition & 1 deletion pluck/gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ POM_DESCRIPTION=A Compose Image Picker.
POM_PACKAGING=aar
POM_INCEPTION_YEAR=2022
GROUP=com.himanshoe
VERSION_NAME=1.0.0-RC1
VERSION_NAME=1.0.0-RC2
VERSION_CODE=1
POM_URL=https://github.com/hi-manshu
POM_LICENCE_NAME=The Apache Software License, Version 2.0
Expand Down
14 changes: 9 additions & 5 deletions pluck/src/main/java/com/himanshoe/pluck/data/PluckDataSource.kt
Original file line number Diff line number Diff line change
Expand Up @@ -25,21 +25,25 @@ package com.himanshoe.pluck.data
import androidx.paging.PagingSource
import androidx.paging.PagingState

private const val Zero = 0
private const val One = 1

class PluckDataSource(private val onFetch: (limit: Int, offset: Int) -> List<PluckImage>) :
PagingSource<Int, PluckImage>() {

override fun getRefreshKey(state: PagingState<Int, PluckImage>): Int? {
return state.anchorPosition?.let {
state.closestPageToPosition(it)?.prevKey?.plus(1)
?: state.closestPageToPosition(it)?.nextKey?.minus(1)
state.closestPageToPosition(it)?.prevKey?.plus(One)
?: state.closestPageToPosition(it)?.nextKey?.minus(One)
}
}

override suspend fun load(params: LoadParams<Int>): LoadResult<Int, PluckImage> {
val pageNumber = params.key ?: 0
val pageNumber = params.key ?: Zero
val pageSize = params.loadSize
val pictures = onFetch.invoke(pageSize, pageNumber * pageSize)
val prevKey = if (pageNumber > 0) pageNumber - 1 else null
val nextKey = if (pictures.isNotEmpty()) pageNumber + 1 else null
val prevKey = if (pageNumber > Zero) pageNumber.minus(One) else null
val nextKey = if (pictures.isNotEmpty()) pageNumber.plus(One) else null

return LoadResult.Page(
data = pictures,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ import androidx.paging.PagingSource
import com.himanshoe.pluck.util.createCursor
import com.himanshoe.pluck.util.fetchPagePicture

private const val Zero = 0
private const val One = 1

internal interface PluckRepository {
suspend fun getCount(): Int
suspend fun getByOffset(offset: Int): PluckImage?
Expand All @@ -36,14 +39,14 @@ internal interface PluckRepository {
internal class PluckRepositoryImpl(private val context: Context) : PluckRepository {

override suspend fun getCount(): Int {
val cursor = context.createCursor(Int.MAX_VALUE, 0) ?: return 0
val cursor = context.createCursor(Int.MAX_VALUE, Zero) ?: return Zero
val count = cursor.count
cursor.close()
return count
}

override suspend fun getByOffset(offset: Int): PluckImage? {
return context.fetchPagePicture(1, offset).firstOrNull()
return context.fetchPagePicture(One, offset).firstOrNull()
}

override fun getPicturePagingSource(): PagingSource<Int, PluckImage> {
Expand Down
3 changes: 3 additions & 0 deletions pluck/src/main/java/com/himanshoe/pluck/theme/PluckDimens.kt
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ import androidx.compose.ui.unit.dp

object PluckDimens {
val Zero = 0.dp
val HalfQuarter = 1.dp
val Quarter = 2.dp
val Half = 4.dp
val One = 8.dp
val Three = 24.dp
val Six = 48.dp
Expand Down
33 changes: 0 additions & 33 deletions pluck/src/main/java/com/himanshoe/pluck/theme/PluckTheme.kt

This file was deleted.

Loading

0 comments on commit b630b4b

Please sign in to comment.