Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 5e550aad authored by calderwoodra's avatar calderwoodra Committed by Copybara-Service
Browse files

Added badge count feature to bottom nav.

This Change doesn't actually fetch the badge counts, but it's now possible to
set badge counts.

Bug: 72525595
Test: manual
PiperOrigin-RevId: 183887322
Change-Id: I452ca6352133befc8cc2a39c44cd84a33fd66d42
parent 54e90e5c
Loading
Loading
Loading
Loading
+14 −0
Original line number Diff line number Diff line
@@ -119,6 +119,20 @@ final class BottomNavBar extends LinearLayout {
    }
  }

  void setNotificationCount(@TabIndex int tab, int count) {
    if (tab == TabIndex.SPEED_DIAL) {
      speedDial.setNotificationCount(count);
    } else if (tab == TabIndex.HISTORY) {
      callLog.setNotificationCount(count);
    } else if (tab == TabIndex.CONTACTS) {
      contacts.setNotificationCount(count);
    } else if (tab == TabIndex.VOICEMAIL) {
      voicemail.setNotificationCount(count);
    } else {
      throw new IllegalStateException("Invalid tab: " + tab);
    }
  }

  void setOnTabSelectedListener(OnBottomNavTabSelectedListener listener) {
    this.listener = listener;
  }
+14 −0
Original line number Diff line number Diff line
@@ -22,15 +22,18 @@ import android.support.annotation.DrawableRes;
import android.support.annotation.Nullable;
import android.support.annotation.StringRes;
import android.util.AttributeSet;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import com.android.dialer.common.Assert;

/** Navigation item in a bottom nav. */
final class BottomNavItem extends LinearLayout {

  private ImageView image;
  private TextView text;
  private TextView notificationBadge;

  public BottomNavItem(Context context, @Nullable AttributeSet attrs) {
    super(context, attrs);
@@ -41,6 +44,7 @@ final class BottomNavItem extends LinearLayout {
    super.onFinishInflate();
    image = findViewById(R.id.bottom_nav_item_image);
    text = findViewById(R.id.bottom_nav_item_text);
    notificationBadge = findViewById(R.id.notification_badge);
  }

  @Override
@@ -56,4 +60,14 @@ final class BottomNavItem extends LinearLayout {
    text.setText(stringRes);
    image.setImageResource(drawableRes);
  }

  void setNotificationCount(int count) {
    Assert.checkArgument(count >= 0, "Invalid count: " + count);
    if (count == 0) {
      notificationBadge.setVisibility(View.GONE);
    } else {
      notificationBadge.setVisibility(View.VISIBLE);
      notificationBadge.setText(String.format(Integer.toString(count)));
    }
  }
}
+22 −0
Original line number Diff line number Diff line
<?xml version="1.0" encoding="utf-8"?>
<!--
  ~ Copyright (C) 2018 The Android Open Source Project
  ~
  ~ Licensed under the Apache License, Version 2.0 (the "License");
  ~ you may not use this file except in compliance with the License.
  ~ You may obtain a copy of the License at
  ~
  ~      http://www.apache.org/licenses/LICENSE-2.0
  ~
  ~ Unless required by applicable law or agreed to in writing, software
  ~ distributed under the License is distributed on an "AS IS" BASIS,
  ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  ~ See the License for the specific language governing permissions and
  ~ limitations under the License
  -->
<shape
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="oval">
  <solid android:color="@color/dialer_secondary_color"/>
  <size android:height="14dp" android:width="14dp"/>
</shape>
 No newline at end of file
+23 −5
Original line number Diff line number Diff line
@@ -25,13 +25,31 @@
    android:paddingStart="12dp"
    android:paddingEnd="12dp"
    android:gravity="center"
    android:theme="@style/Theme.AppCompat"
    android:background="?android:selectableItemBackgroundBorderless">

  <FrameLayout
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:layout_marginBottom="2dp">

    <ImageView
        android:id="@+id/bottom_nav_item_image"
        android:layout_width="24dp"
        android:layout_height="24dp"
      android:layout_marginBottom="6dp"/>
        android:layout_margin="4dp"/>

    <TextView
        android:id="@+id/notification_badge"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="top|end"
        android:gravity="center"
        android:textSize="12sp"
        android:textColor="@color/dialer_primary_text_color_white"
        android:background="@drawable/notification_badge"
        android:visibility="gone"/>
  </FrameLayout>

  <TextView
      android:id="@+id/bottom_nav_item_text"