sockeqwe / mosby

A Model-View-Presenter / Model-View-Intent library for modern Android apps
http://hannesdorfmann.com/mosby/
Apache License 2.0
5.49k stars 841 forks source link

Using ListLceViewState instead ArrayListLceViewState #154

Closed atetc closed 7 years ago

atetc commented 8 years ago

Due to https://sbforge.org/sonar/rules/show/squid:S1319 I start refactor classes and faced with ArrayListLceViewState

My suggestion is to introduce:

public class ListLceViewState<D extends List<? extends Parcelable>, V extends MvpLceView<D>>
        extends AbsParcelableLceViewState<D, V> {

    public static final Parcelable.Creator<ListLceViewState> CREATOR =
            new Parcelable.Creator<ListLceViewState>() {
                @Override public ListLceViewState createFromParcel(Parcel source) {
                    return new ListLceViewState(source);
                }

                @Override public ListLceViewState[] newArray(int size) {
                    return new ListLceViewState[size];
                }
            };

    public ListLceViewState() {
        // Do nothing
    }

    private ListLceViewState(Parcel source) {
        readFromParcel(source);
    }

    @Override public void writeToParcel(Parcel dest, int flags) {

        dest.writeList(loadedData);

        super.writeToParcel(dest, flags);
    }

    @Override protected void readFromParcel(Parcel source) {

        List list = new ArrayList<>();
        source.readList(list, getClassLoader());
        super.readFromParcel(source);
    }

    /**
     * The class loader used for deserializing the list of parcelable items
     */
    protected ClassLoader getClassLoader() {
        return getClass().getClassLoader();
    }
}
sockeqwe commented 8 years ago

Thanks for your suggestion, I will add this!

sockeqwe commented 7 years ago

Upcoming 3.0 version contains ParcelableListLceViewState