Skip to content

Commit

Permalink
Agregamos un badge a la toolbar principal, con el conteo de promocion…
Browse files Browse the repository at this point in the history
…es de remote config
  • Loading branch information
hall9zeha committed Feb 28, 2022
1 parent f958d62 commit c0e0d08
Show file tree
Hide file tree
Showing 8 changed files with 145 additions and 72 deletions.
17 changes: 17 additions & 0 deletions NiloPartner/.idea/deploymentTargetDropDown.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion NiloPartner/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@
</activity>
<activity
android:name=".MainActivity"
android:exported="true">
android:exported="true"
android:theme="@style/Theme.NiloClient.NoActionBar"
>
<intent-filter>
<action android:name="android.intent.action.MAIN" />

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.barryzea.niloclient

import android.annotation.SuppressLint
import android.content.Intent
import android.content.pm.PackageManager
import android.os.Build
Expand Down Expand Up @@ -35,6 +36,8 @@ import com.firebase.ui.auth.AuthMethodPickerLayout
import com.firebase.ui.auth.AuthUI
import com.firebase.ui.auth.ErrorCodes
import com.firebase.ui.auth.IdpResponse
import com.google.android.material.badge.BadgeDrawable
import com.google.android.material.badge.BadgeUtils
import com.google.firebase.analytics.FirebaseAnalytics
import com.google.firebase.analytics.ktx.analytics
import com.google.firebase.analytics.ktx.logEvent
Expand Down Expand Up @@ -131,9 +134,10 @@ class MainActivity : AppCompatActivity(), OnProductListener, MainAux {
}

private fun configToolbar() {

setSupportActionBar(bind.toolbar)
}

