Implement settings screen redesign

This commit is contained in:
Niels Andriesse 2020-01-06 14:26:52 +11:00
parent 1616e841da
commit c76335150c
17 changed files with 612 additions and 16 deletions

View File

@ -150,6 +150,9 @@
android:name="org.thoughtcrime.securesms.loki.redesign.activities.JoinPublicChatActivity"
android:launchMode="singleTask"
android:windowSoftInputMode="adjustResize" />
<activity
android:name="org.thoughtcrime.securesms.loki.redesign.activities.SettingsActivity"
android:launchMode="singleTask" />
<!-- Session -->
<activity android:name="org.thoughtcrime.securesms.loki.LinkedDevicesActivity" />
<activity

240
res/drawable/ic_qr_code.xml Normal file
View File

@ -0,0 +1,240 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="25dp"
android:height="25dp"
android:viewportWidth="25"
android:viewportHeight="25">
<group>
<clip-path android:pathData="M7.81,7.81H1.56V1.56h6.25V7.81zM9.38,0H0v9.38h9.38V0z M 0,0"/>
<group>
<clip-path android:pathData="M-335,-28h375v908h-375z M 0,0"/>
<path
android:pathData="M-5,-5h19.38v19.38h-19.38z"
android:fillColor="#FFFFFF"/>
</group>
</group>
<group>
<clip-path android:pathData="M3.12,3.12h3.12v3.12h-3.12z M 0,0"/>
<group>
<clip-path android:pathData="M-335,-28h375v908h-375z M 0,0"/>
<path
android:pathData="M-1.88,-1.88h13.12v13.12h-13.12z"
android:fillColor="#FFFFFF"/>
</group>
</group>
<group>
<clip-path android:pathData="M1.56,17.19h6.25v6.25H1.56V17.19zM0,25h9.38v-9.38H0V25z M 0,0"/>
<group>
<clip-path android:pathData="M-335,-28h375v908h-375z M 0,0"/>
<path
android:pathData="M-5,10.62h19.38v19.38h-19.38z"
android:fillColor="#FFFFFF"/>
</group>
</group>
<group>
<clip-path android:pathData="M3.12,18.75h3.12v3.12h-3.12z M 0,0"/>
<group>
<clip-path android:pathData="M-335,-28h375v908h-375z M 0,0"/>
<path
android:pathData="M-1.88,13.75h13.12v13.12h-13.12z"
android:fillColor="#FFFFFF"/>
</group>
</group>
<group>
<clip-path android:pathData="M23.44,7.81h-6.25V1.56h6.25V7.81zM15.62,0v9.38H25V0H15.62z M 0,0"/>
<group>
<clip-path android:pathData="M-335,-28h375v908h-375z M 0,0"/>
<path
android:pathData="M10.62,-5h19.38v19.38h-19.38z"
android:fillColor="#FFFFFF"/>
</group>
</group>
<group>
<clip-path android:pathData="M18.75,3.12h3.12v3.12h-3.12z M 0,0"/>
<group>
<clip-path android:pathData="M-335,-28h375v908h-375z M 0,0"/>
<path
android:pathData="M13.75,-1.88h13.12v13.12h-13.12z"
android:fillColor="#FFFFFF"/>
</group>
</group>
<group>
<clip-path android:pathData="M3.12,10.94l-3.12,0l0,3.12l4.69,0l0,-1.56l-1.57,0z M 0,0"/>
<group>
<clip-path android:pathData="M-335,-28h375v908h-375z M 0,0"/>
<path
android:pathData="M-5,5.94h14.69v13.12h-14.69z"
android:fillColor="#FFFFFF"/>
</group>
</group>
<group>
<clip-path android:pathData="M10.94,14.06h3.12v3.12h-3.12z M 0,0"/>
<group>
<clip-path android:pathData="M-335,-28h375v908h-375z M 0,0"/>
<path
android:pathData="M5.94,9.06h13.12v13.12h-13.12z"
android:fillColor="#FFFFFF"/>
</group>
</group>
<group>
<clip-path android:pathData="M4.69,10.94h3.12v1.56h-3.12z M 0,0"/>
<group>
<clip-path android:pathData="M-335,-28h375v908h-375z M 0,0"/>
<path
android:pathData="M-0.31,5.94h13.12v11.56h-13.12z"
android:fillColor="#FFFFFF"/>
</group>
</group>
<group>
<clip-path android:pathData="M14.06,18.75l-3.12,0l0,1.56l1.56,0l0,1.57l1.56,0l0,-1.57z M 0,0"/>
<group>
<clip-path android:pathData="M-335,-28h375v908h-375z M 0,0"/>
<path
android:pathData="M5.94,13.75h13.12v13.12h-13.12z"
android:fillColor="#FFFFFF"/>
</group>
</group>
<group>
<clip-path android:pathData="M9.38,10.94l0,1.56l-1.57,0l0,1.56l3.13,0l0,-3.12z M 0,0"/>
<group>
<clip-path android:pathData="M-335,-28h375v908h-375z M 0,0"/>
<path
android:pathData="M2.81,5.94h13.12v13.12h-13.12z"
android:fillColor="#FFFFFF"/>
</group>
</group>
<group>
<clip-path android:pathData="M12.5,6.25h1.56v3.12h-1.56z M 0,0"/>
<group>
<clip-path android:pathData="M-335,-28h375v908h-375z M 0,0"/>
<path
android:pathData="M7.5,1.25h11.56v13.12h-11.56z"
android:fillColor="#FFFFFF"/>
</group>
</group>
<group>
<clip-path android:pathData="M14.06,12.5l0,1.56l3.13,0l0,-3.12l-4.69,0l0,1.56z M 0,0"/>
<group>
<clip-path android:pathData="M-335,-28h375v908h-375z M 0,0"/>
<path
android:pathData="M7.5,5.94h14.69v13.12h-14.69z"
android:fillColor="#FFFFFF"/>
</group>
</group>
<group>
<clip-path android:pathData="M10.94,9.38h1.56v1.56h-1.56z M 0,0"/>
<group>
<clip-path android:pathData="M-335,-28h375v908h-375z M 0,0"/>
<path
android:pathData="M5.94,4.38h11.56v11.56h-11.56z"
android:fillColor="#FFFFFF"/>
</group>
</group>
<group>
<clip-path android:pathData="M14.06,21.88h3.12v3.12h-3.12z M 0,0"/>
<group>
<clip-path android:pathData="M-335,-28h375v908h-375z M 0,0"/>
<path
android:pathData="M9.06,16.88h13.12v13.12h-13.12z"
android:fillColor="#FFFFFF"/>
</group>
</group>
<group>
<clip-path android:pathData="M10.94,21.88h1.56v3.12h-1.56z M 0,0"/>
<group>
<clip-path android:pathData="M-335,-28h375v908h-375z M 0,0"/>
<path
android:pathData="M5.94,16.88h11.56v13.12h-11.56z"
android:fillColor="#FFFFFF"/>
</group>
</group>
<group>
<clip-path android:pathData="M14.06,17.19h1.56v1.56h-1.56z M 0,0"/>
<group>
<clip-path android:pathData="M-335,-28h375v908h-375z M 0,0"/>
<path
android:pathData="M9.06,12.19h11.56v11.56h-11.56z"
android:fillColor="#FFFFFF"/>
</group>
</group>
<group>
<clip-path android:pathData="M14.06,4.69l0,-3.13l-1.56,0l0,-1.56l-1.56,0l0,6.25l1.56,0l0,-1.56z M 0,0"/>
<group>
<clip-path android:pathData="M-335,-28h375v908h-375z M 0,0"/>
<path
android:pathData="M5.94,-5h13.12v16.25h-13.12z"
android:fillColor="#FFFFFF"/>
</group>
</group>
<group>
<clip-path android:pathData="M18.75,21.88h1.56v3.12h-1.56z M 0,0"/>
<group>
<clip-path android:pathData="M-335,-28h375v908h-375z M 0,0"/>
<path
android:pathData="M13.75,16.88h11.56v13.12h-11.56z"
android:fillColor="#FFFFFF"/>
</group>
</group>
<group>
<clip-path android:pathData="M18.75,18.75h3.12v1.56h-3.12z M 0,0"/>
<group>
<clip-path android:pathData="M-335,-28h375v908h-375z M 0,0"/>
<path
android:pathData="M13.75,13.75h13.12v11.56h-13.12z"
android:fillColor="#FFFFFF"/>
</group>
</group>
<group>
<clip-path android:pathData="M17.19,20.31h1.56v1.56h-1.56z M 0,0"/>
<group>
<clip-path android:pathData="M-335,-28h375v908h-375z M 0,0"/>
<path
android:pathData="M12.19,15.31h11.56v11.56h-11.56z"
android:fillColor="#FFFFFF"/>
</group>
</group>
<group>
<clip-path android:pathData="M15.62,18.75h1.56v1.56h-1.56z M 0,0"/>
<group>
<clip-path android:pathData="M-335,-28h375v908h-375z M 0,0"/>
<path
android:pathData="M10.62,13.75h11.56v11.56h-11.56z"
android:fillColor="#FFFFFF"/>
</group>
</group>
<group>
<clip-path android:pathData="M21.88,15.62l0,1.57l1.56,0l0,1.56l1.56,0l0,-3.13l-1.56,0z M 0,0"/>
<group>
<clip-path android:pathData="M-335,-28h375v908h-375z M 0,0"/>
<path
android:pathData="M16.88,10.62h13.12v13.12h-13.12z"
android:fillColor="#FFFFFF"/>
</group>
</group>
<group>
<clip-path android:pathData="M23.44,20.31l-1.56,0l0,4.69l3.12,0l0,-3.12l-1.56,0z M 0,0"/>
<group>
<clip-path android:pathData="M-335,-28h375v908h-375z M 0,0"/>
<path
android:pathData="M16.88,15.31h13.12v14.69h-13.12z"
android:fillColor="#FFFFFF"/>
</group>
</group>
<group>
<clip-path android:pathData="M15.62,15.62l0,1.57l4.69,0l0,-3.13l-3.12,0l0,1.56z M 0,0"/>
<group>
<clip-path android:pathData="M-335,-28h375v908h-375z M 0,0"/>
<path
android:pathData="M10.62,9.06h14.69v13.12h-14.69z"
android:fillColor="#FFFFFF"/>
</group>
</group>
<group>
<clip-path android:pathData="M18.75,10.94l0,1.56l3.13,0l0,1.56l3.12,0l0,-3.12l-3.12,0z M 0,0"/>
<group>
<clip-path android:pathData="M-335,-28h375v908h-375z M 0,0"/>
<path
android:pathData="M13.75,5.94h16.25v13.12h-16.25z"
android:fillColor="#FFFFFF"/>
</group>
</group>
</vector>

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="38dp" />
<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/transparent" />
<corners android:radius="38dp" />
<stroke android:width="@dimen/profile_picture_border_thickness" android:color="@color/border" />
</shape>

