Add option to copy userID from profile. Fixes #1144

This commit is contained in:
Phillip Thelen 2019-10-30 18:37:57 +01:00
parent 2f44d83f39
commit d4c3d7aff6
6 changed files with 51 additions and 76 deletions

View file

@ -68,7 +68,7 @@
android:name=".ui.activities.NotificationsActivity"
android:parentActivityName=".ui.activities.MainActivity"
android:label="@string/notifications"
android:screenOrientation="portrait"
android:screenOrientation="unspecified"
tools:ignore="UnusedAttribute">
</activity>
<activity
@ -150,6 +150,7 @@
<activity
android:name=".ui.activities.FullProfileActivity"
android:parentActivityName=".ui.activities.MainActivity"
android:theme="@style/MainAppTheme"
tools:ignore="UnusedAttribute">
<meta-data
android:name="android.support.PARENT_ACTIVITY"
@ -176,12 +177,12 @@
android:configChanges="keyboard|keyboardHidden|screenLayout|screenSize|orientation"
android:label="@string/app_name" />
<activity android:name=".ui.activities.MaintenanceActivity"
android:screenOrientation="portrait"
android:screenOrientation="unspecified"
android:theme="@style/Theme.AppCompat.Light.NoActionBar" />
<activity android:name=".ui.activities.GemPurchaseActivity"
android:screenOrientation="portrait" />
android:screenOrientation="unspecified" />
<activity android:name=".ui.activities.VerifyUsernameActivity"
android:screenOrientation="portrait"
android:screenOrientation="unspecified"
android:windowSoftInputMode="stateHidden" />
<receiver android:name=".receivers.NotificationPublisher" />

View file

@ -151,7 +151,7 @@ android {
multiDexEnabled true
resConfigs "en", "bg", "de", "en-rGB", "es", "fr", "hr-rHR", "in", "it", "iw", "ja", "ko", "lt", "nl", "pl", "pt-rBR", "pt-rPT", "ru", "tr", "zh", "zh-rTW"
versionCode 2280
versionCode 2282
versionName "2.3"
}

View file

@ -18,9 +18,8 @@
android:layout_height="wrap_content"
android:minHeight="?attr/actionBarSize"
android:theme="@style/Toolbar"
android:background="@color/brand_300"
app:layout_scrollFlags="scroll|enterAlways"
app:popupTheme="@style/ThemeOverlay.AppCompat.Dark"/>
app:popupTheme="@style/Theme.AppCompat.Light"/>
</com.google.android.material.appbar.AppBarLayout>
<androidx.core.widget.NestedScrollView
@ -248,44 +247,6 @@
</LinearLayout>
</androidx.cardview.widget.CardView>
<androidx.cardview.widget.CardView
style="@style/CardView.Default"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
style="@style/CardContent"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
style="@style/CardTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/username"
android:textStyle="bold" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=""
android:id="@+id/username"
android:layout_gravity="end"/>
</LinearLayout>
<Button
android:text="@string/copy"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibility="gone"
android:id="@+id/copy_username" />
</LinearLayout>
</androidx.cardview.widget.CardView>
<androidx.cardview.widget.CardView
style="@style/CardView.Default"
android:layout_width="match_parent"

View file

@ -2,10 +2,8 @@
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools">
<item android:id="@+id/private_message"
android:title="@string/profile_private_message"
android:icon="@drawable/ic_action_chat"
android:orderInCategory="100"
app:showAsAction="always"
/>
<item android:id="@+id/copy_username"
android:title="@string/copy_username" />
<item android:id="@+id/copy_userid"
android:title="@string/copy_userid" />
</menu>

View file

@ -875,4 +875,7 @@
<string name="gift_gems_balance_subtitle">Enter how many of your Gems you\'d like to send below or switch tabs to purchase Gems to gift</string>
<string name="gems_to_gift">Gems to gift</string>
<string name="send_gift">Send Gift</string>
<string name="copy_userid">Copy User ID</string>
<string name="id_copied">Copied User ID to clipboard</string>
<string name="copy_username">Copy Username</string>
</resources>

View file

