Java tutorial
/** * 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 android.view.View; import android.view.View.OnClickListener; import com.liferay.alerts.R; import com.liferay.alerts.activity.MainActivity; import com.liferay.alerts.util.SettingsUtil; import com.liferay.alerts.util.ToastUtil; import com.liferay.mobile.android.service.Session; import com.liferay.mobile.android.task.callback.typed.JSONObjectAsyncTaskCallback; import com.liferay.mobile.android.v62.pushnotificationsentry.PushnotificationsentryService; import org.json.JSONObject; /** * @author Bruno Farache */ public class LikeCallback extends JSONObjectAsyncTaskCallback implements OnClickListener { public LikeCallback(Context context, long alertId) { _context = context.getApplicationContext(); _alertId = alertId; } @Override public void onClick(View view) { Session session = SettingsUtil.getSession(this); PushnotificationsentryService service = new PushnotificationsentryService(session); try { _like = !view.isSelected(); if (_like) { service.likePushNotificationsEntry(_alertId); } else { service.unlikePushNotificationsEntry(_alertId); } } catch (Exception e) { ToastUtil.show(_context, R.string.like_failure, true); } } @Override public void onFailure(Exception e) { ToastUtil.show(_context, R.string.like_failure, true); } @Override public void onSuccess(JSONObject result) { MainActivity.updateLiked(_context, (int) _alertId, _like); } private long _alertId; private Context _context; private boolean _like; }