View File

@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<ripple
xmlns:android="http://schemas.android.com/apk/res/android"
android:color="@color/cell_selected">
<item>
<color android:color="@color/cell_background" />
</item>
</ripple>

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/transparent" />
<corners android:radius="24dp" />
<stroke android:width="@dimen/border_thickness" android:color="@color/text" />
</shape>

View File

@ -24,7 +24,8 @@
android:id="@+id/profileButton"
android:layout_width="@dimen/small_profile_picture_size"
android:layout_height="@dimen/small_profile_picture_size"
android:layout_alignParentStart="true"
android:layout_marginLeft="8dp"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"/>
<TextView
@ -34,16 +35,16 @@
android:textColor="@color/text"
android:textSize="@dimen/very_large_font_size"
android:fontFamily="sans-serif-medium"
android:layout_alignParentStart="true"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:layout_marginStart="64dp" />
android:layout_marginLeft="64dp" />
<ImageView
android:id="@+id/joinPublicChatButton"
android:layout_width="24dp"
android:layout_height="24dp"
android:src="@drawable/ic_globe"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_centerVertical="true" />
</RelativeLayout>

View File

@ -0,0 +1,169 @@
<?xml version="1.0" encoding="utf-8"?>
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scrollbars="none">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/default_session_background"
android:orientation="vertical"
android:gravity="center_horizontal">
<org.thoughtcrime.securesms.loki.redesign.views.ProfilePictureView
android:id="@+id/profilePictureView"
android:layout_width="@dimen/large_profile_picture_size"
android:layout_height="@dimen/large_profile_picture_size"
android:layout_marginTop="@dimen/large_spacing" />
<TextView
android:id="@+id/displayNameTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/large_spacing"
android:layout_marginTop="@dimen/small_spacing"
android:layout_marginRight="@dimen/large_spacing"
android:textColor="@color/text"
android:textSize="@dimen/very_large_font_size"
android:textStyle="bold" />
<org.thoughtcrime.securesms.loki.redesign.views.SeparatorView
android:id="@+id/separatorView"
android:layout_width="match_parent"
android:layout_height="32dp"
android:layout_marginLeft="@dimen/large_spacing"
android:layout_marginTop="@dimen/large_spacing"
android:layout_marginRight="@dimen/large_spacing"/>
<TextView
android:id="@+id/publicKeyTextView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/large_spacing"
android:layout_marginTop="@dimen/large_spacing"
android:layout_marginRight="@dimen/large_spacing"
android:textSize="@dimen/large_font_size"
android:textColor="@color/text"
android:fontFamily="@font/space_mono_regular"
android:textAlignment="center"
android:text="05987d601943c267879be41830888066c6a024cbdc9a548d06813924bf3372ea78" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/large_spacing"
android:layout_marginTop="@dimen/large_spacing"
android:layout_marginRight="@dimen/large_spacing"
android:orientation="horizontal">
<Button
style="@style/MediumProminentOutlineButton"
android:id="@+id/copyButton"
android:layout_width="0dp"
android:layout_height="@dimen/medium_button_height"
android:layout_weight="1"
android:text="Copy" />
<Button
style="@style/MediumUnimportantOutlineButton"
android:id="@+id/shareButton"
android:layout_width="0dp"
android:layout_height="@dimen/medium_button_height"
android:layout_weight="1"
android:layout_marginLeft="@dimen/medium_spacing"
android:text="Share" />
</LinearLayout>
<View
android:layout_width="match_parent"
android:layout_height="1px"
android:layout_marginTop="@dimen/large_spacing"
android:background="@color/separator" />
<TextView
android:id="@+id/privacyButton"
android:layout_width="match_parent"
android:layout_height="@dimen/setting_button_height"
android:background="@drawable/setting_button_background"
android:textColor="@color/text"
android:textSize="@dimen/medium_font_size"
android:textStyle="bold"
android:gravity="center"
android:text="Privacy" />
<View
android:layout_width="match_parent"
android:layout_height="1px"
android:background="@color/separator" />
<TextView
android:id="@+id/notificationsButton"
android:layout_width="match_parent"
android:layout_height="@dimen/setting_button_height"
android:background="@drawable/setting_button_background"
android:textColor="@color/text"
android:textSize="@dimen/medium_font_size"
android:textStyle="bold"
android:gravity="center"
android:text="Notifications" />
<View
android:layout_width="match_parent"
android:layout_height="1px"
android:background="@color/separator" />
<TextView
android:id="@+id/linkedDevicesButton"
android:layout_width="match_parent"
android:layout_height="@dimen/setting_button_height"
android:background="@drawable/setting_button_background"
android:textColor="@color/text"
android:textSize="@dimen/medium_font_size"
android:textStyle="bold"
android:gravity="center"
android:text="Linked Devices" />
<View
android:layout_width="match_parent"
android:layout_height="1px"
android:background="@color/separator" />
<TextView
android:id="@+id/seedButton"
android:layout_width="match_parent"
android:layout_height="@dimen/setting_button_height"
android:background="@drawable/setting_button_background"
android:textColor="@color/text"
android:textSize="@dimen/medium_font_size"
android:textStyle="bold"
android:gravity="center"
android:text="Show Seed" />
<View
android:layout_width="match_parent"
android:layout_height="1px"
android:background="@color/separator" />
<TextView
android:id="@+id/clearAllDataButton"
android:layout_width="match_parent"
android:layout_height="@dimen/setting_button_height"
android:background="@drawable/setting_button_background"
android:textColor="@color/destructive"
android:textSize="@dimen/medium_font_size"
android:textStyle="bold"
android:gravity="center"
android:text="Clear All Data" />
<View
android:layout_width="match_parent"
android:layout_height="1px"
android:layout_marginBottom="@dimen/large_spacing"
android:background="@color/separator" />
</LinearLayout>
</ScrollView>

