Skip to content

Commit

Permalink
Add Google flavor
Browse files Browse the repository at this point in the history
  • Loading branch information
tananaev committed Dec 12, 2022
1 parent 88eb351 commit be0d996
Show file tree
Hide file tree
Showing 11 changed files with 161 additions and 32 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@
.idea
.DS_Store
local.properties
google-services.json
*.iml
build
39 changes: 34 additions & 5 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,21 @@ android {

defaultConfig {
applicationId 'com.tananaev.passportreader'
minSdkVersion 15
minSdkVersion 19
targetSdkVersion 33
versionCode 18
versionName "2.3"
versionCode 19
versionName '3.0'
multiDexEnabled = true
}
namespace "com.tananaev.passportreader"
namespace 'com.tananaev.passportreader'

flavorDimensions 'default'
productFlavors {
regular {
isDefault = true
}
google
}

packagingOptions {
resources {
Expand All @@ -35,6 +43,27 @@ dependencies {
implementation 'com.madgag.spongycastle:prov:1.54.0.0'
implementation 'com.gemalto.jp2:jp2-android:1.0.3'
implementation 'com.github.mhshams:jnbis:1.1.0'
implementation 'org.bouncycastle:bcpkix-jdk15on:1.65'
implementation 'org.bouncycastle:bcpkix-jdk15on:1.65' // do not update
implementation 'commons-io:commons-io:2.8.0'
googleImplementation platform('com.google.firebase:firebase-bom:31.0.0')
googleImplementation 'com.google.firebase:firebase-analytics-ktx'
googleImplementation 'com.google.firebase:firebase-crashlytics'
googleImplementation 'com.google.android.gms:play-services-ads:21.3.0'
googleImplementation 'com.google.android.play:review-ktx:2.0.1'
}

if (getGradle().getStartParameter().getTaskRequests().toString().contains('Google')) {
apply plugin: 'com.google.gms.google-services'
apply plugin: 'com.google.firebase.crashlytics'

task copyJson(type: Copy) {
from '../../environment/firebase'
into '.'
include 'passport-reader.json'
rename('passport-reader.json', 'google-services.json')
}

afterEvaluate {
preBuild.dependsOn copyJson
}
}
24 changes: 24 additions & 0 deletions app/src/google/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android">

<application>

<activity
android:name=".GoogleActivity"
android:screenOrientation="fullSensor"
android:exported="true">

<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>

<intent-filter>
<action android:name="com.tananaev.passportreader.REQUEST" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>

</activity>

</application>

</manifest>
60 changes: 60 additions & 0 deletions app/src/google/java/com/tananaev/passportreader/GoogleActivity.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
package com.tananaev.passportreader

import android.os.Bundle
import android.preference.PreferenceManager
import android.widget.FrameLayout
import com.google.android.gms.ads.AdRequest
import com.google.android.gms.ads.AdSize
import com.google.android.gms.ads.AdView
import com.google.android.gms.ads.MobileAds
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

class GoogleActivity : MainActivity() {
private lateinit var firebaseAnalytics: FirebaseAnalytics

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
firebaseAnalytics = Firebase.analytics
MobileAds.initialize(this) {}

val adView = AdView(this).apply {
setAdSize(AdSize.BANNER)
adUnitId = "ca-app-pub-9061647223840223/5869276959"
loadAd(AdRequest.Builder().build())
}
val params = FrameLayout.LayoutParams(
FrameLayout.LayoutParams.MATCH_PARENT,
FrameLayout.LayoutParams.WRAP_CONTENT,
)
val containerView: FrameLayout = findViewById(R.id.bottom_container)
containerView.addView(adView, params)
}

override fun onResume() {
super.onResume()
handleRating()
}

@Suppress("DEPRECATION")
private fun handleRating() {
val preferences = PreferenceManager.getDefaultSharedPreferences(this)
if (!preferences.getBoolean("ratingShown", false)) {
val openTimes = preferences.getInt("openTimes", 0) + 1
preferences.edit().putInt("openTimes", openTimes).apply()
if (openTimes >= 5) {
val reviewManager = ReviewManagerFactory.create(this)
reviewManager.requestReviewFlow().addOnCompleteListener { infoTask ->
if (infoTask.isSuccessful) {
val flow = reviewManager.launchReviewFlow(this, infoTask.result)
flow.addOnCompleteListener {
preferences.edit().putBoolean("ratingShown", true).apply()
}
}
}
}
}
}
}
29 changes: 4 additions & 25 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,35 +12,14 @@
android:supportsRtl="true"
android:theme="@style/AppTheme">

<activity
android:exported="true"
android:name=".MainActivity"
android:screenOrientation="fullSensor">

<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>

<intent-filter>
<action android:name="com.tananaev.passportreader.REQUEST" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>

<!--<intent-filter>
<action android:name="android.nfc.action.TECH_DISCOVERED" />
</intent-filter>
<meta-data
android:name="android.nfc.action.TECH_DISCOVERED"
android:resource="@xml/nfc_tech_filter" />-->

</activity>
<meta-data
android:name="com.google.android.gms.ads.APPLICATION_ID"
android:value="ca-app-pub-9061647223840223~3001602354"/>

<activity
android:exported="true"
android:name=".ResultActivity"
android:screenOrientation="portrait" />
android:screenOrientation="fullSensor" />

</application>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ import java.text.ParseException
import java.text.SimpleDateFormat
import java.util.*

class MainActivity : AppCompatActivity() {
abstract class MainActivity : AppCompatActivity() {

private lateinit var passportNumberView: EditText
private lateinit var expirationDateView: EditText
Expand Down
6 changes: 6 additions & 0 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -98,4 +98,10 @@

</ScrollView>

<FrameLayout
android:id="@+id/bottom_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom" />

</FrameLayout>
24 changes: 24 additions & 0 deletions app/src/regular/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android">

<application>

<activity
android:name=".RegularActivity"
android:screenOrientation="fullSensor"
android:exported="true">

<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>

<intent-filter>
<action android:name="com.tananaev.passportreader.REQUEST" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>

</activity>

</application>

</manifest>
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package com.tananaev.passportreader

class RegularActivity : MainActivity()
4 changes: 3 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@ buildscript {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:7.3.1'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath 'com.android.tools.build:gradle:7.3.1'
classpath 'com.google.gms:google-services:4.3.14'
classpath 'com.google.firebase:firebase-crashlytics-gradle:2.9.2'
}
}

Expand Down
1 change: 1 addition & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
org.gradle.jvmargs=-Xmx4096m
android.enableJetifier=true
android.useAndroidX=true

0 comments on commit be0d996

Please sign in to comment.