diff --git a/app/src/main/java/com/keylesspalace/tusky/EditProfileActivity.kt b/app/src/main/java/com/keylesspalace/tusky/EditProfileActivity.kt index f373521ac..94c160f74 100644 --- a/app/src/main/java/com/keylesspalace/tusky/EditProfileActivity.kt +++ b/app/src/main/java/com/keylesspalace/tusky/EditProfileActivity.kt @@ -52,7 +52,7 @@ import com.keylesspalace.tusky.util.await import com.keylesspalace.tusky.util.show import com.keylesspalace.tusky.util.viewBinding import com.keylesspalace.tusky.viewmodel.EditProfileViewModel -import com.keylesspalace.tusky.viewmodel.ProfileData +import com.keylesspalace.tusky.viewmodel.ProfileDataInUi import com.mikepenz.iconics.IconicsDrawable import com.mikepenz.iconics.typeface.library.googlematerial.GoogleMaterial import com.mikepenz.iconics.utils.colorInt @@ -101,7 +101,7 @@ class EditProfileActivity : BaseActivity(), Injectable { } private val currentProfileData - get() = ProfileData( + get() = ProfileDataInUi( displayName = binding.displayNameEditText.text.toString(), note = binding.noteEditText.text.toString(), locked = binding.lockedCheckBox.isChecked, @@ -322,15 +322,14 @@ class EditProfileActivity : BaseActivity(), Injectable { } private fun showUnsavedChangesDialog() = lifecycleScope.launch { - when (launchAlertDialog()) { + when (launchSaveDialog()) { AlertDialog.BUTTON_POSITIVE -> save() else -> finish() } } - private suspend fun launchAlertDialog() = AlertDialog.Builder(this) - .setTitle(getString(R.string.title_edit_profile_save_changes_prompt)) - .setMessage(getString(R.string.message_edit_profile_save_changes_prompt)) + private suspend fun launchSaveDialog() = AlertDialog.Builder(this) + .setMessage(getString(R.string.dialog_save_profile_changes_message)) .create() .await(R.string.action_save, R.string.action_discard) } diff --git a/app/src/main/java/com/keylesspalace/tusky/viewmodel/EditProfileViewModel.kt b/app/src/main/java/com/keylesspalace/tusky/viewmodel/EditProfileViewModel.kt index 2e1a8d43c..55de04be4 100644 --- a/app/src/main/java/com/keylesspalace/tusky/viewmodel/EditProfileViewModel.kt +++ b/app/src/main/java/com/keylesspalace/tusky/viewmodel/EditProfileViewModel.kt @@ -50,10 +50,7 @@ import javax.inject.Inject private const val HEADER_FILE_NAME = "header.png" private const val AVATAR_FILE_NAME = "avatar.png" -/** - * Conveniently groups Profile Data users can modify in the UI. - */ -internal data class ProfileData( +internal data class ProfileDataInUi( val displayName: String, val note: String, val locked: Boolean, @@ -105,7 +102,7 @@ class EditProfileViewModel @Inject constructor( headerData.value = getHeaderUri() } - internal fun save(newProfileData: ProfileData) { + internal fun save(newProfileData: ProfileDataInUi) { if (saveData.value is Loading || profileData.value !is Success) { return } @@ -115,7 +112,7 @@ class EditProfileViewModel @Inject constructor( val diff = getProfileDiff(apiProfileAccount, newProfileData) if (!diff.hasChanges()) { // if nothing has changed, there is no need to make an api call - saveData.postValue(Success()) + saveData.value = Success() return } @@ -157,7 +154,7 @@ class EditProfileViewModel @Inject constructor( } // cache activity state for rotation change - internal fun updateProfile(newProfileData: ProfileData) { + internal fun updateProfile(newProfileData: ProfileDataInUi) { if (profileData.value is Success) { val newProfileSource = profileData.value?.data?.source?.copy(note = newProfileData.note, fields = newProfileData.fields) val newProfile = profileData.value?.data?.copy( @@ -166,17 +163,17 @@ class EditProfileViewModel @Inject constructor( source = newProfileSource ) - profileData.postValue(Success(newProfile)) + profileData.value = Success(newProfile) } } - internal fun hasUnsavedChanges(newProfileData: ProfileData): Boolean { + internal fun hasUnsavedChanges(newProfileData: ProfileDataInUi): Boolean { val diff = getProfileDiff(apiProfileAccount, newProfileData) return diff.hasChanges() } - private fun getProfileDiff(oldProfileAccount: Account?, newProfileData: ProfileData): DiffProfileData { + private fun getProfileDiff(oldProfileAccount: Account?, newProfileData: ProfileDataInUi): DiffProfileData { val displayName = if (oldProfileAccount?.displayName == newProfileData.displayName) { null } else { diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 2233b2dea..a04f6ca5b 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -819,6 +819,5 @@ Playback failed: %s Delete filter \'%1$s\'?" Delete - Unsaved Changes - Do you want to save your profile changes? + Do you want to save your profile changes?