Android Open Source - Joetz-Android-V2 Person Validator Binding






From Project

Back to project page Joetz-Android-V2.

License

The source code is released under:

GNU General Public License

If you think the Android project Joetz-Android-V2 listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.example.jens.myapplication.domain.binding;
//from w ww  .  j  a  va2 s .c om
import android.widget.EditText;
import com.example.jens.myapplication.domain.Person;
import com.example.jens.myapplication.domain.converter.MyStringParser;
import com.example.jens.myapplication.domain.validator.PersonValidator;
import com.example.jens.myapplication.sam.JoetzApplication;
import com.example.jens.myapplication.util.MyMonths;

import org.joda.time.DateTime;

import java.util.List;

/**
 * Created by Sam on 29/10/2014.
 */
public class PersonValidatorBinding extends ValidatorBinding<PersonValidator> {
    public static final int FIELD_EMAIL = 0;
    public static final int FIELD_FIRST_NAME = 1;
    public static final int FIELD_LAST_NAME = 2;
    public static final int FIELD_DATE_OF_BIRTH = 3;
    public static final int FIELD_STREET = 4;
    public static final int FIELD_POSTAL_CODE = 5;
    public static final int FIELD_CITY = 6;
    public static final int FIELD_PHONE = 7;
    public static final int FIELD_RIJKSREGISTERNUMMER = 8;
    public static final int FIELD_BOND_AANSLUITINGSNUMMER = 9;
    public static final int FIELD_BOND_CODE_GERECHTIGDE = 10;
    public static final int FIELD_HOUSE_NUMBER = 11;
    public static final int FIELD_BUS = 12;

    public PersonValidatorBinding(PersonValidator validator, EditText view, int field, String itemName) {
        super(validator, view, field, itemName);
    }

    public PersonValidatorBinding(PersonValidator validator, EditText view, int field, String itemName, boolean required){
        super(validator, view, field, itemName, required);
    }

    @Override
    protected void setValue(String value) {
        Person p = validator.getObj();
        switch(field){
            case FIELD_EMAIL: p.setEmail(value); break;
            case FIELD_FIRST_NAME: p.setFirstName(value); break;
            case FIELD_LAST_NAME: p.setLastName(value); break;
            //Possibly add parser for dob in the future. for now dont set it this way.
            case FIELD_STREET: p.setStreet(value); break;
            case FIELD_HOUSE_NUMBER: p.setHouseNumber(MyStringParser.parseInt(value)); break;
            case FIELD_BUS: p.setBus(value); break;
            case FIELD_POSTAL_CODE: p.setPostalCode(MyStringParser.parseInt(value)); break;
            case FIELD_CITY: p.setCity(value); break;
            case FIELD_PHONE: p.setPhone(value); break;
            case FIELD_RIJKSREGISTERNUMMER: p.setRijksRegisterNummer(value); break;
            case FIELD_BOND_AANSLUITINGSNUMMER: p.setBondAansluitingsNr(value); break;
            case FIELD_BOND_CODE_GERECHTIGDE: p.setBondCodeGerechtigde(value); break;
        }
    }

    @Override
    public void fillValue() {
        Person p = validator.getObj();
        switch(field){
            case FIELD_EMAIL: view.setText(p.getEmail()); break;
            case FIELD_FIRST_NAME: view.setText(p.getFirstName()); break;
            case FIELD_LAST_NAME: view.setText(p.getLastName()); break;
            case FIELD_DATE_OF_BIRTH:
                DateTime dob = p.getDateOfBirth();
                if(dob == null){ return; }
                String monthString = JoetzApplication.getContext().getString(MyMonths.getMonthShortResId(dob.getMonthOfYear()));
                view.setText(dob.getDayOfMonth() + " " + monthString + " " + dob.getYear()); break;
            case FIELD_STREET: view.setText(p.getStreet()); break;
            case FIELD_HOUSE_NUMBER: view.setText(
                    p.getHouseNumber() < 1 ? "" : String.valueOf(p.getHouseNumber())); break;
            case FIELD_BUS: view.setText(p.getBus()); break;
            case FIELD_POSTAL_CODE: view.setText(
                    p.getPostalCode() < 1 ? "" : String.valueOf(p.getPostalCode())); break;
            case FIELD_CITY: view.setText(p.getCity()); break;
            case FIELD_PHONE: view.setText(p.getPhone()); break;
            case FIELD_RIJKSREGISTERNUMMER: view.setText(p.getRijksRegisterNummer()); break;
            case FIELD_BOND_AANSLUITINGSNUMMER: view.setText(p.getBondAansluitingsNr()); break;
            case FIELD_BOND_CODE_GERECHTIGDE: view.setText(p.getBondCodeGerechtigde()); break;
        }
    }

