mirror of
https://github.com/pierre42100/ComunicAndroid
synced 2024-12-27 22:18:58 +00:00
Conversations name displayed in the "Conversation" tab.
This commit is contained in:
parent
b8ca813d09
commit
c92587cf26
@ -0,0 +1,70 @@
|
||||
package org.communiquons.android.comunic.client.data.conversations;
|
||||
|
||||
import android.content.Context;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.ArrayAdapter;
|
||||
import android.widget.TextView;
|
||||
|
||||
import org.communiquons.android.comunic.client.R;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.zip.Inflater;
|
||||
|
||||
import static android.R.id.list;
|
||||
|
||||
/**
|
||||
* Conversations adapter
|
||||
*
|
||||
* Handles the rendering of the conversations in a {@link android.widget.ListView}
|
||||
*
|
||||
* @author Pierre HUBERT
|
||||
* Created by pierre on 12/10/17.
|
||||
*/
|
||||
|
||||
public class ConversationsListAdapter extends ArrayAdapter<ConversationsInfo> {
|
||||
|
||||
/**
|
||||
* Class constructor
|
||||
*
|
||||
* @param context The context of the application
|
||||
* @param list The list of conversations to display
|
||||
*/
|
||||
public ConversationsListAdapter(Context context, ArrayList<ConversationsInfo> list){
|
||||
super(context, 0, list);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Handle the rendering of the views
|
||||
*
|
||||
* @param position The position of the view to inflate in the list
|
||||
* @param convertView The view to convert / null if it is a new view
|
||||
* @param parent The parent
|
||||
* @return The converted view
|
||||
*/
|
||||
@NonNull
|
||||
@Override
|
||||
public View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent) {
|
||||
|
||||
//Check if it is the first time the view is used
|
||||
if(convertView == null){
|
||||
convertView = LayoutInflater.from(getContext())
|
||||
.inflate(R.layout.fragment_conversationslist_item, parent, false);
|
||||
}
|
||||
|
||||
//Get information about the conversation
|
||||
ConversationsInfo infos = getItem(position);
|
||||
|
||||
//Set the name of the conversation
|
||||
TextView conversationName = convertView
|
||||
.findViewById(R.id.fragment_conversationslist_item_name);
|
||||
conversationName.setText(infos.getDisplayName());
|
||||
|
||||
return convertView;
|
||||
|
||||
}
|
||||
}
|
@ -9,6 +9,7 @@ import android.util.Log;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.ListView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import org.communiquons.android.comunic.client.R;
|
||||
@ -16,6 +17,7 @@ import org.communiquons.android.comunic.client.data.DatabaseHelper;
|
||||
import org.communiquons.android.comunic.client.data.UsersInfo.GetUsersHelper;
|
||||
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 java.util.ArrayList;
|
||||
@ -51,6 +53,16 @@ public class ConversationsListFragment extends Fragment {
|
||||
*/
|
||||
private ConversationsListHelper conversationsListHelper;
|
||||
|
||||
/**
|
||||
* Conversations ListView
|
||||
*/
|
||||
private ListView conversationsListView;
|
||||
|
||||
/**
|
||||
* Conversation list adapter
|
||||
*/
|
||||
private ConversationsListAdapter conversationsListAdapter;
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, Bundle savedInstanceState) {
|
||||
@ -70,6 +82,9 @@ public class ConversationsListFragment extends Fragment {
|
||||
//Create the conversation list helper
|
||||
conversationsListHelper = new ConversationsListHelper(getActivity());
|
||||
|
||||
//Get the conversation target list view
|
||||
conversationsListView = view.findViewById(R.id.fragment_conversationslist_list);
|
||||
|
||||
//Get the list of conversations
|
||||
new AsyncTask<Void, Void, ArrayList<ConversationsInfo>>(){
|
||||
@Override
|
||||
@ -188,8 +203,13 @@ public class ConversationsListFragment extends Fragment {
|
||||
return;
|
||||
}
|
||||
|
||||
for(ConversationsInfo info : list){
|
||||
Log.v(TAG, "Conversation " + info.getID() + " : " + info.getDisplayName());
|
||||
}
|
||||
//Save the list
|
||||
convList = list;
|
||||
|
||||
//Create the adapter
|
||||
conversationsListAdapter = new ConversationsListAdapter(getActivity(), convList);
|
||||
|
||||
//Attach it to the view
|
||||
conversationsListView.setAdapter(conversationsListAdapter);
|
||||
}
|
||||
}
|
||||
|
14
app/src/main/res/layout/fragment_conversationslist_item.xml
Normal file
14
app/src/main/res/layout/fragment_conversationslist_item.xml
Normal file
@ -0,0 +1,14 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:orientation="vertical">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/fragment_conversationslist_item_name"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
tools:text="Conversation name"/>
|
||||
|
||||
</LinearLayout>
|
Loading…
Reference in New Issue
Block a user