Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Alpha #5

Merged
merged 2 commits into from
Aug 31, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@
.externalNativeBuild
.cxx
local.properties
app/src/main/java/com/prime/toolz2/billing/Private.kt
1 change: 1 addition & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 9 additions & 9 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ android {
applicationId "com.prime.toolz2"
minSdk 21
targetSdk 32
versionCode 38
versionName "1.0.0-alpha05"
versionCode 39
versionName "1.0.0-alpha06"

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
vectorDrawables {
Expand Down Expand Up @@ -62,15 +62,15 @@ android {
freeCompilerArgs = [
"-Xopt-in=kotlin.RequiresOptIn",
"-Xcontext-receivers",
// "-Xuse-k2",
// "-Xjdk-release=1.8"
"-Xuse-k2",
"-Xjdk-release=1.8"
]
}
buildFeatures {
compose true
}
composeOptions {
kotlinCompilerExtensionVersion '1.3.0'
kotlinCompilerExtensionVersion '1.2.0-rc01'
}
packagingOptions {
resources {
Expand All @@ -85,7 +85,7 @@ dependencies {
implementation 'androidx.core:core-ktx:1.8.0'
//implementation 'com.google.android.material:material:1.6.1'

def compose_version = '1.3.0-alpha03'
def compose_version = '1.3.0-beta01'
implementation "androidx.compose.ui:ui:$compose_version"
implementation "androidx.compose.material:material:$compose_version"
implementation "androidx.compose.ui:ui-tooling-preview:$compose_version"
Expand Down Expand Up @@ -115,8 +115,8 @@ dependencies {
implementation "com.airbnb.android:lottie-compose:$lottieVersion"

//Preferences and other widgets
def accomplice_version = '1.0.0-alpha07'
implementation "com.github.prime-zs:accomplice:$accomplice_version"
def support_version = '1.0.0-alpha09'
implementation "com.github.prime-zs:support:$support_version"

// Splash Screen API
implementation 'androidx.core:core-splashscreen:1.0.0'
Expand All @@ -128,7 +128,7 @@ dependencies {
implementation "com.google.accompanist:accompanist-navigation-animation:$accompanist_version"

//kotlin-serialization
implementation 'org.jetbrains.kotlinx:kotlinx-serialization-json:1.3.3'
implementation 'org.jetbrains.kotlinx:kotlinx-serialization-json:1.4.0'

//hilt
implementation "com.google.dagger:hilt-android:$hilt_version"
Expand Down
9 changes: 4 additions & 5 deletions app/src/main/java/com/prime/toolz2/MainActivity.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.prime.toolz2

import LocalWindowSizeClass
import android.animation.ObjectAnimator
import android.app.Activity
import android.os.Bundle
Expand Down Expand Up @@ -30,7 +29,8 @@ import com.google.android.play.core.review.ReviewManagerFactory
import com.google.firebase.analytics.FirebaseAnalytics
import com.google.firebase.analytics.ktx.analytics
import com.google.firebase.ktx.Firebase
import com.prime.toolz2.common.billing.BillingManager
import com.prime.toolz2.billing.BillingManager
import com.prime.toolz2.billing.Product
import com.prime.toolz2.common.compose.*
import com.prime.toolz2.settings.GlobalKeys
import com.prime.toolz2.settings.NightMode
Expand All @@ -42,7 +42,6 @@ import com.primex.preferences.longPreferenceKey
import dagger.hilt.android.AndroidEntryPoint
import kotlinx.coroutines.flow.receiveAsFlow
import kotlinx.coroutines.launch
import rememberWindowSizeClass
import java.util.concurrent.TimeUnit
import javax.inject.Inject

Expand Down Expand Up @@ -90,13 +89,13 @@ class MainActivity : ComponentActivity() {
BillingManager(
context = this,
products = arrayOf(
BillingTokens.DISABLE_ASD_IN_APP_PRODUCT
Product.DISABLE_ASD
)
)
lifecycle.addObserver(billingManager)

setContent {
val sWindow = rememberWindowSizeClass()
val sWindow = calculateWindowSizeClass(activity = this)

// observe the change to density
val density = LocalDensity.current
Expand Down
4 changes: 4 additions & 0 deletions app/src/main/java/com/prime/toolz2/billing/Advertiser.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package com.prime.toolz2.billing

interface Advertiser {
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.prime.toolz2.common.billing
package com.prime.toolz2.billing

import android.app.Activity
import android.content.Context
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.prime.toolz2.common.billing;
package com.prime.toolz2.billing;

/*
* This class is an sample of how you can check to make sure your purchases on the device came from
Expand All @@ -8,13 +8,11 @@
* harder. The reason this code isn't just part of the library is to allow you to customize it (and
* rename it!) to make generic patching exploits more difficult.
*/

import android.text.TextUtils;
import android.util.Base64;
import android.util.Log;

import com.prime.toolz2.BillingTokens;
import com.prime.toolz2.BuildConfig;

import java.io.IOException;
import java.security.InvalidKeyException;
import java.security.KeyFactory;
Expand All @@ -41,7 +39,7 @@ class Security {
* your local.properties, it will be echoed into BuildConfig.
*/

final private static String BASE_64_ENCODED_PUBLIC_KEY = BillingTokens.PUBLIC_KEY;
final private static String BASE_64_ENCODED_PUBLIC_KEY = Product.PUBLIC_KEY;

/**
* Verifies that the data was signed with the given signature
Expand Down
21 changes: 0 additions & 21 deletions app/src/main/java/com/prime/toolz2/common/Util.kt
Original file line number Diff line number Diff line change
@@ -1,25 +1,4 @@
package com.prime.toolz2.common

import android.app.Activity
import android.util.Log
import androidx.compose.material.SnackbarDuration
import androidx.lifecycle.lifecycleScope
import com.google.android.play.core.appupdate.AppUpdateManager
import com.google.android.play.core.appupdate.AppUpdateManagerFactory
import com.google.android.play.core.ktx.AppUpdateResult
import com.google.android.play.core.ktx.requestAppUpdateInfo
import com.google.android.play.core.ktx.requestReview
import com.google.android.play.core.ktx.requestUpdateFlow
import com.google.android.play.core.review.ReviewManagerFactory
import com.prime.toolz2.MainActivity
import com.prime.toolz2.common.compose.SnackDataChannel
import com.prime.toolz2.common.compose.send
import com.prime.toolz2.settings.GlobalKeys
import com.primex.core.activity
import com.primex.core.runCatching
import com.primex.preferences.longPreferenceKey
import kotlinx.coroutines.launch
import java.util.concurrent.TimeUnit

private const val TAG = "Util"

This file was deleted.

98 changes: 95 additions & 3 deletions app/src/main/java/com/prime/toolz2/common/compose/Compose.kt
Original file line number Diff line number Diff line change
@@ -1,13 +1,105 @@
package com.prime.toolz2.common.compose

import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.layout.calculateEndPadding
import androidx.compose.foundation.layout.calculateStartPadding
import androidx.compose.foundation.BorderStroke
import androidx.compose.foundation.interaction.MutableInteractionSource
import androidx.compose.foundation.layout.*
import androidx.compose.material.*
import androidx.compose.runtime.Composable
import androidx.compose.runtime.NonRestartableComposable
import androidx.compose.runtime.remember
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.drawWithContent
import androidx.compose.ui.geometry.Offset
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.Shape
import androidx.compose.ui.graphics.painter.Painter
import androidx.compose.ui.text.AnnotatedString
import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.dp
import androidx.compose.ui.window.DialogProperties
import com.primex.ui.Label

@NonRestartableComposable
@Composable
fun Dialog(
expanded: Boolean,
onDismissRequest: () -> Unit,
properties: DialogProperties = DialogProperties(),
content: @Composable () -> Unit
) {
if (expanded)
androidx.compose.ui.window.Dialog(
onDismissRequest = onDismissRequest,
properties = properties,
content = content
)
}

@NonRestartableComposable
@Composable
fun TextButton(
label: AnnotatedString,
onClick: () -> Unit,
leading: Painter? = null,
modifier: Modifier = Modifier,
enabled: Boolean = true,
interactionSource: MutableInteractionSource = remember { MutableInteractionSource() },
elevation: ButtonElevation? = null,
shape: Shape = MaterialTheme.shapes.small,
border: BorderStroke? = null,
colors: ButtonColors = ButtonDefaults.textButtonColors(),
contentPadding: PaddingValues = ButtonDefaults.TextButtonContentPadding,
) {
TextButton(
onClick = onClick,
modifier = modifier,
enabled = enabled,
interactionSource = interactionSource,
elevation = elevation,
shape = shape,
border = border,
colors = colors,
contentPadding = contentPadding,
) {
if (leading != null)
Icon(
painter = leading, contentDescription = null, modifier = Modifier.padding(
end = ContentPadding.medium
)
)
Label(text = label)
}
}

@NonRestartableComposable
@Composable
fun TextButton(
label: String,
onClick: () -> Unit,
leading: Painter? = null,
modifier: Modifier = Modifier,
enabled: Boolean = true,
interactionSource: MutableInteractionSource = remember { MutableInteractionSource() },
elevation: ButtonElevation? = null,
shape: Shape = MaterialTheme.shapes.small,
border: BorderStroke? = null,
colors: ButtonColors = ButtonDefaults.textButtonColors(),
contentPadding: PaddingValues = ButtonDefaults.TextButtonContentPadding,
){
TextButton(
label = AnnotatedString(label),
leading = leading,
onClick = onClick,
modifier = modifier,
enabled = enabled,
interactionSource = interactionSource,
elevation = elevation,
shape = shape,
border = border,
colors = colors,
contentPadding = contentPadding,
)


}

49 changes: 36 additions & 13 deletions app/src/main/java/com/prime/toolz2/common/compose/Util.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,7 @@ package com.prime.toolz2.common.compose
import android.app.Activity
import android.content.res.Resources
import androidx.compose.animation.core.AnimationConstants
import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.layout.WindowInsets
import androidx.compose.foundation.layout.statusBars
import androidx.compose.foundation.layout.statusBarsPadding
import androidx.compose.foundation.layout.*
import androidx.compose.material.ContentAlpha
import androidx.compose.material.MaterialTheme
import androidx.compose.runtime.*
Expand All @@ -27,7 +24,7 @@ import com.google.android.play.core.install.model.AppUpdateType
import com.google.android.play.core.install.model.UpdateAvailability
import com.google.android.play.core.ktx.installStatus
import com.google.android.play.core.review.ReviewManager
import com.prime.toolz2.common.billing.BillingManager
import com.prime.toolz2.billing.BillingManager
import com.primex.core.Text
import com.primex.core.resolve
import com.primex.core.runCatching
Expand Down Expand Up @@ -227,15 +224,15 @@ fun AppUpdateManager.check(
resultCode: Int,
report: Boolean = false,
emit: (snack: Snack) -> Unit
){
) {
// obtain the task for each check
val task = appUpdateInfo
task.addOnSuccessListener { info ->
val availability = info.updateAvailability()
val status = info.installStatus
emit(Snack("$status"))
when(availability){
UpdateAvailability.UNKNOWN -> emit(Snack("Unknown error occurred!. $availability"))
when (availability) {
UpdateAvailability.UNKNOWN -> emit(Snack("Unknown error occurred!. $availability"))

UpdateAvailability.UPDATE_NOT_AVAILABLE ->
emit(Snack("App is already updated to latest version."))
Expand All @@ -247,16 +244,16 @@ fun AppUpdateManager.check(

// in case it is 0 to avoid exception.
val total = info.totalBytesToDownload() + 1
val progress = downloaded / total * 100
val progress = downloaded / total * 100
emit(Snack("Downloaded: $progress"))
// update is available
//FixMe - Add way to manually adjust flexibility.
//val isFlexible = (info.clientVersionStalenessDays ?: -1) <= FLEXIBLE_UPDATE_STALENESS_DAYS
val isFlexible = info.isUpdateTypeAllowed(AppUpdateType.FLEXIBLE)
val options = if (isFlexible) AppUpdateType.FLEXIBLE else AppUpdateType.IMMEDIATE
val options = if (isFlexible) AppUpdateType.FLEXIBLE else AppUpdateType.IMMEDIATE
emit(Snack("$options"))
runCatching(TAG){
startUpdateFlowForResult(info, options, activity, resultCode)
runCatching(TAG) {
startUpdateFlowForResult(info, options, activity, resultCode)
}
}

Expand All @@ -265,4 +262,30 @@ fun AppUpdateManager.check(
task.addOnFailureListener {
emit(Snack("Unknown error occured: ${it.message}"))
}
}
}


fun Modifier.padding(
horizontal: Dp,
top: Dp = 0.dp,
bottom: Dp = 0.dp
) = this.then(
Modifier.padding(
start = horizontal,
end = horizontal,
top = top,
bottom = bottom
)
)

/*
fun Modifier.padding(
vertical: Dp,
start: Dp = 0.dp,
end: Dp = 0.dp
) = Modifier.padding(
start = start,
end = end,
top = vertical,
bottom = vertical
)*/
Loading