Display module/releases last publish time (#2012)

* Display module/releases last update time

Co-authored-by: Howard20181 <40033067+Howard20181@users.noreply.github.com>
Co-authored-by: 南宫雪珊 <vvb2060@gmail.com>
This commit is contained in:
TigerBeanst 2022-06-29 21:38:37 +08:00 committed by GitHub
parent 307b88f1d6
commit f565075c43
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 67 additions and 7 deletions

View File

@ -46,6 +46,9 @@ public class OnlineModule {
@SerializedName("latestRelease") @SerializedName("latestRelease")
@Expose @Expose
private String latestRelease; private String latestRelease;
@SerializedName("latestReleaseTime")
@Expose
private String latestReleaseTime;
@SerializedName("releases") @SerializedName("releases")
@Expose @Expose
private List<Release> releases = new ArrayList<>(); private List<Release> releases = new ArrayList<>();
@ -125,6 +128,10 @@ public class OnlineModule {
return releases; return releases;
} }
public String getLatestReleaseTime() {
return latestReleaseTime;
}
public void setReleases(List<Release> releases) { public void setReleases(List<Release> releases) {
this.releases = releases; this.releases = releases;
} }

View File

@ -58,6 +58,9 @@ import org.lsposed.manager.ui.widget.EmptyStateRecyclerView;
import org.lsposed.manager.util.ModuleUtil; import org.lsposed.manager.util.ModuleUtil;
import java.time.Instant; import java.time.Instant;
import java.time.ZoneId;
import java.time.format.DateTimeFormatter;
import java.time.format.FormatStyle;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.Collections; import java.util.Collections;
@ -283,7 +286,10 @@ public class RepoFragment extends BaseFragment implements RepoLoader.RepoListene
OnlineModule module = showList.get(position); OnlineModule module = showList.get(position);
holder.appName.setText(module.getDescription()); holder.appName.setText(module.getDescription());
holder.appPackageName.setText(module.getName()); holder.appPackageName.setText(module.getName());
var instant = Instant.parse(module.getLatestReleaseTime());
var formatter = DateTimeFormatter.ofLocalizedDate(FormatStyle.SHORT)
.withLocale(App.getLocale()).withZone(ZoneId.systemDefault());
holder.publishedTime.setText(String.format(getString(R.string.module_repo_updated_time), formatter.format(instant)));
SpannableStringBuilder sb = new SpannableStringBuilder(); SpannableStringBuilder sb = new SpannableStringBuilder();
String summary = module.getSummary(); String summary = module.getSummary();
@ -352,7 +358,7 @@ public class RepoFragment extends BaseFragment implements RepoLoader.RepoListene
if (sort == 0) { if (sort == 0) {
return labelComparator.compare(a.getDescription(), b.getDescription()); return labelComparator.compare(a.getDescription(), b.getDescription());
} else { } else {
return Instant.parse(b.getReleases().get(0).getUpdatedAt()).compareTo(Instant.parse(a.getReleases().get(0).getUpdatedAt())); return Instant.parse(b.getLatestReleaseTime()).compareTo(Instant.parse(a.getLatestReleaseTime()));
} }
}).collect(Collectors.toList()); }).collect(Collectors.toList());
String queryStr = searchView != null ? searchView.getQuery().toString() : ""; String queryStr = searchView != null ? searchView.getQuery().toString() : "";
@ -392,14 +398,16 @@ public class RepoFragment extends BaseFragment implements RepoLoader.RepoListene
TextView appPackageName; TextView appPackageName;
TextView appDescription; TextView appDescription;
TextView hint; TextView hint;
TextView publishedTime;
ViewHolder(ItemOnlinemoduleBinding binding) { ViewHolder(ItemOnlinemoduleBinding binding) {
super(binding.getRoot()); super(binding.getRoot());
root = binding.itemRoot; root = binding.itemRoot;
appName = binding.appName; appName = binding.appName;
appPackageName=binding.appPackageName; appPackageName = binding.appPackageName;
appDescription = binding.description; appDescription = binding.description;
hint = binding.hint; hint = binding.hint;
publishedTime = binding.publishedTime;
} }
} }

View File

