diff --git a/Habitica/res/layout/dialog_edittext_confirm_pw.xml b/Habitica/res/layout/dialog_edittext_confirm_pw.xml index b71ed91661..cbd8afb9f9 100644 --- a/Habitica/res/layout/dialog_edittext_confirm_pw.xml +++ b/Habitica/res/layout/dialog_edittext_confirm_pw.xml @@ -8,6 +8,7 @@ android:layout_width="match_parent" android:layout_height="wrap_content" /> Change Password Change Email Address Change Login Name + Change Username Change Character Level Auto Allocate Points diff --git a/Habitica/src/main/java/com/habitrpg/android/habitica/data/ApiClient.kt b/Habitica/src/main/java/com/habitrpg/android/habitica/data/ApiClient.kt index 815a9ac07f..1b0363ff79 100644 --- a/Habitica/src/main/java/com/habitrpg/android/habitica/data/ApiClient.kt +++ b/Habitica/src/main/java/com/habitrpg/android/habitica/data/ApiClient.kt @@ -232,6 +232,7 @@ interface ApiClient { fun sendPasswordResetEmail(email: String): Flowable fun updateLoginName(newLoginName: String, password: String): Flowable + fun updateUsername(newLoginName: String): Flowable fun updateEmail(newEmail: String, password: String): Flowable diff --git a/Habitica/src/main/java/com/habitrpg/android/habitica/data/UserRepository.kt b/Habitica/src/main/java/com/habitrpg/android/habitica/data/UserRepository.kt index 6be0237fa0..e2a5ff5685 100644 --- a/Habitica/src/main/java/com/habitrpg/android/habitica/data/UserRepository.kt +++ b/Habitica/src/main/java/com/habitrpg/android/habitica/data/UserRepository.kt @@ -63,7 +63,7 @@ interface UserRepository : BaseRepository { fun sendPasswordResetEmail(email: String): Flowable - fun updateLoginName(newLoginName: String, password: String): Flowable + fun updateLoginName(newLoginName: String, password: String? = null): Flowable fun updateEmail(newEmail: String, password: String): Flowable fun updatePassword(newPassword: String, oldPassword: String, oldPasswordConfirmation: String): Flowable diff --git a/Habitica/src/main/java/com/habitrpg/android/habitica/data/implementation/ApiClientImpl.kt b/Habitica/src/main/java/com/habitrpg/android/habitica/data/implementation/ApiClientImpl.kt index c6018a6219..50936f351d 100644 --- a/Habitica/src/main/java/com/habitrpg/android/habitica/data/implementation/ApiClientImpl.kt +++ b/Habitica/src/main/java/com/habitrpg/android/habitica/data/implementation/ApiClientImpl.kt @@ -653,6 +653,12 @@ class ApiClientImpl//private OnHabitsAPIResult mResultListener; return apiService.updateLoginName(updateObject).compose(configureApiCallObserver()) } + override fun updateUsername(newLoginName: String): Flowable { + val updateObject = HashMap() + updateObject["username"] = newLoginName + return apiService.updateLoginName(updateObject).compose(configureApiCallObserver()) + } + override fun updateEmail(newEmail: String, password: String): Flowable { val updateObject = HashMap() updateObject["newEmail"] = newEmail diff --git a/Habitica/src/main/java/com/habitrpg/android/habitica/data/implementation/UserRepositoryImpl.kt b/Habitica/src/main/java/com/habitrpg/android/habitica/data/implementation/UserRepositoryImpl.kt index 5924f8a5b8..f5401e3a69 100644 --- a/Habitica/src/main/java/com/habitrpg/android/habitica/data/implementation/UserRepositoryImpl.kt +++ b/Habitica/src/main/java/com/habitrpg/android/habitica/data/implementation/UserRepositoryImpl.kt @@ -205,8 +205,13 @@ class UserRepositoryImpl(localRepository: UserLocalRepository, apiClient: ApiCli override fun sendPasswordResetEmail(email: String): Flowable = apiClient.sendPasswordResetEmail(email) - override fun updateLoginName(newLoginName: String, password: String): Flowable = + override fun updateLoginName(newLoginName: String, password: String?): Flowable { + return if (password != null) { apiClient.updateLoginName(newLoginName, password) + } else { + apiClient.updateUsername(newLoginName) + } + } override fun updateEmail(newEmail: String, password: String): Flowable = apiClient.updateEmail(newEmail, password) diff --git a/Habitica/src/main/java/com/habitrpg/android/habitica/helpers/RemoteConfigManager.java b/Habitica/src/main/java/com/habitrpg/android/habitica/helpers/RemoteConfigManager.java index 316fffab40..5a77394469 100644 --- a/Habitica/src/main/java/com/habitrpg/android/habitica/helpers/RemoteConfigManager.java +++ b/Habitica/src/main/java/com/habitrpg/android/habitica/helpers/RemoteConfigManager.java @@ -24,6 +24,7 @@ public class RemoteConfigManager { private Boolean enableNewShops = false; private String shopSpriteSuffix = ""; private Integer maxChatLength = 3000; + private Boolean enableChangeUsername = false; private String REMOTE_STRING_KEY = "remote-string"; public RemoteConfigManager(Context context) { @@ -46,6 +47,8 @@ public String shopSpriteSuffix() { public Integer maxChatLength() { return maxChatLength; } + public Boolean enableChangeUsername() { return enableChangeUsername; } + private void loadFromPreferences () { String storedPreferences = PreferenceManager.getDefaultSharedPreferences(context) .getString(REMOTE_STRING_KEY, ""); @@ -70,6 +73,9 @@ private void parseConfig(String jsonString) { if (obj.has("maxChatLength")) { maxChatLength = obj.getInt("maxChatLength"); } + if (obj.has("enableChangeUsername")) { + enableChangeUsername = obj.getBoolean("enableChangeUsername"); + } } catch (JSONException e) { e.printStackTrace(); } diff --git a/Habitica/src/main/java/com/habitrpg/android/habitica/ui/activities/LoginActivity.kt b/Habitica/src/main/java/com/habitrpg/android/habitica/ui/activities/LoginActivity.kt index ce97803f88..7f3d4f45f1 100644 --- a/Habitica/src/main/java/com/habitrpg/android/habitica/ui/activities/LoginActivity.kt +++ b/Habitica/src/main/java/com/habitrpg/android/habitica/ui/activities/LoginActivity.kt @@ -125,6 +125,7 @@ class LoginActivity : BaseActivity(), Consumer { } override fun onCreate(savedInstanceState: Bundle?) { + FacebookSdk.sdkInitialize(this.applicationContext) super.onCreate(savedInstanceState) supportActionBar?.hide() //Set default values to avoid null-responses when requesting unedited settings @@ -248,9 +249,9 @@ class LoginActivity : BaseActivity(), Consumer { } override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { - super.onActivityResult(requestCode, resultCode, intent) - callbackManager.onActivityResult(requestCode, resultCode, intent) - val scanResult = IntentIntegrator.parseActivityResult(requestCode, resultCode, intent) + super.onActivityResult(requestCode, resultCode, data) + callbackManager.onActivityResult(requestCode, resultCode, data) + val scanResult = IntentIntegrator.parseActivityResult(requestCode, resultCode, data) if (scanResult != null) { try { Log.d("scanresult", scanResult.contents) diff --git a/Habitica/src/main/java/com/habitrpg/android/habitica/ui/fragments/preferences/AuthenticationPreferenceFragment.kt b/Habitica/src/main/java/com/habitrpg/android/habitica/ui/fragments/preferences/AuthenticationPreferenceFragment.kt index 99c7344dbd..bdea0efffd 100644 --- a/Habitica/src/main/java/com/habitrpg/android/habitica/ui/fragments/preferences/AuthenticationPreferenceFragment.kt +++ b/Habitica/src/main/java/com/habitrpg/android/habitica/ui/fragments/preferences/AuthenticationPreferenceFragment.kt @@ -10,8 +10,10 @@ import android.support.v4.content.ContextCompat import android.support.v7.app.AlertDialog import android.support.v7.preference.Preference import android.text.InputType +import android.view.View import android.widget.EditText import android.widget.LinearLayout +import android.widget.TextView import android.widget.Toast import com.habitrpg.android.habitica.HabiticaApplication import com.habitrpg.android.habitica.HabiticaBaseApplication @@ -19,14 +21,19 @@ import com.habitrpg.android.habitica.R import com.habitrpg.android.habitica.events.commands.OpenGemPurchaseFragmentCommand import com.habitrpg.android.habitica.extensions.layoutInflater import com.habitrpg.android.habitica.extensions.notNull +import com.habitrpg.android.habitica.helpers.RemoteConfigManager import com.habitrpg.android.habitica.helpers.RxErrorHandler import com.habitrpg.android.habitica.models.user.User import com.habitrpg.android.habitica.ui.views.subscriptions.SubscriptionDetailsView import io.reactivex.functions.Consumer import org.greenrobot.eventbus.EventBus +import javax.inject.Inject class AuthenticationPreferenceFragment: BasePreferencesFragment() { + @Inject + lateinit var configManager: RemoteConfigManager + override var user: User? = null set(value) { field = value @@ -37,6 +44,10 @@ class AuthenticationPreferenceFragment: BasePreferencesFragment() { override fun onCreate(savedInstanceState: Bundle?) { HabiticaBaseApplication.component?.inject(this) super.onCreate(savedInstanceState) + + if (configManager.enableChangeUsername()) { + findPreference("login_name").title = context?.getString(R.string.username) + } } private fun updateUserFields() { @@ -109,11 +120,20 @@ class AuthenticationPreferenceFragment: BasePreferencesFragment() { val loginNameEditText = view?.findViewById(R.id.editText) loginNameEditText?.setText(user?.authentication?.localAuthentication?.username) val passwordEditText = view?.findViewById(R.id.passwordEditText) + if (configManager.enableChangeUsername()) { + passwordEditText?.visibility = View.GONE + val passwordTitleTextView = view?.findViewById(R.id.passwordTitleTextView) + passwordTitleTextView?.visibility = View.GONE + } context.notNull { context -> - val dialog = AlertDialog.Builder(context) + var builder = AlertDialog.Builder(context) + builder = if (configManager.enableChangeUsername()) { + builder.setTitle(R.string.change_username) + } else { + builder.setTitle(R.string.change_login_name) + } - .setTitle(R.string.change_login_name) - .setPositiveButton(R.string.change) { thisDialog, _ -> + val dialog = builder.setPositiveButton(R.string.change) { thisDialog, _ -> thisDialog.dismiss() userRepository.updateLoginName(loginNameEditText?.text.toString(), passwordEditText?.text.toString()) .subscribe(Consumer {