@SuppressLint("UnsafeOptInUsageError")
private fun configRemoteConfig() {
val remoteConfig=Firebase.remoteConfig
val configSettings= remoteConfigSettings {
Expand All @@ -157,7 +161,11 @@ class MainActivity : AppCompatActivity(), OnProductListener, MainAux {
val percentage=remoteConfig.getDouble("percentage")
val photoUrl=remoteConfig.getString("photoUrl")
val message=remoteConfig.getString("message")
Toast.makeText(this, message, Toast.LENGTH_SHORT).show()
if(isPromoDay){
val badge=BadgeDrawable.create(this)
BadgeUtils.attachBadgeDrawable(badge,bind.toolbar,R.id.itemPromo)
badge.number=promCounter.toInt()
}

}
}
Expand Down Expand Up @@ -301,6 +309,9 @@ class MainActivity : AppCompatActivity(), OnProductListener, MainAux {
R.id.itemSettings->{
startActivity(Intent(this, SettingsActivity::class.java))
}
R.id.itemPromo->{

}
}
return super.onOptionsItemSelected(item)

Expand Down
10 changes: 10 additions & 0 deletions NiloPartner/app/src/main/res/drawable/ic_offer.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24"
android:tint="?attr/colorControlNormal">
<path
android:fillColor="@android:color/white"
android:pathData="M21.41,11.58l-9,-9C12.05,2.22 11.55,2 11,2H4c-1.1,0 -2,0.9 -2,2v7c0,0.55 0.22,1.05 0.59,1.42l9,9c0.36,0.36 0.86,0.58 1.41,0.58 0.55,0 1.05,-0.22 1.41,-0.59l7,-7c0.37,-0.36 0.59,-0.86 0.59,-1.41 0,-0.55 -0.23,-1.06 -0.59,-1.42zM5.5,7C4.67,7 4,6.33 4,5.5S4.67,4 5.5,4 7,4.67 7,5.5 6.33,7 5.5,7z"/>
</vector>
146 changes: 82 additions & 64 deletions NiloPartner/app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
@@ -1,74 +1,92 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
<androidx.coordinatorlayout.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/containerMain"
tools:context=".MainActivity">
<com.google.android.material.textview.MaterialTextView
android:layout_width="0dp"
android:layout_height="@dimen/product_preview_card_height"
android:id="@+id/tvTotal"
android:text="@string/car_empty"
android:textAppearance="@style/TextAppearance.MaterialComponents.Headline6"
android:gravity="center_vertical"
android:layout_marginStart="@dimen/common_padding_default"
android:layout_marginEnd="@dimen/common_padding_min"
app:layout_constraintEnd_toStartOf="@id/btnViewCar"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintBottom_toBottomOf="parent"/>
<com.google.android.material.button.MaterialButton
android:layout_width="wrap_content"
android:layout_height="match_parent">
<com.google.android.material.appbar.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/btnViewCar"
android:text="@string/view_car"
android:layout_marginEnd="@dimen/common_padding_default"
android:layout_marginStart="@dimen/common_padding_min"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintBottom_toBottomOf="@id/tvTotal"
app:layout_constraintTop_toTopOf="@id/tvTotal"/>

<androidx.core.widget.NestedScrollView
android:layout_width="0dp"
android:layout_height="0dp"
android:id="@+id/nsvProducts"
android:orientation="horizontal"
android:visibility="gone"
tools:visibility="visible"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toTopOf="@id/tvTotal"
>
<androidx.recyclerview.widget.RecyclerView
<com.google.android.material.appbar.MaterialToolbar
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/rvProducts"
tools:listitem="@layout/item_product"/>
</androidx.core.widget.NestedScrollView>
android:layout_height="wrap_content"
android:theme="@style/Theme.NiloClient.AppBarOverlay"
app:popupTheme="@style/Theme.NiloClient.AppPopupOverlay"
android:id="@+id/toolbar"/>
</com.google.android.material.appbar.AppBarLayout>
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/containerMain"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:context=".MainActivity">
<com.google.android.material.textview.MaterialTextView
android:layout_width="0dp"
android:layout_height="@dimen/product_preview_card_height"
android:id="@+id/tvTotal"
android:text="@string/car_empty"
android:textAppearance="@style/TextAppearance.MaterialComponents.Headline6"
android:gravity="center_vertical"
android:layout_marginStart="@dimen/common_padding_default"
android:layout_marginEnd="@dimen/common_padding_min"
app:layout_constraintEnd_toStartOf="@id/btnViewCar"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintBottom_toBottomOf="parent"/>
<com.google.android.material.button.MaterialButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/btnViewCar"
android:text="@string/view_car"
android:layout_marginEnd="@dimen/common_padding_default"
android:layout_marginStart="@dimen/common_padding_min"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintBottom_toBottomOf="@id/tvTotal"
app:layout_constraintTop_toTopOf="@id/tvTotal"/>

<androidx.core.widget.NestedScrollView
android:layout_width="0dp"
android:layout_height="0dp"
android:id="@+id/nsvProducts"
android:orientation="horizontal"
android:visibility="gone"
tools:visibility="visible"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toTopOf="@id/tvTotal"

>
<androidx.recyclerview.widget.RecyclerView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/rvProducts"
tools:listitem="@layout/item_product"/>
</androidx.core.widget.NestedScrollView>


<LinearLayout
android:id="@+id/lnLoading"
android:layout_width="0dp"
android:layout_height="0dp"
android:orientation="vertical"
android:visibility="visible"
android:gravity="center"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent">
<ProgressBar
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Preparando todo..."/>
</LinearLayout>

<LinearLayout
android:id="@+id/lnLoading"
android:layout_width="0dp"
android:layout_height="0dp"
android:orientation="vertical"
android:visibility="visible"
android:gravity="center"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent">
<ProgressBar
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Preparando todo..."/>
</LinearLayout>


</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.coordinatorlayout.widget.CoordinatorLayout>
13 changes: 9 additions & 4 deletions NiloPartner/app/src/main/res/menu/menu_logout.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,22 @@
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item android:id="@+id/itemLogOut"
android:title="Cerrar sesión"
android:title="@string/item_title_logout"
app:showAsAction="never"/>
<item android:id="@+id/itemOrder"
android:title=""
app:showAsAction="ifRoom"
android:title="@string/item_title_order"
app:showAsAction="never"
android:icon="@drawable/ic_history"/>
<item android:id="@+id/itemProfile"
android:title="Editar perfil"
android:title="@string/item_title_profile"
/>
<item android:id="@+id/itemSettings"
android:title="@string/settings"
app:showAsAction="never"
/>
<item android:id="@+id/itemPromo"
android:title=""
app:showAsAction="always"
android:icon="@drawable/ic_offer"
/>
</menu>
3 changes: 3 additions & 0 deletions NiloPartner/app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@
<string name="prefs_offers_title">Ofertas y promociones</string>
<string name="settings">Configuración</string>
<string name="topic_offers">topic_offers</string>
<string name="item_title_logout">Cerrar sesión</string>
<string name="item_title_profile">Editar perfil</string>
<string name="item_title_order">Historial de compras</string>


</resources>
9 changes: 8 additions & 1 deletion NiloPartner/app/src/main/res/values/styles.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,12 @@
<style name="PreferencesTheme" parent="Theme.NiloClient">
<item name="colorSecondary">@color/yellow_a400_dark</item>
</style>

<!--solamente aplicaremos este estilo a la mainActivity en el manifest-->
<style name="Theme.NiloClient.NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>
<!--y para mostrar correctamente la toolbar aplicada a mainActivity y el menu popup-->
<style name="Theme.NiloClient.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar"/>
<style name="Theme.NiloClient.AppPopupOverlay" parent="ThemeOverlay.AppCompat.Light"/>
</resources>

0 comments on commit c0e0d08

Please sign in to comment.