Untitled

mail@pastecode.io avatar
unknown
plain_text
a year ago
9.9 kB
2
Indexable
Never
package com.birrthdayreminder.counntdowna.activitiesalex

import android.annotation.SuppressLint
import android.content.Context
import android.content.Intent
import android.net.ConnectivityManager
import android.os.Bundle
import android.os.Handler
import android.util.Log
import android.view.View
import com.birrthdayreminder.counntdowna.databinding.ActivitySplashAvengersBinding
import com.birrthdayreminder.counntdowna.iron_alex.baseclass.Alex_BaseActivity
import com.birrthdayreminder.counntdowna.iron_alex.iron_activity.*
import com.birrthdayreminder.counntdowna.iron_alex.main.AdsGlobalClassEveryTimeADAD
import com.birrthdayreminder.counntdowna.iron_alex.utils.ConnectionDetectorADAD
import com.birrthdayreminder.counntdowna.pvrfncmakads.pvrutils.MyPreferenceManagerADAD
import com.google.firebase.database.*
import com.google.firebase.database.ktx.database
import com.google.firebase.ktx.Firebase
import dagger.hilt.android.AndroidEntryPoint
import javax.inject.Inject

@SuppressLint("CustomSplashScreen")
@AndroidEntryPoint
class Alex_SplashActivity : Alex_BaseActivity() {

    private val mContext: Context = this
    private lateinit var binding: ActivitySplashAvengersBinding
    internal lateinit var cd: ConnectionDetectorADAD
    var banneradid = ""
    var nativeadid = ""
    var interstrealadid = ""
    var fullscreencount=""
    var moreapps = ""
    private lateinit var mDatabase: DatabaseReference


    @Inject
    lateinit var prefenrencMyPreferenceManager: MyPreferenceManagerADAD


    @SuppressLint("ClickableViewAccessibility")
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
//        window.statusBarColor = ContextCompat.getColor(applicationContext, R.color.textcolor)
        if (!isTaskRoot
            && intent.hasCategory(Intent.CATEGORY_LAUNCHER)
            && intent.action != null
            && intent.action.equals(Intent.ACTION_MAIN)
        ) {
            finish()
            return
        }

