aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorsteckbrief <steckbrief@chefmail.de>2015-01-20 22:42:53 +0100
committersteckbrief <steckbrief@chefmail.de>2015-01-20 22:42:53 +0100
commit46bbf1ce5f5d6adbf21674c0b6f38243cb8d9fc7 (patch)
treea9629270cb551f0a1e0d764ef3b31295fc2223b1 /src
parente8ca2a1ae3259c66991f69d62c470ca611ee4659 (diff)
- Avoiding accessing shared preferences to know if emoticons should be parsed for every single message
- Adding support to show online status in Conversations overview (configurable via the setting "send_button_status")
Diffstat (limited to '')
-rw-r--r--src/main/java/de/tzur/conversations/Settings.java55
-rw-r--r--src/main/java/eu/siacs/conversations/Config.java1
-rw-r--r--src/main/java/eu/siacs/conversations/ui/SettingsActivity.java33
-rw-r--r--src/main/java/eu/siacs/conversations/ui/XmppActivity.java4
-rw-r--r--src/main/java/eu/siacs/conversations/ui/adapter/ConversationAdapter.java28
-rw-r--r--src/main/java/eu/siacs/conversations/ui/adapter/MessageAdapter.java6
-rw-r--r--src/main/res/layout/conversation_list_row.xml12
7 files changed, 116 insertions, 23 deletions
diff --git a/src/main/java/de/tzur/conversations/Settings.java b/src/main/java/de/tzur/conversations/Settings.java
new file mode 100644
index 00000000..25079ea1
--- /dev/null
+++ b/src/main/java/de/tzur/conversations/Settings.java
@@ -0,0 +1,55 @@
+package de.tzur.conversations;
+
+import android.content.SharedPreferences;
+import android.util.Log;
+
+/**
+ * This class is used to provide access to settings which have to be accessed frequently.
+ * Every setting in this class has to be updated using @see SettingsActivity#onSharedPreferenceChanged.
+ */
+public final class Settings {
+
+ /**
+ * Initializes the settings provided via this static class.
+ * @param preferences the shared preferences of the app.
+ */
+ public static void initSettingsClassWithPreferences(SharedPreferences preferences) {
+ Log.d("SETTING", "Initializing settings");
+ String[] preferenceNames = { "parse_emoticons", "send_button_status" };
+ for (String name : preferenceNames) {
+ Settings.synchronizeSettingsClassWithPreferences(preferences, name);
+ }
+ }
+
+ /**
+ * Synchronizes the setting value in this class on settings update in SettingsActivity.
+ * @param preferences the shared preferences of the app.
+ * @param name the name of the setting to synchronize.
+ */
+ public static void synchronizeSettingsClassWithPreferences(SharedPreferences preferences, String name) {
+ Log.d("SETTING", "Synchronizing settings");
+ switch (name) {
+ case "parse_emoticons":
+ Settings.PARSE_EMOTICONS = preferences.getBoolean(name, Settings.PARSE_EMOTICONS);
+ break;
+ case "send_button_status":
+ Settings.SHOW_ONLINE_STATUS = preferences.getBoolean(name, Settings.SHOW_ONLINE_STATUS);
+ break;
+ }
+ }
+ /**
+ * Boolean if emoticons should be parsed to emoticons or not.
+ */
+ public static boolean PARSE_EMOTICONS = false;
+ /**
+ * Boolean if online status should be shown or not.
+ */
+ public static boolean SHOW_ONLINE_STATUS = false;
+
+ /**
+ * This is a utility class - private constructor avoids any instantiation.
+ */
+ private Settings() {
+ // Private constructor to avoid instantiation
+ }
+}
diff --git a/src/main/java/eu/siacs/conversations/Config.java b/src/main/java/eu/siacs/conversations/Config.java
index ad874660..f403701c 100644
--- a/src/main/java/eu/siacs/conversations/Config.java
+++ b/src/main/java/eu/siacs/conversations/Config.java
@@ -18,7 +18,6 @@ public final class Config {
public static final int MESSAGE_MERGE_WINDOW = 20;
- public static final boolean PARSE_EMOTICONS = false;
public static final boolean UTF8_EMOTICONS = false;
public static final int PAGE_SIZE = 50;
diff --git a/src/main/java/eu/siacs/conversations/ui/SettingsActivity.java b/src/main/java/eu/siacs/conversations/ui/SettingsActivity.java
index c6e7ab33..352652de 100644
--- a/src/main/java/eu/siacs/conversations/ui/SettingsActivity.java
+++ b/src/main/java/eu/siacs/conversations/ui/SettingsActivity.java
@@ -4,6 +4,7 @@ import java.util.ArrayList;
import java.util.Arrays;
import java.util.Locale;
+import de.tzur.conversations.Settings;
import eu.siacs.conversations.entities.Account;
import android.content.SharedPreferences;
@@ -58,20 +59,24 @@ public class SettingsActivity extends XmppActivity implements
@Override
public void onSharedPreferenceChanged(SharedPreferences preferences,
String name) {
- if (name.equals("resource")) {
- String resource = preferences.getString("resource", "mobile")
- .toLowerCase(Locale.US);
- if (xmppConnectionServiceBound) {
- for (Account account : xmppConnectionService.getAccounts()) {
- account.setResource(resource);
- if (!account.isOptionSet(Account.OPTION_DISABLED)) {
- xmppConnectionService.reconnectAccount(account, false);
- }
- }
- }
- } else if (name.equals("keep_foreground_service")) {
- xmppConnectionService.toggleForegroundService();
- }
+ switch (name) {
+ case "resource":
+ String resource = preferences.getString("resource", "mobile")
+ .toLowerCase(Locale.US);
+ if (xmppConnectionServiceBound) {
+ for (Account account : xmppConnectionService.getAccounts()) {
+ account.setResource(resource);
+ if (!account.isOptionSet(Account.OPTION_DISABLED)) {
+ xmppConnectionService.reconnectAccount(account, false);
+ }
+ }
+ }
+ break;
+ case "keep_foreground_service":
+ xmppConnectionService.toggleForegroundService();
+ break;
+ }
+ Settings.synchronizeSettingsClassWithPreferences(getPreferences(), name);
}
}
diff --git a/src/main/java/eu/siacs/conversations/ui/XmppActivity.java b/src/main/java/eu/siacs/conversations/ui/XmppActivity.java
index 69dd47e7..535aa6a5 100644
--- a/src/main/java/eu/siacs/conversations/ui/XmppActivity.java
+++ b/src/main/java/eu/siacs/conversations/ui/XmppActivity.java
@@ -60,6 +60,7 @@ import java.util.Hashtable;
import java.util.List;
import java.util.concurrent.RejectedExecutionException;
+import de.tzur.conversations.Settings;
import eu.siacs.conversations.Config;
import eu.siacs.conversations.R;
import eu.siacs.conversations.entities.Account;
@@ -304,7 +305,8 @@ public abstract class XmppActivity extends Activity {
this.mTheme = findTheme();
setTheme(this.mTheme);
mUseSubject = getPreferences().getBoolean("use_subject", true);
- }
+ Settings.initSettingsClassWithPreferences(getPreferences());
+ }
protected SharedPreferences getPreferences() {
return PreferenceManager
diff --git a/src/main/java/eu/siacs/conversations/ui/adapter/ConversationAdapter.java b/src/main/java/eu/siacs/conversations/ui/adapter/ConversationAdapter.java
index 6758acb6..22f6b662 100644
--- a/src/main/java/eu/siacs/conversations/ui/adapter/ConversationAdapter.java
+++ b/src/main/java/eu/siacs/conversations/ui/adapter/ConversationAdapter.java
@@ -2,12 +2,14 @@ package eu.siacs.conversations.ui.adapter;
import java.util.List;
+import de.tzur.conversations.Settings;
import eu.siacs.conversations.Config;
import eu.siacs.conversations.R;
import eu.siacs.conversations.entities.Conversation;
import eu.siacs.conversations.entities.Downloadable;
import eu.siacs.conversations.entities.DownloadableFile;
import eu.siacs.conversations.entities.Message;
+import eu.siacs.conversations.entities.Presences;
import eu.siacs.conversations.ui.ConversationActivity;
import eu.siacs.conversations.ui.XmppActivity;
import eu.siacs.conversations.utils.UIHelper;
@@ -15,6 +17,7 @@ import android.content.Context;
import android.graphics.Color;
import android.graphics.Typeface;
import android.preference.PreferenceManager;
+import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
@@ -69,6 +72,26 @@ public class ConversationAdapter extends ArrayAdapter<Conversation> {
ImageView imagePreview = (ImageView) view
.findViewById(R.id.conversation_lastimage);
+ if (Settings.SHOW_ONLINE_STATUS) {
+ TextView status = (TextView) view.findViewById(R.id.status);
+
+ String color = "#000000";
+ switch (conversation.getContact().getMostAvailableStatus()) {
+ case Presences.ONLINE:
+ case Presences.CHAT:
+ color = "#259B23";
+ break;
+ case Presences.AWAY:
+ case Presences.XA:
+ color = "#FF9800";
+ break;
+ case Presences.DND:
+ color = "#E51C23";
+ break;
+ }
+ status.setBackgroundColor(Color.parseColor(color));
+ }
+
Message message = conversation.getLatestMessage();
if (!conversation.isRead()) {
@@ -140,9 +163,8 @@ public class ConversationAdapter extends ArrayAdapter<Conversation> {
} else {
if ((message.getEncryption() != Message.ENCRYPTION_PGP)
&& (message.getEncryption() != Message.ENCRYPTION_DECRYPTION_FAILED)) {
- boolean parseEmoticons = PreferenceManager
- .getDefaultSharedPreferences(activity).getBoolean("parse_emoticons", true);
- mLastMessage.setText(parseEmoticons ? UIHelper
+ boolean parseEmoticons = Settings.PARSE_EMOTICONS;
+ mLastMessage.setText(parseEmoticons ? UIHelper
.transformAsciiEmoticons(getContext(), message.getBody()) : message
.getBody());
} else {
diff --git a/src/main/java/eu/siacs/conversations/ui/adapter/MessageAdapter.java b/src/main/java/eu/siacs/conversations/ui/adapter/MessageAdapter.java
index 88c5c93d..2771c4de 100644
--- a/src/main/java/eu/siacs/conversations/ui/adapter/MessageAdapter.java
+++ b/src/main/java/eu/siacs/conversations/ui/adapter/MessageAdapter.java
@@ -24,6 +24,7 @@ import android.widget.Toast;
import java.util.List;
+import de.tzur.conversations.Settings;
import eu.siacs.conversations.Config;
import eu.siacs.conversations.R;
import eu.siacs.conversations.entities.Account;
@@ -226,9 +227,8 @@ public class MessageAdapter extends ArrayAdapter<Message> {
viewHolder.messageBody.setVisibility(View.VISIBLE);
if (message.getBody() != null) {
if (message.getType() != Message.TYPE_PRIVATE) {
- boolean parseEmoticons = PreferenceManager
- .getDefaultSharedPreferences(getContext()).getBoolean("parse_emoticons", true);
- viewHolder.messageBody.setText(parseEmoticons ? UIHelper
+ boolean parseEmoticons = Settings.PARSE_EMOTICONS;
+ viewHolder.messageBody.setText(parseEmoticons ? UIHelper
.transformAsciiEmoticons(getContext(), message.getMergedBody())
: message.getMergedBody());
} else {
diff --git a/src/main/res/layout/conversation_list_row.xml b/src/main/res/layout/conversation_list_row.xml
index 21147b4a..99f52c5d 100644
--- a/src/main/res/layout/conversation_list_row.xml
+++ b/src/main/res/layout/conversation_list_row.xml
@@ -11,12 +11,22 @@
android:layout_alignParentLeft="true"
android:scaleType="centerCrop" />
+ <TextView
+ android:layout_width="56dp"
+ android:layout_height="4dp"
+ android:textAppearance="?android:attr/textAppearanceSmall"
+ android:id="@+id/status"
+ android:layout_below="@+id/conversation_image"
+ android:paddingTop="8dp"
+ android:paddingRight="8dp"/>
+
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_toRightOf="@+id/conversation_image"
- android:paddingLeft="8dp" >
+ android:paddingLeft="8dp"
+ android:id="@+id/relativeLayout">
<TextView
android:id="@+id/conversation_name"