mirror of
https://github.com/gsantner/dandelion
synced 2025-09-10 10:49:42 +02:00
Fix #151; URL handling; language; dia.so
* Language switcher in settings (#151) * Handle dia.so links * Improve security at internal browser decision
This commit is contained in:
parent
47184fe878
commit
ac2327d2f2
17 changed files with 208 additions and 69 deletions
|
@ -152,8 +152,8 @@ public class SettingsActivity extends ThemedActivity implements SharedPreference
|
|||
}
|
||||
|
||||
@Override
|
||||
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String s) {
|
||||
if (s.equals(getString(R.string.pref_key__screen_rotation))) {
|
||||
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
|
||||
if (key.equals(getString(R.string.pref_key__screen_rotation))) {
|
||||
this.updateScreenRotation();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -21,6 +21,7 @@ package com.github.dfa.diaspora_android.ui.theme;
|
|||
import android.annotation.TargetApi;
|
||||
import android.app.ActivityManager;
|
||||
import android.content.pm.ActivityInfo;
|
||||
import android.content.res.Configuration;
|
||||
import android.graphics.drawable.BitmapDrawable;
|
||||
import android.os.Build;
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
|
@ -28,6 +29,9 @@ import android.support.v7.app.AppCompatActivity;
|
|||
import com.github.dfa.diaspora_android.App;
|
||||
import com.github.dfa.diaspora_android.R;
|
||||
import com.github.dfa.diaspora_android.util.AppSettings;
|
||||
import com.github.dfa.diaspora_android.util.Helpers;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
/**
|
||||
* Activity that supports color schemes
|
||||
|
@ -44,6 +48,7 @@ public abstract class ThemedActivity extends AppCompatActivity {
|
|||
protected void onResume() {
|
||||
super.onResume();
|
||||
ThemeHelper.getInstance(getAppSettings());
|
||||
updateLanguage();
|
||||
updateStatusBarColor();
|
||||
updateRecentAppColor();
|
||||
applyColorToViews();
|
||||
|
@ -91,4 +96,12 @@ public abstract class ThemedActivity extends AppCompatActivity {
|
|||
}
|
||||
setRequestedOrientation(rotation);
|
||||
}
|
||||
|
||||
public void updateLanguage() {
|
||||
AppSettings appSettings = getAppSettings();
|
||||
Locale locale = Helpers.getLocaleByAndroidCode(appSettings.getLanguage());
|
||||
Configuration config = appSettings.getApplicationContext().getResources().getConfiguration();
|
||||
config.locale = locale != null ? locale : Locale.getDefault();
|
||||
appSettings.getApplicationContext().getResources().updateConfiguration(config, null);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -430,6 +430,14 @@ public class AppSettings {
|
|||
setLong(prefPod, R.string.pref_key__podprofile_last_stream_position, timestamp);
|
||||
}
|
||||
|
||||
public void setLanguage(String value){
|
||||
setString(prefApp, R.string.pref_key__language, value);
|
||||
}
|
||||
|
||||
public String getLanguage(){
|
||||
return getString(prefApp, R.string.pref_key__language, "");
|
||||
}
|
||||
|
||||
public void setPrimaryColorSettings(int base, int shade) {
|
||||
setInt(prefApp, R.string.pref_key__primary_color_base, base);
|
||||
setInt(prefApp, R.string.pref_key__primary_color_shade, shade);
|
||||
|
|
|
@ -27,8 +27,10 @@ import android.os.Build;
|
|||
import android.os.Bundle;
|
||||
import android.os.Environment;
|
||||
import android.support.design.widget.Snackbar;
|
||||
import android.text.TextUtils;
|
||||
import android.view.View;
|
||||
|
||||
import com.github.dfa.diaspora_android.App;
|
||||
import com.github.dfa.diaspora_android.R;
|
||||
import com.github.dfa.diaspora_android.web.WebHelper;
|
||||
|
||||
|
@ -84,6 +86,16 @@ public class Helpers {
|
|||
);
|
||||
}
|
||||
|
||||
public static Locale getLocaleByAndroidCode(String code) {
|
||||
if (!TextUtils.isEmpty(code)) {
|
||||
return code.contains("-r")
|
||||
? new Locale(code.substring(0, 2), code.substring(4, 6)) // de-rAT
|
||||
: new Locale(code); // de
|
||||
}
|
||||
return Locale.getDefault();
|
||||
}
|
||||
|
||||
|
||||
public static String readTextfileFromRawRessource(Context context, int rawRessourceId, String linePrefix, String linePostfix) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
String line;
|
||||
|
|
|
@ -26,10 +26,11 @@ import android.webkit.WebViewClient;
|
|||
|
||||
import com.github.dfa.diaspora_android.App;
|
||||
import com.github.dfa.diaspora_android.activity.MainActivity;
|
||||
import com.github.dfa.diaspora_android.data.DiasporaPodList;
|
||||
|
||||
public class CustomWebViewClient extends WebViewClient {
|
||||
private final App app;
|
||||
private String lastLoadUrl ="";
|
||||
private String lastLoadUrl = "";
|
||||
|
||||
public CustomWebViewClient(App app, WebView webView) {
|
||||
this.app = app;
|
||||
|
@ -37,13 +38,18 @@ public class CustomWebViewClient extends WebViewClient {
|
|||
|
||||
//Open non-diaspora links in customtab/external browser
|
||||
public boolean shouldOverrideUrlLoading(WebView view, String url) {
|
||||
if (!url.contains(app.getSettings().getPod().getPodUrl().getHost())) {
|
||||
String host = app.getSettings().getPod().getPodUrl().getHost();
|
||||
|
||||
if (url.startsWith("https://" + host)
|
||||
|| url.startsWith("http://" + host)
|
||||
|| url.startsWith("https://dia.so/")) {
|
||||
return false;
|
||||
} else {
|
||||
Intent i = new Intent(MainActivity.ACTION_OPEN_EXTERNAL_URL);
|
||||
i.putExtra(MainActivity.EXTRA_URL, url);
|
||||
LocalBroadcastManager.getInstance(app.getApplicationContext()).sendBroadcast(i);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public void onPageFinished(WebView view, String url) {
|
||||
|
@ -51,14 +57,17 @@ public class CustomWebViewClient extends WebViewClient {
|
|||
|
||||
final CookieManager cookieManager = app.getCookieManager();
|
||||
String cookies = cookieManager.getCookie(url);
|
||||
//Log.d(this, "All the cookies in a string:" + cookies);
|
||||
DiasporaPodList.DiasporaPod pod = app.getSettings().getPod();
|
||||
|
||||
if (cookies != null) {
|
||||
cookieManager.setCookie(url, cookies);
|
||||
cookieManager.setCookie(app.getSettings().getPod().getPodUrl().getBaseUrl(), cookies);
|
||||
//for (String c : cookies.split(";")) {
|
||||
//AppLog.d(this, "Cookie: " + c.split("=")[0] + " Value:" + c.split("=")[1]);
|
||||
//}
|
||||
if (pod != null && pod.getPodUrl() != null) {
|
||||
cookieManager.setCookie(pod.getPodUrl().getBaseUrl(), cookies);
|
||||
cookieManager.setCookie(".dia.so", "pod=" + pod.getPodUrl().getHost());
|
||||
}
|
||||
for (String c : cookies.split(";")) {
|
||||
//AppLog.d(this, "Cookie: " + c.split("=")[0] + " Value:" + c.split("=")[1]);
|
||||
}
|
||||
//new ProfileFetchTask(app).execute();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue