Fixes issue #249 & #250 - External browser issue

This commit is contained in:
stom79 2018-01-17 07:27:52 +01:00
parent 9700b0b4df
commit 8ce1defef2
5 changed files with 58 additions and 58 deletions

View File

@ -333,13 +333,9 @@ public class ShowAccountActivity extends BaseActivity implements OnPostActionInt
return true; return true;
case R.id.action_open_browser: case R.id.action_open_browser:
if( accountUrl != null) { if( accountUrl != null) {
Intent intent = new Intent(getApplicationContext(), WebviewActivity.class);
Bundle b = new Bundle();
if( !accountUrl.startsWith("http://") && ! accountUrl.startsWith("https://")) if( !accountUrl.startsWith("http://") && ! accountUrl.startsWith("https://"))
accountUrl = "http://" + accountUrl; accountUrl = "http://" + accountUrl;
b.putString("url", accountUrl); Helper.openBrowser(ShowAccountActivity.this, accountUrl);
intent.putExtras(b);
startActivity(intent);
} }
return true; return true;
case R.id.action_mention: case R.id.action_mention:
@ -482,13 +478,9 @@ public class ShowAccountActivity extends BaseActivity implements OnPostActionInt
warning_message.setOnClickListener(new View.OnClickListener() { warning_message.setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View view) { public void onClick(View view) {
Intent intent = new Intent(getApplicationContext(), WebviewActivity.class);
Bundle b = new Bundle();
if( !accountUrl.startsWith("http://") && ! accountUrl.startsWith("https://")) if( !accountUrl.startsWith("http://") && ! accountUrl.startsWith("https://"))
accountUrl = "http://" + accountUrl; accountUrl = "http://" + accountUrl;
b.putString("url", accountUrl); Helper.openBrowser(ShowAccountActivity.this, accountUrl);
intent.putExtras(b);
startActivity(intent);
} }
}); });
//Timed muted account //Timed muted account

View File

@ -621,39 +621,34 @@ public class Status implements Parcelable{
spannableString.removeSpan(span); spannableString.removeSpan(span);
List<Mention> mentions = this.status.getReblog() != null ? this.status.getReblog().getMentions() : this.status.getMentions(); List<Mention> mentions = this.status.getReblog() != null ? this.status.getReblog().getMentions() : this.status.getMentions();
SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, android.content.Context.MODE_PRIVATE); SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, android.content.Context.MODE_PRIVATE);
boolean embedded_browser = sharedpreferences.getBoolean(Helper.SET_EMBEDDED_BROWSER, true);
if( embedded_browser){
Matcher matcher;
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.KITKAT)
matcher = Patterns.WEB_URL.matcher(spannableString);
else
matcher = Helper.urlPattern.matcher(spannableString);
while (matcher.find()){
int matchStart = matcher.start(1);
int matchEnd = matcher.end();
final String url = spannableString.toString().substring(matchStart, matchEnd);
spannableString.setSpan(new ClickableSpan() {
@Override
public void onClick(View textView) {
Intent intent = new Intent(context, WebviewActivity.class);
Bundle b = new Bundle();
String finalUrl = url;
if( !url.startsWith("http://") && ! url.startsWith("https://"))
finalUrl = "http://" + url;
b.putString("url", finalUrl);
intent.putExtras(b);
context.startActivity(intent);
}
@Override
public void updateDrawState(TextPaint ds) {
super.updateDrawState(ds);
}
},
matchStart, matchEnd,
Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
}
Matcher matcher;
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.KITKAT)
matcher = Patterns.WEB_URL.matcher(spannableString);
else
matcher = Helper.urlPattern.matcher(spannableString);
while (matcher.find()){
int matchStart = matcher.start(1);
int matchEnd = matcher.end();
final String url = spannableString.toString().substring(matchStart, matchEnd);
spannableString.setSpan(new ClickableSpan() {
@Override
public void onClick(View textView) {
String finalUrl = url;
if( !url.startsWith("http://") && ! url.startsWith("https://"))
finalUrl = "http://" + url;
Helper.openBrowser(context, finalUrl);
}
@Override
public void updateDrawState(TextPaint ds) {
super.updateDrawState(ds);
}
},
matchStart, matchEnd,
Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
} }
//Deals with mention to make them clickable //Deals with mention to make them clickable
if( mentions != null && mentions.size() > 0 ) { if( mentions != null && mentions.size() > 0 ) {
//Looping through accounts which are mentioned //Looping through accounts which are mentioned
@ -685,7 +680,7 @@ public class Status implements Parcelable{
} }
} }
Matcher matcher = Helper.hashtagPattern.matcher(spannableString); matcher = Helper.hashtagPattern.matcher(spannableString);
while (matcher.find()){ while (matcher.find()){
int matchStart = matcher.start(1); int matchStart = matcher.start(1);
int matchEnd = matcher.end(); int matchEnd = matcher.end();

View File

@ -965,11 +965,7 @@ public class StatusListAdapter extends RecyclerView.Adapter implements OnPostAct
holder.status_cardview.setOnClickListener(new View.OnClickListener() { holder.status_cardview.setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View view) { public void onClick(View view) {
Intent intent = new Intent(context, WebviewActivity.class); Helper.openBrowser(context, status.getCard().getUrl());
Bundle b = new Bundle();
b.putString("url", status.getCard().getUrl());
intent.putExtras(b);
context.startActivity(intent);
} }
}); });
}else { }else {
@ -991,11 +987,7 @@ public class StatusListAdapter extends RecyclerView.Adapter implements OnPostAct
} }
@Override @Override
public boolean shouldOverrideUrlLoading (WebView view, String url){ public boolean shouldOverrideUrlLoading (WebView view, String url){
Intent intent = new Intent(context, WebviewActivity.class); Helper.openBrowser(context, url);
Bundle b = new Bundle();
b.putString("url", url);
intent.putExtras(b);
context.startActivity(intent);
holder.status_cardview_webview.loadUrl(finalSrc); holder.status_cardview_webview.loadUrl(finalSrc);
return true; return true;
} }

