mirror of
https://github.com/pierre42100/ComunicAndroid
synced 2024-11-23 22:09:30 +00:00
Created the update conversation fragment
This commit is contained in:
parent
fc9d09fcd4
commit
ae5f851101
@ -21,6 +21,7 @@ import org.communiquons.android.comunic.client.data.friendsList.FriendRefreshLoo
|
||||
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.UpdateConversationFragment;
|
||||
import org.communiquons.android.comunic.client.fragments.UserInfosFragment;
|
||||
|
||||
|
||||
@ -30,7 +31,8 @@ import org.communiquons.android.comunic.client.fragments.UserInfosFragment;
|
||||
* @author Pierre HUBERT
|
||||
*/
|
||||
public class MainActivity extends AppCompatActivity
|
||||
implements ConversationsListHelper.openConversationListener {
|
||||
implements ConversationsListHelper.openConversationListener,
|
||||
ConversationsListHelper.updateConversationListener {
|
||||
|
||||
/**
|
||||
* Account object
|
||||
@ -276,4 +278,26 @@ public class MainActivity extends AppCompatActivity
|
||||
transaction.commit();
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void createConversation() {
|
||||
updateConversation(0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateConversation(int convID) {
|
||||
|
||||
//Set the arguments of the fragment
|
||||
Bundle args = new Bundle();
|
||||
|
||||
//Create the fragment
|
||||
UpdateConversationFragment updateConversationFragment = new UpdateConversationFragment();
|
||||
updateConversationFragment.setArguments(args);
|
||||
|
||||
//Display the fragment
|
||||
FragmentTransaction transaction = getFragmentManager().beginTransaction();
|
||||
transaction.replace(R.id.main_fragment, updateConversationFragment);
|
||||
transaction.addToBackStack(null);
|
||||
transaction.commit();
|
||||
}
|
||||
}
|
||||
|
@ -298,4 +298,22 @@ public class ConversationsListHelper {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles the creation and / or the update of a conversation
|
||||
*/
|
||||
public interface updateConversationListener {
|
||||
|
||||
/**
|
||||
* This method is called when a user wants to create a new conversation
|
||||
*/
|
||||
void createConversation();
|
||||
|
||||
/**
|
||||
* This method is called when the user want to open a conversation
|
||||
*
|
||||
* @param convID The ID of the conversation to open
|
||||
*/
|
||||
void updateConversation(int convID);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,9 +1,7 @@
|
||||
package org.communiquons.android.comunic.client.fragments;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.AlertDialog;
|
||||
import android.app.Fragment;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.os.AsyncTask;
|
||||
import android.os.Bundle;
|
||||
@ -30,8 +28,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 org.communiquons.android.comunic.client.data.conversations.ConversationsListHelper.openConversationListener;
|
||||
import org.communiquons.android.comunic.client.data.conversations.ConversationsListHelper.updateConversationListener;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
@ -76,6 +74,11 @@ public class ConversationsListFragment extends Fragment implements AdapterView.O
|
||||
*/
|
||||
private openConversationListener openConvListener;
|
||||
|
||||
/**
|
||||
* Conversation updater
|
||||
*/
|
||||
private updateConversationListener updateConversationListener;
|
||||
|
||||
/**
|
||||
* Conversation list adapter
|
||||
*/
|
||||
@ -114,13 +117,23 @@ public class ConversationsListFragment extends Fragment implements AdapterView.O
|
||||
//Refresh conversations list
|
||||
refresh_conversations_list();
|
||||
|
||||
//Set the open conversation listener
|
||||
//Set the open and update conversation listener
|
||||
try {
|
||||
openConvListener = (openConversationListener) getActivity();
|
||||
updateConversationListener = (updateConversationListener) getActivity();
|
||||
} catch (ClassCastException e){
|
||||
throw new ClassCastException(getActivity().toString() +
|
||||
" must implement OpenConversationListener");
|
||||
" must implement OpenConversationListener and updateConversationListener");
|
||||
}
|
||||
|
||||
//Set create conversation button listener
|
||||
view.findViewById(R.id.fragment_conversationslist_create)
|
||||
.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
updateConversationListener.createConversation();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -287,7 +300,7 @@ public class ConversationsListFragment extends Fragment implements AdapterView.O
|
||||
@Override
|
||||
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenu.ContextMenuInfo menuInfo) {
|
||||
MenuInflater inflater = getActivity().getMenuInflater();
|
||||
inflater.inflate(R.menu.menu_fragment_conserationslist_item, menu);
|
||||
inflater.inflate(R.menu.menu_fragment_conversationslist_item, menu);
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -0,0 +1,94 @@
|
||||
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.Button;
|
||||
import android.widget.CheckBox;
|
||||
import android.widget.ListView;
|
||||
import android.widget.TextView;
|
||||
|
||||
import org.communiquons.android.comunic.client.MainActivity;
|
||||
import org.communiquons.android.comunic.client.R;
|
||||
|
||||
/**
|
||||
* Create and / or update a conversation fragment
|
||||
*
|
||||
* @author Pierre HUBERT
|
||||
* Created by pierre on 1/1/18.
|
||||
*/
|
||||
|
||||
public class UpdateConversationFragment extends Fragment {
|
||||
|
||||
/**
|
||||
* The name of the conversation
|
||||
*/
|
||||
private TextView nameView;
|
||||
|
||||
/**
|
||||
* Follow a conversation checkbox
|
||||
*/
|
||||
private CheckBox followCheckbox;
|
||||
|
||||
/**
|
||||
* Members listview
|
||||
*/
|
||||
private ListView membersList;
|
||||
|
||||
/**
|
||||
* Add a member button
|
||||
*/
|
||||
private Button addMember;
|
||||
|
||||
/**
|
||||
* Submit the conversation button
|
||||
*/
|
||||
private Button submitButton;
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, Bundle savedInstanceState) {
|
||||
return inflater.inflate(R.layout.fragment_update_conversation, container, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
|
||||
super.onViewCreated(view, savedInstanceState);
|
||||
|
||||
//Get the view
|
||||
nameView = view.findViewById(R.id.fragment_update_conversation_name);
|
||||
followCheckbox = view.findViewById(R.id.fragment_update_conversation_follow);
|
||||
membersList = view.findViewById(R.id.fragment_update_conversation_members);
|
||||
addMember = view.findViewById(R.id.fragment_update_conversation_addmember);
|
||||
submitButton = view.findViewById(R.id.fragment_update_conversation_submit);
|
||||
|
||||
//Make add button lives
|
||||
addMember.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
requestAddMember();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
|
||||
//Update title and dock
|
||||
getActivity().setTitle(R.string.fragment_update_conversation_title_create);
|
||||
((MainActivity) getActivity()).setSelectedNavigationItem(
|
||||
R.id.main_bottom_navigation_conversations);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create and submit an intent to add a user to the members list
|
||||
*/
|
||||
private void requestAddMember(){
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -23,8 +23,9 @@
|
||||
|
||||
<!-- Create new conversations button -->
|
||||
<Button
|
||||
android:id="@+id/fragment_conversationslist_create"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/fragment_conversationslist_create_button"
|
||||
android:enabled="false" /><!-- Not available yet -->
|
||||
android:enabled="true" />
|
||||
</LinearLayout>
|
52
app/src/main/res/layout/fragment_update_conversation.xml
Normal file
52
app/src/main/res/layout/fragment_update_conversation.xml
Normal file
@ -0,0 +1,52 @@
|
||||
<?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">
|
||||
|
||||
<!-- Conversation name -->
|
||||
<android.support.design.widget.TextInputLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content">
|
||||
|
||||
<EditText
|
||||
android:id="@+id/fragment_update_conversation_name"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:hint="@string/fragment_update_conversation_name_placeholder"
|
||||
android:inputType="textCapSentences"
|
||||
android:maxLines="1"
|
||||
/>
|
||||
|
||||
</android.support.design.widget.TextInputLayout>
|
||||
|
||||
<!-- Conversation members -->
|
||||
<ListView
|
||||
android:id="@+id/fragment_update_conversation_members"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="0dp"
|
||||
android:layout_weight="1"/>
|
||||
|
||||
<Button
|
||||
android:id="@+id/fragment_update_conversation_addmember"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:padding="0dp"
|
||||
android:text="@string/fragment_update_conversation_addmember"
|
||||
/>
|
||||
|
||||
<!-- Follow or not the conversation -->
|
||||
<CheckBox
|
||||
android:id="@+id/fragment_update_conversation_follow"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/fragment_update_conversation_follow"/>
|
||||
|
||||
<!-- Create the conversation -->
|
||||
<Button
|
||||
android:id="@+id/fragment_update_conversation_submit"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/fragment_update_conversation_button_create"
|
||||
android:background="@color/colorPrimary"/>
|
||||
|
||||
</LinearLayout>
|
@ -74,4 +74,9 @@
|
||||
<string name="popup_deleteconversation_cancel">Cancel</string>
|
||||
<string name="fragment_conversationslist_err_del_conversation">Could not delete conversation !</string>
|
||||
<string name="fragment_conversation_no_msg">No message yet.</string>
|
||||
<string name="fragment_update_conversation_title_create">Create a conversation</string>
|
||||
<string name="fragment_update_conversation_name_placeholder">Conversation name</string>
|
||||
<string name="fragment_update_conversation_button_create">Create</string>
|
||||
<string name="fragment_update_conversation_follow">Follow the conversation</string>
|
||||
<string name="fragment_update_conversation_addmember">Add a member</string>
|
||||
</resources>
|
||||
|
Loading…
Reference in New Issue
Block a user