From 8dc37ead17b4ff827bea71c669b21ac963fc361b Mon Sep 17 00:00:00 2001 From: armanhossiny Date: Thu, 4 Jan 2024 13:17:14 +0330 Subject: [PATCH 1/8] update project --- Sample/.gitignore | 15 +++ Sample/.idea/.gitignore | 3 + Sample/.idea/.name | 1 + Sample/.idea/compiler.xml | 6 + Sample/.idea/gradle.xml | 19 +++ Sample/.idea/kotlinc.xml | 6 + Sample/.idea/misc.xml | 10 ++ Sample/app/build.gradle | 54 -------- Sample/app/build.gradle.kts | 72 +++++++++++ .../zarinpal}/ExampleInstrumentedTest.kt | 4 +- Sample/app/src/main/AndroidManifest.xml | 12 +- .../sample/inappbilling/MainActivity.kt | 116 ------------------ .../java/ir/nujen/zarinpal/MainActivity.kt | 46 +++++++ .../java/ir/nujen/zarinpal/ui/theme/Color.kt | 11 ++ .../java/ir/nujen/zarinpal/ui/theme/Theme.kt | 70 +++++++++++ .../java/ir/nujen/zarinpal/ui/theme/Type.kt | 34 +++++ .../ic_launcher_foreground.xml | 0 .../app/src/main/res/layout/activity_main.xml | 48 -------- .../res/mipmap-anydpi-v26/ic_launcher.xml | 1 + .../mipmap-anydpi-v26/ic_launcher_round.xml | 1 + .../app/src/main/res/values-night/themes.xml | 16 --- Sample/app/src/main/res/values/strings.xml | 2 +- Sample/app/src/main/res/values/themes.xml | 19 +-- Sample/app/src/main/res/xml/backup_rules.xml | 13 ++ .../main/res/xml/data_extraction_rules.xml | 19 +++ .../nujen/zarinpal}/ExampleUnitTest.kt | 2 +- Sample/build.gradle | 19 --- Sample/build.gradle.kts | 5 + Sample/gradle.properties | 11 +- .../gradle/wrapper/gradle-wrapper.properties | 6 +- .../{settings.gradle => settings.gradle.kts} | 14 ++- 31 files changed, 369 insertions(+), 286 deletions(-) create mode 100644 Sample/.gitignore create mode 100644 Sample/.idea/.gitignore create mode 100644 Sample/.idea/.name create mode 100644 Sample/.idea/compiler.xml create mode 100644 Sample/.idea/gradle.xml create mode 100644 Sample/.idea/kotlinc.xml create mode 100644 Sample/.idea/misc.xml delete mode 100644 Sample/app/build.gradle create mode 100644 Sample/app/build.gradle.kts rename Sample/app/src/androidTest/java/{com/zarinpal/sample/inappbilling => ir/nujen/zarinpal}/ExampleInstrumentedTest.kt (82%) delete mode 100644 Sample/app/src/main/java/com/zarinpal/sample/inappbilling/MainActivity.kt create mode 100644 Sample/app/src/main/java/ir/nujen/zarinpal/MainActivity.kt create mode 100644 Sample/app/src/main/java/ir/nujen/zarinpal/ui/theme/Color.kt create mode 100644 Sample/app/src/main/java/ir/nujen/zarinpal/ui/theme/Theme.kt create mode 100644 Sample/app/src/main/java/ir/nujen/zarinpal/ui/theme/Type.kt rename Sample/app/src/main/res/{drawable-v24 => drawable}/ic_launcher_foreground.xml (100%) delete mode 100644 Sample/app/src/main/res/layout/activity_main.xml delete mode 100644 Sample/app/src/main/res/values-night/themes.xml create mode 100644 Sample/app/src/main/res/xml/backup_rules.xml create mode 100644 Sample/app/src/main/res/xml/data_extraction_rules.xml rename Sample/app/src/test/java/{com/zarinpal/sample/inappbilling => ir/nujen/zarinpal}/ExampleUnitTest.kt (88%) delete mode 100644 Sample/build.gradle create mode 100644 Sample/build.gradle.kts rename Sample/{settings.gradle => settings.gradle.kts} (50%) diff --git a/Sample/.gitignore b/Sample/.gitignore new file mode 100644 index 0000000..aa724b7 --- /dev/null +++ b/Sample/.gitignore @@ -0,0 +1,15 @@ +*.iml +.gradle +/local.properties +/.idea/caches +/.idea/libraries +/.idea/modules.xml +/.idea/workspace.xml +/.idea/navEditor.xml +/.idea/assetWizardSettings.xml +.DS_Store +/build +/captures +.externalNativeBuild +.cxx +local.properties diff --git a/Sample/.idea/.gitignore b/Sample/.idea/.gitignore new file mode 100644 index 0000000..26d3352 --- /dev/null +++ b/Sample/.idea/.gitignore @@ -0,0 +1,3 @@ +# Default ignored files +/shelf/ +/workspace.xml diff --git a/Sample/.idea/.name b/Sample/.idea/.name new file mode 100644 index 0000000..9daee13 --- /dev/null +++ b/Sample/.idea/.name @@ -0,0 +1 @@ +zarinpal \ No newline at end of file diff --git a/Sample/.idea/compiler.xml b/Sample/.idea/compiler.xml new file mode 100644 index 0000000..b589d56 --- /dev/null +++ b/Sample/.idea/compiler.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/Sample/.idea/gradle.xml b/Sample/.idea/gradle.xml new file mode 100644 index 0000000..6d89050 --- /dev/null +++ b/Sample/.idea/gradle.xml @@ -0,0 +1,19 @@ + + + + + + \ No newline at end of file diff --git a/Sample/.idea/kotlinc.xml b/Sample/.idea/kotlinc.xml new file mode 100644 index 0000000..0fc3113 --- /dev/null +++ b/Sample/.idea/kotlinc.xml @@ -0,0 +1,6 @@ + + + + + \ No newline at end of file diff --git a/Sample/.idea/misc.xml b/Sample/.idea/misc.xml new file mode 100644 index 0000000..0ad17cb --- /dev/null +++ b/Sample/.idea/misc.xml @@ -0,0 +1,10 @@ + + + + + + + + + \ No newline at end of file diff --git a/Sample/app/build.gradle b/Sample/app/build.gradle deleted file mode 100644 index 4454e38..0000000 --- a/Sample/app/build.gradle +++ /dev/null @@ -1,54 +0,0 @@ -plugins { - id 'com.android.application' - id 'kotlin-android' -} - - -project.ext { - zarinpalSdkVersion = "0.5.3" -} - -android { - compileSdk 31 - - defaultConfig { - applicationId "com.zarinpal.sample.inappbilling" - minSdk 21 - targetSdk 31 - versionCode 1 - versionName "1.0" - - testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" - } - - buildTypes { - release { - minifyEnabled false - proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' - } - } - compileOptions { - sourceCompatibility JavaVersion.VERSION_1_8 - targetCompatibility JavaVersion.VERSION_1_8 - } - kotlinOptions { - jvmTarget = '1.8' - } - - viewBinding { - enabled = true - } - -} - -dependencies { - - implementation 'androidx.core:core-ktx:1.7.0' - implementation 'androidx.appcompat:appcompat:1.4.1' - implementation 'com.google.android.material:material:1.5.0' - implementation "com.zarinpal:payment-provider:" + project.ext.zarinpalSdkVersion - - //If you have access to mpg by ZarinPal. - implementation "com.zarinpal:mpg:" + project.ext.zarinpalSdkVersion - -} \ No newline at end of file diff --git a/Sample/app/build.gradle.kts b/Sample/app/build.gradle.kts new file mode 100644 index 0000000..24e177e --- /dev/null +++ b/Sample/app/build.gradle.kts @@ -0,0 +1,72 @@ +plugins { + id("com.android.application") + id("org.jetbrains.kotlin.android") +} + +android { + namespace = "ir.nujen.zarinpal" + compileSdk = 34 + + defaultConfig { + applicationId = "ir.nujen.zarinpal" + minSdk = 24 + targetSdk = 34 + versionCode = 1 + versionName = "1.0" + + testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" + vectorDrawables { + useSupportLibrary = true + } + } + + buildTypes { + release { + isMinifyEnabled = false + proguardFiles( + getDefaultProguardFile("proguard-android-optimize.txt"), + "proguard-rules.pro" + ) + } + } + compileOptions { + sourceCompatibility = JavaVersion.VERSION_1_8 + targetCompatibility = JavaVersion.VERSION_1_8 + } + kotlinOptions { + jvmTarget = "1.8" + } + buildFeatures { + compose = true + } + composeOptions { + kotlinCompilerExtensionVersion = "1.4.3" + } + packaging { + resources { + excludes += "/META-INF/{AL2.0,LGPL2.1}" + } + } +} + +dependencies { + + implementation("androidx.core:core-ktx:1.9.0") + implementation("androidx.lifecycle:lifecycle-runtime-ktx:2.6.2") + implementation("androidx.activity:activity-compose:1.8.2") + implementation(platform("androidx.compose:compose-bom:2023.03.00")) + implementation("androidx.compose.ui:ui") + implementation("androidx.compose.ui:ui-graphics") + implementation("androidx.compose.ui:ui-tooling-preview") + implementation("androidx.compose.material3:material3") + testImplementation("junit:junit:4.13.2") + androidTestImplementation("androidx.test.ext:junit:1.1.5") + androidTestImplementation("androidx.test.espresso:espresso-core:3.5.1") + androidTestImplementation(platform("androidx.compose:compose-bom:2023.03.00")) + androidTestImplementation("androidx.compose.ui:ui-test-junit4") + debugImplementation("androidx.compose.ui:ui-tooling") + debugImplementation("androidx.compose.ui:ui-test-manifest") + //-----------------------------------------------------------zarinpal + implementation("com.zarinpal:payment-provider:0.6.2") + implementation("com.zarinpal:mpg:0.6.2") +} \ No newline at end of file diff --git a/Sample/app/src/androidTest/java/com/zarinpal/sample/inappbilling/ExampleInstrumentedTest.kt b/Sample/app/src/androidTest/java/ir/nujen/zarinpal/ExampleInstrumentedTest.kt similarity index 82% rename from Sample/app/src/androidTest/java/com/zarinpal/sample/inappbilling/ExampleInstrumentedTest.kt rename to Sample/app/src/androidTest/java/ir/nujen/zarinpal/ExampleInstrumentedTest.kt index eb156d4..7f7708c 100644 --- a/Sample/app/src/androidTest/java/com/zarinpal/sample/inappbilling/ExampleInstrumentedTest.kt +++ b/Sample/app/src/androidTest/java/ir/nujen/zarinpal/ExampleInstrumentedTest.kt @@ -1,4 +1,4 @@ -package com.zarinpal.sample.inappbilling +package ir.nujen.zarinpal import androidx.test.platform.app.InstrumentationRegistry import androidx.test.ext.junit.runners.AndroidJUnit4 @@ -19,6 +19,6 @@ class ExampleInstrumentedTest { fun useAppContext() { // Context of the app under test. val appContext = InstrumentationRegistry.getInstrumentation().targetContext - assertEquals("com.zarinpal.sample.inappbilling", appContext.packageName) + assertEquals("ir.nujen.zarinpal", appContext.packageName) } } \ No newline at end of file diff --git a/Sample/app/src/main/AndroidManifest.xml b/Sample/app/src/main/AndroidManifest.xml index 1295bce..435a81c 100644 --- a/Sample/app/src/main/AndroidManifest.xml +++ b/Sample/app/src/main/AndroidManifest.xml @@ -1,18 +1,22 @@ + xmlns:tools="http://schemas.android.com/tools"> - + android:theme="@style/Theme.Zarinpal" + tools:targetApi="31"> + android:exported="true" + android:label="@string/app_name" + android:theme="@style/Theme.Zarinpal"> diff --git a/Sample/app/src/main/java/com/zarinpal/sample/inappbilling/MainActivity.kt b/Sample/app/src/main/java/com/zarinpal/sample/inappbilling/MainActivity.kt deleted file mode 100644 index 88f4c6f..0000000 --- a/Sample/app/src/main/java/com/zarinpal/sample/inappbilling/MainActivity.kt +++ /dev/null @@ -1,116 +0,0 @@ -package com.zarinpal.sample.inappbilling - -import androidx.appcompat.app.AppCompatActivity -import android.os.Bundle -import android.util.Log -import android.view.View -import android.widget.TextView -import android.widget.Toast -import androidx.appcompat.app.AppCompatDelegate -import com.zarinpal.ZarinPalBillingClient -import com.zarinpal.billing.purchase.Purchase -import com.zarinpal.client.BillingClientStateListener -import com.zarinpal.client.ClientState -import com.zarinpal.provider.core.future.FutureCompletionListener -import com.zarinpal.provider.core.future.TaskResult -import com.zarinpal.provider.model.response.Receipt -import com.zarinpal.sample.inappbilling.databinding.ActivityMainBinding - -class MainActivity : AppCompatActivity() { - - private var client: ZarinPalBillingClient? = null - - companion object { - const val TAG = "InAppBilling Sample: " - } - - override fun onCreate(savedInstanceState: Bundle?) { - super.onCreate(savedInstanceState) - setContentView(R.layout.activity_main) - - val txtReceipt = findViewById(R.id.txt_receipt) - - val billingClientStateListener = object : BillingClientStateListener { - override fun onClientServiceDisconnected() { - Log.d(TAG, "onClientServiceDisconnected") - } - - override fun onClientSetupFinished(state: ClientState) { - Log.d(TAG, "onClientSetupFinished ${state.name}") - - } - } - - - val purchaseCompletedListener = object : FutureCompletionListener { - override fun onComplete(task: TaskResult) { - Log.d(TAG, "onComplete Receipt is ${task.isSuccess}") - - if (task.isSuccess) { - txtReceipt.text = "Receipt: \n" + - "Transaction id: ${task.success?.transactionID}\n" + - "Amount: ${task.success?.amount}\n" + - "Date: ${task.success?.date}\n" + - "Status: ${task.success?.isSuccess}\n" - } else { - - txtReceipt.text = "Receipt failed: \n" + - "${task.failure?.message}" - } - - } - } - - - - client = ZarinPalBillingClient.newBuilder(this) - .setNightMode(AppCompatDelegate.MODE_NIGHT_YES) - .enableShowInvoice() - .setListener(billingClientStateListener) - .build() - - - findViewById(R.id.btn_payment_request).setOnClickListener { - client?.launchBillingFlow(getPurchaseAsPaymentRequest(), purchaseCompletedListener) - } - - findViewById(R.id.btn_authority).setOnClickListener { - client?.launchBillingFlow(getPurchaseAsAuthority(), purchaseCompletedListener) - } - - findViewById(R.id.btn_sku).setOnClickListener { - client?.launchBillingFlow(getPurchaseAsSku(), purchaseCompletedListener) - } - - } - - private fun getPurchaseAsPaymentRequest(): Purchase { - val merchantId = "6c64a645-1b28-4956-b32e-7b777864121a" - val amount = 1000L - val description = "Payment Request via ZarinPal SDK" - val callback = "https://google.com" // Your Server address - - - return Purchase.newBuilder() - .asPaymentRequest(merchantId, amount, callback, description) - .build() - - } - - - private fun getPurchaseAsAuthority(): Purchase { - - val authority = "" // The authority that resolved from ZarinPal - return Purchase.newBuilder() - .asAuthority(authority) - .build() - - } - - private fun getPurchaseAsSku(): Purchase { - val sku = "" // sku created from ZarinPal - return Purchase.newBuilder() - .asSku(sku) - .build() - } -} \ No newline at end of file diff --git a/Sample/app/src/main/java/ir/nujen/zarinpal/MainActivity.kt b/Sample/app/src/main/java/ir/nujen/zarinpal/MainActivity.kt new file mode 100644 index 0000000..7772d64 --- /dev/null +++ b/Sample/app/src/main/java/ir/nujen/zarinpal/MainActivity.kt @@ -0,0 +1,46 @@ +package ir.nujen.zarinpal + +import android.os.Bundle +import androidx.activity.ComponentActivity +import androidx.activity.compose.setContent +import androidx.compose.foundation.layout.fillMaxSize +import androidx.compose.material3.MaterialTheme +import androidx.compose.material3.Surface +import androidx.compose.material3.Text +import androidx.compose.runtime.Composable +import androidx.compose.ui.Modifier +import androidx.compose.ui.tooling.preview.Preview +import ir.nujen.zarinpal.ui.theme.ZarinpalTheme + +class MainActivity : ComponentActivity() { + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + setContent { + ZarinpalTheme { + // A surface container using the 'background' color from the theme + Surface( + modifier = Modifier.fillMaxSize(), + color = MaterialTheme.colorScheme.background + ) { + Greeting("Android") + } + } + } + } +} + +@Composable +fun Greeting(name: String, modifier: Modifier = Modifier) { + Text( + text = "Hello $name!", + modifier = modifier + ) +} + +@Preview(showBackground = true) +@Composable +fun GreetingPreview() { + ZarinpalTheme { + Greeting("Android") + } +} \ No newline at end of file diff --git a/Sample/app/src/main/java/ir/nujen/zarinpal/ui/theme/Color.kt b/Sample/app/src/main/java/ir/nujen/zarinpal/ui/theme/Color.kt new file mode 100644 index 0000000..cc21f9f --- /dev/null +++ b/Sample/app/src/main/java/ir/nujen/zarinpal/ui/theme/Color.kt @@ -0,0 +1,11 @@ +package ir.nujen.zarinpal.ui.theme + +import androidx.compose.ui.graphics.Color + +val Purple80 = Color(0xFFD0BCFF) +val PurpleGrey80 = Color(0xFFCCC2DC) +val Pink80 = Color(0xFFEFB8C8) + +val Purple40 = Color(0xFF6650a4) +val PurpleGrey40 = Color(0xFF625b71) +val Pink40 = Color(0xFF7D5260) \ No newline at end of file diff --git a/Sample/app/src/main/java/ir/nujen/zarinpal/ui/theme/Theme.kt b/Sample/app/src/main/java/ir/nujen/zarinpal/ui/theme/Theme.kt new file mode 100644 index 0000000..bc28122 --- /dev/null +++ b/Sample/app/src/main/java/ir/nujen/zarinpal/ui/theme/Theme.kt @@ -0,0 +1,70 @@ +package ir.nujen.zarinpal.ui.theme + +import android.app.Activity +import android.os.Build +import androidx.compose.foundation.isSystemInDarkTheme +import androidx.compose.material3.MaterialTheme +import androidx.compose.material3.darkColorScheme +import androidx.compose.material3.dynamicDarkColorScheme +import androidx.compose.material3.dynamicLightColorScheme +import androidx.compose.material3.lightColorScheme +import androidx.compose.runtime.Composable +import androidx.compose.runtime.SideEffect +import androidx.compose.ui.graphics.toArgb +import androidx.compose.ui.platform.LocalContext +import androidx.compose.ui.platform.LocalView +import androidx.core.view.WindowCompat + +private val DarkColorScheme = darkColorScheme( + primary = Purple80, + secondary = PurpleGrey80, + tertiary = Pink80 +) + +private val LightColorScheme = lightColorScheme( + primary = Purple40, + secondary = PurpleGrey40, + tertiary = Pink40 + + /* Other default colors to override + background = Color(0xFFFFFBFE), + surface = Color(0xFFFFFBFE), + onPrimary = Color.White, + onSecondary = Color.White, + onTertiary = Color.White, + onBackground = Color(0xFF1C1B1F), + onSurface = Color(0xFF1C1B1F), + */ +) + +@Composable +fun ZarinpalTheme( + darkTheme: Boolean = isSystemInDarkTheme(), + // Dynamic color is available on Android 12+ + dynamicColor: Boolean = true, + content: @Composable () -> Unit +) { + val colorScheme = when { + dynamicColor && Build.VERSION.SDK_INT >= Build.VERSION_CODES.S -> { + val context = LocalContext.current + if (darkTheme) dynamicDarkColorScheme(context) else dynamicLightColorScheme(context) + } + + darkTheme -> DarkColorScheme + else -> LightColorScheme + } + val view = LocalView.current + if (!view.isInEditMode) { + SideEffect { + val window = (view.context as Activity).window + window.statusBarColor = colorScheme.primary.toArgb() + WindowCompat.getInsetsController(window, view).isAppearanceLightStatusBars = darkTheme + } + } + + MaterialTheme( + colorScheme = colorScheme, + typography = Typography, + content = content + ) +} \ No newline at end of file diff --git a/Sample/app/src/main/java/ir/nujen/zarinpal/ui/theme/Type.kt b/Sample/app/src/main/java/ir/nujen/zarinpal/ui/theme/Type.kt new file mode 100644 index 0000000..90cafd9 --- /dev/null +++ b/Sample/app/src/main/java/ir/nujen/zarinpal/ui/theme/Type.kt @@ -0,0 +1,34 @@ +package ir.nujen.zarinpal.ui.theme + +import androidx.compose.material3.Typography +import androidx.compose.ui.text.TextStyle +import androidx.compose.ui.text.font.FontFamily +import androidx.compose.ui.text.font.FontWeight +import androidx.compose.ui.unit.sp + +// Set of Material typography styles to start with +val Typography = Typography( + bodyLarge = TextStyle( + fontFamily = FontFamily.Default, + fontWeight = FontWeight.Normal, + fontSize = 16.sp, + lineHeight = 24.sp, + letterSpacing = 0.5.sp + ) + /* Other default text styles to override + titleLarge = TextStyle( + fontFamily = FontFamily.Default, + fontWeight = FontWeight.Normal, + fontSize = 22.sp, + lineHeight = 28.sp, + letterSpacing = 0.sp + ), + labelSmall = TextStyle( + fontFamily = FontFamily.Default, + fontWeight = FontWeight.Medium, + fontSize = 11.sp, + lineHeight = 16.sp, + letterSpacing = 0.5.sp + ) + */ +) \ No newline at end of file diff --git a/Sample/app/src/main/res/drawable-v24/ic_launcher_foreground.xml b/Sample/app/src/main/res/drawable/ic_launcher_foreground.xml similarity index 100% rename from Sample/app/src/main/res/drawable-v24/ic_launcher_foreground.xml rename to Sample/app/src/main/res/drawable/ic_launcher_foreground.xml diff --git a/Sample/app/src/main/res/layout/activity_main.xml b/Sample/app/src/main/res/layout/activity_main.xml deleted file mode 100644 index c44dafb..0000000 --- a/Sample/app/src/main/res/layout/activity_main.xml +++ /dev/null @@ -1,48 +0,0 @@ - - - -