mirror of
https://github.com/pierre42100/ComunicAndroid
synced 2024-11-23 22:09:30 +00:00
Created Conversation Fragment
This commit is contained in:
parent
d4f586631c
commit
5343372f21
@ -16,7 +16,9 @@ import org.communiquons.android.comunic.client.api.APIRequest;
|
||||
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.DatabaseHelper;
|
||||
import org.communiquons.android.comunic.client.data.conversations.ConversationsListHelper;
|
||||
import org.communiquons.android.comunic.client.data.friendsList.FriendRefreshLoopRunnable;
|
||||
import org.communiquons.android.comunic.client.fragments.ConversationFragment;
|
||||
import org.communiquons.android.comunic.client.fragments.ConversationsListFragment;
|
||||
import org.communiquons.android.comunic.client.fragments.FriendsListFragment;
|
||||
import org.communiquons.android.comunic.client.fragments.UserInfosFragment;
|
||||
@ -27,7 +29,8 @@ import org.communiquons.android.comunic.client.fragments.UserInfosFragment;
|
||||
*
|
||||
* @author Pierre HUBERT
|
||||
*/
|
||||
public class MainActivity extends AppCompatActivity {
|
||||
public class MainActivity extends AppCompatActivity
|
||||
implements ConversationsListHelper.openConversationListener {
|
||||
|
||||
/**
|
||||
* Account object
|
||||
@ -236,4 +239,28 @@ public class MainActivity extends AppCompatActivity {
|
||||
transaction.addToBackStack(null);
|
||||
transaction.commit();
|
||||
}
|
||||
|
||||
/**
|
||||
* Open a conversation
|
||||
*
|
||||
* @param id The ID of the conversation to open
|
||||
*/
|
||||
@Override
|
||||
public void openConversation(int id) {
|
||||
|
||||
//Set the arguments for the conversation
|
||||
Bundle args = new Bundle();
|
||||
args.putInt(ConversationFragment.ARG_CONVERSATION_ID ,id);
|
||||
|
||||
//Create the fragment
|
||||
ConversationFragment conversationFragment = new ConversationFragment();
|
||||
conversationFragment.setArguments(args);
|
||||
|
||||
//Display it
|
||||
FragmentTransaction transaction = getFragmentManager().beginTransaction();
|
||||
transaction.replace(R.id.main_fragment, conversationFragment);
|
||||
transaction.addToBackStack(null);
|
||||
transaction.commit();
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -137,4 +137,20 @@ public class ConversationsListHelper {
|
||||
return info;
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles the opening of a conversation
|
||||
*
|
||||
* This interface should be implemented in all the activity that should handle such action
|
||||
*/
|
||||
public interface openConversationListener {
|
||||
|
||||
/**
|
||||
* Open the conversation specified by its ID
|
||||
*
|
||||
* @param id The ID of the conversation to open
|
||||
*/
|
||||
void openConversation(int id);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,65 @@
|
||||
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 android.widget.Toast;
|
||||
|
||||
import org.communiquons.android.comunic.client.R;
|
||||
|
||||
/**
|
||||
* Conversation fragment
|
||||
*
|
||||
* Display a conversation, its message. Allow the user to send and receive messages
|
||||
*
|
||||
* @author Pierre HUBERT
|
||||
* Created by pierre on 12/16/17.
|
||||
*/
|
||||
|
||||
public class ConversationFragment extends Fragment {
|
||||
|
||||
/**
|
||||
* Debug tag
|
||||
*/
|
||||
private static final String TAG = "ConversationFragment";
|
||||
|
||||
/**
|
||||
* The conversation ID argument
|
||||
*/
|
||||
public static final String ARG_CONVERSATION_ID = "conversation_id";
|
||||
|
||||
/**
|
||||
* The conversation ID
|
||||
*/
|
||||
private int conversation_id;
|
||||
|
||||
|
||||
@Override
|
||||
public void onCreate(@Nullable Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
//Get the conversation ID
|
||||
conversation_id = getArguments().getInt(ARG_CONVERSATION_ID);
|
||||
|
||||
if(conversation_id < 1){
|
||||
throw new RuntimeException(TAG + " requires a valid conversation ID when created !");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, Bundle savedInstanceState) {
|
||||
return inflater.inflate(R.layout.fragment_conversation, container, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
|
||||
super.onViewCreated(view, savedInstanceState);
|
||||
|
||||
Toast.makeText(getActivity(), "Open : " + conversation_id, Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
}
|
@ -1,6 +1,8 @@
|
||||
package org.communiquons.android.comunic.client.fragments;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.Fragment;
|
||||
import android.content.Context;
|
||||
import android.os.AsyncTask;
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.Nullable;
|
||||
@ -9,6 +11,7 @@ import android.util.Log;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.AdapterView;
|
||||
import android.widget.ListView;
|
||||
import android.widget.Toast;
|
||||
|
||||
@ -19,6 +22,8 @@ import org.communiquons.android.comunic.client.data.UsersInfo.UserInfo;
|
||||
import org.communiquons.android.comunic.client.data.conversations.ConversationsInfo;
|
||||
import org.communiquons.android.comunic.client.data.conversations.ConversationsListAdapter;
|
||||
import org.communiquons.android.comunic.client.data.conversations.ConversationsListHelper;
|
||||
import org.communiquons.android.comunic.client.data.conversations.ConversationsListHelper
|
||||
.openConversationListener;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
@ -31,7 +36,7 @@ import java.util.ArrayList;
|
||||
* Created by pierre on 12/6/17.
|
||||
*/
|
||||
|
||||
public class ConversationsListFragment extends Fragment {
|
||||
public class ConversationsListFragment extends Fragment implements AdapterView.OnItemClickListener {
|
||||
|
||||
/**
|
||||
* Debug tag
|
||||
@ -58,6 +63,11 @@ public class ConversationsListFragment extends Fragment {
|
||||
*/
|
||||
private ListView conversationsListView;
|
||||
|
||||
/**
|
||||
* Conversation opener
|
||||
*/
|
||||
private openConversationListener openConvListener;
|
||||
|
||||
/**
|
||||
* Conversation list adapter
|
||||
*/
|
||||
@ -103,12 +113,20 @@ public class ConversationsListFragment extends Fragment {
|
||||
}
|
||||
}.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||
|
||||
|
||||
//Set the open conversation listener
|
||||
try {
|
||||
openConvListener = (openConversationListener) getActivity();
|
||||
} catch (ClassCastException e){
|
||||
throw new ClassCastException(getActivity().toString() +
|
||||
" must implement OpenConversationListener");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Process the conversation list
|
||||
*
|
||||
* This method must be called on a separate thread
|
||||
*
|
||||
* @param list The list of conversations
|
||||
*/
|
||||
public void process_conversations_list(ArrayList<ConversationsInfo> list){
|
||||
@ -211,5 +229,23 @@ public class ConversationsListFragment extends Fragment {
|
||||
|
||||
//Attach it to the view
|
||||
conversationsListView.setAdapter(conversationsListAdapter);
|
||||
|
||||
conversationsListView.setOnItemClickListener(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles the click on a conversation to open it
|
||||
*
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
|
||||
|
||||
//Get the clicked conversation
|
||||
ConversationsInfo conv = convList.get(position);
|
||||
|
||||
//Open the specified conversation
|
||||
openConvListener.openConversation(conv.getID());
|
||||
|
||||
}
|
||||
}
|
||||
|
11
app/src/main/res/layout/fragment_conversation.xml
Normal file
11
app/src/main/res/layout/fragment_conversation.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 conversation"/>
|
||||
|
||||
</LinearLayout>
|
Loading…
Reference in New Issue
Block a user