mirror of
https://github.com/oxen-io/session-android.git
synced 2025-12-03 11:03:07 +00:00
Implement new private chat screen redesign
This commit is contained in:
@@ -10,13 +10,13 @@ import org.thoughtcrime.securesms.PassphraseRequiredActionBarActivity
|
||||
import org.thoughtcrime.securesms.conversation.ConversationActivity
|
||||
import org.thoughtcrime.securesms.database.DatabaseFactory
|
||||
import org.thoughtcrime.securesms.database.model.ThreadRecord
|
||||
import org.thoughtcrime.securesms.loki.NewConversationActivity
|
||||
import org.thoughtcrime.securesms.loki.redesign.utilities.push
|
||||
import org.thoughtcrime.securesms.loki.redesign.views.ConversationView
|
||||
import org.thoughtcrime.securesms.util.TextSecurePreferences
|
||||
|
||||
class HomeActivity : PassphraseRequiredActionBarActivity, ConversationClickListener {
|
||||
|
||||
// region Lifecycle
|
||||
constructor() : super()
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?, isReady: Boolean) {
|
||||
@@ -27,7 +27,7 @@ class HomeActivity : PassphraseRequiredActionBarActivity, ConversationClickListe
|
||||
supportActionBar!!.title = "Messages"
|
||||
// Set up recycler view
|
||||
val cursor = DatabaseFactory.getThreadDatabase(this).conversationList
|
||||
val conversationAdapter = ConversationAdapter(this, cursor)
|
||||
val conversationAdapter = HomeAdapter(this, cursor)
|
||||
conversationAdapter.conversationClickListener = this
|
||||
recyclerView.adapter = conversationAdapter
|
||||
recyclerView.layoutManager = LinearLayoutManager(this)
|
||||
@@ -42,6 +42,7 @@ class HomeActivity : PassphraseRequiredActionBarActivity, ConversationClickListe
|
||||
application.startRSSFeedPollersIfNeeded()
|
||||
}
|
||||
}
|
||||
// endregion
|
||||
|
||||
override fun onConversationClick(view: ConversationView) {
|
||||
val thread = view.thread ?: return
|
||||
@@ -64,7 +65,7 @@ class HomeActivity : PassphraseRequiredActionBarActivity, ConversationClickListe
|
||||
}
|
||||
|
||||
private fun createPrivateChat() {
|
||||
val intent = Intent(this, NewConversationActivity::class.java)
|
||||
val intent = Intent(this, NewPrivateChatActivity::class.java)
|
||||
startActivity(intent)
|
||||
}
|
||||
}
|
||||
@@ -9,7 +9,7 @@ import org.thoughtcrime.securesms.database.DatabaseFactory
|
||||
import org.thoughtcrime.securesms.database.model.ThreadRecord
|
||||
import org.thoughtcrime.securesms.loki.redesign.views.ConversationView
|
||||
|
||||
class ConversationAdapter(context: Context, cursor: Cursor) : CursorRecyclerViewAdapter<ConversationAdapter.ViewHolder>(context, cursor) {
|
||||
class HomeAdapter(context: Context, cursor: Cursor) : CursorRecyclerViewAdapter<HomeAdapter.ViewHolder>(context, cursor) {
|
||||
private val threadDatabase = DatabaseFactory.getThreadDatabase(context)
|
||||
var conversationClickListener: ConversationClickListener? = null
|
||||
|
||||
@@ -30,7 +30,7 @@ class ConversationAdapter(context: Context, cursor: Cursor) : CursorRecyclerView
|
||||
}
|
||||
|
||||
private fun getThread(cursor: Cursor): ThreadRecord? {
|
||||
return threadDatabase.readerFor(cursor).getCurrent()
|
||||
return threadDatabase.readerFor(cursor).current
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,63 @@
|
||||
package org.thoughtcrime.securesms.loki.redesign.activities
|
||||
|
||||
import android.os.Bundle
|
||||
import android.support.v4.app.Fragment
|
||||
import android.support.v4.app.FragmentManager
|
||||
import android.support.v4.app.FragmentPagerAdapter
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import kotlinx.android.synthetic.main.activity_new_private_chat.*
|
||||
import kotlinx.android.synthetic.main.fragment_enter_public_key.*
|
||||
import network.loki.messenger.R
|
||||
import org.thoughtcrime.securesms.BaseActionBarActivity
|
||||
|
||||
class NewPrivateChatActivity : BaseActionBarActivity() {
|
||||
private val adapter = Adapter(supportFragmentManager)
|
||||
|
||||
// region Lifecycle
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
// Set content view
|
||||
setContentView(R.layout.activity_new_private_chat)
|
||||
// Set title
|
||||
supportActionBar!!.title = "New Conversation"
|
||||
// Set up view pager
|
||||
viewPager.adapter = adapter
|
||||
tabLayout.setupWithViewPager(viewPager)
|
||||
}
|
||||
// endregion
|
||||
}
|
||||
|
||||
// region Adapter
|
||||
private class Adapter(manager: FragmentManager) : FragmentPagerAdapter(manager) {
|
||||
|
||||
override fun getCount(): Int {
|
||||
return 2
|
||||
}
|
||||
|
||||
override fun getItem(index: Int): Fragment {
|
||||
return EnterPublicKeyFragment()
|
||||
}
|
||||
|
||||
override fun getPageTitle(index: Int): CharSequence? {
|
||||
return when (index) {
|
||||
0 -> "Enter Public Key"
|
||||
1 -> "Scan QR Code"
|
||||
else -> throw IllegalStateException()
|
||||
}
|
||||
}
|
||||
}
|
||||
// endregion
|
||||
|
||||
class EnterPublicKeyFragment : Fragment() {
|
||||
|
||||
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View {
|
||||
return inflater.inflate(R.layout.fragment_enter_public_key, container, false)
|
||||
}
|
||||
|
||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||
super.onViewCreated(view, savedInstanceState)
|
||||
separatorView.title = "Test"
|
||||
}
|
||||
}
|
||||
@@ -6,7 +6,7 @@ import android.util.AttributeSet
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.widget.LinearLayout
|
||||
import kotlinx.android.synthetic.main.conversation_view.view.*
|
||||
import kotlinx.android.synthetic.main.view_conversation.view.*
|
||||
import network.loki.messenger.R
|
||||
import org.thoughtcrime.securesms.database.model.ThreadRecord
|
||||
import org.thoughtcrime.securesms.loki.LokiAPIUtilities.populateUserHexEncodedPublicKeyCacheIfNeeded
|
||||
@@ -37,7 +37,7 @@ class ConversationView : LinearLayout {
|
||||
|
||||
private fun setUpViewHierarchy() {
|
||||
val inflater = context.applicationContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE) as LayoutInflater
|
||||
val contentView = inflater.inflate(R.layout.conversation_view, null)
|
||||
val contentView = inflater.inflate(R.layout.view_conversation, null)
|
||||
addView(contentView)
|
||||
}
|
||||
// endregion
|
||||
|
||||
@@ -7,7 +7,7 @@ import android.util.AttributeSet
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.widget.ScrollView
|
||||
import kotlinx.android.synthetic.main.fake_chat_view.view.*
|
||||
import kotlinx.android.synthetic.main.view_fake_chat.view.*
|
||||
import network.loki.messenger.R
|
||||
|
||||
class FakeChatView : ScrollView {
|
||||
@@ -38,7 +38,7 @@ class FakeChatView : ScrollView {
|
||||
|
||||
private fun setUpViewHierarchy() {
|
||||
val inflater = context.applicationContext.getSystemService(LAYOUT_INFLATER_SERVICE) as LayoutInflater
|
||||
val contentView = inflater.inflate(R.layout.fake_chat_view, null)
|
||||
val contentView = inflater.inflate(R.layout.view_fake_chat, null)
|
||||
addView(contentView)
|
||||
isVerticalScrollBarEnabled = false
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@ import android.util.AttributeSet
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.widget.RelativeLayout
|
||||
import kotlinx.android.synthetic.main.profile_picture_view.view.*
|
||||
import kotlinx.android.synthetic.main.view_profile_picture.view.*
|
||||
import network.loki.messenger.R
|
||||
|
||||
class ProfilePictureView : RelativeLayout {
|
||||
@@ -32,10 +32,12 @@ class ProfilePictureView : RelativeLayout {
|
||||
|
||||
private fun setUpViewHierarchy() {
|
||||
val inflater = context.applicationContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE) as LayoutInflater
|
||||
val contentView = inflater.inflate(R.layout.profile_picture_view, null)
|
||||
val contentView = inflater.inflate(R.layout.view_profile_picture, null)
|
||||
addView(contentView)
|
||||
}
|
||||
// endregion
|
||||
|
||||
// region Updating
|
||||
fun update() {
|
||||
val hexEncodedPublicKey = hexEncodedPublicKey ?: return
|
||||
val additionalHexEncodedPublicKey = additionalHexEncodedPublicKey
|
||||
|
||||
@@ -0,0 +1,71 @@
|
||||
package org.thoughtcrime.securesms.loki.redesign.views
|
||||
|
||||
import android.content.Context
|
||||
import android.graphics.Canvas
|
||||
import android.graphics.Paint
|
||||
import android.graphics.Path
|
||||
import android.util.AttributeSet
|
||||
import android.view.LayoutInflater
|
||||
import android.widget.RelativeLayout
|
||||
import kotlinx.android.synthetic.main.view_separator.view.*
|
||||
import network.loki.messenger.R
|
||||
import org.thoughtcrime.securesms.loki.getColorWithID
|
||||
import org.thoughtcrime.securesms.loki.toPx
|
||||
|
||||
class SeparatorView : RelativeLayout {
|
||||
lateinit var title: CharSequence
|
||||
|
||||
private val path = Path()
|
||||
|
||||
private val paint: Paint = {
|
||||
val result = Paint()
|
||||
result.style = Paint.Style.STROKE
|
||||
result.color = resources.getColorWithID(R.color.separator, context.theme)
|
||||
result.strokeWidth = 2.0f
|
||||
result.isAntiAlias = true
|
||||
result
|
||||
}()
|
||||
|
||||
// region Lifecycle
|
||||
constructor(context: Context) : super(context) {
|
||||
setUpViewHierarchy()
|
||||
}
|
||||
|
||||
constructor(context: Context, attrs: AttributeSet) : super(context, attrs) {
|
||||
setUpViewHierarchy()
|
||||
}
|
||||
|
||||
constructor(context: Context, attrs: AttributeSet, defStyleAttr: Int) : super(context, attrs, defStyleAttr) {
|
||||
setUpViewHierarchy()
|
||||
}
|
||||
|
||||
constructor(context: Context, attrs: AttributeSet, defStyleAttr: Int, defStyleRes: Int) : super(context, attrs, defStyleAttr, defStyleRes) {
|
||||
setUpViewHierarchy()
|
||||
}
|
||||
|
||||
private fun setUpViewHierarchy() {
|
||||
val inflater = context.applicationContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE) as LayoutInflater
|
||||
val contentView = inflater.inflate(R.layout.view_separator, null)
|
||||
val layoutParams = LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT)
|
||||
addView(contentView, layoutParams)
|
||||
setWillNotDraw(false)
|
||||
}
|
||||
// endregion
|
||||
|
||||
// region Updating
|
||||
override fun onDraw(c: Canvas) {
|
||||
super.onDraw(c)
|
||||
val w = width.toFloat()
|
||||
val h = height.toFloat()
|
||||
val hMargin = toPx(10, resources).toFloat()
|
||||
path.reset()
|
||||
path.moveTo(0.0f, h / 2)
|
||||
path.lineTo(titleTextView.left - hMargin, h / 2)
|
||||
path.addRoundRect(titleTextView.left - hMargin, 0.0f, titleTextView.right + hMargin, h, h / 2, h / 2, Path.Direction.CCW)
|
||||
path.moveTo(titleTextView.right + hMargin, h / 2)
|
||||
path.lineTo(w, h / 2)
|
||||
path.close()
|
||||
c.drawPath(path, paint)
|
||||
}
|
||||
// endregion
|
||||
}
|
||||
Reference in New Issue
Block a user