Search in sources :

Example 6 with TextButtonItem

use of com.abewy.klyph.items.TextButtonItem in project Klyph by jonathangerbaud.

the class KlyphFragment2 method startLoading.

protected void startLoading() {
    loading = true;
    if (isError == true && getAdapter().getCount() > 0) {
        GraphObject lastObject = getAdapter().getLastItem();
        if (lastObject instanceof TextButtonItem) {
            getAdapter().remove(lastObject);
        }
    }
    isError = false;
    if (!firstLoad) {
        if (!loadingObjectAsFirstItem)
            getAdapter().add(loadingObject);
        else
            getAdapter().insert(loadingObject, 0);
        getAdapter().notifyDataSetChanged();
    }
}
Also used : TextButtonItem(com.abewy.klyph.items.TextButtonItem) GraphObject(com.abewy.android.apps.klyph.core.graph.GraphObject)

Example 7 with TextButtonItem

use of com.abewy.klyph.items.TextButtonItem in project Klyph by jonathangerbaud.

the class KlyphFragment2 method onRequestError.

private void onRequestError(RequestError error) {
    Log.d(TAG, "error " + error.toString());
    // Crashlytics report on request error
    try {
        throw new Exception("Class :�" + this.getClass().getName() + "\n, Request " + requestType + ", Id " + elementId + ", Offset " + offset + "\n, Error " + error.getMessage());
    } catch (Exception e) {
        Crashlytics.logException(e);
    }
    if (getView() == null || getGridView() == null)
        return;
    isError = true;
    loading = false;
    int errorText = this.errorText;
    if (!ConnectionState.getInstance(getActivity()).isOnline()) {
        errorText = R.string.request_connexion_error;
    }
    // Fragment can be destroyed but receive the error
    if (getAdapter() != null) {
        if (getAdapter().isEmpty()) {
            setEmptyText(errorText);
            populate(new ArrayList<GraphObject>());
        } else {
            TextButtonItem errorItem = new TextButtonItem();
            errorItem.setText(getString(errorText));
            // TODO This is not a good coding practice !
            errorItem.setButtonListener(new View.OnClickListener() {

                @Override
                public void onClick(View v) {
                    retryRequestAfterError();
                }
            });
            getAdapter().add(errorItem);
            endLoading();
        }
    }
}
Also used : TextButtonItem(com.abewy.klyph.items.TextButtonItem) GraphObject(com.abewy.android.apps.klyph.core.graph.GraphObject) ListEmptyView(com.abewy.android.apps.klyph.view.ListEmptyView) View(android.view.View) AdapterView(android.widget.AdapterView) AbsListView(android.widget.AbsListView) KlyphGridView(com.abewy.android.apps.klyph.widget.KlyphGridView)

Example 8 with TextButtonItem

use of com.abewy.klyph.items.TextButtonItem in project Klyph by jonathangerbaud.

the class KlyphFragment2 method loadNewest.

protected void loadNewest() {
    newestLoading = true;
    if (getAdapter().getFirstItem() instanceof TextButtonItem) {
        getAdapter().removeFirst();
        getAdapter().notifyDataSetChanged();
    }
    String offset = null;
    /*
		 * if (KlyphPreferences.getNewsfeedGoToTop() == false && getAdapter().getCount() > 0 && getAdapter().getCount() > insertNewestToIndex)
		 * {
		 * GraphObject first = (GraphObject) getAdapter().getItem(insertNewestToIndex);
		 * offset = getNewestOffset(first);
		 * }
		 */
    AsyncRequest request = new AsyncRequest(requestNewestType, getElementId(), offset, new AsyncRequest.Callback() {

        public void onComplete(Response response) {
            Log.i("StreamListFragment", "onCompleted");
            onRequestNewestComplete(response);
        }
    });
    request.execute();
}
Also used : Response(com.abewy.android.apps.klyph.core.request.Response) AsyncRequest(com.abewy.android.apps.klyph.request.AsyncRequest) TextButtonItem(com.abewy.klyph.items.TextButtonItem)

Example 9 with TextButtonItem

use of com.abewy.klyph.items.TextButtonItem in project Klyph by jonathangerbaud.

the class KlyphFragment method loadNewest.

protected void loadNewest() {
    newestLoading = true;
    setPullToRefreshRefreshing(true);
    if (getAdapter().getFirstItem() instanceof TextButtonItem) {
        getAdapter().removeAt(0);
        getAdapter().notifyDataSetChanged();
    }
    String offset = null;
    AsyncRequest request = new AsyncRequest(requestNewestType, getElementId(), offset, new AsyncRequest.Callback() {

        public void onComplete(Response response) {
            onRequestNewestComplete(response);
        }
    });
    request.execute();
}
Also used : Response(com.abewy.android.apps.klyph.core.request.Response) AsyncRequest(com.abewy.android.apps.klyph.request.AsyncRequest) TextButtonItem(com.abewy.klyph.items.TextButtonItem)

Example 10 with TextButtonItem

use of com.abewy.klyph.items.TextButtonItem in project Klyph by jonathangerbaud.

the class KlyphFragment method startLoading.

protected void startLoading() {
    loading = true;
    if (isError == true && getAdapter().getCount() > 0) {
        GraphObject lastObject = getAdapter().getLastItem();
        if (lastObject instanceof TextButtonItem) {
            getAdapter().remove(lastObject);
        }
    }
    isError = false;
    if (!firstLoad) {
        if (!loadingObjectAsFirstItem)
            getAdapter().add(loadingObject);
        else
            getAdapter().insert(loadingObject, 0);
        getAdapter().notifyDataSetChanged();
    }
}
Also used : TextButtonItem(com.abewy.klyph.items.TextButtonItem) GraphObject(com.abewy.android.apps.klyph.core.graph.GraphObject)

Aggregations

TextButtonItem (com.abewy.klyph.items.TextButtonItem)11 View (android.view.View)5 AbsListView (android.widget.AbsListView)5 GraphObject (com.abewy.android.apps.klyph.core.graph.GraphObject)5 ListEmptyView (com.abewy.android.apps.klyph.view.ListEmptyView)5 AdapterView (android.widget.AdapterView)2 ListView (android.widget.ListView)2 Response (com.abewy.android.apps.klyph.core.request.Response)2 AsyncRequest (com.abewy.android.apps.klyph.request.AsyncRequest)2 KlyphGridView (com.abewy.android.apps.klyph.widget.KlyphGridView)2 KlyphListView (com.abewy.android.apps.klyph.widget.KlyphListView)2 TextButtonItemHolder (com.abewy.android.apps.klyph.adapter.holder.TextButtonItemHolder)1