Fixes a little bug in contactlist activity.
authorDa Risk <darisk972@gmail.com>
Sat, 15 May 2010 14:36:13 +0200
changeset 740 a91db9ddc46f
parent 739 106f089f8cde
child 741 af1c21ab7ab9
Fixes a little bug in contactlist activity. Refactor and clean of some codes. refs #262 Check for translation needed.
res/layout/preferences.xml
res/values-de/strings.xml
res/values-fr/strings.xml
res/values-ru/strings.xml
res/values/strings.xml
src/com/beem/project/beem/BeemApplication.java
src/com/beem/project/beem/BeemService.java
src/com/beem/project/beem/service/BeemChatManager.java
src/com/beem/project/beem/service/RosterAdapter.java
src/com/beem/project/beem/service/XmppConnectionAdapter.java
src/com/beem/project/beem/ui/ContactList.java
--- a/res/layout/preferences.xml	Mon May 10 20:13:12 2010 +0200
+++ b/res/layout/preferences.xml	Sat May 15 14:36:13 2010 +0200
@@ -25,11 +25,11 @@
 				android:hint="@string/away_message_hint" />
 		</PreferenceScreen>
 		<PreferenceScreen android:title="@string/notification_preferences">
-			<CheckBoxPreference android:title="@string/notification_disable_vibrate_title"
-				android:defaultValue="false" android:summary="@string/notification_disable_vibrate_sum"
-				android:key="settings_notification_disable_vibrate" />
+			<CheckBoxPreference android:title="@string/notification_enable_vibrate_title"
+				android:defaultValue="false" android:summary="@string/notification_enable_vibrate_sum"
+				android:key="notification_vibrate" />
 			<RingtonePreference
-				android:title="@string/notification_snd_title" android:key="settings_notification_snd"
+				android:title="@string/notification_snd_title" android:key="notification_sound"
 				android:summary="@string/notification_snd_sum" android:ringtoneType="notification"
 				android:showDefault="true" />
 		</PreferenceScreen>
--- a/res/values-de/strings.xml	Mon May 10 20:13:12 2010 +0200
+++ b/res/values-de/strings.xml	Sat May 15 14:36:13 2010 +0200
@@ -21,11 +21,6 @@
 	<string name="BeemServiceCreated">Beem Service erstellt</string>
 	<string name="BeemServiceDestroyed">Beem Service verworfen</string>
 
-	<!--  Preferences informations -->
-	<string name="PreferenceStatus">Status</string>
-	<string name="PreferenceStatusText">status_text</string>
-	<string name="PreferenceIsConfigured">preference_is_configured	</string>
-
 	<!-- ContactListSettings class -->
 	<string name="CLSServerConnection">Server Verbindung</string>
 	<string name="CLSUserid">Benutzer id:</string>
@@ -122,8 +117,8 @@
 	<string name="away_message_sum">Angezeigte Abwesendheitsnachricht</string>
 	<string name="away_message_hint">Ich bin abwesend, mein Telefonbildschirm ist aus</string>
 	<string name="notification_preferences">Benachrichtigungseinstellungen</string>
-	<string name="notification_disable_vibrate_title">Vibrieren</string>
-	<string name="notification_disable_vibrate_sum">Deaktivieren Sie vibriert bei eingehenden Nachrichten</string>
+	<string name="notification_enable_vibrate_title">Vibrieren</string>
+	<string name="notification_enable_vibrate_sum">Aktivieren Sie vibriert bei eingehenden Nachrichten</string>
 	<string name="notification_snd_title">Nachrichtensignalton</string>
 	<string name="notification_snd_sum">Lege den Signalton für eingehende Nachrichten fest</string>
 
--- a/res/values-fr/strings.xml	Mon May 10 20:13:12 2010 +0200
+++ b/res/values-fr/strings.xml	Sat May 15 14:36:13 2010 +0200
@@ -119,8 +119,8 @@
 	<string name="away_message_sum">Votre Message d\'absence</string>
 	<string name="away_message_hint">Je suis absent car mon ecran est éteind</string>
 	<string name="notification_preferences">Paramètres des notifications</string>
