mirror of
https://github.com/pierre42100/ComunicAndroid
synced 2024-11-23 22:09:30 +00:00
Preliminary version of drawer
This commit is contained in:
parent
36cba023af
commit
1ac52e6cfd
@ -2,14 +2,17 @@ package org.communiquons.android.comunic.client.ui.activities;
|
|||||||
|
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.app.AlertDialog;
|
import android.app.AlertDialog;
|
||||||
import android.support.v4.app.FragmentTransaction;
|
|
||||||
import android.content.DialogInterface;
|
import android.content.DialogInterface;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.os.AsyncTask;
|
import android.os.AsyncTask;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.support.annotation.NonNull;
|
import android.support.annotation.NonNull;
|
||||||
import android.support.annotation.Nullable;
|
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.support.v7.app.AppCompatActivity;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.view.Menu;
|
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.crashreporter.CrashReporter;
|
||||||
import org.communiquons.android.comunic.client.data.helpers.APIRequestHelper;
|
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.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.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.runnables.FriendRefreshLoopRunnable;
|
||||||
import org.communiquons.android.comunic.client.data.services.NotificationsService;
|
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.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.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.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.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.onOpenUsersPageListener;
|
||||||
import org.communiquons.android.comunic.client.ui.listeners.onPostOpenListener;
|
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.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
|
* @author Pierre HUBERT
|
||||||
*/
|
*/
|
||||||
public class MainActivity extends AppCompatActivity implements openConversationListener,
|
public class MainActivity extends AppCompatActivity implements
|
||||||
|
NavigationView.OnNavigationItemSelectedListener, openConversationListener,
|
||||||
updateConversationListener, onOpenUsersPageListener, onPostOpenListener {
|
updateConversationListener, onOpenUsersPageListener, onPostOpenListener {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -91,7 +95,7 @@ public class MainActivity extends AppCompatActivity implements openConversationL
|
|||||||
/**
|
/**
|
||||||
* Bottom navigation view
|
* Bottom navigation view
|
||||||
*/
|
*/
|
||||||
private BottomNavigationView navigationView;
|
private DrawerLayout mDrawer;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
@ -116,8 +120,8 @@ public class MainActivity extends AppCompatActivity implements openConversationL
|
|||||||
//Set the content of the activity
|
//Set the content of the activity
|
||||||
setContentView(R.layout.activity_main);
|
setContentView(R.layout.activity_main);
|
||||||
|
|
||||||
//Enable bottom navigation menu
|
//Enable drawer
|
||||||
init_bottom_menu();
|
init_drawer();
|
||||||
|
|
||||||
//Check for connectivity
|
//Check for connectivity
|
||||||
if (!APIRequestHelper.isAPIavailable(this)) {
|
if (!APIRequestHelper.isAPIavailable(this)) {
|
||||||
@ -166,6 +170,10 @@ public class MainActivity extends AppCompatActivity implements openConversationL
|
|||||||
friendsListRefreshRunnable.interrupt();
|
friendsListRefreshRunnable.interrupt();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Top menu creation
|
* Top menu creation
|
||||||
*/
|
*/
|
||||||
@ -190,7 +198,7 @@ public class MainActivity extends AppCompatActivity implements openConversationL
|
|||||||
|
|
||||||
//To go backward
|
//To go backward
|
||||||
if (id == android.R.id.home) {
|
if (id == android.R.id.home) {
|
||||||
getSupportFragmentManager().popBackStack();
|
toggleDrawer();
|
||||||
return true;
|
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
|
@Override
|
||||||
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
|
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
|
* Ask user to confirm if he really what to sign out or not
|
||||||
*/
|
*/
|
||||||
|
9
app/src/main/res/drawable/side_nav_bar.xml
Normal file
9
app/src/main/res/drawable/side_nav_bar.xml
Normal 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>
|
@ -1,23 +1,34 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?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"
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
|
android:id="@+id/drawer_layout"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
android:fitsSystemWindows="false"
|
||||||
android:orientation="vertical">
|
tools:openDrawer="start">
|
||||||
|
|
||||||
|
|
||||||
|
<android.support.design.widget.CoordinatorLayout
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
tools:context=".MainActivity">
|
||||||
|
|
||||||
<FrameLayout
|
<FrameLayout
|
||||||
android:id="@+id/main_fragment"
|
android:id="@+id/main_fragment"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="0dp"
|
android:layout_height="match_parent"
|
||||||
android:layout_weight="2" />
|
android:layout_weight="2" />
|
||||||
|
|
||||||
<android.support.design.widget.BottomNavigationView
|
</android.support.design.widget.CoordinatorLayout>
|
||||||
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" />
|
|
||||||
|
|
||||||
</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>
|
36
app/src/main/res/layout/nav_header_main.xml
Normal file
36
app/src/main/res/layout/nav_header_main.xml
Normal 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>
|
@ -6,17 +6,17 @@
|
|||||||
android:title="@string/navigation_bottom_notif_item"
|
android:title="@string/navigation_bottom_notif_item"
|
||||||
android:icon="@drawable/ic_notif"/>
|
android:icon="@drawable/ic_notif"/>
|
||||||
|
|
||||||
<!--<item
|
<item
|
||||||
android:id="@+id/main_bottom_navigation_friends_list"
|
android:id="@+id/main_bottom_navigation_friends_list"
|
||||||
android:title="@string/navigation_bottom_friends_item"
|
android:title="@string/navigation_bottom_friends_item"
|
||||||
android:icon="@drawable/ic_menu_allfriends"
|
android:icon="@drawable/ic_menu_allfriends"
|
||||||
/>-->
|
/>
|
||||||
|
|
||||||
<!--<item
|
<item
|
||||||
android:id="@+id/main_bottom_navigation_users_view"
|
android:id="@+id/main_bottom_navigation_users_view"
|
||||||
android:title="@string/navigation_bottom_user_item"
|
android:title="@string/navigation_bottom_user_item"
|
||||||
android:icon="@drawable/perm_group_personal_info"
|
android:icon="@drawable/perm_group_personal_info"
|
||||||
android:visible="false" />-->
|
android:visible="false" />
|
||||||
|
|
||||||
<item
|
<item
|
||||||
android:id="@+id/main_bottom_navigation_me_view"
|
android:id="@+id/main_bottom_navigation_me_view"
|
@ -1,4 +1,11 @@
|
|||||||
<resources>
|
<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 -->
|
<!-- The default size of an account image -->
|
||||||
<dimen name="account_image_default_width">64dp</dimen>
|
<dimen name="account_image_default_width">64dp</dimen>
|
||||||
<dimen name="account_image_default_height">64dp</dimen>
|
<dimen name="account_image_default_height">64dp</dimen>
|
||||||
|
@ -196,4 +196,7 @@
|
|||||||
<string name="tab_posts">Posts</string>
|
<string name="tab_posts">Posts</string>
|
||||||
<string name="member_for">Member for</string>
|
<string name="member_for">Member for</string>
|
||||||
<string name="action_create_post">Create a new post</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>
|
</resources>
|
||||||
|
@ -1,5 +1,9 @@
|
|||||||
<resources>
|
<resources>
|
||||||
|
|
||||||
|
<style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" />
|
||||||
|
|
||||||
|
<style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" />
|
||||||
|
|
||||||
<!-- Base application theme. -->
|
<!-- Base application theme. -->
|
||||||
<style name="AppTheme" parent="Base.Theme.AppCompat.Light.DarkActionBar">
|
<style name="AppTheme" parent="Base.Theme.AppCompat.Light.DarkActionBar">
|
||||||
<!-- Customize your theme here. -->
|
<!-- Customize your theme here. -->
|
||||||
|
Loading…
Reference in New Issue
Block a user