Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How works updateOnRelationshipChanges #5

Open
samy-baili opened this issue Mar 2, 2016 · 0 comments
Open

How works updateOnRelationshipChanges #5

samy-baili opened this issue Mar 2, 2016 · 0 comments

Comments

@samy-baili
Copy link

Hi,

Firstly thank your awesome work, you save me a lot of time :)
EDIT: is called when I update a Column of my Model, despite updateOnRelationshipChanges = true, But after a long delay.
I launch LoaderManager.LoaderCallbacks from several fragment inside a view pager. This why the process taking so much time ?

My model:

@Table(name = "Schedule", id = BaseColumns._ID)
public class Schedule extends Model implements Parcelable {

    private final static String ID = "id";
    private final static String NAME = "name";
    private final static String DESCRIPTION = "description";
    public final static String BEGINS_AT = "begins_at";
    private final static String ENDS_AT = "ends_at";
    private final static String PLACE = "place";
    private final static String LATITUDE = "latitude";
    private final static String LONGITUDE = "longitude";
    private final static String URL = "url";
    private final static String HASHTAG = "hashtag";
    private final static String MAP_URL = "map_url";
    private final static String EVENT_TYPE = "event_type";
    public final static String USER_STATUS = "user_status";

    @SerializedName(ID)
    @Column(name = ID, unique = true, onUniqueConflict = Column.ConflictAction.REPLACE)
    public long id;
    @SerializedName(NAME)
    @Column(name = NAME)
    public String name;
    @SerializedName(DESCRIPTION)
    @Column(name = DESCRIPTION)
    public String description;
    @SerializedName(PLACE)
    @Column(name = PLACE)
    public String place;
    @SerializedName(URL)
    @Column(name = URL)
    public String url;
    @SerializedName(HASHTAG)
    @Column(name = HASHTAG)
    public String hashtag;
    @SerializedName(MAP_URL)
    @Column(name = MAP_URL)
    public String mapURL;
    @SerializedName(EVENT_TYPE)
    @Column(name = EVENT_TYPE)
    public String eventType;
    @SerializedName(USER_STATUS)
    @Column(name = USER_STATUS)
    public String userStatus;

    public Schedule() {
        super();
    }

    public Schedule(JSONObject json) {
        super();
        this.id = json.optLong(ID, -1);
        this.name = json.optString(NAME);
        this.description = json.optString(DESCRIPTION);
        this.place = json.optString(PLACE);
        this.url = json.optString(URL);
        this.hashtag = json.optString(HASHTAG);
        this.mapURL = json.optString(MAP_URL);
        this.eventType = json.optString(EVENT_TYPE);
        this.userStatus = json.optString(USER_STATUS);

    public Schedule(final Parcel in) {
        super();
        this.id = in.readLong();
        this.name = in.readString();
        this.description = in.readString();
        this.place = in.readString();
        this.url = in.readString();
        this.hashtag = in.readString();
        this.mapURL = in.readString();
        this.eventType = in.readString();
        this.userStatus = in.readString();
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeLong(id);
        dest.writeString(name);
        dest.writeString(description);
        dest.writeString(place);
        dest.writeString(url);
        dest.writeString(hashtag);
        dest.writeString(mapURL);
        dest.writeString(eventType);
        dest.writeString(userStatus);
    }

    @Override
    public int describeContents() {
        return 0;
    }

    public static final Creator<Schedule> CREATOR = new Creator<Schedule>() {
        public Schedule createFromParcel(final Parcel in) {
            return new Schedule(in);
        }

        public Schedule[] newArray(final int size) {
            return new Schedule[size];
        }
    };

LoaderCallback:

public class PlanningManager implements LoaderManager.LoaderCallbacks<List<Schedule>> {

    public final static String SORT_DAY = "SORT_DAY";
    public final static String SORT_HOUR = "SORT_HOUR";
    public final static String SORT_PLACE = "SORT_PLACE";
    public final static String SORT_CATEGORY = "SORT_CATEGORY";
    public final static String SORT_ATTENDING = "SORT_ATTENDING";

    private Context mContext;
    private String mCurrentSort;
    private PlanningCallback mPlanningCallback;

    private boolean isFromPanel;

    public PlanningManager(Context context) {
        this.mContext = context;
        this.mCurrentSort = SORT_DAY;
        this.isFromPanel = false;
    }

    public void launchCursorRequest(Bundle bundle, int loaderID) {
        if (mContext instanceof  SwapcardActivityWithoutAnimation)
            ((SwapcardActivityWithoutAnimation)mContext).getSupportLoaderManager().initLoader(loaderID, bundle, this);
    }

    @Override
    public void onLoaderReset(Loader<List<Schedule>> loader) {

    }

    @Override
    public Loader<List<Schedule>> onCreateLoader(int id, Bundle args) {
        Log.d("OnCreateLoader", "-------------- TEST -------------- ");
        From from = !isFromPanel ? getFromPager() : getFromPanel(args);
        if (from != null) {
            Log.d("OnCreateLoader", "-------------- FROM == [ " + from.toSql() + " ] -------------- ");
            return new ModelLoader<>(mContext, Schedule.class, from, true);
        }
        return null;
    }

    @Override
    public void onLoadFinished(Loader<List<Schedule>> loader, List<Schedule> data) {
        Log.d("OnLoadFinished", "-------------- Size == [ " + data.size() + " ] -------------- ");
        for (int i = 0; i < data.size(); i++) {
            Log.d("OnLoadFinished", "-------------- Size == [ " + DateUtils.changeFormatDate(data.get(i).beginsAT, "dd MMM yyyy") + " ] -------------- ");
        }
        if (mPlanningCallback != null)
            mPlanningCallback.onQueryFinished(data);
    }

    public static Bundle getQueryParams() {
        Bundle bundle = new Bundle();

        return bundle;
    }

    public void setPlanningCallback(PlanningCallback planningCallback) {
        this.mPlanningCallback = planningCallback;
    }

    public interface PlanningCallback {
        void onQueryFinished(List<Schedule> scheduleList);
    }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant