Skip to content

Commit 9b9a63f

Browse files
Merge pull request #237 from smswithoutborders/view-account
View current logged in account
2 parents 5c36b2a + 5575cbc commit 9b9a63f

17 files changed

Lines changed: 99 additions & 6 deletions

File tree

app/src/main/java/com/example/sw0b_001/ui/appbars/RecentAppBar.kt

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,20 @@ import androidx.compose.foundation.layout.Row
77
import androidx.compose.foundation.layout.Spacer
88
import androidx.compose.foundation.layout.fillMaxWidth
99
import androidx.compose.foundation.layout.padding
10+
import androidx.compose.foundation.layout.size
1011
import androidx.compose.foundation.layout.width
1112
import androidx.compose.foundation.text.KeyboardActions
1213
import androidx.compose.foundation.text.KeyboardOptions
1314
import androidx.compose.material.icons.Icons
15+
import androidx.compose.material.icons.filled.AccountCircle
1416
import androidx.compose.material.icons.filled.Close
1517
import androidx.compose.material.icons.filled.MoreVert
1618
import androidx.compose.material.icons.filled.Search
1719
import androidx.compose.material3.CenterAlignedTopAppBar
1820
import androidx.compose.material3.DropdownMenu
1921
import androidx.compose.material3.DropdownMenuItem
2022
import androidx.compose.material3.ExperimentalMaterial3Api
23+
import androidx.compose.material3.HorizontalDivider
2124
import androidx.compose.material3.Icon
2225
import androidx.compose.material3.IconButton
2326
import androidx.compose.material3.MaterialTheme
@@ -39,6 +42,7 @@ import androidx.compose.ui.platform.LocalContext
3942
import androidx.compose.ui.platform.LocalFocusManager
4043
import androidx.compose.ui.res.stringResource
4144
import androidx.compose.ui.text.TextStyle
45+
import androidx.compose.ui.text.font.FontWeight
4246
import androidx.compose.ui.text.input.ImeAction
4347
import androidx.compose.ui.tooling.preview.Preview
4448
import androidx.compose.ui.unit.dp
@@ -47,6 +51,7 @@ import com.example.sw0b_001.R
4751
import com.example.sw0b_001.SettingsActivity
4852
import com.example.sw0b_001.ui.navigation.AboutScreen
4953
import com.example.sw0b_001.ui.theme.AppTheme
54+
import com.example.sw0b_001.utils.getPhoneNumberFromPrefs
5055

