Clickable status link

This commit is contained in:
stom79 2018-09-01 15:59:16 +02:00
parent 997bba9ce3
commit ac69434ee2
4 changed files with 35 additions and 18 deletions

View File

@ -125,7 +125,9 @@ import static fr.gouv.etalab.mastodon.helper.Helper.INTENT_TARGETED_ACCOUNT;
import static fr.gouv.etalab.mastodon.helper.Helper.NOTIFICATION_INTENT;
import static fr.gouv.etalab.mastodon.helper.Helper.PREF_KEY_ID;
import static fr.gouv.etalab.mastodon.helper.Helper.SEARCH_KEYWORD;
import static fr.gouv.etalab.mastodon.helper.Helper.SEARCH_REMOTE;
import static fr.gouv.etalab.mastodon.helper.Helper.SEARCH_TAG;
import static fr.gouv.etalab.mastodon.helper.Helper.SEARCH_URL;
import static fr.gouv.etalab.mastodon.helper.Helper.THEME_BLACK;
import static fr.gouv.etalab.mastodon.helper.Helper.changeDrawableColor;
import static fr.gouv.etalab.mastodon.helper.Helper.changeUser;
@ -1134,7 +1136,6 @@ public abstract class BaseMainActivity extends BaseActivity
String type = intent.getType();
Bundle extras = intent.getExtras();
String userIdIntent;
if( extras != null && extras.containsKey(INTENT_ACTION) ){
final NavigationView navigationView = findViewById(R.id.nav_view);
userIdIntent = extras.getString(PREF_KEY_ID); //Id of the account in the intent
@ -1171,20 +1172,23 @@ public abstract class BaseMainActivity extends BaseActivity
}else if( extras.getInt(INTENT_ACTION) == BACKUP_INTENT){
Intent myIntent = new Intent(BaseMainActivity.this, OwnerStatusActivity.class);
startActivity(myIntent);
}else if(extras.getInt(INTENT_ACTION) == SEARCH_TAG){
String keyword = extras.getString(SEARCH_KEYWORD);
if( keyword != null){
adapter = new PagerAdapter
(getSupportFragmentManager(), tabLayout.getTabCount());
viewPager.setAdapter(adapter);
for(int i = 0; i < tabLayout.getTabCount() ; i++ ){
if( tabLayout.getTabAt(i).getText() != null && tabLayout.getTabAt(i).getText().equals(keyword.trim())){
tabLayout.getTabAt(i).select();
break;
}
}
}else if (extras.getInt(INTENT_ACTION) == SEARCH_REMOTE) {
String url = extras.getString(SEARCH_URL);
if( url == null)
return;
Matcher matcher;
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.KITKAT)
matcher = Patterns.WEB_URL.matcher(url);
else
matcher = Helper.urlPattern.matcher(url);
boolean isUrl = false;
while (matcher.find()){
isUrl = true;
}
if(!isUrl)
return;
//Here we know that the intent contains a valid URL
new RetrieveRemoteDataAsyncTask(BaseMainActivity.this, url, BaseMainActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
}else if( Intent.ACTION_SEND.equals(action) && type != null ) {
if ("text/plain".equals(type)) {

View File

@ -55,10 +55,15 @@ import java.util.regex.Pattern;
import fr.gouv.etalab.mastodon.R;
import fr.gouv.etalab.mastodon.activities.HashTagActivity;
import fr.gouv.etalab.mastodon.activities.MainActivity;
import fr.gouv.etalab.mastodon.activities.ShowAccountActivity;
import fr.gouv.etalab.mastodon.helper.Helper;
import fr.gouv.etalab.mastodon.interfaces.OnRetrieveEmojiInterface;
import static fr.gouv.etalab.mastodon.helper.Helper.INTENT_ACTION;
import static fr.gouv.etalab.mastodon.helper.Helper.SEARCH_REMOTE;
import static fr.gouv.etalab.mastodon.helper.Helper.SEARCH_URL;
/**
* Created by Thomas on 23/04/2017.
* Manage Status (ie: toots)
@ -695,7 +700,6 @@ public class Status implements Parcelable{
int theme = sharedpreferences.getInt(Helper.SET_THEME, Helper.THEME_DARK);
Matcher matcher;
Pattern aLink = Pattern.compile("(<\\s?a\\s?href=\"(https?:\\/\\/[\\da-z\\.-]+\\.[a-z\\.]{2,6}[\\/]?[^\"@(\\/tags\\/)]*)\"\\s?[^.]*<\\s?\\/\\s?a\\s?>)");
Matcher matcherALink = aLink.matcher(spannableString.toString());
while (matcherALink.find()){
@ -778,9 +782,16 @@ public class Status implements Parcelable{
@Override
public void onClick(View textView) {
String finalUrl = url;
if( !url.startsWith("http://") && ! url.startsWith("https://"))
Pattern link = Pattern.compile("https?:\\/\\/([\\da-z\\.-]+\\.[a-z\\.]{2,6})\\/(@[\\/\\w._-]*[0-9]*)");
if( url.contains("@")){
Intent intent = new Intent(context, MainActivity.class);
intent.putExtra(INTENT_ACTION, SEARCH_REMOTE);
intent.putExtra(SEARCH_URL, url);
context.startActivity(intent);
}else if( !url.startsWith("http://") && ! url.startsWith("https://")) {
finalUrl = "http://" + url;
Helper.openBrowser(context, finalUrl);
Helper.openBrowser(context, finalUrl);
}
}
@Override
public void updateDrawState(TextPaint ds) {

View File

@ -214,6 +214,7 @@ public class Helper {
public static final String SHOULD_CONTINUE_STREAMING_FEDERATED = "should_continue_streaming_federated";
public static final String SHOULD_CONTINUE_STREAMING_LOCAL = "should_continue_streaming_local";
public static final String SEARCH_KEYWORD = "search_keyword";
public static final String SEARCH_URL = "search_url";
public static final String CLIP_BOARD = "clipboard";
public static final String INSTANCE_NAME = "instance_name";
//Notifications
@ -225,6 +226,7 @@ public class Helper {
public static final int BACKUP_INTENT = 6;
public static final int SEARCH_TAG = 7;
public static final int SEARCH_INSTANCE = 8;
public static final int SEARCH_REMOTE = 9;
//Settings
public static final String SET_TOOTS_PER_PAGE = "set_toots_per_page";

View File

@ -555,7 +555,7 @@
<string name="toast_instance_already_added">You already follow this instance!</string>
<string name="toast_instance_followed">The instance is followed!</string>
<string name="mastohost_name" translatable="false">masto.host</string>
<string name="about_partnership" translatable="false"><b>Masto.host</b> is our Mastodon hosting partner.\nWith this partnership they provide me free hosting for <a href="https://ins.mastalab.app">Mastalab\'s instance</a> and in exchange I promote them in here.\nTo be clear, there is no money involved or tracking of users sent. I needed an instance for testing, we talked and agreed on this.\n\n<a href="https://masto.host">Go check them out</a> if you want to run your own Mastodon instance.</string>
<string name="about_partnership" translatable="false"><b>Masto.host</b> is our Mastodon hosting partner.\n\nWith this partnership they provide me free hosting for <a href="https://ins.mastalab.app">Mastalab\'s instance</a> and in exchange I promote them in here.\n\nTo be clear, there is no money involved or tracking of users. I needed an instance for testing, we talked and agreed on this.\n\n<a href="https://masto.host">Go check them out</a> if you want to run your own Mastodon instance.</string>
<string name="action_partnership" >Partnerships</string>
<string name="neutral_menu_information">Information</string>
<string-array translatable="false" name="proxy_type_choice">