Commit 30a3d9cf authored by Grigory Fedorov's avatar Grigory Fedorov

AccountInfoEditorFragment: "save" button activated only after data change....

AccountInfoEditorFragment: "save" button activated only after data change. todo: save state for rotation.
parent bec8b4b3
...@@ -73,6 +73,7 @@ public class AccountInfoEditor extends ManagedActivity implements Toolbar.OnMenu ...@@ -73,6 +73,7 @@ public class AccountInfoEditor extends ManagedActivity implements Toolbar.OnMenu
toolbar.inflateMenu(SAVE_MENU); toolbar.inflateMenu(SAVE_MENU);
toolbar.setOnMenuItemClickListener(this); toolbar.setOnMenuItemClickListener(this);
toolbar.getMenu().findItem(R.id.action_save).setEnabled(false);
} }
@Override @Override
...@@ -115,6 +116,10 @@ public class AccountInfoEditor extends ManagedActivity implements Toolbar.OnMenu ...@@ -115,6 +116,10 @@ public class AccountInfoEditor extends ManagedActivity implements Toolbar.OnMenu
@Override @Override
public void onVCardSavingFinished() { public void onVCardSavingFinished() {
toolbar.setTitle(R.string.edit_account_user_info); toolbar.setTitle(R.string.edit_account_user_info);
}
@Override
public void enableSave() {
toolbar.getMenu().findItem(R.id.action_save).setEnabled(true); toolbar.getMenu().findItem(R.id.action_save).setEnabled(true);
} }
} }
...@@ -8,6 +8,8 @@ import android.net.Uri; ...@@ -8,6 +8,8 @@ import android.net.Uri;
import android.os.Bundle; import android.os.Bundle;
import android.provider.MediaStore; import android.provider.MediaStore;
import android.support.annotation.Nullable; import android.support.annotation.Nullable;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.MenuItem; import android.view.MenuItem;
import android.view.View; import android.view.View;
...@@ -50,7 +52,7 @@ import java.util.GregorianCalendar; ...@@ -50,7 +52,7 @@ import java.util.GregorianCalendar;
import java.util.Locale; import java.util.Locale;
import java.util.TimeZone; import java.util.TimeZone;
public class AccountInfoEditorFragment extends Fragment implements OnVCardSaveListener, OnVCardListener, DatePickerDialog.OnDateSetListener { public class AccountInfoEditorFragment extends Fragment implements OnVCardSaveListener, OnVCardListener, DatePickerDialog.OnDateSetListener, TextWatcher {
public static final String ARGUMENT_ACCOUNT = "com.xabber.android.ui.AccountInfoEditorFragment.ARGUMENT_ACCOUNT"; public static final String ARGUMENT_ACCOUNT = "com.xabber.android.ui.AccountInfoEditorFragment.ARGUMENT_ACCOUNT";
public static final String ARGUMENT_VCARD = "com.xabber.android.ui.AccountInfoEditorFragment.ARGUMENT_USER"; public static final String ARGUMENT_VCARD = "com.xabber.android.ui.AccountInfoEditorFragment.ARGUMENT_USER";
...@@ -113,10 +115,12 @@ public class AccountInfoEditorFragment extends Fragment implements OnVCardSaveLi ...@@ -113,10 +115,12 @@ 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;
interface Listener { interface Listener {
void onVCardSavingStarted(); void onVCardSavingStarted();
void onVCardSavingFinished(); void onVCardSavingFinished();
void enableSave();
} }
public static AccountInfoEditorFragment newInstance(String account, String vCard) { public static AccountInfoEditorFragment newInstance(String account, String vCard) {
...@@ -165,13 +169,13 @@ public class AccountInfoEditorFragment extends Fragment implements OnVCardSaveLi ...@@ -165,13 +169,13 @@ public class AccountInfoEditorFragment extends Fragment implements OnVCardSaveLi
account_jid = (TextView) view.findViewById(R.id.vcard_jid); account_jid = (TextView) view.findViewById(R.id.vcard_jid);
prefixName = (EditText) view.findViewById(R.id.vcard_prefix_name); prefixName = setUpInputField(view, R.id.vcard_prefix_name);
formattedName = (EditText) view.findViewById(R.id.vcard_formatted_name); formattedName = setUpInputField(view, R.id.vcard_formatted_name);
givenName = (EditText) view.findViewById(R.id.vcard_given_name); givenName = setUpInputField(view, R.id.vcard_given_name);
middleName = (EditText) view.findViewById(R.id.vcard_middle_name); middleName = setUpInputField(view, R.id.vcard_middle_name);
familyName = (EditText) view.findViewById(R.id.vcard_family_name); familyName = setUpInputField(view, R.id.vcard_family_name);
suffixName = (EditText) view.findViewById(R.id.vcard_suffix_name); suffixName = setUpInputField(view, R.id.vcard_suffix_name);
nickName = (EditText) view.findViewById(R.id.vcard_nickname); nickName = setUpInputField(view, R.id.vcard_nickname);
avatar = (ImageView) view.findViewById(R.id.vcard_avatar); avatar = (ImageView) view.findViewById(R.id.vcard_avatar);
avatarSize = (TextView) view.findViewById(R.id.vcard_avatar_size_text_view); avatarSize = (TextView) view.findViewById(R.id.vcard_avatar_size_text_view);
...@@ -191,6 +195,7 @@ public class AccountInfoEditorFragment extends Fragment implements OnVCardSaveLi ...@@ -191,6 +195,7 @@ public class AccountInfoEditorFragment extends Fragment implements OnVCardSaveLi
datePicker.show(); datePicker.show();
} }
}); });
birthDate.addTextChangedListener(this);
birthDateRemoveButton = view.findViewById(R.id.vcard_birth_date_remove_button); birthDateRemoveButton = view.findViewById(R.id.vcard_birth_date_remove_button);
birthDateRemoveButton.setOnClickListener(new View.OnClickListener() { birthDateRemoveButton.setOnClickListener(new View.OnClickListener() {
...@@ -200,42 +205,48 @@ public class AccountInfoEditorFragment extends Fragment implements OnVCardSaveLi ...@@ -200,42 +205,48 @@ public class AccountInfoEditorFragment extends Fragment implements OnVCardSaveLi
} }
}); });
title = (EditText) view.findViewById(R.id.vcard_title); title = setUpInputField(view, R.id.vcard_title);
role = (EditText) view.findViewById(R.id.vcard_role); role = setUpInputField(view, R.id.vcard_role);
organization = (EditText) view.findViewById(R.id.vcard_organization_name); organization = setUpInputField(view, R.id.vcard_organization_name);
organizationUnit = (EditText) view.findViewById(R.id.vcard_organization_unit); organizationUnit = setUpInputField(view, R.id.vcard_organization_unit);
url = (EditText) view.findViewById(R.id.vcard_url); url = setUpInputField(view, R.id.vcard_url);
description = (EditText) view.findViewById(R.id.vcard_decsription); description = setUpInputField(view, R.id.vcard_decsription);
phoneHome = (EditText) view.findViewById(R.id.vcard_phone_home); phoneHome = setUpInputField(view, R.id.vcard_phone_home);
phoneWork = (EditText) view.findViewById(R.id.vcard_phone_work); phoneWork = setUpInputField(view, R.id.vcard_phone_work);
emailHome = (EditText) view.findViewById(R.id.vcard_email_home); emailHome = setUpInputField(view, R.id.vcard_email_home);
emailWork = (EditText) view.findViewById(R.id.vcard_email_work); emailWork = setUpInputField(view, R.id.vcard_email_work);
addressHomePostOfficeBox = (EditText) view.findViewById(R.id.vcard_address_home_post_office_box); addressHomePostOfficeBox = setUpInputField(view, R.id.vcard_address_home_post_office_box);
addressHomePostExtended = (EditText) view.findViewById(R.id.vcard_address_home_post_extended); addressHomePostExtended = setUpInputField(view, R.id.vcard_address_home_post_extended);
addressHomePostStreet = (EditText) view.findViewById(R.id.vcard_address_home_post_street); addressHomePostStreet = setUpInputField(view, R.id.vcard_address_home_post_street);
addressHomeLocality = (EditText) view.findViewById(R.id.vcard_address_home_locality); addressHomeLocality = setUpInputField(view, R.id.vcard_address_home_locality);
addressHomeRegion = (EditText) view.findViewById(R.id.vcard_address_home_region); addressHomeRegion = setUpInputField(view, R.id.vcard_address_home_region);
addressHomeCountry = (EditText) view.findViewById(R.id.vcard_address_home_country); addressHomeCountry = setUpInputField(view, R.id.vcard_address_home_country);
addressHomePostalCode = (EditText) view.findViewById(R.id.vcard_address_home_postal_code); addressHomePostalCode = setUpInputField(view, R.id.vcard_address_home_postal_code);
addressWorkPostOfficeBox = (EditText) view.findViewById(R.id.vcard_address_work_post_office_box); addressWorkPostOfficeBox = setUpInputField(view, R.id.vcard_address_work_post_office_box);
addressWorkPostExtended = (EditText) view.findViewById(R.id.vcard_address_work_post_extended); addressWorkPostExtended = setUpInputField(view, R.id.vcard_address_work_post_extended);
addressWorkPostStreet = (EditText) view.findViewById(R.id.vcard_address_work_post_street); addressWorkPostStreet = setUpInputField(view, R.id.vcard_address_work_post_street);
addressWorkLocality = (EditText) view.findViewById(R.id.vcard_address_work_locality); addressWorkLocality = setUpInputField(view, R.id.vcard_address_work_locality);
addressWorkRegion = (EditText) view.findViewById(R.id.vcard_address_work_region); addressWorkRegion = setUpInputField(view, R.id.vcard_address_work_region);
addressWorkCountry = (EditText) view.findViewById(R.id.vcard_address_work_country); addressWorkCountry = setUpInputField(view, R.id.vcard_address_work_country);
addressWorkPostalCode = (EditText) view.findViewById(R.id.vcard_address_work_postal_code); addressWorkPostalCode = setUpInputField(view, R.id.vcard_address_work_postal_code);
setFieldsFromVCard(); setFieldsFromVCard();
return view; return view;
} }
private EditText setUpInputField(View rootView, int resourceId) {
EditText inputField = (EditText) rootView.findViewById(resourceId);
inputField.addTextChangedListener(this);
return inputField;
}
@Override @Override
public void onResume() { public void onResume() {
super.onResume(); super.onResume();
...@@ -264,6 +275,8 @@ public class AccountInfoEditorFragment extends Fragment implements OnVCardSaveLi ...@@ -264,6 +275,8 @@ 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()));
...@@ -321,6 +334,8 @@ public class AccountInfoEditorFragment extends Fragment implements OnVCardSaveLi ...@@ -321,6 +334,8 @@ 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() {
...@@ -419,6 +434,8 @@ public class AccountInfoEditorFragment extends Fragment implements OnVCardSaveLi ...@@ -419,6 +434,8 @@ public class AccountInfoEditorFragment extends Fragment implements OnVCardSaveLi
newAvatarImageUri = null; newAvatarImageUri = null;
removeAvatarFlag = true; removeAvatarFlag = true;
avatar.setImageDrawable(AvatarManager.getInstance().getDefaultAccountAvatar(account)); avatar.setImageDrawable(AvatarManager.getInstance().getDefaultAccountAvatar(account));
listener.enableSave();
avatarSize.setVisibility(View.INVISIBLE);
} }
@Override @Override
...@@ -448,6 +465,7 @@ public class AccountInfoEditorFragment extends Fragment implements OnVCardSaveLi ...@@ -448,6 +465,7 @@ public class AccountInfoEditorFragment extends Fragment implements OnVCardSaveLi
File file = new File(newAvatarImageUri.getPath()); File file = new File(newAvatarImageUri.getPath());
avatarSize.setText(file.length() / KB_SIZE_IN_BYTES + "KB"); avatarSize.setText(file.length() / KB_SIZE_IN_BYTES + "KB");
avatarSize.setVisibility(View.VISIBLE); avatarSize.setVisibility(View.VISIBLE);
listener.enableSave();
} else if (resultCode == Crop.RESULT_ERROR) { } else if (resultCode == Crop.RESULT_ERROR) {
avatarSize.setVisibility(View.INVISIBLE); avatarSize.setVisibility(View.INVISIBLE);
Toast.makeText(getActivity(), Crop.getError(result).getMessage(), Toast.LENGTH_SHORT).show(); Toast.makeText(getActivity(), Crop.getError(result).getMessage(), Toast.LENGTH_SHORT).show();
...@@ -574,6 +592,7 @@ public class AccountInfoEditorFragment extends Fragment implements OnVCardSaveLi ...@@ -574,6 +592,7 @@ public class AccountInfoEditorFragment extends Fragment implements OnVCardSaveLi
} }
disableProgressMode(); disableProgressMode();
listener.enableSave();
Toast.makeText(getActivity(), getString(R.string.account_user_info_save_fail), Toast.LENGTH_LONG).show(); Toast.makeText(getActivity(), getString(R.string.account_user_info_save_fail), Toast.LENGTH_LONG).show();
isSaveSuccess = false; isSaveSuccess = false;
} }
...@@ -630,4 +649,21 @@ public class AccountInfoEditorFragment extends Fragment implements OnVCardSaveLi ...@@ -630,4 +649,21 @@ public class AccountInfoEditorFragment extends Fragment implements OnVCardSaveLi
birthDateRemoveButton.setVisibility(View.VISIBLE); birthDateRemoveButton.setVisibility(View.VISIBLE);
} }
} }
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
if (!updateFromVCardFlag) {
listener.enableSave();
}
}
@Override
public void afterTextChanged(Editable s) {
}
} }
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