View File

@ -77,4 +77,22 @@
android:textSize="@dimen/small_font_size"
android:background="@drawable/profile_picture_view_rss_medium_background" />
<RelativeLayout
android:id="@+id/largeSingleModeImageViewContainer"
android:layout_width="@dimen/large_profile_picture_size"
android:layout_height="@dimen/large_profile_picture_size">
<ImageView
android:id="@+id/largeSingleModeImageView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/profile_picture_view_large_background" />
<View
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/profile_picture_view_large_foreground" />
</RelativeLayout>
</RelativeLayout>

View File

@ -0,0 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<menu
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item
android:id="@+id/showQRCodeItem"
android:title="Show QR Code"
android:icon="@drawable/ic_qr_code"
app:showAsAction="always" />
</menu>

View File

@ -16,6 +16,7 @@
<dimen name="accent_line_thickness">4dp</dimen>
<dimen name="small_profile_picture_size">36dp</dimen>
<dimen name="medium_profile_picture_size">46dp</dimen>
<dimen name="large_profile_picture_size">76dp</dimen>
<dimen name="conversation_view_status_indicator_size">14dp</dimen>
<dimen name="border_thickness">2dp</dimen>
<dimen name="profile_picture_border_thickness">1dp</dimen>
@ -25,6 +26,7 @@
<dimen name="fake_chat_view_bubble_width">224dp</dimen>
<dimen name="fake_chat_view_bubble_corner_radius">10dp</dimen>
<dimen name="fake_chat_view_height">234dp</dimen>
<dimen name="setting_button_height">72dp</dimen>
<!-- Distances -->
<dimen name="small_spacing">8dp</dimen>

