package com.uservoice.uservoicesdk.activity;

import android.annotation.SuppressLint;
import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.Toast;

import com.uservoice.uservoicesdk.R;
import com.uservoice.uservoicesdk.Session;
import com.uservoice.uservoicesdk.babayaga.Babayaga;
import com.uservoice.uservoicesdk.dialog.UnhelpfulDialogFragment;
import com.uservoice.uservoicesdk.model.Article;
import com.uservoice.uservoicesdk.ui.Utils;

public class ArticleActivity extends SearchActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.uv_article_layout);
        final Article article = getIntent().getParcelableExtra("article");
        setTitle(article.getTitle());
        WebView webView = (WebView) findViewById(R.id.uv_webview);
        Utils.displayArticle(webView, article, this);
        findViewById(R.id.uv_container).setBackgroundColor(Utils.isDarkTheme(this) ? Color.BLACK : Color.WHITE);
        webView.setWebViewClient(new WebViewClient() {
            @Override
            public void onPageFinished(WebView view, String url) {
                super.onPageFinished(view, url);
                findViewById(R.id.uv_helpful_section).setVisibility(View.VISIBLE);
            }
        });
        findViewById(R.id.uv_helpful_button).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Babayaga.track(Babayaga.Event.VOTE_ARTICLE, article.getId());
                Toast.makeText(ArticleActivity.this, R.string.uv_thanks, Toast.LENGTH_SHORT).show();
            }
        });
        findViewById(R.id.uv_unhelpful_button).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                UnhelpfulDialogFragment dialog = new UnhelpfulDialogFragment();
                dialog.show(getSupportFragmentManager(), "UnhelpfulDialogFragment");
            }
        });

        Babayaga.track(Babayaga.Event.VIEW_ARTICLE, article.getId());
    }

    @Override
    @SuppressLint("NewApi")
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.uv_portal, menu);
        setupScopedSearch(menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        if (item.getItemId() == R.id.uv_action_contact) {
            startActivity(new Intent(this, ContactActivity.class));
            return true;
        }
        return super.onOptionsItemSelected(item);
    }

    @Override
    public void finish() {
        // This is what you have to do to make it stop the flash player
        WebView webview = (WebView) findViewById(R.id.uv_webview);
        webview.loadData("", "text/html", "utf-8");
        super.finish();
    }
}

@@ -163,24 +163,49 @@
 .os.Bundle;%0A
+import android.util.Log;%0A
 import andro
@@ -218,16 +218,16 @@
 w.Menu;%0A
-
 import a
@@ -270,24 +270,67 @@
 .view.View;%0A
+import android.webkit.JavascriptInterface;%0A
 import andro
@@ -381,24 +381,92 @@
 ViewClient;%0A
+import android.widget.LinearLayout;%0Aimport android.widget.ListView;%0A
 import andro
@@ -831,16 +831,46 @@
 vity %7B%0A%0A
+    private WebView webView;%0A%0A
     @Ove
@@ -1150,24 +1150,16 @@
         
-WebView 
 webView 
@@ -1193,32 +1193,107 @@
 id.uv_webview);%0A
+        final View helpfulSection = findViewById(R.id.uv_helpful_section);%0A
         Utils.di
@@ -1656,45 +1656,22 @@
     
-findViewById(R.id.uv_
 helpful
-_s
+S
 ection
-)
 .set
@@ -2504,32 +2504,271 @@
 etId());%0A    %7D%0A%0A
+    @Override%0A    public ListView getListView() %7B%0A        // This is called by setupScopedSearch(menu) to make sure the list is added,%0A        // but we don't want a list. Should probably refactor this somehow.%0A        return null;%0A    %7D%0A%0A
     @Override%0A  
@@ -3380,79 +3380,12 @@
     
-WebView webview = (WebView) findViewById(R.id.uv_webview);%0A        webv
+webV
 iew.

Fix bug that prevented browsing articles