mirror of
https://github.com/sudoxnym/habitica-android.git
synced 2026-05-22 05:38:55 +00:00
Refactor: Fix logic for language discovery at registration
This commit fixes the logic of language discovery at registration. As opposed to using the LanguageHelper class, the new logic looks at the resources themselves to determine whether the app can support the language of the phone.
This commit is contained in:
parent
d2d8cb597f
commit
4b63b63b0d
2 changed files with 10 additions and 20 deletions
|
|
@ -9,8 +9,6 @@ public class LanguageHelper {
|
|||
|
||||
private Locale locale = null;
|
||||
private String languageCode = null;
|
||||
private boolean languageAvailable = false;
|
||||
|
||||
|
||||
public LanguageHelper (String languageSharedPref) {
|
||||
|
||||
|
|
@ -18,22 +16,18 @@ public class LanguageHelper {
|
|||
case "iw":
|
||||
locale = new Locale("iw");
|
||||
languageCode = "he";
|
||||
languageAvailable = true;
|
||||
break;
|
||||
case "hr":
|
||||
locale = new Locale("hr", "HR");
|
||||
languageCode = "hu";
|
||||
languageAvailable = true;
|
||||
break;
|
||||
case "in":
|
||||
locale = new Locale("in");
|
||||
languageCode = "id";
|
||||
languageAvailable = true;
|
||||
break;
|
||||
case "pt":
|
||||
locale = new Locale("pt","PT");
|
||||
languageCode = "pt";
|
||||
languageAvailable = true;
|
||||
break;
|
||||
default:
|
||||
if (languageSharedPref.contains("_")) {
|
||||
|
|
@ -43,15 +37,10 @@ public class LanguageHelper {
|
|||
locale = new Locale(languageSharedPref);
|
||||
}
|
||||
languageCode = languageSharedPref;
|
||||
languageAvailable = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isLanguageAvailable() {
|
||||
return languageAvailable;
|
||||
}
|
||||
|
||||
public String getLanguageCode() {
|
||||
return languageCode;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,7 +16,6 @@ import com.habitrpg.android.habitica.callbacks.HabitRPGUserCallback;
|
|||
import com.habitrpg.android.habitica.callbacks.MergeUserCallback;
|
||||
import com.habitrpg.android.habitica.components.AppComponent;
|
||||
import com.habitrpg.android.habitica.events.commands.UpdateUserCommand;
|
||||
import com.habitrpg.android.habitica.helpers.LanguageHelper;
|
||||
import com.habitrpg.android.habitica.ui.fragments.setup.AvatarSetupFragment;
|
||||
import com.habitrpg.android.habitica.ui.fragments.setup.TaskSetupFragment;
|
||||
import com.magicmicky.habitrpgwrapper.lib.models.HabitRPGUser;
|
||||
|
|
@ -79,6 +78,16 @@ public class SetupActivity extends BaseActivity implements View.OnClickListener,
|
|||
} catch (JSONException exception) {
|
||||
}
|
||||
Amplitude.getInstance().logEvent("setup", eventProperties);
|
||||
|
||||
String currentDeviceLanguage = Locale.getDefault().getLanguage();
|
||||
for (String language : getResources().getStringArray(R.array.LanguageValues)) {
|
||||
if (language.equals(currentDeviceLanguage)) {
|
||||
apiHelper.apiService.registrationLanguage(currentDeviceLanguage)
|
||||
.compose(apiHelper.configureApiCallObserver())
|
||||
.subscribe(new MergeUserCallback(this, user), throwable -> {
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -151,14 +160,6 @@ public class SetupActivity extends BaseActivity implements View.OnClickListener,
|
|||
@Override
|
||||
public void onClick(View v) {
|
||||
if (v == this.nextButton) {
|
||||
String currentDeviceLanguage = Locale.getDefault().getLanguage();
|
||||
LanguageHelper languageHelper = new LanguageHelper(currentDeviceLanguage);
|
||||
if (languageHelper.isLanguageAvailable()){
|
||||
apiHelper.apiService.registrationLanguage(currentDeviceLanguage)
|
||||
.compose(apiHelper.configureApiCallObserver())
|
||||
.subscribe(new MergeUserCallback(this, user), throwable -> {
|
||||
});
|
||||
}
|
||||
if (this.pager.getCurrentItem() == 1) {
|
||||
List<Task> newTasks = this.taskSetupFragment.createSampleTasks();
|
||||
this.completedSetup = true;
|
||||
|
|
|
|||
Loading…
Reference in a new issue