chat menu settings
author"Vincent Veronis"
Sat, 05 Feb 2011 21:12:06 +0100
changeset 860 d1b0d878eac9
parent 858 f0f107c35a07
child 861 9b8914162ed2
chat menu settings history chat path file setting
res/layout/preferences.xml
res/values-fr/strings.xml
res/values/strings.xml
src/com/beem/project/beem/BeemApplication.java
src/com/beem/project/beem/service/BeemChatManager.java
src/com/beem/project/beem/service/ChatAdapter.java
src/com/beem/project/beem/ui/Settings.java
--- a/res/layout/preferences.xml	Tue Feb 01 00:46:43 2011 +0100
+++ b/res/layout/preferences.xml	Sat Feb 05 21:12:06 2011 +0100
@@ -8,9 +8,6 @@
 <PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
 	android:shouldDisableView="true" android:selectable="true">
 	<PreferenceCategory android:title="@string/general_preferences">
-		<CheckBoxPreference android:id="@+id/settings_key_history"
-			android:title="@string/history" android:defaultValue="false"
-			android:key="settings_key_history" />
 		<PreferenceScreen android:key="contact_list"
 			android:title="@string/contact_list_preferences" android:summary="@string/contact_list_preferences_sum">
 			<CheckBoxPreference android:title="@string/CLP_hidden_contact"
@@ -26,10 +23,24 @@
 				android:singleLine="true" android:summary="@string/away_message_sum"
 				android:title="@string/away_message_title" android:key="settings_away_message"
 				android:hint="@string/away_message_hint" />
-			<CheckBoxPreference android:title="@string/settings_chat_compact"
-				android:defaultValue="false" android:summary="@string/settings_chat_compact_sum"
-				android:key="settings_chat_compact_key" />
 		</PreferenceScreen>
+		<PreferenceScreen android:key="chat"
+			android:title="@string/chat_preferences" android:summary="@string/chat_preferences_sum">
+			<PreferenceCategory android:title="@string/history_preferences">
+				<CheckBoxPreference android:id="@+id/chat_history"
+					android:title="@string/history" android:summary="@string/history_sum"
+					 android:defaultValue="false" android:key="settings_key_history" />
+				<EditTextPreference android:dependency="settings_key_history"
+					android:singleLine="true" android:title="@string/chat_history_path"
+					android:summary="@string/chat_history_path_sum" android:key="settings_chat_history_path"
+					android:hint="/Android/data/com.beem.project.beem/chat/" />
+			</PreferenceCategory>
+			<PreferenceCategory android:title="@string/chat_layout_option">
+				<CheckBoxPreference android:title="@string/settings_chat_compact"
+					android:defaultValue="false" android:summary="@string/settings_chat_compact_sum"
+					android:key="settings_chat_compact_key" />
+			</PreferenceCategory>
+			</PreferenceScreen>
 		<PreferenceScreen android:title="@string/notification_preferences">
 			<CheckBoxPreference android:title="@string/notification_enable_vibrate_title"
 				android:defaultValue="false" android:summary="@string/notification_enable_vibrate_sum"
--- a/res/values-fr/strings.xml	Tue Feb 01 00:46:43 2011 +0100
+++ b/res/values-fr/strings.xml	Sat Feb 05 21:12:06 2011 +0100
@@ -120,8 +120,13 @@
 	<string name="settings_chat_compact">Chat compact</string>
 	<string name="settings_chat_compact_sum">Activer la fenetre Chat compact</string>
 	<string name="history">Historique</string>
+	<string name="history_sum">Cochez cette option pour enregistrer les discussions sur la SDCard</string>
 	<string name="history_mount">Il vous faut avoir une SDcard utilisable en écriture pour activer l\'historique</string>
 	<string name="history_on_off">Activer la l\'historique des messages</string>
+	<string name="chat_preferences">Chat</string>
+	<string name="chat_preferences_sum">Historique, taille de la fenêtre ...</string>
+	<string name="chat_history_path">Répertoire d\'historique</string>
+	<string name="chat_history_path_sum">Les conversations sont enregistrées dans un dossier sur la SDCard</string>
 	<string name="settings_smack_debug">Activer le debugger XMPP</string>
 	<string name="settings_full_jid_login">Utiliser le JID entier en tant que login</string>
 	<string name="settings_full_jid_login_sum">Nécessaire pour certains serveurs (Google Talk)</string>
@@ -217,6 +222,9 @@
 	<string name="settings_tab_label_xmpp">XMPP</string>
 	<string name="settings_tab_tag_proxy">edit_settings_tab_proxy</string>
 	<string name="settings_tab_label_proxy">Proxy</string>
