mirror of
https://github.com/pierre42100/ComunicAndroid
synced 2024-11-23 22:09:30 +00:00
Intermediate commit
This commit is contained in:
parent
c0f62d4d72
commit
ec7a852fc4
@ -55,7 +55,7 @@
|
|||||||
<ConfirmationsSetting value="0" id="Add" />
|
<ConfirmationsSetting value="0" id="Add" />
|
||||||
<ConfirmationsSetting value="0" id="Remove" />
|
<ConfirmationsSetting value="0" id="Remove" />
|
||||||
</component>
|
</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" />
|
<output url="file://$PROJECT_DIR$/build/classes" />
|
||||||
</component>
|
</component>
|
||||||
<component name="ProjectType">
|
<component name="ProjectType">
|
||||||
|
@ -127,9 +127,8 @@ public class ConversationMessage {
|
|||||||
*
|
*
|
||||||
* @return The content
|
* @return The content
|
||||||
*/
|
*/
|
||||||
@NonNull
|
|
||||||
public String getContent() {
|
public String getContent() {
|
||||||
return content != null ? content : "";
|
return content;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1,14 +1,20 @@
|
|||||||
package org.communiquons.android.comunic.client.data.conversations;
|
package org.communiquons.android.comunic.client.data.conversations;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
import android.os.Build;
|
||||||
import android.support.annotation.NonNull;
|
import android.support.annotation.NonNull;
|
||||||
import android.support.annotation.Nullable;
|
import android.support.annotation.Nullable;
|
||||||
|
import android.util.Log;
|
||||||
|
import android.view.Gravity;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
import android.widget.ArrayAdapter;
|
import android.widget.ArrayAdapter;
|
||||||
|
import android.widget.ImageView;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
|
||||||
|
import org.communiquons.android.comunic.client.R;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -20,14 +26,58 @@ import java.util.ArrayList;
|
|||||||
|
|
||||||
public class ConversationMessageAdapter extends ArrayAdapter<ConversationMessage> {
|
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
|
* Public class constructor
|
||||||
*
|
*
|
||||||
* @param context The context of execution of the application
|
* @param context The context of execution of the application
|
||||||
* @param list The dataset
|
* @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);
|
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
|
@Override
|
||||||
public View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent) {
|
public View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent) {
|
||||||
|
|
||||||
|
//Inflate view if required
|
||||||
if(convertView == null)
|
if(convertView == null)
|
||||||
convertView = LayoutInflater.from(getContext()).
|
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;
|
return convertView;
|
||||||
}
|
}
|
||||||
|
@ -11,6 +11,7 @@ import android.widget.ListView;
|
|||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
|
||||||
import org.communiquons.android.comunic.client.R;
|
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.DatabaseHelper;
|
||||||
import org.communiquons.android.comunic.client.data.conversations.ConversationMessage;
|
import org.communiquons.android.comunic.client.data.conversations.ConversationMessage;
|
||||||
import org.communiquons.android.comunic.client.data.conversations.ConversationMessageAdapter;
|
import org.communiquons.android.comunic.client.data.conversations.ConversationMessageAdapter;
|
||||||
@ -104,7 +105,8 @@ public class ConversationFragment extends Fragment
|
|||||||
//Conversation messages listView
|
//Conversation messages listView
|
||||||
ListView convMessListView = view.findViewById(R.id.fragment_conversation_messageslist);
|
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);
|
convMessListView.setAdapter(convMessAdapter);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -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>
|
@ -8,4 +8,10 @@
|
|||||||
<color name="darker_gray">#aaa</color>
|
<color name="darker_gray">#aaa</color>
|
||||||
<color name="darker_darker_gray">#5b5b5b</color>
|
<color name="darker_darker_gray">#5b5b5b</color>
|
||||||
<color name="dark_blue">#303F9F</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>
|
</resources>
|
||||||
|
Loading…
Reference in New Issue
Block a user