Implement profile picture view

This commit is contained in:
Niels Andriesse 2019-12-17 16:24:42 +01:00
parent a2776cde0f
commit 5c2b33bfdc
16 changed files with 174 additions and 24 deletions

View File

@ -5,7 +5,7 @@
android:interpolator="@android:anim/decelerate_interpolator">
<scale
android:duration="150"
android:duration="250"
android:fromXScale="1.0"
android:fromYScale="1.0"
android:toXScale="0.85"
@ -14,7 +14,7 @@
android:pivotY="50%" />
<alpha
android:duration="150"
android:duration="250"
android:fromAlpha="1.0"
android:toAlpha="0.6" />

View File

@ -5,7 +5,7 @@
android:interpolator="@android:anim/decelerate_interpolator">
<translate
android:duration="150"
android:duration="250"
android:fromXDelta="-100%"
android:toXDelta="0%" />

View File

@ -5,7 +5,7 @@
android:interpolator="@android:anim/decelerate_interpolator">
<translate
android:duration="150"
android:duration="250"
android:fromXDelta="100%"
android:toXDelta="0%" />

View File

@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<shape
xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:color="@color/unimportant" />
<corners android:radius="23dp" />
<stroke android:width="@dimen/profile_picture_border_thickness" android:color="@color/border" />
</shape>

View File

@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<shape
xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:color="#353535" />
<corners android:radius="23dp" />
<stroke android:width="@dimen/profile_picture_border_thickness" android:color="@color/border" />
</shape>

View File

@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<shape
xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:color="@color/unimportant" />
<corners android:radius="18dp" />
<stroke android:width="@dimen/profile_picture_border_thickness" android:color="@color/border" />
</shape>

View File

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<org.thoughtcrime.securesms.loki.redesign.views.ConversationView
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
@ -13,13 +13,13 @@
android:layout_height="match_parent"
android:background="@color/accent" />
<View
<org.thoughtcrime.securesms.loki.redesign.views.ProfilePictureView
android:id="@+id/profilePictureView"
android:layout_width="@dimen/medium_profile_picture_size"
android:layout_height="@dimen/medium_profile_picture_size"
android:layout_marginTop="@dimen/medium_spacing"
android:layout_marginLeft="@dimen/medium_spacing"
android:layout_marginBottom="@dimen/medium_spacing"
android:background="@color/unimportant" />
android:layout_marginBottom="@dimen/medium_spacing" />
<LinearLayout
android:layout_width="match_parent"
@ -95,4 +95,4 @@
</LinearLayout>
</org.thoughtcrime.securesms.loki.redesign.views.ConversationView>
</LinearLayout>

View File

@ -0,0 +1,46 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<RelativeLayout
android:id="@+id/doubleModeImageViewContainer"
android:layout_width="@dimen/medium_profile_picture_size"
android:layout_height="@dimen/medium_profile_picture_size">
<ImageView
android:id="@+id/doubleModeImageView1"
android:layout_width="@dimen/small_profile_picture_size"
android:layout_height="@dimen/small_profile_picture_size"
android:background="@drawable/profile_picture_view_small_background"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true" />
<ImageView
android:id="@+id/doubleModeImageView2"
android:layout_width="@dimen/small_profile_picture_size"
android:layout_height="@dimen/small_profile_picture_size"
android:background="@drawable/profile_picture_view_small_background"
android:layout_alignParentRight="true"
android:layout_alignParentBottom="true" />
</RelativeLayout>
<ImageView
android:id="@+id/singleModeImageView"
android:layout_width="@dimen/medium_profile_picture_size"
android:layout_height="@dimen/medium_profile_picture_size"
android:background="@drawable/profile_picture_view_medium_background" />
<TextView
android:id="@+id/rssTextView"
android:layout_width="@dimen/medium_profile_picture_size"
android:layout_height="@dimen/medium_profile_picture_size"
android:gravity="center"
android:text="RSS"
android:textColor="@color/text"
android:textSize="@dimen/small_font_size"
android:background="@drawable/profile_picture_view_rss_medium_background" />
</RelativeLayout>

View File

@ -5,6 +5,7 @@
<color name="accent">#00F782</color>
<color name="text">#FFFFFF</color>
<color name="unimportant">#D8D8D8</color>
<color name="border">#979797</color>
<color name="cell_background">#1B1B1B</color>
<color name="cell_selected">#0C0C0C</color>
<color name="action_bar_background">#171717</color>

View File

@ -14,9 +14,11 @@
<!-- Element Sizes -->
<dimen name="medium_button_height">48dp</dimen>
<dimen name="accent_line_thickness">4dp</dimen>
<dimen name="medium_profile_picture_size">45dp</dimen>
<dimen name="small_profile_picture_size">36dp</dimen>
<dimen name="medium_profile_picture_size">46dp</dimen>
<dimen name="conversation_view_status_indicator_size">14dp</dimen>
<dimen name="border_thickness">2dp</dimen>
<dimen name="profile_picture_border_thickness">1dp</dimen>
<dimen name="new_conversation_button_size">56dp</dimen>
<dimen name="text_view_corner_radius">8dp</dimen>
<dimen name="fake_chat_view_bubble_width">224dp</dimen>

View File