    @Override
    protected ValidationTask createTask(int field) {
        switch(field){
            case FIELD_EMAIL: return new ValidationTask() {
                @Override
                public List<Integer> validate(List<Integer> errors) {
                    return validator.validateEmail(errors);
                }
            };
            case FIELD_FIRST_NAME: return new ValidationTask() {
                @Override
                public List<Integer> validate(List<Integer> errors) {
                    return validator.validateFirstName(errors);
                }
            };
            case FIELD_LAST_NAME: return new ValidationTask() {
                @Override
                public List<Integer> validate(List<Integer> errors) {
                    return validator.validateLastName(errors);
                }
            };
            case FIELD_DATE_OF_BIRTH: return new ValidationTask() {
                @Override
                public List<Integer> validate(List<Integer> errors) {
                    return validator.validateDateOfBirth(errors);
                }
            };
            case FIELD_STREET: return new ValidationTask() {
                @Override
                public List<Integer> validate(List<Integer> errors) {
                    return validator.validateStreet(errors);
                }
            };
            case FIELD_HOUSE_NUMBER: return new ValidationTask() {
                @Override
                public List<Integer> validate(List<Integer> errors) {
                    return validator.validateHouseNumber(errors);
                }
            };
            case FIELD_BUS: return new ValidationTask() {
                @Override
                public List<Integer> validate(List<Integer> errors) {
                    return validator.validateBus(errors);
                }
            };
            case FIELD_POSTAL_CODE: return new ValidationTask() {
                @Override
                public List<Integer> validate(List<Integer> errors) {
                    return validator.validatePostalCode(errors);
                }
            };
            case FIELD_CITY: return new ValidationTask() {
                @Override
                public List<Integer> validate(List<Integer> errors) {
                    return validator.validateCity(errors);
                }
            };
            case FIELD_PHONE: return new ValidationTask() {
                @Override
                public List<Integer> validate(List<Integer> errors) {
                    return validator.validatePhone(errors);
                }
            };
            case FIELD_RIJKSREGISTERNUMMER: return new ValidationTask() {
                @Override
                public List<Integer> validate(List<Integer> errors) {
                    return validator.validateRijksRegisterNummer(errors);
                }
            };
            case FIELD_BOND_AANSLUITINGSNUMMER: return new ValidationTask() {
                @Override
                public List<Integer> validate(List<Integer> errors) {
                    return validator.validateBondAansluitingsNummer(errors);
                }
            };
            case FIELD_BOND_CODE_GERECHTIGDE: return new ValidationTask() {
                @Override
                public List<Integer> validate(List<Integer> errors) {
                    return validator.validateBondCodeGerechtigde(errors);
                }
            };
        }
        return null;
    }
}




Java Source Code List

