diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml
index 9780610..2a7e9ab 100644
--- a/app/src/main/AndroidManifest.xml
+++ b/app/src/main/AndroidManifest.xml
@@ -14,8 +14,20 @@
android:label="@string/app_name">
+
+
+
+
+
+
+
+
-
+
+
\ No newline at end of file
diff --git a/app/src/main/java/org/literacyapp/chat/MessageListArrayAdapter.java b/app/src/main/java/org/literacyapp/chat/MessageListArrayAdapter.java
index 3dfef55..610dfe6 100644
--- a/app/src/main/java/org/literacyapp/chat/MessageListArrayAdapter.java
+++ b/app/src/main/java/org/literacyapp/chat/MessageListArrayAdapter.java
@@ -1,6 +1,11 @@
package org.literacyapp.chat;
import android.content.Context;
+import android.content.SharedPreferences;
+import android.graphics.Bitmap;
+import android.graphics.BitmapFactory;
+import android.preference.PreferenceManager;
+import android.text.TextUtils;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
@@ -10,7 +15,9 @@
import android.widget.TextView;
import org.literacyapp.chat.model.Message;
+import org.literacyapp.chat.receiver.StudentUpdateReceiver;
+import java.io.File;
import java.util.List;
public class MessageListArrayAdapter extends ArrayAdapter {
@@ -51,6 +58,16 @@ public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder viewHolder = (ViewHolder) listItem.getTag();
viewHolder.textViewListItem.setText(message.getText());
+ SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context);
+ String studentAvatar = sharedPreferences.getString(StudentUpdateReceiver.PREF_STUDENT_AVATAR, null);
+ if (!TextUtils.isEmpty(studentAvatar)) {
+ File file = new File(studentAvatar);
+ if (file.exists()) {
+ Bitmap bitmap = BitmapFactory.decodeFile(file.getAbsolutePath());
+ viewHolder.imageViewAvatar.setImageBitmap(bitmap);
+ }
+ }
+
return listItem;
}
}
diff --git a/app/src/main/java/org/literacyapp/chat/receiver/StudentUpdateReceiver.java b/app/src/main/java/org/literacyapp/chat/receiver/StudentUpdateReceiver.java
new file mode 100644
index 0000000..37cd822
--- /dev/null
+++ b/app/src/main/java/org/literacyapp/chat/receiver/StudentUpdateReceiver.java
@@ -0,0 +1,36 @@
+package org.literacyapp.chat.receiver;
+
+import android.content.BroadcastReceiver;
+import android.content.Context;
+import android.content.Intent;
+import android.content.SharedPreferences;
+import android.preference.PreferenceManager;
+import android.text.TextUtils;
+import android.util.Log;
+
+public class StudentUpdateReceiver extends BroadcastReceiver {
+
+ public static final String PREF_STUDENT_ID = "pref_student_id";
+ public static final String PREF_STUDENT_AVATAR = "pref_student_avatar";
+
+ @Override
+ public void onReceive(Context context, Intent intent) {
+ Log.i(getClass().getName(), "onReceive");
+
+ String studentId = intent.getStringExtra("studentId");
+ Log.i(getClass().getName(), "studentId: " + studentId);
+
+ String studentAvatar = intent.getStringExtra("studentAvatar");
+ Log.i(getClass().getName(), "studentAvatar: " + studentAvatar);
+
+ SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context);
+
+ if (!TextUtils.isEmpty(studentId)) {
+ sharedPreferences.edit().putString(PREF_STUDENT_ID, studentId).commit();
+ }
+
+ if (!TextUtils.isEmpty(studentAvatar)) {
+ sharedPreferences.edit().putString(PREF_STUDENT_AVATAR, studentAvatar).commit();
+ }
+ }
+}