@ -77,6 +77,10 @@ import org.lsposed.manager.util.chrome.CustomTabsURLSpan;
import java.io.ByteArrayInputStream; import java.io.ByteArrayInputStream;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
import java.time.Instant;
import java.time.ZoneId;
import java.time.format.DateTimeFormatter;
import java.time.format.FormatStyle;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.ListIterator; import java.util.ListIterator;
@ -411,6 +415,10 @@ public class RepoItemFragment extends BaseFragment implements RepoLoader.RepoLis
} else { } else {
Release release = items.get(position); Release release = items.get(position);
holder.title.setText(release.getName()); holder.title.setText(release.getName());
var instant = Instant.parse(release.getPublishedAt());
var formatter = DateTimeFormatter.ofLocalizedDateTime(FormatStyle.SHORT)
.withLocale(App.getLocale()).withZone(ZoneId.systemDefault());
holder.publishedTime.setText(String.format(getString(R.string.module_repo_published_time), formatter.format(instant)));
renderGithubMarkdown(holder.description, release.getDescriptionHTML()); renderGithubMarkdown(holder.description, release.getDescriptionHTML());
holder.openInBrowser.setOnClickListener(v -> NavUtil.startURL(requireActivity(), release.getUrl())); holder.openInBrowser.setOnClickListener(v -> NavUtil.startURL(requireActivity(), release.getUrl()));
List<ReleaseAsset> assets = release.getReleaseAssets(); List<ReleaseAsset> assets = release.getReleaseAssets();
@ -443,6 +451,7 @@ public class RepoItemFragment extends BaseFragment implements RepoLoader.RepoLis
class ViewHolder extends RecyclerView.ViewHolder { class ViewHolder extends RecyclerView.ViewHolder {
TextView title; TextView title;
TextView publishedTime;
WebView description; WebView description;
MaterialButton openInBrowser; MaterialButton openInBrowser;
MaterialButton viewAssets; MaterialButton viewAssets;
@ -457,6 +466,7 @@ public class RepoItemFragment extends BaseFragment implements RepoLoader.RepoLis
public ReleaseViewHolder(ItemRepoReleaseBinding binding) { public ReleaseViewHolder(ItemRepoReleaseBinding binding) {
super(binding.getRoot()); super(binding.getRoot());
title = binding.title; title = binding.title;
publishedTime = binding.publishedTime;
description = binding.description; description = binding.description;
openInBrowser = binding.openInBrowser; openInBrowser = binding.openInBrowser;
viewAssets = binding.viewAssets; viewAssets = binding.viewAssets;

View File

@ -98,7 +98,7 @@
android:textAppearance="?android:attr/textAppearanceListItemSecondary" android:textAppearance="?android:attr/textAppearanceListItemSecondary"
android:textColor="?android:attr/textColorPrimary" android:textColor="?android:attr/textColorPrimary"
app:layout_constrainedWidth="true" app:layout_constrainedWidth="true"
app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintBottom_toTopOf="@id/published_Time"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0" app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
@ -106,5 +106,22 @@
app:layout_constraintWidth_max="wrap" app:layout_constraintWidth_max="wrap"
tools:text="@tools:sample/lorem" /> tools:text="@tools:sample/lorem" />
<com.google.android.material.textview.MaterialTextView
android:id="@+id/published_Time"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:textAppearance="?android:attr/textAppearanceSmall"
app:layout_constrainedWidth="true"
android:textSize="12sp"
android:layout_marginTop="2dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/hint"
app:layout_constraintWidth_max="wrap"
tools:text="@tools:sample/lorem" />
</androidx.constraintlayout.widget.ConstraintLayout> </androidx.constraintlayout.widget.ConstraintLayout>
</FrameLayout> </FrameLayout>

View File

@ -47,12 +47,26 @@
android:textSize="16sp" android:textSize="16sp"
app:layout_constrainedWidth="true" app:layout_constrainedWidth="true"
app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintBottom_toTopOf="@id/description" app:layout_constraintBottom_toTopOf="@id/published_Time"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" app:layout_constraintTop_toTopOf="parent"
app:layout_constraintWidth_max="wrap" app:layout_constraintWidth_max="wrap"
tools:text="@tools:sample/lorem" /> tools:text="@tools:sample/lorem" />
<com.google.android.material.textview.MaterialTextView
android:id="@+id/published_Time"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textSize="14sp"
app:layout_constrainedWidth="true"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintBottom_toTopOf="@id/description"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/title"
app:layout_constraintWidth_max="wrap"
tools:text="@tools:sample/lorem" />
<org.lsposed.manager.ui.widget.ScrollWebView <org.lsposed.manager.ui.widget.ScrollWebView
android:id="@+id/description" android:id="@+id/description"
android:layout_width="0dp" android:layout_width="0dp"
@ -62,8 +76,8 @@
android:textAppearance="?android:attr/textAppearanceSmall" android:textAppearance="?android:attr/textAppearanceSmall"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="1.0" app:layout_constraintHorizontal_bias="1.0"
app:layout_constraintStart_toStartOf="@+id/title" app:layout_constraintStart_toStartOf="@+id/published_Time"
app:layout_constraintTop_toBottomOf="@id/title" app:layout_constraintTop_toBottomOf="@id/published_Time"
tools:text="@tools:sample/lorem" /> tools:text="@tools:sample/lorem" />
<com.google.android.material.button.MaterialButton <com.google.android.material.button.MaterialButton

View File

@ -33,6 +33,8 @@
<string name="module_repo">仓库</string> <string name="module_repo">仓库</string>
<string name="module_repo_loading">加载中…</string> <string name="module_repo_loading">加载中…</string>
<string name="module_repo_up_to_date">所有模块均已最新</string> <string name="module_repo_up_to_date">所有模块均已最新</string>
<string name="module_repo_published_time">发布于 %s</string>
<string name="module_repo_updated_time">更新于 %s</string>
<plurals name="module_repo_upgradable"> <plurals name="module_repo_upgradable">
<item quantity="other">%d 个模块可更新</item> <item quantity="other">%d 个模块可更新</item>
</plurals> </plurals>

View File

@ -34,6 +34,8 @@
<string name="module_repo">Repository</string> <string name="module_repo">Repository</string>
<string name="module_repo_loading">Loading…</string> <string name="module_repo_loading">Loading…</string>
<string name="module_repo_up_to_date">All modules up to date</string> <string name="module_repo_up_to_date">All modules up to date</string>
<string name="module_repo_published_time">Published at %s</string>
<string name="module_repo_updated_time">Updated at %s</string>
<plurals name="module_repo_upgradable"> <plurals name="module_repo_upgradable">
<item quantity="one">%d module upgradable</item> <item quantity="one">%d module upgradable</item>
<item quantity="other">%d modules upgradable</item> <item quantity="other">%d modules upgradable</item>