mirror of
https://github.com/pierre42100/ComunicAndroid
synced 2024-11-27 15:59:29 +00:00
Notification system ready.
This commit is contained in:
parent
281821333c
commit
e66e077964
@ -40,7 +40,7 @@ public class PostsList extends ArrayList<Post> {
|
|||||||
//Process the list of comments
|
//Process the list of comments
|
||||||
for(Comment comment : post.getComments_list()){
|
for(Comment comment : post.getComments_list()){
|
||||||
|
|
||||||
if(ids.contains(comment.getUserID()))
|
if(!ids.contains(comment.getUserID()))
|
||||||
ids.add(comment.getUserID());
|
ids.add(comment.getUserID());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -23,8 +23,10 @@ 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.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.ui.fragments.SinglePostFragment;
|
||||||
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.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.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;
|
||||||
@ -44,7 +46,7 @@ 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 openConversationListener,
|
||||||
updateConversationListener, onOpenUsersPageListener {
|
updateConversationListener, onOpenUsersPageListener, onPostOpenListener {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Debug tag
|
* Debug tag
|
||||||
@ -458,4 +460,22 @@ public class MainActivity extends AppCompatActivity implements openConversationL
|
|||||||
transaction.addToBackStack(null);
|
transaction.addToBackStack(null);
|
||||||
transaction.commit();
|
transaction.commit();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onOpenPost(int postID) {
|
||||||
|
|
||||||
|
//Prepare the arguments
|
||||||
|
Bundle arguments = new Bundle();
|
||||||
|
arguments.putInt(SinglePostFragment.ARGUMENT_POST_ID, postID);
|
||||||
|
|
||||||
|
//Create the fragment
|
||||||
|
SinglePostFragment singlePostFragment = new SinglePostFragment();
|
||||||
|
singlePostFragment.setArguments(arguments);
|
||||||
|
|
||||||
|
//Perform the transaction
|
||||||
|
FragmentTransaction transaction = getFragmentManager().beginTransaction();
|
||||||
|
transaction.addToBackStack(null);
|
||||||
|
transaction.replace(R.id.main_fragment, singlePostFragment);
|
||||||
|
transaction.commit();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -27,6 +27,7 @@ import org.communiquons.android.comunic.client.data.models.Notif;
|
|||||||
import org.communiquons.android.comunic.client.ui.activities.MainActivity;
|
import org.communiquons.android.comunic.client.ui.activities.MainActivity;
|
||||||
import org.communiquons.android.comunic.client.ui.adapters.NotificationsAdapter;
|
import org.communiquons.android.comunic.client.ui.adapters.NotificationsAdapter;
|
||||||
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;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Notifications fragment
|
* Notifications fragment
|
||||||
@ -78,6 +79,11 @@ public class NotificationsFragment extends Fragment implements View.OnCreateCont
|
|||||||
*/
|
*/
|
||||||
private onOpenUsersPageListener mUserPageOpener;
|
private onOpenUsersPageListener mUserPageOpener;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Post open listener
|
||||||
|
*/
|
||||||
|
private onPostOpenListener mOpenPostListener;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onAttach(Context context) {
|
public void onAttach(Context context) {
|
||||||
super.onAttach(context);
|
super.onAttach(context);
|
||||||
@ -129,6 +135,9 @@ public class NotificationsFragment extends Fragment implements View.OnCreateCont
|
|||||||
//Get user page opener
|
//Get user page opener
|
||||||
mUserPageOpener = (onOpenUsersPageListener) getActivity();
|
mUserPageOpener = (onOpenUsersPageListener) getActivity();
|
||||||
|
|
||||||
|
//Get post opener
|
||||||
|
mOpenPostListener = (onPostOpenListener) getActivity();
|
||||||
|
|
||||||
//Check if it is required to fetch the list of notifications
|
//Check if it is required to fetch the list of notifications
|
||||||
if(mNotificationsList == null){
|
if(mNotificationsList == null){
|
||||||
|
|
||||||
@ -331,12 +340,12 @@ public class NotificationsFragment extends Fragment implements View.OnCreateCont
|
|||||||
@Override
|
@Override
|
||||||
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
|
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
|
||||||
|
|
||||||
//Delete the notification
|
|
||||||
//deleteNotification(position);
|
|
||||||
|
|
||||||
//Perform notification action
|
//Perform notification action
|
||||||
Notif notif = mNotificationsList.get(position);
|
Notif notif = mNotificationsList.get(position);
|
||||||
|
|
||||||
|
//Delete the notification
|
||||||
|
deleteNotification(position);
|
||||||
|
|
||||||
//For friendship request
|
//For friendship request
|
||||||
if(notif.getOn_elem_type() == NotifElemType.FRIEND_REQUEST){
|
if(notif.getOn_elem_type() == NotifElemType.FRIEND_REQUEST){
|
||||||
|
|
||||||
@ -345,5 +354,12 @@ public class NotificationsFragment extends Fragment implements View.OnCreateCont
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//If the notification is targeting a post
|
||||||
|
if(notif.getOn_elem_type() == NotifElemType.POST){
|
||||||
|
|
||||||
|
//Open the post
|
||||||
|
mOpenPostListener.onOpenPost(notif.getOn_elem_id());
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,169 @@
|
|||||||
|
package org.communiquons.android.comunic.client.ui.fragments;
|
||||||
|
|
||||||
|
import android.app.Fragment;
|
||||||
|
import android.app.FragmentTransaction;
|
||||||
|
import android.content.Context;
|
||||||
|
import android.os.AsyncTask;
|
||||||
|
import android.os.Bundle;
|
||||||
|
import android.support.annotation.Nullable;
|
||||||
|
import android.util.ArrayMap;
|
||||||
|
import android.view.LayoutInflater;
|
||||||
|
import android.view.View;
|
||||||
|
import android.view.ViewGroup;
|
||||||
|
import android.widget.Toast;
|
||||||
|
|
||||||
|
import org.communiquons.android.comunic.client.R;
|
||||||
|
import org.communiquons.android.comunic.client.data.arrays.PostsList;
|
||||||
|
import org.communiquons.android.comunic.client.data.helpers.GetUsersHelper;
|
||||||
|
import org.communiquons.android.comunic.client.data.helpers.PostsHelper;
|
||||||
|
import org.communiquons.android.comunic.client.data.models.Post;
|
||||||
|
import org.communiquons.android.comunic.client.data.models.UserInfo;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Single post fragment
|
||||||
|
*
|
||||||
|
* This fragment allows to display a single post
|
||||||
|
*
|
||||||
|
* @author Pierre HUBERT
|
||||||
|
* Created by pierre on 4/12/18.
|
||||||
|
*/
|
||||||
|
|
||||||
|
public class SinglePostFragment extends Fragment {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The name of the argument that contains the ID of the post to open
|
||||||
|
*/
|
||||||
|
public static final String ARGUMENT_POST_ID = "post_id";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The ID of the post
|
||||||
|
*/
|
||||||
|
private int mPostID = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Information about the post
|
||||||
|
*/
|
||||||
|
private Post mPost;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Post list that contains only a single post
|
||||||
|
*/
|
||||||
|
private PostsList mPostsList;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Information about the related users
|
||||||
|
*/
|
||||||
|
private ArrayMap<Integer, UserInfo> mUserInfo;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Post helper
|
||||||
|
*/
|
||||||
|
private PostsHelper mPostsHelper;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get user information helper
|
||||||
|
*/
|
||||||
|
private GetUsersHelper mGetUserHelper;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onAttach(Context context) {
|
||||||
|
super.onAttach(context);
|
||||||
|
|
||||||
|
//Create post helper
|
||||||
|
mPostsHelper = new PostsHelper(context);
|
||||||
|
|
||||||
|
//Create get user helper
|
||||||
|
mGetUserHelper = new GetUsersHelper(context);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onCreate(@Nullable Bundle savedInstanceState) {
|
||||||
|
super.onCreate(savedInstanceState);
|
||||||
|
|
||||||
|
//Get post ID
|
||||||
|
mPostID = getArguments().getInt(ARGUMENT_POST_ID);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
@Override
|
||||||
|
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, Bundle savedInstanceState) {
|
||||||
|
return inflater.inflate(R.layout.fragment_single_post, container, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onResume() {
|
||||||
|
super.onResume();
|
||||||
|
|
||||||
|
//Check if the fragment contains information about the post
|
||||||
|
if(mPost == null || mUserInfo == null){
|
||||||
|
getPostInfo();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
onGotPostInfo();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get information about the post and its related users
|
||||||
|
*/
|
||||||
|
private void getPostInfo(){
|
||||||
|
|
||||||
|
//Perform the request in the background
|
||||||
|
new AsyncTask<Integer, Void, Void>(){
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Void doInBackground(Integer... params) {
|
||||||
|
|
||||||
|
//Intend to get information about the post
|
||||||
|
mPost = mPostsHelper.getSingle(params[0]);
|
||||||
|
|
||||||
|
if(mPost != null) {
|
||||||
|
mPostsList = new PostsList();
|
||||||
|
mPostsList.add(mPost);
|
||||||
|
mUserInfo = mGetUserHelper.getMultiple(mPostsList.getUsersId());
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onPostExecute(Void aVoid) {
|
||||||
|
|
||||||
|
if(getActivity() == null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
onGotPostInfo();
|
||||||
|
}
|
||||||
|
}.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, mPostID);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This method is triggered once we got informations about the post
|
||||||
|
*/
|
||||||
|
private void onGotPostInfo(){
|
||||||
|
|
||||||
|
//Check if we did not get post information
|
||||||
|
if(mPost == null){
|
||||||
|
Toast.makeText(getActivity(), R.string.err_get_post_info, Toast.LENGTH_SHORT).show();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
//Check if we could not get user information
|
||||||
|
if(mUserInfo == null){
|
||||||
|
Toast.makeText(getActivity(), R.string.err_get_users_info, Toast.LENGTH_SHORT).show();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
//Apply the post fragment
|
||||||
|
PostsListFragment postsListFragment = new PostsListFragment();
|
||||||
|
postsListFragment.setPostsList(mPostsList);
|
||||||
|
postsListFragment.setUsersInfos(mUserInfo);
|
||||||
|
|
||||||
|
//Create and commit a transaction
|
||||||
|
FragmentTransaction transaction = getChildFragmentManager().beginTransaction();
|
||||||
|
transaction.replace(R.id.posts_list_target, postsListFragment);
|
||||||
|
transaction.commit();
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,19 @@
|
|||||||
|
package org.communiquons.android.comunic.client.ui.listeners;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This interface must be implemented by all the activities that can open post
|
||||||
|
*
|
||||||
|
* @author Pierre HUBERT
|
||||||
|
* Created by pierre on 4/12/18.
|
||||||
|
*/
|
||||||
|
|
||||||
|
public interface onPostOpenListener {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This method is triggered when a request to open a single post is made
|
||||||
|
*
|
||||||
|
* @param postID The ID of the post to open
|
||||||
|
*/
|
||||||
|
void onOpenPost(int postID);
|
||||||
|
|
||||||
|
}
|
11
app/src/main/res/layout/fragment_single_post.xml
Normal file
11
app/src/main/res/layout/fragment_single_post.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">
|
||||||
|
|
||||||
|
<FrameLayout
|
||||||
|
android:id="@+id/posts_list_target"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent" />
|
||||||
|
|
||||||
|
</LinearLayout>
|
@ -172,4 +172,5 @@
|
|||||||
<string name="button_accept_friend_request">Accept request</string>
|
<string name="button_accept_friend_request">Accept request</string>
|
||||||
<string name="button_reject_friend_request">Reject request</string>
|
<string name="button_reject_friend_request">Reject request</string>
|
||||||
<string name="err_get_friendship_status">An error occurred while retrieving friendship status!</string>
|
<string name="err_get_friendship_status">An error occurred while retrieving friendship status!</string>
|
||||||
|
<string name="err_get_post_info">An error occurred while trying to get post information!</string>
|
||||||
</resources>
|
</resources>
|
||||||
|
Loading…
Reference in New Issue
Block a user