mirror of
https://github.com/oxen-io/session-android.git
synced 2025-02-20 08:08:26 +00:00
add logic and UI in create private chat view
This commit is contained in:
parent
ae23266058
commit
e6cdd3ee0e
@ -1,5 +1,7 @@
|
|||||||
package org.thoughtcrime.securesms.loki.activities
|
package org.thoughtcrime.securesms.loki.activities
|
||||||
|
|
||||||
|
import android.animation.Animator
|
||||||
|
import android.animation.AnimatorListenerAdapter
|
||||||
import android.content.ClipData
|
import android.content.ClipData
|
||||||
import android.content.ClipboardManager
|
import android.content.ClipboardManager
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
@ -13,8 +15,14 @@ import android.view.inputmethod.EditorInfo
|
|||||||
import android.view.inputmethod.InputMethodManager
|
import android.view.inputmethod.InputMethodManager
|
||||||
import android.widget.Toast
|
import android.widget.Toast
|
||||||
import kotlinx.android.synthetic.main.activity_create_private_chat.*
|
import kotlinx.android.synthetic.main.activity_create_private_chat.*
|
||||||
|
import kotlinx.android.synthetic.main.activity_create_private_chat.loader
|
||||||
|
import kotlinx.android.synthetic.main.activity_create_private_chat.tabLayout
|
||||||
|
import kotlinx.android.synthetic.main.activity_create_private_chat.viewPager
|
||||||
|
import kotlinx.android.synthetic.main.activity_join_public_chat.*
|
||||||
import kotlinx.android.synthetic.main.fragment_enter_public_key.*
|
import kotlinx.android.synthetic.main.fragment_enter_public_key.*
|
||||||
|
import kotlinx.android.synthetic.main.permissions_rationale_dialog.*
|
||||||
import network.loki.messenger.R
|
import network.loki.messenger.R
|
||||||
|
import org.session.libsession.snode.SnodeAPI
|
||||||
import org.thoughtcrime.securesms.PassphraseRequiredActionBarActivity
|
import org.thoughtcrime.securesms.PassphraseRequiredActionBarActivity
|
||||||
import org.thoughtcrime.securesms.conversation.ConversationActivity
|
import org.thoughtcrime.securesms.conversation.ConversationActivity
|
||||||
import org.session.libsession.utilities.Address
|
import org.session.libsession.utilities.Address
|
||||||
@ -48,6 +56,23 @@ class CreatePrivateChatActivity : PassphraseRequiredActionBarActivity(), ScanQRC
|
|||||||
}
|
}
|
||||||
// endregion
|
// endregion
|
||||||
|
|
||||||
|
// region Updating
|
||||||
|
private fun showLoader() {
|
||||||
|
loader.visibility = View.VISIBLE
|
||||||
|
loader.animate().setDuration(150).alpha(1.0f).start()
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun hideLoader() {
|
||||||
|
loader.animate().setDuration(150).alpha(0.0f).setListener(object : AnimatorListenerAdapter() {
|
||||||
|
|
||||||
|
override fun onAnimationEnd(animation: Animator?) {
|
||||||
|
super.onAnimationEnd(animation)
|
||||||
|
loader.visibility = View.GONE
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
// endregion
|
||||||
|
|
||||||
// region Interaction
|
// region Interaction
|
||||||
override fun onOptionsItemSelected(item: MenuItem): Boolean {
|
override fun onOptionsItemSelected(item: MenuItem): Boolean {
|
||||||
when(item.itemId) {
|
when(item.itemId) {
|
||||||
@ -60,8 +85,27 @@ class CreatePrivateChatActivity : PassphraseRequiredActionBarActivity(), ScanQRC
|
|||||||
createPrivateChatIfPossible(hexEncodedPublicKey)
|
createPrivateChatIfPossible(hexEncodedPublicKey)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun createPrivateChatIfPossible(hexEncodedPublicKey: String) {
|
fun createPrivateChatIfPossible(onsNameOrPublicKey: String) {
|
||||||
if (!PublicKeyValidation.isValid(hexEncodedPublicKey)) { return Toast.makeText(this, R.string.invalid_session_id, Toast.LENGTH_SHORT).show() }
|
if (!PublicKeyValidation.isValid(onsNameOrPublicKey)) {
|
||||||
|
createPrivateChat(onsNameOrPublicKey)
|
||||||
|
} else {
|
||||||
|
// This could be an ONS name
|
||||||
|
showLoader()
|
||||||
|
SnodeAPI.getSessionIDFor(onsNameOrPublicKey).success { hexEncodedPublicKey ->
|
||||||
|
hideLoader()
|
||||||
|
this.createPrivateChat(hexEncodedPublicKey)
|
||||||
|
}.fail { exception ->
|
||||||
|
hideLoader()
|
||||||
|
var message = "Please check the Session ID or ONS name and try again."
|
||||||
|
exception.localizedMessage?.let {
|
||||||
|
message = it
|
||||||
|
}
|
||||||
|
Toast.makeText(this, message, Toast.LENGTH_SHORT).show()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun createPrivateChat(hexEncodedPublicKey: String) {
|
||||||
val recipient = Recipient.from(this, Address.fromSerialized(hexEncodedPublicKey), false)
|
val recipient = Recipient.from(this, Address.fromSerialized(hexEncodedPublicKey), false)
|
||||||
val intent = Intent(this, ConversationActivity::class.java)
|
val intent = Intent(this, ConversationActivity::class.java)
|
||||||
intent.putExtra(ConversationActivity.ADDRESS_EXTRA, recipient.address)
|
intent.putExtra(ConversationActivity.ADDRESS_EXTRA, recipient.address)
|
||||||
|
@ -1,14 +1,40 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<androidx.viewpager.widget.ViewPager
|
<RelativeLayout
|
||||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
android:id="@+id/viewPager"
|
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent" >
|
android:layout_height="match_parent">
|
||||||
|
|
||||||
<com.google.android.material.tabs.TabLayout
|
<androidx.viewpager.widget.ViewPager
|
||||||
style="@style/Widget.Session.TabLayout"
|
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
android:id="@+id/tabLayout"
|
android:id="@+id/viewPager"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="@dimen/tab_bar_height" />
|
android:layout_height="match_parent" >
|
||||||
|
|
||||||
</androidx.viewpager.widget.ViewPager>
|
<com.google.android.material.tabs.TabLayout
|
||||||
|
style="@style/Widget.Session.TabLayout"
|
||||||
|
android:id="@+id/tabLayout"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="@dimen/tab_bar_height" />
|
||||||
|
|
||||||
|
</androidx.viewpager.widget.ViewPager>
|
||||||
|
|
||||||
|
<RelativeLayout
|
||||||
|
android:id="@+id/loader"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:background="#A4000000"
|
||||||
|
android:visibility="gone"
|
||||||
|
android:alpha="0">
|
||||||
|
|
||||||
|
<com.github.ybq.android.spinkit.SpinKitView
|
||||||
|
style="@style/SpinKitView.Large.ThreeBounce"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginTop="8dp"
|
||||||
|
android:layout_centerInParent="true"
|
||||||
|
app:SpinKit_Color="@android:color/white" />
|
||||||
|
|
||||||
|
</RelativeLayout>
|
||||||
|
|
||||||
|
</RelativeLayout>
|
Loading…
x
Reference in New Issue
Block a user