diff --git a/AndroidManifest.xml b/AndroidManifest.xml index 33dcdfa4..ce4ea5df 100644 --- a/AndroidManifest.xml +++ b/AndroidManifest.xml @@ -1,8 +1,8 @@ + android:versionCode="31" + android:versionName="0.7.3" > @@ -63,6 +62,14 @@ + + + + + + + + + + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + diff --git a/art/render.rb b/art/render.rb index 5464b9f5..a78a2f47 100755 --- a/art/render.rb +++ b/art/render.rb @@ -1,6 +1,6 @@ #!/bin/env ruby resolutions={'mdpi'=> 1, 'hdpi' => 1.5, 'xhdpi' => 2, 'xxhdpi' => 3} -images = { 'conversations.svg' => ['ic_launcher',48], 'conversations_baloon.svg' => ['ic_activity', 32], 'conversations_mono.svg' => ['ic_notification',24], 'ic_received_indicator.svg' => ['ic_received_indicator',12] } +images = { 'conversations.svg' => ['ic_launcher', 48], 'conversations_baloon.svg' => ['ic_activity', 32], 'conversations_mono.svg' => ['ic_notification', 24], 'ic_received_indicator.svg' => ['ic_received_indicator', 12], 'ic_action_copy.svg' => ['ic_action_copy', 32] } images.each do |source, result| resolutions.each do |name, factor| size = factor * result[1] diff --git a/res/drawable-hdpi/ic_action_copy.png b/res/drawable-hdpi/ic_action_copy.png new file mode 100644 index 00000000..b47bb69c Binary files /dev/null and b/res/drawable-hdpi/ic_action_copy.png differ diff --git a/res/drawable-mdpi/ic_action_copy.png b/res/drawable-mdpi/ic_action_copy.png new file mode 100644 index 00000000..75788f1f Binary files /dev/null and b/res/drawable-mdpi/ic_action_copy.png differ diff --git a/res/drawable-xhdpi/ic_action_copy.png b/res/drawable-xhdpi/ic_action_copy.png new file mode 100644 index 00000000..a45423f6 Binary files /dev/null and b/res/drawable-xhdpi/ic_action_copy.png differ diff --git a/res/drawable-xxhdpi/ic_action_copy.png b/res/drawable-xxhdpi/ic_action_copy.png new file mode 100644 index 00000000..3a0e8449 Binary files /dev/null and b/res/drawable-xxhdpi/ic_action_copy.png differ diff --git a/res/layout-sw360dp/fragment_conversations_overview.xml b/res/layout-w360dp/fragment_conversations_overview.xml similarity index 93% rename from res/layout-sw360dp/fragment_conversations_overview.xml rename to res/layout-w360dp/fragment_conversations_overview.xml index ef8a1b6e..a600118d 100644 --- a/res/layout-sw360dp/fragment_conversations_overview.xml +++ b/res/layout-w360dp/fragment_conversations_overview.xml @@ -1,11 +1,11 @@ diff --git a/res/layout-sw384dp/fragment_conversations_overview.xml b/res/layout-w384dp/fragment_conversations_overview.xml similarity index 96% rename from res/layout-sw384dp/fragment_conversations_overview.xml rename to res/layout-w384dp/fragment_conversations_overview.xml index 2a422052..c3aa67ae 100644 --- a/res/layout-sw384dp/fragment_conversations_overview.xml +++ b/res/layout-w384dp/fragment_conversations_overview.xml @@ -1,5 +1,5 @@ diff --git a/res/layout-sw600dp/fragment_conversations_overview.xml b/res/layout-w600dp/fragment_conversations_overview.xml similarity index 93% rename from res/layout-sw600dp/fragment_conversations_overview.xml rename to res/layout-w600dp/fragment_conversations_overview.xml index 5dfdceff..331fb1f0 100644 --- a/res/layout-sw600dp/fragment_conversations_overview.xml +++ b/res/layout-w600dp/fragment_conversations_overview.xml @@ -1,11 +1,11 @@ diff --git a/res/layout-sw720dp/fragment_conversations_overview.xml b/res/layout-w960dp/fragment_conversations_overview.xml similarity index 65% rename from res/layout-sw720dp/fragment_conversations_overview.xml rename to res/layout-w960dp/fragment_conversations_overview.xml index bc52ec46..2744f38e 100644 --- a/res/layout-sw720dp/fragment_conversations_overview.xml +++ b/res/layout-w960dp/fragment_conversations_overview.xml @@ -1,12 +1,14 @@ - + android:layout_height="match_parent" + android:orientation="horizontal" + android:baselineAligned="false"> @@ -21,10 +23,10 @@ - \ No newline at end of file + \ No newline at end of file diff --git a/res/layout/activity_edit_account.xml b/res/layout/activity_edit_account.xml index 04f63795..91bda7b1 100644 --- a/res/layout/activity_edit_account.xml +++ b/res/layout/activity_edit_account.xml @@ -180,13 +180,38 @@ android:textSize="?attr/TextSizeHeadline" android:textStyle="bold" /> - + android:layout_height="match_parent" + android:layout_marginTop="8dp"> + + + + + + + @@ -226,4 +251,4 @@ android:textColor="@color/secondarytext" /> - \ No newline at end of file + diff --git a/res/layout/dialog_verify_otr.xml b/res/layout/dialog_verify_otr.xml index 831f06ed..499ef6cd 100644 --- a/res/layout/dialog_verify_otr.xml +++ b/res/layout/dialog_verify_otr.xml @@ -11,7 +11,7 @@ android:layout_width="wrap_content" android:layout_height="wrap_content" android:paddingTop="8dp" - android:text="Jabber ID" + android:text="@string/account_settings_jabber_id" android:textColor="@color/primarytext" android:textSize="?attr/TextSizeHeadline" /> diff --git a/res/layout/fragment_conversation.xml b/res/layout/fragment_conversation.xml index 0f5f692e..f9aae10a 100644 --- a/res/layout/fragment_conversation.xml +++ b/res/layout/fragment_conversation.xml @@ -37,7 +37,7 @@ android:layout_toLeftOf="@+id/textSendButton" android:background="@color/primarybackground" android:ems="10" - android:imeOptions="flagNoExtractUi" + android:imeOptions="flagNoExtractUi|actionSend" android:inputType="textShortMessage|textMultiLine|textCapSentences" android:minHeight="48dp" android:minLines="1" diff --git a/res/layout/fragment_conversations_overview.xml b/res/layout/fragment_conversations_overview.xml index bc52ec46..d4145761 100644 --- a/res/layout/fragment_conversations_overview.xml +++ b/res/layout/fragment_conversations_overview.xml @@ -1,5 +1,5 @@ diff --git a/res/layout/message_null.xml b/res/layout/message_null.xml index 1e148585..0e0f1c92 100644 --- a/res/layout/message_null.xml +++ b/res/layout/message_null.xml @@ -1,6 +1,7 @@ + android:layout_height="0dp" + android:background="#00000000"> \ No newline at end of file diff --git a/res/layout/message_received.xml b/res/layout/message_received.xml index 28c04a70..730d00d5 100644 --- a/res/layout/message_received.xml +++ b/res/layout/message_received.xml @@ -54,7 +54,7 @@ android:text="@string/download_image" android:visibility="gone" /> - - - + android:alpha="0.54" + android:gravity="center_vertical" + android:src="@drawable/ic_secure_indicator" /> - - + android:alpha="0.54" + android:gravity="center_vertical" + android:src="@drawable/ic_secure_indicator" /> + - - + android:alpha="0.54" + android:gravity="center_vertical" + android:src="@drawable/ic_received_indicator" /> @@ -99,4 +97,4 @@ android:scaleType="fitXY" android:src="@drawable/ic_profile" /> - + \ No newline at end of file diff --git a/res/values-de/arrays.xml b/res/values-de/arrays.xml index e468f478..9b429c5a 100644 --- a/res/values-de/arrays.xml +++ b/res/values-de/arrays.xml @@ -20,5 +20,12 @@ 524288 1048576 + + 30 Minuten + eine Stunde + 2 Stunden + 8 Stunden + bis auf Widerruf + \ No newline at end of file diff --git a/res/values-de/strings.xml b/res/values-de/strings.xml index 14397e16..72121774 100644 --- a/res/values-de/strings.xml +++ b/res/values-de/strings.xml @@ -259,5 +259,11 @@ Absende-Knopf zeigt Online-Status an Absende-Knopf einfärben, um den Online-Status des Kontakts zu signalisieren Sonstiges + Konferenz-Name + Konferenz-Thema statt Raum-JID als Name verwenden + OTR Fingerabdruck in die Zwischenablage kopiert! + Du wurdest aus dem Konferenzraum verbannt + Der Konferenzraum ist nur für Mitglieder + Du wurdest aus dem Konferenzraum geworfen diff --git a/res/values-es/strings.xml b/res/values-es/strings.xml index d6fbc7cb..7fdc95c0 100644 --- a/res/values-es/strings.xml +++ b/res/values-es/strings.xml @@ -254,5 +254,16 @@ Por favor, cuidado con estas opciones Incrementar tamaño de fuente Usar fuentes grandes en toda la aplicación + Botón enviar indica estado + Solicitar entrega de mensaje + Cuando el contacto reciba el mensaje será indicado con una marca verde. Cuidado, esto podría no funcionar en todos los casos. + El color del botón enviar indica el estado del contacto + Otros + Nombre de conferencia + Usar el asunto de la conferencia en lugar del identificador jabber como nombre de conferencia + ¡Clave OTR copiada en el portapapeles! + Tu entrada a esta conferencia ha sido prohibida + Esta conferencia es solo para miembros + Has sido expulsado de esta conferencia \ No newline at end of file diff --git a/res/values-eu/arrays.xml b/res/values-eu/arrays.xml index cb1c20fd..a34d3c6a 100644 --- a/res/values-eu/arrays.xml +++ b/res/values-eu/arrays.xml @@ -26,8 +26,9 @@ 2 ordu 8 ordu abisatu arte - - + + + 1800 3600 7200 @@ -35,4 +36,4 @@ -1 - + \ No newline at end of file diff --git a/res/values-eu/strings.xml b/res/values-eu/strings.xml index 72737284..4d3522fd 100644 --- a/res/values-eu/strings.xml +++ b/res/values-eu/strings.xml @@ -256,5 +256,5 @@ Letra tamaina handiagoa erabili aplikazio osoan zehar Bidaltze botoiak egoera adierazten du Bidaltze botoia koloreztatu kontaktu baten egoera adierazteko - - + + \ No newline at end of file diff --git a/res/values-he/arrays.xml b/res/values-iw/arrays.xml similarity index 100% rename from res/values-he/arrays.xml rename to res/values-iw/arrays.xml diff --git a/res/values-he/strings.xml b/res/values-iw/strings.xml similarity index 100% rename from res/values-he/strings.xml rename to res/values-iw/strings.xml diff --git a/res/values-zh-rCN/arrays.xml b/res/values-zh-rCN/arrays.xml new file mode 100644 index 00000000..1a243079 --- /dev/null +++ b/res/values-zh-rCN/arrays.xml @@ -0,0 +1,39 @@ + + + + + 手机 + 电话 + 平板电脑 + Conversations + Android + + + 永不 + 256 KB + 512 KB + 1 MB + + + 0 + 262144 + 524288 + 1048576 + + + 30 分钟 + 1 小时 + 2 小时 + 8 小时 + 直至另行取消 + + + + 1800 + 3600 + 7200 + 28800 + -1 + + + \ No newline at end of file diff --git a/res/values-zh/strings.xml b/res/values-zh-rCN/strings.xml similarity index 100% rename from res/values-zh/strings.xml rename to res/values-zh-rCN/strings.xml diff --git a/res/values-zh-rTW/arrays.xml b/res/values-zh-rTW/arrays.xml new file mode 100644 index 00000000..b9c261ad --- /dev/null +++ b/res/values-zh-rTW/arrays.xml @@ -0,0 +1,39 @@ + + + + + 手機 + 電話 + 平板電腦 + Conversations + Android + + + 永不 + 256 KB + 512 KB + 1 MB + + + 0 + 262144 + 524288 + 1048576 + + + 30 分鐘 + 1 小時 + 2 小時 + 8 小時 + 直至另行取消 + + + + 1800 + 3600 + 7200 + 28800 + -1 + + + \ No newline at end of file diff --git a/res/values-zh-rTW/strings.xml b/res/values-zh-rTW/strings.xml new file mode 100644 index 00000000..2c3ea225 --- /dev/null +++ b/res/values-zh-rTW/strings.xml @@ -0,0 +1,263 @@ + + + + Conversations + 設定 + 新對話 + 管理帳戶 + 結束對話 + 聯絡人詳情 + 安全對話 + 新增帳戶 + 編輯姓名 + 新增到手機通訊錄 + 從列表中刪除 + 管理帳戶 + 群組詳情 + 聯絡人詳情 + 對話 + 分享對話 + 開始對話 + 選擇聯絡人 + 剛剛 + 1 分鐘前 + %d 分鐘前 + 未讀對話 + 正在發送… + 正在解密訊息中,請稍候… + 該用戶名稱已被使用 + 管理員 + 擁有人 + 版主 + 成員 + 訪客 + 你確定要將 %s 從聯絡人清單中移除嗎?與該聯絡人的對話將不會被清除。 + 你確定要將 %s 從書籤清單中移除嗎?與該聯絡人的對話將不會被清除。 + 在伺服器上註冊新帳戶 + 分享 + 開始對話 + 邀請聯絡人 + 聯絡人 + 取消 + 新增 + 編輯 + 刪除 + 儲存 + 好的 + Conversations 停止運行 + 發送「堆疊追蹤」給 Conversations 的開發人員能幫助改進本程式。\n警告: 你的 XMPP 帳戶將被用作發送有關訊息之用。 + 現在發送 + 不再詢問 + 無法連接至帳戶 + 無法連接至多個帳戶 + 點擊此處管理帳戶。 + 附件 + 該聯絡人不在你的聯絡人清單上,需要加為聯絡人嗎? + 新增聯絡人 + 傳遞失敗 + 拒絕 + 接收圖片文件中,請稍候… + 準備傳輸圖片 + 清除歷史記錄 + 清除對話記錄 + 你確定要刪除該對話中所有訊息嗎?\n\n警告: 這將不會影響其他設備或伺服器儲存的訊息。 + 刪除訊息 + 之後結束這對話 + 選擇狀態訊息 + 發送純文字訊息 + 發送 OTR 加密訊息 + 發送 OpenPGP 加密訊息 + 用戶名稱修改成功 + 下載圖片 + 可供下載的圖像文件 + 不加密發送 + 解密失敗,可能是私鑰不正確。 + OpenKeychain + Conversations 使用一個名為 OpenKeychain 的第三方程式來加密、解碼訊息以及管理您的公鑰。\n\nOpenKeychain 以 GPLv3 釋出,並可在 F-Droid 和 Google Play 上下載。\n\n(之後請重新啟動 Conversations。) + 重新啟動 + 安裝 + 提供中… + 等待中… + 找不到 OpenPGP 鑰匙 + Conversations 不能將你的訊息加密,因為聯絡人沒有公佈他/她的公鑰。\n\n請通知聯絡人設定 OpenPGP。 + 找不到多條 OpenPGP 鑰匙 + Conversations 不能將你的訊息加密,因為多位聯絡人沒有公佈他/她的公鑰。\n\n請通知聯絡人設定 OpenPGP。 + 已收到加密訊息,點擊進行解密和查看。 + 已收到加密圖片,點擊進行解密和查看。 + 已收到圖片,點擊查看 + 一般 + XMPP 資源 + 客戶端標示名稱 + 接收文件 + 自動接收小於 … 的文件 + 通知設定 + 通知 + 收到新訊息時通知 + 震動 + 收到新訊息時震動 + 聲音 + 收到新訊息時播放鈴聲 + 群組通知 + 當有新訊息時總是通知,而不是被標記時才通知 + 通知限期 + 收到副本後,關閉通知一小段時間 + 進階選項 + 總是不發送故障報告 + 發送「堆疊追蹤」給 Conversations 的開發人員能幫助改進本程式 + 確認訊息 + 讓你的聯絡人知道你已收到及閱讀訊息 + 介面選項 + OpenKeychain 回報了一個錯誤 + 解密文件時出現 I/O 錯誤 + 接受 + 發生了一個錯誤 + 同意更新狀態訊息 + 預先更新狀態訊息並關注聯絡人的狀態訊息 + 關注 + 你的帳戶 + 鑰匙 + 發送狀態訊息 + 接收狀態訊息 + 關注狀態訊息 + 選擇圖片 + 拍照 + 預先同意關注請求 + 您選擇的文件不是圖片 + 轉換圖片時發生錯誤 + 找不到文件 + 一般的 I/O 錯誤。是存儲空間不足嗎? + 你用來選擇圖片的 app 沒有給予足夠權限我們去讀取文件。\n\n請使用另一文件管理器來選擇圖片 + 未知 + 暫時停用 + 在線 + 連接中\u2026 + 離線 + 未授權 + 未找到伺服器 + 未連接網絡 + 註冊失敗 + 該用戶名稱已被使用 + 註冊完成 + 伺服器不支持註冊 + 純文字內容 + OTR + OpenPGP + 編輯帳戶 + 刪除帳戶 + 暫時停用 + 發佈頭像 + 發布 OpenPGP 公共鑰匙 + 啟用帳戶 + 你確定嗎? + 如果刪除帳戶,則所有對話訊息將會被刪除 + 錄音 + Jabber ID + 密碼 + username@example.com + 確認密碼 + 密碼 + 確認密碼 + 密碼不一致 + 該 Jabber ID 無效 + 空間不足,圖片過大 + 你確定要新增 %s 為聯絡人嗎? + 線上 + 目前有空 + 離開 + 長時間離開 + 請勿打擾 + 離線 + 群組 + 其他成員 + XEP-0280: Message Carbons + XEP-0198: Stream Management + XEP-0163: PEP (Avatars) + 支援 + 不支援 + 沒有公佈公鑰訊息。 + 剛剛曾在線上 + 一分鐘前曾在線上 + %d 分鐘前曾在線上 + 一小時前曾在線上 + %d 小時前曾在線上 + 一天前曾在線上 + %d 天前曾在線上 + 未曾上線 + 加密的訊息。請安裝 OpenKeychain 以解密。 + 未知的 OTR 指紋 + 發現以 OpenPGP 加密的訊息 + 接收失敗 + 你的指紋 + OTR 指紋 + 驗證 + 解密 + 群組 + 查找 + 新增聯絡人 + 加入群組 + 刪除聯絡人 + 查看聯絡人詳細訊息 + 新增 + 聯絡人已存在 + 加入 + 群組地址 + room@conference.example.com + 儲存為書籤 + 刪除書籤 + 該書籤已存在 + + 編輯群組主題 + 群組未找到 + 離開 + 聯絡人已新增你到聯絡人列表 + 新增為聯絡人 + %s 讀到此處 + 發佈 + 點擊頭像可選擇頭像 + 請注意: 所有關注你狀態訊息的人將看到該圖像。 + 發佈中… + 伺服器拒絕了你的發佈請求 + 發佈頭像時發生錯誤 + 將頭像儲存至硬碟時發生錯誤 + (或長按以回復預設頭像) + 你的伺服器不支持發佈頭像 + 私密聊天 + 給 %s + 發送私密消息給 %s + 連接 + 該帳戶已存在 + 下一步 + 已建立連接 + 其他訊息 + 略過 + 關閉通知 + 關閉該對話消息 + 通知已關閉 + 打開通知 + 群組設有密碼 + 輸入密碼 + 缺少聯絡人狀態訊息 + 請先發送關注狀態訊息請求。\n\n這將用來判斷您的聯絡人所用的客戶端類型。 + 現在發送請求 + 刪除指紋 + 你確定刪除該指紋嗎? + 忽略 + 警告: 在沒有互相關注狀態訊息的情況下發送或會引起不能預計的問題。\n\n請檢視聯絡人詳情頁面以確認你們的關注狀態。 + 加密設定 + 強制要求端到端加密 + 總是發送加密訊息 (群組訊息除外) + 不儲存加密訊息 + 警告: 此操作或會導致訊息丟失 + 專家選項 + 請小心設定 + 增加字體大小 + 讓整個 app 界面使用更大號的字體 + 用「發送」按鈕顯示狀態訊息 + 要求讀取收據 + 已被讀取的訊息會以綠色勾號表示。請注意,這個功能未必每次有效。 + 將「發送」按鈕設成不同顏色,以表示不同的狀態訊息。 + 其他 + 群組名稱 + 使用群組的名稱而不是 JID 來識別之。 + + \ No newline at end of file diff --git a/res/values/strings.xml b/res/values/strings.xml index 8d976dce..58af226b 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -261,5 +261,9 @@ Other Conference name Use room’s subject instead of JID to identify conferences + OTR fingerprint copied to clipboard! + You are banned from this conference + This conference is members only + You have been kicked from this conference - \ No newline at end of file + diff --git a/res/xml/preferences.xml b/res/xml/preferences.xml index 024335f1..eccc8bae 100644 --- a/res/xml/preferences.xml +++ b/res/xml/preferences.xml @@ -52,15 +52,9 @@ - - - - + + + - + \ No newline at end of file diff --git a/src/eu/siacs/conversations/Config.java b/src/eu/siacs/conversations/Config.java index 1725eca6..a11e1763 100644 --- a/src/eu/siacs/conversations/Config.java +++ b/src/eu/siacs/conversations/Config.java @@ -10,7 +10,7 @@ public final class Config { public static final int PING_MIN_INTERVAL = 30; public static final int PING_TIMEOUT = 10; public static final int CONNECT_TIMEOUT = 90; - public static final int CARBON_GRACE_PERIOD = 60; + public static final int CARBON_GRACE_PERIOD = 120; public static final int AVATAR_SIZE = 192; public static final Bitmap.CompressFormat AVATAR_FORMAT = Bitmap.CompressFormat.WEBP; diff --git a/src/eu/siacs/conversations/entities/Bookmark.java b/src/eu/siacs/conversations/entities/Bookmark.java index 14f010e7..722fb6d9 100644 --- a/src/eu/siacs/conversations/entities/Bookmark.java +++ b/src/eu/siacs/conversations/entities/Bookmark.java @@ -7,46 +7,35 @@ import android.graphics.Bitmap; import eu.siacs.conversations.utils.UIHelper; import eu.siacs.conversations.xml.Element; -public class Bookmark implements ListItem { +public class Bookmark extends Element implements ListItem { private Account account; - private String jid; - private String nick; - private String name; - private String password; - private boolean autojoin; - private boolean providePassword; private Conversation mJoinedConversation; public Bookmark(Account account, String jid) { + super("conference"); + this.setAttribute("jid", jid); + this.account = account; + } + + private Bookmark(Account account) { + super("conference"); this.account = account; - this.jid = jid; } public static Bookmark parse(Element element, Account account) { - Bookmark bookmark = new Bookmark(account, element.getAttribute("jid")); - bookmark.setName(element.getAttribute("name")); - String autojoin = element.getAttribute("autojoin"); - if (autojoin != null - && (autojoin.equals("true") || autojoin.equals("1"))) { - bookmark.setAutojoin(true); - } else { - bookmark.setAutojoin(false); - } - Element nick = element.findChild("nick"); - if (nick != null) { - bookmark.setNick(nick.getContent()); - } - Element password = element.findChild("password"); - if (password != null) { - bookmark.setPassword(password.getContent()); - bookmark.setProvidePassword(true); - } + Bookmark bookmark = new Bookmark(account); + bookmark.setAttributes(element.getAttributes()); + bookmark.setChildren(element.getChildren()); return bookmark; } public void setAutojoin(boolean autojoin) { - this.autojoin = autojoin; + if (autojoin) { + this.setAttribute("autojoin", "true"); + } else { + this.setAttribute("autojoin", "false"); + } } public void setName(String name) { @@ -54,15 +43,18 @@ public class Bookmark implements ListItem { } public void setNick(String nick) { - this.nick = nick; + Element element = this.findChild("nick"); + if (element == null) { + element = this.addChild("nick"); + } + element.setContent(nick); } public void setPassword(String password) { - this.password = password; - } - - private void setProvidePassword(boolean providePassword) { - this.providePassword = providePassword; + Element element = this.findChild("password"); + if (element != null) { + element.setContent(password); + } } @Override @@ -76,32 +68,45 @@ public class Bookmark implements ListItem { if (this.mJoinedConversation != null && (this.mJoinedConversation.getMucOptions().getSubject() != null)) { return this.mJoinedConversation.getMucOptions().getSubject(); - } else if (name != null) { - return name; + } else if (getName() != null) { + return getName(); } else { - return this.jid.split("@")[0]; + return this.getJid().split("@")[0]; } } @Override public String getJid() { - return this.jid.toLowerCase(Locale.US); + String jid = this.getAttribute("jid"); + if (jid != null) { + return jid.toLowerCase(Locale.US); + } else { + return null; + } } public String getNick() { - return this.nick; + Element nick = this.findChild("nick"); + if (nick != null) { + return nick.getContent(); + } else { + return null; + } } public boolean autojoin() { - return autojoin; + String autojoin = this.getAttribute("autojoin"); + return (autojoin != null && (autojoin.equalsIgnoreCase("true") || autojoin + .equalsIgnoreCase("1"))); } public String getPassword() { - return this.password; - } - - public boolean isProvidePassword() { - return this.providePassword; + Element password = this.findChild("password"); + if (password != null) { + return password.getContent(); + } else { + return null; + } } public boolean match(String needle) { @@ -131,27 +136,7 @@ public class Bookmark implements ListItem { } public String getName() { - return name; - } - - public Element toElement() { - Element element = new Element("conference"); - element.setAttribute("jid", this.getJid()); - if (this.getName() != null) { - element.setAttribute("name", this.getName()); - } - if (this.autojoin) { - element.setAttribute("autojoin", "true"); - } else { - element.setAttribute("autojoin", "false"); - } - if (this.nick != null) { - element.addChild("nick").setContent(this.nick); - } - if (this.password != null && isProvidePassword()) { - element.addChild("password").setContent(this.password); - } - return element; + return this.getAttribute("name"); } public void unregisterConversation() { diff --git a/src/eu/siacs/conversations/entities/Contact.java b/src/eu/siacs/conversations/entities/Contact.java index dfd6c059..b1ebe662 100644 --- a/src/eu/siacs/conversations/entities/Contact.java +++ b/src/eu/siacs/conversations/entities/Contact.java @@ -156,6 +156,7 @@ public class Contact implements ListItem { public void clearPresences() { this.presences.clearPresences(); + this.resetOption(Options.PENDING_SUBSCRIPTION_REQUEST); } public int getMostAvailableStatus() { diff --git a/src/eu/siacs/conversations/entities/Conversation.java b/src/eu/siacs/conversations/entities/Conversation.java index 8395449d..b4c99dc1 100644 --- a/src/eu/siacs/conversations/entities/Conversation.java +++ b/src/eu/siacs/conversations/entities/Conversation.java @@ -4,6 +4,9 @@ import java.security.interfaces.DSAPublicKey; import java.util.List; import java.util.concurrent.CopyOnWriteArrayList; +import org.json.JSONException; +import org.json.JSONObject; + import eu.siacs.conversations.services.XmppConnectionService; import eu.siacs.conversations.utils.UIHelper; @@ -36,6 +39,11 @@ public class Conversation extends AbstractEntity { public static final String STATUS = "status"; public static final String CREATED = "created"; public static final String MODE = "mode"; + public static final String ATTRIBUTES = "attributes"; + + public static final String ATTRIBUTE_NEXT_ENCRYPTION = "next_encryption"; + public static final String ATTRIBUTE_MUC_PASSWORD = "muc_password"; + public static final String ATTRIBUTE_MUTED_TILL = "muted_till"; private String name; private String contactUuid; @@ -45,7 +53,7 @@ public class Conversation extends AbstractEntity { private long created; private int mode; - private long mutedTill = 0; + private JSONObject attributes = new JSONObject(); private String nextPresence; @@ -56,12 +64,11 @@ public class Conversation extends AbstractEntity { private transient String otrFingerprint = null; - private int nextMessageEncryption = -1; private String nextMessage; private transient MucOptions mucOptions = null; - private transient String latestMarkableMessageId; + //private transient String latestMarkableMessageId; private byte[] symmetricKey; @@ -73,13 +80,13 @@ public class Conversation extends AbstractEntity { int mode) { this(java.util.UUID.randomUUID().toString(), name, null, account .getUuid(), contactJid, System.currentTimeMillis(), - STATUS_AVAILABLE, mode); + STATUS_AVAILABLE, mode, ""); this.account = account; } public Conversation(String uuid, String name, String contactUuid, String accountUuid, String contactJid, long created, int status, - int mode) { + int mode, String attributes) { this.uuid = uuid; this.name = name; this.contactUuid = contactUuid; @@ -88,6 +95,14 @@ public class Conversation extends AbstractEntity { this.created = created; this.status = status; this.mode = mode; + try { + if (attributes == null) { + attributes = new String(); + } + this.attributes = new JSONObject(attributes); + } catch (JSONException e) { + this.attributes = new JSONObject(); + } } public List getMessages() { @@ -123,10 +138,20 @@ public class Conversation extends AbstractEntity { } } - public String popLatestMarkableMessageId() { - String id = this.latestMarkableMessageId; - this.latestMarkableMessageId = null; - return id; + public String getLatestMarkableMessageId() { + if (this.messages == null) { + return null; + } + for(int i = this.messages.size() - 1; i >= 0; --i) { + if (this.messages.get(i).getStatus() <= Message.STATUS_RECEIVED && this.messages.get(i).markable) { + if (this.messages.get(i).isRead()) { + return null; + } else { + return this.messages.get(i).getRemoteMsgId(); + } + } + } + return null; } public Message getLatestMessage() { @@ -198,6 +223,7 @@ public class Conversation extends AbstractEntity { values.put(CREATED, created); values.put(STATUS, status); values.put(MODE, mode); + values.put(ATTRIBUTES, attributes.toString()); return values; } @@ -209,7 +235,8 @@ public class Conversation extends AbstractEntity { cursor.getString(cursor.getColumnIndex(CONTACTJID)), cursor.getLong(cursor.getColumnIndex(CREATED)), cursor.getInt(cursor.getColumnIndex(STATUS)), - cursor.getInt(cursor.getColumnIndex(MODE))); + cursor.getInt(cursor.getColumnIndex(MODE)), + cursor.getString(cursor.getColumnIndex(ATTRIBUTES))); } public void setStatus(int status) { @@ -229,8 +256,8 @@ public class Conversation extends AbstractEntity { if (this.otrSession != null) { return this.otrSession; } else { - SessionID sessionId = new SessionID( - this.getContactJid().split("/",2)[0], presence, "xmpp"); + SessionID sessionId = new SessionID(this.getContactJid().split("/", + 2)[0], presence, "xmpp"); this.otrSession = new SessionImpl(sessionId, getAccount() .getOtrEngine(service)); try { @@ -345,7 +372,8 @@ public class Conversation extends AbstractEntity { } public int getNextEncryption(boolean force) { - if (this.nextMessageEncryption == -1) { + int next = this.getIntAttribute(ATTRIBUTE_NEXT_ENCRYPTION, -1); + if (next == -1) { int latest = this.getLatestEncryption(); if (latest == Message.ENCRYPTION_NONE) { if (force && getMode() == MODE_SINGLE) { @@ -363,16 +391,16 @@ public class Conversation extends AbstractEntity { return latest; } } - if (this.nextMessageEncryption == Message.ENCRYPTION_NONE && force + if (next == Message.ENCRYPTION_NONE && force && getMode() == MODE_SINGLE) { return Message.ENCRYPTION_OTR; } else { - return this.nextMessageEncryption; + return next; } } public void setNextEncryption(int encryption) { - this.nextMessageEncryption = encryption; + this.setAttribute(ATTRIBUTE_NEXT_ENCRYPTION, String.valueOf(encryption)); } public String getNextMessage() { @@ -387,12 +415,6 @@ public class Conversation extends AbstractEntity { this.nextMessage = message; } - public void setLatestMarkableMessageId(String id) { - if (id != null) { - this.latestMarkableMessageId = id; - } - } - public void setSymmetricKey(byte[] key) { this.symmetricKey = key; } @@ -433,11 +455,55 @@ public class Conversation extends AbstractEntity { return false; } - public void setMutedTill(long mutedTill) { - this.mutedTill = mutedTill; + public void setMutedTill(long value) { + this.setAttribute(ATTRIBUTE_MUTED_TILL, String.valueOf(value)); } public boolean isMuted() { - return SystemClock.elapsedRealtime() < this.mutedTill; + return SystemClock.elapsedRealtime() < this.getLongAttribute( + ATTRIBUTE_MUTED_TILL, 0); + } + + public boolean setAttribute(String key, String value) { + try { + this.attributes.put(key, value); + return true; + } catch (JSONException e) { + return false; + } + } + + public String getAttribute(String key) { + try { + return this.attributes.getString(key); + } catch (JSONException e) { + return null; + } + } + + public int getIntAttribute(String key, int defaultValue) { + String value = this.getAttribute(key); + if (value == null) { + return defaultValue; + } else { + try { + return Integer.parseInt(value); + } catch (NumberFormatException e) { + return defaultValue; + } + } + } + + public long getLongAttribute(String key, long defaultValue) { + String value = this.getAttribute(key); + if (value == null) { + return defaultValue; + } else { + try { + return Long.parseLong(value); + } catch (NumberFormatException e) { + return defaultValue; + } + } } } diff --git a/src/eu/siacs/conversations/entities/Message.java b/src/eu/siacs/conversations/entities/Message.java index 8f9885c5..49482bbc 100644 --- a/src/eu/siacs/conversations/entities/Message.java +++ b/src/eu/siacs/conversations/entities/Message.java @@ -57,9 +57,9 @@ public class Message extends AbstractEntity { protected boolean read = true; protected String remoteMsgId = null; - protected transient Conversation conversation = null; - - protected transient Downloadable downloadable = null; + protected Conversation conversation = null; + protected Downloadable downloadable = null; + public boolean markable = false; private Message() { diff --git a/src/eu/siacs/conversations/entities/MucOptions.java b/src/eu/siacs/conversations/entities/MucOptions.java index 676fb4f4..12ea4e93 100644 --- a/src/eu/siacs/conversations/entities/MucOptions.java +++ b/src/eu/siacs/conversations/entities/MucOptions.java @@ -15,6 +15,13 @@ public class MucOptions { public static final int ERROR_NICK_IN_USE = 1; public static final int ERROR_ROOM_NOT_FOUND = 2; public static final int ERROR_PASSWORD_REQUIRED = 3; + public static final int ERROR_BANNED = 4; + public static final int ERROR_MEMBERS_ONLY = 5; + + public static final int KICKED_FROM_ROOM = 9; + + public static final String STATUS_CODE_BANNED = "301"; + public static final String STATUS_CODE_KICKED = "307"; public interface OnRenameListener { public void onRename(boolean success); @@ -108,7 +115,6 @@ public class MucOptions { private String subject = null; private String joinnick; private String password = null; - private boolean passwordChanged = false; public MucOptions(Account account) { this.account = account; @@ -134,7 +140,7 @@ public class MucOptions { } public void processPacket(PresencePacket packet, PgpEngine pgp) { - String[] fromParts = packet.getFrom().split("/",2); + String[] fromParts = packet.getFrom().split("/", 2); if (fromParts.length >= 2) { String name = fromParts[1]; String type = packet.getAttribute("type"); @@ -158,10 +164,6 @@ public class MucOptions { } aboutToRename = false; } - if (conversation.getBookmark() != null - && conversation.getBookmark().isProvidePassword()) { - this.passwordChanged = false; - } } else { addUser(user); } @@ -179,11 +181,27 @@ public class MucOptions { x.getContent())); } } + } else if (type.equals("unavailable") && name.equals(this.joinnick)) { + Element x = packet.findChild("x", + "http://jabber.org/protocol/muc#user"); + if (x != null) { + Element status = x.findChild("status"); + if (status != null) { + String code = status.getAttribute("code"); + if (STATUS_CODE_KICKED.equals(code)) { + this.isOnline = false; + this.error = KICKED_FROM_ROOM; + } else if (STATUS_CODE_BANNED.equals(code)) { + this.isOnline = false; + this.error = ERROR_BANNED; + } + } + } } else if (type.equals("unavailable")) { - deleteUser(packet.getAttribute("from").split("/",2)[1]); + deleteUser(packet.getAttribute("from").split("/", 2)[1]); } else if (type.equals("error")) { Element error = packet.findChild("error"); - if (error.hasChild("conflict")) { + if (error != null && error.hasChild("conflict")) { if (aboutToRename) { if (renameListener != null) { renameListener.onRename(false); @@ -193,12 +211,13 @@ public class MucOptions { } else { this.error = ERROR_NICK_IN_USE; } - } else if (error.hasChild("not-authorized")) { - if (conversation.getBookmark() != null - && conversation.getBookmark().isProvidePassword()) { - this.passwordChanged = true; - } + } else if (error != null && error.hasChild("not-authorized")) { this.error = ERROR_PASSWORD_REQUIRED; + } else if (error != null && error.hasChild("forbidden")) { + this.error = ERROR_BANNED; + } else if (error != null + && error.hasChild("registration-required")) { + this.error = ERROR_MEMBERS_ONLY; } } } @@ -209,7 +228,7 @@ public class MucOptions { } public String getProposedNick() { - String[] mucParts = conversation.getContactJid().split("/",2); + String[] mucParts = conversation.getContactJid().split("/", 2); if (conversation.getBookmark() != null && conversation.getBookmark().getNick() != null) { return conversation.getBookmark().getNick(); @@ -309,7 +328,7 @@ public class MucOptions { } public String getJoinJid() { - return this.conversation.getContactJid().split("/",2)[0] + "/" + return this.conversation.getContactJid().split("/", 2)[0] + "/" + this.joinnick; } @@ -323,7 +342,9 @@ public class MucOptions { } public String getPassword() { - if (conversation.getBookmark() != null + this.password = conversation + .getAttribute(Conversation.ATTRIBUTE_MUC_PASSWORD); + if (this.password == null && conversation.getBookmark() != null && conversation.getBookmark().getPassword() != null) { return conversation.getBookmark().getPassword(); } else { @@ -332,16 +353,12 @@ public class MucOptions { } public void setPassword(String password) { - if (conversation.getBookmark() != null - && conversation.getBookmark().isProvidePassword()) { + if (conversation.getBookmark() != null) { conversation.getBookmark().setPassword(password); } else { this.password = password; } + conversation + .setAttribute(Conversation.ATTRIBUTE_MUC_PASSWORD, password); } - - public boolean isPasswordChanged() { - return this.passwordChanged; - } - } \ No newline at end of file diff --git a/src/eu/siacs/conversations/entities/Roster.java b/src/eu/siacs/conversations/entities/Roster.java index f11f0250..b6908793 100644 --- a/src/eu/siacs/conversations/entities/Roster.java +++ b/src/eu/siacs/conversations/entities/Roster.java @@ -14,13 +14,18 @@ public class Roster { this.account = account; } - public boolean hasContact(String jid) { - String cleanJid = jid.split("/",2)[0]; - return contacts.containsKey(cleanJid); + public Contact getContactAsShownInRoster(String jid) { + String cleanJid = jid.split("/", 2)[0]; + Contact contact = contacts.get(cleanJid); + if (contact != null && contact.showInRoster()) { + return contact; + } else { + return null; + } } public Contact getContact(String jid) { - String cleanJid = jid.split("/",2)[0].toLowerCase(Locale.getDefault()); + String cleanJid = jid.split("/", 2)[0].toLowerCase(Locale.getDefault()); if (contacts.containsKey(cleanJid)) { return contacts.get(cleanJid); } else { diff --git a/src/eu/siacs/conversations/generator/AbstractGenerator.java b/src/eu/siacs/conversations/generator/AbstractGenerator.java index 61f290e4..c96d116d 100644 --- a/src/eu/siacs/conversations/generator/AbstractGenerator.java +++ b/src/eu/siacs/conversations/generator/AbstractGenerator.java @@ -21,9 +21,9 @@ public abstract class AbstractGenerator { "urn:xmpp:avatar:metadata+notify" }; public final String IDENTITY_NAME = "Conversations 0.7"; public final String IDENTITY_TYPE = "phone"; - + protected XmppConnectionService mXmppConnectionService; - + protected AbstractGenerator(XmppConnectionService service) { this.mXmppConnectionService = service; } diff --git a/src/eu/siacs/conversations/generator/MessageGenerator.java b/src/eu/siacs/conversations/generator/MessageGenerator.java index d4cab3ed..dd833e56 100644 --- a/src/eu/siacs/conversations/generator/MessageGenerator.java +++ b/src/eu/siacs/conversations/generator/MessageGenerator.java @@ -34,7 +34,7 @@ public class MessageGenerator extends AbstractGenerator { packet.setTo(message.getCounterpart()); packet.setType(MessagePacket.TYPE_CHAT); } else { - packet.setTo(message.getCounterpart().split("/",2)[0]); + packet.setTo(message.getCounterpart().split("/", 2)[0]); packet.setType(MessagePacket.TYPE_GROUPCHAT); } packet.setFrom(account.getFullJid()); @@ -134,7 +134,7 @@ public class MessageGenerator extends AbstractGenerator { String subject) { MessagePacket packet = new MessagePacket(); packet.setType(MessagePacket.TYPE_GROUPCHAT); - packet.setTo(conversation.getContactJid().split("/",2)[0]); + packet.setTo(conversation.getContactJid().split("/", 2)[0]); Element subjectChild = new Element("subject"); subjectChild.setContent(subject); packet.addChild(subjectChild); @@ -148,13 +148,13 @@ public class MessageGenerator extends AbstractGenerator { packet.setTo(contact); packet.setFrom(conversation.getAccount().getFullJid()); Element x = packet.addChild("x", "jabber:x:conference"); - x.setAttribute("jid", conversation.getContactJid().split("/",2)[0]); + x.setAttribute("jid", conversation.getContactJid().split("/", 2)[0]); return packet; } public MessagePacket invite(Conversation conversation, String contact) { MessagePacket packet = new MessagePacket(); - packet.setTo(conversation.getContactJid().split("/",2)[0]); + packet.setTo(conversation.getContactJid().split("/", 2)[0]); packet.setFrom(conversation.getAccount().getFullJid()); Element x = new Element("x"); x.setAttribute("xmlns", "http://jabber.org/protocol/muc#user"); diff --git a/src/eu/siacs/conversations/parser/AbstractParser.java b/src/eu/siacs/conversations/parser/AbstractParser.java index efbf5aef..5541c1c6 100644 --- a/src/eu/siacs/conversations/parser/AbstractParser.java +++ b/src/eu/siacs/conversations/parser/AbstractParser.java @@ -60,7 +60,7 @@ public abstract class AbstractParser { protected void updateLastseen(Element packet, Account account, boolean presenceOverwrite) { - String[] fromParts = packet.getAttribute("from").split("/",2); + String[] fromParts = packet.getAttribute("from").split("/", 2); String from = fromParts[0]; String presence = null; if (fromParts.length >= 2) { diff --git a/src/eu/siacs/conversations/parser/IqParser.java b/src/eu/siacs/conversations/parser/IqParser.java index 592b77a4..df6754f2 100644 --- a/src/eu/siacs/conversations/parser/IqParser.java +++ b/src/eu/siacs/conversations/parser/IqParser.java @@ -73,6 +73,9 @@ public class IqParser extends AbstractParser implements OnIqPacketReceived { IqPacket response = mXmppConnectionService.getIqGenerator() .discoResponse(packet); account.getXmppConnection().sendIqPacket(response, null); + } else if (packet.hasChild("ping", "urn:xmpp:ping")) { + IqPacket response = packet.generateRespone(IqPacket.TYPE_RESULT); + mXmppConnectionService.sendIqPacket(account, response, null); } else { if ((packet.getType() == IqPacket.TYPE_GET) || (packet.getType() == IqPacket.TYPE_SET)) { diff --git a/src/eu/siacs/conversations/parser/MessageParser.java b/src/eu/siacs/conversations/parser/MessageParser.java index 1c77d10d..f8329037 100644 --- a/src/eu/siacs/conversations/parser/MessageParser.java +++ b/src/eu/siacs/conversations/parser/MessageParser.java @@ -1,13 +1,12 @@ package eu.siacs.conversations.parser; -import android.os.SystemClock; import net.java.otr4j.session.Session; import net.java.otr4j.session.SessionStatus; -import eu.siacs.conversations.Config; import eu.siacs.conversations.entities.Account; import eu.siacs.conversations.entities.Contact; import eu.siacs.conversations.entities.Conversation; import eu.siacs.conversations.entities.Message; +import eu.siacs.conversations.services.NotificationService; import eu.siacs.conversations.services.XmppConnectionService; import eu.siacs.conversations.utils.CryptoHelper; import eu.siacs.conversations.xml.Element; @@ -17,9 +16,6 @@ import eu.siacs.conversations.xmpp.stanzas.MessagePacket; public class MessageParser extends AbstractParser implements OnMessagePacketReceived { - - private long lastCarbonMessageReceived = -(Config.CARBON_GRACE_PERIOD * 1000); - public MessageParser(XmppConnectionService service) { super(service); } @@ -28,7 +24,6 @@ public class MessageParser extends AbstractParser implements String[] fromParts = packet.getFrom().split("/", 2); Conversation conversation = mXmppConnectionService .findOrCreateConversation(account, fromParts[0], false); - conversation.setLatestMarkableMessageId(getMarkableMessageId(packet)); updateLastseen(packet, account, true); String pgpBody = getPgpBody(packet); Message finishedMessage; @@ -41,6 +36,7 @@ public class MessageParser extends AbstractParser implements Message.STATUS_RECEIVED); } finishedMessage.setRemoteMsgId(packet.getId()); + finishedMessage.markable = isMarkable(packet); if (conversation.getMode() == Conversation.MODE_MULTI && fromParts.length >= 2) { finishedMessage.setType(Message.TYPE_PRIVATE); @@ -71,7 +67,7 @@ public class MessageParser extends AbstractParser implements updateLastseen(packet, account, true); String body = packet.getBody(); if (body.matches("^\\?OTRv\\d*\\?")) { - conversation.resetOtrSession(); + conversation.endOtrIfNeeded(); } if (!conversation.hasValidOtrSession()) { if (properlyAddressed) { @@ -112,13 +108,12 @@ public class MessageParser extends AbstractParser implements conversation.setSymmetricKey(CryptoHelper.hexToBytes(key)); return null; } - conversation - .setLatestMarkableMessageId(getMarkableMessageId(packet)); Message finishedMessage = new Message(conversation, packet.getFrom(), body, Message.ENCRYPTION_OTR, Message.STATUS_RECEIVED); finishedMessage.setTime(getTimestamp(packet)); finishedMessage.setRemoteMsgId(packet.getId()); + finishedMessage.markable = isMarkable(packet); return finishedMessage; } catch (Exception e) { String receivedId = packet.getId(); @@ -160,7 +155,6 @@ public class MessageParser extends AbstractParser implements status = Message.STATUS_RECEIVED; } String pgpBody = getPgpBody(packet); - conversation.setLatestMarkableMessageId(getMarkableMessageId(packet)); Message finishedMessage; if (pgpBody == null) { finishedMessage = new Message(conversation, counterPart, @@ -170,6 +164,7 @@ public class MessageParser extends AbstractParser implements Message.ENCRYPTION_PGP, status); } finishedMessage.setRemoteMsgId(packet.getId()); + finishedMessage.markable = isMarkable(packet); if (status == Message.STATUS_RECEIVED) { finishedMessage.setTrueCounterpart(conversation.getMucOptions() .getTrueCounterpart(counterPart)); @@ -201,10 +196,24 @@ public class MessageParser extends AbstractParser implements return null; } Element message = forwarded.findChild("message"); - if ((message == null) || (!message.hasChild("body"))) { + if (message == null) { + return null; + } + if (!message.hasChild("body")) { if (status == Message.STATUS_RECEIVED && message.getAttribute("from") != null) { parseNonMessage(message, account); + } else if (status == Message.STATUS_SEND + && message.hasChild("displayed", "urn:xmpp:chat-markers:0")) { + String to = message.getAttribute("to"); + if (to != null) { + Conversation conversation = mXmppConnectionService.find( + mXmppConnectionService.getConversations(), account, + to.split("/")[0]); + if (conversation != null) { + mXmppConnectionService.markRead(conversation, false); + } + } } return null; } @@ -224,8 +233,6 @@ public class MessageParser extends AbstractParser implements String[] parts = fullJid.split("/", 2); Conversation conversation = mXmppConnectionService .findOrCreateConversation(account, parts[0], false); - conversation.setLatestMarkableMessageId(getMarkableMessageId(packet)); - String pgpBody = getPgpBody(message); Message finishedMessage; if (pgpBody != null) { @@ -238,6 +245,7 @@ public class MessageParser extends AbstractParser implements } finishedMessage.setTime(getTimestamp(message)); finishedMessage.setRemoteMsgId(message.getAttribute("id")); + finishedMessage.markable = isMarkable(message); if (conversation.getMode() == Conversation.MODE_MULTI && parts.length >= 2) { finishedMessage.setType(Message.TYPE_PRIVATE); @@ -298,6 +306,8 @@ public class MessageParser extends AbstractParser implements Element password = x.findChild("password"); conversation.getMucOptions().setPassword( password.getContent()); + mXmppConnectionService.databaseBackend + .updateConversation(conversation); } mXmppConnectionService.joinMuc(conversation); mXmppConnectionService.updateConversationUi(); @@ -313,6 +323,8 @@ public class MessageParser extends AbstractParser implements if (!conversation.getMucOptions().online()) { if (password != null) { conversation.getMucOptions().setPassword(password); + mXmppConnectionService.databaseBackend + .updateConversation(conversation); } mXmppConnectionService.joinMuc(conversation); mXmppConnectionService.updateConversationUi(); @@ -371,22 +383,18 @@ public class MessageParser extends AbstractParser implements } } - private String getMarkableMessageId(Element message) { - if (message.hasChild("markable", "urn:xmpp:chat-markers:0")) { - return message.getAttribute("id"); - } else { - return null; - } + private boolean isMarkable(Element message) { + return message.hasChild("markable", "urn:xmpp:chat-markers:0"); } @Override public void onMessagePacketReceived(Account account, MessagePacket packet) { Message message = null; - boolean notify = true; - if (mXmppConnectionService.getPreferences().getBoolean( - "notification_grace_period_after_carbon_received", true)) { - notify = (SystemClock.elapsedRealtime() - lastCarbonMessageReceived) > (Config.CARBON_GRACE_PERIOD * 1000); - } + boolean notify = mXmppConnectionService.getPreferences().getBoolean( + "show_notification", true); + boolean alwaysNotifyInConference = notify + && mXmppConnectionService.getPreferences().getBoolean( + "always_notify_in_conference", false); this.parseNick(packet, account); @@ -397,7 +405,9 @@ public class MessageParser extends AbstractParser implements if (message != null) { message.markUnread(); } - } else if (packet.hasChild("body")) { + } else if (packet.hasChild("body") + && !(packet.hasChild("x", + "http://jabber.org/protocol/muc#user"))) { message = this.parseChat(packet, account); if (message != null) { message.markUnread(); @@ -407,10 +417,11 @@ public class MessageParser extends AbstractParser implements message = this.parseCarbonMessage(packet, account); if (message != null) { if (message.getStatus() == Message.STATUS_SEND) { - lastCarbonMessageReceived = SystemClock - .elapsedRealtime(); + mXmppConnectionService.getNotificationService() + .activateGracePeriod(); notify = false; - message.getConversation().markRead(); + mXmppConnectionService.markRead( + message.getConversation(), false); } else { message.markUnread(); } @@ -423,9 +434,14 @@ public class MessageParser extends AbstractParser implements if (message != null) { if (message.getStatus() == Message.STATUS_RECEIVED) { message.markUnread(); + notify = alwaysNotifyInConference + || NotificationService + .wasHighlightedOrPrivate(message); } else { - message.getConversation().markRead(); - lastCarbonMessageReceived = SystemClock.elapsedRealtime(); + mXmppConnectionService.markRead(message.getConversation(), + false); + mXmppConnectionService.getNotificationService() + .activateGracePeriod(); notify = false; } } @@ -463,7 +479,10 @@ public class MessageParser extends AbstractParser implements } } notify = notify && !conversation.isMuted(); - mXmppConnectionService.notifyUi(conversation, notify); + if (notify) { + mXmppConnectionService.getNotificationService().push(message); + } + mXmppConnectionService.updateConversationUi(); } private void parseHeadline(MessagePacket packet, Account account) { diff --git a/src/eu/siacs/conversations/parser/PresenceParser.java b/src/eu/siacs/conversations/parser/PresenceParser.java index e240a858..2c3a7dbc 100644 --- a/src/eu/siacs/conversations/parser/PresenceParser.java +++ b/src/eu/siacs/conversations/parser/PresenceParser.java @@ -22,7 +22,7 @@ public class PresenceParser extends AbstractParser implements PgpEngine mPgpEngine = mXmppConnectionService.getPgpEngine(); if (packet.hasChild("x", "http://jabber.org/protocol/muc#user")) { Conversation muc = mXmppConnectionService.find(account, packet - .getAttribute("from").split("/",2)[0]); + .getAttribute("from").split("/", 2)[0]); if (muc != null) { boolean before = muc.getMucOptions().online(); muc.getMucOptions().processPacket(packet, mPgpEngine); @@ -32,7 +32,7 @@ public class PresenceParser extends AbstractParser implements } } else if (packet.hasChild("x", "http://jabber.org/protocol/muc")) { Conversation muc = mXmppConnectionService.find(account, packet - .getAttribute("from").split("/",2)[0]); + .getAttribute("from").split("/", 2)[0]); if (muc != null) { boolean before = muc.getMucOptions().online(); muc.getMucOptions().processPacket(packet, mPgpEngine); @@ -58,6 +58,8 @@ public class PresenceParser extends AbstractParser implements Presences.parseShow(packet.findChild("show"))); } else if (type.equals("unavailable")) { account.removePresence(fromParts[1]); + mXmppConnectionService.getNotificationService() + .deactivateGracePeriod(); } } } else { diff --git a/src/eu/siacs/conversations/persistance/DatabaseBackend.java b/src/eu/siacs/conversations/persistance/DatabaseBackend.java index 51fd79e5..0991dd2d 100644 --- a/src/eu/siacs/conversations/persistance/DatabaseBackend.java +++ b/src/eu/siacs/conversations/persistance/DatabaseBackend.java @@ -19,7 +19,7 @@ public class DatabaseBackend extends SQLiteOpenHelper { private static DatabaseBackend instance = null; private static final String DATABASE_NAME = "history"; - private static final int DATABASE_VERSION = 7; + private static final int DATABASE_VERSION = 8; private static String CREATE_CONTATCS_STATEMENT = "create table " + Contact.TABLENAME + "(" + Contact.ACCOUNT + " TEXT, " @@ -50,10 +50,10 @@ public class DatabaseBackend extends SQLiteOpenHelper { + " TEXT, " + Conversation.CONTACT + " TEXT, " + Conversation.ACCOUNT + " TEXT, " + Conversation.CONTACTJID + " TEXT, " + Conversation.CREATED + " NUMBER, " - + Conversation.STATUS + " NUMBER," + Conversation.MODE - + " NUMBER," + "FOREIGN KEY(" + Conversation.ACCOUNT - + ") REFERENCES " + Account.TABLENAME + "(" + Account.UUID - + ") ON DELETE CASCADE);"); + + Conversation.STATUS + " NUMBER, " + Conversation.MODE + + " NUMBER, " + Conversation.ATTRIBUTES + " TEXT, FOREIGN KEY(" + + Conversation.ACCOUNT + ") REFERENCES " + Account.TABLENAME + + "(" + Account.UUID + ") ON DELETE CASCADE);"); db.execSQL("create table " + Message.TABLENAME + "( " + Message.UUID + " TEXT PRIMARY KEY, " + Message.CONVERSATION + " TEXT, " + Message.TIME_SENT + " NUMBER, " + Message.COUNTERPART @@ -96,6 +96,10 @@ public class DatabaseBackend extends SQLiteOpenHelper { db.execSQL("ALTER TABLE " + Account.TABLENAME + " ADD COLUMN " + Account.AVATAR + " TEXT"); } + if (oldVersion < 8 && newVersion >= 8) { + db.execSQL("ALTER TABLE " + Conversation.TABLENAME + " ADD COLUMN " + + Conversation.ATTRIBUTES + " TEXT"); + } } public static synchronized DatabaseBackend getInstance(Context context) { @@ -206,6 +210,7 @@ public class DatabaseBackend extends SQLiteOpenHelper { while (cursor.moveToNext()) { list.add(Account.fromCursor(cursor)); } + cursor.close(); return list; } @@ -221,13 +226,15 @@ public class DatabaseBackend extends SQLiteOpenHelper { String[] args = { account.getUuid() }; db.delete(Account.TABLENAME, Account.UUID + "=?", args); } - + public boolean hasEnabledAccounts() { SQLiteDatabase db = this.getReadableDatabase(); - Cursor cursor= db.rawQuery("select count("+Account.UUID+") from "+Account.TABLENAME+" where not options & (1 <<1)", null); + Cursor cursor = db.rawQuery("select count(" + Account.UUID + ") from " + + Account.TABLENAME + " where not options & (1 <<1)", null); cursor.moveToFirst(); int count = cursor.getInt(0); - return (count>0); + cursor.close(); + return (count > 0); } @Override @@ -253,6 +260,7 @@ public class DatabaseBackend extends SQLiteOpenHelper { while (cursor.moveToNext()) { roster.initContact(Contact.fromCursor(cursor)); } + cursor.close(); } public void writeRoster(Roster roster) { diff --git a/src/eu/siacs/conversations/persistance/FileBackend.java b/src/eu/siacs/conversations/persistance/FileBackend.java index 2b2aa86e..d86c0ee1 100644 --- a/src/eu/siacs/conversations/persistance/FileBackend.java +++ b/src/eu/siacs/conversations/persistance/FileBackend.java @@ -250,7 +250,10 @@ public class FileBackend { if (!file.exists()) { file = getJingleFileLegacy(message); } - Bitmap fullsize = BitmapFactory.decodeFile(file.getAbsolutePath()); + BitmapFactory.Options options = new BitmapFactory.Options(); + options.inSampleSize = calcSampleSize(file, size); + Bitmap fullsize = BitmapFactory.decodeFile(file.getAbsolutePath(), + options); if (fullsize == null) { throw new FileNotFoundException(); } @@ -414,6 +417,17 @@ public class FileBackend { options.inJustDecodeBounds = true; BitmapFactory.decodeStream(context.getContentResolver() .openInputStream(image), null, options); + return calcSampleSize(options, size); + } + + private int calcSampleSize(File image, int size) { + BitmapFactory.Options options = new BitmapFactory.Options(); + options.inJustDecodeBounds = true; + BitmapFactory.decodeFile(image.getAbsolutePath(), options); + return calcSampleSize(options, size); + } + + private int calcSampleSize(BitmapFactory.Options options, int size) { int height = options.outHeight; int width = options.outWidth; int inSampleSize = 1; @@ -428,7 +442,6 @@ public class FileBackend { } } return inSampleSize; - } public Uri getJingleFileUri(Message message) { diff --git a/src/eu/siacs/conversations/services/EventReceiver.java b/src/eu/siacs/conversations/services/EventReceiver.java index e2445b2a..dfbe9db7 100644 --- a/src/eu/siacs/conversations/services/EventReceiver.java +++ b/src/eu/siacs/conversations/services/EventReceiver.java @@ -15,7 +15,8 @@ public class EventReceiver extends BroadcastReceiver { } else { mIntentForService.setAction("other"); } - if (intent.getAction().equals("ui") || DatabaseBackend.getInstance(context).hasEnabledAccounts()) { + if (intent.getAction().equals("ui") + || DatabaseBackend.getInstance(context).hasEnabledAccounts()) { context.startService(mIntentForService); } } diff --git a/src/eu/siacs/conversations/services/ImageProvider.java b/src/eu/siacs/conversations/services/ImageProvider.java index af8ab4b2..ac78a454 100644 --- a/src/eu/siacs/conversations/services/ImageProvider.java +++ b/src/eu/siacs/conversations/services/ImageProvider.java @@ -31,7 +31,7 @@ public class ImageProvider extends ContentProvider { if (uuids == null) { throw new FileNotFoundException(); } - String[] uuidsSplited = uuids.split("/",2); + String[] uuidsSplited = uuids.split("/", 2); if (uuidsSplited.length != 3) { throw new FileNotFoundException(); } diff --git a/src/eu/siacs/conversations/services/NotificationService.java b/src/eu/siacs/conversations/services/NotificationService.java new file mode 100644 index 00000000..41656707 --- /dev/null +++ b/src/eu/siacs/conversations/services/NotificationService.java @@ -0,0 +1,241 @@ +package eu.siacs.conversations.services; + +import java.util.ArrayList; +import java.util.LinkedHashMap; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +import android.app.Notification; +import android.app.NotificationManager; +import android.app.PendingIntent; +import android.content.Context; +import android.content.Intent; +import android.content.SharedPreferences; +import android.net.Uri; +import android.os.PowerManager; +import android.os.SystemClock; +import android.support.v4.app.NotificationCompat; +import android.support.v4.app.TaskStackBuilder; +import android.text.Html; + +import eu.siacs.conversations.Config; +import eu.siacs.conversations.R; +import eu.siacs.conversations.entities.Conversation; +import eu.siacs.conversations.entities.Message; +import eu.siacs.conversations.ui.ConversationActivity; + +public class NotificationService { + + private XmppConnectionService mXmppConnectionService; + private NotificationManager mNotificationManager; + + private LinkedHashMap> notifications = new LinkedHashMap>(); + + public int NOTIFICATION_ID = 0x2342; + private Conversation mOpenConversation; + private boolean mIsInForeground; + + private long mEndGracePeriod = 0L; + + public NotificationService(XmppConnectionService service) { + this.mXmppConnectionService = service; + this.mNotificationManager = (NotificationManager) service + .getSystemService(Context.NOTIFICATION_SERVICE); + } + + public synchronized void push(Message message) { + + PowerManager pm = (PowerManager) mXmppConnectionService + .getSystemService(Context.POWER_SERVICE); + boolean isScreenOn = pm.isScreenOn(); + if (this.mIsInForeground && isScreenOn + && this.mOpenConversation == message.getConversation()) { + return; + } + String conversationUuid = message.getConversationUuid(); + if (notifications.containsKey(conversationUuid)) { + notifications.get(conversationUuid).add(message); + } else { + ArrayList mList = new ArrayList(); + mList.add(message); + notifications.put(conversationUuid, mList); + } + updateNotification((!(this.mIsInForeground && this.mOpenConversation == null) || !isScreenOn) + && !inGracePeriod()); + } + + public void clear() { + notifications.clear(); + updateNotification(false); + } + + public void clear(Conversation conversation) { + notifications.remove(conversation.getUuid()); + updateNotification(false); + } + + private void updateNotification(boolean notify) { + SharedPreferences preferences = mXmppConnectionService.getPreferences(); + + String ringtone = preferences.getString("notification_ringtone", null); + boolean vibrate = preferences.getBoolean("vibrate_on_notification", + true); + + if (notifications.size() == 0) { + mNotificationManager.cancel(NOTIFICATION_ID); + } else { + NotificationCompat.Builder mBuilder = new NotificationCompat.Builder( + mXmppConnectionService); + mBuilder.setSmallIcon(R.drawable.ic_notification); + if (notifications.size() == 1) { + ArrayList messages = notifications.values().iterator() + .next(); + if (messages.size() >= 1) { + Conversation conversation = messages.get(0) + .getConversation(); + mBuilder.setLargeIcon(conversation.getImage( + mXmppConnectionService, 64)); + mBuilder.setContentTitle(conversation.getName()); + StringBuilder text = new StringBuilder(); + for (int i = 0; i < messages.size(); ++i) { + text.append(messages.get(i).getReadableBody( + mXmppConnectionService)); + if (i != messages.size() - 1) { + text.append("\n"); + } + } + mBuilder.setStyle(new NotificationCompat.BigTextStyle() + .bigText(text.toString())); + mBuilder.setContentText(messages.get(0).getReadableBody( + mXmppConnectionService)); + if (notify) { + mBuilder.setTicker(messages.get(messages.size() - 1) + .getReadableBody(mXmppConnectionService)); + } + mBuilder.setContentIntent(createContentIntent(conversation + .getUuid())); + } else { + mNotificationManager.cancel(NOTIFICATION_ID); + return; + } + } else { + NotificationCompat.InboxStyle style = new NotificationCompat.InboxStyle(); + style.setBigContentTitle(notifications.size() + + " " + + mXmppConnectionService + .getString(R.string.unread_conversations)); + StringBuilder names = new StringBuilder(); + Conversation conversation = null; + for (ArrayList messages : notifications.values()) { + if (messages.size() > 0) { + conversation = messages.get(0).getConversation(); + String name = conversation.getName(); + style.addLine(Html.fromHtml("" + + name + + " " + + messages.get(0).getReadableBody( + mXmppConnectionService))); + names.append(name); + names.append(", "); + } + } + if (names.length() >= 2) { + names.delete(names.length() - 2, names.length()); + } + mBuilder.setContentTitle(notifications.size() + + " " + + mXmppConnectionService + .getString(R.string.unread_conversations)); + mBuilder.setContentText(names.toString()); + mBuilder.setStyle(style); + if (conversation != null) { + mBuilder.setContentIntent(createContentIntent(conversation + .getUuid())); + } + } + if (notify) { + if (vibrate) { + int dat = 70; + long[] pattern = { 0, 3 * dat, dat, dat }; + mBuilder.setVibrate(pattern); + } + if (ringtone != null) { + mBuilder.setSound(Uri.parse(ringtone)); + } + } + mBuilder.setDeleteIntent(createDeleteIntent()); + if (!inGracePeriod()) { + mBuilder.setLights(0xffffffff, 2000, 4000); + } + Notification notification = mBuilder.build(); + mNotificationManager.notify(NOTIFICATION_ID, notification); + } + } + + private PendingIntent createContentIntent(String conversationUuid) { + TaskStackBuilder stackBuilder = TaskStackBuilder + .create(mXmppConnectionService); + stackBuilder.addParentStack(ConversationActivity.class); + + Intent viewConversationIntent = new Intent(mXmppConnectionService, + ConversationActivity.class); + viewConversationIntent.setAction(Intent.ACTION_VIEW); + viewConversationIntent.putExtra(ConversationActivity.CONVERSATION, + conversationUuid); + viewConversationIntent.setType(ConversationActivity.VIEW_CONVERSATION); + + stackBuilder.addNextIntent(viewConversationIntent); + + PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, + PendingIntent.FLAG_UPDATE_CURRENT); + return resultPendingIntent; + } + + private PendingIntent createDeleteIntent() { + Intent intent = new Intent(mXmppConnectionService, + XmppConnectionService.class); + intent.setAction("clear_notification"); + return PendingIntent.getService(mXmppConnectionService, 0, intent, 0); + } + + public static boolean wasHighlightedOrPrivate(Message message) { + String nick = message.getConversation().getMucOptions().getActualNick(); + Pattern highlight = generateNickHighlightPattern(nick); + if (message.getBody() == null || nick == null) { + return false; + } + Matcher m = highlight.matcher(message.getBody()); + return (m.find() || message.getType() == Message.TYPE_PRIVATE); + } + + private static Pattern generateNickHighlightPattern(String nick) { + // We expect a word boundary, i.e. space or start of string, followed by + // the + // nick (matched in case-insensitive manner), followed by optional + // punctuation (for example "bob: i disagree" or "how are you alice?"), + // followed by another word boundary. + return Pattern.compile("\\b" + nick + "\\p{Punct}?\\b", + Pattern.CASE_INSENSITIVE | Pattern.UNICODE_CASE); + } + + public void setOpenConversation(Conversation conversation) { + this.mOpenConversation = conversation; + } + + public void setIsInForeground(boolean foreground) { + this.mIsInForeground = foreground; + } + + public void activateGracePeriod() { + this.mEndGracePeriod = SystemClock.elapsedRealtime() + + (Config.CARBON_GRACE_PERIOD * 1000); + } + + public void deactivateGracePeriod() { + this.mEndGracePeriod = 0L; + } + + private boolean inGracePeriod() { + return SystemClock.elapsedRealtime() < this.mEndGracePeriod; + } +} diff --git a/src/eu/siacs/conversations/services/XmppConnectionService.java b/src/eu/siacs/conversations/services/XmppConnectionService.java index db3ee2b9..e6297f4f 100644 --- a/src/eu/siacs/conversations/services/XmppConnectionService.java +++ b/src/eu/siacs/conversations/services/XmppConnectionService.java @@ -90,9 +90,12 @@ public class XmppConnectionService extends Service { public long startDate; private static String ACTION_MERGE_PHONE_CONTACTS = "merge_phone_contacts"; + public static String ACTION_CLEAR_NOTIFICATION = "clear_notification"; private MemorizingTrustManager mMemorizingTrustManager; + private NotificationService mNotificationService; + private MessageParser mMessageParser = new MessageParser(this); private PresenceParser mPresenceParser = new PresenceParser(this); private IqParser mIqParser = new IqParser(this); @@ -316,14 +319,16 @@ public class XmppConnectionService extends Service { @Override public int onStartCommand(Intent intent, int flags, int startId) { - if ((intent != null) - && (ACTION_MERGE_PHONE_CONTACTS.equals(intent.getAction()))) { - mergePhoneContactsWithRoster(); - return START_STICKY; - } else if ((intent != null) - && (Intent.ACTION_SHUTDOWN.equals(intent.getAction()))) { - logoutAndSave(); - return START_NOT_STICKY; + if (intent != null && intent.getAction() != null) { + if (intent.getAction().equals(ACTION_MERGE_PHONE_CONTACTS)) { + mergePhoneContactsWithRoster(); + return START_STICKY; + } else if (intent.getAction().equals(Intent.ACTION_SHUTDOWN)) { + logoutAndSave(); + return START_NOT_STICKY; + } else if (intent.getAction().equals(ACTION_CLEAR_NOTIFICATION)) { + mNotificationService.clear(); + } } this.wakeLock.acquire(); ConnectivityManager cm = (ConnectivityManager) getApplicationContext() @@ -401,6 +406,7 @@ public class XmppConnectionService extends Service { this.mRandom = new SecureRandom(); this.mMemorizingTrustManager = new MemorizingTrustManager( getApplicationContext()); + this.mNotificationService = new NotificationService(this); this.databaseBackend = DatabaseBackend .getInstance(getApplicationContext()); this.fileBackend = new FileBackend(getApplicationContext()); @@ -511,7 +517,8 @@ public class XmppConnectionService extends Service { MessagePacket packet = null; boolean saveInDb = true; boolean send = false; - if (account.getStatus() == Account.STATUS_ONLINE) { + if (account.getStatus() == Account.STATUS_ONLINE + && account.getXmppConnection() != null) { if (message.getType() == Message.TYPE_IMAGE) { if (message.getPresence() != null) { if (message.getEncryption() == Message.ENCRYPTION_OTR) { @@ -561,6 +568,10 @@ public class XmppConnectionService extends Service { send = true; } } + if (!account.getXmppConnection().getFeatures().sm() + && conv.getMode() != Conversation.MODE_MULTI) { + message.setStatus(Message.STATUS_SEND); + } } else { message.setStatus(Message.STATUS_WAITING); if (message.getType() == Message.TYPE_TEXT) { @@ -586,10 +597,6 @@ public class XmppConnectionService extends Service { } conv.getMessages().add(message); - if (!account.getXmppConnection().getFeatures().sm() - && conv.getMode() != Conversation.MODE_MULTI) { - message.setStatus(Message.STATUS_SEND); - } if (saveInDb) { if (message.getEncryption() == Message.ENCRYPTION_NONE || saveEncryptedMessages()) { @@ -742,7 +749,7 @@ public class XmppConnectionService extends Service { Element query = iqPacket.query("jabber:iq:private"); Element storage = query.addChild("storage", "storage:bookmarks"); for (Bookmark bookmark : account.getBookmarks()) { - storage.addChild(bookmark.toElement()); + storage.addChild(bookmark); } sendIqPacket(account, iqPacket, null); } @@ -824,7 +831,7 @@ public class XmppConnectionService extends Service { } }); } - + public int loadMoreMessages(Conversation conversation, long timestamp) { List messages = databaseBackend.getMessages(conversation, 50, timestamp); @@ -851,8 +858,9 @@ public class XmppConnectionService extends Service { public Conversation find(List haystack, Account account, String jid) { for (Conversation conversation : haystack) { - if ((conversation.getAccount().equals(account)) - && (conversation.getContactJid().split("/",2)[0].equals(jid))) { + if ((account == null || conversation.getAccount().equals(account)) + && (conversation.getContactJid().split("/", 2)[0] + .equals(jid))) { return conversation; } } @@ -901,10 +909,12 @@ public class XmppConnectionService extends Service { public void archiveConversation(Conversation conversation) { if (conversation.getMode() == Conversation.MODE_MULTI) { - Bookmark bookmark = conversation.getBookmark(); - if (bookmark != null && bookmark.autojoin()) { - bookmark.setAutojoin(false); - pushBookmarks(bookmark.getAccount()); + if (conversation.getAccount().getStatus() == Account.STATUS_ONLINE) { + Bookmark bookmark = conversation.getBookmark(); + if (bookmark != null && bookmark.autojoin()) { + bookmark.setAutojoin(false); + pushBookmarks(bookmark.getAccount()); + } } leaveMuc(conversation); } else { @@ -963,10 +973,12 @@ public class XmppConnectionService extends Service { public void setOnConversationListChangedListener( OnConversationUpdate listener) { + this.mNotificationService.deactivateGracePeriod(); if (checkListeners()) { switchToForeground(); } this.mOnConversationUpdate = listener; + this.mNotificationService.setIsInForeground(true); this.convChangedListenerCount++; } @@ -974,6 +986,7 @@ public class XmppConnectionService extends Service { this.convChangedListenerCount--; if (this.convChangedListenerCount == 0) { this.mOnConversationUpdate = null; + this.mNotificationService.setIsInForeground(false); if (checkListeners()) { switchToBackground(); } @@ -981,6 +994,7 @@ public class XmppConnectionService extends Service { } public void setOnAccountListChangedListener(OnAccountUpdate listener) { + this.mNotificationService.deactivateGracePeriod(); if (checkListeners()) { switchToForeground(); } @@ -999,6 +1013,7 @@ public class XmppConnectionService extends Service { } public void setOnRosterUpdateListener(OnRosterUpdate listener) { + this.mNotificationService.deactivateGracePeriod(); if (checkListeners()) { switchToForeground(); } @@ -1111,13 +1126,11 @@ public class XmppConnectionService extends Service { public void providePasswordForMuc(Conversation conversation, String password) { if (conversation.getMode() == Conversation.MODE_MULTI) { conversation.getMucOptions().setPassword(password); - if (conversation.getBookmark() != null - && conversation.getMucOptions().isPasswordChanged()) { - if (!conversation.getBookmark().autojoin()) { - conversation.getBookmark().setAutojoin(true); - } + if (conversation.getBookmark() != null) { + conversation.getBookmark().setAutojoin(true); pushBookmarks(conversation.getAccount()); } + databaseBackend.updateConversation(conversation); joinMuc(conversation); } } @@ -1266,7 +1279,7 @@ public class XmppConnectionService extends Service { } } } - notifyUi(conversation, false); + updateConversationUi(); } public boolean renewSymmetricKey(Conversation conversation) { @@ -1498,6 +1511,9 @@ public class XmppConnectionService extends Service { thread.start(); scheduleWakeupCall((int) (Config.CONNECT_TIMEOUT * 1.2), false); + } else { + account.getRoster().clearPresences(); + account.setXmppConnection(null); } } }).start(); @@ -1523,24 +1539,34 @@ public class XmppConnectionService extends Service { public boolean markMessage(Account account, String recipient, String uuid, int status) { - for (Conversation conversation : getConversations()) { - if (conversation.getContactJid().equals(recipient) - && conversation.getAccount().equals(account)) { - return markMessage(conversation, uuid, status); + if (uuid == null) { + return false; + } else { + for (Conversation conversation : getConversations()) { + if (conversation.getContactJid().equals(recipient) + && conversation.getAccount().equals(account)) { + return markMessage(conversation, uuid, status); + } } + return false; } - return false; } public boolean markMessage(Conversation conversation, String uuid, int status) { - for (Message message : conversation.getMessages()) { - if (message.getUuid().equals(uuid)) { - markMessage(message, status); - return true; + if (uuid == null) { + return false; + } else { + for (Message message : conversation.getMessages()) { + if (uuid.equals(message.getUuid()) + || (message.getStatus() >= Message.STATUS_SEND && uuid + .equals(message.getRemoteMsgId()))) { + markMessage(message, status); + return true; + } } + return false; } - return false; } public void markMessage(Message message, int status) { @@ -1575,15 +1601,6 @@ public class XmppConnectionService extends Service { return getPreferences().getBoolean("indicate_received", false); } - public void notifyUi(Conversation conversation, boolean notify) { - if (mOnConversationUpdate != null) { - mOnConversationUpdate.onConversationUpdate(); - } else { - UIHelper.updateNotification(getApplicationContext(), - getConversations(), conversation, notify); - } - } - public void updateConversationUi() { if (mOnConversationUpdate != null) { mOnConversationUpdate.onConversationUpdate(); @@ -1620,15 +1637,21 @@ public class XmppConnectionService extends Service { return null; } - public void markRead(Conversation conversation) { + public void markRead(Conversation conversation, boolean calledByUi) { + mNotificationService.clear(conversation); + String id = conversation.getLatestMarkableMessageId(); conversation.markRead(); - String id = conversation.popLatestMarkableMessageId(); - if (confirmMessages() && id != null) { + if (confirmMessages() && id != null && calledByUi) { + Log.d(Config.LOGTAG, conversation.getAccount().getJid() + + ": sending read marker for " + conversation.getName()); Account account = conversation.getAccount(); String to = conversation.getContactJid(); this.sendMessagePacket(conversation.getAccount(), mMessageGenerator.confirm(account, to, id)); } + if (!calledByUi) { + updateConversationUi(); + } } public void failWaitingOtrMessages(Conversation conversation) { @@ -1703,16 +1726,25 @@ public class XmppConnectionService extends Service { } public void sendMessagePacket(Account account, MessagePacket packet) { - account.getXmppConnection().sendMessagePacket(packet); + XmppConnection connection = account.getXmppConnection(); + if (connection != null) { + connection.sendMessagePacket(packet); + } } public void sendPresencePacket(Account account, PresencePacket packet) { - account.getXmppConnection().sendPresencePacket(packet); + XmppConnection connection = account.getXmppConnection(); + if (connection != null) { + connection.sendPresencePacket(packet); + } } public void sendIqPacket(Account account, IqPacket packet, OnIqPacketReceived callback) { - account.getXmppConnection().sendIqPacket(packet, callback); + XmppConnection connection = account.getXmppConnection(); + if (connection != null) { + connection.sendIqPacket(packet, callback); + } } public MessageGenerator getMessageGenerator() { @@ -1742,4 +1774,22 @@ public class XmppConnectionService extends Service { public interface OnRosterUpdate { public void onRosterUpdate(); } + + public List findContacts(String jid) { + ArrayList contacts = new ArrayList(); + for (Account account : getAccounts()) { + if (!account.isOptionSet(Account.OPTION_DISABLED)) { + Contact contact = account.getRoster() + .getContactAsShownInRoster(jid); + if (contact != null) { + contacts.add(contact); + } + } + } + return contacts; + } + + public NotificationService getNotificationService() { + return this.mNotificationService; + } } diff --git a/src/eu/siacs/conversations/ui/ConferenceDetailsActivity.java b/src/eu/siacs/conversations/ui/ConferenceDetailsActivity.java index 76c12a47..04059d52 100644 --- a/src/eu/siacs/conversations/ui/ConferenceDetailsActivity.java +++ b/src/eu/siacs/conversations/ui/ConferenceDetailsActivity.java @@ -201,7 +201,7 @@ public class ConferenceDetailsActivity extends XmppActivity { private void populateView() { mYourPhoto.setImageBitmap(conversation.getAccount().getImage(this, 48)); setTitle(conversation.getName()); - mFullJid.setText(conversation.getContactJid().split("/",2)[0]); + mFullJid.setText(conversation.getContactJid().split("/", 2)[0]); mYourNick.setText(conversation.getMucOptions().getActualNick()); mRoleAffiliaton = (TextView) findViewById(R.id.muc_role); if (conversation.getMucOptions().online()) { diff --git a/src/eu/siacs/conversations/ui/ContactDetailsActivity.java b/src/eu/siacs/conversations/ui/ContactDetailsActivity.java index 9d384c60..9926e126 100644 --- a/src/eu/siacs/conversations/ui/ContactDetailsActivity.java +++ b/src/eu/siacs/conversations/ui/ContactDetailsActivity.java @@ -39,8 +39,6 @@ import eu.siacs.conversations.utils.UIHelper; public class ContactDetailsActivity extends XmppActivity { public static final String ACTION_VIEW_CONTACT = "view_contact"; - protected ContactDetailsActivity activity = this; - private Contact contact; private String accountJid; @@ -58,8 +56,8 @@ public class ContactDetailsActivity extends XmppActivity { @Override public void onClick(DialogInterface dialog, int which) { - activity.xmppConnectionService.deleteContactOnServer(contact); - activity.finish(); + ContactDetailsActivity.this.xmppConnectionService.deleteContactOnServer(contact); + ContactDetailsActivity.this.finish(); } }; @@ -73,14 +71,14 @@ public class ContactDetailsActivity extends XmppActivity { intent.putExtra(Intents.Insert.IM_PROTOCOL, CommonDataKinds.Im.PROTOCOL_JABBER); intent.putExtra("finishActivityOnSaveCompleted", true); - activity.startActivityForResult(intent, 0); + ContactDetailsActivity.this.startActivityForResult(intent, 0); } }; private OnClickListener onBadgeClick = new OnClickListener() { @Override public void onClick(View v) { - AlertDialog.Builder builder = new AlertDialog.Builder(activity); + AlertDialog.Builder builder = new AlertDialog.Builder(ContactDetailsActivity.this); builder.setTitle(getString(R.string.action_add_phone_book)); builder.setMessage(getString(R.string.add_phone_book_text, contact.getJid())); @@ -206,7 +204,7 @@ public class ContactDetailsActivity extends XmppActivity { @Override public void onValueEdited(String value) { contact.setServerName(value); - activity.xmppConnectionService + ContactDetailsActivity.this.xmppConnectionService .pushContactToServer(contact); populateView(); } @@ -354,7 +352,7 @@ public class ContactDetailsActivity extends XmppActivity { @Override public void onClick(View v) { - PgpEngine pgp = activity.xmppConnectionService + PgpEngine pgp = ContactDetailsActivity.this.xmppConnectionService .getPgpEngine(); if (pgp != null) { PendingIntent intent = pgp.getIntentForKey(contact); diff --git a/src/eu/siacs/conversations/ui/ConversationActivity.java b/src/eu/siacs/conversations/ui/ConversationActivity.java index 89d823a1..ad1cd283 100644 --- a/src/eu/siacs/conversations/ui/ConversationActivity.java +++ b/src/eu/siacs/conversations/ui/ConversationActivity.java @@ -12,11 +12,11 @@ import eu.siacs.conversations.services.XmppConnectionService.OnConversationUpdat import eu.siacs.conversations.services.XmppConnectionService.OnRosterUpdate; import eu.siacs.conversations.ui.adapter.ConversationAdapter; import eu.siacs.conversations.utils.ExceptionHelper; -import eu.siacs.conversations.utils.UIHelper; import android.net.Uri; import android.os.Bundle; import android.os.SystemClock; import android.provider.MediaStore; +import android.annotation.SuppressLint; import android.app.ActionBar; import android.app.AlertDialog; import android.app.FragmentTransaction; @@ -59,8 +59,13 @@ public class ConversationActivity extends XmppActivity implements private static final int ATTACHMENT_CHOICE_CHOOSE_IMAGE = 0x0301; private static final int ATTACHMENT_CHOICE_TAKE_PHOTO = 0x0302; private static final int ATTACHMENT_CHOICE_RECORD_VOICE = 0x0303; + private static final String STATE_OPEN_CONVERSATION = "state_open_conversation"; + private static final String STATE_PANEL_OPEN = "state_panel_open"; - protected SlidingPaneLayout spl; + private String mOpenConverstaion = null; + private boolean mPanelOpen = true; + + private View mContentView; private List conversationList = new ArrayList(); private Conversation selectedConversation = null; @@ -69,7 +74,6 @@ public class ConversationActivity extends XmppActivity implements private boolean paneShouldBeOpen = true; private ArrayAdapter listAdapter; - protected ConversationActivity activity = this; private Toast prepareImageToast; private Uri pendingImageUri = null; @@ -90,18 +94,52 @@ public class ConversationActivity extends XmppActivity implements return this.listView; } - public SlidingPaneLayout getSlidingPaneLayout() { - return this.spl; - } - public boolean shouldPaneBeOpen() { return paneShouldBeOpen; } + public void showConversationsOverview() { + if (mContentView instanceof SlidingPaneLayout) { + SlidingPaneLayout mSlidingPaneLayout = (SlidingPaneLayout) mContentView; + mSlidingPaneLayout.openPane(); + } + } + + public void hideConversationsOverview() { + if (mContentView instanceof SlidingPaneLayout) { + SlidingPaneLayout mSlidingPaneLayout = (SlidingPaneLayout) mContentView; + mSlidingPaneLayout.closePane(); + } + } + + public boolean isConversationsOverviewHideable() { + if (mContentView instanceof SlidingPaneLayout) { + SlidingPaneLayout mSlidingPaneLayout = (SlidingPaneLayout) mContentView; + return mSlidingPaneLayout.isSlideable(); + } else { + return false; + } + } + + public boolean isConversationsOverviewVisable() { + if (mContentView instanceof SlidingPaneLayout) { + SlidingPaneLayout mSlidingPaneLayout = (SlidingPaneLayout) mContentView; + return mSlidingPaneLayout.isOpen(); + } else { + return true; + } + } + @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); + if (savedInstanceState != null) { + mOpenConverstaion = savedInstanceState.getString( + STATE_OPEN_CONVERSATION, null); + mPanelOpen = savedInstanceState.getBoolean(STATE_PANEL_OPEN, true); + } + setContentView(R.layout.fragment_conversations_overview); listView = (ListView) findViewById(R.id.list); @@ -122,63 +160,80 @@ public class ConversationActivity extends XmppActivity implements setSelectedConversation(conversationList.get(position)); swapConversationFragment(); } else { - spl.closePane(); + hideConversationsOverview(); } } }); - spl = (SlidingPaneLayout) findViewById(R.id.slidingpanelayout); - spl.setParallaxDistance(150); - spl.setShadowResource(R.drawable.es_slidingpane_shadow); - spl.setSliderFadeColor(0); - spl.setPanelSlideListener(new PanelSlideListener() { + mContentView = findViewById(R.id.content_view_spl); + if (mContentView == null) { + mContentView = findViewById(R.id.content_view_ll); + } + if (mContentView instanceof SlidingPaneLayout) { + SlidingPaneLayout mSlidingPaneLayout = (SlidingPaneLayout) mContentView; + mSlidingPaneLayout.setParallaxDistance(150); + mSlidingPaneLayout + .setShadowResource(R.drawable.es_slidingpane_shadow); + mSlidingPaneLayout.setSliderFadeColor(0); + mSlidingPaneLayout.setPanelSlideListener(new PanelSlideListener() { - @Override - public void onPanelOpened(View arg0) { - paneShouldBeOpen = true; - ActionBar ab = getActionBar(); - if (ab != null) { - ab.setDisplayHomeAsUpEnabled(false); - ab.setHomeButtonEnabled(false); - ab.setTitle(R.string.app_name); - } - invalidateOptionsMenu(); - hideKeyboard(); - } - - @Override - public void onPanelClosed(View arg0) { - paneShouldBeOpen = false; - if ((conversationList.size() > 0) - && (getSelectedConversation() != null)) { + @Override + public void onPanelOpened(View arg0) { + paneShouldBeOpen = true; ActionBar ab = getActionBar(); if (ab != null) { - ab.setDisplayHomeAsUpEnabled(true); - ab.setHomeButtonEnabled(true); - if (getSelectedConversation().getMode() == Conversation.MODE_SINGLE - || activity.useSubjectToIdentifyConference()) { - ab.setTitle(getSelectedConversation().getName()); - } else { - ab.setTitle(getSelectedConversation() - .getContactJid().split("/")[0]); - } + ab.setDisplayHomeAsUpEnabled(false); + ab.setHomeButtonEnabled(false); + ab.setTitle(R.string.app_name); } invalidateOptionsMenu(); - if (!getSelectedConversation().isRead()) { - xmppConnectionService - .markRead(getSelectedConversation()); - UIHelper.updateNotification(getApplicationContext(), - getConversationList(), null, false); - listView.invalidateViews(); + hideKeyboard(); + if (xmppConnectionServiceBound) { + xmppConnectionService.getNotificationService() + .setOpenConversation(null); } } - } - @Override - public void onPanelSlide(View arg0, float arg1) { - // TODO Auto-generated method stub + @Override + public void onPanelClosed(View arg0) { + paneShouldBeOpen = false; + if ((conversationList.size() > 0) + && (getSelectedConversation() != null)) { + openConversation(getSelectedConversation()); + if (!getSelectedConversation().isRead()) { + xmppConnectionService.markRead( + getSelectedConversation(), true); + listView.invalidateViews(); + } + } + } + @Override + public void onPanelSlide(View arg0, float arg1) { + // TODO Auto-generated method stub + + } + }); + } + } + + public void openConversation(Conversation conversation) { + ActionBar ab = getActionBar(); + if (ab != null) { + ab.setDisplayHomeAsUpEnabled(true); + ab.setHomeButtonEnabled(true); + if (getSelectedConversation().getMode() == Conversation.MODE_SINGLE + || ConversationActivity.this.useSubjectToIdentifyConference()) { + ab.setTitle(getSelectedConversation().getName()); + } else { + ab.setTitle(getSelectedConversation().getContactJid() + .split("/")[0]); } - }); + } + invalidateOptionsMenu(); + if (xmppConnectionServiceBound) { + xmppConnectionService.getNotificationService().setOpenConversation( + conversation); + } } @Override @@ -198,7 +253,8 @@ public class ConversationActivity extends XmppActivity implements .findItem(R.id.action_invite); MenuItem menuMute = (MenuItem) menu.findItem(R.id.action_mute); - if ((spl.isOpen() && (spl.isSlideable()))) { + if (isConversationsOverviewVisable() + && isConversationsOverviewHideable()) { menuArchive.setVisible(false); menuMucDetails.setVisible(false); menuContactDetails.setVisible(false); @@ -208,7 +264,7 @@ public class ConversationActivity extends XmppActivity implements menuClearHistory.setVisible(false); menuMute.setVisible(false); } else { - menuAdd.setVisible(!spl.isSlideable()); + menuAdd.setVisible(!isConversationsOverviewHideable()); if (this.getSelectedConversation() != null) { if (this.getSelectedConversation().getLatestMessage() .getEncryption() != Message.ENCRYPTION_NONE) { @@ -296,6 +352,8 @@ public class ConversationActivity extends XmppActivity implements int which) { conversation .setNextEncryption(Message.ENCRYPTION_NONE); + xmppConnectionService.databaseBackend + .updateConversation(conversation); selectPresenceToAttachFile(attachmentChoice); } }); @@ -315,7 +373,7 @@ public class ConversationActivity extends XmppActivity implements @Override public boolean onOptionsItemSelected(MenuItem item) { if (item.getItemId() == android.R.id.home) { - spl.openPane(); + showConversationsOverview(); return true; } else if (item.getItemId() == R.id.action_add) { startActivity(new Intent(this, StartConversationActivity.class)); @@ -367,7 +425,7 @@ public class ConversationActivity extends XmppActivity implements public void endConversation(Conversation conversation) { conversation.setStatus(Conversation.STATUS_ARCHIVED); paneShouldBeOpen = true; - spl.openPane(); + showConversationsOverview(); xmppConnectionService.archiveConversation(conversation); if (conversationList.size() > 0) { setSelectedConversation(conversationList.get(0)); @@ -376,6 +434,7 @@ public class ConversationActivity extends XmppActivity implements } } + @SuppressLint("InflateParams") protected void clearHistoryDialog(final Conversation conversation) { AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setTitle(getString(R.string.clear_conversation_history)); @@ -390,7 +449,7 @@ public class ConversationActivity extends XmppActivity implements @Override public void onClick(DialogInterface dialog, int which) { - activity.xmppConnectionService + ConversationActivity.this.xmppConnectionService .clearConversationHistory(conversation); if (endConversationCheckBox.isChecked()) { endConversation(conversation); @@ -399,7 +458,7 @@ public class ConversationActivity extends XmppActivity implements }); builder.create().show(); } - + protected void attachFileDialog() { View menuAttachFile = findViewById(R.id.action_attach_file); if (menuAttachFile == null) { @@ -470,6 +529,8 @@ public class ConversationActivity extends XmppActivity implements conversation.setNextEncryption(Message.ENCRYPTION_NONE); break; } + xmppConnectionService.databaseBackend + .updateConversation(conversation); fragment.updateChatMsgHint(); return true; } @@ -523,6 +584,8 @@ public class ConversationActivity extends XmppActivity implements + (durations[which] * 1000); } conversation.setMutedTill(till); + ConversationActivity.this.xmppConnectionService.databaseBackend + .updateConversation(conversation); ConversationFragment selectedFragment = (ConversationFragment) getFragmentManager() .findFragmentByTag("conversation"); if (selectedFragment != null) { @@ -550,8 +613,8 @@ public class ConversationActivity extends XmppActivity implements @Override public boolean onKeyDown(int keyCode, KeyEvent event) { if (keyCode == KeyEvent.KEYCODE_BACK) { - if (!spl.isOpen()) { - spl.openPane(); + if (!isConversationsOverviewVisable()) { + showConversationsOverview(); return false; } } @@ -599,62 +662,75 @@ public class ConversationActivity extends XmppActivity implements xmppConnectionService.removeOnConversationListChangedListener(); xmppConnectionService.removeOnAccountListChangedListener(); xmppConnectionService.removeOnRosterUpdateListener(); + xmppConnectionService.getNotificationService().setOpenConversation( + null); } super.onStop(); } + @Override + public void onSaveInstanceState(Bundle savedInstanceState) { + Conversation conversation = getSelectedConversation(); + if (conversation != null) { + savedInstanceState.putString(STATE_OPEN_CONVERSATION, + conversation.getUuid()); + } + savedInstanceState.putBoolean(STATE_PANEL_OPEN, + isConversationsOverviewVisable()); + super.onSaveInstanceState(savedInstanceState); + } + @Override void onBackendConnected() { this.registerListener(); - if (conversationList.size() == 0) { - updateConversationList(); + updateConversationList(); + + if (xmppConnectionService.getAccounts().size() == 0) { + startActivity(new Intent(this, EditAccountActivity.class)); + } else if (conversationList.size() <= 0) { + startActivity(new Intent(this, StartConversationActivity.class)); + finish(); + } else if (mOpenConverstaion != null) { + selectConversationByUuid(mOpenConverstaion); + paneShouldBeOpen = mPanelOpen; + if (paneShouldBeOpen) { + showConversationsOverview(); + } + swapConversationFragment(); + mOpenConverstaion = null; + } else if (getIntent() != null + && VIEW_CONVERSATION.equals(getIntent().getType())) { + String uuid = (String) getIntent().getExtras().get(CONVERSATION); + String text = getIntent().getExtras().getString(TEXT, null); + selectConversationByUuid(uuid); + paneShouldBeOpen = false; + swapConversationFragment().setText(text); + setIntent(null); + } else { + showConversationsOverview(); + ConversationFragment selectedFragment = (ConversationFragment) getFragmentManager() + .findFragmentByTag("conversation"); + if (selectedFragment != null) { + selectedFragment.onBackendConnected(); + } else { + pendingImageUri = null; + setSelectedConversation(conversationList.get(0)); + swapConversationFragment(); + } } - if (getSelectedConversation() != null && pendingImageUri != null) { + if (pendingImageUri != null) { attachImageToConversation(getSelectedConversation(), pendingImageUri); pendingImageUri = null; - } else { - pendingImageUri = null; } + ExceptionHelper.checkForCrash(this, this.xmppConnectionService); + } - if ((getIntent().getAction() != null) - && (getIntent().getAction().equals(Intent.ACTION_VIEW) && (!handledViewIntent))) { - if (getIntent().getType().equals( - ConversationActivity.VIEW_CONVERSATION)) { - handledViewIntent = true; - - String convToView = (String) getIntent().getExtras().get( - CONVERSATION); - - for (int i = 0; i < conversationList.size(); ++i) { - if (conversationList.get(i).getUuid().equals(convToView)) { - setSelectedConversation(conversationList.get(i)); - } - } - paneShouldBeOpen = false; - String text = getIntent().getExtras().getString(TEXT, null); - swapConversationFragment().setText(text); - } - } else { - if (xmppConnectionService.getAccounts().size() == 0) { - startActivity(new Intent(this, EditAccountActivity.class)); - } else if (conversationList.size() <= 0) { - // add no history - startActivity(new Intent(this, StartConversationActivity.class)); - finish(); - } else { - spl.openPane(); - // find currently loaded fragment - ConversationFragment selectedFragment = (ConversationFragment) getFragmentManager() - .findFragmentByTag("conversation"); - if (selectedFragment != null) { - selectedFragment.onBackendConnected(); - } else { - setSelectedConversation(conversationList.get(0)); - swapConversationFragment(); - } - ExceptionHelper.checkForCrash(this, this.xmppConnectionService); + private void selectConversationByUuid(String uuid) { + for (int i = 0; i < conversationList.size(); ++i) { + if (conversationList.get(i).getUuid().equals(uuid)) { + setSelectedConversation(conversationList.get(i)); } } } @@ -778,7 +854,7 @@ public class ConversationActivity extends XmppActivity implements @Override public void userInputRequried(PendingIntent pi, Message message) { - activity.runIntent(pi, + ConversationActivity.this.runIntent(pi, ConversationActivity.REQUEST_SEND_MESSAGE); } diff --git a/src/eu/siacs/conversations/ui/ConversationFragment.java b/src/eu/siacs/conversations/ui/ConversationFragment.java index feed9df5..cdaa7152 100644 --- a/src/eu/siacs/conversations/ui/ConversationFragment.java +++ b/src/eu/siacs/conversations/ui/ConversationFragment.java @@ -76,10 +76,11 @@ public class ConversationFragment extends Fragment { @Override public boolean onEditorAction(TextView v, int actionId, KeyEvent event) { - if (actionId == EditorInfo.IME_ACTION_DONE) { + if (actionId == EditorInfo.IME_ACTION_SEND) { InputMethodManager imm = (InputMethodManager) v.getContext() .getSystemService(Context.INPUT_METHOD_SERVICE); imm.hideSoftInputFromWindow(v.getWindowToken(), 0); + sendMessage(); return true; } else { return false; @@ -131,6 +132,14 @@ public class ConversationFragment extends Fragment { } }; + private OnClickListener joinMuc = new OnClickListener() { + + @Override + public void onClick(View v) { + activity.xmppConnectionService.joinMuc(conversation); + } + }; + private OnClickListener enterPassword = new OnClickListener() { @Override @@ -169,6 +178,7 @@ public class ConversationFragment extends Fragment { conversation, timestamp); messageList.clear(); messageList.addAll(conversation.getMessages()); + updateStatusMessages(); messageListAdapter.notifyDataSetChanged(); if (size != 0) { messagesLoaded = true; @@ -244,9 +254,7 @@ public class ConversationFragment extends Fragment { @Override public void onClick(View v) { - if (activity.getSlidingPaneLayout().isSlideable()) { - activity.getSlidingPaneLayout().closePane(); - } + activity.hideConversationsOverview(); } }); mEditMessage.setOnEditorActionListener(mEditorActionListener); @@ -375,17 +383,10 @@ public class ConversationFragment extends Fragment { int position = mEditMessage.length(); Editable etext = mEditMessage.getText(); Selection.setSelection(etext, position); - if (activity.getSlidingPaneLayout().isSlideable()) { + if (activity.isConversationsOverviewHideable()) { if (!activity.shouldPaneBeOpen()) { - activity.getSlidingPaneLayout().closePane(); - activity.getActionBar().setDisplayHomeAsUpEnabled(true); - activity.getActionBar().setHomeButtonEnabled(true); - if (conversation.getMode() == Conversation.MODE_SINGLE || activity.useSubjectToIdentifyConference()) { - activity.getActionBar().setTitle(conversation.getName()); - } else { - activity.getActionBar().setTitle(conversation.getContactJid().split("/")[0]); - } - activity.invalidateOptionsMenu(); + activity.hideConversationsOverview(); + activity.openConversation(conversation); } } if (this.conversation.getMode() == Conversation.MODE_MULTI) { @@ -437,6 +438,8 @@ public class ConversationFragment extends Fragment { @Override public void onClick(View v) { conversation.setMutedTill(0); + activity.xmppConnectionService.databaseBackend + .updateConversation(conversation); updateMessages(); } }); @@ -492,6 +495,18 @@ public class ConversationFragment extends Fragment { showSnackbar(R.string.conference_requires_password, R.string.enter_password, enterPassword); break; + case MucOptions.ERROR_BANNED: + showSnackbar(R.string.conference_banned, + R.string.leave, leaveMuc); + break; + case MucOptions.ERROR_MEMBERS_ONLY: + showSnackbar(R.string.conference_members_only, + R.string.leave, leaveMuc); + break; + case MucOptions.KICKED_FROM_ROOM: + showSnackbar(R.string.conference_kicked, R.string.join, + joinMuc); + break; default: break; } @@ -500,9 +515,7 @@ public class ConversationFragment extends Fragment { getActivity().invalidateOptionsMenu(); updateChatMsgHint(); if (!activity.shouldPaneBeOpen()) { - activity.xmppConnectionService.markRead(conversation); - UIHelper.updateNotification(getActivity(), - activity.getConversationList(), null, false); + activity.xmppConnectionService.markRead(conversation, true); activity.updateConversationList(); } this.updateSendButton(); @@ -511,9 +524,7 @@ public class ConversationFragment extends Fragment { private void messageSent() { int size = this.messageList.size(); - if (size >= 1 && this.messagesView.getLastVisiblePosition() != size - 1) { - messagesView.setSelection(size - 1); - } + messagesView.setSelection(size - 1); mEditMessage.setText(""); updateChatMsgHint(); } @@ -667,6 +678,8 @@ public class ConversationFragment extends Fragment { int which) { conversation .setNextEncryption(Message.ENCRYPTION_NONE); + xmppService.databaseBackend + .updateConversation(conversation); message.setEncryption(Message.ENCRYPTION_NONE); xmppService.sendMessage(message); messageSent(); @@ -695,6 +708,8 @@ public class ConversationFragment extends Fragment { conversation .setNextEncryption(Message.ENCRYPTION_NONE); message.setEncryption(Message.ENCRYPTION_NONE); + xmppService.databaseBackend + .updateConversation(conversation); xmppService.sendMessage(message); messageSent(); } diff --git a/src/eu/siacs/conversations/ui/EditAccountActivity.java b/src/eu/siacs/conversations/ui/EditAccountActivity.java index bc946115..0ec38547 100644 --- a/src/eu/siacs/conversations/ui/EditAccountActivity.java +++ b/src/eu/siacs/conversations/ui/EditAccountActivity.java @@ -1,8 +1,12 @@ package eu.siacs.conversations.ui; import android.app.PendingIntent; +import android.content.ClipData; +import android.content.ClipboardManager; import android.content.Intent; import android.os.Bundle; +import android.text.Editable; +import android.text.TextWatcher; import android.view.View; import android.view.View.OnClickListener; import android.widget.AutoCompleteTextView; @@ -10,9 +14,11 @@ import android.widget.Button; import android.widget.CheckBox; import android.widget.CompoundButton; import android.widget.EditText; +import android.widget.ImageButton; import android.widget.LinearLayout; import android.widget.CompoundButton.OnCheckedChangeListener; import android.widget.TextView; +import android.widget.Toast; import eu.siacs.conversations.R; import eu.siacs.conversations.entities.Account; import eu.siacs.conversations.services.XmppConnectionService.OnAccountUpdate; @@ -38,6 +44,7 @@ public class EditAccountActivity extends XmppActivity { private TextView mSessionEst; private TextView mOtrFingerprint; private TextView mOtrFingerprintHeadline; + private ImageButton mOtrFingerprintToClipboardButton; private String jidToEdit; private Account mAccount; @@ -48,6 +55,12 @@ public class EditAccountActivity extends XmppActivity { @Override public void onClick(View v) { + if (mAccount != null + && mAccount.getStatus() == Account.STATUS_DISABLED) { + mAccount.setOption(Account.OPTION_DISABLED, false); + xmppConnectionService.updateAccount(mAccount); + return; + } if (!Validator.isValidJid(mAccountJid.getText().toString())) { mAccountJid.setError(getString(R.string.invalid_jid)); mAccountJid.requestFocus(); @@ -157,6 +170,25 @@ public class EditAccountActivity extends XmppActivity { } }; private KnownHostsAdapter mKnownHostsAdapter; + private TextWatcher mTextWatcher = new TextWatcher() { + + @Override + public void onTextChanged(CharSequence s, int start, int before, + int count) { + updateSaveButton(); + } + + @Override + public void beforeTextChanged(CharSequence s, int start, int count, + int after) { + + } + + @Override + public void afterTextChanged(Editable s) { + + } + }; protected void finishInitialSetup(final Avatar avatar) { runOnUiThread(new Runnable() { @@ -197,6 +229,11 @@ public class EditAccountActivity extends XmppActivity { this.mSaveButton.setEnabled(false); this.mSaveButton.setTextColor(getSecondaryTextColor()); this.mSaveButton.setText(R.string.account_status_connecting); + } else if (mAccount != null + && mAccount.getStatus() == Account.STATUS_DISABLED) { + this.mSaveButton.setEnabled(true); + this.mSaveButton.setTextColor(getPrimaryTextColor()); + this.mSaveButton.setText(R.string.enable); } else { this.mSaveButton.setEnabled(true); this.mSaveButton.setTextColor(getPrimaryTextColor()); @@ -204,6 +241,10 @@ public class EditAccountActivity extends XmppActivity { if (mAccount != null && mAccount.getStatus() == Account.STATUS_ONLINE) { this.mSaveButton.setText(R.string.save); + if (!accountInfoEdited()) { + this.mSaveButton.setEnabled(false); + this.mSaveButton.setTextColor(getSecondaryTextColor()); + } } else { this.mSaveButton.setText(R.string.connect); } @@ -213,12 +254,21 @@ public class EditAccountActivity extends XmppActivity { } } + protected boolean accountInfoEdited() { + return (!this.mAccount.getJid().equals( + this.mAccountJid.getText().toString())) + || (!this.mAccount.getPassword().equals( + this.mPassword.getText().toString())); + } + @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_edit_account); this.mAccountJid = (AutoCompleteTextView) findViewById(R.id.account_jid); + this.mAccountJid.addTextChangedListener(this.mTextWatcher); this.mPassword = (EditText) findViewById(R.id.account_password); + this.mPassword.addTextChangedListener(this.mTextWatcher); this.mPasswordConfirm = (EditText) findViewById(R.id.account_password_confirm); this.mRegisterNew = (CheckBox) findViewById(R.id.account_register_new); this.mStats = (LinearLayout) findViewById(R.id.stats); @@ -228,6 +278,7 @@ public class EditAccountActivity extends XmppActivity { this.mServerInfoPep = (TextView) findViewById(R.id.server_info_pep); this.mOtrFingerprint = (TextView) findViewById(R.id.otr_fingerprint); this.mOtrFingerprintHeadline = (TextView) findViewById(R.id.otr_fingerprint_headline); + this.mOtrFingerprintToClipboardButton = (ImageButton) findViewById(R.id.action_copy_to_clipboard); this.mSaveButton = (Button) findViewById(R.id.save_button); this.mCancelButton = (Button) findViewById(R.id.cancel_button); this.mSaveButton.setOnClickListener(this.mSaveButtonClickListener); @@ -255,7 +306,7 @@ public class EditAccountActivity extends XmppActivity { this.jidToEdit = getIntent().getStringExtra("jid"); if (this.jidToEdit != null) { this.mRegisterNew.setVisibility(View.GONE); - getActionBar().setTitle(R.string.mgmt_account_edit); + getActionBar().setTitle(jidToEdit); } else { getActionBar().setTitle(R.string.action_add_account); } @@ -324,13 +375,30 @@ public class EditAccountActivity extends XmppActivity { } else { this.mServerInfoPep.setText(R.string.server_info_unavailable); } - String fingerprint = this.mAccount + final String fingerprint = this.mAccount .getOtrFingerprint(xmppConnectionService); if (fingerprint != null) { this.mOtrFingerprintHeadline.setVisibility(View.VISIBLE); this.mOtrFingerprint.setVisibility(View.VISIBLE); this.mOtrFingerprint.setText(fingerprint); + this.mOtrFingerprintToClipboardButton + .setVisibility(View.VISIBLE); + this.mOtrFingerprintToClipboardButton + .setOnClickListener(new View.OnClickListener() { + + @Override + public void onClick(View v) { + + if (OtrFingerprintToClipBoard(fingerprint)) { + Toast.makeText( + EditAccountActivity.this, + R.string.toast_message_otr_fingerprint, + Toast.LENGTH_SHORT).show(); + } + } + }); } else { + this.mOtrFingerprintToClipboardButton.setVisibility(View.GONE); this.mOtrFingerprint.setVisibility(View.GONE); this.mOtrFingerprintHeadline.setVisibility(View.GONE); } @@ -343,4 +411,15 @@ public class EditAccountActivity extends XmppActivity { this.mStats.setVisibility(View.GONE); } } + + private boolean OtrFingerprintToClipBoard(String fingerprint) { + ClipboardManager mClipBoardManager = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE); + String label = getResources().getString(R.string.otr_fingerprint); + if (mClipBoardManager != null) { + ClipData mClipData = ClipData.newPlainText(label, fingerprint); + mClipBoardManager.setPrimaryClip(mClipData); + return true; + } + return false; + } } diff --git a/src/eu/siacs/conversations/ui/ManageAccountActivity.java b/src/eu/siacs/conversations/ui/ManageAccountActivity.java index ca17eb0d..afe9e06e 100644 --- a/src/eu/siacs/conversations/ui/ManageAccountActivity.java +++ b/src/eu/siacs/conversations/ui/ManageAccountActivity.java @@ -24,8 +24,6 @@ import android.widget.ListView; public class ManageAccountActivity extends XmppActivity { - protected ManageAccountActivity activity = this; - protected Account selectedAccount = null; protected List accountList = new ArrayList(); @@ -72,7 +70,7 @@ public class ManageAccountActivity extends XmppActivity { public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) { super.onCreateContextMenu(menu, v, menuInfo); - activity.getMenuInflater().inflate(R.menu.manageaccounts_context, menu); + ManageAccountActivity.this.getMenuInflater().inflate(R.menu.manageaccounts_context, menu); AdapterView.AdapterContextMenuInfo acmi = (AdapterContextMenuInfo) menuInfo; this.selectedAccount = accountList.get(acmi.position); if (this.selectedAccount.isOptionSet(Account.OPTION_DISABLED)) { @@ -181,7 +179,7 @@ public class ManageAccountActivity extends XmppActivity { } private void publishOpenPGPPublicKey(Account account) { - if (activity.hasPgp()) { + if (ManageAccountActivity.this.hasPgp()) { announcePgp(account, null); } else { this.showInstallPgpDialog(); @@ -189,7 +187,7 @@ public class ManageAccountActivity extends XmppActivity { } private void deleteAccount(final Account account) { - AlertDialog.Builder builder = new AlertDialog.Builder(activity); + AlertDialog.Builder builder = new AlertDialog.Builder(ManageAccountActivity.this); builder.setTitle(getString(R.string.mgmt_account_are_you_sure)); builder.setIconAttribute(android.R.attr.alertDialogIcon); builder.setMessage(getString(R.string.mgmt_account_delete_confirm_text)); diff --git a/src/eu/siacs/conversations/ui/SettingsActivity.java b/src/eu/siacs/conversations/ui/SettingsActivity.java index fc361fb8..fc6308fc 100644 --- a/src/eu/siacs/conversations/ui/SettingsActivity.java +++ b/src/eu/siacs/conversations/ui/SettingsActivity.java @@ -21,7 +21,7 @@ public class SettingsActivity extends XmppActivity implements super.onCreate(savedInstanceState); mSettingsFragment = new SettingsFragment(); getFragmentManager().beginTransaction() - .replace(android.R.id.content,mSettingsFragment).commit(); + .replace(android.R.id.content, mSettingsFragment).commit(); } @Override @@ -34,12 +34,16 @@ public class SettingsActivity extends XmppActivity implements super.onStart(); PreferenceManager.getDefaultSharedPreferences(this) .registerOnSharedPreferenceChangeListener(this); - ListPreference resources = (ListPreference) mSettingsFragment.findPreference("resource"); - if (resources!=null) { - ArrayList entries = new ArrayList(Arrays.asList(resources.getEntries())); - entries.add(0,Build.MODEL); - resources.setEntries(entries.toArray(new CharSequence[entries.size()])); - resources.setEntryValues(entries.toArray(new CharSequence[entries.size()])); + ListPreference resources = (ListPreference) mSettingsFragment + .findPreference("resource"); + if (resources != null) { + ArrayList entries = new ArrayList( + Arrays.asList(resources.getEntries())); + entries.add(0, Build.MODEL); + resources.setEntries(entries.toArray(new CharSequence[entries + .size()])); + resources.setEntryValues(entries.toArray(new CharSequence[entries + .size()])); } } diff --git a/src/eu/siacs/conversations/ui/StartConversationActivity.java b/src/eu/siacs/conversations/ui/StartConversationActivity.java index db6c1509..a1a2d4c2 100644 --- a/src/eu/siacs/conversations/ui/StartConversationActivity.java +++ b/src/eu/siacs/conversations/ui/StartConversationActivity.java @@ -1,9 +1,12 @@ package eu.siacs.conversations.ui; +import java.io.UnsupportedEncodingException; +import java.net.URLDecoder; import java.util.ArrayList; import java.util.Collections; import java.util.List; +import android.annotation.SuppressLint; import android.app.ActionBar; import android.app.ActionBar.Tab; import android.app.ActionBar.TabListener; @@ -14,6 +17,8 @@ import android.app.ListFragment; import android.content.Context; import android.content.DialogInterface; import android.content.DialogInterface.OnClickListener; +import android.content.Intent; +import android.net.Uri; import android.os.Bundle; import android.support.v13.app.FragmentPagerAdapter; import android.support.v4.view.ViewPager; @@ -157,6 +162,8 @@ public class StartConversationActivity extends XmppActivity { }); } }; + private MenuItem mMenuSearchView; + private String mInitialJid; @Override public void onCreate(Bundle savedInstanceState) { @@ -308,7 +315,8 @@ public class StartConversationActivity extends XmppActivity { } - protected void showCreateContactDialog() { + @SuppressLint("InflateParams") + protected void showCreateContactDialog(String prefilledJid) { AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setTitle(R.string.create_contact); View dialogView = getLayoutInflater().inflate( @@ -318,6 +326,9 @@ public class StartConversationActivity extends XmppActivity { .findViewById(R.id.jid); jid.setAdapter(new KnownHostsAdapter(this, android.R.layout.simple_list_item_1, mKnownHosts)); + if (prefilledJid != null) { + jid.append(prefilledJid); + } populateAccountSpinner(spinner); builder.setView(dialogView); builder.setNegativeButton(R.string.cancel, null); @@ -348,8 +359,8 @@ public class StartConversationActivity extends XmppActivity { jid.setError(getString(R.string.contact_already_exists)); } else { xmppConnectionService.createContact(contact); - switchToConversation(contact); dialog.dismiss(); + switchToConversation(contact); } } else { jid.setError(getString(R.string.invalid_jid)); @@ -359,6 +370,7 @@ public class StartConversationActivity extends XmppActivity { } + @SuppressLint("InflateParams") protected void showJoinConferenceDialog() { AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setTitle(R.string.join_conference); @@ -391,6 +403,10 @@ public class StartConversationActivity extends XmppActivity { String conferenceJid = jid.getText().toString(); Account account = xmppConnectionService .findAccountByJid(accountJid); + if (account == null) { + dialog.dismiss(); + return; + } if (bookmarkCheckBox.isChecked()) { if (account.hasBookmarkFor(conferenceJid)) { jid.setError(getString(R.string.bookmark_already_exists)); @@ -409,6 +425,7 @@ public class StartConversationActivity extends XmppActivity { xmppConnectionService .joinMuc(conversation); } + dialog.dismiss(); switchToConversation(conversation); } } else { @@ -418,6 +435,7 @@ public class StartConversationActivity extends XmppActivity { if (!conversation.getMucOptions().online()) { xmppConnectionService.joinMuc(conversation); } + dialog.dismiss(); switchToConversation(conversation); } } else { @@ -449,9 +467,9 @@ public class StartConversationActivity extends XmppActivity { .findItem(R.id.action_create_contact); MenuItem menuCreateConference = (MenuItem) menu .findItem(R.id.action_join_conference); - MenuItem menuSearchView = (MenuItem) menu.findItem(R.id.action_search); - menuSearchView.setOnActionExpandListener(mOnActionExpandListener); - View mSearchView = menuSearchView.getActionView(); + mMenuSearchView = (MenuItem) menu.findItem(R.id.action_search); + mMenuSearchView.setOnActionExpandListener(mOnActionExpandListener); + View mSearchView = mMenuSearchView.getActionView(); mSearchEditText = (EditText) mSearchView .findViewById(R.id.search_field); mSearchEditText.addTextChangedListener(mSearchTextWatcher); @@ -460,6 +478,11 @@ public class StartConversationActivity extends XmppActivity { } else { menuCreateContact.setVisible(false); } + if (mInitialJid != null) { + mMenuSearchView.expandActionView(); + mSearchEditText.append(mInitialJid); + filter(mInitialJid); + } return true; } @@ -467,7 +490,7 @@ public class StartConversationActivity extends XmppActivity { public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case R.id.action_create_contact: - showCreateContactDialog(); + showCreateContactDialog(null); break; case R.id.action_join_conference: showJoinConferenceDialog(); @@ -486,13 +509,8 @@ public class StartConversationActivity extends XmppActivity { } @Override - void onBackendConnected() { + protected void onBackendConnected() { xmppConnectionService.setOnRosterUpdateListener(this.onRosterUpdate); - if (mSearchEditText != null) { - filter(mSearchEditText.getText().toString()); - } else { - filter(null); - } this.mActivatedAccounts.clear(); for (Account account : xmppConnectionService.getAccounts()) { if (account.getStatus() != Account.STATUS_DISABLED) { @@ -502,6 +520,55 @@ public class StartConversationActivity extends XmppActivity { this.mKnownHosts = xmppConnectionService.getKnownHosts(); this.mKnownConferenceHosts = xmppConnectionService .getKnownConferenceHosts(); + if (!startByIntent()) { + if (mSearchEditText != null) { + filter(mSearchEditText.getText().toString()); + } else { + filter(null); + } + } + } + + protected boolean startByIntent() { + if (getIntent() != null + && Intent.ACTION_SENDTO.equals(getIntent().getAction())) { + try { + String jid = URLDecoder.decode( + getIntent().getData().getEncodedPath(), "UTF-8").split( + "/")[1]; + setIntent(null); + return handleJid(jid); + } catch (UnsupportedEncodingException e) { + setIntent(null); + return false; + } + } else if (getIntent() != null + && Intent.ACTION_VIEW.equals(getIntent().getAction())) { + Uri uri = getIntent().getData(); + String jid = uri.getSchemeSpecificPart().split("\\?")[0]; + return handleJid(jid); + } + return false; + } + + private boolean handleJid(String jid) { + List contacts = xmppConnectionService.findContacts(jid); + if (contacts.size() == 0) { + showCreateContactDialog(jid); + return false; + } else if (contacts.size() == 1) { + switchToConversation(contacts.get(0)); + return true; + } else { + if (mMenuSearchView != null) { + mMenuSearchView.expandActionView(); + mSearchEditText.setText(jid); + filter(jid); + } else { + mInitialJid = jid; + } + return true; + } } protected void filter(String needle) { diff --git a/src/eu/siacs/conversations/ui/XmppActivity.java b/src/eu/siacs/conversations/ui/XmppActivity.java index 26a33d1a..cd77557c 100644 --- a/src/eu/siacs/conversations/ui/XmppActivity.java +++ b/src/eu/siacs/conversations/ui/XmppActivity.java @@ -15,6 +15,7 @@ import eu.siacs.conversations.entities.Presences; import eu.siacs.conversations.services.XmppConnectionService; import eu.siacs.conversations.services.XmppConnectionService.XmppConnectionBinder; import eu.siacs.conversations.utils.ExceptionHelper; +import android.annotation.SuppressLint; import android.app.Activity; import android.app.AlertDialog; import android.app.PendingIntent; @@ -58,11 +59,12 @@ public abstract class XmppActivity extends Activity { protected int mPrimaryTextColor; protected int mSecondaryTextColor; + protected int mSecondaryBackgroundColor; protected int mColorRed; protected int mColorOrange; protected int mColorGreen; protected int mPrimaryColor; - + protected boolean mUseSubject = true; private DisplayMetrics metrics; @@ -206,6 +208,8 @@ public abstract class XmppActivity extends Activity { mColorOrange = getResources().getColor(R.color.orange); mColorGreen = getResources().getColor(R.color.green); mPrimaryColor = getResources().getColor(R.color.primary); + mSecondaryBackgroundColor = getResources().getColor( + R.color.secondarybackground); if (getPreferences().getBoolean("use_larger_font", false)) { setTheme(R.style.ConversationsTheme_LargerText); } @@ -216,7 +220,7 @@ public abstract class XmppActivity extends Activity { return PreferenceManager .getDefaultSharedPreferences(getApplicationContext()); } - + public boolean useSubjectToIdentifyConference() { return mUseSubject; } @@ -245,6 +249,7 @@ public abstract class XmppActivity extends Activity { | Intent.FLAG_ACTIVITY_CLEAR_TOP); } startActivity(viewConversationIntent); + finish(); } public void switchToContactDetails(Contact contact) { @@ -254,7 +259,7 @@ public abstract class XmppActivity extends Activity { intent.putExtra("contact", contact.getJid()); startActivity(intent); } - + public void switchToAccount(Account account) { Intent intent = new Intent(this, EditAccountActivity.class); intent.putExtra("jid", account.getJid()); @@ -292,6 +297,8 @@ public abstract class XmppActivity extends Activity { if (conversation != null) { conversation .setNextEncryption(Message.ENCRYPTION_PGP); + xmppConnectionService.databaseBackend + .updateConversation(conversation); } } @@ -389,6 +396,7 @@ public abstract class XmppActivity extends Activity { quickEdit(previousValue, callback, true); } + @SuppressLint("InflateParams") private void quickEdit(final String previousValue, final OnValueEdited callback, boolean password) { AlertDialog.Builder builder = new AlertDialog.Builder(this); @@ -514,6 +522,10 @@ public abstract class XmppActivity extends Activity { return this.mPrimaryColor; } + public int getSecondaryBackgroundColor() { + return this.mSecondaryBackgroundColor; + } + class BitmapWorkerTask extends AsyncTask { private final WeakReference imageViewReference; private Message message = null; diff --git a/src/eu/siacs/conversations/ui/adapter/ConversationAdapter.java b/src/eu/siacs/conversations/ui/adapter/ConversationAdapter.java index e40723f4..f74856b0 100644 --- a/src/eu/siacs/conversations/ui/adapter/ConversationAdapter.java +++ b/src/eu/siacs/conversations/ui/adapter/ConversationAdapter.java @@ -40,9 +40,10 @@ public class ConversationAdapter extends ArrayAdapter { Conversation conv = getItem(position); if (this.activity instanceof ConversationActivity) { ConversationActivity activity = (ConversationActivity) this.activity; - if (!activity.getSlidingPaneLayout().isSlideable()) { + if (!activity.isConversationsOverviewHideable()) { if (conv == activity.getSelectedConversation()) { - view.setBackgroundColor(0xffdddddd); + view.setBackgroundColor(activity + .getSecondaryBackgroundColor()); } else { view.setBackgroundColor(Color.TRANSPARENT); } @@ -52,7 +53,8 @@ public class ConversationAdapter extends ArrayAdapter { } TextView convName = (TextView) view .findViewById(R.id.conversation_name); - if (conv.getMode() == Conversation.MODE_SINGLE || activity.useSubjectToIdentifyConference()) { + if (conv.getMode() == Conversation.MODE_SINGLE + || activity.useSubjectToIdentifyConference()) { convName.setText(conv.getName()); } else { convName.setText(conv.getContactJid().split("/")[0]); diff --git a/src/eu/siacs/conversations/ui/adapter/ListItemAdapter.java b/src/eu/siacs/conversations/ui/adapter/ListItemAdapter.java index 9ef427fc..df67e566 100644 --- a/src/eu/siacs/conversations/ui/adapter/ListItemAdapter.java +++ b/src/eu/siacs/conversations/ui/adapter/ListItemAdapter.java @@ -24,7 +24,7 @@ public class ListItemAdapter extends ArrayAdapter { .getSystemService(Context.LAYOUT_INFLATER_SERVICE); ListItem item = getItem(position); if (view == null) { - view = (View) inflater.inflate(R.layout.contact, null); + view = (View) inflater.inflate(R.layout.contact, parent, false); } TextView name = (TextView) view.findViewById(R.id.contact_display_name); TextView jid = (TextView) view.findViewById(R.id.contact_jid); @@ -36,4 +36,4 @@ public class ListItemAdapter extends ArrayAdapter { return view; } -} \ No newline at end of file +} diff --git a/src/eu/siacs/conversations/ui/adapter/MessageAdapter.java b/src/eu/siacs/conversations/ui/adapter/MessageAdapter.java index 035d18c5..2671cf50 100644 --- a/src/eu/siacs/conversations/ui/adapter/MessageAdapter.java +++ b/src/eu/siacs/conversations/ui/adapter/MessageAdapter.java @@ -417,7 +417,17 @@ public class MessageAdapter extends ArrayAdapter { viewHolder = (ViewHolder) view.getTag(); } - if (type == STATUS || type == NULL) { + if (type == STATUS) { + return view; + } + if (type == NULL) { + if (position == getCount() - 1) { + view.getLayoutParams().height = 1; + } else { + view.getLayoutParams().height = 0; + + } + view.setLayoutParams(view.getLayoutParams()); return view; } diff --git a/src/eu/siacs/conversations/utils/DNSHelper.java b/src/eu/siacs/conversations/utils/DNSHelper.java index fd3b1953..c51a75ac 100644 --- a/src/eu/siacs/conversations/utils/DNSHelper.java +++ b/src/eu/siacs/conversations/utils/DNSHelper.java @@ -30,17 +30,17 @@ public class DNSHelper { String dns[] = client.findDNS(); if (dns != null) { - // we have a list of DNS servers, let's go for (String dnsserver : dns) { InetAddress ip = InetAddress.getByName(dnsserver); Bundle b = queryDNS(host, ip); if (b.containsKey("name")) { return b; + } else if (b.containsKey("error") + && "nosrv".equals(b.getString("error", null))) { + return b; } } } - - // fallback return queryDNS(host, InetAddress.getByName("8.8.8.8")); } @@ -164,10 +164,8 @@ public class DNSHelper { } } catch (SocketTimeoutException e) { - Log.d(Config.LOGTAG, "timeout during dns"); namePort.putString("error", "timeout"); } catch (Exception e) { - Log.d(Config.LOGTAG, "unhandled exception in sub project"); namePort.putString("error", "unhandled"); } return namePort; diff --git a/src/eu/siacs/conversations/utils/UIHelper.java b/src/eu/siacs/conversations/utils/UIHelper.java index f6e66cdb..671e66d5 100644 --- a/src/eu/siacs/conversations/utils/UIHelper.java +++ b/src/eu/siacs/conversations/utils/UIHelper.java @@ -7,16 +7,15 @@ import java.util.Date; import java.util.List; import java.util.Locale; import java.util.regex.Pattern; -import java.util.regex.Matcher; import eu.siacs.conversations.R; import eu.siacs.conversations.entities.Account; import eu.siacs.conversations.entities.Contact; import eu.siacs.conversations.entities.Conversation; -import eu.siacs.conversations.entities.Message; import eu.siacs.conversations.entities.MucOptions.User; import eu.siacs.conversations.ui.ConversationActivity; import eu.siacs.conversations.ui.ManageAccountActivity; +import android.annotation.SuppressLint; import android.app.Activity; import android.app.AlertDialog; import android.app.Notification; @@ -26,7 +25,6 @@ import android.content.Context; import android.content.DialogInterface; import android.content.DialogInterface.OnClickListener; import android.content.Intent; -import android.content.SharedPreferences; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.graphics.Canvas; @@ -34,13 +32,11 @@ import android.graphics.Paint; import android.graphics.Rect; import android.graphics.Typeface; import android.net.Uri; -import android.preference.PreferenceManager; import android.provider.ContactsContract.Contacts; import android.support.v4.app.NotificationCompat; import android.support.v4.app.TaskStackBuilder; import android.text.format.DateFormat; import android.text.format.DateUtils; -import android.text.Html; import android.util.DisplayMetrics; import android.view.LayoutInflater; import android.view.View; @@ -330,177 +326,6 @@ public class UIHelper { mNotificationManager.notify(1111, notification); } - private static Pattern generateNickHighlightPattern(String nick) { - // We expect a word boundary, i.e. space or start of string, followed by - // the - // nick (matched in case-insensitive manner), followed by optional - // punctuation (for example "bob: i disagree" or "how are you alice?"), - // followed by another word boundary. - return Pattern.compile("\\b" + nick + "\\p{Punct}?\\b", - Pattern.CASE_INSENSITIVE | Pattern.UNICODE_CASE); - } - - public static void updateNotification(Context context, - List conversations, Conversation currentCon, - boolean notify) { - NotificationManager mNotificationManager = (NotificationManager) context - .getSystemService(Context.NOTIFICATION_SERVICE); - - SharedPreferences preferences = PreferenceManager - .getDefaultSharedPreferences(context); - boolean showNofifications = preferences.getBoolean("show_notification", - true); - boolean vibrate = preferences.getBoolean("vibrate_on_notification", - true); - boolean alwaysNotify = preferences.getBoolean( - "notify_in_conversation_when_highlighted", false); - - if (!showNofifications) { - mNotificationManager.cancel(2342); - return; - } - - String targetUuid = ""; - - if ((currentCon != null) - && (currentCon.getMode() == Conversation.MODE_MULTI) - && (!alwaysNotify) && notify) { - String nick = currentCon.getMucOptions().getActualNick(); - Pattern highlight = generateNickHighlightPattern(nick); - Matcher m = highlight.matcher(currentCon.getLatestMessage() - .getBody()); - notify = m.find() - || (currentCon.getLatestMessage().getType() == Message.TYPE_PRIVATE); - } - - List unread = new ArrayList(); - for (Conversation conversation : conversations) { - if (conversation.getMode() == Conversation.MODE_MULTI) { - if ((!conversation.isRead()) - && ((wasHighlightedOrPrivate(conversation) || (alwaysNotify)))) { - unread.add(conversation); - } - } else { - if (!conversation.isRead()) { - unread.add(conversation); - } - } - } - String ringtone = preferences.getString("notification_ringtone", null); - - NotificationCompat.Builder mBuilder = new NotificationCompat.Builder( - context); - if (unread.size() == 0) { - mNotificationManager.cancel(2342); - return; - } else if (unread.size() == 1) { - Conversation conversation = unread.get(0); - targetUuid = conversation.getUuid(); - mBuilder.setLargeIcon(conversation.getImage(context, 64)); - mBuilder.setContentTitle(conversation.getName()); - if (notify) { - mBuilder.setTicker(conversation.getLatestMessage() - .getReadableBody(context)); - } - StringBuilder bigText = new StringBuilder(); - List messages = conversation.getMessages(); - String firstLine = ""; - for (int i = messages.size() - 1; i >= 0; --i) { - if (!messages.get(i).isRead()) { - if (i == messages.size() - 1) { - firstLine = messages.get(i).getReadableBody(context); - bigText.append(firstLine); - } else { - firstLine = messages.get(i).getReadableBody(context); - bigText.insert(0, firstLine + "\n"); - } - } else { - break; - } - } - mBuilder.setContentText(firstLine); - mBuilder.setStyle(new NotificationCompat.BigTextStyle() - .bigText(bigText.toString())); - } else { - NotificationCompat.InboxStyle style = new NotificationCompat.InboxStyle(); - style.setBigContentTitle(unread.size() + " " - + context.getString(R.string.unread_conversations)); - StringBuilder names = new StringBuilder(); - for (int i = 0; i < unread.size(); ++i) { - targetUuid = unread.get(i).getUuid(); - if (i < unread.size() - 1) { - names.append(unread.get(i).getName() + ", "); - } else { - names.append(unread.get(i).getName()); - } - style.addLine(Html.fromHtml("" - + unread.get(i).getName() - + " " - + unread.get(i).getLatestMessage() - .getReadableBody(context))); - } - mBuilder.setContentTitle(unread.size() + " " - + context.getString(R.string.unread_conversations)); - mBuilder.setContentText(names.toString()); - mBuilder.setStyle(style); - } - if ((currentCon != null) && (notify)) { - targetUuid = currentCon.getUuid(); - } - if (unread.size() != 0) { - mBuilder.setSmallIcon(R.drawable.ic_notification); - if (notify) { - if (vibrate) { - int dat = 70; - long[] pattern = { 0, 3 * dat, dat, dat }; - mBuilder.setVibrate(pattern); - } - mBuilder.setLights(0xffffffff, 2000, 4000); - if (ringtone != null) { - mBuilder.setSound(Uri.parse(ringtone)); - } - } - - TaskStackBuilder stackBuilder = TaskStackBuilder.create(context); - stackBuilder.addParentStack(ConversationActivity.class); - - Intent viewConversationIntent = new Intent(context, - ConversationActivity.class); - viewConversationIntent.setAction(Intent.ACTION_VIEW); - viewConversationIntent.putExtra(ConversationActivity.CONVERSATION, - targetUuid); - viewConversationIntent - .setType(ConversationActivity.VIEW_CONVERSATION); - - stackBuilder.addNextIntent(viewConversationIntent); - - PendingIntent resultPendingIntent = stackBuilder.getPendingIntent( - 0, PendingIntent.FLAG_UPDATE_CURRENT); - - mBuilder.setContentIntent(resultPendingIntent); - Notification notification = mBuilder.build(); - mNotificationManager.notify(2342, notification); - } - } - - private static boolean wasHighlightedOrPrivate(Conversation conversation) { - List messages = conversation.getMessages(); - String nick = conversation.getMucOptions().getActualNick(); - Pattern highlight = generateNickHighlightPattern(nick); - for (int i = messages.size() - 1; i >= 0; --i) { - if (messages.get(i).isRead()) { - break; - } else { - Matcher m = highlight.matcher(messages.get(i).getBody()); - if (m.find() - || messages.get(i).getType() == Message.TYPE_PRIVATE) { - return true; - } - } - } - return false; - } - public static void prepareContactBadge(final Activity activity, QuickContactBadge badge, final Contact contact, Context context) { if (contact.getSystemAccount() != null) { @@ -511,6 +336,7 @@ public class UIHelper { badge.setImageBitmap(contact.getImage(72, context)); } + @SuppressLint("InflateParams") public static AlertDialog getVerifyFingerprintDialog( final ConversationActivity activity, final Conversation conversation, final View msg) { diff --git a/src/eu/siacs/conversations/xmpp/XmppConnection.java b/src/eu/siacs/conversations/xmpp/XmppConnection.java index 8694e68c..54409be4 100644 --- a/src/eu/siacs/conversations/xmpp/XmppConnection.java +++ b/src/eu/siacs/conversations/xmpp/XmppConnection.java @@ -166,8 +166,14 @@ public class XmppConnection implements Runnable { + ":" + srvRecordPort); socket = new Socket(srvRecordServer, srvRecordPort); } - } else { + } else if (namePort.containsKey("error") + && "nosrv".equals(namePort.getString("error", null))) { socket = new Socket(account.getServer(), 5222); + } else { + Log.d(Config.LOGTAG, account.getJid() + + ": timeout in DNS resolution"); + changeStatus(Account.STATUS_OFFLINE); + return; } OutputStream out = socket.getOutputStream(); tagWriter.setOutputStream(out); @@ -307,7 +313,8 @@ public class XmppConnection implements Runnable { } catch (NumberFormatException e) { } - changeStatus(Account.STATUS_ONLINE); + sendInitialPing(); + } else if (nextTag.isStart("r")) { tagReader.readElement(nextTag); AckPacket ack = new AckPacket(this.stanzasReceived, smVersion); @@ -348,6 +355,22 @@ public class XmppConnection implements Runnable { } } + private void sendInitialPing() { + Log.d(Config.LOGTAG, account.getJid() + ": sending intial ping"); + IqPacket iq = new IqPacket(IqPacket.TYPE_GET); + iq.setFrom(account.getFullJid()); + iq.addChild("ping", "urn:xmpp:ping"); + this.sendIqPacket(iq, new OnIqPacketReceived() { + + @Override + public void onIqPacketReceived(Account account, IqPacket packet) { + Log.d(Config.LOGTAG, account.getJid() + + ": online with resource " + account.getResource()); + changeStatus(Account.STATUS_ONLINE); + } + }); + } + private Element processPacket(Tag currentTag, int packetType) throws XmlPullParserException, IOException { Element element; @@ -372,8 +395,11 @@ public class XmppConnection implements Runnable { while (!nextTag.isEnd(element.getName())) { if (!nextTag.isNo()) { Element child = tagReader.readElement(nextTag); - if ((packetType == PACKET_IQ) - && ("jingle".equals(child.getName()))) { + String type = currentTag.getAttribute("type"); + if (packetType == PACKET_IQ + && "jingle".equals(child.getName()) + && ("set".equalsIgnoreCase(type) || "get" + .equalsIgnoreCase(type))) { element = new JinglePacket(); element.setAttributes(currentTag.getAttributes()); } @@ -410,7 +436,9 @@ public class XmppConnection implements Runnable { } packetCallbacks.remove(packet.getId()); - } else if (this.unregisteredIqListener != null) { + } else if ((packet.getType() == IqPacket.TYPE_GET || packet + .getType() == IqPacket.TYPE_SET) + && this.unregisteredIqListener != null) { this.unregisteredIqListener.onIqPacketReceived(account, packet); } } @@ -657,7 +685,7 @@ public class XmppConnection implements Runnable { if (bind != null) { Element jid = bind.findChild("jid"); if (jid != null && jid.getContent() != null) { - account.setResource(jid.getContent().split("/",2)[1]); + account.setResource(jid.getContent().split("/", 2)[1]); if (streamFeatures.hasChild("sm", "urn:xmpp:sm:3")) { smVersion = 3; EnablePacket enable = new EnablePacket(smVersion); @@ -677,7 +705,7 @@ public class XmppConnection implements Runnable { if (bindListener != null) { bindListener.onBind(account); } - changeStatus(Account.STATUS_ONLINE); + sendInitialPing(); } else { disconnect(true); } @@ -882,8 +910,7 @@ public class XmppConnection implements Runnable { } public void disconnect(boolean force) { - changeStatus(Account.STATUS_OFFLINE); - Log.d(Config.LOGTAG, "disconnecting"); + Log.d(Config.LOGTAG, account.getJid()+": disconnecting"); try { if (force) { socket.close(); @@ -901,6 +928,7 @@ public class XmppConnection implements Runnable { Thread.sleep(100); } tagWriter.writeTag(Tag.end("stream:stream")); + socket.close(); } catch (IOException e) { Log.d(Config.LOGTAG, "io exception during disconnect"); diff --git a/src/eu/siacs/conversations/xmpp/jingle/JingleConnection.java b/src/eu/siacs/conversations/xmpp/jingle/JingleConnection.java index 4eac99e6..92fdbe0b 100644 --- a/src/eu/siacs/conversations/xmpp/jingle/JingleConnection.java +++ b/src/eu/siacs/conversations/xmpp/jingle/JingleConnection.java @@ -88,8 +88,8 @@ public class JingleConnection implements Downloadable { sendSuccess(); if (acceptedAutomatically) { message.markUnread(); - JingleConnection.this.mXmppConnectionService.notifyUi( - message.getConversation(), true); + JingleConnection.this.mXmppConnectionService + .getNotificationService().push(message); } BitmapFactory.Options options = new BitmapFactory.Options(); options.inJustDecodeBounds = true; @@ -256,12 +256,12 @@ public class JingleConnection implements Downloadable { this.status = STATUS_INITIATED; Conversation conversation = this.mXmppConnectionService .findOrCreateConversation(account, - packet.getFrom().split("/",2)[0], false); + packet.getFrom().split("/", 2)[0], false); this.message = new Message(conversation, "", Message.ENCRYPTION_NONE); this.message.setType(Message.TYPE_IMAGE); this.message.setStatus(Message.STATUS_RECEIVED_OFFER); this.message.setDownloadable(this); - String[] fromParts = packet.getFrom().split("/",2); + String[] fromParts = packet.getFrom().split("/", 2); this.message.setPresence(fromParts[1]); this.account = account; this.initiator = packet.getFrom(); @@ -319,8 +319,8 @@ public class JingleConnection implements Downloadable { + " allowed size:" + this.mJingleConnectionManager .getAutoAcceptFileSize()); - this.mXmppConnectionService - .notifyUi(conversation, true); + this.mXmppConnectionService.getNotificationService() + .push(message); } this.file = this.mXmppConnectionService.getFileBackend() .getJingleFile(message, false);