@ -16,7 +16,7 @@ class ConversationAdapter(context: Context, cursor: Cursor) : CursorRecyclerView
class ViewHolder(val view: ConversationView) : RecyclerView.ViewHolder(view)
override fun onCreateItemViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
val view = ConversationView.get(context, parent)
val view = ConversationView(context)
view.setOnClickListener { conversationClickListener?.onConversationClick(view) }
view.setOnLongClickListener {
conversationClickListener?.onLongConversationClick(view)

View File

@ -15,6 +15,7 @@ import org.thoughtcrime.securesms.loki.redesign.utilities.setUpActionBarSessionL
import org.thoughtcrime.securesms.util.TextSecurePreferences
import org.whispersystems.signalservice.api.crypto.ProfileCipher
class DisplayNameActivity : BaseActionBarActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
@ -54,7 +55,8 @@ class DisplayNameActivity : BaseActionBarActivity() {
val servers = DatabaseFactory.getLokiThreadDatabase(this).getAllPublicChatServers()
servers.forEach { publicChatAPI.setDisplayName(displayName, it) }
}
startActivity(Intent(this, ConversationListActivity::class.java))
val intent = Intent(this, ConversationListActivity::class.java)
intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TASK
push(intent)
}
}

View File

@ -5,7 +5,6 @@ import android.graphics.Typeface
import android.util.AttributeSet
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.LinearLayout
import kotlinx.android.synthetic.main.conversation_view.view.*
import network.loki.messenger.R
@ -13,26 +12,34 @@ import org.thoughtcrime.securesms.database.model.ThreadRecord
import org.thoughtcrime.securesms.loki.LokiAPIUtilities.populateUserHexEncodedPublicKeyCacheIfNeeded
import org.thoughtcrime.securesms.loki.MentionUtilities.highlightMentions
import org.thoughtcrime.securesms.util.DateUtils
import org.whispersystems.signalservice.loki.api.LokiAPI
import java.util.*
class ConversationView : LinearLayout {
var thread: ThreadRecord? = null
// region Lifecycle
companion object {
fun get(context: Context, parent: ViewGroup?): ConversationView {
return LayoutInflater.from(context).inflate(R.layout.conversation_view, parent, false) as ConversationView
}
constructor(context: Context) : super(context) {
setUpViewHierarchy()
}
constructor(context: Context) : super(context)
constructor(context: Context, attrs: AttributeSet) : super(context, attrs) {
setUpViewHierarchy()
}
constructor(context: Context, attrs: AttributeSet) : super(context, attrs)
constructor(context: Context, attrs: AttributeSet, defStyleAttr: Int) : super(context, attrs, defStyleAttr) {
setUpViewHierarchy()
}
constructor(context: Context, attrs: AttributeSet, defStyleAttr: Int) : super(context, attrs, defStyleAttr)
constructor(context: Context, attrs: AttributeSet, defStyleAttr: Int, defStyleRes: Int) : super(context, attrs, defStyleAttr, defStyleRes) {
setUpViewHierarchy()
}
constructor(context: Context, attrs: AttributeSet, defStyleAttr: Int, defStyleRes: Int) : super(context, attrs, defStyleAttr, defStyleRes)
private fun setUpViewHierarchy() {
val inflater = context.applicationContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE) as LayoutInflater
val contentView = inflater.inflate(R.layout.conversation_view, null)
addView(contentView)
}
// endregion
// region Updating
@ -40,6 +47,18 @@ class ConversationView : LinearLayout {
this.thread = thread
populateUserHexEncodedPublicKeyCacheIfNeeded(thread.threadId, context) // FIXME: This is a terrible place to do this
unreadMessagesIndicatorView.visibility = if (thread.unreadCount > 0) View.VISIBLE else View.INVISIBLE
if (thread.recipient.isGroupRecipient) {
val users = LokiAPI.userHexEncodedPublicKeyCache[thread.threadId]?.toList() ?: listOf()
val randomUsers = users.sorted() // Sort to provide a level of stability
profilePictureView.hexEncodedPublicKey = randomUsers.getOrNull(0) ?: ""
profilePictureView.additionalHexEncodedPublicKey = randomUsers.getOrNull(1) ?: ""
profilePictureView.isRSSFeed = thread.recipient.name == "Loki News" || thread.recipient.name == "Loki Messenger Updates"
} else {
profilePictureView.hexEncodedPublicKey = thread.recipient.address.toString()
profilePictureView.additionalHexEncodedPublicKey = null
profilePictureView.isRSSFeed = false
}
profilePictureView.update()
val senderDisplayName = if (thread.recipient.isLocalNumber) context.getString(R.string.note_to_self) else thread.recipient.name
displayNameTextView.text = senderDisplayName
timestampTextView.text = DateUtils.getBriefRelativeTimeSpanString(context, Locale.getDefault(), thread.date)

View File

@ -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_content_view.view.*
import kotlinx.android.synthetic.main.fake_chat_view.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_content_view, null)
val contentView = inflater.inflate(R.layout.fake_chat_view, null)
addView(contentView)
isVerticalScrollBarEnabled = false
}

View File

@ -0,0 +1,47 @@
package org.thoughtcrime.securesms.loki.redesign.views
import android.content.Context
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 network.loki.messenger.R
class ProfilePictureView : RelativeLayout {
var hexEncodedPublicKey: String? = null
var additionalHexEncodedPublicKey: String? = null
var isRSSFeed = false
// 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.profile_picture_view, null)
addView(contentView)
}
fun update() {
val hexEncodedPublicKey = hexEncodedPublicKey ?: return
val additionalHexEncodedPublicKey = additionalHexEncodedPublicKey
doubleModeImageViewContainer.visibility = if (additionalHexEncodedPublicKey != null && !isRSSFeed) View.VISIBLE else View.INVISIBLE
singleModeImageView.visibility = if (additionalHexEncodedPublicKey == null && !isRSSFeed) View.VISIBLE else View.INVISIBLE
rssTextView.visibility = if (isRSSFeed) View.VISIBLE else View.INVISIBLE
}
// endregion
}