Intermediate commit

This commit is contained in:
Pierre 2017-12-18 19:00:28 +01:00
parent c0f62d4d72
commit ec7a852fc4
6 changed files with 176 additions and 7 deletions

2
.idea/misc.xml generated
View File

@ -55,7 +55,7 @@
<ConfirmationsSetting value="0" id="Add" />
<ConfirmationsSetting value="0" id="Remove" />
</component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_7" default="true" assert-keyword="true" jdk-15="true" project-jdk-name="1.8" project-jdk-type="JavaSDK">
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" default="true" assert-keyword="true" jdk-15="true" project-jdk-name="1.8" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/build/classes" />
</component>
<component name="ProjectType">

View File

@ -127,9 +127,8 @@ public class ConversationMessage {
*
* @return The content
*/
@NonNull
public String getContent() {
return content != null ? content : "";
return content;
}
/**

View File

@ -1,14 +1,20 @@
package org.communiquons.android.comunic.client.data.conversations;
import android.content.Context;
import android.os.Build;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.util.Log;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;
import org.communiquons.android.comunic.client.R;
import java.util.ArrayList;
/**
@ -20,14 +26,58 @@ import java.util.ArrayList;
public class ConversationMessageAdapter extends ArrayAdapter<ConversationMessage> {
/**
* Debug tag
*/
private static final String TAG = "ConversationMessageAdap";
/**
* Possible colors for the message
*/
private int usercolorText;
private int usercolorBackground;
private int otherusercolorText;
private int otherusercolorBackground;
/**
* The ID of the current user
*/
private int userID;
/**
* Public class constructor
*
* @param context The context of execution of the application
* @param list The dataset
* @param userID The ID of the current user
*/
public ConversationMessageAdapter(Context context, ArrayList<ConversationMessage> list){
public ConversationMessageAdapter(Context context, ArrayList<ConversationMessage> list,
int userID){
super(context, 0, list);
//Set user ID
this.userID = userID;
//Get the color codes
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
usercolorText = getContext().getResources().
getColor(R.color.conversation_user_messages_textColor, getContext().getTheme());
usercolorBackground = getContext().getResources().
getColor(R.color.conversation_user_messages_background, getContext().getTheme());
otherusercolorText = getContext().getResources().
getColor(R.color.conversation_otheruser_messages_textColor, getContext().getTheme());
otherusercolorBackground = getContext().getResources().
getColor(R.color.conversation_otheruser_messages_background, getContext().getTheme());
} else {
usercolorText = getContext().getResources().
getColor(R.color.conversation_user_messages_textColor);
usercolorBackground = getContext().getResources().
getColor(R.color.conversation_user_messages_background);
otherusercolorText = getContext().getResources().
getColor(R.color.conversation_otheruser_messages_textColor);
otherusercolorBackground = getContext().getResources().
getColor(R.color.conversation_otheruser_messages_background);
}
}
@ -35,11 +85,51 @@ public class ConversationMessageAdapter extends ArrayAdapter<ConversationMessage
@Override
public View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent) {
//Inflate view if required
if(convertView == null)
convertView = LayoutInflater.from(getContext()).
inflate(android.R.layout.simple_list_item_1, parent, false);
inflate(R.layout.fragment_conversation_message_item, parent, false);
((TextView) convertView).setText(getItem(position).getContent());
//Get the content of the message
ConversationMessage message = getItem(position);
assert message != null;
/*
Update message content
*/
//Set the text of the message
TextView contentView = convertView.
findViewById(R.id.fragment_conversation_message_item_content);
contentView.setText(message.getContent());
//Set the color of the message
Log.v(TAG, "User ID : " + message.getUser_id() + " current: " + userID);
if(message.getUser_id() == userID) {
contentView.setTextColor(usercolorText);
contentView.setBackgroundColor(usercolorBackground);
}
else {
contentView.setTextColor(otherusercolorText);
contentView.setBackgroundColor(otherusercolorBackground);
}
/*
Update account image
*/
//Get the image of the message
ImageView accountImage = convertView.
findViewById(R.id.fragment_conversation_message_item_accountimage);
if(message.getUser_id() == userID){
accountImage.setVisibility(View.GONE);
}
else {
accountImage.setVisibility(View.VISIBLE);
}
return convertView;
}

View File

@ -11,6 +11,7 @@ import android.widget.ListView;
import android.widget.Toast;
import org.communiquons.android.comunic.client.R;
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.ConversationMessage;
import org.communiquons.android.comunic.client.data.conversations.ConversationMessageAdapter;
@ -104,7 +105,8 @@ public class ConversationFragment extends Fragment
//Conversation messages listView
ListView convMessListView = view.findViewById(R.id.fragment_conversation_messageslist);
convMessAdapter = new ConversationMessageAdapter(getActivity(), messagesList);
int userID = new AccountUtils(getActivity()).get_current_user_id();
convMessAdapter = new ConversationMessageAdapter(getActivity(), messagesList, userID);
convMessListView.setAdapter(convMessAdapter);
}

View File

@ -0,0 +1,72 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="5dp"
android:paddingBottom="5dp"
android:paddingStart="5dp"
android:paddingEnd="5dp">
<LinearLayout
android:id="@+id/fragment_conversation_message_left"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="1dp">
<ImageView
android:id="@+id/fragment_conversation_message_item_accountimage"
android:layout_width="24dp"
android:layout_height="24dp"
android:layout_gravity="center"
android:layout_marginEnd="5dp"
android:src="@drawable/default_account_image" />
<TextView
android:id="@+id/fragment_conversation_message_item_content"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@color/conversation_otheruser_messages_background"
android:padding="5dp"
android:paddingStart="15dp"
android:paddingEnd="15dp"
tools:text="A message"
android:layout_gravity="center"
android:textColor="@color/conversation_otheruser_messages_textColor"/>
</LinearLayout>
<LinearLayout
android:id="@+id/fragment_conversation_message_right"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:padding="1dp">
<TextView
android:id="@+id/fragment_conversation_message_item_content_right"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@color/conversation_user_messages_background"
android:padding="5dp"
android:paddingStart="15dp"
android:paddingEnd="15dp"
tools:text="A message"
android:layout_gravity="center"
android:textColor="@color/conversation_user_messages_textColor"/>
<ImageView
android:id="@+id/fragment_conversation_message_item_accountimage_right"
android:layout_width="24dp"
android:layout_height="24dp"
android:layout_gravity="center"
android:layout_marginStart="5dp"
android:src="@drawable/default_account_image" />
</LinearLayout>
</LinearLayout>

View File

@ -8,4 +8,10 @@
<color name="darker_gray">#aaa</color>
<color name="darker_darker_gray">#5b5b5b</color>
<color name="dark_blue">#303F9F</color>
<!-- Conversation messages -->
<color name="conversation_user_messages_background">#3F51B5</color>
<color name="conversation_user_messages_textColor">#FFFFFF</color>
<color name="conversation_otheruser_messages_background">#aaa</color>
<color name="conversation_otheruser_messages_textColor">#000000</color>
</resources>