1 package com.moiseum.wolnelektury.view;
3 import android.os.Bundle;
4 import android.support.v4.app.Fragment;
5 import android.view.View;
6 import android.webkit.WebSettings;
7 import android.webkit.WebView;
8 import android.webkit.WebViewClient;
9 import android.widget.Button;
10 import android.widget.TextView;
12 import com.moiseum.wolnelektury.R;
13 import com.moiseum.wolnelektury.base.AbstractFragment;
15 import butterknife.BindView;
21 public class WebViewFragment extends AbstractFragment {
23 private static final String PARAM_URL = "PARAM_URL";
25 @BindView(R.id.wvAbout)
27 @BindView(R.id.btnBack)
29 @BindView(R.id.btnRefresh)
31 @BindView(R.id.btnNext)
33 @BindView(R.id.tvPageError)
36 private boolean loadFailed;
38 public static Fragment newInstance(String url) {
39 WebViewFragment fragment = new WebViewFragment();
40 Bundle args = new Bundle(1);
41 args.putString(PARAM_URL, url);
42 fragment.setArguments(args);
47 public int getLayoutResourceId() {
48 return R.layout.fragment_web_view;
52 public void prepareView(View view, Bundle savedInstanceState) {
56 private void initWebView() {
57 wvPage.getSettings().setCacheMode(WebSettings.LOAD_CACHE_ELSE_NETWORK);
58 wvPage.getSettings().setJavaScriptEnabled(true);
59 wvPage.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);
60 wvPage.setWebViewClient(new WebViewClient() {
63 public boolean shouldOverrideUrlLoading(WebView view, String url) {
69 public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
70 if (tvPageError == null) {
74 tvPageError.setVisibility(View.VISIBLE);
78 public void onPageFinished(WebView view, String url) {
79 super.onPageFinished(view, url);
80 if (tvPageError == null) {
84 tvPageError.setVisibility(View.GONE);
86 btnBack.setEnabled(wvPage.canGoBack());
87 btnNext.setEnabled(wvPage.canGoForward());
90 String url = getArguments().getString(PARAM_URL);
93 btnRefresh.setOnClickListener(new View.OnClickListener() {
95 public void onClick(View v) {
101 btnBack.setOnClickListener(new View.OnClickListener() {
103 public void onClick(View v) {
108 btnNext.setOnClickListener(new View.OnClickListener() {
110 public void onClick(View v) {