-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Agregamos fragmento de promoción, ara cargar los datos del remote config
- Loading branch information
Showing
4 changed files
with
159 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
110 changes: 110 additions & 0 deletions
110
NiloPartner/app/src/main/java/com/barryzea/niloclient/promo/PromoFragment.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" | ||
xmlns:app="http://schemas.android.com/apk/res-auto" | ||
xmlns:tools="http://schemas.android.com/tools" | ||
android:clickable="true" | ||
android:focusable="true" | ||
android:background="@color/white"> | ||
<ImageView | ||
android:layout_width="0dp" | ||
android:layout_height="0dp" | ||
android:id="@+id/imgPromo" | ||
app:layout_constraintStart_toStartOf="parent" | ||
app:layout_constraintEnd_toEndOf="parent" | ||
app:layout_constraintTop_toTopOf="parent" | ||
app:layout_constraintDimensionRatio="16:9"/> | ||
<com.google.android.material.textview.MaterialTextView | ||
android:layout_width="0dp" | ||
android:layout_height="wrap_content" | ||
android:id="@+id/tvPercentage" | ||
android:padding="@dimen/common_padding_default" | ||
android:textAppearance="@style/TextAppearance.MaterialComponents.Headline5" | ||
tools:text="Descuento del 10%" | ||
app:layout_constraintStart_toStartOf="parent" | ||
app:layout_constraintEnd_toEndOf="parent" | ||
app:layout_constraintBottom_toBottomOf="parent"/> | ||
<com.google.android.material.textview.MaterialTextView | ||
android:layout_width="0dp" | ||
android:layout_height="0dp" | ||
android:id="@+id/tvMessage" | ||
android:padding="@dimen/common_padding_default" | ||
android:textAppearance="@style/TextAppearance.MaterialComponents.Subtitle1" | ||
tools:text="@string/welcome_text" | ||
app:layout_constraintStart_toStartOf="parent" | ||
app:layout_constraintEnd_toEndOf="parent" | ||
app:layout_constraintTop_toBottomOf="@id/imgPromo" | ||
app:layout_constraintBottom_toTopOf="@id/tvPercentage"/> | ||
|
||
|
||
</androidx.constraintlayout.widget.ConstraintLayout> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters