Skip to content

Commit f8629b9

Browse files
author
dilipsuthar1997
committed
code cleanup, add interstitial
1 parent de3183d commit f8629b9

11 files changed

Lines changed: 116 additions & 39 deletions

File tree

app/build.gradle

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,20 @@ android {
1212
applicationId "com.techflow.materialcolor"
1313
minSdkVersion 22
1414
targetSdkVersion 29
15-
versionCode 301
16-
versionName "3.0.1"
15+
versionCode 30103
16+
versionName "3.0.103"
1717
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
1818
}
1919
buildTypes {
2020
release {
21-
minifyEnabled false
21+
minifyEnabled true
22+
//shrinkResources true
2223
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
2324
}
2425
}
2526
buildTypes.each {
2627
it.buildConfigField('String', 'AUDIENCE_BANNER_ID', AUDIENCE_BANNER_ID)
28+
it.buildConfigField('String', 'AUDIENCE_INTERSTITIAL_ID', AUDIENCE_INTERSTITIAL_ID)
2729
}
2830
dataBinding {
2931
enabled = true
@@ -34,13 +36,11 @@ dependencies {
3436

3537
implementation fileTree(dir: 'libs', include: ['*.jar'])
3638
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
37-
implementation 'androidx.appcompat:appcompat:1.0.2'
39+
implementation 'androidx.appcompat:appcompat:1.1.0'
3840
implementation 'androidx.core:core-ktx:1.1.0'
3941
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
4042
implementation 'com.google.android.material:material:1.0.0-rc01'
4143
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
42-
implementation 'androidx.emoji:emoji:1.0.0'
43-
implementation 'androidx.emoji:emoji-bundled:1.0.0' // Emoji handler
4444
implementation 'androidx.palette:palette:1.0.0' // Color Extractor form image
4545
implementation 'com.android.billingclient:billing:1.2' // In app purchase
4646
implementation 'androidx.browser:browser:1.0.0' // Chrome custom tab
@@ -55,7 +55,7 @@ dependencies {
5555
implementation 'com.balysv:material-ripple:1.0.2' // Ripple effect
5656
implementation 'com.theartofdev.edmodo:android-image-cropper:2.8.0' // Image cropper
5757
implementation 'com.getkeepsafe.taptargetview:taptargetview:1.13.0' // Tap target view
58-
implementation 'com.afollestad.material-dialogs:core:3.1.0' // Material dialog
58+
implementation 'com.afollestad.material-dialogs:core:3.1.1' // Material dialog
5959
implementation 'com.mikhaellopez:circularimageview:3.2.0' // Circle Image View
6060
implementation 'com.facebook.android:audience-network-sdk:5.+' // Facebook audience
6161
}

app/src/main/java/com/techflow/materialcolor/activity/BaseActivity.kt

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,7 @@
11
package com.techflow.materialcolor.activity
22

3-
import android.os.Build
43
import android.os.Bundle
5-
import android.view.View
64
import androidx.appcompat.app.AppCompatActivity
7-
import androidx.emoji.bundled.BundledEmojiCompatConfig
8-
import androidx.emoji.text.EmojiCompat
95
import com.facebook.ads.AudienceNetworkAds
106
import com.techflow.materialcolor.R
117
import com.techflow.materialcolor.utils.ThemeUtils
@@ -19,10 +15,6 @@ abstract class BaseActivity : AppCompatActivity() {
1915
}
2016
super.onCreate(savedInstanceState)
2117

22-
// Initialize emoji first
23-
val config: EmojiCompat.Config = BundledEmojiCompatConfig(this)
24-
EmojiCompat.init(config)
25-
2618
// Set recent app header color
2719
ThemeUtils.setRecentAppsHeaderColor(this)
2820
customizeStatusBar()

app/src/main/java/com/techflow/materialcolor/activity/HomeActivity.kt

Lines changed: 61 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,25 @@ package com.techflow.materialcolor.activity
22

33
import android.os.Bundle
44
import com.techflow.materialcolor.utils.Tools
5-
import android.app.ProgressDialog
5+
import android.content.Context
66
import android.content.Intent
77
import android.view.Menu
88
import android.view.MenuItem
99
import android.widget.Toast
1010
import androidx.appcompat.widget.Toolbar
1111
import androidx.databinding.DataBindingUtil
1212
import androidx.fragment.app.Fragment
13+
import com.facebook.ads.Ad
14+
import com.facebook.ads.AdError
15+
import com.facebook.ads.InterstitialAd
16+
import com.facebook.ads.InterstitialAdListener
1317
import com.google.android.material.snackbar.Snackbar
1418
import com.google.android.play.core.appupdate.AppUpdateManagerFactory
1519
import com.google.android.play.core.install.InstallStateUpdatedListener
1620
import com.google.android.play.core.install.model.AppUpdateType
1721
import com.google.android.play.core.install.model.InstallStatus
1822
import com.google.android.play.core.install.model.UpdateAvailability
23+
import com.techflow.materialcolor.BuildConfig
1924
import com.techflow.materialcolor.R
2025
import com.techflow.materialcolor.databinding.ActivityHomeBinding
2126
import com.techflow.materialcolor.fragment.ColorPickerFragment
@@ -50,10 +55,25 @@ class HomeActivity : BaseActivity() {
5055
val BACK_STACK_ROOT_NAME = "root_fragment"
5156
val UPDATE_RC = 201
5257

58+
// STATIC
59+
companion object {
60+
// Audience
61+
private lateinit var interstitialAd: InterstitialAd
62+
63+
fun showAd(context: Context) {
64+
if (interstitialAd.isAdLoaded) {
65+
if (interstitialAd.isAdInvalidated)
66+
return
67+
else if (SharedPref.getInstance(context).actionShowInterstitialAd())
68+
interstitialAd.show()
69+
} else if (Tools.hasNetwork(context))
70+
interstitialAd.loadAd()
71+
}
72+
}
73+
5374
private lateinit var binding: ActivityHomeBinding
5475

5576
private lateinit var sharedPref: SharedPref
56-
private lateinit var progressDialog: ProgressDialog
5777

5878
private lateinit var homeFragment: HomeFragment
5979
private lateinit var gradientFragment: GradientFragment
@@ -74,6 +94,7 @@ class HomeActivity : BaseActivity() {
7494
initComponent()
7595
initIntro()
7696
initBottomNavigation()
97+
initAd()
7798
initInAppUpdate() // Init in-app update
7899
}
79100

@@ -134,6 +155,11 @@ class HomeActivity : BaseActivity() {
134155

135156
private fun initBottomNavigation() {
136157
binding.justBar.setOnBarItemClickListener { barItem, position ->
158+
159+
// Load ad
160+
if (SharedPref.getInstance(this).getBoolean(Preferences.SHOW_AD, true))
161+
showAd(this)
162+
137163
when(barItem.id) {
138164
R.id.nav_home -> {
139165
displayFragment(homeFragment)
@@ -178,6 +204,39 @@ class HomeActivity : BaseActivity() {
178204
finish()
179205
}
180206

207+
private fun initAd() {
208+
interstitialAd = InterstitialAd(this, BuildConfig.AUDIENCE_INTERSTITIAL_ID)
209+
if (Tools.hasNetwork(this))
210+
interstitialAd.loadAd()
211+
212+
interstitialAd.setAdListener(object : InterstitialAdListener {
213+
214+
override fun onInterstitialDisplayed(p0: Ad?) {
215+
216+
}
217+
218+
override fun onInterstitialDismissed(p0: Ad?) {
219+
220+
}
221+
222+
override fun onAdLoaded(p0: Ad?) {
223+
224+
}
225+
226+
override fun onError(p0: Ad?, p1: AdError?) {
227+
if (Tools.hasNetwork(this@HomeActivity))
228+
interstitialAd.loadAd()
229+
}
230+
231+
override fun onAdClicked(p0: Ad?) {
232+
233+
}
234+
235+
override fun onLoggingImpression(p0: Ad?) {
236+
237+
}
238+
})
239+
}
181240

182241

183242
/** @method in-app update functionality */

app/src/main/java/com/techflow/materialcolor/activity/WelcomeActivity.kt

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,17 @@ import com.techflow.materialcolor.R
1212
/**
1313
* Copyright 2019 Dilip Suthar
1414
15-
Licensed under the Apache License, Version 2.0 (the "License");
16-
you may not use this file except in compliance with the License.
17-
You may obtain a copy of the License at
15+
Licensed under the Apache License, Version 2.0 (the "License");
16+
you may not use this file except in compliance with the License.
17+
You may obtain a copy of the License at
1818
19-
http://www.apache.org/licenses/LICENSE-2.0
19+
http://www.apache.org/licenses/LICENSE-2.0
2020
21-
Unless required by applicable law or agreed to in writing, software
22-
distributed under the License is distributed on an "AS IS" BASIS,
23-
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
24-
See the License for the specific language governing permissions and
25-
limitations under the License.
21+
Unless required by applicable law or agreed to in writing, software
22+
distributed under the License is distributed on an "AS IS" BASIS,
23+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
24+
See the License for the specific language governing permissions and
25+
limitations under the License.
2626
*/
2727
class WelcomeActivity : BaseActivity() {
2828

app/src/main/java/com/techflow/materialcolor/adapter/AdapterColor.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ class AdapterColor(
4949

5050
} else if (holder is AdViewHolder) {
5151

52-
// Check if purchased and load >> advertisement
52+
// Check if purchased and load Ad
5353
if (SharedPref.getInstance(context).getBoolean(Preferences.SHOW_AD, true)) {
5454
holder.loadAds(context)
5555
}

app/src/main/java/com/techflow/materialcolor/fragment/HomeFragment.kt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,13 @@ import androidx.recyclerview.widget.LinearLayoutManager
1111

1212
import com.techflow.materialcolor.R
1313
import com.techflow.materialcolor.activity.ColorActivity
14+
import com.techflow.materialcolor.activity.HomeActivity
1415
import com.techflow.materialcolor.adapter.AdapterColor
1516
import com.techflow.materialcolor.data.DataGenerator
1617
import com.techflow.materialcolor.databinding.FragmentHomeBinding
1718
import com.techflow.materialcolor.model.Color
19+
import com.techflow.materialcolor.utils.Preferences
20+
import com.techflow.materialcolor.utils.SharedPref
1821
import com.techflow.materialcolor.utils.Tools
1922
/**
2023
* Created by Dilip on 16/02/19
@@ -35,6 +38,11 @@ class HomeFragment : Fragment() {
3538
super.onCreate(savedInstanceState)
3639
mOnItemClickListener = object : AdapterColor.OnItemClickListener {
3740
override fun onItemClick(view: View, color: Color, position: Int) {
41+
42+
// Load ad
43+
if (SharedPref.getInstance(context!!).getBoolean(Preferences.SHOW_AD, true))
44+
HomeActivity.showAd(context!!)
45+
3846
val i = Intent(activity, ColorActivity::class.java)
3947
i.putExtra("COLOR_NAME", color.colorName)
4048
i.putExtra("COLOR", color.color)

app/src/main/java/com/techflow/materialcolor/fragment/SettingFragment.kt

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,10 @@ class SettingFragment : Fragment(), View.OnClickListener {
9494
if (Tools.hasNetwork(context!!)) {
9595
Tools.visibleViews(bind.progressBar)
9696
Tools.inVisibleViews(bind.btnRemoveAds, type = Tools.GONE)
97-
startPurchase()
98-
}
97+
if (::billingClient.isInitialized)
98+
startPurchase()
99+
} else
100+
Toast.makeText(context, "No active network", Toast.LENGTH_SHORT).show()
99101
}
100102
R.id.btn_rate -> {
101103
val intent = Intent(Intent.ACTION_VIEW, Uri.parse(appUrl))
@@ -247,9 +249,11 @@ class SettingFragment : Fragment(), View.OnClickListener {
247249
.build()
248250

249251
billingClient.querySkuDetailsAsync(skuDetailParam) { _, skuDetailsList ->
250-
skuDetails = skuDetailsList[0] as SkuDetails
251-
if (skuDetails.price != null) {
252-
bind.btnRemoveAds.text = skuDetails.price // Set product price to button text
252+
if (skuDetailsList.isNotEmpty()) {
253+
skuDetails = skuDetailsList[0] as SkuDetails
254+
if (skuDetails.price != null) {
255+
bind.btnRemoveAds.text = "Check & Pay ${skuDetails.price}" // Set product price to button text
256+
}
253257
}
254258
}
255259
}

app/src/main/java/com/techflow/materialcolor/utils/SharedPref.kt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,4 +41,17 @@ class SharedPref constructor(context: Context){
4141
}
4242
}
4343

44+
fun actionShowInterstitialAd(): Boolean {
45+
var count = getInt("clicks_count", 1)
46+
var isReset = false
47+
if (count < 9)
48+
count++
49+
else {
50+
count = 1
51+
isReset = true
52+
}
53+
54+
saveData("clicks_count", count)
55+
return isReset
56+
}
4457
}

app/src/main/res/layout/activity_welcome.xml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,15 +33,14 @@
3333
android:textSize="32.0sp" />
3434
</LinearLayout>
3535

36-
<androidx.emoji.widget.EmojiTextView
36+
<TextView
3737
android:id="@+id/tv_bottom_msg"
3838
android:layout_width="wrap_content"
3939
android:layout_height="wrap_content"
4040
android:layout_gravity="bottom|center_horizontal"
4141
android:layout_marginStart="8dp"
4242
android:layout_marginEnd="8dp"
4343
android:layout_marginBottom="16dp"
44-
android:imeOptions="actionSend"
4544
android:inputType="textCapSentences|textMultiLine"
4645
android:textColor="?attr/colorTextPrimary"
4746
app:layout_constraintBottom_toBottomOf="parent"

app/src/main/res/layout/fragment_setting.xml

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,27 +55,28 @@
5555
android:layout_width="wrap_content"
5656
android:layout_height="wrap_content"
5757
android:layout_marginStart="16dp"
58-
android:layout_marginBottom="16dp"
5958
android:text="Remove ads forever"
6059
android:textColor="?attr/colorTextSecondary"
61-
app:layout_constraintBottom_toBottomOf="parent"
6260
app:layout_constraintStart_toStartOf="parent"
6361
app:layout_constraintTop_toBottomOf="@+id/textView5" />
6462

6563
<com.google.android.material.button.MaterialButton
6664
android:id="@+id/btn_remove_ads"
6765
style="@style/Widget.MaterialComponents.Button"
68-
android:layout_width="wrap_content"
66+
android:layout_width="0dp"
6967
android:layout_height="wrap_content"
68+
android:layout_marginStart="16dp"
7069
android:layout_marginTop="8dp"
7170
android:layout_marginEnd="16dp"
7271
android:layout_marginBottom="8dp"
73-
android:text="REMOVE"
72+
android:text="Check &amp; Pay"
73+
android:textAllCaps="false"
7474
android:textStyle="bold"
7575
app:backgroundTint="@color/colorAccent"
7676
app:layout_constraintBottom_toBottomOf="parent"
7777
app:layout_constraintEnd_toEndOf="parent"
78-
app:layout_constraintTop_toTopOf="parent" />
78+
app:layout_constraintStart_toStartOf="parent"
79+
app:layout_constraintTop_toBottomOf="@+id/textView6" />
7980

8081
<ProgressBar
8182
android:id="@+id/progress_bar"

0 commit comments

Comments
 (0)