mirror of
https://github.com/M66B/FairEmail.git
synced 2025-03-19 02:15:28 +00:00
Refactoring
This commit is contained in:
parent
f7f749cb06
commit
ef1d2c229e
2 changed files with 25 additions and 21 deletions
|
@ -46,7 +46,6 @@ import android.view.KeyEvent;
|
|||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.inputmethod.EditorInfo;
|
||||
import android.webkit.URLUtil;
|
||||
import android.widget.Button;
|
||||
import android.widget.CheckBox;
|
||||
import android.widget.CompoundButton;
|
||||
|
@ -139,26 +138,7 @@ public class FragmentDialogOpenLink extends FragmentDialogBase {
|
|||
// Preload web view
|
||||
Helper.customTabsWarmup(context);
|
||||
|
||||
final Uri uri;
|
||||
if (_uri.getScheme() == null) {
|
||||
String url = _uri.toString();
|
||||
if (Helper.EMAIL_ADDRESS.matcher(url).matches())
|
||||
uri = Uri.parse("mailto:" + _uri.toString());
|
||||
else if (android.util.Patterns.PHONE.matcher(url).matches())
|
||||
// Alternative: PhoneNumberUtils.isGlobalPhoneNumber()
|
||||
uri = Uri.parse("tel:" + _uri.toString());
|
||||
else {
|
||||
Uri g = Uri.parse(URLUtil.guessUrl(url));
|
||||
String scheme = g.getScheme();
|
||||
if (scheme != null) {
|
||||
if ("http".equals(scheme))
|
||||
scheme = "https";
|
||||
uri = Uri.parse(scheme + "://" + _uri.toString());
|
||||
} else
|
||||
uri = _uri;
|
||||
}
|
||||
} else
|
||||
uri = _uri;
|
||||
final Uri uri = UriHelper.guessScheme(_uri);
|
||||
|
||||
// Process link
|
||||
final Uri sanitized;
|
||||
|
|
|
@ -20,7 +20,9 @@ package eu.faircode.email;
|
|||
*/
|
||||
|
||||
import android.content.Context;
|
||||
import android.net.Uri;
|
||||
import android.text.TextUtils;
|
||||
import android.webkit.URLUtil;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
|
@ -96,6 +98,28 @@ public class UriHelper {
|
|||
return null;
|
||||
}
|
||||
|
||||
static @NonNull
|
||||
Uri guessScheme(@NonNull Uri uri) {
|
||||
if (uri.getScheme() != null)
|
||||
return uri;
|
||||
|
||||
String url = uri.toString();
|
||||
if (Helper.EMAIL_ADDRESS.matcher(url).matches())
|
||||
return Uri.parse("mailto:" + url);
|
||||
else if (android.util.Patterns.PHONE.matcher(url).matches())
|
||||
// Alternative: PhoneNumberUtils.isGlobalPhoneNumber()
|
||||
return Uri.parse("tel:" + url);
|
||||
else {
|
||||
Uri g = Uri.parse(URLUtil.guessUrl(url));
|
||||
String scheme = g.getScheme();
|
||||
if (scheme == null)
|
||||
return uri;
|
||||
else if ("http".equals(scheme))
|
||||
scheme = "https";
|
||||
return Uri.parse(scheme + "://" + url);
|
||||
}
|
||||
}
|
||||
|
||||
static void ensureSuffixList(Context context) {
|
||||
synchronized (suffixList) {
|
||||
if (suffixList.size() > 0)
|
||||
|
|
Loading…
Add table
Reference in a new issue