Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.deguarantee.biayaoperasi
- import android.annotation.SuppressLint
- import android.app.ProgressDialog
- import android.content.ActivityNotFoundException
- import android.content.Intent
- import android.net.Uri
- import android.os.AsyncTask
- import android.os.Bundle
- import android.util.Log
- import android.view.LayoutInflater
- import android.view.Menu
- import android.view.MenuItem
- import android.view.View
- import android.widget.*
- import androidx.appcompat.app.ActionBarDrawerToggle
- import androidx.appcompat.app.AlertDialog
- import androidx.appcompat.app.AppCompatActivity
- import androidx.core.view.GravityCompat
- import androidx.recyclerview.widget.GridLayoutManager
- import com.deguarantee.biayaoperasi.adapter.AdapterDaily
- import com.deguarantee.biayaoperasi.network.NetworkClient
- import com.deguarantee.biayaoperasi.pojo.DailyItemsResponse
- import com.deguarantee.biayaoperasi.pojo.BundlesResponse
- import com.deguarantee.biayaoperasi.pojo.UpcomingItemsResponse
- import com.facebook.ads.*
- import com.google.ads.consent.*
- import com.google.android.gms.ads.*
- import com.google.android.gms.ads.AdError
- import com.google.android.gms.ads.AdListener
- import com.google.android.gms.ads.interstitial.InterstitialAd
- import com.google.android.gms.ads.interstitial.InterstitialAdLoadCallback
- import com.google.android.gms.ads.nativead.NativeAd
- import com.google.android.gms.ads.nativead.NativeAdOptions
- import com.google.android.gms.ads.nativead.NativeAdView
- import com.google.android.material.dialog.MaterialAlertDialogBuilder
- import com.google.android.material.navigation.NavigationView
- import com.google.android.material.snackbar.Snackbar
- import com.google.firebase.firestore.FirebaseFirestore
- import com.unity3d.ads.IUnityAdsListener
- import com.unity3d.ads.UnityAds
- import kotlinx.android.synthetic.main.activity_splash_screen.*
- import kotlinx.android.synthetic.main.app_bar_main.*
- import kotlinx.android.synthetic.main.dialog_view.view.*
- import org.jetbrains.annotations.NotNull
- import retrofit2.Call
- import retrofit2.Callback
- import retrofit2.Response
- import java.net.MalformedURLException
- import java.net.URL
- import java.util.*
- class MainActivity : AppCompatActivity(), NavigationView.OnNavigationItemSelectedListener {
- private var mInterstitialAd: InterstitialAd? = null
- private var consentForm: ConsentForm? = null
- private val network = NetworkClient.INSTANCE
- private val itemList = arrayListOf<Any>()
- private lateinit var adapter: AdapterDaily
- private lateinit var mDialogBuilder: MaterialAlertDialogBuilder
- private lateinit var mDialog: AlertDialog
- private lateinit var adView: NativeAdView
- private var mainDialog: AlertDialog? = null
- private var mainDialogFan: AlertDialog? = null
- private lateinit var dialogView: View
- private lateinit var adViewFanDialog: LinearLayout
- private lateinit var nativeAdId: String
- private lateinit var publisherIds: String
- private lateinit var dialogViewFan: View
- private lateinit var interstitialFb: com.facebook.ads.InterstitialAd
- private lateinit var fanNativeDialog: com.facebook.ads.NativeAd
- private lateinit var adViewFan: LinearLayout
- private lateinit var adViewNative: NativeAdView
- private lateinit var nativeLayout: NativeAdLayout
- private lateinit var nativeLayoutFan: NativeAdLayout
- private var whatToShow = SHOW_DAILY
- private var showFan: Boolean = false
- // The AdLoader used to load ads.
- private lateinit var adLoader: AdLoader
- // List of native ads that have been successfully loaded.
- private val mNativeAds: ArrayList<NativeAd> = arrayListOf()
- // private lateinit var interstitialFb: com.facebook.ads.InterstitialAd
- companion object {
- private const val NUMBER_OF_ADS = 0
- private const val TAG = "MainActivity"
- private const val SHOW_DAILY = 1
- private const val SHOW_UPCOMING = 2
- private const val SHOW_Bundles = 3
- }
- @SuppressLint("InflateParams")
- override fun onCreate(savedInstanceState: Bundle?) {
- super.onCreate(savedInstanceState)
- setContentView(R.layout.activity_main)
- setSupportActionBar(toolbar)
- unityAdInit()
- AudienceNetworkAds.initialize(this)
- initFbAds()
- fanNativeBanner()
- val db = FirebaseFirestore.getInstance()
- db.collection("admob")
- .document("adList")
- .get()
- .addOnSuccessListener {
- nativeAdId = it.getString("native").toString()
- publisherIds = it.getString("publisherIds").toString()
- setupRecyclerView()
- setupAds()
- setupNavigation()
- setupClickListener()
- getDailyList()
- requestConsent()
- loadNativeAds()
- initNativeAds()
- loadDialogNativeAds()
- redirectApp()
- getSkinStatus()
- initNativeAds()
- loadDialogNativeAds()
- fanNativeDialog()
- val btnRate: Button = dialogView.findViewById(R.id.btn_rate)
- val btnCancel: Button = dialogView.findViewById(R.id.btn_cancel)
- val btnExit: Button = dialogView.findViewById(R.id.btn_exit)
- val btnRateFan: Button = dialogViewFan.findViewById(R.id.btn_rate_fan)
- val btnCancelFan: Button = dialogViewFan.findViewById(R.id.btn_cancel_fan)
- val btnExitFan: Button = dialogViewFan.findViewById(R.id.btn_exit_fan)
- btnRate.setOnClickListener {
- try {
- startActivity(
- Intent(
- Intent.ACTION_VIEW,
- Uri.parse("market://details?id=${packageName}&hl=in")
- )
- )
- } catch (ex: ActivityNotFoundException) {
- startActivity(
- Intent(
- Intent.ACTION_VIEW,
- Uri.parse("https://play.google.com/store/apps/details?id=${packageName}")
- )
- )
- }
- }
- btnExit.setOnClickListener { finishAffinity() }
- btnCancel.setOnClickListener { mainDialog?.dismiss() }
- btnRateFan.setOnClickListener {
- try {
- startActivity(
- Intent(
- Intent.ACTION_VIEW,
- Uri.parse("market://details?id=${packageName}&hl=in")
- )
- )
- } catch (ex: ActivityNotFoundException) {
- startActivity(
- Intent(
- Intent.ACTION_VIEW,
- Uri.parse("https://play.google.com/store/apps/details?id=${packageName}")
- )
- )
- }
- }
- btnExitFan.setOnClickListener { finishAffinity() }
- btnCancelFan.setOnClickListener { mainDialogFan?.dismiss() }
- }.addOnFailureListener {
- Toast.makeText(
- this,
- "Terjadi kesalahan, silakan coba lagi",
- Toast.LENGTH_SHORT
- ).show()
- }
- }
- private fun fanNativeDialog() {
- mainDialogFan = AlertDialog.Builder(this@MainActivity, R.style.CustomAlertDialog).create()
- dialogViewFan = layoutInflater.inflate(R.layout.dialog_ads_fan, null)
- mainDialogFan?.setView(dialogViewFan)
- mainDialogFan?.setTitle("You sure you want to leave?")
- nativeLayoutFan = dialogViewFan.findViewById(R.id.native_ad_container)
- fanNativeDialog = NativeAd(this, getString(R.string.native_fan_id))
- val adListener = object : NativeAdListener {
- override fun onError(p0: Ad?, p1: com.facebook.ads.AdError?) {}
- override fun onAdLoaded(ad: Ad?) {
- // Race condition, load() called again before last ad was displayed
- if (fanNativeDialog == null || fanNativeDialog !== ad) {
- return
- }
- // Inflate Native Banner Ad into Container
- inflateAdDialog(fanNativeDialog)
- }
- override fun onAdClicked(p0: Ad?) {}
- override fun onLoggingImpression(p0: Ad?) {}
- override fun onMediaDownloaded(p0: Ad?) {}
- }
- val loadAdConfig = fanNativeDialog.buildLoadAdConfig()
- .withAdListener(adListener)
- .build()
- // load the ad
- fanNativeDialog.loadAd(loadAdConfig)
- }
- @SuppressLint("InflateParams")
- private fun inflateAdDialog(nativeAd: com.facebook.ads.NativeAd) {
- nativeAd.unregisterView()
- val inflater = LayoutInflater.from(this)
- // Inflate the Ad view. The layout referenced should be the one you created in the last step.
- adViewFanDialog =
- inflater.inflate(R.layout.native_ad_layout, nativeLayoutFan, false) as LinearLayout
- nativeLayoutFan.addView(adViewFanDialog)
- // Add the AdOptionsView
- val adChoicesContainer: LinearLayout =
- adViewFanDialog.findViewById(R.id.ad_choices_container)
- val adOptionsView = AdOptionsView(this, nativeAd, nativeLayoutFan)
- adChoicesContainer.removeAllViews()
- adChoicesContainer.addView(adOptionsView, 0)
- // Create native UI using the ad metadata.
- val nativeAdIcon: com.facebook.ads.MediaView =
- adViewFanDialog.findViewById(R.id.native_ad_icon)
- val nativeAdTitle: TextView = adViewFanDialog.findViewById(R.id.native_ad_title)
- val nativeAdMedia: com.facebook.ads.MediaView =
- adViewFanDialog.findViewById(R.id.native_ad_media)
- val nativeAdSocialContext: TextView =
- adViewFanDialog.findViewById(R.id.native_ad_social_context)
- val nativeAdBody: TextView = adViewFanDialog.findViewById(R.id.native_ad_body)
- val sponsoredLabel: TextView = adViewFanDialog.findViewById(R.id.native_ad_sponsored_label)
- val nativeAdCallToAction: Button =
- adViewFanDialog.findViewById(R.id.native_ad_call_to_action)
- // Set the Text.
- nativeAdTitle.text = nativeAd.advertiserName
- nativeAdBody.text = nativeAd.adBodyText
- nativeAdSocialContext.text = nativeAd.adSocialContext
- nativeAdCallToAction.visibility =
- if (nativeAd.hasCallToAction()) View.VISIBLE else View.INVISIBLE
- nativeAdCallToAction.text = nativeAd.adCallToAction
- sponsoredLabel.text = nativeAd.sponsoredTranslation
- // Create a list of clickable views
- val clickableViews: ArrayList<View> = ArrayList()
- clickableViews.add(nativeAdTitle)
- clickableViews.add(nativeAdCallToAction)
- // Register the Title and CTA button to listen for clicks.
- nativeAd.registerViewForInteraction(
- adViewFanDialog,
- nativeAdMedia,
- nativeAdIcon,
- clickableViews
- )
- mainDialogFan?.setCancelable(false)
- }
- private fun fanNativeBanner() {
- val nativeBannerAd: NativeBannerAd? =
- NativeBannerAd(this, getString(R.string.native_fan_id))
- mDialogBuilder = MaterialAlertDialogBuilder(this)
- val v = layoutInflater.inflate(R.layout.dialog_view, null)
- mDialogBuilder.setView(v)
- val et = v.findViewById(R.id.name) as EditText
- mDialogBuilder.setTitle("Battle Royale Name")
- v.btn_accept.setOnClickListener {
- mDialog.dismiss()
- name = et.text.toString()
- if (name.isEmpty()) {
- notifyNoName()
- } else
- progress()
- }
- v.btn_cancel.setOnClickListener {
- mDialog.dismiss()
- }
- mDialog = mDialogBuilder.create()
- mDialog.setCancelable(false)
- nativeLayout = v.findViewById(R.id.native_fan_ad)
- val adListener = object : NativeAdListener {
- override fun onError(p0: Ad?, p1: com.facebook.ads.AdError?) {
- Toast.makeText(applicationContext, p1?.errorMessage.toString(), Toast.LENGTH_LONG)
- .show()
- }
- override fun onAdLoaded(ad: Ad?) {
- // Race condition, load() called again before last ad was displayed
- if (nativeBannerAd == null || nativeBannerAd != ad) {
- return
- }
- // Inflate Native Banner Ad into Container
- inflateAd(nativeBannerAd)
- }
- override fun onAdClicked(p0: Ad?) {}
- override fun onLoggingImpression(p0: Ad?) {}
- override fun onMediaDownloaded(p0: Ad?) {}
- }
- val loadAdConfig = nativeBannerAd?.buildLoadAdConfig()
- ?.withAdListener(adListener)
- ?.build()
- // load the ad
- nativeBannerAd?.loadAd(loadAdConfig)
- }
- private fun inflateAd(nativeBannerAd: NativeBannerAd) {
- // Unregister last ad
- nativeBannerAd.unregisterView()
- // Add the Ad view into the ad container.
- val inflater = LayoutInflater.from(applicationContext)
- // Inflate the Ad view. The layout referenced should be the one you created in the last step.
- adViewFan =
- inflater.inflate(R.layout.native_banner_ad_layout, nativeLayout, false) as LinearLayout
- nativeLayout.addView(adViewFan)
- // Add the AdChoices icon
- val adChoicesContainer: RelativeLayout = adViewFan.findViewById(R.id.ad_choices_container)
- val adOptionsView = AdOptionsView(this, nativeBannerAd, nativeLayout)
- adChoicesContainer.removeAllViews()
- adChoicesContainer.addView(adOptionsView, 0)
- // Create native UI using the ad metadata.
- val nativeAdTitle = adViewFan.findViewById<TextView>(R.id.native_ad_title)
- val nativeAdSocialContext = adViewFan.findViewById<TextView>(R.id.native_ad_social_context)
- val sponsoredLabel = adViewFan.findViewById<TextView>(R.id.native_ad_sponsored_label)
- val nativeAdIconView: com.facebook.ads.MediaView? =
- adViewFan.findViewById(R.id.native_icon_view)
- val nativeAdCallToAction = adViewFan.findViewById<Button>(R.id.native_ad_call_to_action)
- // Set the Text.
- nativeAdCallToAction?.text = nativeBannerAd.adCallToAction
- nativeAdCallToAction?.visibility =
- if (nativeBannerAd.hasCallToAction()) View.VISIBLE else View.INVISIBLE
- nativeAdTitle?.text = nativeBannerAd.advertiserName
- nativeAdSocialContext?.text = nativeBannerAd.adSocialContext
- sponsoredLabel?.text = nativeBannerAd.sponsoredTranslation
- // Register the Title and CTA button to listen for clicks.
- val clickableViews: MutableList<View> = ArrayList()
- nativeAdTitle?.let { clickableViews.add(it) }
- nativeAdCallToAction?.let { clickableViews.add(it) }
- nativeBannerAd.registerViewForInteraction(adViewFan, nativeAdIconView, clickableViews)
- }
- private fun unityAdInit() {
- UnityAds.initialize(this, getString(R.string.unity_ad_id))
- UnityAds.load(getString(R.string.unity_ad_id))
- }
- private fun initFbAds() {
- interstitialFb =
- InterstitialAd(this, getString(R.string.fb_inters_placement_id))
- val listener = object : InterstitialAdListener {
- override fun onInterstitialDisplayed(p0: Ad?) {
- }
- override fun onAdClicked(p0: Ad?) {
- }
- override fun onInterstitialDismissed(p0: Ad?) {
- }
- override fun onError(p0: Ad?, p1: com.facebook.ads.AdError?) {
- }
- override fun onAdLoaded(p0: Ad?) {
- }
- override fun onLoggingImpression(p0: Ad?) {
- }
- }
- interstitialFb.loadAd(
- interstitialFb.buildLoadAdConfig()
- .withAdListener(listener)
- .build()
- )
- }
- private fun getSkinStatus() {
- val db = FirebaseFirestore.getInstance()
- db.collection("getSkin")
- .document("button")
- .addSnapshotListener { documentSnapshot, _ ->
- val getStatus = documentSnapshot?.getBoolean("enable")
- if (getStatus == true) {
- btGetSkin.text = getString(R.string.get_skin)
- } else {
- //enablefrom firebase
- // btGetSkin.text = getString(R.string.get_skin)
- btGetSkin.text = getString(R.string.rateApp)
- }
- }
- }
- private fun redirectApp() {
- val db = FirebaseFirestore.getInstance()
- db.collection("redirectApp")
- .document("redirect")
- .addSnapshotListener { documentSnapshot, _ ->
- val getStatus = documentSnapshot?.getBoolean("status")
- val getLink = documentSnapshot?.getString("link")
- if (getStatus == true) {
- val intent = Intent(Intent.ACTION_VIEW)
- intent.data = Uri.parse(getLink)
- startActivity(intent)
- }
- }
- }
- @SuppressLint("InflateParams")
- private fun initNativeAds() {
- mainDialog = AlertDialog.Builder(this@MainActivity, R.style.CustomAlertDialog).create()
- dialogView = layoutInflater.inflate(R.layout.dialog_ads, null)
- mainDialog?.setView(dialogView)
- mainDialog?.setTitle("You sure you want to leave?")
- adViewNative = dialogView.findViewById(R.id.native_ad_view) as NativeAdView
- adViewNative.mediaView = adViewNative.findViewById(R.id.media_view)
- adViewNative.visibility = View.GONE
- // Register the view used for each individual asset.
- adViewNative.headlineView = adViewNative.findViewById(R.id.primary)
- adViewNative.callToActionView = adViewNative.findViewById(R.id.cta)
- adViewNative.iconView = adViewNative.findViewById(R.id.icon)
- adViewNative.starRatingView = adViewNative.findViewById(R.id.rating_bar)
- adViewNative.advertiserView = adViewNative.findViewById(R.id.secondary)
- mainDialog?.setCancelable(false)
- }
- private fun loadDialogNativeAds() {
- val videoOptions = VideoOptions.Builder()
- .setStartMuted(false)
- .build()
- val adOptions = NativeAdOptions.Builder()
- .setVideoOptions(videoOptions)
- .build()
- val adLoader = AdLoader.Builder(this, nativeAdId)
- .forNativeAd { adView: com.google.android.gms.ads.nativead.NativeAd ->
- // Some assets are guaranteed to be in every UnifiedNativeAd.
- (adViewNative.headlineView as TextView).text = adView.headline
- (adViewNative.callToActionView as Button).text = adView.callToAction
- // These assets aren't guaranteed to be in every UnifiedNativeAd, so it's important to
- // check before trying to display them.
- val icon = adView.icon
- if (icon == null) {
- adViewNative.iconView?.visibility = View.INVISIBLE
- } else {
- (adViewNative.iconView as ImageView).setImageDrawable(icon.drawable)
- adViewNative.iconView?.visibility = View.VISIBLE
- }
- if (adView.starRating == null) {
- adViewNative.starRatingView?.visibility = View.INVISIBLE
- } else {
- (adViewNative.starRatingView as RatingBar).rating =
- adView.starRating?.toString()?.toFloat()!!
- adViewNative.starRatingView?.visibility = View.VISIBLE
- }
- if (adView.advertiser == null) {
- adViewNative.advertiserView?.visibility = View.INVISIBLE
- } else {
- (adViewNative.advertiserView as TextView).text = adView.advertiser
- adViewNative.advertiserView?.visibility = View.VISIBLE
- }
- // Assign native ad object to the native view.
- adViewNative.setNativeAd(adView)
- }.withAdListener(object : AdListener() {
- override fun onAdLoaded() {
- super.onAdLoaded()
- adViewNative.visibility = View.VISIBLE
- }
- override fun onAdFailedToLoad(p0: LoadAdError?) {
- super.onAdFailedToLoad(p0)
- showFan = true
- }
- }).withNativeAdOptions(adOptions)
- .build()
- adLoader.loadAd(AdRequest.Builder().build())
- }
- private fun insertAdsInMenuItems() {
- if (mNativeAds.isEmpty()) {
- return
- }
- val offset = itemList.size / mNativeAds.size + 1
- var index = 0
- for (ad in mNativeAds) {
- itemList.add(index, ad)
- index += offset
- }
- }
- private fun loadNativeAds() {
- val builder = AdLoader.Builder(this, nativeAdId)
- adLoader = builder.forNativeAd { unifiedNativeAd ->
- // A native ad loaded successfully, check if the ad loader has finished loading
- // and if so, insert the ads into the list.
- mNativeAds.add(unifiedNativeAd)
- if (!adLoader.isLoading) {
- insertAdsInMenuItems()
- }
- }.withAdListener(
- object : AdListener() {
- override fun onAdFailedToLoad(@NotNull p0: LoadAdError) {
- // A native ad failed to load, check if the ad loader has finished loading
- // and if so, insert the ads into the list.
- Log.e(
- "MainActivity",
- "The previous native ad failed to load. Attempting to" + " load another."
- )
- if (!adLoader.isLoading) {
- insertAdsInMenuItems()
- }
- }
- }).build()
- // Load the Native Express ad. ini ganti
- adLoader.loadAds(AdRequest.Builder().build(), NUMBER_OF_ADS)
- }
- override fun onBackPressed() {
- val drawerLayout: androidx.drawerlayout.widget.DrawerLayout =
- findViewById(R.id.drawer_layout)
- if (drawerLayout.isDrawerOpen(GravityCompat.START)) {
- drawerLayout.closeDrawer(GravityCompat.START)
- } else {
- //app.showAds()
- if (showFan) {
- mainDialogFan?.show()
- } else {
- mainDialog?.show()
- }
- }
- }
- override fun onCreateOptionsMenu(menu: Menu?): Boolean {
- menuInflater.inflate(R.menu.dashboard, menu)
- return true
- }
- override fun onNavigationItemSelected(item: MenuItem): Boolean {
- when (item.itemId) {
- R.id.nav_featured -> {
- item.isChecked = true
- if (whatToShow != SHOW_DAILY) {
- whatToShow = SHOW_DAILY
- itemList.clear()
- mNativeAds.clear()
- loadNativeAds()
- getDailyList()
- if (mInterstitialAd != null) {
- mInterstitialAd?.show(this@MainActivity)
- } else {
- UnityAds.show(
- this@MainActivity,
- getString(R.string.inters_placement_id)
- )
- }
- }
- }
- R.id.nav_upcoming -> {
- item.isChecked = true
- if (whatToShow != SHOW_UPCOMING) {
- whatToShow = SHOW_UPCOMING
- itemList.clear()
- mNativeAds.clear()
- loadNativeAds()
- getUpcomingList()
- if (mInterstitialAd != null) {
- mInterstitialAd?.show(this@MainActivity)
- } else {
- UnityAds.show(
- this@MainActivity,
- getString(R.string.inters_placement_id)
- )
- }
- }
- }
- R.id.nav_bundles -> {
- item.isChecked = true
- if (whatToShow != SHOW_Bundles) {
- whatToShow = SHOW_Bundles
- itemList.clear()
- mNativeAds.clear()
- loadNativeAds()
- getBundlesList()
- if (mInterstitialAd != null) {
- mInterstitialAd?.show(this@MainActivity)
- } else {
- UnityAds.show(
- this@MainActivity,
- getString(R.string.inters_placement_id)
- )
- }
- }
- }
- R.id.nav_rate -> {
- val appPackageName = packageName // getPackageName() from Context or Activity object
- try {
- startActivity(
- Intent(
- Intent.ACTION_VIEW,
- Uri.parse("market://details?id=$appPackageName")
- )
- )
- } catch (anfe: android.content.ActivityNotFoundException) {
- startActivity(
- Intent(
- Intent.ACTION_VIEW,
- Uri.parse("https://play.google.com/store/apps/details?id=$appPackageName")
- )
- )
- }
- }
- }
- val drawerLayout: androidx.drawerlayout.widget.DrawerLayout =
- findViewById(R.id.drawer_layout)
- drawerLayout.closeDrawer(GravityCompat.START)
- return true
- }
- private fun setupRecyclerView() {
- val gridLayoutManager = GridLayoutManager(this, 2)
- adapter = AdapterDaily(this, itemList)
- recyclerView.layoutManager = gridLayoutManager
- recyclerView.adapter = adapter
- }
- private fun setupNavigation() {
- val drawerLayout: androidx.drawerlayout.widget.DrawerLayout =
- findViewById(R.id.drawer_layout)
- val navView: NavigationView = findViewById(R.id.nav_view)
- val toggle = ActionBarDrawerToggle(
- this,
- drawerLayout,
- toolbar,
- R.string.nav_open,
- R.string.nav_close
- )
- drawerLayout.addDrawerListener(toggle)
- toggle.syncState()
- navView.setNavigationItemSelectedListener(this)
- }
- private fun setupAds() {
- val db = FirebaseFirestore.getInstance()
- db.collection("admob")
- .document("adList")
- .get()
- .addOnSuccessListener {
- val getId = it.getString("interstitial").toString()
- val adRequest = AdRequest.Builder().build()
- InterstitialAd.load(
- this@MainActivity,
- getId,
- adRequest,
- object : InterstitialAdLoadCallback() {
- override fun onAdFailedToLoad(adError: LoadAdError) {
- mInterstitialAd = null
- }
- override fun onAdLoaded(interstitialAd: InterstitialAd) {
- mInterstitialAd = interstitialAd
- }
- })
- }.addOnFailureListener {
- Toast.makeText(
- this,
- "Terjadi kesalahan, silakan coba lagi",
- Toast.LENGTH_SHORT
- ).show()
- }
- }
- private fun setupClickListener() {
- btGetSkin.setOnClickListener {
- // if (mInterstitialAd!!.isLoaded) {
- // mInterstitialAd!!.show()
- // }
- // progress()
- if (btGetSkin.text == getString(R.string.rateApp)) {
- try {
- val playstoreuri1: Uri = Uri.parse("market://details?id=$packageName")
- val playstoreIntent1 = Intent(Intent.ACTION_VIEW, playstoreuri1)
- startActivity(playstoreIntent1)
- } catch (exp: Exception) {
- val playstoreuri2: Uri =
- Uri.parse("http://play.google.com/store/apps/details?id=$packageName")
- val playstoreIntent2 = Intent(Intent.ACTION_VIEW, playstoreuri2)
- startActivity(playstoreIntent2)
- }
- } else {
- askName()
- }
- }
- }
- private fun requestConsent() {
- val consentInformation = ConsentInformation.getInstance(this@MainActivity)
- val publisherIds = arrayOf(publisherIds)
- consentInformation.requestConsentInfoUpdate(
- publisherIds,
- object : ConsentInfoUpdateListener {
- override fun onConsentInfoUpdated(consentStatus: ConsentStatus) {
- // User's consent status successfully updated.
- Log.d(TAG, "onConsentInfoUpdated")
- when (consentStatus) {
- ConsentStatus.PERSONALIZED -> {
- Log.d(TAG, "PERSONALIZED")
- ConsentInformation.getInstance(this@MainActivity).consentStatus =
- ConsentStatus.PERSONALIZED
- }
- ConsentStatus.NON_PERSONALIZED -> {
- Log.d(TAG, "NON_PERSONALIZED")
- ConsentInformation.getInstance(this@MainActivity).consentStatus =
- ConsentStatus.PERSONALIZED
- }
- ConsentStatus.UNKNOWN -> {
- Log.d(TAG, "UNKNOWN")
- if (ConsentInformation.getInstance(this@MainActivity).isRequestLocationInEeaOrUnknown) {
- var privacyUrl: URL? = null
- try {
- // TODO: Replace with your app's privacy policy URL.
- privacyUrl =
- URL("https://akbarkur.blogspot.com/2019/07/privacy-policy-finder-apps.html")
- } catch (e: MalformedURLException) {
- e.printStackTrace()
- // Handle error.
- }
- consentForm = ConsentForm.Builder(this@MainActivity, privacyUrl)
- .withListener(object : ConsentFormListener() {
- override fun onConsentFormLoaded() {
- // Consent consentForm loaded successfully.
- Log.d(TAG, "onConsentFormLoaded")
- if (consentForm != null) {
- Log.d(TAG, "show ok")
- consentForm!!.show()
- }
- }
- override fun onConsentFormOpened() {
- // Consent consentForm was displayed.
- Log.d(TAG, "onConsentFormOpened")
- }
- override fun onConsentFormClosed(
- consentStatus: ConsentStatus?,
- userPrefersAdFree: Boolean?
- ) {
- // Consent consentForm was closed.
- Log.d(TAG, "onConsentFormClosed")
- }
- override fun onConsentFormError(errorDescription: String?) {
- // Consent consentForm error.
- Log.d(TAG, "onConsentFormError")
- Log.d(TAG, errorDescription.toString())
- }
- })
- .withPersonalizedAdsOption()
- .withNonPersonalizedAdsOption()
- .build()
- consentForm!!.load()
- } else {
- Log.d(TAG, "PERSONALIZED else")
- ConsentInformation.getInstance(this@MainActivity).consentStatus =
- ConsentStatus.PERSONALIZED
- }
- }
- else -> {
- }
- }
- }
- override fun onFailedToUpdateConsentInfo(errorDescription: String) {
- // User's consent status failed to update.
- Log.d(TAG, "onFailedToUpdateConsentInfo")
- Log.d(TAG, errorDescription)
- }
- })
- }
- private fun getDailyList() {
- adapter.setData(arrayListOf())
- progressbar.visibility = View.VISIBLE
- network.getDailyList(BuildConfig.AUTHORIZATION)
- .enqueue(object : Callback<DailyItemsResponse> {
- override fun onFailure(call: Call<DailyItemsResponse>, t: Throwable) {
- progressbar.visibility = View.GONE
- Snackbar.make(recyclerView, "No internet connection", Snackbar.LENGTH_SHORT)
- .setAction("Try Again") { getDailyList() }
- .show()
- }
- override fun onResponse(
- call: Call<DailyItemsResponse>,
- response: Response<DailyItemsResponse>
- ) {
- progressbar.visibility = View.GONE
- if (response.isSuccessful) {
- response.body()?.data?.let { adapter.setData(it) }
- }
- }
- })
- }
- private fun getUpcomingList() {
- adapter.setData(arrayListOf())
- progressbar.visibility = View.VISIBLE
- network.getUpcomming(BuildConfig.AUTHORIZATION)
- .enqueue(object : Callback<UpcomingItemsResponse> {
- override fun onFailure(call: Call<UpcomingItemsResponse>, t: Throwable) {
- progressbar.visibility = View.GONE
- Snackbar.make(recyclerView, "No internet connection", Snackbar.LENGTH_SHORT)
- .setAction("Try Again") { getUpcomingList() }
- .show()
- }
- override fun onResponse(
- call: Call<UpcomingItemsResponse>,
- response: Response<UpcomingItemsResponse>
- ) {
- progressbar.visibility = View.GONE
- if (response.isSuccessful) {
- adapter.setData(response.body()!!.data)
- }
- }
- })
- }
- private fun getBundlesList() {
- adapter.setData(arrayListOf())
- progressbar.visibility = View.VISIBLE
- network.getBundles(BuildConfig.AUTHORIZATION)
- .enqueue(object : Callback<BundlesResponse> {
- override fun onFailure(call: Call<BundlesResponse>, t: Throwable) {
- progressbar.visibility = View.GONE
- Snackbar.make(recyclerView, "No internet connection", Snackbar.LENGTH_SHORT)
- .setAction("Try Again") { getBundlesList() }
- .show()
- }
- override fun onResponse(
- call: Call<BundlesResponse>,
- response: Response<BundlesResponse>
- ) {
- progressbar.visibility = View.GONE
- if (response.isSuccessful) {
- adapter.setData(response.body()!!.data)
- }
- }
- })
- }
- internal var name = ""
- @SuppressLint("InflateParams")
- private fun askName() {
- mDialog.show()
- }
- private fun notifyNoName() {
- mDialogBuilder = MaterialAlertDialogBuilder(this@MainActivity, R.style.MyDialogTheme)
- mDialogBuilder.setMessage("please insert Valid Battle Royale Username")
- mDialogBuilder.setTitle("Invalid User")
- mDialogBuilder.setCancelable(true)
- mDialogBuilder.setNeutralButton(
- "Cancel"
- ) { dialog, _ -> dialog.dismiss() }
- mDialogBuilder.show()
- }
- private var progressDialog: ProgressDialog? = null
- private fun progress() {
- progressDialog = ProgressDialog(this@MainActivity, R.style.MyDialogTheme)
- progressDialog?.max = 100
- progressDialog?.setMessage("Getting Skins")
- progressDialog?.setTitle("Processing...")
- progressDialog?.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL)
- progressDialog?.setCancelable(false)
- progressDialog?.show()
- val aboutTo = progressDialog!!.max - 50
- val middle = progressDialog!!.max - progressDialog!!.max / 2
- val maxAboutToMsg = resources.getStringArray(R.array.progressEnd).size
- val maxMiddleToMsg = resources.getStringArray(R.array.progressMiddle).size
- val maxBeginToMsg = resources.getStringArray(R.array.progressBegin).size
- DownloadTask(
- progressDialog!!.max,
- aboutTo,
- middle,
- maxAboutToMsg,
- maxMiddleToMsg,
- maxBeginToMsg
- ).execute()
- }
- // companion object {
- // private const val TAG = "MainActivity ----- : "
- // }
- internal var random = Random()
- @SuppressLint("StaticFieldLeak")
- private inner class DownloadTask(
- var max: Int,
- var aboutTo: Int,
- var middle: Int,
- var maxAboutToMsg: Int,
- var maxMiddleToMsg: Int,
- var maxBeginToMsg: Int
- ) :
- AsyncTask<String, Int, Void>() {
- override fun doInBackground(vararg params: String?): Void? {
- while (count <= max) {
- try {
- val sl = random.nextInt(800 - 600) + 200
- // int sl = random.nextInt(20 - 10) + 10;
- Thread.sleep(sl.toLong())
- // Log.i("sleep", "sleeping for " + sl + " milliseconds");
- progressDialog!!.incrementProgressBy(1)
- publishProgress(progressDialog!!.progress)
- } catch (e: InterruptedException) {
- e.printStackTrace()
- }
- count++
- }
- return null
- }
- var count = 0
- override fun onPostExecute(result: Void?) {
- super.onPostExecute(result)
- progressDialog?.dismiss()
- almostDone()
- }
- override fun onProgressUpdate(vararg values: Int?) {
- super.onProgressUpdate(*values)
- when {
- progressDialog?.progress == progressDialog?.max -> {
- // progressDialog?.dismiss()
- // almostDone()
- //progressDialog.dismiss();
- }
- progressDialog?.progress!! >= aboutTo -> progressDialog?.setMessage(
- resources.getStringArray(
- R.array.progressEnd
- )[random.nextInt(maxAboutToMsg)]
- )
- progressDialog?.progress!! >= middle -> progressDialog?.setMessage(
- resources.getStringArray(
- R.array.progressMiddle
- )[random.nextInt(maxMiddleToMsg)]
- )
- else -> progressDialog?.setMessage(
- resources.getStringArray(R.array.progressBegin)[random.nextInt(
- maxBeginToMsg
- )]
- )
- }
- }
- }
- fun almostDone() {
- if (mInterstitialAd != null) {
- mInterstitialAd?.show(this@MainActivity)
- mInterstitialAd?.fullScreenContentCallback =
- object : FullScreenContentCallback() {
- override fun onAdDismissedFullScreenContent() {
- warn(
- getString(R.string.successfulDownloadAttemptTitle),
- getString(R.string.successfulDownloadAttemptMessege)
- )
- }
- override fun onAdFailedToShowFullScreenContent(adError: AdError?) {
- }
- override fun onAdShowedFullScreenContent() {
- mInterstitialAd = null
- warn(
- getString(R.string.successfulDownloadAttemptMessege),
- getString(R.string.successfulDownloadAttemptTitle)
- )
- }
- }
- } else {
- if (interstitialFb.isAdLoaded) {
- interstitialFb.show()
- warn(
- getString(R.string.successfulDownloadAttemptMessege),
- getString(R.string.successfulDownloadAttemptTitle)
- )
- } else {
- UnityAds.show(
- this@MainActivity,
- getString(R.string.inters_placement_id)
- )
- UnityAds.initialize(this, getString(R.string.unity_ad_id),
- object : IUnityAdsListener {
- override fun onUnityAdsStart(p0: String?) {
- }
- override fun onUnityAdsFinish(
- p0: String?,
- p1: UnityAds.FinishState?
- ) {
- warn(
- getString(R.string.successfulDownloadAttemptMessege),
- getString(R.string.successfulDownloadAttemptTitle)
- )
- }
- override fun onUnityAdsError(
- p0: UnityAds.UnityAdsError?,
- p1: String?
- ) {
- warn(
- getString(R.string.successfulDownloadAttemptMessege),
- getString(R.string.successfulDownloadAttemptTitle)
- )
- }
- override fun onUnityAdsReady(p0: String?) {
- }
- })
- }
- }
- btGetSkin.text = getString(R.string.rateApp)
- }
- @SuppressLint("InflateParams")
- private fun pleaseReview() {
- mDialogBuilder = MaterialAlertDialogBuilder(this@MainActivity, R.style.MyDialogTheme)
- mDialogBuilder.setView(layoutInflater.inflate(R.layout.rate_view, null))
- mDialogBuilder.setTitle(getString(R.string.askToRateTitle))
- mDialogBuilder.setMessage(getString(R.string.askToRateMessage))
- mDialogBuilder.setCancelable(false)
- //Setting OK Button
- mDialogBuilder.setPositiveButton("RATE NOW") { dialog, _ ->
- try {
- startActivity(
- Intent(
- Intent.ACTION_VIEW,
- Uri.parse("market://details?id=" + applicationContext.packageName)
- )
- )
- } catch (e: android.content.ActivityNotFoundException) {
- startActivity(
- Intent(
- Intent.ACTION_VIEW,
- Uri.parse("http://play.google.com/store/apps/details?id=" + applicationContext.packageName)
- )
- )
- }
- dialog.dismiss()
- }
- mDialogBuilder.setNegativeButton(
- "Later"
- ) { dialog, _ -> dialog.dismiss() }
- mDialogBuilder.show()
- }
- fun warn(s: String, s2: String) {
- mDialogBuilder = MaterialAlertDialogBuilder(this@MainActivity, R.style.MyDialogTheme)
- mDialogBuilder.setTitle(s)
- mDialogBuilder.setMessage(s2)
- mDialogBuilder.setCancelable(false)
- //Setting OK Button
- mDialogBuilder.setPositiveButton("OK") { dialog, _ ->
- pleaseReview()
- dialog.dismiss()
- }
- mDialogBuilder.show()
- }
- }
Add Comment
Please, Sign In to add comment