mirror of
https://github.com/AngelAuraMC/Amethyst-Android.git
synced 2025-09-13 23:00:45 -04:00
Localizable changelog
This commit is contained in:
parent
bd253b2449
commit
3671d59464
@ -7,6 +7,8 @@ import android.os.Bundle;
|
|||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
import androidx.annotation.RequiresApi;
|
import androidx.annotation.RequiresApi;
|
||||||
import androidx.fragment.app.Fragment;
|
import androidx.fragment.app.Fragment;
|
||||||
|
|
||||||
|
import android.util.Log;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
@ -17,28 +19,65 @@ import android.webkit.WebViewClient;
|
|||||||
|
|
||||||
import net.kdt.pojavlaunch.R;
|
import net.kdt.pojavlaunch.R;
|
||||||
import net.kdt.pojavlaunch.*;
|
import net.kdt.pojavlaunch.*;
|
||||||
|
import net.kdt.pojavlaunch.prefs.LauncherPreferences;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.net.HttpURLConnection;
|
||||||
|
import java.net.MalformedURLException;
|
||||||
|
import java.net.URL;
|
||||||
|
import java.util.Locale;
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
public class LauncherFragment extends Fragment
|
public class LauncherFragment extends Fragment
|
||||||
{
|
{
|
||||||
private WebView webNews;
|
private WebView webNews;
|
||||||
private View view;
|
private View view;
|
||||||
|
private Thread validUrlSelectorThread;
|
||||||
|
private String validChangelog = "/changelog.html";
|
||||||
|
private boolean interruptLoad = false;
|
||||||
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
|
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
|
||||||
super.onCreateView(inflater, container, savedInstanceState);
|
super.onCreateView(inflater, container, savedInstanceState);
|
||||||
view = inflater.inflate(R.layout.lmaintab_news, container, false);
|
view = inflater.inflate(R.layout.lmaintab_news, container, false);
|
||||||
return view;
|
return view;
|
||||||
}
|
}
|
||||||
|
public void selectValidUrl() {
|
||||||
|
String lang = LauncherPreferences.PREF_LANGUAGE;
|
||||||
|
if(lang.equals("default")) lang = Locale.getDefault().getLanguage();
|
||||||
|
final String localizedUrl = "/changelog-"+lang+".html";
|
||||||
|
if(!tryUrl(Tools.URL_HOME+localizedUrl)) return;
|
||||||
|
else {
|
||||||
|
requireActivity().runOnUiThread(()->{
|
||||||
|
interruptLoad = true;
|
||||||
|
validChangelog = localizedUrl;
|
||||||
|
webNews.loadUrl(Tools.URL_HOME+validChangelog);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public boolean tryUrl(String url) {
|
||||||
|
Log.i("ChangelogLocale","Trying localized url: "+url);
|
||||||
|
try {
|
||||||
|
HttpURLConnection conn = (HttpURLConnection) new URL(url).openConnection();
|
||||||
|
conn.connect();
|
||||||
|
Log.i("ChangelogLocale","Code: "+conn.getResponseCode());
|
||||||
|
return ("" + conn.getResponseCode()).startsWith("2");
|
||||||
|
}catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
@Override
|
@Override
|
||||||
public void onActivityCreated(Bundle p1)
|
public void onActivityCreated(Bundle p1)
|
||||||
{
|
{
|
||||||
super.onActivityCreated(p1);
|
super.onActivityCreated(p1);
|
||||||
|
|
||||||
webNews = (WebView) getView().findViewById(R.id.lmaintabnewsNewsView);
|
webNews = (WebView) getView().findViewById(R.id.lmaintabnewsNewsView);
|
||||||
webNews.setWebViewClient(new WebViewClient(){
|
webNews.setWebViewClient(new WebViewClient(){
|
||||||
|
|
||||||
// API < 23
|
// API < 23
|
||||||
@Override
|
@Override
|
||||||
public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
|
public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
|
||||||
|
Log.i("WebNews",failingUrl + ": "+description);
|
||||||
if(webNews != null){
|
if(webNews != null){
|
||||||
|
if(validUrlSelectorThread.isAlive()) validUrlSelectorThread.stop();
|
||||||
removeWebView();
|
removeWebView();
|
||||||
//Change the background to match the other pages.
|
//Change the background to match the other pages.
|
||||||
//We change it only when the webView is removed to avoid huge overdraw.
|
//We change it only when the webView is removed to avoid huge overdraw.
|
||||||
@ -48,7 +87,7 @@ public class LauncherFragment extends Fragment
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean shouldOverrideUrlLoading(WebView view, String url) {
|
public boolean shouldOverrideUrlLoading(WebView view, String url) {
|
||||||
if(!url.equals(Tools.URL_HOME + "/changelog.html")){
|
if(!url.equals(Tools.URL_HOME + validChangelog)){
|
||||||
Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
|
Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
|
||||||
startActivity(i);
|
startActivity(i);
|
||||||
return true;
|
return true;
|
||||||
@ -59,7 +98,9 @@ public class LauncherFragment extends Fragment
|
|||||||
@RequiresApi(23) //API 23+
|
@RequiresApi(23) //API 23+
|
||||||
@Override
|
@Override
|
||||||
public void onReceivedError(WebView view, WebResourceRequest request, WebResourceError error) {
|
public void onReceivedError(WebView view, WebResourceRequest request, WebResourceError error) {
|
||||||
|
Log.i("WebNews",error.getDescription()+"");
|
||||||
if(webNews != null){
|
if(webNews != null){
|
||||||
|
if(validUrlSelectorThread.isAlive()) validUrlSelectorThread.stop();
|
||||||
removeWebView();
|
removeWebView();
|
||||||
LauncherFragment.this.view.setBackgroundColor(Color.parseColor("#44000000"));
|
LauncherFragment.this.view.setBackgroundColor(Color.parseColor("#44000000"));
|
||||||
}
|
}
|
||||||
@ -68,7 +109,7 @@ public class LauncherFragment extends Fragment
|
|||||||
@RequiresApi(23)
|
@RequiresApi(23)
|
||||||
@Override
|
@Override
|
||||||
public boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request) {
|
public boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request) {
|
||||||
if(!request.getUrl().toString().equals(Tools.URL_HOME + "/changelog.html")){
|
if(!request.getUrl().toString().equals(Tools.URL_HOME + validChangelog)){
|
||||||
Intent i = new Intent(Intent.ACTION_VIEW, request.getUrl());
|
Intent i = new Intent(Intent.ACTION_VIEW, request.getUrl());
|
||||||
startActivity(i);
|
startActivity(i);
|
||||||
return true;
|
return true;
|
||||||
@ -78,7 +119,9 @@ public class LauncherFragment extends Fragment
|
|||||||
});
|
});
|
||||||
webNews.clearCache(true);
|
webNews.clearCache(true);
|
||||||
webNews.getSettings().setJavaScriptEnabled(true);
|
webNews.getSettings().setJavaScriptEnabled(true);
|
||||||
webNews.loadUrl(Tools.URL_HOME + "/changelog.html");
|
validUrlSelectorThread = new Thread(this::selectValidUrl);
|
||||||
|
validUrlSelectorThread.start();
|
||||||
|
if(!interruptLoad)webNews.loadUrl(Tools.URL_HOME + validChangelog);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void removeWebView() {
|
private void removeWebView() {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user