-	<string name="notification_disable_vibrate_title">Vibreur</string>
-	<string name="notification_disable_vibrate_sum">Désactiver le vibreur pour les messages entrants</string>
+	<string name="notification_enable_vibrate_title">Activer le vibreur</string>
+	<string name="notification_enable_vibrate_sum">Activer le vibreur pour les messages entrants</string>
 	<string name="notification_snd_title">Sonnerie des messages</string>
 	<string name="notification_snd_sum">Configurer la sonnerie des messages entrants</string>
 	
--- a/res/values-ru/strings.xml	Mon May 10 20:13:12 2010 +0200
+++ b/res/values-ru/strings.xml	Sat May 15 14:36:13 2010 +0200
@@ -21,12 +21,6 @@
 <string name="BeemServiceCreated"></string>
 <string name="BeemServiceDestroyed"></string>
 
-<!--  Preferences informations -->
-<string name="PreferenceStatus">Статус</string>
-<string name="PreferenceStatusText"></string>
-<string name="PreferenceIsConfigured">preference_is_configured
-</string>
-
 <!-- ContactListSettings class -->
 <string name="CLSServerConnection">Соединение</string>
 <string name="CLSUserid">Имя пользователя:</string>
@@ -125,8 +119,8 @@
 <string name="away_message_sum"></string>
 <string name="away_message_hint"></string>
 <string name="notification_preferences">Настройка оповещений</string>
-<string name="notification_disable_vibrate_title">Вибрация</string>
-<string name="notification_disable_vibrate_sum">Отключить вибрировать на входящие сообщения</string>
+<string name="notification_enable_vibrate_title">Вибрация</string>
+<string name="notification_enable_vibrate_sum">Активировать вибрировать на входящие сообщения</string>
 <string name="notification_snd_title">Сигнал сообщений</string>
 <string name="notification_snd_sum"></string>
 
--- a/res/values/strings.xml	Mon May 10 20:13:12 2010 +0200
+++ b/res/values/strings.xml	Sat May 15 14:36:13 2010 +0200
@@ -119,8 +119,8 @@
 	<string name="away_message_sum">The away message that will be displayed</string>
 	<string name="away_message_hint">I\'m away, my cellphone screen is off</string>
 	<string name="notification_preferences">Notification settings</string>
-	<string name="notification_disable_vibrate_title">Vibrate</string>
-	<string name="notification_disable_vibrate_sum">Disable vibrate on incoming messages</string>
+	<string name="notification_enable_vibrate_title">Enable vibrate</string>
+	<string name="notification_enable_vibrate_sum">Enable vibrate on incoming messages</string>
 	<string name="notification_snd_title">Message ringtone</string>
 	<string name="notification_snd_sum">Set your incoming message ringtone</string>
 
--- a/src/com/beem/project/beem/BeemApplication.java	Mon May 10 20:13:12 2010 +0200
+++ b/src/com/beem/project/beem/BeemApplication.java	Sat May 15 14:36:13 2010 +0200
@@ -79,6 +79,11 @@
     public static final String PROXY_USERNAME_KEY = "proxy_username";
     /** Preference key for the proxy password */
     public static final String PROXY_PASSWORD_KEY = "proxy_password";
+    /** Preference key for vibrate on notification */
+    public static final String NOTIFICATION_VIBRATE_KEY = "notification_vibrate";
+    /** Preference key for notification sound */
+    public static final String NOTIFICATION_SOUND_KEY = "notification_sound";
+
     //TODO add the other one
 
     private boolean mIsConnected;
--- a/src/com/beem/project/beem/BeemService.java	Mon May 10 20:13:12 2010 +0200
+++ b/src/com/beem/project/beem/BeemService.java	Sat May 15 14:36:13 2010 +0200
@@ -64,6 +64,7 @@
 import android.content.SharedPreferences;
 import android.content.SharedPreferences.Editor;
 import android.net.ConnectivityManager;
+import android.net.Uri;
 import android.os.IBinder;
 import android.os.RemoteException;
 import android.preference.PreferenceManager;
