mirror of
https://github.com/sudoxnym/habitica-android.git
synced 2026-05-24 06:35:46 +00:00
Fix updating username
This commit is contained in:
parent
3371db97e0
commit
436ca59954
7 changed files with 16 additions and 11 deletions
|
|
@ -10,6 +10,7 @@ import com.habitrpg.android.habitica.models.tasks.Task
|
|||
import com.habitrpg.android.habitica.models.user.Stats
|
||||
import com.habitrpg.android.habitica.models.user.User
|
||||
import io.reactivex.Flowable
|
||||
import io.reactivex.Maybe
|
||||
import io.realm.RealmResults
|
||||
|
||||
interface UserRepository : BaseRepository {
|
||||
|
|
@ -63,7 +64,7 @@ interface UserRepository : BaseRepository {
|
|||
|
||||
fun sendPasswordResetEmail(email: String): Flowable<Void>
|
||||
|
||||
fun updateLoginName(newLoginName: String, password: String? = null): Flowable<Void>
|
||||
fun updateLoginName(newLoginName: String, password: String? = null): Maybe<User>
|
||||
fun updateEmail(newEmail: String, password: String): Flowable<Void>
|
||||
fun updatePassword(newPassword: String, oldPassword: String, oldPasswordConfirmation: String): Flowable<Void>
|
||||
|
||||
|
|
|
|||
|
|
@ -205,12 +205,19 @@ class UserRepositoryImpl(localRepository: UserLocalRepository, apiClient: ApiCli
|
|||
override fun sendPasswordResetEmail(email: String): Flowable<Void> =
|
||||
apiClient.sendPasswordResetEmail(email)
|
||||
|
||||
override fun updateLoginName(newLoginName: String, password: String?): Flowable<Void> {
|
||||
return if (password != null) {
|
||||
override fun updateLoginName(newLoginName: String, password: String?): Maybe<User> {
|
||||
return (if (password != null && password.isNotEmpty()) {
|
||||
apiClient.updateLoginName(newLoginName, password)
|
||||
} else {
|
||||
apiClient.updateUsername(newLoginName)
|
||||
}
|
||||
}).flatMapMaybe { localRepository.getUser(userID).firstElement() }
|
||||
.doOnNext { user ->
|
||||
localRepository.executeTransaction {
|
||||
user.authentication?.localAuthentication?.username = newLoginName
|
||||
user.flags?.isVerifiedUsername = true
|
||||
}
|
||||
}
|
||||
.firstElement()
|
||||
}
|
||||
|
||||
override fun updateEmail(newEmail: String, password: String): Flowable<Void> =
|
||||
|
|
|
|||
|
|
@ -47,7 +47,7 @@ public class RemoteConfigManager {
|
|||
|
||||
public Integer maxChatLength() { return maxChatLength; }
|
||||
|
||||
public Boolean enableChangeUsername() { return enableChangeUsername; }
|
||||
public Boolean enableChangeUsername() { return true; }
|
||||
|
||||
private void loadFromPreferences () {
|
||||
String storedPreferences = PreferenceManager.getDefaultSharedPreferences(context)
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@ import io.realm.annotations.PrimaryKey;
|
|||
public class LocalAuthentication extends RealmObject {
|
||||
|
||||
@PrimaryKey
|
||||
public String userID;
|
||||
String username;
|
||||
String email;
|
||||
|
||||
|
|
|
|||
|
|
@ -13,6 +13,7 @@ open class Authentication : RealmObject() {
|
|||
set(value) {
|
||||
field = value
|
||||
timestamps?.userId = value
|
||||
localAuthentication?.userID = value
|
||||
}
|
||||
|
||||
@SerializedName("local")
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@ abstract class BasePreferencesFragment : PreferenceFragmentCompat() {
|
|||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
|
||||
userRepository.getUser(userId).firstElement().subscribe(Consumer<User> {
|
||||
userRepository.getUser(userId).subscribe(Consumer<User> {
|
||||
this.user = it
|
||||
}, RxErrorHandler.handleEmptyError())
|
||||
}
|
||||
|
|
|
|||
|
|
@ -45,11 +45,6 @@ class PreferencesFragment : BasePreferencesFragment(), SharedPreferences.OnShare
|
|||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
HabiticaBaseApplication.component?.inject(this)
|
||||
super.onCreate(savedInstanceState)
|
||||
|
||||
val userID = preferenceManager.sharedPreferences.getString(context?.getString(R.string.SP_userID), null)
|
||||
if (userID != null) {
|
||||
compositeSubscription.add(userRepository.getUser(userID).subscribe(Consumer { this@PreferencesFragment.setUser(it) }, RxErrorHandler.handleEmptyError()))
|
||||
}
|
||||
}
|
||||
|
||||
override fun setupPreferences() {
|
||||
|
|
|
|||
Loading…
Reference in a new issue