Skip to content
This repository has been archived by the owner on Jan 23, 2019. It is now read-only.

Commit

Permalink
Fix EditText/Button not being updated on locale change
Browse files Browse the repository at this point in the history
  • Loading branch information
Lonami committed Jan 25, 2017
1 parent 70199ae commit e07237d
Showing 1 changed file with 21 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import android.os.Bundle;
import android.os.Environment;
import android.os.ParcelFileDescriptor;
import android.support.annotation.NonNull;
import android.support.v4.provider.DocumentFile;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;
Expand Down Expand Up @@ -797,6 +798,11 @@ private void loadStringIDsSpinner() {

// Sets the current locale also updating the spinner selection
private void setCurrentLocale(String locale) {
// Clear the previous EditText fields
mOriginalStringEditText.setText("");
mTranslatedStringEditText.setText("");

// Update the selected locale
mSelectedLocale = locale;
mRepo.setLastLocale(locale);

Expand All @@ -810,6 +816,9 @@ private void setCurrentLocale(String locale) {

checkTranslationVisibility();
loadStringIDsSpinner();

// There might be no strings, in which case we need to hide some buttons
checkPreviousNextVisibility();
}

//endregion
Expand Down Expand Up @@ -898,23 +907,28 @@ private void setStringId(String id) {
}

// Updates the selected resource ID and also the EditTexts for its contents
private void updateSelectedResourceId(String resourceId) {
mSelectedResource = mDefaultResources.getTag(resourceId);
mOriginalStringEditText.setText(mSelectedResource.getContent());
mTranslatedStringEditText.setText(mSelectedLocaleResources.getContent(resourceId));
private void updateSelectedResourceId(@NonNull String resourceId) {
if (resourceId.isEmpty()) {
mSelectedResource = null;
mOriginalStringEditText.setText("");
mTranslatedStringEditText.setText("");
} else {
mSelectedResource = mDefaultResources.getTag(resourceId);
mOriginalStringEditText.setText(mSelectedResource.getContent());
mTranslatedStringEditText.setText(mSelectedLocaleResources.getContent(resourceId));
}
checkPreviousNextVisibility();
updateProgress();
}

private void checkPreviousNextVisibility() {
int i = mStringIdSpinner.getSelectedItemPosition();
int countM1 = mStringIdSpinner.getCount()-1;

if (countM1 == 0) {
if (countM1 <= 0) {
// Special case: set visibility to GONE so the Save button grows
mPreviousButton.setVisibility(View.GONE);
mNextButton.setVisibility(View.GONE);
} else {
int i = mStringIdSpinner.getSelectedItemPosition();
mPreviousButton.setVisibility(i == 0 ? View.INVISIBLE : View.VISIBLE);
mNextButton.setVisibility(i == countM1 ? View.INVISIBLE : View.VISIBLE);
}
Expand Down

0 comments on commit e07237d

Please sign in to comment.