com.example.jens.myapplication.ApplicationTest.java
com.example.jens.myapplication.account.FragmentAccount.java
com.example.jens.myapplication.account.LoginDialogActivity.java
com.example.jens.myapplication.account.LoginFragment.java
com.example.jens.myapplication.account.PersonsFragment.java
com.example.jens.myapplication.account.ProfileFragment.java
com.example.jens.myapplication.account.RegisterDialogActivity.java
com.example.jens.myapplication.account.RegisterFragment.java
com.example.jens.myapplication.account.TabsPagerAdapter.java
com.example.jens.myapplication.activities.ActivityDetailActivity.java
com.example.jens.myapplication.activities.ActivityDetailFragment.java
com.example.jens.myapplication.activities.FragmentListActivities.java
com.example.jens.myapplication.activities.JoetzActivitiesAdapter.java
com.example.jens.myapplication.activities.JoetzActivity.java
com.example.jens.myapplication.activities.StartActivity.java
com.example.jens.myapplication.apimanager.ApiConnection.java
com.example.jens.myapplication.apimanager.CancellableTask.java
com.example.jens.myapplication.apimanager.JSONParsingTask.java
com.example.jens.myapplication.apimanager.PostRequestTask.java
com.example.jens.myapplication.apimanager.RequestParams.java
com.example.jens.myapplication.apimanager.SimpleRequestTask.java
com.example.jens.myapplication.apimanager.filter.PersonFilter.java
com.example.jens.myapplication.apimanager.manager.ActivityManager.java
com.example.jens.myapplication.apimanager.manager.AuthToken.java
com.example.jens.myapplication.apimanager.manager.BookingManager.java
com.example.jens.myapplication.apimanager.manager.CampManager.java
com.example.jens.myapplication.apimanager.manager.ImageManager.java
com.example.jens.myapplication.apimanager.manager.LoginManager.java
com.example.jens.myapplication.apimanager.manager.ProfileManager.java
com.example.jens.myapplication.apimanager.manager.RegisterManager.java
com.example.jens.myapplication.booking.AddPersonActivity.java
com.example.jens.myapplication.booking.BookingActivity.java
com.example.jens.myapplication.booking.BookingBondFragment.java
com.example.jens.myapplication.booking.BookingContactFragment.java
com.example.jens.myapplication.booking.BookingExtraFragment.java
com.example.jens.myapplication.booking.BookingParticipantsFragment.java
com.example.jens.myapplication.bookingHistory.BookingHistoryDetailActivity.java
com.example.jens.myapplication.bookingHistory.BookingHistoryDetailFragment.java
com.example.jens.myapplication.bookingHistory.BookingHistoryOverviewFragment.java
com.example.jens.myapplication.bookingHistory.BookingsAdapter.java
com.example.jens.myapplication.calendar.FragmentCalendar.java
com.example.jens.myapplication.calendar.KalenderAdapter.java
com.example.jens.myapplication.calendar.KalenderItem.java
com.example.jens.myapplication.camps.CampAdapter.java
com.example.jens.myapplication.camps.CampDetailActivity.java
com.example.jens.myapplication.camps.CampFilterActivity.java
com.example.jens.myapplication.camps.FilterFragment.java
com.example.jens.myapplication.camps.FragmentListCamps.java
com.example.jens.myapplication.camps.ImageActivity.java
com.example.jens.myapplication.camps.ImagePagerFragment.java
com.example.jens.myapplication.camps.InfoFragment.java
com.example.jens.myapplication.camps.PhotoFragment.java
com.example.jens.myapplication.camps.RecyclerItemClickListener.java
com.example.jens.myapplication.camps.SquareImageView.java
com.example.jens.myapplication.camps.TabsPagerAdapter.java
com.example.jens.myapplication.domain.BookingStatus.java
com.example.jens.myapplication.domain.Booking.java
com.example.jens.myapplication.domain.Camp.java
com.example.jens.myapplication.domain.PeriodCategory.java
com.example.jens.myapplication.domain.Person.java
com.example.jens.myapplication.domain.UserRole.java
com.example.jens.myapplication.domain.User.java
com.example.jens.myapplication.domain.binding.PersonValidatorBinding.java
com.example.jens.myapplication.domain.binding.UserValidatorBinding.java
com.example.jens.myapplication.domain.binding.ValidatorBinding.java
com.example.jens.myapplication.domain.converter.ErrorConverter.java
com.example.jens.myapplication.domain.converter.MyStringParser.java
com.example.jens.myapplication.domain.converter.UnixDateTimeConverter.java
com.example.jens.myapplication.domain.validator.PersonValidator.java
com.example.jens.myapplication.domain.validator.UserValidator.java
com.example.jens.myapplication.domain.validator.Validator.java
com.example.jens.myapplication.home.AanbevolenAdapter.java
com.example.jens.myapplication.home.HomeFragment.java
com.example.jens.myapplication.home.ImageSlideAdapter.java
com.example.jens.myapplication.home.Reclame.java
com.example.jens.myapplication.lib.RangeSeekBar.java
com.example.jens.myapplication.main.MainActivity.java
com.example.jens.myapplication.main.NavDrawerAdapter.java
com.example.jens.myapplication.main.NavDrawerItem.java
com.example.jens.myapplication.main.NavMenuItem.java
com.example.jens.myapplication.main.NavMenuSection.java
com.example.jens.myapplication.sam.JoetzApplication.java
com.example.jens.myapplication.sam.MyFragment.java
com.example.jens.myapplication.sam.MySaveableFragment.java
com.example.jens.myapplication.util.AESEncryption.java
com.example.jens.myapplication.util.ActivityUtils.java
com.example.jens.myapplication.util.BindingUtils.java
com.example.jens.myapplication.util.DateTimeStringConverter.java
com.example.jens.myapplication.util.JsonUtils.java
com.example.jens.myapplication.util.MyMonths.java
com.example.jens.myapplication.util.StringUtils.java
com.example.jens.myapplication.view.MyLinearLayout.java