diff --git a/NiloPartner/app/src/main/java/com/barryzea/niloclient/MainActivity.kt b/NiloPartner/app/src/main/java/com/barryzea/niloclient/MainActivity.kt
index 7111d4a..b0a1080 100644
--- a/NiloPartner/app/src/main/java/com/barryzea/niloclient/MainActivity.kt
+++ b/NiloPartner/app/src/main/java/com/barryzea/niloclient/MainActivity.kt
@@ -28,6 +28,7 @@ import com.barryzea.niloclient.interfaces.OnProductListener
import com.barryzea.niloclient.order.OrderActivity
import com.barryzea.niloclient.pojo.Product
import com.barryzea.niloclient.profile.ProfileFragment
+import com.barryzea.niloclient.promo.PromoFragment
import com.barryzea.niloclient.settings.SettingsActivity
import com.barryzea.niloclient.settings.SettingsFragment
import com.firebase.ui.auth.AuthMethodPickerLayout
@@ -310,7 +311,12 @@ class MainActivity : AppCompatActivity(), OnProductListener, MainAux {
startActivity(Intent(this, SettingsActivity::class.java))
}
R.id.itemPromo->{
-
+ val fragment=PromoFragment()
+ supportFragmentManager
+ .beginTransaction()
+ .add(R.id.containerMain, fragment)
+ .addToBackStack(null)
+ .commit()
}
}
return super.onOptionsItemSelected(item)
diff --git a/NiloPartner/app/src/main/java/com/barryzea/niloclient/promo/PromoFragment.kt b/NiloPartner/app/src/main/java/com/barryzea/niloclient/promo/PromoFragment.kt
new file mode 100644
index 0000000..34e312c
--- /dev/null
+++ b/NiloPartner/app/src/main/java/com/barryzea/niloclient/promo/PromoFragment.kt
@@ -0,0 +1,110 @@
+package com.barryzea.niloclient.promo
+
+import android.annotation.SuppressLint
+import android.os.Bundle
+import android.view.*
+import androidx.appcompat.app.AppCompatActivity
+import androidx.fragment.app.Fragment
+import com.barryzea.niloclient.R
+import com.barryzea.niloclient.databinding.FragmentPromoBinding
+import com.barryzea.niloclient.interfaces.MainAux
+import com.bumptech.glide.Glide
+import com.bumptech.glide.load.engine.DiskCacheStrategy
+import com.google.android.material.badge.BadgeDrawable
+import com.google.android.material.badge.BadgeUtils
+import com.google.firebase.ktx.Firebase
+import com.google.firebase.remoteconfig.ktx.remoteConfig
+import com.google.firebase.remoteconfig.ktx.remoteConfigSettings
+import kotlin.math.roundToInt
+
+/****
+ * Project Nilo Client
+ * Created by Barry Zea H. on 28/02/2022.
+ * Copyright (c) All rights reserved.
+ ***/
+
+class PromoFragment: Fragment() {
+ private var bind:FragmentPromoBinding?=null
+ private var title:String=""
+
+ override fun onCreateView(
+ inflater: LayoutInflater,
+ container: ViewGroup?,
+ savedInstanceState: Bundle?
+ ): View? {
+ bind= FragmentPromoBinding.inflate(inflater, container, false)
+ bind?.let{
+ return it.root
+ }
+
+ return super.onCreateView(inflater, container, savedInstanceState)
+
+ }
+
+ override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
+ super.onViewCreated(view, savedInstanceState)
+ configToolbar()
+ configRemoteConfig()
+ }
+ private fun configToolbar(){
+ (activity as? MainAux)?.showButton(false)
+ (activity as? AppCompatActivity)?.apply {
+ supportActionBar?.setDisplayHomeAsUpEnabled(true)
+ title=supportActionBar?.title
+ supportActionBar?.title=getString(R.string.promo_fragment_title)
+ setHasOptionsMenu(true)
+
+ }
+ }
+ @SuppressLint("UnsafeOptInUsageError")
+ private fun configRemoteConfig() {
+ val remoteConfig= Firebase.remoteConfig
+ remoteConfig.setDefaultsAsync(R.xml.remote_config_default)
+ //solicitar y extraer datos de remoteconfig
+ remoteConfig.fetchAndActivate()
+
+ //si no hay ningún error se extraerán los datos ya sea desde el servidor o localmente
+ .addOnCompleteListener {
+ if(it.isSuccessful){
+
+ val percentage=remoteConfig.getDouble("percentage")
+ val photoUrl=remoteConfig.getString("photoUrl")
+ val message=remoteConfig.getString("message")
+ bind?.let{
+ it.tvMessage.text=message
+ it.tvPercentage.text=String.format("%s0%%", (percentage).roundToInt().toString())
+
+ Glide.with(this)
+ .load(photoUrl)
+ .diskCacheStrategy(DiskCacheStrategy.NONE)
+ .placeholder(R.drawable.ic_access_time)
+ .error(R.drawable.ic_offer)
+ .centerCrop()
+ .into(it.imgPromo)
+ }
+
+ }
+ }
+ }
+
+ override fun onPrepareOptionsMenu(menu: Menu) {
+ menu.clear()
+ super.onPrepareOptionsMenu(menu)
+ }
+ override fun onOptionsItemSelected(item: MenuItem): Boolean {
+ if(item.itemId == android.R.id.home){
+ activity?.onBackPressed()
+ }
+ return super.onOptionsItemSelected(item)
+ }
+ override fun onDestroyView() {
+ super.onDestroyView()
+ (activity as? MainAux)?.showButton(true)
+ (activity as? AppCompatActivity)?.apply {
+ supportActionBar?.setDisplayHomeAsUpEnabled(false)
+ supportActionBar?.title=title
+ setHasOptionsMenu(false)
+ }
+ bind=null
+ }
+}
\ No newline at end of file
diff --git a/NiloPartner/app/src/main/res/layout/fragment_promo.xml b/NiloPartner/app/src/main/res/layout/fragment_promo.xml
new file mode 100644
index 0000000..87c3324
--- /dev/null
+++ b/NiloPartner/app/src/main/res/layout/fragment_promo.xml
@@ -0,0 +1,41 @@
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/NiloPartner/app/src/main/res/values/strings.xml b/NiloPartner/app/src/main/res/values/strings.xml
index 143d0e7..fab096f 100644
--- a/NiloPartner/app/src/main/res/values/strings.xml
+++ b/NiloPartner/app/src/main/res/values/strings.xml
@@ -54,6 +54,7 @@
Cerrar sesión
Editar perfil
Historial de compras
+ Promociones
\ No newline at end of file