content: /*
   * Copyright 2017 Akhil Kedia
   * This file is part of AllTrans.
   *
   * AllTrans is free software: you can redistribute it and/or modify
   * it under the terms of the GNU General Public License as published by
   * the Free Software Foundation, either version 3 of the License, or
   * (at your option) any later version.
   *
   * AllTrans is distributed in the hope that it will be useful,
   * but WITHOUT ANY WARRANTY; without even the implied warranty of
   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
   * GNU General Public License for more details.
   *
   * You should have received a copy of the GNU General Public License
   * along with AllTrans. If not, see <http://www.gnu.org/licenses/>.
   *
   */
  
  package akhil.alltrans;
  
  
  import android.annotation.SuppressLint;
  import android.app.ProgressDialog;
  import android.os.Bundle;
  import android.view.LayoutInflater;
  import android.view.View;
  import android.view.ViewGroup;
  import android.webkit.WebView;
  import android.webkit.WebViewClient;
  
  import java.util.Arrays;
  import java.util.Locale;
  
  import androidx.annotation.NonNull;
  import androidx.fragment.app.Fragment;
  
  
  /**
   * A simple {@link Fragment} subclass.
   */
  public class InstructionsFragment extends Fragment {
  
      @SuppressLint("SetJavaScriptEnabled")
      @Override
      public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container,
                               Bundle savedInstanceState) {
  
          //noinspection ConstantConditions
          final WebView webView = new WebView(getActivity());
          webView.getSettings().setLoadWithOverviewMode(true);
          webView.getSettings().setUseWideViewPort(false);
          webView.getSettings().setJavaScriptEnabled(true);
  
          final ProgressDialog progressDialog = new ProgressDialog(getContext());
          progressDialog.setMessage("");
          progressDialog.show();
          webView.setWebViewClient(new WebViewClient() {
              @Override
              public void onPageFinished(WebView view, String url) {
                  if (progressDialog.isShowing()) {
                      progressDialog.dismiss();
                  }
              }
          });
  
          String versionName = BuildConfig.VERSION_NAME;
          String system_language = Locale.getDefault().getLanguage();
          String url;
          String[] allowed_languages = {"hi", "ko", "af", "sq", "am", "ar", "hy", "az", "eu", "be", "bn", "bs", "bg", "ca", "ceb", "ny", "zh", "zh-CN", "zh-TW", "co", "hr", "cs", "da", "nl", "eo", "et", "tl", "fi", "fr", "fy", "gl", "ka", "de", "el", "gu", "ht", "ha", "haw", "iw", "hi", "hmn", "hu", "is", "ig", "id", "ga", "it", "ja", "jw", "kn", "kk", "km", "rw", "ko", "ku", "ky", "lo", "la", "lv", "lt", "lb", "mk", "mg", "ms", "ml", "mt", "mi", "mr", "mn", "my", "ne", "no", "or", "ps", "fa", "pl", "pt", "pa", "ro", "ru", "sm", "gd", "sr", "st", "sn", "sd", "si", "sk", "sl", "so", "es", "su", "sw", "sv", "tg", "ta", "tt", "te", "th", "tr", "tk", "uk", "ur", "ug", "uz", "vi", "cy", "xh", "yi", "yo", "zu"};
          if (Arrays.asList(allowed_languages).contains(system_language)) {
              url = "https://translate.google.com/translate?sl=en&tl=" + system_language + "&u=https%3A%2F%2Fakhilkedia.github.io%2FAllTrans%2F" + versionName;
          } else {
              url = "https://akhilkedia.github.io/AllTrans/" + versionName;
          }
          webView.loadUrl(url);
          return webView;
      }
  
  }
  