View File

@ -1286,11 +1286,7 @@ public class Helper {
spannableString.setSpan(new ClickableSpan() { spannableString.setSpan(new ClickableSpan() {
@Override @Override
public void onClick(View textView) { public void onClick(View textView) {
Intent intent = new Intent(context, WebviewActivity.class); Helper.openBrowser(context, url);
Bundle b = new Bundle();
b.putString("url", url);
intent.putExtras(b);
context.startActivity(intent);
} }
@Override @Override
public void updateDrawState(TextPaint ds) { public void updateDrawState(TextPaint ds) {
@ -1786,6 +1782,31 @@ public class Helper {
}); });
} }
/**
* Manage URLs to open (built-in or external app)
* @param context Context
* @param url String url to open
*/
public static void openBrowser(Context context, String url){
SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, android.content.Context.MODE_PRIVATE);
boolean embedded_browser = sharedpreferences.getBoolean(Helper.SET_EMBEDDED_BROWSER, true);
if( embedded_browser) {
Intent intent = new Intent(context, WebviewActivity.class);
Bundle b = new Bundle();
String finalUrl = url;
if (!url.startsWith("http://") && !url.startsWith("https://"))
finalUrl = "http://" + url;
b.putString("url", finalUrl);
intent.putExtras(b);
context.startActivity(intent);
}else {
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse(url));
context.startActivity(intent);
}
}
public static void installProvider(){ public static void installProvider(){
Security.insertProviderAt(Conscrypt.newProvider(),1); Security.insertProviderAt(Conscrypt.newProvider(),1);
} }

View File

@ -263,7 +263,7 @@ public class NotificationsSyncJob extends Job {
}) })
.into(new SimpleTarget<Bitmap>() { .into(new SimpleTarget<Bitmap>() {
@Override @Override
public void onResourceReady(Bitmap resource, Transition<? super Bitmap> transition) { public void onResourceReady(@NonNull Bitmap resource, Transition<? super Bitmap> transition) {
notify_user(getContext(), intent, notificationId, resource, finalTitle, message); notify_user(getContext(), intent, notificationId, resource, finalTitle, message);
String lastNotif = sharedpreferences.getString(Helper.LAST_NOTIFICATION_MAX_ID + account.getId() + account.getInstance(), null); String lastNotif = sharedpreferences.getString(Helper.LAST_NOTIFICATION_MAX_ID + account.getId() + account.getInstance(), null);
if( lastNotif == null || Long.parseLong(notifications.get(0).getId()) > Long.parseLong(lastNotif)){ if( lastNotif == null || Long.parseLong(notifications.get(0).getId()) > Long.parseLong(lastNotif)){