pull/254/head
Thomas 2 years ago
parent f47866660e
commit 06c3da5d2c

@ -77,7 +77,7 @@ public class Nitter implements Serializable {
public static Status convert(Context context, String instance, FeedItem feedItem) { public static Status convert(Context context, String instance, FeedItem feedItem) {
Status status = new Status(); Status status = new Status();
status.id = feedItem.pubDate; status.id = feedItem.pubDate;
status.content = feedItem.title; status.content = feedItem.description;
status.text = feedItem.title; status.text = feedItem.title;
status.visibility = "public"; status.visibility = "public";
status.created_at = Helper.stringToDateWithFormat(context, feedItem.pubDate, "EEE, dd MMM yyyy HH:mm:ss zzz"); status.created_at = Helper.stringToDateWithFormat(context, feedItem.pubDate, "EEE, dd MMM yyyy HH:mm:ss zzz");
@ -103,8 +103,8 @@ public class Nitter implements Serializable {
app.fedilab.android.client.entities.api.Account account = new app.fedilab.android.client.entities.api.Account(); app.fedilab.android.client.entities.api.Account account = new app.fedilab.android.client.entities.api.Account();
String[] names = nitterAccount.image.title.split("/"); String[] names = nitterAccount.image.title.split("/");
account.id = feedItem.guid; account.id = feedItem.guid;
account.acct = names[1]; account.acct = names[1].replace("@", "");
account.username = names[1]; account.username = names[1].replace("@", "");
account.display_name = names[0]; account.display_name = names[0];
account.avatar = nitterAccount.image.url; account.avatar = nitterAccount.image.url;
account.avatar_static = nitterAccount.image.url; account.avatar_static = nitterAccount.image.url;

@ -650,8 +650,9 @@ public class Helper {
} else { } else {
Intent intent = new Intent(Intent.ACTION_VIEW); Intent intent = new Intent(Intent.ACTION_VIEW);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
if (!url.toLowerCase().startsWith("http://") && !url.toLowerCase().startsWith("https://") && !url.toLowerCase().startsWith("gemini://")) if (url != null && !url.toLowerCase().startsWith("http://") && !url.toLowerCase().startsWith("https://") && !url.toLowerCase().startsWith("gemini://")) {
url = "http://" + url; url = "http://" + url;
}
intent.setData(Uri.parse(url)); intent.setData(Uri.parse(url));
try { try {
context.startActivity(intent); context.startActivity(intent);

@ -1007,6 +1007,41 @@ public class SpannableHelper {
return statuses; return statuses;
} }
public static List<Status> convertNitterStatus(Context context, List<Status> statuses) {
if (statuses != null) {
for (Status status : statuses) {
convertNitterStatus(context, status);
}
}
return statuses;
}
public static Status convertNitterStatus(Context context, Status status) {
if (status != null) {
status.span_content = SpannableHelper.convertNitter(context, status.content);
}
return status;
}
/**
* Convert HTML content to text. Also, it handles click on link and transform emoji
* This needs to be run asynchronously
*
* @param context {@link Context}
* @param text String - text to convert, it can be content, spoiler, poll items, etc.
* @return Spannable string
*/
private static Spannable convertNitter(@NonNull Context context, String text) {
SpannableString initialContent;
if (text == null) {
return null;
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N)
initialContent = new SpannableString(Html.fromHtml(text, Html.FROM_HTML_MODE_LEGACY));
else
initialContent = new SpannableString(Html.fromHtml(text));
return initialContent;
}
public static List<Announcement> convertAnnouncement(Context context, List<Announcement> announcements) { public static List<Announcement> convertAnnouncement(Context context, List<Announcement> announcements) {
if (announcements != null) { if (announcements != null) {

@ -72,7 +72,7 @@ public class ContextAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder
StatusesVM statusesVM = new ViewModelProvider((ViewModelStoreOwner) context).get(StatusesVM.class); StatusesVM statusesVM = new ViewModelProvider((ViewModelStoreOwner) context).get(StatusesVM.class);
SearchVM searchVM = new ViewModelProvider((ViewModelStoreOwner) context).get(SearchVM.class); SearchVM searchVM = new ViewModelProvider((ViewModelStoreOwner) context).get(SearchVM.class);
StatusAdapter.StatusViewHolder holder = (StatusAdapter.StatusViewHolder) viewHolder; StatusAdapter.StatusViewHolder holder = (StatusAdapter.StatusViewHolder) viewHolder;
statusManagement(context, statusesVM, searchVM, holder, this, statusList, null, status, Timeline.TimeLineEnum.UNKNOWN, false); statusManagement(context, statusesVM, searchVM, holder, this, statusList, null, status, Timeline.TimeLineEnum.UNKNOWN, false, true);
//Hide/Show specific view //Hide/Show specific view
} }

@ -169,7 +169,7 @@ public class NotificationAdapter extends RecyclerView.Adapter<RecyclerView.ViewH
} }
StatusesVM statusesVM = new ViewModelProvider((ViewModelStoreOwner) context).get(StatusesVM.class); StatusesVM statusesVM = new ViewModelProvider((ViewModelStoreOwner) context).get(StatusesVM.class);
SearchVM searchVM = new ViewModelProvider((ViewModelStoreOwner) context).get(SearchVM.class); SearchVM searchVM = new ViewModelProvider((ViewModelStoreOwner) context).get(SearchVM.class);
statusManagement(context, statusesVM, searchVM, holderStatus, this, null, notificationList, notification.status, Timeline.TimeLineEnum.NOTIFICATION, false); statusManagement(context, statusesVM, searchVM, holderStatus, this, null, notificationList, notification.status, Timeline.TimeLineEnum.NOTIFICATION, false, true);
holderStatus.bindingNotification.status.dateShort.setText(Helper.dateDiff(context, notification.created_at)); holderStatus.bindingNotification.status.dateShort.setText(Helper.dateDiff(context, notification.created_at));
holderStatus.bindingNotification.containerTransparent.setAlpha(.3f); holderStatus.bindingNotification.containerTransparent.setAlpha(.3f);
if (getItemViewType(position) == TYPE_MENTION || getItemViewType(position) == TYPE_STATUS) { if (getItemViewType(position) == TYPE_MENTION || getItemViewType(position) == TYPE_STATUS) {

@ -141,11 +141,13 @@ public class StatusAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
private final Timeline.TimeLineEnum timelineType; private final Timeline.TimeLineEnum timelineType;
public FetchMoreCallBack fetchMoreCallBack; public FetchMoreCallBack fetchMoreCallBack;
private Context context; private Context context;
private final boolean canBeFederated;
public StatusAdapter(List<Status> statuses, Timeline.TimeLineEnum timelineType, boolean minified) { public StatusAdapter(List<Status> statuses, Timeline.TimeLineEnum timelineType, boolean minified, boolean canBeFederated) {
this.statusList = statuses; this.statusList = statuses;
this.timelineType = timelineType; this.timelineType = timelineType;
this.minified = minified; this.minified = minified;
this.canBeFederated = canBeFederated;
} }
@ -293,7 +295,7 @@ public class StatusAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
List<Notification> notificationList, List<Notification> notificationList,
Status status, Status status,
Timeline.TimeLineEnum timelineType, Timeline.TimeLineEnum timelineType,
boolean minified) { boolean minified, boolean canBeFederated) {
if (status == null) { if (status == null) {
return; return;
} }
@ -469,7 +471,7 @@ public class StatusAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
} else { } else {
holder.binding.card.setVisibility(View.GONE); holder.binding.card.setVisibility(View.GONE);
} }
if (minified) { if (minified || !canBeFederated) {
holder.binding.actionButtons.setVisibility(View.GONE); holder.binding.actionButtons.setVisibility(View.GONE);
} else { } else {
holder.binding.actionButtons.setVisibility(View.VISIBLE); holder.binding.actionButtons.setVisibility(View.VISIBLE);
@ -1298,7 +1300,7 @@ public class StatusAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
} }
return false; return false;
}); });
if (!minified) { if (!minified && canBeFederated) {
holder.binding.mainContainer.setOnClickListener(v -> { holder.binding.mainContainer.setOnClickListener(v -> {
holder.binding.statusContent.callOnClick(); holder.binding.statusContent.callOnClick();
}); });
@ -1335,6 +1337,9 @@ public class StatusAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
} }
} }
}); });
} else if (!canBeFederated) {
holder.binding.mainContainer.setOnClickListener(v -> Helper.openBrowser(context, status.url));
holder.binding.statusContent.setOnClickListener(v -> Helper.openBrowser(context, status.url));
} }
@ -1756,7 +1761,7 @@ public class StatusAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
StatusViewHolder holder = (StatusViewHolder) viewHolder; StatusViewHolder holder = (StatusViewHolder) viewHolder;
StatusesVM statusesVM = new ViewModelProvider((ViewModelStoreOwner) context).get(StatusesVM.class); StatusesVM statusesVM = new ViewModelProvider((ViewModelStoreOwner) context).get(StatusesVM.class);
SearchVM searchVM = new ViewModelProvider((ViewModelStoreOwner) context).get(SearchVM.class); SearchVM searchVM = new ViewModelProvider((ViewModelStoreOwner) context).get(SearchVM.class);
statusManagement(context, statusesVM, searchVM, holder, this, statusList, null, status, timelineType, minified); statusManagement(context, statusesVM, searchVM, holder, this, statusList, null, status, timelineType, minified, canBeFederated);
if (holder.timer != null) { if (holder.timer != null) {
holder.timer.cancel(); holder.timer.cancel();
holder.timer = null; holder.timer = null;

@ -169,7 +169,7 @@ public class FragmentMastodonContext extends Fragment {
this.statuses = new ArrayList<>(); this.statuses = new ArrayList<>();
focusedStatus.isFocused = true; focusedStatus.isFocused = true;
this.statuses.add(focusedStatus); this.statuses.add(focusedStatus);
statusAdapter = new StatusAdapter(this.statuses, Timeline.TimeLineEnum.UNKNOWN, false); statusAdapter = new StatusAdapter(this.statuses, Timeline.TimeLineEnum.UNKNOWN, false, true);
binding.swipeContainer.setRefreshing(false); binding.swipeContainer.setRefreshing(false);
LinearLayoutManager mLayoutManager = new LinearLayoutManager(requireActivity()); LinearLayoutManager mLayoutManager = new LinearLayoutManager(requireActivity());
binding.recyclerView.setLayoutManager(mLayoutManager); binding.recyclerView.setLayoutManager(mLayoutManager);

@ -144,6 +144,7 @@ public class FragmentMastodonTimeline extends Fragment implements StatusAdapter.
private String ident; private String ident;
private String instance, user_id; private String instance, user_id;
private ArrayList<String> idOfAddedStatuses; private ArrayList<String> idOfAddedStatuses;
private boolean canBeFederated;
/** /**
* Return the position of the status in the ArrayList * Return the position of the status in the ArrayList
@ -199,6 +200,7 @@ public class FragmentMastodonTimeline extends Fragment implements StatusAdapter.
timelineType = Timeline.TimeLineEnum.HOME; timelineType = Timeline.TimeLineEnum.HOME;
instance = MainActivity.currentInstance; instance = MainActivity.currentInstance;
user_id = MainActivity.currentUserID; user_id = MainActivity.currentUserID;
canBeFederated = true;
if (getArguments() != null) { if (getArguments() != null) {
timelineType = (Timeline.TimeLineEnum) getArguments().get(Helper.ARG_TIMELINE_TYPE); timelineType = (Timeline.TimeLineEnum) getArguments().get(Helper.ARG_TIMELINE_TYPE);
list_id = getArguments().getString(Helper.ARG_LIST_ID, null); list_id = getArguments().getString(Helper.ARG_LIST_ID, null);
@ -211,6 +213,7 @@ public class FragmentMastodonTimeline extends Fragment implements StatusAdapter.
} else { } else {
SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(requireActivity()); SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(requireActivity());
remoteInstance = sharedpreferences.getString(getString(R.string.SET_NITTER_HOST), getString(R.string.DEFAULT_NITTER_HOST)).toLowerCase(); remoteInstance = sharedpreferences.getString(getString(R.string.SET_NITTER_HOST), getString(R.string.DEFAULT_NITTER_HOST)).toLowerCase();
canBeFederated = false;
} }
} }
@ -336,12 +339,13 @@ public class FragmentMastodonTimeline extends Fragment implements StatusAdapter.
if (min_id == null || (statuses.pagination.min_id != null && statuses.pagination.min_id.compareTo(min_id) > 0)) { if (min_id == null || (statuses.pagination.min_id != null && statuses.pagination.min_id.compareTo(min_id) > 0)) {
min_id = statuses.pagination.min_id; min_id = statuses.pagination.min_id;
} }
statusAdapter = new StatusAdapter(this.statuses, timelineType, minified); statusAdapter = new StatusAdapter(this.statuses, timelineType, minified, canBeFederated);
statusAdapter.fetchMoreCallBack = this; statusAdapter.fetchMoreCallBack = this;
if (statusReport != null) { if (statusReport != null) {
scrollToTop(); scrollToTop();
} }
mLayoutManager = new LinearLayoutManager(requireActivity()); mLayoutManager = new LinearLayoutManager(requireActivity());
mLayoutManager.setOrientation(LinearLayoutManager.VERTICAL);
binding.recyclerView.setLayoutManager(mLayoutManager); binding.recyclerView.setLayoutManager(mLayoutManager);
binding.recyclerView.setAdapter(statusAdapter); binding.recyclerView.setAdapter(statusAdapter);

@ -184,11 +184,9 @@ public class TimelinesVM extends AndroidViewModel {
statusList.add(status); statusList.add(status);
} }
} }
List<Status> filteredStatuses = TimelineHelper.filterStatus(getApplication(), statusList, TimelineHelper.FilterTimeLineType.PUBLIC); statuses.statuses = SpannableHelper.convertNitterStatus(getApplication().getApplicationContext(), statusList);
statuses.statuses = SpannableHelper.convertStatus(getApplication().getApplicationContext(), filteredStatuses);
statuses.pagination = MastodonHelper.getPagination(publicTlResponse.headers()); statuses.pagination = MastodonHelper.getPagination(publicTlResponse.headers());
} }
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} }

Loading…
Cancel
Save