@ -3,15 +3,13 @@ package com.habitrpg.android.habitica.ui.activities
import android.content.Context
import android.graphics.Typeface
import android.os.Bundle
import android.view.LayoutInflater
import android.view.MenuItem
import android.view.View
import android.view.ViewGroup
import android.view.*
import android.widget.*
import androidx.appcompat.widget.AppCompatImageView
import androidx.appcompat.widget.Toolbar
import androidx.core.content.ContextCompat
import androidx.core.os.bundleOf
import androidx.core.widget.NestedScrollView
import com.facebook.drawee.backends.pipeline.Fresco
import com.facebook.drawee.controller.BaseControllerListener
import com.facebook.drawee.view.SimpleDraweeView
@ -61,8 +59,6 @@ class FullProfileActivity : BaseActivity() {
private val profileImage: SimpleDraweeView by bindView(R.id.profile_image)
private val blurbTextView: TextView by bindView(R.id.profile_blurb)
private val avatarView: AvatarView by bindView(R.id.avatarView)
private val copyUsernameButton: Button by bindView(R.id.copy_username)
private val usernameText: TextView by bindView(R.id.username)
private val attributesCardView: androidx.cardview.widget.CardView by bindView(R.id.profile_attributes_card)
private val attributesTableLayout: TableLayout by bindView(R.id.attributes_table)
private val attributesCollapseIcon: AppCompatImageView by bindView(R.id.attributes_collapse_icon)
@ -70,7 +66,7 @@ class FullProfileActivity : BaseActivity() {
private val costumeTableLayout: TableLayout by bindView(R.id.costume_table)
private val costumeCard: androidx.cardview.widget.CardView by bindView(R.id.profile_costume_card)
private val avatarWithStatsView: View by bindView(R.id.avatar_with_bars)
private val scrollView: ScrollView by bindView(R.id.fullprofile_scrollview)
private val scrollView: NestedScrollView by bindView(R.id.fullprofile_scrollview)
private val petsFoundCount: TextView by bindView(R.id.profile_pets_found_count)
private val mountsTamedCount: TextView by bindView(R.id.profile_mounts_tamed_count)
private val currentPetDrawee: SimpleDraweeView by bindView(R.id.current_pet_drawee)
@ -86,7 +82,8 @@ class FullProfileActivity : BaseActivity() {
private val giftSubscriptionButton: Button by bindView(R.id.gift_subscription_button)
private var userID = ""
private var userName: String? = null
private var username: String? = null
private var userDisplayName: String? = null
private var avatarWithBars: AvatarWithBarsViewModel? = null
private var attributeStrSum = 0f
private var attributeIntSum = 0f
@ -128,12 +125,35 @@ class FullProfileActivity : BaseActivity() {
super.onDestroy()
}
override fun onCreateOptionsMenu(menu: Menu?): Boolean {
val inflater = menuInflater
inflater.inflate(R.menu.menu_full_profile, menu)
return super.onCreateOptionsMenu(menu)
}
override fun onOptionsItemSelected(item: MenuItem): Boolean {
return if (item.itemId == android.R.id.home) {
finish()
true
} else {
super.onOptionsItemSelected(item)
return when {
item.itemId == android.R.id.home -> {
finish()
true
}
item.itemId == R.id.copy_username -> {
val clipboard = this.getSystemService(Context.CLIPBOARD_SERVICE) as? android.content.ClipboardManager
val clip = android.content.ClipData.newPlainText(username, username)
clipboard?.setPrimaryClip(clip)
HabiticaSnackbar.showSnackbar(this@FullProfileActivity.scrollView.getChildAt(0) as ViewGroup,
String.format(getString(R.string.username_copied), userDisplayName), SnackbarDisplayType.NORMAL)
true
}
item.itemId == R.id.copy_userid -> {
val clipboard = this.getSystemService(Context.CLIPBOARD_SERVICE) as? android.content.ClipboardManager
val clip = android.content.ClipData.newPlainText(userID, userID)
clipboard?.setPrimaryClip(clip)
HabiticaSnackbar.showSnackbar(this@FullProfileActivity.scrollView.getChildAt(0) as ViewGroup,
String.format(getString(R.string.id_copied), userDisplayName), SnackbarDisplayType.NORMAL)
true
}
else -> super.onOptionsItemSelected(item)
}
}
@ -144,14 +164,14 @@ class FullProfileActivity : BaseActivity() {
val emojiEditText = newMessageView.findViewById<EmojiEditText>(R.id.edit_new_message_text)
val newMessageTitle = newMessageView.findViewById<TextView>(R.id.new_message_title)
newMessageTitle.text = String.format(getString(R.string.profile_send_message_to), userName)
newMessageTitle.text = String.format(getString(R.string.profile_send_message_to), userDisplayName)
val addMessageDialog = HabiticaAlertDialog(this)
addMessageDialog.addButton(android.R.string.ok, true) { _, _ ->
socialRepository.postPrivateMessage(userID, emojiEditText.text.toString())
.subscribe(Consumer {
HabiticaSnackbar.showSnackbar(this@FullProfileActivity.scrollView.getChildAt(0) as ViewGroup,
String.format(getString(R.string.profile_message_sent_to), userName), SnackbarDisplayType.NORMAL)
String.format(getString(R.string.profile_message_sent_to), userDisplayName), SnackbarDisplayType.NORMAL)
}, RxErrorHandler.handleEmptyError())
dismissKeyboard()
@ -165,7 +185,8 @@ class FullProfileActivity : BaseActivity() {
val profile = user.profile ?: return
updatePetsMountsView(user)
userName = profile.name
userDisplayName = profile.name
username = user.username
title = profile.name
@ -192,15 +213,6 @@ class FullProfileActivity : BaseActivity() {
user.authentication?.timestamps?.lastLoggedIn?.let { lastLoginView.text = dateFormatter.format(it) }
totalCheckinsView.text = user.loginIncentives.toString()
usernameText.text = user.username
copyUsernameButton.visibility = View.VISIBLE
copyUsernameButton.setOnClickListener { view ->
val clipboard = view.context
.getSystemService(Context.CLIPBOARD_SERVICE) as? android.content.ClipboardManager
val clip = android.content.ClipData.newPlainText(user.username, user.username)
clipboard?.setPrimaryClip(clip)
}
avatarView.setAvatar(user)
avatarWithBars?.updateData(user)