com.liferay.alerts.callback.AddCommentCallback.java Source code

Java tutorial

Introduction

Here is the source code for com.liferay.alerts.callback.AddCommentCallback.java

Source

/**
 * Copyright (c) 2000-present Liferay, Inc. All rights reserved.
 *
 * This library is free software; you can redistribute it and/or modify it under
 * the terms of the GNU Lesser General Public License as published by the Free
 * Software Foundation; either version 2.1 of the License, or (at your option)
 * any later version.
 *
 * This library is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
 * details.
 */

package com.liferay.alerts.callback;

import android.content.Context;

import com.liferay.alerts.activity.CommentsActivity;
import com.liferay.alerts.model.Alert;
import com.liferay.alerts.model.User;
import com.liferay.alerts.util.ToastUtil;
import com.liferay.mobile.android.task.callback.typed.JSONObjectAsyncTaskCallback;

import org.json.JSONObject;

/**
 * @author Bruno Farache
 */
public class AddCommentCallback extends JSONObjectAsyncTaskCallback {

    public AddCommentCallback(Context context) {
        _context = context.getApplicationContext();
    }

    @Override
    public void onFailure(Exception exception) {
        ToastUtil.show(_context, exception.getMessage());
    }

    @Override
    public void onSuccess(JSONObject jsonObject) {
        try {
            long id = jsonObject.getLong(Alert.PUSH_NOTIFICATIONS_ENTRY_ID);

            JSONObject userJSONObject = jsonObject.getJSONObject(Alert.USER);

            User user = new User(userJSONObject);

            JSONObject payload = new JSONObject(jsonObject.getString(Alert.PAYLOAD));

            CommentsActivity.addComment(_context, new Alert(id, user, payload));
        } catch (Exception e) {
            ToastUtil.show(_context, e.getMessage());
        }
    }

    private Context _context;

}