5156
@Composable
5257
@OptIn(ExperimentalMaterial3Api::class)
@@ -56,7 +61,7 @@ fun RecentAppBar(
5661
searchQuery: String,
5762
isSearchActive: Boolean,
5863
onToggleSearch: () -> Unit,
59-
onSearchDone: () -> Unit
64+
onSearchDone: () -> Unit,
6065
) {
6166
val context = LocalContext.current
6267
val focusManager = LocalFocusManager.current
@@ -72,6 +77,9 @@ fun RecentAppBar(
7277
}
7378
)
7479
}
80+
81+
val phoneNumber = remember { getPhoneNumberFromPrefs(context) }
82+
7583
Column(modifier = Modifier.fillMaxWidth()) {
7684
CenterAlignedTopAppBar(
7785
title = {
@@ -99,6 +107,36 @@ fun RecentAppBar(
99107
expanded = showMenu,
100108
onDismissRequest = { showMenu = false }
101109
) {
110+
if (!phoneNumber.isNullOrBlank()) {
111+
DropdownMenuItem(
112+
text = {
113+
Row(verticalAlignment = Alignment.CenterVertically) {
114+
Icon(
115+
imageVector = Icons.Default.AccountCircle,
116+
contentDescription = stringResource(R.string.your_account),
117+
modifier = Modifier.size(40.dp),
118+
tint = MaterialTheme.colorScheme.onSurfaceVariant
119+
)
120+
Spacer(modifier = Modifier.width(16.dp))
121+
Column {
122+
Text(
123+
text = stringResource(R.string.your_account),
124+
fontWeight = FontWeight.SemiBold,
125+
style = MaterialTheme.typography.bodyMedium
126+
)
127+
Text(
128+
text = phoneNumber,
129+
style = MaterialTheme.typography.bodySmall,
130+
color = MaterialTheme.colorScheme.onSurfaceVariant
131+
)
132+
}
133+
}
134+
},
135+
onClick = { },
136+
enabled = false
137+
)
138+
HorizontalDivider(modifier = Modifier.padding(vertical = 8.dp))
139+
}
102140
DropdownMenuItem(
103141
text = { Text(stringResource(R.string.settings)) },
104142
onClick = {

app/src/main/java/com/example/sw0b_001/ui/features/FeatureInfo.kt

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,17 @@ data class FeatureInfo(
1414
object AppFeatures {
1515
val ALL_FEATURES = listOf(
1616
FeatureInfo(
17-
id = "oauth_token_storage_device_setting_info_alert",
17+
id = "view_current_account",
1818
titleRes = R.string.new_feature_title,
19-
descriptionRes = R.string.oauth_token_storage_device_setting_info,
19+
descriptionRes = R.string.view_account_menu,
2020
iconRes = R.drawable.relaysms_icon_default_shape
2121
),
22+
// FeatureInfo(
23+
// id = "oauth_token_storage_device_setting_info_alert",
24+
// titleRes = R.string.new_feature_title,
25+
// descriptionRes = R.string.oauth_token_storage_device_setting_info,
26+
// iconRes = R.drawable.relaysms_icon_default_shape
27+
// ),
2228

2329
)
2430
}

app/src/main/java/com/example/sw0b_001/ui/views/OtpCodeVerificationView.kt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,13 +63,16 @@ import androidx.compose.ui.unit.dp
6363
import androidx.compose.ui.unit.sp
6464
import androidx.core.app.ActivityCompat.startActivityForResult
6565
import androidx.core.content.ContextCompat
66+
import androidx.core.content.edit
6667
import androidx.navigation.NavController
6768
import androidx.navigation.compose.rememberNavController
69+
import androidx.preference.PreferenceManager
6870
import com.example.sw0b_001.BuildConfig
6971
import com.example.sw0b_001.Models.Platforms.PlatformsViewModel
7072
import com.example.sw0b_001.Models.Vaults
7173
import com.example.sw0b_001.ui.navigation.HomepageScreen
7274
import com.example.sw0b_001.ui.theme.AppTheme
75+
import com.example.sw0b_001.utils.savePhoneNumberToPrefs
7376
import com.google.android.gms.auth.api.phone.SmsRetriever
7477
import com.google.android.gms.common.api.CommonStatusCodes
7578
import com.google.android.gms.common.api.Status
@@ -466,6 +469,8 @@ private fun submitOTPCode(
466469
}
467470
}
468471

472+
savePhoneNumberToPrefs(context, phoneNumber)
473+
469474
vault.refreshStoredTokens(context) {
470475
platformsViewModel.accountsForMissingDialog = it
471476
}
@@ -481,4 +486,5 @@ private fun submitOTPCode(
481486
onCompleteCallback()
482487
}
483488
}
484-
}
489+
}
490+

app/src/main/java/com/example/sw0b_001/ui/views/compose/MessageComposeView.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -433,8 +433,8 @@ private fun processSend(
433433
?: return@launch onFailure("Could not find platform details for '${account.name}'.")
434434

435435

436-
val accessToken = if (platform.protocol_type == "oauth2") account.accessToken else null
437-
val refreshToken = if (platform.protocol_type == "oauth2") account.refreshToken else null
436+
val accessToken = account.accessToken
437+
val refreshToken = account.refreshToken
438438
Log.d("MessageComposeView", "Access Token: $accessToken, Refresh Token: $refreshToken")
439439

440440
val contentFormatV2Bytes = createMessageByteBuffer(
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package com.example.sw0b_001.utils
2+
3+
import android.content.Context
4+
import androidx.core.content.edit
5+
import androidx.preference.PreferenceManager
6+
7+
const val PREF_KEY_PHONE_NUMBER = "user_phone_number"
8+
9+
fun savePhoneNumberToPrefs(context: Context, phoneNumber: String) {
10+
val prefs = PreferenceManager.getDefaultSharedPreferences(context)
11+
prefs.edit {
12+
putString(PREF_KEY_PHONE_NUMBER, phoneNumber)
13+
}
14+
}
15+
16+
fun getPhoneNumberFromPrefs(context: Context): String? {
17+
val prefs = PreferenceManager.getDefaultSharedPreferences(context)
18+
return prefs.getString(PREF_KEY_PHONE_NUMBER, null)
19+
}

app/src/main/res/values-ar/strings.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -321,5 +321,7 @@
321321
<string name="recipient_account_format_hint">تأكد من أن حساب المستلم بالتنسيق الصحيح.</string>
322322
<string name="slack_recipient">قناة أو مستخدم سلاك</string>
323323
<string name="slack_hint">للقنوات: استخدم #الاسم أو مُعرّف (مثال: #عام أو C123ABC). للرسائل الخاصة: استخدم @اسم_المستخدم، أو بريد إلكتروني، أو مُعرّف مستخدم (مثال: @jane أو @user@gmail.com أو U456DEF).</string>
324+
<string name="view_account_menu">يمكنك الآن رؤية الحساب الذي سجلت دخولك به حاليًا بالنقر على أيقونة القائمة في شريط التنقل</string>
325+
<string name="your_account">حسابك</string>
324326

325327
</resources>

app/src/main/res/values-de/strings.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -319,5 +319,7 @@
319319
<string name="recipient_account_format_hint">Stellen Sie sicher, dass das Empfängerkonto im richtigen Format ist.</string>
320320
<string name="slack_recipient">Slack-Kanal oder -Benutzer</string>
321321
<string name="slack_hint">Für Kanäle: Verwenden Sie #Name oder eine ID (z.B. #general oder C123ABC). Für DMs: Verwenden Sie @Benutzername, eine E-Mail-Adresse oder eine Benutzer-ID (z.B. @jane oder @user@gmail.com oder U456DEF).</string>
322+
<string name="view_account_menu">Sie können Ihr aktuell angemeldetes Konto jetzt sehen, indem Sie auf das Menü-Symbol in der Navigationsleiste klicken</string>
323+
<string name="your_account">Ihr Konto</string>
322324

323325
</resources>

app/src/main/res/values-es/strings.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -320,5 +320,7 @@
320320
<string name="recipient_account_format_hint">Asegúrese de que la cuenta del destinatario esté en el formato correcto.</string>
321321
<string name="slack_recipient">Canal o usuario de Slack</string>
322322
<string name="slack_hint">Para canales: use #nombre o una ID (ej., #general o C123ABC). Para MD: use @nombredeusuario, un correo electrónico o una ID de usuario (ej., @jane o @user@gmail.com o U456DEF).</string>
323+
<string name="view_account_menu">Ahora puede ver la cuenta en la que ha iniciado sesión haciendo clic en el icono del menú en la barra de navegación</string>
324+
<string name="your_account">Su cuenta</string>
323325

324326
</resources>

app/src/main/res/values-fa/strings.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -320,5 +320,7 @@
320320
<string name="recipient_account_format_hint">اطمینان حاصل کنید که فرمت حساب گیرنده صحیح باشد.</string>
321321
<string name="slack_recipient">کانال یا کاربر Slack</string>
322322
<string name="slack_hint">برای کانال‌ها: از #نام یا یک شناسه (مثلا #general یا C123ABC) استفاده کنید. برای پیام‌های مستقیم: از @نام‌کاربری، یک ایمیل یا شناسه کاربری (مثلا @jane یا @user@gmail.com یا U456DEF) استفاده کنید.</string>
323+
<string name="view_account_menu">اکنون می‌توانید حسابی که با آن وارد شده‌اید را با کلیک بر روی آیکون منو در نوار پیمایش مشاهده کنید</string>
324+
<string name="your_account">حساب شما</string>
323325

324326
</resources>

app/src/main/res/values-fr/strings.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -320,4 +320,6 @@
320320
<string name="recipient_account_format_hint">Assurez-vous que le compte du destinataire est au bon format.</string>
321321
<string name="slack_recipient">Canal ou utilisateur Slack</string>
322322
<string name="slack_hint">Pour les canaux : utilisez #nom ou un ID (par ex., #general ou C123ABC). Pour les MP : utilisez @nomutilisateur, une adresse e-mail ou un ID utilisateur (par ex., @jane ou @user@gmail.com ou U456DEF).</string>
323+
<string name="view_account_menu">Vous pouvez maintenant voir le compte sur lequel vous êtes actuellement connecté en cliquant sur l\'icône du menu dans la barre de navigation</string>
324+
<string name="your_account">Votre compte</string>
323325
</resources>

0 commit comments

Comments
 (0)