-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
84 changed files
with
1,813 additions
and
117 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
Empty file.
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 was deleted.
Oops, something went wrong.
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
80 changes: 63 additions & 17 deletions
80
core/admob/src/androidMain/kotlin/io/spherelabs/admob/GADBannerView.android.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 |
---|---|---|
@@ -1,45 +1,91 @@ | ||
package io.spherelabs.admob | ||
|
||
import androidx.compose.runtime.Composable | ||
import androidx.compose.runtime.remember | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.platform.LocalContext | ||
import com.google.android.gms.ads.AdSize | ||
import com.google.android.gms.ads.AdView as AndroidBannerView | ||
import android.annotation.SuppressLint | ||
import androidx.compose.foundation.layout.fillMaxWidth | ||
import androidx.compose.foundation.background | ||
import androidx.compose.foundation.layout.* | ||
import androidx.compose.runtime.* | ||
import androidx.compose.ui.graphics.Color | ||
import androidx.compose.ui.platform.LocalContext | ||
import androidx.compose.ui.unit.dp | ||
import androidx.compose.ui.viewinterop.AndroidView | ||
import com.google.android.gms.ads.AdListener | ||
import com.google.android.gms.ads.AdRequest | ||
import com.google.android.gms.ads.LoadAdError | ||
import io.spherelabs.system.ui.shimmer.shimmer | ||
|
||
|
||
@SuppressLint("MissingPermission") | ||
@Composable | ||
actual fun GADBannerView( | ||
adId: String, | ||
modifier: Modifier, | ||
onAdLoaded: (loaded: Boolean) -> Unit, | ||
) { | ||
val context = LocalContext.current | ||
val bannerView: AndroidBannerView = remember { AndroidBannerView(context) } | ||
var adLoaded by remember { mutableStateOf(false) } | ||
|
||
DisposableEffect(adId) { | ||
onDispose { | ||
bannerView.destroy() | ||
} | ||
} | ||
|
||
val bannerListener = rememberBannerAdListener( | ||
onAdFailedToLoad = {}, | ||
onAdLoaded = { adLoaded = true }, | ||
) | ||
|
||
val currentAdSize = remember { | ||
AdSize.BANNER | ||
} | ||
|
||
val adRequest = AdRequest.Builder().build() | ||
|
||
val bannerView = remember { | ||
AndroidBannerView(context).apply { | ||
setAdSize(currentAdSize) | ||
adUnitId = adId | ||
Box(modifier = modifier.height(currentAdSize.height.dp).padding(horizontal = 24.dp)) { | ||
if (!adLoaded) { | ||
Box( | ||
Modifier | ||
.fillMaxWidth().fillMaxHeight().shimmer() | ||
.background(color = Color.White.copy(0.5f)), | ||
) | ||
} | ||
|
||
AndroidView( | ||
factory = { | ||
bannerView.apply { | ||
setAdSize(currentAdSize) | ||
adUnitId = adId | ||
adListener = bannerListener | ||
} | ||
}, | ||
modifier = modifier.fillMaxSize(), | ||
update = { currentBannerView -> | ||
currentBannerView.loadAd(adRequest) | ||
}, | ||
) | ||
} | ||
|
||
|
||
AndroidView( | ||
factory = { | ||
bannerView | ||
}, | ||
modifier = modifier.fillMaxWidth(), | ||
update = { currentBannerView -> | ||
currentBannerView.loadAd(adRequest) | ||
}, | ||
) | ||
} | ||
|
||
|
||
@Composable | ||
private fun rememberBannerAdListener( | ||
onAdFailedToLoad: (LoadAdError) -> Unit, | ||
onAdLoaded: () -> Unit, | ||
) = remember { | ||
object : AdListener() { | ||
override fun onAdFailedToLoad(error: LoadAdError) { | ||
onAdFailedToLoad(error) | ||
} | ||
|
||
override fun onAdLoaded() { | ||
super.onAdLoaded() | ||
onAdLoaded() | ||
} | ||
} | ||
} |
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
6 changes: 6 additions & 0 deletions
6
core/admob/src/commonMain/kotlin/io/spherelabs/admob/di/LoadGADError.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 io.spherelabs.admob.di | ||
|
||
data class LoadGADError( | ||
val code: Int, | ||
val message: String, | ||
) |
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 |
---|---|---|
@@ -1,3 +1,4 @@ | ||
|
||
@file:Suppress("DSL_SCOPE_VIOLATION") | ||
|
||
plugins { alias(libs.plugins.anypass.common) } | ||
|
36 changes: 36 additions & 0 deletions
36
core/common/src/commonMain/kotlin/io/spherelabs/common/LocalDateTimeExtension.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,36 @@ | ||
package io.spherelabs.common | ||
|
||
import kotlinx.datetime.Instant | ||
import kotlinx.datetime.TimeZone | ||
import kotlinx.datetime.toLocalDateTime | ||
|
||
val Instant.timestamp: String | ||
get() { | ||
val timezone = TimeZone.currentSystemDefault() | ||
val datetime = this.toLocalDateTime(timezone) | ||
val year = datetime.year | ||
val month = datetime.monthNumber | ||
val dayOfMonth = datetime.dayOfMonth | ||
|
||
val hour = datetime.hour | ||
val minutes = datetime.minute | ||
val seconds = datetime.second | ||
|
||
return "$year/$month/$dayOfMonth $hour:$minutes:$seconds" | ||
} | ||
|
||
val Instant.month: Int | ||
get() { | ||
val timezone = TimeZone.currentSystemDefault() | ||
val datetime = this.toLocalDateTime(timezone) | ||
return datetime.monthNumber | ||
} | ||
|
||
fun Long.getMonth(): Int { | ||
return Instant.fromEpochMilliseconds(this).month | ||
} | ||
|
||
fun Long.formatLongTime(): String { | ||
return Instant.fromEpochMilliseconds(this).timestamp | ||
} | ||
|
16 changes: 16 additions & 0 deletions
16
core/common/src/commonTest/kotlin/LocalDateTimeExtensionTest.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 @@ | ||
import assertk.assertThat | ||
import assertk.assertions.isEqualTo | ||
import io.spherelabs.common.formatLongTime | ||
import kotlin.test.Test | ||
|
||
class LocalDateTimeExtensionTest { | ||
@Test | ||
fun `GIVEN the current time WHEN format to string THEN checks the right timestamp`() { | ||
// val now = 1704760525488 | ||
// | ||
// val instant = now.formatLongTime() | ||
// val currentTimestamp = "2024/1/9 9:35:25" | ||
// | ||
// assertThat(instant).isEqualTo(currentTimestamp) | ||
} | ||
} |
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
17 changes: 17 additions & 0 deletions
17
...system/ui/src/androidMain/kotlin/io/spherelabs/system/ui/shimmer/ShimmerBounds.android.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,17 @@ | ||
package io.spherelabs.system.ui.shimmer | ||
|
||
import android.content.res.Resources | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.runtime.remember | ||
import androidx.compose.ui.geometry.Rect | ||
|
||
/** | ||
* Copied from https://github.com/valentinilk/compose-shimmer/tree/master | ||
*/ | ||
|
||
@Composable | ||
internal actual fun rememberWindowBounds(): Rect = remember { | ||
val metrics = Resources.getSystem().displayMetrics | ||
|
||
Rect(0f, 0f, metrics.widthPixels.toFloat(), metrics.heightPixels.toFloat()) | ||
} |
Oops, something went wrong.