Skip to content

Commit

Permalink
Include 2 news Composables and more extensions
Browse files Browse the repository at this point in the history
  • Loading branch information
jeluchu committed Aug 16, 2021
1 parent 21264f8 commit e42c8fb
Show file tree
Hide file tree
Showing 13 changed files with 230 additions and 11 deletions.
1 change: 1 addition & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ android {
}

dependencies {

implementation project(':jchucomponentscompose')
implementation 'androidx.appcompat:appcompat:1.3.1'
implementation 'com.google.android.material:material:1.4.0'
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.jeluchu.compposecomponents">

<uses-permission android:name="android.permission.INTERNET" />

<application
android:allowBackup="true"
android:fullBackupContent="false"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.layout.ContentScale
import androidx.compose.ui.unit.dp
import com.jeluchu.jchucomponentscompose.ui.images.DoubleTapAnimation
import com.jeluchu.jchucomponentscompose.ui.images.NetworkImage

class MainActivity : ComponentActivity() {
Expand Down Expand Up @@ -61,6 +62,13 @@ class MainActivity : ComponentActivity() {
androidx.compose.material.Text("Open Gallery")
}

DoubleTapAnimation(
"https://i.picsum.photos/id/1016/3844/2563.jpg?hmac=WEryKFRvTdeae2aUrY-DHscSmZuyYI9jd_-p94stBvc",
iconResource = R.drawable.ic_btnfavourite
) {
// Action when double tap
}

}
}
}
Expand Down
9 changes: 9 additions & 0 deletions app/src/main/res/drawable/ic_btnfavourite.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="28dp"
android:height="28dp"
android:viewportWidth="28"
android:viewportHeight="28">
<path
android:fillColor="#212121"
android:pathData="M14.6036,6.1928C17.205,3.2606 21.7875,3.2705 24.3762,6.2139C26.6389,8.7867 26.5238,12.6719 24.1126,15.1062L14.5327,24.7778C14.3919,24.92 14.2001,25 13.9999,25C13.7998,25 13.6079,24.92 13.4671,24.7778L3.8873,15.106C1.4763,12.6718 1.3611,8.7868 3.6237,6.214C6.2124,3.2706 10.7949,3.2606 13.3963,6.1928L13.9999,6.8732L14.6036,6.1928Z" />
</vector>
5 changes: 1 addition & 4 deletions jchucomponentscompose/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ dependencies {
implementation 'androidx.compose.ui:ui-tooling-preview:1.0.1'
implementation 'androidx.activity:activity-compose:1.3.1'
debugImplementation 'androidx.compose.ui:ui-tooling:1.0.1'
implementation 'androidx.activity:activity-compose:1.3.1'
implementation 'androidx.compose.material:material-icons-extended:1.0.1'
implementation 'androidx.compose.foundation:foundation:1.0.1'
implementation 'androidx.compose.foundation:foundation-layout:1.0.1'
Expand All @@ -58,15 +57,13 @@ dependencies {
implementation 'androidx.compose.runtime:runtime-livedata:1.0.1'
implementation 'androidx.constraintlayout:constraintlayout-compose:1.0.0-beta02'
implementation 'androidx.navigation:navigation-compose:2.4.0-alpha06'
implementation 'androidx.activity:activity-compose:1.3.1'

// ACCOMPANIST GOOGLE LIBRARY ------------------------------------------------------------------
implementation 'com.google.accompanist:accompanist-systemuicontroller:0.16.1'
implementation 'com.google.accompanist:accompanist-navigation-animation:0.16.1'

// ANDROIDX LIBRARY ----------------------------------------------------------------------------
implementation 'androidx.core:core-ktx:1.6.0'
implementation 'androidx.appcompat:appcompat:1.3.1'
implementation 'androidx.browser:browser:1.3.0'
implementation 'androidx.preference:preference-ktx:1.1.1'

Expand All @@ -91,7 +88,7 @@ afterEvaluate {
from components.release
groupId = "com.jeluchu"
artifactId = "jchucomponentscompose"
version = "0.0.4"
version = "0.0.6"
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.jeluchu.jchucomponentscompose.core.extensions.activities

import android.Manifest
import android.app.Activity
import android.content.pm.PackageManager
import androidx.core.app.ActivityCompat


private val permissionsList =
arrayOf(Manifest.permission.WRITE_EXTERNAL_STORAGE, Manifest.permission.READ_EXTERNAL_STORAGE)

val Activity.permissions: Unit
get() {
val perm =
ActivityCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE)
if (perm != PackageManager.PERMISSION_GRANTED) {
ActivityCompat.requestPermissions(
this,
permissionsList,
1
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,21 @@ import android.view.LayoutInflater
import android.widget.Toast
import androidx.annotation.DrawableRes
import androidx.browser.customtabs.CustomTabsIntent
import androidx.core.app.ActivityCompat
import androidx.core.content.ContextCompat
import com.jeluchu.jchucomponentscompose.R
import com.jeluchu.jchucomponentscompose.core.extensions.coroutines.noCrash
import com.jeluchu.jchucomponentscompose.core.extensions.packageutils.buildIsMAndLower
import com.jeluchu.jchucomponentscompose.core.extensions.sharedprefs.SharedPrefsHelpers
import com.jeluchu.jchucomponentscompose.utils.broadcast.CustomTabsCopyReceiver
import com.jeluchu.jchucomponentscompose.utils.broadcast.ShareBroadcastReceiver
import java.io.IOException

/** ---- PERMISSIONS --------------------------------------------------------------------------- **/

fun Context.checkSelfPermissionCompat(permission: String) =
ActivityCompat.checkSelfPermission(this, permission)

/** ---- NETWORKS ------------------------------------------------------------------------------ **/

@Suppress("DEPRECATION")
Expand Down Expand Up @@ -99,10 +106,13 @@ fun Context.addToClipboard(str: CharSequence?) {

/** ---- BROWSER TABS -------------------------------------------------------------------------- **/

/*fun Context.openInCustomTab(string: String) = customTabsWeb(string)
fun Context.openInCustomTab(url: String, colorBar: Int) = customTabsWeb(url, colorBar)

@Suppress("DEPRECATION")
private fun Context.customTabsWeb(string: String) {
private fun Context.customTabsWeb(
string: String,
colorBar: Int = R.color.browser_actions_bg_grey
) {
try {

val share = Intent(this, ShareBroadcastReceiver::class.java)
Expand All @@ -123,7 +133,7 @@ private fun Context.customTabsWeb(string: String) {
"#" + Integer.toHexString(
ContextCompat.getColor(
this,
R.color.chipBackground
colorBar
)
)
)
Expand All @@ -150,7 +160,7 @@ private fun Context.customTabsWeb(string: String) {
intent.putExtra(Browser.EXTRA_APPLICATION_ID, packageName)
startActivity(intent)
}
}*/
}

/** ---- PRIVATE METHODS ----------------------------------------------------------------------- **/

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package com.jeluchu.jchucomponentscompose.core.extensions.file

import java.io.File

val File.extension: String
get() = name.substringAfterLast('.', "")
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import java.text.DecimalFormat

fun Int.Companion.empty() = 0
fun Int?.orEmpty() = this ?: Int.empty()

fun Long.bytesToMeg(): String = (this / (1024L * 1024L)).toString()

fun Int.fixedDecimalsTime(): String {
val decimalFormat = DecimalFormat("00")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.jeluchu.jchucomponentscompose.core.extensions.lists

import androidx.compose.foundation.MutatePriority
import androidx.compose.foundation.lazy.LazyListState
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.awaitCancellation
import kotlinx.coroutines.launch

/** Await indefinitely, blocking scrolls **/
fun LazyListState.disableScrolling(scope: CoroutineScope) {
scope.launch {
scroll(scrollPriority = MutatePriority.PreventUserInput) {
awaitCancellation()
}
}
}

/** Cancel the previous indefinite "scroll" blocking **/
fun LazyListState.reenableScrolling(scope: CoroutineScope) {
scope.launch {
scroll(scrollPriority = MutatePriority.PreventUserInput) {}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,6 @@ fun String.decodeBase64toImage(): Bitmap {

/** ---- CONVERTERS AND MODIFIERS -------------------------------------------------------------- **/

fun Long.bytesToMeg(): String = (this / (1024L * 1024L)).toString()

fun String.capitalizeWords(): String =
split(" ").joinToString(" ") { it.uppercase(Locale.getDefault()) }

Expand All @@ -133,6 +131,7 @@ fun String.remove(@RegExp pattern: String) = remove(Regex(pattern, RegexOption.I
fun String.remove(regex: Regex) = replace(regex, "")

fun String.Companion.empty() = ""
fun CharSequence.isEmpty(): Boolean = length == 0

fun String.isEmpty(): Boolean = length == 0
fun String.replace(): String = replace("-", " ")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
package com.jeluchu.jchucomponentscompose.ui.images

import androidx.compose.animation.core.Spring
import androidx.compose.animation.core.animateDpAsState
import androidx.compose.animation.core.spring
import androidx.compose.foundation.Image
import androidx.compose.foundation.gestures.detectTapGestures
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.size
import androidx.compose.material.Icon
import androidx.compose.runtime.*
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.input.pointer.pointerInput
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.dp
import com.jeluchu.jchucomponentscompose.core.extensions.ints.empty
import com.jeluchu.jchucomponentscompose.core.extensions.strings.empty

@Composable
fun DoubleTapAnimation(
imageRemote: String = String.empty(),
imageResources: Int = Int.empty(),
iconResource: Int,
size: Dp = 250.dp,
onDoubleTap: () -> Unit
) {
var isLike by remember { mutableStateOf(false) }
val animatedSize by animateDpAsState(
targetValue = if (isLike) size else 0.dp,
animationSpec = spring(
dampingRatio = Spring.DampingRatioMediumBouncy,
stiffness = 500f
)
)
Box(modifier = Modifier.fillMaxSize()) {

if (imageRemote.isNotEmpty()) {
NetworkImage(
url = imageRemote,
modifier = Modifier
.align(Alignment.Center)
.pointerInput(Unit) {
detectTapGestures(
onDoubleTap = {
isLike = true
onDoubleTap()
}
)
}
)
} else {
Image(
painter = painterResource(id = imageResources),
contentDescription = String.empty(),
modifier = Modifier
.align(Alignment.Center)
.pointerInput(Unit) {
detectTapGestures(
onDoubleTap = {
isLike = true
onDoubleTap()
}
)
})
}


if (isLike) {
Icon(
painterResource(id = iconResource),
tint = Color.White,
modifier = Modifier
.size(animatedSize)
.align(Alignment.Center),
contentDescription = ""
)
if (animatedSize == size) {
isLike = false
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package com.jeluchu.jchucomponentscompose.ui.loaders

import androidx.compose.animation.core.*
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.shape.CircleShape
import androidx.compose.material.Card
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.alpha
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.unit.dp

@Composable
fun PulseLoading(
durationMillis:Int = 1000,
maxPulseSize:Float = 300f,
minPulseSize:Float = 50f,
pulseColor: Color = Color(234,240,246),
centreColor:Color = Color(66,133,244)
){
val infiniteTransition = rememberInfiniteTransition()
val size by infiniteTransition.animateFloat(
initialValue = minPulseSize,
targetValue = maxPulseSize,
animationSpec = infiniteRepeatable(
animation = tween(durationMillis, easing = LinearEasing),
repeatMode = RepeatMode.Restart
)
)
val alpha by infiniteTransition.animateFloat(
initialValue = 1f,
targetValue = 0f,
animationSpec = infiniteRepeatable(
animation = tween(durationMillis, easing = LinearEasing),
repeatMode = RepeatMode.Restart
)
)
Box(contentAlignment = Alignment.Center,modifier = Modifier.fillMaxSize()) {
Card(
shape = CircleShape,
modifier = Modifier.size(size.dp).align(Alignment.Center).alpha(alpha),
backgroundColor = pulseColor,
elevation = 0.dp
) {}
Card(modifier = Modifier
.size(minPulseSize.dp)
.align(Alignment.Center),
shape = CircleShape,
backgroundColor = centreColor){}
}
}

0 comments on commit e42c8fb

Please sign in to comment.