Commit 2c7d2e16 authored by Grigory Fedorov's avatar Grigory Fedorov

AccountInfoEditor: "save" menu item state stored correctly.

parent 53b9fcbb
...@@ -21,6 +21,8 @@ public class AccountInfoEditor extends ManagedActivity implements Toolbar.OnMenu ...@@ -21,6 +21,8 @@ public class AccountInfoEditor extends ManagedActivity implements Toolbar.OnMenu
public static final String ARG_VCARD = "com.xabber.android.ui.AccountInfoEditor.ARG_VCARD"; public static final String ARG_VCARD = "com.xabber.android.ui.AccountInfoEditor.ARG_VCARD";
public static final int SAVE_MENU = R.menu.save; public static final int SAVE_MENU = R.menu.save;
public static final String ARGUMENT_SAVE_BUTTON_ENABLED = "com.xabber.android.ui.AccountInfoEditor.ARGUMENT_SAVE_BUTTON_ENABLED";
private Toolbar toolbar; private Toolbar toolbar;
...@@ -64,16 +66,25 @@ public class AccountInfoEditor extends ManagedActivity implements Toolbar.OnMenu ...@@ -64,16 +66,25 @@ public class AccountInfoEditor extends ManagedActivity implements Toolbar.OnMenu
BarPainter barPainter = new BarPainter(this, toolbar); BarPainter barPainter = new BarPainter(this, toolbar);
barPainter.updateWithAccountName(account); barPainter.updateWithAccountName(account);
toolbar.inflateMenu(SAVE_MENU);
toolbar.setOnMenuItemClickListener(this);
boolean isSaveButtonEnabled = false;
if (savedInstanceState == null) { if (savedInstanceState == null) {
getFragmentManager().beginTransaction() getFragmentManager().beginTransaction()
.add(R.id.fragment_container, AccountInfoEditorFragment.newInstance(account, vCard)).commit(); .add(R.id.fragment_container, AccountInfoEditorFragment.newInstance(account, vCard)).commit();
} else {
isSaveButtonEnabled = savedInstanceState.getBoolean(ARGUMENT_SAVE_BUTTON_ENABLED);
} }
toolbar.getMenu().findItem(R.id.action_save).setEnabled(isSaveButtonEnabled);
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN); getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN);
}
toolbar.inflateMenu(SAVE_MENU); @Override
toolbar.setOnMenuItemClickListener(this); protected void onSaveInstanceState(Bundle outState) {
toolbar.getMenu().findItem(R.id.action_save).setEnabled(false); super.onSaveInstanceState(outState);
outState.putBoolean(ARGUMENT_SAVE_BUTTON_ENABLED, toolbar.getMenu().findItem(R.id.action_save).isEnabled());
} }
@Override @Override
......
...@@ -65,42 +65,35 @@ public class AccountInfoEditorFragment extends Fragment implements OnVCardSaveLi ...@@ -65,42 +65,35 @@ public class AccountInfoEditorFragment extends Fragment implements OnVCardSaveLi
public static final String DATE_FORMAT_INT_TO_STRING = "%d-%02d-%02d"; public static final String DATE_FORMAT_INT_TO_STRING = "%d-%02d-%02d";
private VCard vCard; private VCard vCard;
private String account;
private View progressBar;
private boolean isSaveSuccess;
private Listener listener;
private boolean updateFromVCardFlag = true;
private TextView account_jid;
private LinearLayout fields;
private EditText formattedName;
private EditText prefixName; private EditText prefixName;
private EditText givenName; private EditText givenName;
private EditText middleName; private EditText middleName;
private EditText familyName; private EditText familyName;
private EditText suffixName; private EditText suffixName;
private EditText nickName; private EditText nickName;
private String account;
private EditText organization;
private EditText organizationUnit;
private EditText title; private EditText title;
private EditText role; private EditText role;
private EditText organizationUnit;
private EditText organization;
private EditText url; private EditText url;
private EditText description; private EditText description;
private EditText emailHome; private EditText emailHome;
private EditText emailWork; private EditText emailWork;
private EditText phoneHome; private EditText phoneHome;
private EditText phoneWork; private EditText phoneWork;
private EditText formattedName;
private View progressBar;
private boolean isSaveSuccess;
private LinearLayout fields;
private TextView avatarSize;
private Listener listener;
private TextView birthDate;
private DatePickerDialog datePicker;
private View changeAvatarButton;
private ImageView avatar;
private Uri newAvatarImageUri;
private Uri photoFileUri;
private boolean removeAvatarFlag = false;
private View birthDateRemoveButton;
private TextView account_jid;
private EditText addressHomePostOfficeBox; private EditText addressHomePostOfficeBox;
private EditText addressHomePostExtended; private EditText addressHomePostExtended;
private EditText addressHomePostStreet; private EditText addressHomePostStreet;
...@@ -108,6 +101,7 @@ public class AccountInfoEditorFragment extends Fragment implements OnVCardSaveLi ...@@ -108,6 +101,7 @@ public class AccountInfoEditorFragment extends Fragment implements OnVCardSaveLi
private EditText addressHomeRegion; private EditText addressHomeRegion;
private EditText addressHomeCountry; private EditText addressHomeCountry;
private EditText addressHomePostalCode; private EditText addressHomePostalCode;
private EditText addressWorkPostOfficeBox; private EditText addressWorkPostOfficeBox;
private EditText addressWorkPostExtended; private EditText addressWorkPostExtended;
private EditText addressWorkPostStreet; private EditText addressWorkPostStreet;
...@@ -115,7 +109,17 @@ public class AccountInfoEditorFragment extends Fragment implements OnVCardSaveLi ...@@ -115,7 +109,17 @@ public class AccountInfoEditorFragment extends Fragment implements OnVCardSaveLi
private EditText addressWorkRegion; private EditText addressWorkRegion;
private EditText addressWorkCountry; private EditText addressWorkCountry;
private EditText addressWorkPostalCode; private EditText addressWorkPostalCode;
private boolean updateFromVCardFlag = false;
private ImageView avatar;
private TextView avatarSize;
private View changeAvatarButton;
private Uri newAvatarImageUri;
private Uri photoFileUri;
private boolean removeAvatarFlag = false;
private TextView birthDate;
private DatePickerDialog datePicker;
private View birthDateRemoveButton;
interface Listener { interface Listener {
void onVCardSavingStarted(); void onVCardSavingStarted();
...@@ -258,6 +262,7 @@ public class AccountInfoEditorFragment extends Fragment implements OnVCardSaveLi ...@@ -258,6 +262,7 @@ public class AccountInfoEditorFragment extends Fragment implements OnVCardSaveLi
if (vCardManager.isVCardRequested(account) || vCardManager.isVCardSaveRequested(account)) { if (vCardManager.isVCardRequested(account) || vCardManager.isVCardSaveRequested(account)) {
enableProgressMode(); enableProgressMode();
} }
updateFromVCardFlag = false;
} }
@Override @Override
...@@ -275,8 +280,6 @@ public class AccountInfoEditorFragment extends Fragment implements OnVCardSaveLi ...@@ -275,8 +280,6 @@ public class AccountInfoEditorFragment extends Fragment implements OnVCardSaveLi
} }
private void setFieldsFromVCard() { private void setFieldsFromVCard() {
updateFromVCardFlag = true;
account_jid.setText(Jid.getBareAddress(account)); account_jid.setText(Jid.getBareAddress(account));
formattedName.setText(vCard.getField(VCardProperty.FN.name())); formattedName.setText(vCard.getField(VCardProperty.FN.name()));
...@@ -334,8 +337,6 @@ public class AccountInfoEditorFragment extends Fragment implements OnVCardSaveLi ...@@ -334,8 +337,6 @@ public class AccountInfoEditorFragment extends Fragment implements OnVCardSaveLi
addressWorkRegion.setText(vCard.getAddressFieldWork(AddressProperty.REGION.name())); addressWorkRegion.setText(vCard.getAddressFieldWork(AddressProperty.REGION.name()));
addressWorkCountry.setText(vCard.getAddressFieldWork(AddressProperty.CTRY.name())); addressWorkCountry.setText(vCard.getAddressFieldWork(AddressProperty.CTRY.name()));
addressWorkPostalCode.setText(vCard.getAddressFieldWork(AddressProperty.PCODE.name())); addressWorkPostalCode.setText(vCard.getAddressFieldWork(AddressProperty.PCODE.name()));
updateFromVCardFlag = false;
} }
public void updateDatePickerDialog() { public void updateDatePickerDialog() {
...@@ -615,9 +616,10 @@ public class AccountInfoEditorFragment extends Fragment implements OnVCardSaveLi ...@@ -615,9 +616,10 @@ public class AccountInfoEditorFragment extends Fragment implements OnVCardSaveLi
getActivity().finish(); getActivity().finish();
} else { } else {
disableProgressMode(); disableProgressMode();
this.vCard = vCard; this.vCard = vCard;
updateFromVCardFlag = true;
setFieldsFromVCard(); setFieldsFromVCard();
updateFromVCardFlag = false;
} }
} }
...@@ -657,7 +659,7 @@ public class AccountInfoEditorFragment extends Fragment implements OnVCardSaveLi ...@@ -657,7 +659,7 @@ public class AccountInfoEditorFragment extends Fragment implements OnVCardSaveLi
@Override @Override
public void onTextChanged(CharSequence s, int start, int before, int count) { public void onTextChanged(CharSequence s, int start, int before, int count) {
if (!updateFromVCardFlag) { if (!updateFromVCardFlag && listener != null) {
listener.enableSave(); listener.enableSave();
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment