/*
 * Copyright (c) 2014, Apptentive, Inc. All Rights Reserved.
 * Please refer to the LICENSE file for the terms and conditions
 * under which redistribution and use of this file is permitted.
 */

package com.apptentive.android.sdk;

import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.view.View;
import android.widget.TextView;
import com.apptentive.android.sdk.module.ActivityContent;
import com.apptentive.android.sdk.util.Constants;

/**
 * @author Sky Kelsey
 */
public class AboutModule {

	private static AboutModule instance = null;

	public static AboutModule getInstance() {
		if (instance == null) {
			instance = new AboutModule();
		}
		return instance;
	}

	private AboutModule() {
	}

	/**
	 * Show About
	 *
	 * @param activity The launching activity
	 * @param showBrandingBand  If true, show branding band on About page
	 */
	public void show(Activity activity, boolean showBrandingBand) {
		Intent intent = new Intent();
		intent.setClass(activity, ViewActivity.class);
		intent.putExtra(ActivityContent.KEY, ActivityContent.Type.ABOUT.toString());
		intent.putExtra(ActivityContent.EXTRA, showBrandingBand);
		activity.startActivity(intent);
	}

	void doShow(final Activity activity, boolean showBrandingBand) {
		activity.setContentView(R.layout.apptentive_about);
		if (!showBrandingBand) {
			activity.findViewById(R.id.apptentive_branding_view).setVisibility(View.GONE);
		} else {
			activity.findViewById(R.id.apptentive_branding_view).setClickable(false); // Don't let the about view launch itself.
		}

		View close = activity.findViewById(R.id.close_about);
		close.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View view) {
				activity.finish();
			}
		});

		TextView information = (TextView) activity.findViewById(R.id.about_description_link);
		information.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View view) {
				Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.apptentive.com"));
				activity.startActivity(browserIntent);
			}
		});

		TextView privacy = (TextView) activity.findViewById(R.id.privacy_link);
		privacy.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View view) {
				Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.apptentive.com/privacy"));
				activity.startActivity(browserIntent);
			}
		});

		TextView version = (TextView) activity.findViewById(R.id.version);
		String versionString = activity.getResources().getString(R.string.apptentive_version);
		version.setText(String.format(versionString, Constants.APPTENTIVE_SDK_VERSION));
	}

	boolean onBackPressed(Activity activity) {
		return true;
	}

}

@@ -20,9 +20,9 @@
  201
-4
+5
 , Ap
@@ -366,24 +366,79 @@
 et.TextView;
+%0A%0Aimport com.apptentive.android.sdk.model.ExtendedData;
 %0Aimport com.
@@ -480,24 +480,94 @@
 ityContent;%0A
+import com.apptentive.android.sdk.module.engagement.EngagementModule;%0A
 import com.a
@@ -663,16 +663,250 @@
 dule %7B%0A%0A
+%09private static final String INTERACTION_NAME = %22About%22;%0A%0A%09private static final String EVENT_NAME_LAUNCH = %22launch%22;%0A%09private static final String EVENT_NAME_CLOSE = %22close%22;%0A%09private static final String EVENT_NAME_CANCEL = %22cancel%22;%0A%0A
 %09private
@@ -1309,16 +1309,149 @@
 Band) %7B%0A
+%09%09EngagementModule.engage(activity, %22com.apptentive%22, INTERACTION_NAME, null, EVENT_NAME_LAUNCH, null, null, (ExtendedData%5B%5D) null);%0A
 %09%09Intent
@@ -2222,24 +2222,158 @@
 iew view) %7B%0A
+%09%09%09%09EngagementModule.engage(activity, %22com.apptentive%22, INTERACTION_NAME, null, EVENT_NAME_CLOSE, null, null, (ExtendedData%5B%5D) null);%0A
 %09%09%09%09activity
@@ -3380,16 +3380,149 @@
 vity) %7B%0A
+%09%09EngagementModule.engage(activity, %22com.apptentive%22, INTERACTION_NAME, null, EVENT_NAME_CANCEL, null, null, (ExtendedData%5B%5D) null);%0A
 %09%09return
@@ -3528,14 +3528,13 @@
 n true;%0A
+
 %09%7D%0A
-%0A
 %7D%0A

Add events to About module. AND-203