Added news number on navigation bar elements

This commit is contained in:
Pierre HUBERT 2018-08-22 16:35:00 +02:00
parent 5f6d7d8e1f
commit 13f109b5fa
5 changed files with 53 additions and 4 deletions

View File

@ -69,7 +69,7 @@ public class NavigationBar extends BaseFrameLayoutView implements NavigationBarI
private void init(){ private void init(){
//Inflate main view //Inflate main view
View view = inflate(getContext(), R.layout.navigation_bar, this); View view = inflate(getContext(), R.layout.view_navigation_bar, this);
mLinearLayout = view.findViewById(R.id.container); mLinearLayout = view.findViewById(R.id.container);
//Inflate menu //Inflate menu

View File

@ -1,11 +1,13 @@
package org.communiquons.android.comunic.client.ui.views; package org.communiquons.android.comunic.client.ui.views;
import android.annotation.SuppressLint;
import android.content.Context; import android.content.Context;
import android.graphics.PorterDuff; import android.graphics.PorterDuff;
import android.graphics.drawable.Drawable; import android.graphics.drawable.Drawable;
import android.support.annotation.NonNull; import android.support.annotation.NonNull;
import android.view.View; import android.view.View;
import android.widget.ImageView; import android.widget.ImageView;
import android.widget.TextView;
import org.communiquons.android.comunic.client.R; import org.communiquons.android.comunic.client.R;
import org.communiquons.android.comunic.client.ui.utils.DrawableUtils; import org.communiquons.android.comunic.client.ui.utils.DrawableUtils;
@ -16,13 +18,18 @@ import org.communiquons.android.comunic.client.ui.utils.UiUtils;
* *
* @author Pierre HUBERT * @author Pierre HUBERT
*/ */
class NavigationBarItem extends BaseFrameLayoutView implements View.OnClickListener { public class NavigationBarItem extends BaseFrameLayoutView implements View.OnClickListener {
/** /**
* Debug tag * Debug tag
*/ */
private static final String TAG = NavigationBarItem.class.getCanonicalName(); private static final String TAG = NavigationBarItem.class.getCanonicalName();
/**
* News number icon
*/
private TextView mNumberNews;
/** /**
* Image icon * Image icon
*/ */
@ -48,13 +55,27 @@ class NavigationBarItem extends BaseFrameLayoutView implements View.OnClickListe
*/ */
private boolean mSelected; private boolean mSelected;
public NavigationBarItem(@NonNull Context context) { NavigationBarItem(@NonNull Context context) {
super(context); super(context);
//Inflate view //Inflate view
View view = inflate(getContext(), R.layout.navigation_bar_item, this); View view = inflate(getContext(), R.layout.view_navigation_bar_item, this);
mIcon = view.findViewById(R.id.icon); mIcon = view.findViewById(R.id.icon);
mNumberNews = view.findViewById(R.id.numberNews);
view.setOnClickListener(this); view.setOnClickListener(this);
setNumberNews(0);
}
/**
* Set the number of news
*
* @param number The number of news to display
*/
@SuppressLint("SetTextI18n")
public void setNumberNews(Integer number){
mNumberNews.setText(""+number);
mNumberNews.setVisibility(number == 0 ? View.GONE : View.VISIBLE);
} }
/** /**

View File

@ -0,0 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval"
android:width="2dp"
android:height="2dp">
<solid android:color="@color/default_drawable_color"/>
<size
android:width="10dp"
android:height="10dp"/>
</shape>

View File

@ -20,4 +20,19 @@
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" /> app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="@+id/numberNews"
android:layout_width="14dp"
android:layout_height="14dp"
android:background="@drawable/ic_circle"
android:backgroundTint="@android:color/holo_red_dark"
android:paddingTop="1dp"
android:textAlignment="center"
android:textColor="@android:color/white"
android:textSize="8sp"
android:textStyle="bold"
app:layout_constraintEnd_toEndOf="@+id/icon"
app:layout_constraintTop_toTopOf="@+id/icon"
tools:text="10" />
</android.support.constraint.ConstraintLayout> </android.support.constraint.ConstraintLayout>