View File

@ -55,6 +55,14 @@
<item name="android:textColor">@color/text</item>
</style>
<style name="MediumUnimportantOutlineButton">
<item name="android:background">@drawable/unimportant_outline_button_medium_background</item>
<item name="android:textAllCaps">false</item>
<item name="android:textSize">@dimen/medium_font_size</item>
<item name="android:textStyle">bold</item>
<item name="android:textColor">@color/text</item>
</style>
<style name="SessionIDTextView">
<item name="android:background">@drawable/session_id_text_view_background</item>
<item name="android:padding">@dimen/medium_spacing</item>

View File

@ -14,7 +14,7 @@ import android.widget.Toast
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
import org.thoughtcrime.securesms.PassphraseRequiredActionBarActivity
import org.thoughtcrime.securesms.conversation.ConversationActivity
import org.thoughtcrime.securesms.database.Address
import org.thoughtcrime.securesms.database.DatabaseFactory
@ -25,12 +25,12 @@ import org.thoughtcrime.securesms.recipients.Recipient
import org.thoughtcrime.securesms.util.TextSecurePreferences
import org.whispersystems.signalservice.loki.utilities.PublicKeyValidation
class CreatePrivateChatActivity : BaseActionBarActivity(), ScanQRCodeWrapperFragmentDelegate {
class CreatePrivateChatActivity : PassphraseRequiredActionBarActivity(), ScanQRCodeWrapperFragmentDelegate {
private val adapter = CreatePrivateChatActivityAdapter(this)
// region Lifecycle
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
override fun onCreate(savedInstanceState: Bundle?, isReady: Boolean) {
super.onCreate(savedInstanceState, isReady)
// Set content view
setContentView(R.layout.activity_create_private_chat)
// Set title

View File

@ -32,6 +32,13 @@ import kotlin.math.abs
class HomeActivity : PassphraseRequiredActionBarActivity, ConversationClickListener {
private lateinit var glide: GlideRequests
private val hexEncodedPublicKey: String
get() {
val masterHexEncodedPublicKey = TextSecurePreferences.getMasterHexEncodedPublicKey(this)
val userHexEncodedPublicKey = TextSecurePreferences.getLocalNumber(this)
return masterHexEncodedPublicKey ?: userHexEncodedPublicKey
}
// region Lifecycle
constructor() : super()
@ -45,7 +52,7 @@ class HomeActivity : PassphraseRequiredActionBarActivity, ConversationClickListe
glide = GlideApp.with(this)
// Set up toolbar buttons
profileButton.glide = glide
profileButton.hexEncodedPublicKey = TextSecurePreferences.getLocalNumber(this)
profileButton.hexEncodedPublicKey = hexEncodedPublicKey
profileButton.update()
profileButton.setOnClickListener { openSettings() }
joinPublicChatButton.setOnClickListener { joinPublicChat() }
@ -110,7 +117,8 @@ class HomeActivity : PassphraseRequiredActionBarActivity, ConversationClickListe
}
private fun openSettings() {
// TODO: Implement
val intent = Intent(this, SettingsActivity::class.java)
startActivity(intent)
}
private fun createPrivateChat() {

View File

@ -9,16 +9,16 @@ 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.PassphraseRequiredActionBarActivity
import org.thoughtcrime.securesms.loki.redesign.fragments.ScanQRCodeWrapperFragment
import org.thoughtcrime.securesms.loki.redesign.fragments.ScanQRCodeWrapperFragmentDelegate
class JoinPublicChatActivity : BaseActionBarActivity(), ScanQRCodeWrapperFragmentDelegate {
class JoinPublicChatActivity : PassphraseRequiredActionBarActivity(), ScanQRCodeWrapperFragmentDelegate {
private val adapter = JoinPublicChatActivityAdapter(this)
// region Lifecycle
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
override fun onCreate(savedInstanceState: Bundle?, isReady: Boolean) {
super.onCreate(savedInstanceState, isReady)
// Set content view
setContentView(R.layout.activity_join_public_chat)
// Set title

View File

@ -0,0 +1,88 @@
package org.thoughtcrime.securesms.loki.redesign.activities
import android.content.ClipData
import android.content.ClipboardManager
import android.content.Context
import android.content.Intent
import android.os.Bundle
import android.view.Menu
import android.view.MenuItem
import android.widget.Toast
import kotlinx.android.synthetic.main.activity_settings.*
import network.loki.messenger.R
import org.thoughtcrime.securesms.PassphraseRequiredActionBarActivity
import org.thoughtcrime.securesms.database.DatabaseFactory
import org.thoughtcrime.securesms.mms.GlideApp
import org.thoughtcrime.securesms.mms.GlideRequests
import org.thoughtcrime.securesms.util.TextSecurePreferences
class SettingsActivity : PassphraseRequiredActionBarActivity() {
private lateinit var glide: GlideRequests
private val hexEncodedPublicKey: String
get() {
val masterHexEncodedPublicKey = TextSecurePreferences.getMasterHexEncodedPublicKey(this)
val userHexEncodedPublicKey = TextSecurePreferences.getLocalNumber(this)
return masterHexEncodedPublicKey ?: userHexEncodedPublicKey
}
// region Lifecycle
override fun onCreate(savedInstanceState: Bundle?, isReady: Boolean) {
super.onCreate(savedInstanceState, isReady)
// Set content view
setContentView(R.layout.activity_settings)
// Set title
supportActionBar!!.title = "Settings"
// Set up Glide
glide = GlideApp.with(this)
// Set up profile picture view
profilePictureView.glide = glide
profilePictureView.hexEncodedPublicKey = hexEncodedPublicKey
profilePictureView.isLarge = true
profilePictureView.update()
// Set up display name text view
displayNameTextView.text = DatabaseFactory.getLokiUserDatabase(this).getDisplayName(hexEncodedPublicKey)
// Set up public key text view
publicKeyTextView.text = hexEncodedPublicKey
// Set up copy button
copyButton.setOnClickListener { copyPublicKey() }
// Set up share button
shareButton.setOnClickListener { sharePublicKey() }
}
override fun onCreateOptionsMenu(menu: Menu?): Boolean {
menuInflater.inflate(R.menu.menu_settings, menu)
return true
}
// endregion
// region Interaction
override fun onOptionsItemSelected(item: MenuItem): Boolean {
val id = item.itemId
when (id) {
R.id.showQRCodeItem -> showQRCode()
else -> { /* Do nothing */ }
}
return super.onOptionsItemSelected(item)
}
private fun showQRCode() {
// TODO: Implement
}
private fun copyPublicKey() {
val clipboard = getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager
val clip = ClipData.newPlainText("Session ID", hexEncodedPublicKey)
clipboard.primaryClip = clip
Toast.makeText(this, R.string.activity_register_public_key_copied_message, Toast.LENGTH_SHORT).show()
}
private fun sharePublicKey() {
val intent = Intent()
intent.action = Intent.ACTION_SEND
intent.putExtra(Intent.EXTRA_TEXT, hexEncodedPublicKey)
intent.type = "text/plain"
startActivity(intent)
}
// endregion
}

View File

@ -15,11 +15,14 @@ import org.thoughtcrime.securesms.loki.JazzIdenticonDrawable
import org.thoughtcrime.securesms.mms.GlideRequests
import org.thoughtcrime.securesms.recipients.Recipient
// TODO: Look into a better way of handling different sizes
class ProfilePictureView : RelativeLayout {
lateinit var glide: GlideRequests
var hexEncodedPublicKey: String? = null
var additionalHexEncodedPublicKey: String? = null
var isRSSFeed = false
var isLarge = false
// region Lifecycle
constructor(context: Context) : super(context) {
@ -50,7 +53,8 @@ class ProfilePictureView : RelativeLayout {
val hexEncodedPublicKey = hexEncodedPublicKey ?: return
val additionalHexEncodedPublicKey = additionalHexEncodedPublicKey
doubleModeImageViewContainer.visibility = if (additionalHexEncodedPublicKey != null && !isRSSFeed) View.VISIBLE else View.INVISIBLE
singleModeImageViewContainer.visibility = if (additionalHexEncodedPublicKey == null && !isRSSFeed) View.VISIBLE else View.INVISIBLE
singleModeImageViewContainer.visibility = if (additionalHexEncodedPublicKey == null && !isRSSFeed && !isLarge) View.VISIBLE else View.INVISIBLE
largeSingleModeImageViewContainer.visibility = if (additionalHexEncodedPublicKey == null && !isRSSFeed && isLarge) View.VISIBLE else View.INVISIBLE
rssTextView.visibility = if (isRSSFeed) View.VISIBLE else View.INVISIBLE
fun setProfilePictureIfNeeded(imageView: ImageView, hexEncodedPublicKey: String, @DimenRes sizeID: Int) {
glide.clear(imageView)
@ -67,9 +71,10 @@ class ProfilePictureView : RelativeLayout {
imageView.setImageDrawable(null)
}
}
setProfilePictureIfNeeded(singleModeImageView, hexEncodedPublicKey, R.dimen.medium_profile_picture_size)
setProfilePictureIfNeeded(doubleModeImageView1, hexEncodedPublicKey, R.dimen.small_profile_picture_size)
setProfilePictureIfNeeded(doubleModeImageView2, additionalHexEncodedPublicKey ?: "", R.dimen.small_profile_picture_size)
setProfilePictureIfNeeded(singleModeImageView, hexEncodedPublicKey, R.dimen.medium_profile_picture_size)
setProfilePictureIfNeeded(largeSingleModeImageView, hexEncodedPublicKey, R.dimen.large_profile_picture_size)
}
// endregion
}