package org.dvbviewer.controller.ui.fragments;

import android.content.Intent;
import android.content.pm.PackageManager.NameNotFoundException;
import android.net.Uri;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.ImageButton;
import android.widget.TextView;

import org.dvbviewer.controller.R;

public class AboutFragment extends Fragment{
	
	private TextView	versionTextView;
	private ImageButton	payPalButton;

	@Override
	public void onActivityCreated(Bundle savedInstanceState) {
		super.onActivityCreated(savedInstanceState);
		String versionName = "";
		try {
			versionName = getActivity().getPackageManager().getPackageInfo(getActivity().getPackageName(), 0).versionName;
		} catch (NameNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		versionTextView.setText(versionName);
		payPalButton.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				getActivity().startActivity(new Intent(Intent.ACTION_VIEW,Uri.parse("https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=XBZT782XQV7AY")));

			}
		});
	}
	
	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
		View v = inflater.inflate(R.layout.fragment_about, container, false);
		payPalButton = (ImageButton) v.findViewById(R.id.paypalButton);
		versionTextView = (TextView) v.findViewById(R.id.versionTextView);
		return v;
	}

}

@@ -41,16 +41,45 @@
 ments;%0A%0A
+import android.app.Activity;%0A
 import a
@@ -215,16 +215,59 @@
 Bundle;%0A
+import android.support.annotation.NonNull;%0A
 import a
@@ -294,24 +294,49 @@
 p.Fragment;%0A
+import android.util.Log;%0A
 import andro
@@ -605,17 +605,84 @@
 Fragment
-%7B
+ %7B%0A%0A%09private final String TAG = AboutFragment.class.getSimpleName();
 %0A%09%0A%09priv
@@ -871,44 +871,101 @@
 ;%0A%09%09
-S
 tr
-ing versionName = %22%22
+y %7B%0A%09%09%09final Activity activity = getActivity()
 ;%0A%09%09
-try %7B%0A%09%09%09
+%09if(activity != null) %7B%0A%09%09%09%09final String 
 vers
@@ -974,29 +974,24 @@
 nName = 
-getA
+a
 ctivity
-()
 .getPack
@@ -1002,16 +1002,23 @@
 anager()
+%0A%09%09%09%09%09%09
 .getPack
@@ -1025,29 +1025,24 @@
 ageInfo(
-getA
+a
 ctivity
-()
 .getPack
@@ -1054,16 +1054,23 @@
 me(), 0)
+%0A%09%09%09%09%09%09
 .version
@@ -1081,149 +1081,142 @@
 ;%0A%09%09
-%7D catch (NameNotFoundException e) %7B%0A%09%09%09// TODO Auto-generated catch block%0A%09%09%09e.printStackTrace();%0A%09%09%7D%0A%09%09versionTextView.setText(
+%09%09versionTextView.setText(versionName);%0A%09%09%09%7D%0A%09%09%7D catch (NameNotFoundException e) %7B%0A%09%09%09Log.e(TAG, %22Error getting 
 version
-Name);
+ name%22, e);%0A%09%09%7D
 %0A%09%09p
@@ -1535,16 +1535,25 @@
 ateView(
+@NonNull 
 LayoutIn
@@ -1711,22 +1711,8 @@
 on =
- (ImageButton)
  v.f
@@ -1766,19 +1766,8 @@
 ew =
- (TextView)
  v.f

fix possible NPE