@@ -163,7 +164,6 @@
     public boolean onUnbind(Intent intent) {
 	Log.d(TAG, "ONUNBIND()");
 	if (!mConnection.getAdaptee().isConnected()) {
-	    Log.d(TAG, "DESTROYED");
 	    this.stopSelf();
 	}
 	return true;
@@ -220,7 +220,6 @@
     @Override
     public void onDestroy() {
 	super.onDestroy();
-	Log.d("Service", "onDestroy");
 	resetStatus();
 	mNotificationManager.cancelAll();
 	unregisterReceiver(mReceiver);
@@ -247,11 +246,16 @@
     }
 
     /**
-     * Show a notification.
+     * Show a notification using the preference of the user.
      * @param id the id of the notification.
      * @param notif the notification to show
      */
     public void sendNotification(int id, Notification notif) {
+	if (mSettings.getBoolean(BeemApplication.NOTIFICATION_VIBRATE_KEY, true))
+	    notif.defaults |= Notification.DEFAULT_VIBRATE;
+	notif.defaults |= Notification.DEFAULT_LIGHTS;
+	String ringtoneStr = mSettings.getString(BeemApplication.NOTIFICATION_SOUND_KEY, "");
+	notif.sound = Uri.parse(ringtoneStr);
 	mNotificationManager.notify(id, notif);
     }
 
--- a/src/com/beem/project/beem/service/BeemChatManager.java	Mon May 10 20:13:12 2010 +0200
+++ b/src/com/beem/project/beem/service/BeemChatManager.java	Sat May 15 14:36:13 2010 +0200
@@ -75,8 +75,8 @@
  * @author darisk
  */
 public class BeemChatManager extends IChatManager.Stub {
-    /** Tag to use with log methods. */
-    public static final String TAG = "BeemChatManager";
+
+    private static final String TAG = "BeemChatManager";
     private final ChatManager mAdaptee;
     private final Map<String, ChatAdapter> mChats = new HashMap<String, ChatAdapter>();
     private final ChatListener mChatListener = new ChatListener();
@@ -95,9 +95,6 @@
 	mAdaptee.addChatListener(mChatListener);
     }
 
-    /**
-     * {@inheritDoc}
-     */
     @Override
     public void addChatCreationListener(IChatManagerListener listener) throws RemoteException {
 	if (listener != null)
@@ -258,7 +255,7 @@
 	 */
 	private PendingIntent makeChatIntent(IChat chat) {
 	    Intent chatIntent = new Intent(mService, com.beem.project.beem.ui.Chat.class);
-	    chatIntent.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT | Intent.FLAG_ACTIVITY_SINGLE_TOP);
+	    chatIntent.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT | Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
 	    try {
 		chatIntent.setData(chat.getParticipant().toUri());
 	    } catch (RemoteException e) {
@@ -280,13 +277,9 @@
 		.getName();
 		Notification notification = new Notification(android.R.drawable.stat_notify_chat, tickerText, System
 		    .currentTimeMillis());
-		if (!pref.getBoolean("settings_notification_disable_vibrate", true))
-		    notification.defaults -= Notification.DEFAULT_VIBRATE;
 		notification.flags = Notification.FLAG_AUTO_CANCEL;
 		notification.setLatestEventInfo(mService, tickerText, mService
 		    .getString(R.string.BeemChatManagerNewMessage), makeChatIntent(chat));
-		String ringtoneStr = pref.getString("settings_notification_snd", "");
-		notification.sound = Uri.parse(ringtoneStr);
 		mService.sendNotification(chat.getParticipant().getJID().hashCode(), notification);
 	    } catch (RemoteException e) {
 		Log.e(TAG, e.getMessage());
--- a/src/com/beem/project/beem/service/RosterAdapter.java	Mon May 10 20:13:12 2010 +0200
+++ b/src/com/beem/project/beem/service/RosterAdapter.java	Sat May 15 14:36:13 2010 +0200
@@ -112,20 +112,6 @@
 	    Log.e(TAG, "Error while adding new contact", e);
 	    return null;
 	}
-	if (groups != null) {
-	    for (String groupStr : groups) {
-		RosterGroup group = mAdaptee.getGroup(groupStr);
-		if (group == null) {
-		    group = mAdaptee.createGroup(groupStr);
-		}
-		try {
-		    group.addEntry(contact);
-		} catch (XMPPException e) {
-		    e.printStackTrace();
-		    return null;
-		}
-	    }
-	}
 	return getContactFromRosterEntry(contact);
     }
 
@@ -147,11 +133,8 @@
      */
     @Override
     public void createGroup(String groupname) throws RemoteException {
-	try {
+	if (mAdaptee.getGroup(groupname) == null)
 	    mAdaptee.createGroup(groupname);
-	} catch (IllegalArgumentException e) {
-	    Log.v(TAG, "Error while creating group", e);
-	}
     }
 
     /**
@@ -170,16 +153,9 @@
     @Override
     public List<Contact> getContactList() throws RemoteException {
 	boolean add = true;
-	List<Contact> coList = new ArrayList<Contact>(mAdaptee.getEntries().size());
-	for (RosterEntry entry : mAdaptee.getEntries()) {
-	    for (Contact c : coList) {
-		if (c.getJID().equals(entry.getUser())) {
-		    add = false;
-		    break;
-		}
-	    }
-	    // Because getEntries return duplicated user.
-	    if (add)
+	Collection<RosterEntry> list = mAdaptee.getEntries();
+	List<Contact> coList = new ArrayList<Contact>(list.size());
+	for (RosterEntry entry : list) {
 		coList.add(getContactFromRosterEntry(entry));
 	}
 	return coList;
--- a/src/com/beem/project/beem/service/XmppConnectionAdapter.java	Mon May 10 20:13:12 2010 +0200
+++ b/src/com/beem/project/beem/service/XmppConnectionAdapter.java	Sat May 15 14:36:13 2010 +0200
@@ -571,10 +571,10 @@
 		    String from = packet.getFrom();
 		    Notification notif = new Notification(android.R.drawable.stat_notify_more, mService.getString(
 			R.string.AcceptContactRequest, from), System.currentTimeMillis());
-		    notif.defaults = Notification.DEFAULT_ALL;
 		    notif.flags = Notification.FLAG_AUTO_CANCEL;
 		    Intent intent = new Intent(mService, Subscription.class);
-		    intent.putExtra("from", from);
+		    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
+			.putExtra("from", from);
 		    notif.setLatestEventInfo(mService, from, mService
 			.getString(R.string.AcceptContactRequestFrom, from), PendingIntent.getActivity(mService, 0,
 			    intent, PendingIntent.FLAG_ONE_SHOT));
@@ -620,16 +620,11 @@
 	    if (p.getType() != Presence.Type.subscribe)
 		return;
 	    String from = p.getFrom();
-	    SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(mService);
 	    Notification notification = new Notification(android.R.drawable.stat_notify_more, mService.getString(
 		R.string.AcceptContactRequest, from), System.currentTimeMillis());
-	    if (!pref.getBoolean("settings_notification_disable_vibrate", true))
-		notification.defaults -= Notification.DEFAULT_VIBRATE;
 	    notification.flags = Notification.FLAG_AUTO_CANCEL;
 	    Intent intent = new Intent(mService, Subscription.class);
 	    intent.putExtra("from", from);
-	    String ringtoneStr = pref.getString("settings_notification_snd", "");
-	    notification.sound = Uri.parse(ringtoneStr);
 	    notification.setLatestEventInfo(mService, from, mService
 		.getString(R.string.AcceptContactRequestFrom, from), PendingIntent.getActivity(mService, 0,
 		    intent, PendingIntent.FLAG_ONE_SHOT));
--- a/src/com/beem/project/beem/ui/ContactList.java	Mon May 10 20:13:12 2010 +0200
+++ b/src/com/beem/project/beem/ui/ContactList.java	Sat May 15 14:36:13 2010 +0200
@@ -127,6 +127,7 @@
     private IXmppFacade mXmppFacade;
     private SharedPreferences mSettings;
     private LayoutInflater mInflater;
+    private boolean mBinded;
 
     /**
      * Constructor.
@@ -289,8 +290,10 @@
     @Override
     protected void onResume() {
 	super.onResume();
-	if (mXmppFacade == null)
-	    bindService(SERVICE_INTENT, mServConn, BIND_AUTO_CREATE);
+	if (!mBinded) {
+	    mBinded = bindService(SERVICE_INTENT, mServConn, BIND_AUTO_CREATE);
+	    Log.d(TAG, "on resume bind = " + mBinded);
+	}
 	else {
 	    if (!mSettings.getBoolean("settings_key_hide_groups", false))
 		buildBanner();
@@ -314,7 +317,10 @@
 	} catch (RemoteException e) {
 	    Log.d("ContactList", "Remote exception", e);
 	}
-	unbindService(mServConn);
+	if (mBinded) {
+	    unbindService(mServConn);
+	    mBinded = false;
+	}
 	mXmppFacade = null;
     }