+	<string name="history_preferences">Historique</string>
+	<string name="chat_layout_option">Fenêtre de chat</string>
+	
 
 	<!-- wizard activities -->
 	<string name="account_wizard_text1"><b>Bienvenue sur BEEM.</b>\n\nVous n\'avez pas encore configuré de compte XMPP (Jabber).\nChoisissez une des options suivantes :</string>
--- a/res/values/strings.xml	Tue Feb 01 00:46:43 2011 +0100
+++ b/res/values/strings.xml	Sat Feb 05 21:12:06 2011 +0100
@@ -120,8 +120,13 @@
 	<string name="settings_chat_compact">Chat compact</string>
 	<string name="settings_chat_compact_sum">Set the chat windows compact</string>
 	<string name="history">History</string>
+	<string name="history_sum">Check this to save chats on the SDCard</string>
 	<string name="history_mount">You need to have SDcard mounted and writable to enable history</string>
 	<string name="history_on_off">Enable history messages</string>
+	<string name="chat_preferences">Chat</string>
+	<string name="chat_preferences_sum">History, Layout size ...</string>
+	<string name="chat_history_path">History path</string>
+	<string name="chat_history_path_sum">Chat conversations are saved in a folder on the SDCard</string>
 	<string name="settings_smack_debug">Enable XMPP debug</string>
 	<string name="settings_full_jid_login">Use my full JID as username</string>
 	<string name="settings_full_jid_login_sum">Need by some server such as Google Talk</string>
@@ -200,6 +205,9 @@
 	<string name="network_preferences">Network options</string>
 	<string name="proxy_proxy_settings">Proxy settings</string>
 	<string name="proxy_user_settings">Proxy settings</string>
+	<string name="history_preferences">History</string>
+	<string name="chat_layout_option">Chat layout</string>
+	
 
 	<!-- EditSettings Activity Tabs -->
 	<string name="settings_tab_tag_account">edit_settings_tab_account</string>
--- a/src/com/beem/project/beem/BeemApplication.java	Tue Feb 01 00:46:43 2011 +0100
+++ b/src/com/beem/project/beem/BeemApplication.java	Sat Feb 05 21:12:06 2011 +0100
@@ -87,6 +87,8 @@
     public static final String SMACK_DEBUG_KEY = "smack_debug";
     /** Preference key for full Jid for login. */
     public static final String FULL_JID_LOGIN_KEY = "full_jid_login";
+    /** Preference key for history path on the SDCard */
+    public static final String CHAT_HISTORY_KEY = "settings_chat_history_path";
 
     //TODO add the other one
 
--- a/src/com/beem/project/beem/service/BeemChatManager.java	Tue Feb 01 00:46:43 2011 +0100
+++ b/src/com/beem/project/beem/service/BeemChatManager.java	Sat Feb 05 21:12:06 2011 +0100
@@ -43,6 +43,7 @@
 */
 package com.beem.project.beem.service;
 
+import java.io.File;
 import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.List;
@@ -56,6 +57,7 @@
 import android.app.PendingIntent;
 import android.content.Intent;
 import android.content.SharedPreferences;
+import android.os.Environment;
 import android.os.RemoteCallbackList;
 import android.os.RemoteException;
 import android.preference.PreferenceManager;
@@ -177,8 +179,12 @@
 	    "settings_key_history", false);
 	String accountUser = PreferenceManager.getDefaultSharedPreferences(mService.getBaseContext()).getString(
 	    BeemApplication.ACCOUNT_USERNAME_KEY, "");
-	res.setHisory(history);
+	String historyPath = PreferenceManager.getDefaultSharedPreferences(mService.getBaseContext()).getString(
+	    BeemApplication.CHAT_HISTORY_KEY, "");
+	if ("".equals(historyPath)) historyPath = "/Android/data/com.beem.project.beem/chat/";
+	res.setHistory(history);
 	res.setAccountUser(accountUser);
+	res.setHistoryPath(new File(Environment.getExternalStorageDirectory(), historyPath));
 	Log.d(TAG, "getChat put " + key);
 	mChats.put(key, res);
 	return res;
--- a/src/com/beem/project/beem/service/ChatAdapter.java	Tue Feb 01 00:46:43 2011 +0100
+++ b/src/com/beem/project/beem/service/ChatAdapter.java	Sat Feb 05 21:12:06 2011 +0100
@@ -79,7 +79,8 @@
     private final List<Message> mMessages;
     private final RemoteCallbackList<IMessageListener> mRemoteListeners = new RemoteCallbackList<IMessageListener>();
     private final MsgListener mMsgListener = new MsgListener();
