feat: show extended description in info

This commit is contained in:
FineFindus 2023-05-22 14:52:04 +02:00
parent 9897b8bfcd
commit 64fc052c55
No known key found for this signature in database
GPG Key ID: 64873EE210FF8E6B
3 changed files with 63 additions and 3 deletions

View File

@ -0,0 +1,12 @@
package org.joinmastodon.android.api.requests.instance;
import org.joinmastodon.android.api.MastodonAPIRequest;
import org.joinmastodon.android.model.ExtendedDescription;
import org.joinmastodon.android.model.Instance;
public class GetExtendedDescription extends MastodonAPIRequest<ExtendedDescription>{
public GetExtendedDescription(){
super(HttpMethod.GET, "/instance/extended_description", ExtendedDescription.class);
}
}

View File

@ -23,12 +23,14 @@ import androidx.recyclerview.widget.LinearLayoutManager;
import org.joinmastodon.android.GlobalUserPreferences;
import org.joinmastodon.android.R;
import org.joinmastodon.android.api.requests.instance.GetExtendedDescription;
import org.joinmastodon.android.api.requests.instance.GetInstance;
import org.joinmastodon.android.api.session.AccountSessionManager;
import org.joinmastodon.android.fragments.onboarding.InstanceRulesFragment;
import org.joinmastodon.android.model.Account;
import org.joinmastodon.android.model.AccountField;
import org.joinmastodon.android.model.Attachment;
import org.joinmastodon.android.model.ExtendedDescription;
import org.joinmastodon.android.model.Instance;
import org.joinmastodon.android.model.TimelineDefinition;
import org.joinmastodon.android.ui.BetterItemAnimator;
@ -64,6 +66,7 @@ import me.grishka.appkit.views.UsableRecyclerView;
public class InstanceInfoFragment extends LoaderFragment {
private Instance instance;
private String extendedDescription;
private CoverImageView cover;
private TextView uri, description;
@ -102,6 +105,7 @@ public class InstanceInfoFragment extends LoaderFragment {
account= AccountSessionManager.getInstance().getAccount(accountID).self;
targetDomain=getArguments().getString("instanceDomain");
loadData();
loadExtendedDescription();
}
@Override
@ -166,10 +170,33 @@ public class InstanceInfoFragment extends LoaderFragment {
}
})
//hack to get instance url for local and remote accounts
.execNoAuth(targetDomain);
}
private void loadExtendedDescription() {
new GetExtendedDescription()
.setCallback(new SimpleCallback<>(this){
@Override
public void onSuccess(ExtendedDescription result){
if (getActivity() == null || result == null || TextUtils.isEmpty(result.content)) return;
extendedDescription = result.content;
updateDescription();
}
})
.execNoAuth(targetDomain);
}
private void updateDescription() {
if (instance == null || description == null)
return;
description.setText(HtmlParser.parse(TextUtils.isEmpty(extendedDescription) ?
TextUtils.isEmpty(instance.description) ? instance.shortDescription : instance.description
: extendedDescription,
account.emojis, Collections.emptyList(), Collections.emptyList(), accountID));
}
@Override
public void onRefresh(){
if(refreshing)
@ -232,8 +259,7 @@ public class InstanceInfoFragment extends LoaderFragment {
uri.setText(instance.title);
setTitle(instance.title);
CharSequence parsedDescription = HtmlParser.parse(TextUtils.isEmpty(instance.description) ? instance.shortDescription : instance.description, account.emojis, Collections.emptyList(), Collections.emptyList(), accountID);
description.setText(parsedDescription);
updateDescription();
fields.clear();

View File

@ -0,0 +1,22 @@
package org.joinmastodon.android.model;
import org.joinmastodon.android.api.RequiredField;
import org.parceler.Parcel;
import java.util.List;
@Parcel
public class ExtendedDescription extends BaseModel{
@RequiredField
public String content;
@RequiredField
public String updatedAt;
@Override
public String toString() {
return "ExtendedDescription{" +
"content='" + content + '\'' +
", updatedAt='" + updatedAt + '\'' +
'}';
}
}