Skip to content

Commit

Permalink
Migrate methots to UI
Browse files Browse the repository at this point in the history
  • Loading branch information
jeluchu committed Jun 14, 2024
1 parent d0e6b10 commit 4abc9bb
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,6 @@ import android.view.LayoutInflater
import androidx.annotation.DrawableRes
import androidx.core.app.ActivityCompat
import androidx.core.content.ContextCompat
import androidx.core.graphics.drawable.toBitmapOrNull
import coil.imageLoader
import coil.request.CachePolicy
import coil.request.ErrorResult
import coil.request.ImageRequest
import coil.request.SuccessResult
import com.google.gson.Gson
import com.jeluchu.jchucomponents.ktx.constants.INTENT_TYPE_IMG_PNG
import com.jeluchu.jchucomponents.ktx.packageutils.buildIsQAndUp
Expand Down Expand Up @@ -101,24 +95,7 @@ fun Context.saveBitmap(
}
}

suspend fun Context.getImageToBitmap(
url: String,
force: Boolean = false,
isHardware: Boolean = false
): Bitmap? {
val request = ImageRequest.Builder(this).data(url).apply {
if (force) {
memoryCachePolicy(CachePolicy.DISABLED)
diskCachePolicy(CachePolicy.DISABLED)
}
allowHardware(isHardware)
}.build()

return when (val result = imageLoader.execute(request)) {
is ErrorResult -> throw result.throwable
is SuccessResult -> result.drawable.toBitmapOrNull()
}
}

fun Context.openPlaystoreSubscriptions(
productId: String,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package com.jeluchu.jchucomponents.ui.extensions.coil

import android.content.Context
import android.graphics.Bitmap
import androidx.core.graphics.drawable.toBitmapOrNull
import coil.imageLoader
import coil.request.CachePolicy
import coil.request.ErrorResult
import coil.request.ImageRequest
import coil.request.SuccessResult

suspend fun Context.getImageToBitmap(
url: String,
force: Boolean = false,
isHardware: Boolean = false
): Bitmap? {
val request = ImageRequest.Builder(this).data(url).apply {
if (force) {
memoryCachePolicy(CachePolicy.DISABLED)
diskCachePolicy(CachePolicy.DISABLED)
}
allowHardware(isHardware)
}.build()

return when (val result = imageLoader.execute(request)) {
is ErrorResult -> throw result.throwable
is SuccessResult -> result.drawable.toBitmapOrNull()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*
*/

package com.jeluchu.jchucomponents.ktx.lists
package com.jeluchu.jchucomponents.ui.extensions.lists

import androidx.compose.foundation.MutatePriority
import androidx.compose.foundation.lazy.LazyListState
Expand All @@ -22,7 +22,7 @@ fun LazyListState.disableScrolling(scope: CoroutineScope) {
}

/** Cancel the previous indefinite "scroll" blocking **/
fun LazyListState.reenableScrolling(scope: CoroutineScope) {
fun LazyListState.enableScrolling(scope: CoroutineScope) {
scope.launch {
scroll(scrollPriority = MutatePriority.PreventUserInput) {}
}
Expand Down

0 comments on commit 4abc9bb

Please sign in to comment.