mirror of
https://github.com/moparisthebest/Conversations
synced 2024-11-30 12:42:16 -05:00
basic persistance layer. refactor some parts of the conversation activity
This commit is contained in:
parent
b273390e26
commit
df9dcb1060
@ -17,7 +17,8 @@
|
|||||||
android:theme="@android:style/Theme.Holo.Light" >
|
android:theme="@android:style/Theme.Holo.Light" >
|
||||||
<activity
|
<activity
|
||||||
android:name="de.gultsch.chat.ui.ConversationActivity"
|
android:name="de.gultsch.chat.ui.ConversationActivity"
|
||||||
android:label="Secure Conversations">
|
android:label="Secure Conversations"
|
||||||
|
android:windowSoftInputMode="stateHidden">
|
||||||
<intent-filter>
|
<intent-filter>
|
||||||
<action android:name="android.intent.action.MAIN" />
|
<action android:name="android.intent.action.MAIN" />
|
||||||
|
|
||||||
|
@ -35,36 +35,35 @@ public final class R {
|
|||||||
public static final int section_header=0x7f020007;
|
public static final int section_header=0x7f020007;
|
||||||
}
|
}
|
||||||
public static final class id {
|
public static final class id {
|
||||||
public static final int action_accounts=0x7f0a001c;
|
public static final int action_accounts=0x7f0a001b;
|
||||||
public static final int action_add=0x7f0a0018;
|
public static final int action_add=0x7f0a0017;
|
||||||
public static final int action_archive=0x7f0a001b;
|
public static final int action_archive=0x7f0a001a;
|
||||||
public static final int action_details=0x7f0a001a;
|
public static final int action_details=0x7f0a0019;
|
||||||
public static final int action_security=0x7f0a0019;
|
public static final int action_security=0x7f0a0018;
|
||||||
public static final int action_settings=0x7f0a001d;
|
public static final int action_settings=0x7f0a001c;
|
||||||
public static final int contact_display_name=0x7f0a0009;
|
public static final int contact_display_name=0x7f0a0009;
|
||||||
public static final int contact_divider=0x7f0a000b;
|
public static final int contact_divider=0x7f0a000b;
|
||||||
public static final int contact_jid=0x7f0a000a;
|
public static final int contact_jid=0x7f0a000a;
|
||||||
public static final int contact_photo=0x7f0a0008;
|
public static final int contact_photo=0x7f0a0008;
|
||||||
public static final int conversation_lastmsg=0x7f0a000f;
|
public static final int conversation_image=0x7f0a000c;
|
||||||
public static final int conversation_name=0x7f0a000e;
|
public static final int conversation_lastmsg=0x7f0a000e;
|
||||||
|
public static final int conversation_name=0x7f0a000d;
|
||||||
public static final int create_new_contact=0x7f0a0007;
|
public static final int create_new_contact=0x7f0a0007;
|
||||||
public static final int duration=0x7f0a0010;
|
public static final int duration=0x7f0a000f;
|
||||||
public static final int editText1=0x7f0a0012;
|
public static final int editText1=0x7f0a0011;
|
||||||
public static final int imageButton1=0x7f0a0013;
|
public static final int imageButton1=0x7f0a0012;
|
||||||
public static final int imageView1=0x7f0a000d;
|
|
||||||
public static final int jabber_contacts=0x7f0a0005;
|
public static final int jabber_contacts=0x7f0a0005;
|
||||||
public static final int jabber_contacts_header=0x7f0a0004;
|
public static final int jabber_contacts_header=0x7f0a0004;
|
||||||
public static final int list=0x7f0a0016;
|
public static final int list=0x7f0a0015;
|
||||||
public static final int new_contact_header=0x7f0a0006;
|
public static final int new_contact_header=0x7f0a0006;
|
||||||
public static final int new_conversation_search=0x7f0a0000;
|
public static final int new_conversation_search=0x7f0a0000;
|
||||||
public static final int phone_contacts=0x7f0a0003;
|
public static final int phone_contacts=0x7f0a0003;
|
||||||
public static final int phone_contacts_header=0x7f0a0002;
|
public static final int phone_contacts_header=0x7f0a0002;
|
||||||
public static final int scrollView1=0x7f0a0001;
|
public static final int scrollView1=0x7f0a0001;
|
||||||
public static final int selected_conversation=0x7f0a0017;
|
public static final int selected_conversation=0x7f0a0016;
|
||||||
public static final int slidingpanelayout=0x7f0a0015;
|
public static final int slidingpanelayout=0x7f0a0014;
|
||||||
public static final int textView1=0x7f0a0014;
|
public static final int textView1=0x7f0a0013;
|
||||||
public static final int textsend=0x7f0a0011;
|
public static final int textsend=0x7f0a0010;
|
||||||
public static final int thumbnail=0x7f0a000c;
|
|
||||||
}
|
}
|
||||||
public static final class layout {
|
public static final class layout {
|
||||||
public static final int activity_new_conversation=0x7f030000;
|
public static final int activity_new_conversation=0x7f030000;
|
||||||
@ -84,7 +83,6 @@ public final class R {
|
|||||||
public static final int action_secure=0x7f070006;
|
public static final int action_secure=0x7f070006;
|
||||||
public static final int action_settings=0x7f070001;
|
public static final int action_settings=0x7f070001;
|
||||||
public static final int app_name=0x7f070000;
|
public static final int app_name=0x7f070000;
|
||||||
public static final int hello_world=0x7f070008;
|
|
||||||
public static final int title_activity_new_conversation=0x7f070007;
|
public static final int title_activity_new_conversation=0x7f070007;
|
||||||
}
|
}
|
||||||
public static final class style {
|
public static final class style {
|
||||||
|
@ -2,61 +2,53 @@
|
|||||||
android:layout_width="fill_parent"
|
android:layout_width="fill_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:orientation="horizontal"
|
android:orientation="horizontal"
|
||||||
android:padding="5dip">
|
android:padding="8dp">
|
||||||
|
|
||||||
<!-- ListRow Left sied Thumbnail image -->
|
|
||||||
<LinearLayout android:id="@+id/thumbnail"
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:padding="3dip"
|
|
||||||
android:layout_alignParentLeft="true"
|
|
||||||
android:layout_marginRight="5dip">
|
|
||||||
|
|
||||||
<ImageView
|
<ImageView
|
||||||
android:id="@+id/imageView1"
|
android:id="@+id/conversation_image"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="56dp"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="56dp"
|
||||||
android:src="@drawable/ic_profile" />
|
android:layout_alignParentLeft="true"/>
|
||||||
|
|
||||||
</LinearLayout>
|
<RelativeLayout
|
||||||
|
android:layout_toRightOf="@+id/conversation_image"
|
||||||
|
android:layout_centerVertical="true"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_width="fill_parent"
|
||||||
|
android:paddingLeft="8dp">
|
||||||
|
|
||||||
<!-- Title Of Song-->
|
<TextView
|
||||||
<TextView
|
android:id="@+id/conversation_name"
|
||||||
android:id="@+id/conversation_name"
|
android:layout_width="wrap_content"
|
||||||
android:layout_width="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:text="Mein Contact"
|
||||||
android:layout_alignTop="@+id/thumbnail"
|
android:textColor="#636363"
|
||||||
android:layout_toRightOf="@+id/thumbnail"
|
android:textSize="20sp"
|
||||||
android:text="Rihanna Love the way lie"
|
android:typeface="sans" />
|
||||||
android:textColor="#636363"
|
|
||||||
android:typeface="sans"
|
|
||||||
android:textSize="20dip"/>
|
|
||||||
|
|
||||||
<!-- Artist Name -->
|
<TextView
|
||||||
<TextView
|
android:id="@+id/conversation_lastmsg"
|
||||||
android:id="@+id/conversation_lastmsg"
|
android:layout_width="fill_parent"
|
||||||
android:layout_width="fill_parent"
|
android:layout_height="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_below="@id/conversation_name"
|
||||||
android:layout_below="@id/conversation_name"
|
android:textColor="#636363"
|
||||||
android:textColor="#636363"
|
android:textSize="14sp"
|
||||||
android:textSize="12dip"
|
android:text="This is my last message"
|
||||||
android:layout_marginTop="1dip"
|
android:paddingTop="3dp"/>
|
||||||
android:layout_toRightOf="@+id/thumbnail"
|
|
||||||
android:text="Just gona stand there and ..." />
|
|
||||||
|
|
||||||
<!-- Rightend Duration -->
|
<TextView
|
||||||
<TextView
|
android:id="@+id/duration"
|
||||||
android:id="@+id/duration"
|
android:layout_width="wrap_content"
|
||||||
android:layout_width="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_alignBaseline="@+id/conversation_name"
|
||||||
android:layout_alignParentRight="true"
|
android:layout_alignParentRight="true"
|
||||||
android:layout_alignBottom="@id/conversation_name"
|
android:gravity="right"
|
||||||
android:gravity="right"
|
android:text="2 min"
|
||||||
android:text="5:45"
|
android:textColor="#636363"
|
||||||
android:layout_marginRight="5dip"
|
android:textSize="12sp" />
|
||||||
android:textSize="10dip"
|
|
||||||
android:textColor="#636363"/>
|
|
||||||
|
|
||||||
|
</RelativeLayout>
|
||||||
|
|
||||||
|
|
||||||
</RelativeLayout>
|
</RelativeLayout>
|
@ -5,10 +5,8 @@
|
|||||||
<string name="action_settings">Settings</string>
|
<string name="action_settings">Settings</string>
|
||||||
<string name="action_add">New conversation</string>
|
<string name="action_add">New conversation</string>
|
||||||
<string name="action_accounts">Manage accounts</string>
|
<string name="action_accounts">Manage accounts</string>
|
||||||
<string name="action_archive">Archive</string>
|
<string name="action_archive">Archive conversation</string>
|
||||||
<string name="action_details">Show details</string>
|
<string name="action_details">Show details</string>
|
||||||
<string name="action_secure">Secure conversation</string>
|
<string name="action_secure">Secure conversation</string>
|
||||||
<string name="title_activity_new_conversation">New Conversation</string>
|
<string name="title_activity_new_conversation">New Conversation</string>
|
||||||
<string name="hello_world">Hello world!</string>
|
|
||||||
|
|
||||||
</resources>
|
</resources>
|
||||||
|
@ -1,21 +0,0 @@
|
|||||||
package de.gultsch.chat;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
|
|
||||||
|
|
||||||
public class Conversation {
|
|
||||||
private String name;
|
|
||||||
private ArrayList<Message> msgs = new ArrayList<Message>();
|
|
||||||
|
|
||||||
public Conversation(String name) {
|
|
||||||
this.name = name;
|
|
||||||
}
|
|
||||||
|
|
||||||
public ArrayList<Message> getLastMessages(int count, int offset) {
|
|
||||||
msgs.add(new Message("this is my last message"));
|
|
||||||
return msgs;
|
|
||||||
}
|
|
||||||
public String getName() {
|
|
||||||
return this.name;
|
|
||||||
}
|
|
||||||
}
|
|
@ -3,6 +3,9 @@ package de.gultsch.chat;
|
|||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
|
import de.gultsch.chat.entities.Conversation;
|
||||||
|
import de.gultsch.chat.entities.Message;
|
||||||
|
|
||||||
|
|
||||||
import android.database.AbstractCursor;
|
import android.database.AbstractCursor;
|
||||||
|
|
||||||
|
@ -4,6 +4,8 @@ import java.util.ArrayList;
|
|||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
|
|
||||||
|
import de.gultsch.chat.entities.Conversation;
|
||||||
|
|
||||||
public class ConversationList extends ArrayList<Conversation> {
|
public class ConversationList extends ArrayList<Conversation> {
|
||||||
|
|
||||||
private static final long serialVersionUID = 3661496589984289968L;
|
private static final long serialVersionUID = 3661496589984289968L;
|
||||||
@ -24,21 +26,6 @@ public class ConversationList extends ArrayList<Conversation> {
|
|||||||
this.selectedConversationPosition = selectedConversation;
|
this.selectedConversationPosition = selectedConversation;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void sort() {
|
|
||||||
Conversation selectedConversation = this.get(selectedConversationPosition);
|
|
||||||
//sort this
|
|
||||||
Collections.sort(this, new Comparator<Conversation>() {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int compare(Conversation lhs, Conversation rhs) {
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
this.selectedConversationPosition = this.indexOf(selectedConversation);
|
|
||||||
}
|
|
||||||
|
|
||||||
public synchronized int addAndReturnPosition(Conversation conversation) {
|
public synchronized int addAndReturnPosition(Conversation conversation) {
|
||||||
this.add(conversation);
|
this.add(conversation);
|
||||||
return size() - 1;
|
return size() - 1;
|
||||||
|
11
src/de/gultsch/chat/entities/Account.java
Normal file
11
src/de/gultsch/chat/entities/Account.java
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
package de.gultsch.chat.entities;
|
||||||
|
|
||||||
|
public class Account {
|
||||||
|
|
||||||
|
private String uuid;
|
||||||
|
|
||||||
|
public String getUuid() {
|
||||||
|
return this.uuid;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -1,4 +1,4 @@
|
|||||||
package de.gultsch.chat;
|
package de.gultsch.chat.entities;
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
|
|
99
src/de/gultsch/chat/entities/Conversation.java
Normal file
99
src/de/gultsch/chat/entities/Conversation.java
Normal file
@ -0,0 +1,99 @@
|
|||||||
|
package de.gultsch.chat.entities;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
import android.content.ContentValues;
|
||||||
|
import android.database.Cursor;
|
||||||
|
import android.net.Uri;
|
||||||
|
|
||||||
|
public class Conversation implements Serializable {
|
||||||
|
|
||||||
|
private static final long serialVersionUID = -6727528868973996739L;
|
||||||
|
public static final int STATUS_AVAILABLE = 0;
|
||||||
|
public static final int STATUS_ARCHIVED = 1;
|
||||||
|
public static final int STATUS_DELETED = 2;
|
||||||
|
private String uuid;
|
||||||
|
private String name;
|
||||||
|
private String profilePhotoUri;
|
||||||
|
private String accountUuid;
|
||||||
|
private String contactJid;
|
||||||
|
private int status;
|
||||||
|
|
||||||
|
// legacy. to be removed
|
||||||
|
private ArrayList<Message> msgs = new ArrayList<Message>();
|
||||||
|
|
||||||
|
public Conversation(String name, Uri profilePhoto, Account account,
|
||||||
|
String contactJid) {
|
||||||
|
this(UUID.randomUUID().toString(), name, profilePhoto.toString(),
|
||||||
|
account.getUuid(), contactJid, STATUS_AVAILABLE);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Conversation(String uuid, String name, String profilePhoto,
|
||||||
|
String accountUuid, String contactJid, int status) {
|
||||||
|
this.uuid = uuid;
|
||||||
|
this.name = name;
|
||||||
|
this.profilePhotoUri = profilePhoto;
|
||||||
|
this.accountUuid = accountUuid;
|
||||||
|
this.contactJid = contactJid;
|
||||||
|
this.status = status;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ArrayList<Message> getLastMessages(int count, int offset) {
|
||||||
|
msgs.add(new Message("this is my last message"));
|
||||||
|
return msgs;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getName() {
|
||||||
|
return this.name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getUuid() {
|
||||||
|
return this.uuid;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getProfilePhotoString() {
|
||||||
|
return this.profilePhotoUri;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getAccountUuid() {
|
||||||
|
return this.accountUuid;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getContactJid() {
|
||||||
|
return this.contactJid;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Uri getProfilePhotoUri() {
|
||||||
|
if (this.profilePhotoUri != null) {
|
||||||
|
return Uri.parse(profilePhotoUri);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getStatus() {
|
||||||
|
return this.status;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ContentValues getContentValues() {
|
||||||
|
ContentValues values = new ContentValues();
|
||||||
|
values.put("uuid", this.uuid);
|
||||||
|
values.put("name", this.name);
|
||||||
|
values.put("profilePhotoUri", this.profilePhotoUri);
|
||||||
|
values.put("accountUuid", this.accountUuid);
|
||||||
|
values.put("contactJid", this.contactJid);
|
||||||
|
values.put("status", this.status);
|
||||||
|
return values;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Conversation fromCursor(Cursor cursor) {
|
||||||
|
return new Conversation(
|
||||||
|
cursor.getString(cursor.getColumnIndex("uuid")),
|
||||||
|
cursor.getString(cursor.getColumnIndex("name")),
|
||||||
|
cursor.getString(cursor.getColumnIndex("profilePhotoUri")),
|
||||||
|
cursor.getString(cursor.getColumnIndex("accountUuid")),
|
||||||
|
cursor.getString(cursor.getColumnIndex("contactJid")),
|
||||||
|
cursor.getInt(cursor.getColumnIndex("status")));
|
||||||
|
}
|
||||||
|
}
|
@ -1,4 +1,4 @@
|
|||||||
package de.gultsch.chat;
|
package de.gultsch.chat.entities;
|
||||||
|
|
||||||
public class Message {
|
public class Message {
|
||||||
|
|
68
src/de/gultsch/chat/persistance/DatabaseBackend.java
Normal file
68
src/de/gultsch/chat/persistance/DatabaseBackend.java
Normal file
@ -0,0 +1,68 @@
|
|||||||
|
package de.gultsch.chat.persistance;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import de.gultsch.chat.entities.Conversation;
|
||||||
|
import android.content.Context;
|
||||||
|
import android.database.Cursor;
|
||||||
|
import android.database.sqlite.SQLiteDatabase;
|
||||||
|
import android.database.sqlite.SQLiteOpenHelper;
|
||||||
|
import android.util.Log;
|
||||||
|
|
||||||
|
public class DatabaseBackend extends SQLiteOpenHelper {
|
||||||
|
|
||||||
|
private static DatabaseBackend instance = null;
|
||||||
|
|
||||||
|
private static final String DATABASE_NAME = "history";
|
||||||
|
private static final int DATABASE_VERSION = 1;
|
||||||
|
|
||||||
|
public DatabaseBackend(Context context) {
|
||||||
|
super(context, DATABASE_NAME, null, DATABASE_VERSION);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onCreate(SQLiteDatabase db) {
|
||||||
|
db.execSQL("create table conversations (uuid TEXT, name TEXT, profilePhotoUri TEXT, accountUuid TEXT, contactJid TEXT)");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onUpgrade(SQLiteDatabase db, int arg1, int arg2) {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public static synchronized DatabaseBackend getInstance(Context context) {
|
||||||
|
if (instance == null) {
|
||||||
|
instance = new DatabaseBackend(context.getApplicationContext());
|
||||||
|
}
|
||||||
|
return instance;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addConversation(Conversation conversation) {
|
||||||
|
SQLiteDatabase db = this.getWritableDatabase();
|
||||||
|
db.insert("conversations", null, conversation.getContentValues());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public int getConversationCount() {
|
||||||
|
SQLiteDatabase db = this.getReadableDatabase();
|
||||||
|
Cursor cursor = db.rawQuery("select count(uuid) as count from conversations",null);
|
||||||
|
cursor.moveToFirst();
|
||||||
|
return cursor.getInt(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<Conversation> getConversations(int status) {
|
||||||
|
List<Conversation> list = new ArrayList<Conversation>();
|
||||||
|
SQLiteDatabase db = this.getReadableDatabase();
|
||||||
|
String[] selectionArgs = {""+status};
|
||||||
|
Cursor cursor = db.rawQuery("select * from conversations where status = ?", selectionArgs);
|
||||||
|
Log.d("gultsch","getConversations has found "+cursor.getCount()+" rows");
|
||||||
|
while(cursor.moveToNext()) {
|
||||||
|
Log.d("gultsch","converting row #"+cursor.getPosition());
|
||||||
|
list.add(Conversation.fromCursor(cursor));
|
||||||
|
}
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -1,15 +1,20 @@
|
|||||||
package de.gultsch.chat.ui;
|
package de.gultsch.chat.ui;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
import de.gultsch.chat.Contact;
|
|
||||||
import de.gultsch.chat.Conversation;
|
|
||||||
import de.gultsch.chat.ConversationCursor;
|
import de.gultsch.chat.ConversationCursor;
|
||||||
import de.gultsch.chat.ConversationList;
|
import de.gultsch.chat.ConversationList;
|
||||||
import de.gultsch.chat.R;
|
import de.gultsch.chat.R;
|
||||||
import de.gultsch.chat.R.id;
|
import de.gultsch.chat.R.id;
|
||||||
|
import de.gultsch.chat.entities.Account;
|
||||||
|
import de.gultsch.chat.entities.Contact;
|
||||||
|
import de.gultsch.chat.entities.Conversation;
|
||||||
|
import de.gultsch.chat.persistance.DatabaseBackend;
|
||||||
|
import android.net.Uri;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
|
import android.app.FragmentManager;
|
||||||
import android.app.FragmentTransaction;
|
import android.app.FragmentTransaction;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
@ -17,14 +22,18 @@ import android.support.v4.widget.SlidingPaneLayout;
|
|||||||
import android.support.v4.widget.SlidingPaneLayout.PanelSlideListener;
|
import android.support.v4.widget.SlidingPaneLayout.PanelSlideListener;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.view.KeyEvent;
|
import android.view.KeyEvent;
|
||||||
|
import android.view.LayoutInflater;
|
||||||
import android.view.Menu;
|
import android.view.Menu;
|
||||||
import android.view.MenuItem;
|
import android.view.MenuItem;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
|
import android.view.ViewGroup;
|
||||||
import android.view.inputmethod.InputMethodManager;
|
import android.view.inputmethod.InputMethodManager;
|
||||||
import android.widget.AdapterView;
|
import android.widget.AdapterView;
|
||||||
import android.widget.AdapterView.OnItemClickListener;
|
import android.widget.AdapterView.OnItemClickListener;
|
||||||
|
import android.widget.ArrayAdapter;
|
||||||
import android.widget.ListView;
|
import android.widget.ListView;
|
||||||
import android.widget.SimpleCursorAdapter;
|
import android.widget.TextView;
|
||||||
|
import android.widget.ImageView;
|
||||||
|
|
||||||
public class ConversationActivity extends Activity {
|
public class ConversationActivity extends Activity {
|
||||||
|
|
||||||
@ -34,34 +43,51 @@ public class ConversationActivity extends Activity {
|
|||||||
protected SlidingPaneLayout spl;
|
protected SlidingPaneLayout spl;
|
||||||
|
|
||||||
protected HashMap<Conversation, ConversationFragment> conversationFragments = new HashMap<Conversation, ConversationFragment>();
|
protected HashMap<Conversation, ConversationFragment> conversationFragments = new HashMap<Conversation, ConversationFragment>();
|
||||||
|
private DatabaseBackend dbb;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
|
|
||||||
|
dbb = DatabaseBackend.getInstance(this);
|
||||||
|
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
|
|
||||||
|
final List<Conversation> conversationList = dbb.getConversations(Conversation.STATUS_AVAILABLE);
|
||||||
|
|
||||||
|
if (getIntent().getAction().equals(Intent.ACTION_MAIN)) {
|
||||||
|
if (conversationList.size() < 0) {
|
||||||
|
Log.d("gultsch",
|
||||||
|
"no conversations detected. redirect to new conversation activity");
|
||||||
|
startActivity(new Intent(this, NewConversationActivity.class));
|
||||||
|
finish();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
setContentView(R.layout.fragment_conversations_overview);
|
setContentView(R.layout.fragment_conversations_overview);
|
||||||
|
|
||||||
final ConversationList conversationList = new ConversationList();
|
|
||||||
|
|
||||||
String[] fromColumns = { ConversationCursor.NAME,
|
|
||||||
ConversationCursor.LAST_MSG };
|
|
||||||
int[] toViews = { R.id.conversation_name, R.id.conversation_lastmsg };
|
|
||||||
|
|
||||||
final SimpleCursorAdapter adapter = new SimpleCursorAdapter(this,
|
|
||||||
R.layout.conversation_list_row, conversationList.getCursor(),
|
|
||||||
fromColumns, toViews, 0);
|
|
||||||
final ListView listView = (ListView) findViewById(R.id.list);
|
final ListView listView = (ListView) findViewById(R.id.list);
|
||||||
listView.setAdapter(adapter);
|
|
||||||
|
listView.setAdapter(new ArrayAdapter<Conversation>(this, R.layout.conversation_list_row, conversationList) {
|
||||||
|
@Override
|
||||||
|
public View getView (int position, View view, ViewGroup parent) {
|
||||||
|
if (view == null) {
|
||||||
|
LayoutInflater inflater = (LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
||||||
|
view = (View) inflater.inflate(R.layout.conversation_list_row,null);
|
||||||
|
((TextView) view.findViewById(R.id.conversation_name)).setText(getItem(position).getName());
|
||||||
|
((ImageView) view.findViewById(R.id.conversation_image)).setImageURI(getItem(position).getProfilePhotoUri());
|
||||||
|
}
|
||||||
|
return view;
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
listView.setOnItemClickListener(new OnItemClickListener() {
|
listView.setOnItemClickListener(new OnItemClickListener() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onItemClick(AdapterView<?> arg0, View clickedView,
|
public void onItemClick(AdapterView<?> arg0, View clickedView,
|
||||||
int position, long arg3) {
|
int position, long arg3) {
|
||||||
conversationList.setSelectedConversationPosition(position);
|
swapConversationFragment(conversationList.get(position));
|
||||||
swapConversationFragment(conversationList);
|
getActionBar().setTitle(conversationList.get(position).getName());
|
||||||
getActionBar().setTitle(
|
|
||||||
conversationList.getSelectedConversation().getName());
|
|
||||||
spl.closePane();
|
spl.closePane();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -95,9 +121,8 @@ public class ConversationActivity extends Activity {
|
|||||||
public void onPanelClosed(View arg0) {
|
public void onPanelClosed(View arg0) {
|
||||||
if (conversationList.size() > 0) {
|
if (conversationList.size() > 0) {
|
||||||
getActionBar().setDisplayHomeAsUpEnabled(true);
|
getActionBar().setDisplayHomeAsUpEnabled(true);
|
||||||
getActionBar().setTitle(
|
ConversationFragment convFrag = (ConversationFragment) getFragmentManager().findFragmentById(R.id.selected_conversation);
|
||||||
conversationList.getSelectedConversation()
|
getActionBar().setTitle(convFrag.getConversation().getName());
|
||||||
.getName());
|
|
||||||
invalidateOptionsMenu();
|
invalidateOptionsMenu();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -116,25 +141,26 @@ public class ConversationActivity extends Activity {
|
|||||||
ConversationActivity.CONVERSATION_CONTACT);
|
ConversationActivity.CONVERSATION_CONTACT);
|
||||||
Log.d("gultsch",
|
Log.d("gultsch",
|
||||||
"start conversation with " + contact.getDisplayName());
|
"start conversation with " + contact.getDisplayName());
|
||||||
int pos = conversationList
|
|
||||||
.addAndReturnPosition(new Conversation(contact
|
// start new conversation
|
||||||
.getDisplayName()));
|
Conversation conversation = new Conversation(
|
||||||
conversationList.setSelectedConversationPosition(pos);
|
contact.getDisplayName(), contact.getProfilePhoto(),
|
||||||
swapConversationFragment(conversationList);
|
new Account(), contact.getJid());
|
||||||
|
|
||||||
|
//@TODO don't write to database here; always go through service
|
||||||
|
dbb.addConversation(conversation);
|
||||||
|
conversationList.add(0, conversation);
|
||||||
|
swapConversationFragment(conversationList.get(0));
|
||||||
spl.closePane();
|
spl.closePane();
|
||||||
|
|
||||||
// why do i even need this
|
// why do i even need this
|
||||||
getActionBar().setDisplayHomeAsUpEnabled(true);
|
getActionBar().setDisplayHomeAsUpEnabled(true);
|
||||||
getActionBar().setTitle(
|
getActionBar().setTitle(conversationList.get(0).getName());
|
||||||
conversationList.getSelectedConversation().getName());
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// normal startup
|
// normal startup
|
||||||
if (conversationList.size() >= 1) {
|
if (conversationList.size() >= 1) {
|
||||||
conversationList.setSelectedConversationPosition(0);
|
swapConversationFragment(conversationList.get(0));
|
||||||
swapConversationFragment(conversationList);
|
|
||||||
} else {
|
|
||||||
startActivity(new Intent(this, NewConversationActivity.class));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -168,24 +194,22 @@ public class ConversationActivity extends Activity {
|
|||||||
break;
|
break;
|
||||||
case R.id.action_add:
|
case R.id.action_add:
|
||||||
startActivity(new Intent(this, NewConversationActivity.class));
|
startActivity(new Intent(this, NewConversationActivity.class));
|
||||||
|
case R.id.action_archive:
|
||||||
|
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
return super.onOptionsItemSelected(item);
|
return super.onOptionsItemSelected(item);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void swapConversationFragment(
|
protected void swapConversationFragment(Conversation conv) {
|
||||||
final ConversationList conversationList) {
|
|
||||||
ConversationFragment selectedFragment;
|
ConversationFragment selectedFragment;
|
||||||
if (conversationFragments.containsKey(conversationList
|
if (conversationFragments.containsKey(conv)) {
|
||||||
.getSelectedConversation())) {
|
selectedFragment = conversationFragments.get(conv);
|
||||||
selectedFragment = conversationFragments.get(conversationList
|
|
||||||
.getSelectedConversation());
|
|
||||||
} else {
|
} else {
|
||||||
selectedFragment = new ConversationFragment();
|
selectedFragment = new ConversationFragment();
|
||||||
conversationFragments.put(
|
selectedFragment.setConversation(conv);
|
||||||
conversationList.getSelectedConversation(),
|
conversationFragments.put(conv,selectedFragment);
|
||||||
selectedFragment);
|
|
||||||
}
|
}
|
||||||
FragmentTransaction transaction = getFragmentManager()
|
FragmentTransaction transaction = getFragmentManager()
|
||||||
.beginTransaction();
|
.beginTransaction();
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package de.gultsch.chat.ui;
|
package de.gultsch.chat.ui;
|
||||||
|
|
||||||
import de.gultsch.chat.R;
|
import de.gultsch.chat.R;
|
||||||
|
import de.gultsch.chat.entities.Conversation;
|
||||||
import android.app.Fragment;
|
import android.app.Fragment;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
@ -9,8 +10,18 @@ import android.view.ViewGroup;
|
|||||||
|
|
||||||
public class ConversationFragment extends Fragment {
|
public class ConversationFragment extends Fragment {
|
||||||
|
|
||||||
|
Conversation conversation;
|
||||||
|
|
||||||
|
public void setConversation(Conversation conv) {
|
||||||
|
this.conversation = conv;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||||
return inflater.inflate(R.layout.fragment_conversation, container, false);
|
return inflater.inflate(R.layout.fragment_conversation, container, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Conversation getConversation() {
|
||||||
|
return conversation;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -5,8 +5,9 @@ import java.util.Map.Entry;
|
|||||||
import java.util.regex.Matcher;
|
import java.util.regex.Matcher;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
import de.gultsch.chat.Contact;
|
|
||||||
import de.gultsch.chat.R;
|
import de.gultsch.chat.R;
|
||||||
|
import de.gultsch.chat.entities.Contact;
|
||||||
|
import de.gultsch.chat.persistance.DatabaseBackend;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.provider.ContactsContract;
|
import android.provider.ContactsContract;
|
||||||
import android.text.Editable;
|
import android.text.Editable;
|
||||||
@ -48,15 +49,14 @@ public class NewConversationActivity extends Activity {
|
|||||||
+ "\") AND (" + ContactsContract.CommonDataKinds.Im.PROTOCOL
|
+ "\") AND (" + ContactsContract.CommonDataKinds.Im.PROTOCOL
|
||||||
+ "=\"" + ContactsContract.CommonDataKinds.Im.PROTOCOL_JABBER
|
+ "=\"" + ContactsContract.CommonDataKinds.Im.PROTOCOL_JABBER
|
||||||
+ "\")";
|
+ "\")";
|
||||||
|
protected static final String DEFAULT_PROFILE_PHOTO = "android.resource://de.gultsch.chat/" + R.drawable.ic_profile;
|
||||||
|
|
||||||
protected View getViewForContact(Contact contact) {
|
protected View getViewForContact(Contact contact) {
|
||||||
LayoutInflater inflater = (LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
LayoutInflater inflater = (LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
||||||
View view = (View) inflater.inflate(R.layout.contact,null);
|
View view = (View) inflater.inflate(R.layout.contact,null);
|
||||||
((TextView) view.findViewById(R.id.contact_display_name)).setText(contact.getDisplayName());
|
((TextView) view.findViewById(R.id.contact_display_name)).setText(contact.getDisplayName());
|
||||||
((TextView) view.findViewById(R.id.contact_jid)).setText(contact.getJid());
|
((TextView) view.findViewById(R.id.contact_jid)).setText(contact.getJid());
|
||||||
if (contact.getProfilePhoto() != null) {
|
|
||||||
((ImageView) view.findViewById(R.id.contact_photo)).setImageURI(contact.getProfilePhoto());
|
((ImageView) view.findViewById(R.id.contact_photo)).setImageURI(contact.getProfilePhoto());
|
||||||
}
|
|
||||||
view.setOnClickListener(new OnClickListener() {
|
view.setOnClickListener(new OnClickListener() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -93,6 +93,12 @@ public class NewConversationActivity extends Activity {
|
|||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
|
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
|
|
||||||
|
if (DatabaseBackend.getInstance(this).getConversationCount() < 1) {
|
||||||
|
getActionBar().setDisplayHomeAsUpEnabled(false);
|
||||||
|
getActionBar().setHomeButtonEnabled(false);
|
||||||
|
}
|
||||||
|
|
||||||
setContentView(R.layout.activity_new_conversation);
|
setContentView(R.layout.activity_new_conversation);
|
||||||
CursorLoader mCursorLoader = new CursorLoader(this,
|
CursorLoader mCursorLoader = new CursorLoader(this,
|
||||||
ContactsContract.Data.CONTENT_URI, PROJECTION, SELECTION, null,
|
ContactsContract.Data.CONTENT_URI, PROJECTION, SELECTION, null,
|
||||||
@ -102,13 +108,17 @@ public class NewConversationActivity extends Activity {
|
|||||||
@Override
|
@Override
|
||||||
public void onLoadComplete(Loader<Cursor> arg0, Cursor cursor) {
|
public void onLoadComplete(Loader<Cursor> arg0, Cursor cursor) {
|
||||||
while (cursor.moveToNext()) {
|
while (cursor.moveToNext()) {
|
||||||
|
String profilePhoto = cursor.getString(cursor.getColumnIndex(ContactsContract.Data.PHOTO_THUMBNAIL_URI));
|
||||||
|
if (profilePhoto == null) {
|
||||||
|
profilePhoto = DEFAULT_PROFILE_PHOTO;
|
||||||
|
}
|
||||||
Contact contact = new Contact(
|
Contact contact = new Contact(
|
||||||
cursor.getString(cursor
|
cursor.getString(cursor
|
||||||
.getColumnIndex(ContactsContract.Data.DISPLAY_NAME)),
|
.getColumnIndex(ContactsContract.Data.DISPLAY_NAME)),
|
||||||
cursor.getString(cursor
|
cursor.getString(cursor
|
||||||
.getColumnIndex(ContactsContract.CommonDataKinds.Im.DATA)),
|
.getColumnIndex(ContactsContract.CommonDataKinds.Im.DATA)),
|
||||||
cursor.getString(cursor
|
profilePhoto
|
||||||
.getColumnIndex(ContactsContract.Data.PHOTO_THUMBNAIL_URI)));
|
);
|
||||||
View contactView = getViewForContact(contact);
|
View contactView = getViewForContact(contact);
|
||||||
availablePhoneContacts.put(contact, getViewForContact(contact));
|
availablePhoneContacts.put(contact, getViewForContact(contact));
|
||||||
((LinearLayout) findViewById(R.id.phone_contacts)).addView(contactView);
|
((LinearLayout) findViewById(R.id.phone_contacts)).addView(contactView);
|
||||||
@ -166,7 +176,7 @@ public class NewConversationActivity extends Activity {
|
|||||||
if (matcher.find()) {
|
if (matcher.find()) {
|
||||||
createNewContact.removeAllViews();
|
createNewContact.removeAllViews();
|
||||||
String name = search.split("@")[0];
|
String name = search.split("@")[0];
|
||||||
newContact = new Contact(name,search,null);
|
newContact = new Contact(name,search,DEFAULT_PROFILE_PHOTO);
|
||||||
newContactView = getViewForContact(newContact);
|
newContactView = getViewForContact(newContact);
|
||||||
newContactView.findViewById(R.id.contact_divider).setVisibility(View.GONE);
|
newContactView.findViewById(R.id.contact_divider).setVisibility(View.GONE);
|
||||||
createNewContact.addView(newContactView);
|
createNewContact.addView(newContactView);
|
||||||
|
Loading…
Reference in New Issue
Block a user