diff --git a/AndroidManifest.xml b/AndroidManifest.xml
index 964d25e62c..33e189c2be 100644
--- a/AndroidManifest.xml
+++ b/AndroidManifest.xml
@@ -143,8 +143,12 @@
android:name="org.thoughtcrime.securesms.loki.redesign.activities.HomeActivity"
android:launchMode="singleTask" />
+
+
+
diff --git a/res/layout/activity_new_private_chat.xml b/res/layout/activity_create_private_chat.xml
similarity index 100%
rename from res/layout/activity_new_private_chat.xml
rename to res/layout/activity_create_private_chat.xml
diff --git a/res/layout/activity_join_public_chat.xml b/res/layout/activity_join_public_chat.xml
new file mode 100644
index 0000000000..d6bf8f66d7
--- /dev/null
+++ b/res/layout/activity_join_public_chat.xml
@@ -0,0 +1,14 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/res/layout/fragment_enter_chat_url.xml b/res/layout/fragment_enter_chat_url.xml
new file mode 100644
index 0000000000..512456eb9a
--- /dev/null
+++ b/res/layout/fragment_enter_chat_url.xml
@@ -0,0 +1,47 @@
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/res/layout/fragment_scan_qr_code_v2.xml b/res/layout/fragment_scan_qr_code_v2.xml
index 7da35396c7..c71bea8880 100644
--- a/res/layout/fragment_scan_qr_code_v2.xml
+++ b/res/layout/fragment_scan_qr_code_v2.xml
@@ -24,7 +24,7 @@
android:layout_height="0dp"/>
+
\ No newline at end of file
diff --git a/src/org/thoughtcrime/securesms/loki/redesign/activities/NewPrivateChatActivity.kt b/src/org/thoughtcrime/securesms/loki/redesign/activities/CreatePrivateChatActivity.kt
similarity index 67%
rename from src/org/thoughtcrime/securesms/loki/redesign/activities/NewPrivateChatActivity.kt
rename to src/org/thoughtcrime/securesms/loki/redesign/activities/CreatePrivateChatActivity.kt
index cfc15311f0..1e029fa8e4 100644
--- a/src/org/thoughtcrime/securesms/loki/redesign/activities/NewPrivateChatActivity.kt
+++ b/src/org/thoughtcrime/securesms/loki/redesign/activities/CreatePrivateChatActivity.kt
@@ -1,22 +1,17 @@
package org.thoughtcrime.securesms.loki.redesign.activities
-import android.Manifest
import android.content.ClipData
import android.content.ClipboardManager
import android.content.Context
import android.content.Intent
-import android.content.pm.PackageManager
import android.os.Bundle
import android.support.v4.app.Fragment
-import android.support.v4.app.FragmentManager
import android.support.v4.app.FragmentPagerAdapter
-import android.support.v4.content.ContextCompat
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.Toast
-import com.tbruyelle.rxpermissions2.RxPermissions
-import kotlinx.android.synthetic.main.activity_new_private_chat.*
+import kotlinx.android.synthetic.main.activity_create_private_chat.*
import kotlinx.android.synthetic.main.fragment_enter_public_key.*
import network.loki.messenger.R
import org.thoughtcrime.securesms.BaseActionBarActivity
@@ -24,22 +19,20 @@ 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.loki.redesign.fragments.ScanQRCodeFragmentV2
-import org.thoughtcrime.securesms.loki.redesign.fragments.ScanQRCodePlaceholderFragment
-import org.thoughtcrime.securesms.loki.redesign.fragments.ScanQRCodePlaceholderFragmentDelegate
-import org.thoughtcrime.securesms.qr.ScanListener
+import org.thoughtcrime.securesms.loki.redesign.fragments.ScanQRCodeWrapperFragment
+import org.thoughtcrime.securesms.loki.redesign.fragments.ScanQRCodeWrapperFragmentDelegate
import org.thoughtcrime.securesms.recipients.Recipient
import org.thoughtcrime.securesms.util.TextSecurePreferences
import org.whispersystems.signalservice.loki.utilities.PublicKeyValidation
-class NewPrivateChatActivity : BaseActionBarActivity() {
- private val adapter = Adapter(supportFragmentManager)
+class CreatePrivateChatActivity : BaseActionBarActivity(), ScanQRCodeWrapperFragmentDelegate {
+ private val adapter = CreatePrivateChatActivityAdapter(this)
// region Lifecycle
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
// Set content view
- setContentView(R.layout.activity_new_private_chat)
+ setContentView(R.layout.activity_create_private_chat)
// Set title
supportActionBar!!.title = "New Conversation"
// Set up view pager
@@ -49,6 +42,10 @@ class NewPrivateChatActivity : BaseActionBarActivity() {
// endregion
// region Interaction
+ override fun handleQRCodeScanned(hexEncodedPublicKey: String) {
+ createPrivateChatIfPossible(hexEncodedPublicKey)
+ }
+
fun createPrivateChatIfPossible(hexEncodedPublicKey: String) {
if (!PublicKeyValidation.isValid(hexEncodedPublicKey)) { return Toast.makeText(this, "Invalid Session ID", Toast.LENGTH_SHORT).show() }
val masterHexEncodedPublicKey = TextSecurePreferences.getMasterHexEncodedPublicKey(this)
@@ -69,7 +66,7 @@ class NewPrivateChatActivity : BaseActionBarActivity() {
}
// region Adapter
-private class Adapter(manager: FragmentManager) : FragmentPagerAdapter(manager) {
+private class CreatePrivateChatActivityAdapter(val activity: CreatePrivateChatActivity) : FragmentPagerAdapter(activity.supportFragmentManager) {
override fun getCount(): Int {
return 2
@@ -78,7 +75,12 @@ private class Adapter(manager: FragmentManager) : FragmentPagerAdapter(manager)
override fun getItem(index: Int): Fragment {
return when (index) {
0 -> EnterPublicKeyFragment()
- 1 -> ScanQRCodeWrapperFragment()
+ 1 -> {
+ val result = ScanQRCodeWrapperFragment()
+ result.delegate = activity
+ result.message = "Users can share their QR code by going into their account settings and tapping "Share QR Code""
+ result
+ }
else -> throw IllegalStateException()
}
}
@@ -95,6 +97,7 @@ private class Adapter(manager: FragmentManager) : FragmentPagerAdapter(manager)
// region Enter Public Key Fragment
class EnterPublicKeyFragment : Fragment() {
+
private val hexEncodedPublicKey: String
get() {
val masterHexEncodedPublicKey = TextSecurePreferences.getMasterHexEncodedPublicKey(context!!)
@@ -131,51 +134,7 @@ class EnterPublicKeyFragment : Fragment() {
private fun createPrivateChatIfPossible() {
val hexEncodedPublicKey = publicKeyEditText.text.trim().toString()
- (activity!! as NewPrivateChatActivity).createPrivateChatIfPossible(hexEncodedPublicKey)
+ (activity!! as CreatePrivateChatActivity).createPrivateChatIfPossible(hexEncodedPublicKey)
}
}
// endregion
-
-// region Scan QR Code Wrapper Fragment
-class ScanQRCodeWrapperFragment : Fragment(), ScanQRCodePlaceholderFragmentDelegate, ScanListener {
-
- override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
- return inflater.inflate(R.layout.fragment_scan_qr_code_wrapper, container, false)
- }
-
- override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
- super.onViewCreated(view, savedInstanceState)
- update()
- }
-
- private fun update() {
- val fragment: Fragment
- if (ContextCompat.checkSelfPermission(activity!!, Manifest.permission.CAMERA) == PackageManager.PERMISSION_GRANTED) {
- val scanQRCodeFragment = ScanQRCodeFragmentV2()
- scanQRCodeFragment.scanListener = this
- fragment = scanQRCodeFragment
- } else {
- val scanQRCodePlaceholderFragment = ScanQRCodePlaceholderFragment()
- scanQRCodePlaceholderFragment.delegate = this
- fragment = scanQRCodePlaceholderFragment
- }
- val transaction = childFragmentManager.beginTransaction()
- transaction.replace(R.id.fragmentContainer, fragment)
- transaction.commit()
- }
-
- override fun requestCameraAccess() {
- @SuppressWarnings("unused")
- val unused = RxPermissions(this).request(Manifest.permission.CAMERA).subscribe { isGranted ->
- if (isGranted) {
- update()
- }
- }
- }
-
- override fun onQrDataFound(hexEncodedPublicKey: String) {
- val activity = activity!! as NewPrivateChatActivity
- activity.createPrivateChatIfPossible(hexEncodedPublicKey)
- }
-}
-// endregion
\ No newline at end of file
diff --git a/src/org/thoughtcrime/securesms/loki/redesign/activities/HomeActivity.kt b/src/org/thoughtcrime/securesms/loki/redesign/activities/HomeActivity.kt
index 95a7f8aca7..da88fbef8b 100644
--- a/src/org/thoughtcrime/securesms/loki/redesign/activities/HomeActivity.kt
+++ b/src/org/thoughtcrime/securesms/loki/redesign/activities/HomeActivity.kt
@@ -3,6 +3,8 @@ package org.thoughtcrime.securesms.loki.redesign.activities
import android.content.Intent
import android.os.Bundle
import android.support.v7.widget.LinearLayoutManager
+import android.view.Menu
+import android.view.MenuItem
import kotlinx.android.synthetic.main.activity_home.*
import network.loki.messenger.R
import org.thoughtcrime.securesms.ApplicationContext
@@ -42,8 +44,23 @@ class HomeActivity : PassphraseRequiredActionBarActivity, ConversationClickListe
application.startRSSFeedPollersIfNeeded()
}
}
+
+ override fun onCreateOptionsMenu(menu: Menu?): Boolean {
+ menuInflater.inflate(R.menu.menu_home, menu)
+ return true
+ }
// endregion
+ // region Interaction
+ override fun onOptionsItemSelected(item: MenuItem): Boolean {
+ val id = item.getItemId()
+ when (id) {
+ R.id.joinPublicChatItem -> joinPublicChat()
+ else -> { /* Do nothing */ }
+ }
+ return super.onOptionsItemSelected(item)
+ }
+
override fun onConversationClick(view: ConversationView) {
val thread = view.thread ?: return
openConversation(thread)
@@ -65,7 +82,13 @@ class HomeActivity : PassphraseRequiredActionBarActivity, ConversationClickListe
}
private fun createPrivateChat() {
- val intent = Intent(this, NewPrivateChatActivity::class.java)
+ val intent = Intent(this, CreatePrivateChatActivity::class.java)
startActivity(intent)
}
+
+ private fun joinPublicChat() {
+ val intent = Intent(this, JoinPublicChatActivity::class.java)
+ startActivity(intent)
+ }
+ // endregion
}
\ No newline at end of file
diff --git a/src/org/thoughtcrime/securesms/loki/redesign/activities/JoinPublicChatActivity.kt b/src/org/thoughtcrime/securesms/loki/redesign/activities/JoinPublicChatActivity.kt
new file mode 100644
index 0000000000..266fc67bda
--- /dev/null
+++ b/src/org/thoughtcrime/securesms/loki/redesign/activities/JoinPublicChatActivity.kt
@@ -0,0 +1,90 @@
+package org.thoughtcrime.securesms.loki.redesign.activities
+
+import android.os.Bundle
+import android.support.v4.app.Fragment
+import android.support.v4.app.FragmentPagerAdapter
+import android.view.LayoutInflater
+import android.view.View
+import android.view.ViewGroup
+import kotlinx.android.synthetic.main.activity_join_public_chat.*
+import kotlinx.android.synthetic.main.fragment_enter_chat_url.*
+import network.loki.messenger.R
+import org.thoughtcrime.securesms.BaseActionBarActivity
+import org.thoughtcrime.securesms.loki.redesign.fragments.ScanQRCodeWrapperFragment
+import org.thoughtcrime.securesms.loki.redesign.fragments.ScanQRCodeWrapperFragmentDelegate
+
+class JoinPublicChatActivity : BaseActionBarActivity(), ScanQRCodeWrapperFragmentDelegate {
+ private val adapter = JoinPublicChatActivityAdapter(this)
+
+ // region Lifecycle
+ override fun onCreate(savedInstanceState: Bundle?) {
+ super.onCreate(savedInstanceState)
+ // Set content view
+ setContentView(R.layout.activity_join_public_chat)
+ // Set title
+ supportActionBar!!.title = "Join Public Chat"
+ // Set up view pager
+ viewPager.adapter = adapter
+ tabLayout.setupWithViewPager(viewPager)
+ }
+ // endregion
+
+ // region Interaction
+ override fun handleQRCodeScanned(url: String) {
+ joinPublicChatIfPossible(url)
+ }
+
+ fun joinPublicChatIfPossible(url: String) {
+ // TODO: Implement
+ }
+ // endregion
+}
+
+// region Adapter
+private class JoinPublicChatActivityAdapter(val activity: JoinPublicChatActivity) : FragmentPagerAdapter(activity.supportFragmentManager) {
+
+ override fun getCount(): Int {
+ return 2
+ }
+
+ override fun getItem(index: Int): Fragment {
+ return when (index) {
+ 0 -> EnterChatURLFragment()
+ 1 -> {
+ val result = ScanQRCodeWrapperFragment()
+ result.delegate = activity
+ result.message = "Scan the QR code of the public chat you'd like to join"
+ result
+ }
+ else -> throw IllegalStateException()
+ }
+ }
+
+ override fun getPageTitle(index: Int): CharSequence? {
+ return when (index) {
+ 0 -> "Enter Chat URL"
+ 1 -> "Scan QR Code"
+ else -> throw IllegalStateException()
+ }
+ }
+}
+// endregion
+
+// region Enter Public Key Fragment
+class EnterChatURLFragment : Fragment() {
+
+ override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View {
+ return inflater.inflate(R.layout.fragment_enter_chat_url, container, false)
+ }
+
+ override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
+ super.onViewCreated(view, savedInstanceState)
+ joinPublicChatButton.setOnClickListener { joinPublicChatIfPossible() }
+ }
+
+ private fun joinPublicChatIfPossible() {
+ val chatURL = chatURLEditText.text.trim().toString()
+ (activity!! as JoinPublicChatActivity).joinPublicChatIfPossible(chatURL)
+ }
+}
+// endregion
\ No newline at end of file
diff --git a/src/org/thoughtcrime/securesms/loki/redesign/fragments/ScanQRCodeFragmentV2.kt b/src/org/thoughtcrime/securesms/loki/redesign/fragments/ScanQRCodeFragmentV2.kt
index e4e93e7f17..a9978a95bc 100644
--- a/src/org/thoughtcrime/securesms/loki/redesign/fragments/ScanQRCodeFragmentV2.kt
+++ b/src/org/thoughtcrime/securesms/loki/redesign/fragments/ScanQRCodeFragmentV2.kt
@@ -7,16 +7,16 @@ import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.LinearLayout
-import kotlinx.android.synthetic.main.fragment_scan_qr_code.*
+import kotlinx.android.synthetic.main.fragment_scan_qr_code_v2.*
import network.loki.messenger.R
import org.thoughtcrime.securesms.qr.ScanListener
import org.thoughtcrime.securesms.qr.ScanningThread
class ScanQRCodeFragmentV2 : Fragment() {
private val scanningThread = ScanningThread()
- private var viewCreated = false
var scanListener: ScanListener? = null
set(value) { field = value; scanningThread.setScanListener(scanListener) }
+ var message: CharSequence = ""
override fun onCreateView(layoutInflater: LayoutInflater, viewGroup: ViewGroup?, bundle: Bundle?): View? {
return layoutInflater.inflate(R.layout.fragment_scan_qr_code_v2, viewGroup, false)
@@ -24,11 +24,11 @@ class ScanQRCodeFragmentV2 : Fragment() {
override fun onViewCreated(view: View, bundle: Bundle?) {
super.onViewCreated(view, bundle)
- viewCreated = true
when (resources.configuration.orientation) {
Configuration.ORIENTATION_LANDSCAPE -> overlayView.orientation = LinearLayout.HORIZONTAL
else -> overlayView.orientation = LinearLayout.VERTICAL
}
+ messageTextView.text = message
}
override fun onResume() {
diff --git a/src/org/thoughtcrime/securesms/loki/redesign/fragments/ScanQRCodeWrapperFragment.kt b/src/org/thoughtcrime/securesms/loki/redesign/fragments/ScanQRCodeWrapperFragment.kt
new file mode 100644
index 0000000000..e3bc7b4ca6
--- /dev/null
+++ b/src/org/thoughtcrime/securesms/loki/redesign/fragments/ScanQRCodeWrapperFragment.kt
@@ -0,0 +1,62 @@
+package org.thoughtcrime.securesms.loki.redesign.fragments
+
+import android.Manifest
+import android.content.pm.PackageManager
+import android.os.Bundle
+import android.support.v4.app.Fragment
+import android.support.v4.content.ContextCompat
+import android.view.LayoutInflater
+import android.view.View
+import android.view.ViewGroup
+import com.tbruyelle.rxpermissions2.RxPermissions
+import network.loki.messenger.R
+import org.thoughtcrime.securesms.qr.ScanListener
+
+class ScanQRCodeWrapperFragment : Fragment(), ScanQRCodePlaceholderFragmentDelegate, ScanListener {
+ var delegate: ScanQRCodeWrapperFragmentDelegate? = null
+ var message: CharSequence = ""
+
+ override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
+ return inflater.inflate(R.layout.fragment_scan_qr_code_wrapper, container, false)
+ }
+
+ override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
+ super.onViewCreated(view, savedInstanceState)
+ update()
+ }
+
+ private fun update() {
+ val fragment: Fragment
+ if (ContextCompat.checkSelfPermission(activity!!, Manifest.permission.CAMERA) == PackageManager.PERMISSION_GRANTED) {
+ val scanQRCodeFragment = ScanQRCodeFragmentV2()
+ scanQRCodeFragment.scanListener = this
+ scanQRCodeFragment.message = message
+ fragment = scanQRCodeFragment
+ } else {
+ val scanQRCodePlaceholderFragment = ScanQRCodePlaceholderFragment()
+ scanQRCodePlaceholderFragment.delegate = this
+ fragment = scanQRCodePlaceholderFragment
+ }
+ val transaction = childFragmentManager.beginTransaction()
+ transaction.replace(R.id.fragmentContainer, fragment)
+ transaction.commit()
+ }
+
+ override fun requestCameraAccess() {
+ @SuppressWarnings("unused")
+ val unused = RxPermissions(this).request(Manifest.permission.CAMERA).subscribe { isGranted ->
+ if (isGranted) {
+ update()
+ }
+ }
+ }
+
+ override fun onQrDataFound(string: String) {
+ delegate?.handleQRCodeScanned(string)
+ }
+}
+
+interface ScanQRCodeWrapperFragmentDelegate {
+
+ fun handleQRCodeScanned(string: String)
+}
\ No newline at end of file