-    private boolean mIsHisory;
+    private boolean mIsHistory;
+    private File mHistoryPath;
     private String mAccountUser;
 
     /**
@@ -108,7 +109,6 @@
     public void sendMessage(com.beem.project.beem.service.Message message) throws RemoteException {
 	org.jivesoftware.smack.packet.Message send = new org.jivesoftware.smack.packet.Message();
 	send.setTo(message.getTo());
-	Log.w(TAG, "message to " + message.getTo());
 	send.setBody(message.getBody());
 	send.setThread(message.getThread());
 	send.setSubject(message.getSubject());
@@ -119,11 +119,11 @@
 	    mAdaptee.sendMessage(send);
 	    mMessages.add(message);
 	} catch (XMPPException e) {
-	    // TODO Auto-generated catch block
 	    e.printStackTrace();
 	}
-	//TODO replace me
-	saveHistory(message, mAccountUser);
+	String state = Environment.getExternalStorageState();
+	if (mIsHistory && Environment.MEDIA_MOUNTED.equals(state))
+	    saveHistory(message, mAccountUser);
     }
 
     /**
@@ -202,7 +202,9 @@
 	    mMessages.remove(0);
 	mMessages.add(msg);
 	if (!"".equals(msg.getBody()) && msg.getBody() != null) {
-	    saveHistory(msg, msg.getFrom());
+	    String state = Environment.getExternalStorageState();
+	    if (mIsHistory && Environment.MEDIA_MOUNTED.equals(state))
+		saveHistory(msg, msg.getFrom());
 	}
     }
 
@@ -212,42 +214,38 @@
      * @param contactName the name of the contact
      */
     public void saveHistory(Message msg, String contactName) {
-    	String state = Environment.getExternalStorageState();
-    	if (mIsHisory && Environment.MEDIA_MOUNTED.equals(state)) {
-    	    File path = new File(Environment.getExternalStorageDirectory(), "beem");
-    	    File filepath;
-    	    if (msg.getFrom() == contactName)
-    		filepath = new File(path, StringUtils.parseBareAddress(contactName));
-    	    else
-    		filepath = new File(path, StringUtils.parseBareAddress(msg.getTo()));
-    	    path.mkdirs();
-    	    try {
-    	    	FileWriter file = new FileWriter(filepath, true);
-    		String log = msg.getTimestamp() + " " + contactName + " " + msg.getBody()
-    			+ System.getProperty("line.separator");
-    		file.write(log);
-    		file.close();
-    		Log.i(TAG, log);
-    	    } catch (IOException e) {
-    	    	e.printStackTrace();
-    	    }
-    	}
+	File path = getHistoryPath();
+    	File filepath;
+    	if (contactName.equals(msg.getFrom()))
+    	    filepath = new File(path, StringUtils.parseBareAddress(contactName));
+    	else
+    	    filepath = new File(path, StringUtils.parseBareAddress(msg.getTo()));
+    	path.mkdirs();
+	try {
+	    FileWriter file = new FileWriter(filepath, true);
+	    String log = msg.getTimestamp() + " " + contactName + " " + msg.getBody()
+		+ System.getProperty("line.separator");
+	    file.write(log);
+	    file.close();
+	} catch (IOException e) {
+	    Log.e(TAG, "Error writing chat history", e);
+	}
     }
 
     /**
-     * set History state.
+     * set History enable/disable.
      * @param isHisory history state
      */
-    public void setHisory(boolean isHisory) {
-	this.mIsHisory = isHisory;
+    public void setHistory(boolean isHisory) {
+	this.mIsHistory = isHisory;
     }
 
     /**
      * get History state.
      * @return mIsHistory
      */
-    public boolean getHisory() {
-	return mIsHisory;
+    public boolean getHistory() {
+	return mIsHistory;
     }
 
     /**
@@ -267,6 +265,22 @@
     }
 
     /**
+     * set History path
+     * @param mHistoryPath history path
+     */
+    public void setHistoryPath(File mHistoryPath) {
+	this.mHistoryPath = mHistoryPath;
+    }
+
+    /**
+     * get History path
+     * @return mHistoryPath;
+     */
+    public File getHistoryPath() {
+	return mHistoryPath;
+    }
+
+    /**
      * Listener.
      */
     private class MsgListener implements ChatStateListener {
--- a/src/com/beem/project/beem/ui/Settings.java	Tue Feb 01 00:46:43 2011 +0100
+++ b/src/com/beem/project/beem/ui/Settings.java	Sat Feb 05 21:12:06 2011 +0100
@@ -76,15 +76,6 @@
     public void onCreate(Bundle savedInstanceState) {
 	super.onCreate(savedInstanceState);
 	addPreferencesFromResource(R.layout.preferences);
-	CheckBoxPreference history = (CheckBoxPreference) findPreference("settings_key_history");
-	String state = Environment.getExternalStorageState();
-	if (!Environment.MEDIA_MOUNTED.equals(state)) {
-	    history.setSelectable(false);
-	    history.setSummary(R.string.history_mount);
-	} else {
-	    history.setSelectable(true);
-	    history.setSummary(R.string.history_on_off);
-	}
     }
 
     /**