mirror of
https://github.com/pierre42100/ComunicAndroid
synced 2024-11-23 22:09:30 +00:00
Added fragments interaction
This commit is contained in:
parent
4d8faf38a5
commit
919f76fd3d
@ -1,22 +1,23 @@
|
|||||||
package org.communiquons.android.comunic.client;
|
package org.communiquons.android.comunic.client;
|
||||||
|
|
||||||
import android.app.AlertDialog;
|
import android.app.AlertDialog;
|
||||||
|
import android.app.FragmentManager;
|
||||||
|
import android.app.FragmentTransaction;
|
||||||
import android.content.DialogInterface;
|
import android.content.DialogInterface;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.support.v7.app.AppCompatActivity;
|
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
import android.support.annotation.NonNull;
|
||||||
|
import android.support.design.widget.BottomNavigationView;
|
||||||
|
import android.support.v7.app.AppCompatActivity;
|
||||||
import android.view.Menu;
|
import android.view.Menu;
|
||||||
import android.view.MenuItem;
|
import android.view.MenuItem;
|
||||||
import android.widget.ImageView;
|
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
|
||||||
import org.communiquons.android.comunic.client.api.APIRequestTask;
|
import org.communiquons.android.comunic.client.api.APIRequestTask;
|
||||||
import org.communiquons.android.comunic.client.data.Account.Account;
|
import org.communiquons.android.comunic.client.data.Account.Account;
|
||||||
import org.communiquons.android.comunic.client.data.Account.AccountUtils;
|
import org.communiquons.android.comunic.client.data.Account.AccountUtils;
|
||||||
import org.communiquons.android.comunic.client.data.DatabaseHelper;
|
import org.communiquons.android.comunic.client.fragments.FriendsListFragment;
|
||||||
import org.communiquons.android.comunic.client.data.ImageLoadTask;
|
import org.communiquons.android.comunic.client.fragments.UserInfosFragment;
|
||||||
import org.communiquons.android.comunic.client.data.UsersInfo.GetUsersInfos;
|
|
||||||
import org.communiquons.android.comunic.client.data.UsersInfo.UserInfo;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -41,6 +42,9 @@ public class MainActivity extends AppCompatActivity {
|
|||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
setContentView(R.layout.activity_main);
|
setContentView(R.layout.activity_main);
|
||||||
|
|
||||||
|
//Enable bottom navigation menu
|
||||||
|
init_bottom_menu();
|
||||||
|
|
||||||
//Check for connectivity
|
//Check for connectivity
|
||||||
if(!APIRequestTask.isAPIavailable(this)){
|
if(!APIRequestTask.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();
|
||||||
@ -48,28 +52,11 @@ public class MainActivity extends AppCompatActivity {
|
|||||||
|
|
||||||
//Initialize account objects
|
//Initialize account objects
|
||||||
account = new Account(this);
|
account = new Account(this);
|
||||||
aUtils = new AccountUtils(this);
|
|
||||||
|
|
||||||
//DEVELOPMENT : Try to get information about a user over the network
|
//If it is the first time the application is launched, started the user friends tab
|
||||||
GetUsersInfos uInfos = new GetUsersInfos(this, new DatabaseHelper(this));
|
if(savedInstanceState == null){
|
||||||
final ImageView imageView = (ImageView) findViewById(R.id.test_img);
|
openFriendsFragment();
|
||||||
|
}
|
||||||
//Get infos... about me! :)
|
|
||||||
final int uID = aUtils.get_current_user_id();
|
|
||||||
uInfos.get(uID, new GetUsersInfos.getUserInfosCallback() {
|
|
||||||
@Override
|
|
||||||
public void callback(UserInfo info) {
|
|
||||||
if(info == null)
|
|
||||||
Toast.makeText(MainActivity.this, "Failure !", Toast.LENGTH_SHORT).show();
|
|
||||||
else {
|
|
||||||
Toast.makeText(MainActivity.this, uID + " is " + info.getFullName() + "!", Toast.LENGTH_SHORT).show();
|
|
||||||
|
|
||||||
new ImageLoadTask(MainActivity.this, info.getAcountImageURL(), imageView).execute();
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -84,7 +71,7 @@ public class MainActivity extends AppCompatActivity {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Menu creation
|
* Top menu creation
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public boolean onCreateOptionsMenu(Menu menu) {
|
public boolean onCreateOptionsMenu(Menu menu) {
|
||||||
@ -108,6 +95,37 @@ public class MainActivity extends AppCompatActivity {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Bottom menu creation
|
||||||
|
*/
|
||||||
|
void init_bottom_menu(){
|
||||||
|
BottomNavigationView navigation =
|
||||||
|
(BottomNavigationView) findViewById(R.id.main_bottom_navigation);
|
||||||
|
navigation.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 choosed to show informations about him
|
||||||
|
case R.id.main_bottom_navigation_me_view:
|
||||||
|
openUserInfosFragment();
|
||||||
|
return true;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
//Selected element not found
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 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
|
||||||
*/
|
*/
|
||||||
@ -139,4 +157,28 @@ public class MainActivity extends AppCompatActivity {
|
|||||||
//Show popup
|
//Show popup
|
||||||
.create().show();
|
.create().show();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Open the friends list fragment
|
||||||
|
*/
|
||||||
|
void openFriendsFragment(){
|
||||||
|
|
||||||
|
FriendsListFragment friendsListFragment = new FriendsListFragment();
|
||||||
|
FragmentTransaction transaction = getFragmentManager().beginTransaction();
|
||||||
|
transaction.replace(R.id.main_fragment, friendsListFragment);
|
||||||
|
transaction.addToBackStack(null);
|
||||||
|
transaction.commit();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Open the user information fragment
|
||||||
|
*/
|
||||||
|
void openUserInfosFragment(){
|
||||||
|
UserInfosFragment userInfosFragment = new UserInfosFragment();
|
||||||
|
FragmentTransaction transaction = getFragmentManager().beginTransaction();
|
||||||
|
transaction.replace(R.id.main_fragment, userInfosFragment);
|
||||||
|
transaction.addToBackStack(null);
|
||||||
|
transaction.commit();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,30 @@
|
|||||||
|
package org.communiquons.android.comunic.client.fragments;
|
||||||
|
|
||||||
|
import android.app.Fragment;
|
||||||
|
import android.os.Bundle;
|
||||||
|
import android.support.annotation.Nullable;
|
||||||
|
import android.view.LayoutInflater;
|
||||||
|
import android.view.View;
|
||||||
|
import android.view.ViewGroup;
|
||||||
|
|
||||||
|
import org.communiquons.android.comunic.client.R;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Friends list fragment
|
||||||
|
*
|
||||||
|
* @author Pierre HUBERT
|
||||||
|
* Created by pierre on 11/11/17.
|
||||||
|
*/
|
||||||
|
|
||||||
|
public class FriendsListFragment extends Fragment {
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
@Override
|
||||||
|
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container,
|
||||||
|
Bundle savedInstanceState) {
|
||||||
|
|
||||||
|
//Inflate the layout for this fragment
|
||||||
|
return inflater.inflate(R.layout.fragment_friendslist, container, false);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,29 @@
|
|||||||
|
package org.communiquons.android.comunic.client.fragments;
|
||||||
|
|
||||||
|
|
||||||
|
import android.app.Fragment;
|
||||||
|
import android.os.Bundle;
|
||||||
|
import android.support.annotation.Nullable;
|
||||||
|
import android.view.LayoutInflater;
|
||||||
|
import android.view.View;
|
||||||
|
import android.view.ViewGroup;
|
||||||
|
|
||||||
|
import org.communiquons.android.comunic.client.R;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* User informations fragment
|
||||||
|
*
|
||||||
|
* This fragment display informations about the user
|
||||||
|
*
|
||||||
|
* @author Pierre HUBERT
|
||||||
|
* Created by pierre on 11/11/17.
|
||||||
|
*/
|
||||||
|
|
||||||
|
public class UserInfosFragment extends Fragment {
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
@Override
|
||||||
|
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, Bundle savedInstanceState) {
|
||||||
|
return inflater.inflate(R.layout.fragment_userinfos, container, false);
|
||||||
|
}
|
||||||
|
}
|
BIN
app/src/main/res/drawable/ic_menu_allfriends.png
Normal file
BIN
app/src/main/res/drawable/ic_menu_allfriends.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 4.5 KiB |
BIN
app/src/main/res/drawable/ic_menu_home.png
Normal file
BIN
app/src/main/res/drawable/ic_menu_home.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 3.8 KiB |
@ -1,28 +1,23 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
<LinearLayout 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:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
tools:context="org.communiquons.android.comunic.client.MainActivity">
|
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||||
|
android:orientation="vertical">
|
||||||
|
|
||||||
<TextView
|
<FrameLayout
|
||||||
android:layout_width="wrap_content"
|
android:id="@+id/main_fragment"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="0dp"
|
||||||
|
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_height="wrap_content"
|
||||||
android:text="Hello World!"
|
android:layout_gravity="bottom"
|
||||||
app:layout_constraintBottom_toBottomOf="parent"
|
android:background="?android:attr/windowBackground"
|
||||||
app:layout_constraintLeft_toLeftOf="parent"
|
app:menu="@menu/main_bottom_navigation" />
|
||||||
app:layout_constraintRight_toRightOf="parent"
|
|
||||||
app:layout_constraintTop_toTopOf="parent" />
|
|
||||||
|
|
||||||
<ImageView
|
</LinearLayout>
|
||||||
android:id="@+id/test_img"
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
tools:layout_width="100dp"
|
|
||||||
tools:layout_height="100dp"
|
|
||||||
app:layout_constraintTop_toTopOf="parent"
|
|
||||||
app:layout_constraintLeft_toLeftOf="parent"
|
|
||||||
/>
|
|
||||||
|
|
||||||
</android.support.constraint.ConstraintLayout>
|
|
11
app/src/main/res/layout/fragment_friendslist.xml
Normal file
11
app/src/main/res/layout/fragment_friendslist.xml
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:orientation="vertical" android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent">
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="Hello from friends list"/>
|
||||||
|
|
||||||
|
</LinearLayout>
|
11
app/src/main/res/layout/fragment_userinfos.xml
Normal file
11
app/src/main/res/layout/fragment_userinfos.xml
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:orientation="vertical" android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent">
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="Hello from informations fragment !"/>
|
||||||
|
|
||||||
|
</LinearLayout>
|
15
app/src/main/res/menu/main_bottom_navigation.xml
Normal file
15
app/src/main/res/menu/main_bottom_navigation.xml
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<menu xmlns:android="http://schemas.android.com/apk/res/android">
|
||||||
|
<item
|
||||||
|
android:id="@+id/main_bottom_navigation_friends_list"
|
||||||
|
android:title="@string/navigation_bottom_friends_item"
|
||||||
|
android:icon="@drawable/ic_menu_allfriends"
|
||||||
|
/>
|
||||||
|
|
||||||
|
<item
|
||||||
|
android:id="@+id/main_bottom_navigation_me_view"
|
||||||
|
android:title="@string/navigation_bottom_me_item"
|
||||||
|
android:icon="@drawable/ic_menu_home"
|
||||||
|
/>
|
||||||
|
|
||||||
|
</menu>
|
@ -14,4 +14,6 @@
|
|||||||
<string name="popup_signout_message">Are you sure do you want to sign out ?</string>
|
<string name="popup_signout_message">Are you sure do you want to sign out ?</string>
|
||||||
<string name="popup_signout_confirm_button">Sign out</string>
|
<string name="popup_signout_confirm_button">Sign out</string>
|
||||||
<string name="popup_signout_cancel_button">Cancel</string>
|
<string name="popup_signout_cancel_button">Cancel</string>
|
||||||
|
<string name="navigation_bottom_friends_item">Friends</string>
|
||||||
|
<string name="navigation_bottom_me_item">Me</string>
|
||||||
</resources>
|
</resources>
|
||||||
|
Loading…
Reference in New Issue
Block a user