mirror of
https://github.com/pierre42100/ComunicAndroid
synced 2024-11-27 15:59:29 +00:00
Navigation bar is live
This commit is contained in:
parent
d910565021
commit
52512b2343
@ -49,6 +49,7 @@ import org.communiquons.android.comunic.client.ui.listeners.onPostOpenListener;
|
|||||||
import org.communiquons.android.comunic.client.ui.listeners.openConversationListener;
|
import org.communiquons.android.comunic.client.ui.listeners.openConversationListener;
|
||||||
import org.communiquons.android.comunic.client.ui.listeners.updateConversationListener;
|
import org.communiquons.android.comunic.client.ui.listeners.updateConversationListener;
|
||||||
import org.communiquons.android.comunic.client.ui.utils.UiUtils;
|
import org.communiquons.android.comunic.client.ui.utils.UiUtils;
|
||||||
|
import org.communiquons.android.comunic.client.ui.views.NavigationBar;
|
||||||
import org.communiquons.android.comunic.client.ui.views.WebUserAccountImage;
|
import org.communiquons.android.comunic.client.ui.views.WebUserAccountImage;
|
||||||
|
|
||||||
|
|
||||||
@ -58,8 +59,8 @@ import org.communiquons.android.comunic.client.ui.views.WebUserAccountImage;
|
|||||||
* @author Pierre HUBERT
|
* @author Pierre HUBERT
|
||||||
*/
|
*/
|
||||||
public class MainActivity extends AppCompatActivity implements
|
public class MainActivity extends AppCompatActivity implements
|
||||||
NavigationView.OnNavigationItemSelectedListener, openConversationListener,
|
openConversationListener, updateConversationListener, onOpenUsersPageListener,
|
||||||
updateConversationListener, onOpenUsersPageListener, onPostOpenListener {
|
onPostOpenListener, NavigationBar.OnNavigationItemSelectedListener {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Debug tag
|
* Debug tag
|
||||||
@ -91,6 +92,11 @@ public class MainActivity extends AppCompatActivity implements
|
|||||||
*/
|
*/
|
||||||
private ConversationsListHelper conversationsListHelper;
|
private ConversationsListHelper conversationsListHelper;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Main navigation bar
|
||||||
|
*/
|
||||||
|
private NavigationBar mNavBar;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
@ -116,9 +122,6 @@ public class MainActivity extends AppCompatActivity implements
|
|||||||
//Set the content of the activity
|
//Set the content of the activity
|
||||||
setContentView(R.layout.activity_main);
|
setContentView(R.layout.activity_main);
|
||||||
|
|
||||||
//Enable drawer
|
|
||||||
init_drawer();
|
|
||||||
|
|
||||||
//Check for connectivity
|
//Check for connectivity
|
||||||
if (!APIRequestHelper.isAPIavailable(this)) {
|
if (!APIRequestHelper.isAPIavailable(this)) {
|
||||||
Toast.makeText(this, R.string.err_no_internet_connection, Toast.LENGTH_SHORT).show();
|
Toast.makeText(this, R.string.err_no_internet_connection, Toast.LENGTH_SHORT).show();
|
||||||
@ -130,6 +133,10 @@ public class MainActivity extends AppCompatActivity implements
|
|||||||
//Initialize conversation list helper
|
//Initialize conversation list helper
|
||||||
conversationsListHelper = new ConversationsListHelper(this, dbHelper);
|
conversationsListHelper = new ConversationsListHelper(this, dbHelper);
|
||||||
|
|
||||||
|
//Use navigation bar
|
||||||
|
mNavBar = findViewById(R.id.nav_bar);
|
||||||
|
mNavBar.setOnNavigationItemSelectedListener(this);
|
||||||
|
|
||||||
//If it is the first time the application is launched, open notifications fragment
|
//If it is the first time the application is launched, open notifications fragment
|
||||||
if (savedInstanceState == null){
|
if (savedInstanceState == null){
|
||||||
openNotificationsFragment(false);
|
openNotificationsFragment(false);
|
||||||
@ -223,18 +230,6 @@ public class MainActivity extends AppCompatActivity implements
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Drawer menu
|
|
||||||
*/
|
|
||||||
void init_drawer() {
|
|
||||||
|
|
||||||
//TODO : remove
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onNavigationItemSelected(@NonNull MenuItem menuItem) {
|
public boolean onNavigationItemSelected(@NonNull MenuItem menuItem) {
|
||||||
int id = menuItem.getItemId();
|
int id = menuItem.getItemId();
|
||||||
|
@ -13,12 +13,14 @@ import android.widget.PopupMenu;
|
|||||||
|
|
||||||
import org.communiquons.android.comunic.client.R;
|
import org.communiquons.android.comunic.client.R;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Application navigation bar
|
* Application navigation bar
|
||||||
*
|
*
|
||||||
* @author Pierre HUBERT
|
* @author Pierre HUBERT
|
||||||
*/
|
*/
|
||||||
public class NavigationBar extends BaseFrameLayoutView {
|
public class NavigationBar extends BaseFrameLayoutView implements NavigationBarItem.OnNavigationBarItemClickListener {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Navigation bar items container
|
* Navigation bar items container
|
||||||
@ -31,10 +33,20 @@ public class NavigationBar extends BaseFrameLayoutView {
|
|||||||
private PopupMenu mPopupMenu;
|
private PopupMenu mPopupMenu;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Associated mMenu
|
* Associated menu
|
||||||
*/
|
*/
|
||||||
private Menu mMenu;
|
private Menu mMenu;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Navigation bar items
|
||||||
|
*/
|
||||||
|
private ArrayList<NavigationBarItem> mItems = new ArrayList<>();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Navigation selected item listener
|
||||||
|
*/
|
||||||
|
private OnNavigationItemSelectedListener mOnNavigationItemSelectedListener;
|
||||||
|
|
||||||
public NavigationBar(@NonNull Context context) {
|
public NavigationBar(@NonNull Context context) {
|
||||||
super(context);
|
super(context);
|
||||||
init();
|
init();
|
||||||
@ -59,7 +71,7 @@ public class NavigationBar extends BaseFrameLayoutView {
|
|||||||
View view = inflate(getContext(), R.layout.navigation_bar, this);
|
View view = inflate(getContext(), R.layout.navigation_bar, this);
|
||||||
mLinearLayout = view.findViewById(R.id.container);
|
mLinearLayout = view.findViewById(R.id.container);
|
||||||
|
|
||||||
//Process mMenu
|
//Inflate menu
|
||||||
mPopupMenu = new PopupMenu(getContext(), null);
|
mPopupMenu = new PopupMenu(getContext(), null);
|
||||||
mMenu = mPopupMenu.getMenu();
|
mMenu = mPopupMenu.getMenu();
|
||||||
getActivity().getMenuInflater().inflate(R.menu.navigation_bar, mMenu);
|
getActivity().getMenuInflater().inflate(R.menu.navigation_bar, mMenu);
|
||||||
@ -70,10 +82,55 @@ public class NavigationBar extends BaseFrameLayoutView {
|
|||||||
NavigationBarItem itemView = new NavigationBarItem(getContext());
|
NavigationBarItem itemView = new NavigationBarItem(getContext());
|
||||||
mLinearLayout.addView(itemView,
|
mLinearLayout.addView(itemView,
|
||||||
new LinearLayout.LayoutParams(0, ViewGroup.LayoutParams.MATCH_PARENT, 1f));
|
new LinearLayout.LayoutParams(0, ViewGroup.LayoutParams.MATCH_PARENT, 1f));
|
||||||
|
mItems.add(itemView);
|
||||||
|
|
||||||
MenuItem item = mMenu.getItem(i);
|
MenuItem item = mMenu.getItem(i);
|
||||||
|
|
||||||
itemView.setIconDrawable(item.getIcon());
|
itemView.setIconDrawable(item.getIcon());
|
||||||
|
itemView.setItemIndex(i);
|
||||||
|
itemView.setOnNavigationBarItemClickListener(this);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the currently selected item by its index in the list
|
||||||
|
*
|
||||||
|
* @param index The index of the item to mark as selected
|
||||||
|
*/
|
||||||
|
public void setIndexSelected(int index){
|
||||||
|
|
||||||
|
//Process the list of items
|
||||||
|
for(NavigationBarItem item : mItems)
|
||||||
|
item.setSelected(index == item.getItemIndex());
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setOnNavigationItemSelectedListener(OnNavigationItemSelectedListener onNavigationItemSelectedListener) {
|
||||||
|
this.mOnNavigationItemSelectedListener = onNavigationItemSelectedListener;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onItemClick(int index) {
|
||||||
|
if(mOnNavigationItemSelectedListener == null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if(mOnNavigationItemSelectedListener.onNavigationItemSelected(mMenu.getItem(index)))
|
||||||
|
setIndexSelected(index);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Navigation item selected listener
|
||||||
|
*/
|
||||||
|
public interface OnNavigationItemSelectedListener {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* When an item is selected by the user
|
||||||
|
*
|
||||||
|
* @param item Selected MenuItem
|
||||||
|
* @return True to keep the item selected (and deselect other ones), false else
|
||||||
|
*/
|
||||||
|
boolean onNavigationItemSelected(MenuItem item);
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -4,8 +4,6 @@ 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.util.Log;
|
|
||||||
import android.view.MotionEvent;
|
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.widget.ImageView;
|
import android.widget.ImageView;
|
||||||
|
|
||||||
@ -18,7 +16,7 @@ import org.communiquons.android.comunic.client.ui.utils.UiUtils;
|
|||||||
*
|
*
|
||||||
* @author Pierre HUBERT
|
* @author Pierre HUBERT
|
||||||
*/
|
*/
|
||||||
class NavigationBarItem extends BaseFrameLayoutView {
|
class NavigationBarItem extends BaseFrameLayoutView implements View.OnClickListener {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Debug tag
|
* Debug tag
|
||||||
@ -35,6 +33,16 @@ class NavigationBarItem extends BaseFrameLayoutView {
|
|||||||
*/
|
*/
|
||||||
private Drawable mSrcDrawable;
|
private Drawable mSrcDrawable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Item index
|
||||||
|
*/
|
||||||
|
private int mItemIndex;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Click listener
|
||||||
|
*/
|
||||||
|
private OnNavigationBarItemClickListener mOnNavigationBarItemClickListener;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Selected state of the drawable
|
* Selected state of the drawable
|
||||||
*/
|
*/
|
||||||
@ -46,7 +54,7 @@ class NavigationBarItem extends BaseFrameLayoutView {
|
|||||||
//Inflate view
|
//Inflate view
|
||||||
View view = inflate(getContext(), R.layout.navigation_bar_item, this);
|
View view = inflate(getContext(), R.layout.navigation_bar_item, this);
|
||||||
mIcon = view.findViewById(R.id.icon);
|
mIcon = view.findViewById(R.id.icon);
|
||||||
|
view.setOnClickListener(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -65,8 +73,12 @@ class NavigationBarItem extends BaseFrameLayoutView {
|
|||||||
public void draw(){
|
public void draw(){
|
||||||
Drawable drawable = DrawableUtils.DuplicateDrawable(mSrcDrawable);
|
Drawable drawable = DrawableUtils.DuplicateDrawable(mSrcDrawable);
|
||||||
|
|
||||||
int color = isSelected() ? R.color.navbar_selected : R.color.navbar_default;
|
int fgColor = isSelected() ? R.color.navbar_fg_selected : R.color.navbar_fg_default;
|
||||||
drawable.setColorFilter(UiUtils.getColor(getContext(), color), PorterDuff.Mode.SRC_IN);
|
int bgColor = isSelected() ? R.color.navbar_bg_selected : R.color.navbar_bg_default;
|
||||||
|
|
||||||
|
drawable.setColorFilter(UiUtils.getColor(getContext(), fgColor), PorterDuff.Mode.SRC_IN);
|
||||||
|
setBackgroundColor(UiUtils.getColor(getContext(), bgColor));
|
||||||
|
|
||||||
|
|
||||||
mIcon.setImageDrawable(drawable);
|
mIcon.setImageDrawable(drawable);
|
||||||
}
|
}
|
||||||
@ -77,5 +89,36 @@ class NavigationBarItem extends BaseFrameLayoutView {
|
|||||||
|
|
||||||
public void setSelected(boolean selected) {
|
public void setSelected(boolean selected) {
|
||||||
this.mSelected = selected;
|
this.mSelected = selected;
|
||||||
|
draw();
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getItemIndex() {
|
||||||
|
return mItemIndex;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setItemIndex(int itemIndex) {
|
||||||
|
this.mItemIndex = itemIndex;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setOnNavigationBarItemClickListener(OnNavigationBarItemClickListener onNavigationBarItemClickListener) {
|
||||||
|
this.mOnNavigationBarItemClickListener = onNavigationBarItemClickListener;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onClick(View v) {
|
||||||
|
if(mOnNavigationBarItemClickListener != null)
|
||||||
|
mOnNavigationBarItemClickListener.onItemClick(getItemIndex());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Interface used to handle navigation bar items click
|
||||||
|
*/
|
||||||
|
interface OnNavigationBarItemClickListener {
|
||||||
|
/**
|
||||||
|
* Called on item click
|
||||||
|
*
|
||||||
|
* @param index The index of the clicked item
|
||||||
|
*/
|
||||||
|
void onItemClick(int index);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -5,6 +5,7 @@
|
|||||||
android:orientation="vertical">
|
android:orientation="vertical">
|
||||||
|
|
||||||
<org.communiquons.android.comunic.client.ui.views.NavigationBar
|
<org.communiquons.android.comunic.client.ui.views.NavigationBar
|
||||||
|
android:id="@+id/nav_bar"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content" />
|
android:layout_height="wrap_content" />
|
||||||
|
|
||||||
|
@ -4,9 +4,7 @@
|
|||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
xmlns:tools="http://schemas.android.com/tools"
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
android:background="@drawable/navbar_item_ripple_effect"
|
android:background="@drawable/navbar_item_ripple_effect">
|
||||||
android:clickable="true"
|
|
||||||
android:focusable="true">
|
|
||||||
|
|
||||||
<ImageView
|
<ImageView
|
||||||
android:id="@+id/icon"
|
android:id="@+id/icon"
|
||||||
|
@ -12,8 +12,11 @@
|
|||||||
<color name="default_drawable_color">#000000</color>
|
<color name="default_drawable_color">#000000</color>
|
||||||
|
|
||||||
<!-- Navigation bar -->
|
<!-- Navigation bar -->
|
||||||
<color name="navbar_default">#FFFFFF</color>
|
<color name="navbar_fg_default">#FFFFFF</color>
|
||||||
<color name="navbar_selected">@color/colorPrimary</color>
|
<color name="navbar_fg_selected">@color/colorPrimary</color>
|
||||||
|
<color name="navbar_bg_default">@color/colorPrimary</color>
|
||||||
|
<color name="navbar_bg_selected">#FFFFFF</color>
|
||||||
|
|
||||||
|
|
||||||
<!-- Conversation messages -->
|
<!-- Conversation messages -->
|
||||||
<color name="conversation_user_messages_background">#3F51B5</color>
|
<color name="conversation_user_messages_background">#3F51B5</color>
|
||||||
|
Loading…
Reference in New Issue
Block a user