From b676c25930dce063c97a0ab8c0beb81f455e7354 Mon Sep 17 00:00:00 2001 From: Mikunj Date: Fri, 11 Oct 2019 09:56:30 +1100 Subject: [PATCH] Add UI --- AndroidManifest.xml | 8 +- res/layout/fragment_add_public_chat.xml | 48 +++++++++++ res/values/strings.xml | 10 +++ res/xml/preferences.xml | 4 + .../ApplicationPreferencesActivity.java | 12 +++ .../securesms/loki/AddPublicChatActivity.kt | 81 +++++++++++++++++++ .../securesms/loki/LokiPublicChatManager.kt | 2 +- 7 files changed, 162 insertions(+), 3 deletions(-) create mode 100644 res/layout/fragment_add_public_chat.xml create mode 100644 src/org/thoughtcrime/securesms/loki/AddPublicChatActivity.kt diff --git a/AndroidManifest.xml b/AndroidManifest.xml index c30e4385da..165f1eb2df 100644 --- a/AndroidManifest.xml +++ b/AndroidManifest.xml @@ -477,8 +477,12 @@ android:configChanges="touchscreen|keyboard|keyboardHidden|orientation|screenLayout|screenSize" /> + android:windowSoftInputMode="stateAlwaysVisible" + android:configChanges="touchscreen|keyboard|keyboardHidden|orientation|screenLayout|screenSize" /> + + diff --git a/res/layout/fragment_add_public_chat.xml b/res/layout/fragment_add_public_chat.xml new file mode 100644 index 0000000000..8f677a5784 --- /dev/null +++ b/res/layout/fragment_add_public_chat.xml @@ -0,0 +1,48 @@ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/res/values/strings.xml b/res/values/strings.xml index 59d313fa93..f1ba97c51a 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -1575,6 +1575,7 @@ Copied to clipboard Share Public Key Show QR Code + Add Public Chat Link Device Show Seed Your Seed @@ -1598,6 +1599,15 @@ Next Invalid public key Please enter the public key of the person you\'d like to message + + Add Public Chat + Server URL + Enter the full URL of the public server. E.g https://public-server.url + Add + Adding Server... + Invalid Url provided + Failed to connect to server + Added public chat server Accept Reject diff --git a/res/xml/preferences.xml b/res/xml/preferences.xml index 99aa910c01..2260f55718 100644 --- a/res/xml/preferences.xml +++ b/res/xml/preferences.xml @@ -41,6 +41,10 @@ android:title="@string/activity_settings_show_qr_code_button_title" android:icon="@drawable/icon_qr_code"/> + + diff --git a/src/org/thoughtcrime/securesms/ApplicationPreferencesActivity.java b/src/org/thoughtcrime/securesms/ApplicationPreferencesActivity.java index 6799c9a3c6..97e646e136 100644 --- a/src/org/thoughtcrime/securesms/ApplicationPreferencesActivity.java +++ b/src/org/thoughtcrime/securesms/ApplicationPreferencesActivity.java @@ -40,8 +40,10 @@ import android.support.v7.preference.Preference; import android.widget.Toast; import org.thoughtcrime.securesms.crypto.IdentityKeyUtil; +import org.thoughtcrime.securesms.loki.AddPublicChatActivity; import org.thoughtcrime.securesms.loki.DeviceLinkingDialog; import org.thoughtcrime.securesms.loki.DeviceLinkingView; +import org.thoughtcrime.securesms.loki.NewConversationActivity; import org.thoughtcrime.securesms.loki.QRCodeDialog; import org.thoughtcrime.securesms.preferences.AppProtectionPreferenceFragment; import org.thoughtcrime.securesms.preferences.ChatsPreferenceFragment; @@ -85,6 +87,7 @@ public class ApplicationPreferencesActivity extends PassphraseRequiredActionBarA private static final String PREFERENCE_CATEGORY_QR_CODE = "preference_category_qr_code"; private static final String PREFERENCE_CATEGORY_LINK_DEVICE = "preference_category_link_device"; private static final String PREFERENCE_CATEGORY_SEED = "preference_category_seed"; + private static final String PREFERENCE_CATEGORY_PUBLIC_CHAT = "preference_category_public_chat"; private final DynamicTheme dynamicTheme = new DynamicTheme(); private final DynamicLanguage dynamicLanguage = new DynamicLanguage(); @@ -187,6 +190,9 @@ public class ApplicationPreferencesActivity extends PassphraseRequiredActionBarA .setOnPreferenceClickListener(new CategoryClickListener(PREFERENCE_CATEGORY_PUBLIC_KEY)); this.findPreference(PREFERENCE_CATEGORY_QR_CODE) .setOnPreferenceClickListener(new CategoryClickListener(PREFERENCE_CATEGORY_QR_CODE)); + this.findPreference(PREFERENCE_CATEGORY_PUBLIC_CHAT) + .setOnPreferenceClickListener(new CategoryClickListener(PREFERENCE_CATEGORY_PUBLIC_CHAT)); + Preference linkDevicePreference = this.findPreference(PREFERENCE_CATEGORY_LINK_DEVICE); // Hide if this is a slave device linkDevicePreference.setVisible(isMasterDevice); @@ -256,6 +262,7 @@ public class ApplicationPreferencesActivity extends PassphraseRequiredActionBarA Drawable qrCode = DrawableCompat.wrap(ContextCompat.getDrawable(context, R.drawable.icon_qr_code)); Drawable linkDevice = DrawableCompat.wrap(ContextCompat.getDrawable(context, R.drawable.icon_link)); Drawable seed = DrawableCompat.wrap(ContextCompat.getDrawable(context, R.drawable.icon_seedling)); + Drawable publicChat = DrawableCompat.wrap(ContextCompat.getDrawable(context, R.drawable.ic_group_white_24dp)); int[] tintAttr = new int[]{R.attr.pref_icon_tint}; TypedArray typedArray = context.obtainStyledAttributes(tintAttr); @@ -273,6 +280,7 @@ public class ApplicationPreferencesActivity extends PassphraseRequiredActionBarA DrawableCompat.setTint(qrCode, color); DrawableCompat.setTint(linkDevice, color); DrawableCompat.setTint(seed, color); + DrawableCompat.setTint(publicChat, color); // this.findPreference(PREFERENCE_CATEGORY_SMS_MMS).setIcon(sms); this.findPreference(PREFERENCE_CATEGORY_NOTIFICATIONS).setIcon(notifications); @@ -285,6 +293,7 @@ public class ApplicationPreferencesActivity extends PassphraseRequiredActionBarA this.findPreference(PREFERENCE_CATEGORY_QR_CODE).setIcon(qrCode); this.findPreference(PREFERENCE_CATEGORY_LINK_DEVICE).setIcon(linkDevice); this.findPreference(PREFERENCE_CATEGORY_SEED).setIcon(seed); + this.findPreference(PREFERENCE_CATEGORY_PUBLIC_CHAT).setIcon(publicChat); } private class CategoryClickListener implements Preference.OnPreferenceClickListener { @@ -369,6 +378,9 @@ public class ApplicationPreferencesActivity extends PassphraseRequiredActionBarA // Do nothing } break; + case PREFERENCE_CATEGORY_PUBLIC_CHAT: + startActivity(new Intent(getActivity(), AddPublicChatActivity.class)); + break; default: throw new AssertionError(); } diff --git a/src/org/thoughtcrime/securesms/loki/AddPublicChatActivity.kt b/src/org/thoughtcrime/securesms/loki/AddPublicChatActivity.kt new file mode 100644 index 0000000000..174396f2e0 --- /dev/null +++ b/src/org/thoughtcrime/securesms/loki/AddPublicChatActivity.kt @@ -0,0 +1,81 @@ +package org.thoughtcrime.securesms.loki + +import android.Manifest +import android.content.Intent +import android.os.Bundle +import android.util.Patterns +import android.view.MenuItem +import android.view.inputmethod.InputMethodManager +import android.widget.Toast +import kotlinx.android.synthetic.main.activity_account_details.* +import kotlinx.android.synthetic.main.fragment_add_public_chat.* +import network.loki.messenger.R +import nl.komponents.kovenant.ui.failUi +import nl.komponents.kovenant.ui.successUi +import org.thoughtcrime.securesms.ApplicationContext +import org.thoughtcrime.securesms.BaseActionBarActivity +import org.thoughtcrime.securesms.PassphraseRequiredActionBarActivity +import org.thoughtcrime.securesms.conversation.ConversationActivity +import org.thoughtcrime.securesms.database.Address +import org.thoughtcrime.securesms.database.DatabaseFactory +import org.thoughtcrime.securesms.database.ThreadDatabase +import org.thoughtcrime.securesms.recipients.Recipient +import org.thoughtcrime.securesms.util.DynamicTheme +import org.thoughtcrime.securesms.util.TextSecurePreferences +import org.whispersystems.signalservice.loki.api.LokiGroupChatAPI +import org.whispersystems.signalservice.loki.utilities.Analytics +import org.whispersystems.signalservice.loki.utilities.PublicKeyValidation + +class AddPublicChatActivity : PassphraseRequiredActionBarActivity() { + private val dynamicTheme = DynamicTheme() + + override fun onPreCreate() { + dynamicTheme.onCreate(this) + } + + override fun onCreate(bundle: Bundle?, isReady: Boolean) { + supportActionBar!!.setTitle(R.string.fragment_add_public_chat_title) + supportActionBar!!.setDisplayHomeAsUpEnabled(true) + setContentView(R.layout.fragment_add_public_chat) + setButtonEnabled(true) + addButton.setOnClickListener { addPublicChatIfPossible() } + } + + public override fun onResume() { + super.onResume() + dynamicTheme.onResume(this) + } + + override fun onOptionsItemSelected(item: MenuItem): Boolean { + if (item.itemId == android.R.id.home) { + onBackPressed() + return true + } + return super.onOptionsItemSelected(item) + } + + private fun addPublicChatIfPossible() { + val inputMethodManager = getSystemService(BaseActionBarActivity.INPUT_METHOD_SERVICE) as InputMethodManager + inputMethodManager.hideSoftInputFromWindow(serverUrlEditText.windowToken, 0) + + val url = serverUrlEditText.text.toString().toLowerCase() + if (!Patterns.WEB_URL.matcher(url).matches()) { return Toast.makeText(this, R.string.fragment_add_public_chat_invalid_url_message, Toast.LENGTH_SHORT).show() } + + setButtonEnabled(false) + + ApplicationContext.getInstance(this).lokiPublicChatManager.addChat(url, 1).successUi { + Toast.makeText(this, R.string.fragment_add_public_chat_success_message, Toast.LENGTH_SHORT).show() + finish() + }.failUi { + setButtonEnabled(true) + Toast.makeText(this, R.string.fragment_add_public_chat_failed_connect_message, Toast.LENGTH_SHORT).show() + } + } + + private fun setButtonEnabled(enabled: Boolean) { + addButton.isEnabled = enabled + val text = if (enabled) R.string.fragment_add_public_chat_add_button_title else R.string.fragment_add_public_chat_adding_server_button_title + addButton.setText(text) + serverUrlEditText.isEnabled = enabled + } +} \ No newline at end of file diff --git a/src/org/thoughtcrime/securesms/loki/LokiPublicChatManager.kt b/src/org/thoughtcrime/securesms/loki/LokiPublicChatManager.kt index bec1b1f1f1..6ee7c68480 100644 --- a/src/org/thoughtcrime/securesms/loki/LokiPublicChatManager.kt +++ b/src/org/thoughtcrime/securesms/loki/LokiPublicChatManager.kt @@ -39,7 +39,7 @@ class LokiPublicChatManager(private val context: Context) { } public fun addChat(server: String, channel: Long): Promise { - val groupChatAPI = ApplicationContext.getInstance(context).lokiGroupChatAPI ?: return Promise.ofFail(IllegalStateException()) + val groupChatAPI = ApplicationContext.getInstance(context).lokiGroupChatAPI ?: return Promise.ofFail(IllegalStateException("LokiGroupChatAPI is not set!")) return groupChatAPI.getAuthToken(server).bind { groupChatAPI.getChannelInfo(channel, server) }.map {