Makes mention clickable in remote instances

This commit is contained in:
stom79 2018-09-03 19:32:23 +02:00
parent 7ae0f21f7c
commit 05c0f258bc
2 changed files with 40 additions and 6 deletions

View File

@ -23,6 +23,7 @@ import java.util.List;
import fr.gouv.etalab.mastodon.client.API;
import fr.gouv.etalab.mastodon.client.APIResponse;
import fr.gouv.etalab.mastodon.client.Entities.Status;
import fr.gouv.etalab.mastodon.helper.FilterToots;
import fr.gouv.etalab.mastodon.interfaces.OnRetrieveFeedsInterface;
import fr.gouv.etalab.mastodon.sqlite.Sqlite;
@ -123,6 +124,12 @@ public class RetrieveFeedsAsyncTask extends AsyncTask<Void, Void, Void> {
break;
case REMOTE_INSTANCE:
apiResponse = api.getPublicTimeline(this.instanceName,false, max_id);
List<fr.gouv.etalab.mastodon.client.Entities.Status> statusesTemp = apiResponse.getStatuses();
if( statusesTemp != null){
for(fr.gouv.etalab.mastodon.client.Entities.Status status: statusesTemp){
status.setType(action);
}
}
break;
case FAVOURITES:
apiResponse = api.getFavourites(max_id);

View File

@ -57,6 +57,8 @@ 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.asynctasks.RetrieveFeedsAsyncTask;
import fr.gouv.etalab.mastodon.helper.CrossActions;
import fr.gouv.etalab.mastodon.helper.Helper;
import fr.gouv.etalab.mastodon.interfaces.OnRetrieveEmojiInterface;
@ -110,7 +112,7 @@ public class Status implements Parcelable{
private Status status;
private String content, contentCW, contentTranslated;
private SpannableString contentSpan, displayNameSpan, contentSpanCW, contentSpanTranslated;
private RetrieveFeedsAsyncTask.Type type;
public Status(){
this.status = this;
@ -826,11 +828,28 @@ public class Status implements Parcelable{
spannableStringT.setSpan(new ClickableSpan() {
@Override
public void onClick(View textView) {
Intent intent = new Intent(context, ShowAccountActivity.class);
Bundle b = new Bundle();
b.putString("accountId", mention.getId());
intent.putExtras(b);
context.startActivity(intent);
if( type == null || type != RetrieveFeedsAsyncTask.Type.REMOTE_INSTANCE) {
Intent intent = new Intent(context, ShowAccountActivity.class);
Bundle b = new Bundle();
b.putString("accountId", mention.getId());
intent.putExtras(b);
context.startActivity(intent);
}else {
String url = mention.getUrl();
Pattern instanceHost = Pattern.compile("https?:\\/\\/([\\da-z\\.-]+\\.[a-z\\.]{2,6})\\/(@[\\/\\w._-]*)");
Matcher matcherAcct = instanceHost.matcher(url);
String instance = null, acct = null;
while (matcherAcct.find()){
instance = matcherAcct.group(1);
acct = matcherAcct.group(2);
}
if( acct != null && instance != null){
Account account = new Account();
account.setInstance(instance);
account.setAcct(acct.replace("@",""));
CrossActions.doCrossProfile(context, account);
}
}
}
@Override
public void updateDrawState(TextPaint ds) {
@ -962,4 +981,12 @@ public class Status implements Parcelable{
public void setReplies_count(int replies_count) {
this.replies_count = replies_count;
}
public RetrieveFeedsAsyncTask.Type getType() {
return type;
}
public void setType(RetrieveFeedsAsyncTask.Type type) {
this.type = type;
}
}