<commit_before>package com.rehivetech.beeeon.gcm.notification;

import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.support.v4.app.NotificationCompat;
import android.util.Log;

import com.rehivetech.beeeon.R;

import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;

import java.io.IOException;

/**
 * Created by Martin on 22. 4. 2015.
 */
public class UriNotification extends VisibleNotification {

	public static final String TAG = UriNotification.class.getSimpleName();

	private String mUri;
	private String mMsg;

	private UriNotification(int msgid, long time, NotificationType type, boolean read, String message, String uri) {
		super(msgid, time, type, read);
		mMsg = message;
		mUri = uri;
	}

	protected static UriNotification getInstance(Integer msgId, Long time, NotificationType type, Bundle bundle) throws NullPointerException, IllegalArgumentException {
		try {
			String message = bundle.getString("msg");
			String uri = bundle.getString("url");

			if (message == null || uri == null) {
				Log.d(TAG, "Watdog: some compulsory value is missing.");
				return null;
			}

			return new UriNotification(msgId, time, type, false, message, uri);
		} catch (IllegalArgumentException | NullPointerException e) {
			return null;
		}
	}

	protected static VisibleNotification getInstance(Integer msgId, Long time, NotificationType type, boolean isRead, XmlPullParser parser) throws IOException, XmlPullParserException, NumberFormatException {
		String message = null;
		String uri = null;

		String text = null;
		int eventType = parser.getEventType();
		while (eventType != XmlPullParser.END_DOCUMENT) {
			if (eventType == XmlPullParser.END_TAG &&
					parser.getName().equals("notif")) {
				break;
			}
			String tagname = parser.getName();
			switch (eventType) {
				case XmlPullParser.START_TAG:
					// ignore it
					break;

				case XmlPullParser.TEXT:
					text = parser.getText();
					break;

				case XmlPullParser.END_TAG:
					if (tagname.equalsIgnoreCase("msg")) {
						message = text;
					} else if (tagname.equalsIgnoreCase("url")) {
						uri = text;
					}
					break;
				default:
					break;
			}
			eventType = parser.next();
		}

		if (message == null || uri == null) {
			Log.d(TAG, "Xml: Some compulsory value is missing.");
			return null;
		}

		return new UriNotification(msgId, time, type, isRead, message, uri);
	}

	@Override
	protected void onGcmHandle(Context context) {
		NotificationCompat.Builder builder = getBaseNotificationBuilder(context);

		// define notification action
		Intent resultIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(mUri));<commit_msg>Fix notification parameter for UriNotification<commit_after>package com.rehivetech.beeeon.gcm.notification;

import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.support.v4.app.NotificationCompat;
import android.util.Log;

import com.rehivetech.beeeon.R;

import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;

import java.io.IOException;

/**
 * Created by Martin on 22. 4. 2015.
 */
public class UriNotification extends VisibleNotification {

	public static final String TAG = UriNotification.class.getSimpleName();

	private String mUri;
	private String mMsg;

	private UriNotification(int msgid, long time, NotificationType type, boolean read, String message, String uri) {
		super(msgid, time, type, read);
		mMsg = message;
		mUri = uri;
	}

	protected static UriNotification getInstance(Integer msgId, Long time, NotificationType type, Bundle bundle) throws NullPointerException, IllegalArgumentException {
		try {
			String message = bundle.getString("msg");
			String uri = bundle.getString("uri");

			if (message == null || uri == null) {
				Log.d(TAG, "Watdog: some compulsory value is missing.");
				return null;
			}

			return new UriNotification(msgId, time, type, false, message, uri);
		} catch (IllegalArgumentException | NullPointerException e) {
			return null;
		}
	}

	protected static VisibleNotification getInstance(Integer msgId, Long time, NotificationType type, boolean isRead, XmlPullParser parser) throws IOException, XmlPullParserException, NumberFormatException {
		String message = null;
		String uri = null;

		String text = null;
		int eventType = parser.getEventType();
		while (eventType != XmlPullParser.END_DOCUMENT) {
			if (eventType == XmlPullParser.END_TAG &&
					parser.getName().equals("notif")) {
				break;
			}
			String tagname = parser.getName();
			switch (eventType) {
				case XmlPullParser.START_TAG:
					// ignore it
					break;

				case XmlPullParser.TEXT:
					text = parser.getText();
					break;

				case XmlPullParser.END_TAG:
					if (tagname.equalsIgnoreCase("msg")) {
						message = text;
					} else if (tagname.equalsIgnoreCase("uri")) {
						uri = text;
					}
					break;
				default:
					break;
			}
			eventType = parser.next();
		}

		if (message == null || uri == null) {
			Log.d(TAG, "Xml: Some compulsory value is missing.");
			return null;
		}

		return new UriNotification(msgId, time, type, isRead, message, uri);
	}

	@Override
	protected void onGcmHandle(Context context) {
		NotificationCompat.Builder builder = getBaseNotificationBuilder(context);

		// define notification action
		Intent resultIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(mUri));
{'fraction_non_alphanumeric': 0.10450189839088772, 'fraction_numerical': 0.0036159826432833123, 'mean_word_length': 4.061299176578225, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 4}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4944103', 'n_tokens_mistral': 1939, 'n_tokens_neox': 1595, 'n_words': 451}