mirror of
https://github.com/oxen-io/session-android.git
synced 2025-12-31 13:06:09 +00:00
Add support for article dates in link previews.
This commit is contained in:
committed by
Alan Evans
parent
bfed03b7b5
commit
dd8b9ff8fb
@@ -23,6 +23,10 @@ import org.thoughtcrime.securesms.mms.SlidesClickedListener;
|
||||
import org.thoughtcrime.securesms.util.ThemeUtil;
|
||||
import org.thoughtcrime.securesms.util.Util;
|
||||
|
||||
import java.text.DateFormat;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Locale;
|
||||
|
||||
import okhttp3.HttpUrl;
|
||||
|
||||
/**
|
||||
@@ -146,14 +150,24 @@ public class LinkPreviewView extends FrameLayout {
|
||||
description.setVisibility(GONE);
|
||||
}
|
||||
|
||||
String domain = null;
|
||||
|
||||
if (!Util.isEmpty(linkPreview.getUrl())) {
|
||||
HttpUrl url = HttpUrl.parse(linkPreview.getUrl());
|
||||
if (url != null) {
|
||||
site.setText(url.topPrivateDomain());
|
||||
site.setVisibility(VISIBLE);
|
||||
} else {
|
||||
site.setVisibility(GONE);
|
||||
domain = url.topPrivateDomain();
|
||||
}
|
||||
}
|
||||
|
||||
if (domain != null && linkPreview.getDate() > 0) {
|
||||
site.setText(getContext().getString(R.string.LinkPreviewView_domain_date, domain, formatDate(linkPreview.getDate())));
|
||||
site.setVisibility(VISIBLE);
|
||||
} else if (domain != null) {
|
||||
site.setText(domain);
|
||||
site.setVisibility(VISIBLE);
|
||||
} else if (linkPreview.getDate() > 0) {
|
||||
site.setText(formatDate(linkPreview.getDate()));
|
||||
site.setVisibility(VISIBLE);
|
||||
} else {
|
||||
site.setVisibility(GONE);
|
||||
}
|
||||
@@ -187,6 +201,11 @@ public class LinkPreviewView extends FrameLayout {
|
||||
: R.string.LinkPreviewView_no_link_preview_available;
|
||||
}
|
||||
|
||||
private static String formatDate(long date) {
|
||||
DateFormat dateFormat = new SimpleDateFormat("MMM dd, yyyy", Locale.getDefault());
|
||||
return dateFormat.format(date);
|
||||
}
|
||||
|
||||
public interface CloseClickedListener {
|
||||
void onCloseClicked();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user