From 14e6187efcb55ac5e72f11504e51cd3274675475 Mon Sep 17 00:00:00 2001 From: FineFindus Date: Thu, 13 Jun 2024 20:42:16 +0200 Subject: [PATCH] feat(ErrorDisplayItem): improve UI/UX with new design Updates the design of the ErrorStatusDisplayItem to be more user-friendly. The new design displays an error message indicating that an error has occurred while attempting to display the item. It then offers the choice of either view the item in the browser or copy the error details. --- .../displayitems/ErrorStatusDisplayItem.java | 43 ++++++----- .../ui/displayitems/StatusDisplayItem.java | 4 +- .../main/res/layout/display_item_error.xml | 76 +++++++++++++++++++ mastodon/src/main/res/values/strings_mo.xml | 5 ++ 4 files changed, 110 insertions(+), 18 deletions(-) create mode 100644 mastodon/src/main/res/layout/display_item_error.xml diff --git a/mastodon/src/main/java/org/joinmastodon/android/ui/displayitems/ErrorStatusDisplayItem.java b/mastodon/src/main/java/org/joinmastodon/android/ui/displayitems/ErrorStatusDisplayItem.java index 7e8fea609..33ca9f4c2 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/ui/displayitems/ErrorStatusDisplayItem.java +++ b/mastodon/src/main/java/org/joinmastodon/android/ui/displayitems/ErrorStatusDisplayItem.java @@ -1,23 +1,26 @@ package org.joinmastodon.android.ui.displayitems; import android.content.Context; -import android.net.Uri; -import android.text.TextUtils; +import android.os.Build; import android.view.View; import android.view.ViewGroup; -import android.widget.TextView; +import org.joinmastodon.android.BuildConfig; import org.joinmastodon.android.R; import org.joinmastodon.android.fragments.BaseStatusListFragment; -import org.joinmastodon.android.model.Attachment; +import org.joinmastodon.android.model.Status; import org.joinmastodon.android.ui.utils.UiUtils; +import java.io.PrintWriter; +import java.io.StringWriter; + public class ErrorStatusDisplayItem extends StatusDisplayItem{ private final Exception exception; - public ErrorStatusDisplayItem(String parentID, BaseStatusListFragment parentFragment, Exception exception) { + public ErrorStatusDisplayItem(String parentID, Status status, BaseStatusListFragment parentFragment, Exception exception) { super(parentID, parentFragment); this.exception=exception; + this.status=status; } @Override @@ -26,24 +29,30 @@ public class ErrorStatusDisplayItem extends StatusDisplayItem{ } public static class Holder extends StatusDisplayItem.Holder { - private final TextView title, domain; public Holder(Context context, ViewGroup parent) { - super(context, R.layout.display_item_file, parent); - title=findViewById(R.id.title); - domain=findViewById(R.id.domain); - findViewById(R.id.inner).setOnClickListener(this::onClick); + super(context, R.layout.display_item_error, parent); + findViewById(R.id.button_open_browser).setOnClickListener(v -> UiUtils.launchWebBrowser(v.getContext(), item.status.url)); + findViewById(R.id.button_copy_error_details).setOnClickListener(this::copyErrorDetails); } @Override - public void onBind(ErrorStatusDisplayItem item) { - title.setText(item.exception.getMessage()); -// title.setEllipsize(item.attachment.description != null ? TextUtils.TruncateAt.END : TextUtils.TruncateAt.MIDDLE); -// domain.setText(url.getHost()); - } + public void onBind(ErrorStatusDisplayItem item) {} - private void onClick(View v) { -// UiUtils.openURL(itemView.getContext(), item.parentFragment.getAccountID(), getUrl()); + private void copyErrorDetails(View v) { + StringWriter stringWriter=new StringWriter(); + PrintWriter printWriter=new PrintWriter(stringWriter); + item.exception.printStackTrace(printWriter); + String stackTrace=stringWriter.toString(); + + String errorDetails=String.format( + "App Version: %s\nOS Version: %s\nStatus URL: %s\nException: %s", + v.getContext().getString(R.string.mo_settings_app_version, BuildConfig.VERSION_NAME, BuildConfig.VERSION_CODE), + "Android " + Build.VERSION.RELEASE, + item.status.url, + stackTrace + ); + UiUtils.copyText(v, errorDetails); } } } diff --git a/mastodon/src/main/java/org/joinmastodon/android/ui/displayitems/StatusDisplayItem.java b/mastodon/src/main/java/org/joinmastodon/android/ui/displayitems/StatusDisplayItem.java index f6b6f5ca4..7dcfd7d27 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/ui/displayitems/StatusDisplayItem.java +++ b/mastodon/src/main/java/org/joinmastodon/android/ui/displayitems/StatusDisplayItem.java @@ -10,6 +10,7 @@ import android.graphics.drawable.ColorDrawable; import android.os.Bundle; import android.text.SpannableStringBuilder; import android.text.TextUtils; +import android.util.Log; import android.view.View; import android.view.ViewGroup; @@ -379,7 +380,8 @@ public abstract class StatusDisplayItem{ : Collections.singletonList(warning) ); } catch(Exception e) { - return new ArrayList<>(Collections.singletonList(new ErrorStatusDisplayItem(parentID, fragment, e))); + Log.e("StatusDisplayItem", "buildItems: failed to build StatusDisplayItem " + e); + return new ArrayList<>(Collections.singletonList(new ErrorStatusDisplayItem(parentID, statusForContent, fragment, e))); } } diff --git a/mastodon/src/main/res/layout/display_item_error.xml b/mastodon/src/main/res/layout/display_item_error.xml new file mode 100644 index 000000000..accd114a1 --- /dev/null +++ b/mastodon/src/main/res/layout/display_item_error.xml @@ -0,0 +1,76 @@ + + + + + + + + + +