package com.wakatime.android;

import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.os.Bundle;
import android.support.v7.app.ActionBar;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import com.marcoscg.easylicensesdialog.EasyLicensesDialog;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class AboutActivity extends AppCompatActivity {

    @BindView(R.id.text_view_version)
    TextView mTextViewVersion;

    @BindView(R.id.btn_license)
    Button mBtnLicense;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_about);
        ButterKnife.bind(this);

        ActionBar actionBar = getSupportActionBar();
        if (actionBar != null) {
            actionBar.setDisplayHomeAsUpEnabled(true);
        }

        setVersion();
    }

    private void setVersion() {
        try {
            PackageInfo info = getPackageManager().getPackageInfo(getPackageName(), 0);
            mTextViewVersion.setText(getString(R.string.version, info.versionName));
        } catch (PackageManager.NameNotFoundException e) {
            mTextViewVersion.setText(R.string.unknown_version);
        }
    }

    @Override
    public void onBackPressed() {
        super.onBackPressed();
        finish(); // remove from backstack and go back to dashboard below it
    }

    @OnClick(R.id.btn_license)
    void openLicenseDialog(View button) {
        EasyLicensesDialog easyLicensesDialog = new EasyLicensesDialog(this);
        easyLicensesDialog.setTitle(getString(R.string.licenses));
        easyLicensesDialog.setCancelable(true);
        easyLicensesDialog.show();
    }
}

@@ -641,16 +641,67 @@
 License;
+%0A    private EasyLicensesDialog easyLicensesDialog;
 %0A%0A    @O
@@ -1039,24 +1039,83 @@
 %0A        %7D%0A%0A
+        easyLicensesDialog = new EasyLicensesDialog(this);%0A
         setV
@@ -1663,74 +1663,75 @@
   @O
-nClick(R.id.btn_license)%0A    void openLicenseDialog(View button) %7B
+verride%0A    protected void onDestroy() %7B%0A        super.onDestroy();
 %0A   
@@ -1735,17 +1735,21 @@
         
-E
+if (e
 asyLicen
@@ -1762,58 +1762,182 @@
 log 
-easyLicensesDialog = new Easy
+!= null) %7B%0A            easyLicensesDialog = null; // remove reference since it leaks%0A        %7D%0A    %7D%0A%0A    @OnClick(R.id.btn_license)%0A    void open
 License
-s
 Dialog(
-this);
+View button) %7B
 %0A   

Fix leak from easy license instance