        mDatabase = Firebase.database.getReference("BirthdayCalender")
        isConnectingToInternet()
        AdsGlobalClassEveryTimeADAD.loadGoogleNative(this@Alex_SplashActivity, prefenrencMyPreferenceManager.nadId(), null)
        AdsGlobalClassEveryTimeADAD.loadbanner(this@Alex_SplashActivity, prefenrencMyPreferenceManager.getGBannerID(), null)
        AdsGlobalClassEveryTimeADAD.loadInterstitialAds(this@Alex_SplashActivity, prefenrencMyPreferenceManager.fId())

    }




    fun isConnectingToInternet(): Boolean {
        val cm = getSystemService(CONNECTIVITY_SERVICE) as ConnectivityManager
        if (cm.activeNetworkInfo != null && cm.activeNetworkInfo!!.isConnected) {
            mDatabase = FirebaseDatabase.getInstance().getReference("BirthdayCalender")
            mDatabase.child("bannerId").addValueEventListener(object : ValueEventListener {
                override fun onDataChange(snapshot: DataSnapshot) {
                    if (snapshot.exists()) {
                        banneradid = snapshot.value.toString()
                        prefenrencMyPreferenceManager.setGBannerID(snapshot.value.toString())
                        Log.d("TAG", "onDataChange:" + snapshot.value.toString())
                    }
                    else {
                        banneradid = "ca-app-pub-3940256099942544/6300978111"
                    }
                }

                override fun onCancelled(error: DatabaseError) {
                    banneradid = "ca-app-pub-3940256099942544/6300978111"
                }
            })
            mDatabase.child("fullScreenCount").addValueEventListener(object : ValueEventListener {
                override fun onDataChange(snapshot: DataSnapshot) {
                    if (snapshot.exists()) {
                        fullscreencount = snapshot.value.toString()
                        prefenrencMyPreferenceManager.fullscreencount = snapshot.value.toString()
                        Log.d("TAG", "onDataChange:" + snapshot.value.toString())
                    } else {

                        fullscreencount = "2"
                        prefenrencMyPreferenceManager.fullscreencount = snapshot.value.toString()
                    }
                }

                override fun onCancelled(error: DatabaseError) {
                    fullscreencount = "2"
                }
            })
//            mDatabase.child("splashScreenCount").addValueEventListener(object : ValueEventListener {
//                override fun onDataChange(snapshot: DataSnapshot) {
//                    if (snapshot.exists()) {
//                        splashscreencount = snapshot.value.toString()
//                        videomvpf_Preferences.getInstance().SavePrefValue(
//                            videomvpf_Preferences.SPLASHFSCN,
//                            snapshot.value.toString()
//                        )
//                        initInterstitialAd()
//                    } else {
//                        splashscreencount = "1"
//                        videomvpf_Preferences.getInstance()
//                            .SavePrefValue(videomvpf_Preferences.SPLASHFSCN, splashscreencount)
//                    }
//                }
//
//                override fun onCancelled(error: DatabaseError) {
//                    splashscreencount = "1"
//                }
//            })
            mDatabase.child("interstitialId").addValueEventListener(object : ValueEventListener {
                override fun onDataChange(snapshot: DataSnapshot) {
                    if (snapshot.exists()) {
                        interstrealadid = snapshot.value.toString()
                        Log.d("TAG", "onDataChange:" + snapshot.value.toString())
                        prefenrencMyPreferenceManager.setfId(snapshot.value.toString())

                    } else {
                        interstrealadid = "ca-app-pub-3940256099942544/1033173712"

                    }
                }

                override fun onCancelled(error: DatabaseError) {
                    interstrealadid = "ca-app-pub-3940256099942544/1033173712"
                }
            })
            mDatabase.child("nativeId").addValueEventListener(object : ValueEventListener {
                override fun onDataChange(snapshot: DataSnapshot) {
                    if (snapshot.exists()) {
                        Log.d("TAG", "onDataChange:" + snapshot.value.toString())
                        prefenrencMyPreferenceManager.setnadId(snapshot.value.toString())
                        nativeadid = snapshot.value.toString()
                    } else {

                        nativeadid = "ca-app-pub-3940256099942544/2247696110"
                    }
                }

                override fun onCancelled(error: DatabaseError) {
                    nativeadid = "ca-app-pub-3940256099942544/2247696110"
                }
            })
            mDatabase.child("moreAppUrl").addValueEventListener(object : ValueEventListener {
                override fun onDataChange(snapshot: DataSnapshot) {
                    if (snapshot.exists()) {
                        moreapps = snapshot.value.toString()
                        Log.d("TAG", "onDataChange:" + snapshot.value.toString())
                        prefenrencMyPreferenceManager.moreApps(snapshot.value.toString())
                    } else {
                        prefenrencMyPreferenceManager.moreApps(moreapps)
                        moreapps = "https://play.google.com/store/apps/developer?id=Adonis+Studio+Mobile"
                    }
                }

                override fun onCancelled(error: DatabaseError) {


                    moreapps = "https://play.google.com/store/apps/developer?id=Adonis+Studio+Mobile"
                }
            })
            return true
        } else {
            Handler().postDelayed({
                startActivity(
                    Intent(
                        this@Alex_SplashActivity,
                        MaintenanceActivity_Dynamo::class.java
                    )
                )
                finish()
            }, 3000)
        }
        return false
    }


    override fun geViewBinding(): View {
        binding = ActivitySplashAvengersBinding.inflate(layoutInflater)
        cd =
            ConnectionDetectorADAD(
                this@Alex_SplashActivity
            )
        return binding.root
    }

    override fun observeViewModel() {
        val isInternetPresent = cd.isConnectingToInternet
        if (isInternetPresent) {

            val handler = Handler()
            handler.postDelayed(runnable, AUTO_HIDE_DELAY_MILLIS)
        } else {
            setNullId()

            val handler = Handler()
            handler.postDelayed(runnable, AUTO_HIDE_DELAY_MILLIS)
        }
    }

    fun setNullId() {
        prefenrencMyPreferenceManager.setGBannerID(null)
        prefenrencMyPreferenceManager.setfId(null)
        prefenrencMyPreferenceManager.setnadId(null)
        prefenrencMyPreferenceManager.setrId(null)
//        prefenrencMyPreferenceManager.setopenId(null)
    }



    companion object {
        private const val AUTO_HIDE_DELAY_MILLIS = 1500L



        fun isNetworkAvailable(context: Context): Boolean {
            val activeNetworkInfo =
                (context.getSystemService(CONNECTIVITY_SERVICE) as ConnectivityManager).activeNetworkInfo
            return activeNetworkInfo != null && activeNetworkInfo.isConnected
        }
    }

    private var runnable = Runnable {
        startActivity(Intent(mContext, DashboardActivity_Dynamo::class.java))
            finishAffinity()

    }
}