Preliminary version of drawer

This commit is contained in:
Pierre HUBERT 2018-07-31 19:01:47 +02:00
parent 36cba023af
commit 1ac52e6cfd
8 changed files with 208 additions and 125 deletions

View File

@ -2,14 +2,17 @@ package org.communiquons.android.comunic.client.ui.activities;
import android.app.Activity;
import android.app.AlertDialog;
import android.support.v4.app.FragmentTransaction;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.AsyncTask;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.design.widget.BottomNavigationView;
import android.support.design.widget.NavigationView;
import android.support.v4.app.FragmentTransaction;
import android.support.v4.view.GravityCompat;
import android.support.v4.widget.DrawerLayout;
import android.support.v7.app.ActionBarDrawerToggle;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.Menu;
@ -22,27 +25,27 @@ import org.communiquons.android.comunic.client.R;
import org.communiquons.android.comunic.client.crashreporter.CrashReporter;
import org.communiquons.android.comunic.client.data.helpers.APIRequestHelper;
import org.communiquons.android.comunic.client.data.helpers.AccountHelper;
import org.communiquons.android.comunic.client.data.helpers.DebugHelper;
import org.communiquons.android.comunic.client.data.utils.AccountUtils;
import org.communiquons.android.comunic.client.data.helpers.DatabaseHelper;
import org.communiquons.android.comunic.client.data.helpers.ConversationsListHelper;
import org.communiquons.android.comunic.client.data.helpers.DatabaseHelper;
import org.communiquons.android.comunic.client.data.helpers.DebugHelper;
import org.communiquons.android.comunic.client.data.runnables.FriendRefreshLoopRunnable;
import org.communiquons.android.comunic.client.data.services.NotificationsService;
import org.communiquons.android.comunic.client.data.utils.AccountUtils;
import org.communiquons.android.comunic.client.data.utils.PreferencesUtils;
import org.communiquons.android.comunic.client.ui.fragments.ConversationFragment;
import org.communiquons.android.comunic.client.ui.fragments.ConversationsListFragment;
import org.communiquons.android.comunic.client.ui.fragments.FriendsListFragment;
import org.communiquons.android.comunic.client.ui.fragments.LatestPostsFragment;
import org.communiquons.android.comunic.client.ui.fragments.NotificationsFragment;
import org.communiquons.android.comunic.client.ui.fragments.SinglePostFragment;
import org.communiquons.android.comunic.client.ui.fragments.UpdateConversationFragment;
import org.communiquons.android.comunic.client.ui.fragments.UserAccessDeniedFragment;
import org.communiquons.android.comunic.client.ui.fragments.UserPageFragment;
import org.communiquons.android.comunic.client.ui.listeners.onOpenUsersPageListener;
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.updateConversationListener;
import org.communiquons.android.comunic.client.ui.utils.UiUtils;
import org.communiquons.android.comunic.client.ui.fragments.ConversationFragment;
import org.communiquons.android.comunic.client.ui.fragments.ConversationsListFragment;
import org.communiquons.android.comunic.client.ui.fragments.FriendsListFragment;
import org.communiquons.android.comunic.client.ui.fragments.NotificationsFragment;
import org.communiquons.android.comunic.client.ui.fragments.UpdateConversationFragment;
import org.communiquons.android.comunic.client.ui.fragments.UserPageFragment;
/**
@ -50,7 +53,8 @@ import org.communiquons.android.comunic.client.ui.fragments.UserPageFragment;
*
* @author Pierre HUBERT
*/
public class MainActivity extends AppCompatActivity implements openConversationListener,
public class MainActivity extends AppCompatActivity implements
NavigationView.OnNavigationItemSelectedListener, openConversationListener,
updateConversationListener, onOpenUsersPageListener, onPostOpenListener {
/**
@ -91,7 +95,7 @@ public class MainActivity extends AppCompatActivity implements openConversationL
/**
* Bottom navigation view
*/
private BottomNavigationView navigationView;
private DrawerLayout mDrawer;
@Override
protected void onCreate(Bundle savedInstanceState) {
@ -116,8 +120,8 @@ public class MainActivity extends AppCompatActivity implements openConversationL
//Set the content of the activity
setContentView(R.layout.activity_main);
//Enable bottom navigation menu
init_bottom_menu();
//Enable drawer
init_drawer();
//Check for connectivity
if (!APIRequestHelper.isAPIavailable(this)) {
@ -166,6 +170,10 @@ public class MainActivity extends AppCompatActivity implements openConversationL
friendsListRefreshRunnable.interrupt();
}
/**
* Top menu creation
*/
@ -190,7 +198,7 @@ public class MainActivity extends AppCompatActivity implements openConversationL
//To go backward
if (id == android.R.id.home) {
getSupportFragmentManager().popBackStack();
toggleDrawer();
return true;
}
@ -234,6 +242,66 @@ public class MainActivity extends AppCompatActivity implements openConversationL
}
/**
* Drawer menu
*/
void init_drawer() {
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
mDrawer = findViewById(R.id.drawer_layout);
ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
this, mDrawer, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
mDrawer.addDrawerListener(toggle);
toggle.syncState();
NavigationView navigationView = findViewById(R.id.nav_view);
navigationView.setNavigationItemSelectedListener(this);
}
@Override
public void onBackPressed() {
if (mDrawer.isDrawerOpen(GravityCompat.START)) {
mDrawer.closeDrawer(GravityCompat.START);
} else {
super.onBackPressed();
}
}
@Override
public boolean onNavigationItemSelected(@NonNull MenuItem menuItem) {
return false;
}
/**
* Set the currently selected item in the drawer
*
* @param item The ID of the item
*/
public void setSelectedNavigationItem(int item) {
}
/**
* Toggle drawer state
*/
void toggleDrawer(){
if (mDrawer.isDrawerOpen(GravityCompat.START)) {
mDrawer.closeDrawer(GravityCompat.START);
} else {
mDrawer.openDrawer(GravityCompat.START);
}
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
@ -256,61 +324,6 @@ public class MainActivity extends AppCompatActivity implements openConversationL
}
/**
* Bottom menu creation
*/
void init_bottom_menu(){
navigationView = (BottomNavigationView) findViewById(R.id.main_bottom_navigation);
navigationView.setOnNavigationItemSelectedListener(new BottomNavigationView.OnNavigationItemSelectedListener() {
@Override
public boolean onNavigationItemSelected(@NonNull MenuItem item) {
//Check which option was selected
switch (item.getItemId()) {
//If the user clicked to show the friends list
/*case R.id.main_bottom_navigation_friends_list:
openFriendsFragment();
return true;*/
//If the user wants to open notifications
case R.id.main_bottom_navigation_notif:
openNotificationsFragment();
return true;
//If the user chose to show information about him
case R.id.main_bottom_navigation_me_view:
//Old versions
//openUserInfosFragment();
//openUserPage(AccountUtils.getID(MainActivity.this));
//New version
openLatestPostsFragment();
return true;
//If the user wants to switch to the conversation fragment
case R.id.main_bottom_navigation_conversations:
openConversationsListFragment();
return true;
}
//Selected element not found
return false;
}
});
}
/**
* Set the currently selected item in the bottom navigation view
*
* @param item The ID of the item
*/
public void setSelectedNavigationItem(int item){
navigationView.getMenu().findItem(item).setChecked(true);
}
/**
* Ask user to confirm if he really what to sign out or not
*/

View File

@ -0,0 +1,9 @@
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<gradient
android:angle="135"
android:centerColor="#009688"
android:endColor="#00695C"
android:startColor="#4DB6AC"
android:type="linear" />
</shape>

View File

@ -1,23 +1,34 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
<android.support.v4.widget.DrawerLayout 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:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical">
android:fitsSystemWindows="false"
tools:openDrawer="start">
<android.support.design.widget.CoordinatorLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<FrameLayout
android:id="@+id/main_fragment"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_height="match_parent"
android:layout_weight="2" />
<android.support.design.widget.BottomNavigationView
android:id="@+id/main_bottom_navigation"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:background="?android:attr/windowBackground"
app:menu="@menu/main_bottom_navigation" />
</android.support.design.widget.CoordinatorLayout>
</LinearLayout>
<android.support.design.widget.NavigationView
android:id="@+id/nav_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
android:fitsSystemWindows="true"
app:headerLayout="@layout/nav_header_main"
app:menu="@menu/activity_main_drawer" />
</android.support.v4.widget.DrawerLayout>

View File

@ -0,0 +1,36 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="@dimen/nav_header_height"
xmlns:tools="http://schemas.android.com/tools"
android:background="@drawable/side_nav_bar"
android:gravity="bottom"
android:orientation="vertical"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:theme="@style/ThemeOverlay.AppCompat.Dark">
<ImageView
android:id="@+id/imageView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:contentDescription="@string/nav_header_desc"
android:paddingTop="@dimen/nav_header_vertical_spacing"
android:src="@drawable/default_account_image" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="@dimen/nav_header_vertical_spacing"
tools:text="User name"
android:textAppearance="@style/TextAppearance.AppCompat.Body1" />
<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
tools:text="email@example.com" />
</LinearLayout>

View File

@ -6,17 +6,17 @@
android:title="@string/navigation_bottom_notif_item"
android:icon="@drawable/ic_notif"/>
<!--<item
<item
android:id="@+id/main_bottom_navigation_friends_list"
android:title="@string/navigation_bottom_friends_item"
android:icon="@drawable/ic_menu_allfriends"
/>-->
/>
<!--<item
<item
android:id="@+id/main_bottom_navigation_users_view"
android:title="@string/navigation_bottom_user_item"
android:icon="@drawable/perm_group_personal_info"
android:visible="false" />-->
android:visible="false" />
<item
android:id="@+id/main_bottom_navigation_me_view"

View File

@ -1,4 +1,11 @@
<resources>
<!-- Default screen margins, per the Android Design guidelines. -->
<dimen name="activity_horizontal_margin">16dp</dimen>
<dimen name="activity_vertical_margin">16dp</dimen>
<dimen name="nav_header_vertical_spacing">8dp</dimen>
<dimen name="nav_header_height">176dp</dimen>
<dimen name="fab_margin">16dp</dimen>
<!-- The default size of an account image -->
<dimen name="account_image_default_width">64dp</dimen>
<dimen name="account_image_default_height">64dp</dimen>

View File

@ -196,4 +196,7 @@
<string name="tab_posts">Posts</string>
<string name="member_for">Member for</string>
<string name="action_create_post">Create a new post</string>
<string name="nav_header_desc">Navigation header</string>
<string name="navigation_drawer_open">Open navigation drawer</string>
<string name="navigation_drawer_close">Close navigation drawer</string>
</resources>

View File

@ -1,5 +1,9 @@
<resources>
<style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" />
<style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" />
<!-- Base application theme. -->
<style name="AppTheme" parent="Base.Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->