diff --git a/mastodon/src/main/java/org/joinmastodon/android/api/MastodonErrorResponse.java b/mastodon/src/main/java/org/joinmastodon/android/api/MastodonErrorResponse.java index 9dfbfdc8..f7d69066 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/api/MastodonErrorResponse.java +++ b/mastodon/src/main/java/org/joinmastodon/android/api/MastodonErrorResponse.java @@ -5,31 +5,62 @@ import android.view.View; import android.widget.TextView; import android.widget.Toast; +import com.google.gson.JsonIOException; +import com.google.gson.JsonSyntaxException; + import org.joinmastodon.android.R; +import java.net.SocketTimeoutException; +import java.net.UnknownHostException; + import me.grishka.appkit.api.ErrorResponse; public class MastodonErrorResponse extends ErrorResponse{ public final String error; public final int httpStatus; public final Throwable underlyingException; + public final int messageResource; public MastodonErrorResponse(String error, int httpStatus, Throwable exception){ this.error=error; this.httpStatus=httpStatus; this.underlyingException=exception; + + if(exception instanceof UnknownHostException){ + this.messageResource=R.string.could_not_reach_server; + }else if(exception instanceof SocketTimeoutException){ + this.messageResource=R.string.connection_timed_out; + }else if(exception instanceof JsonSyntaxException || exception instanceof JsonIOException || httpStatus>=500){ + this.messageResource=R.string.server_error; + }else if(httpStatus==404){ + this.messageResource=R.string.not_found; + }else{ + this.messageResource=0; + } } @Override public void bindErrorView(View view){ TextView text=view.findViewById(R.id.error_text); - text.setText(error); + String message; + if(messageResource>0){ + message=view.getContext().getString(messageResource, error); + }else{ + message=error; + } + text.setText(message); } @Override public void showToast(Context context){ if(context==null) return; - Toast.makeText(context, error, Toast.LENGTH_SHORT).show(); + String message; + if(messageResource>0){ + message=context.getString(messageResource, error); + }else{ + message=error; + } + Toast.makeText(context, message, Toast.LENGTH_SHORT).show(); } } diff --git a/mastodon/src/main/java/org/joinmastodon/android/fragments/settings/SettingsServerAboutFragment.java b/mastodon/src/main/java/org/joinmastodon/android/fragments/settings/SettingsServerAboutFragment.java index cd464289..307dfd83 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/fragments/settings/SettingsServerAboutFragment.java +++ b/mastodon/src/main/java/org/joinmastodon/android/fragments/settings/SettingsServerAboutFragment.java @@ -100,15 +100,19 @@ public class SettingsServerAboutFragment extends LoaderFragment{ scroller.setClipToPadding(false); scroller.addView(scrollingLayout); - FixedAspectRatioImageView banner=new FixedAspectRatioImageView(getActivity()); - banner.setAspectRatio(1.914893617f); - banner.setScaleType(ImageView.ScaleType.CENTER_CROP); - banner.setOutlineProvider(OutlineProviders.bottomRoundedRect(16)); - banner.setClipToOutline(true); - ViewImageLoader.loadWithoutAnimation(banner, getResources().getDrawable(R.drawable.image_placeholder, getActivity().getTheme()), new UrlImageLoaderRequest(instance.thumbnail)); - LinearLayout.LayoutParams blp=new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT); - blp.bottomMargin=V.dp(24); - scrollingLayout.addView(banner, blp); + if(!TextUtils.isEmpty(instance.thumbnail)){ + FixedAspectRatioImageView banner=new FixedAspectRatioImageView(getActivity()); + banner.setAspectRatio(1.914893617f); + banner.setScaleType(ImageView.ScaleType.CENTER_CROP); + banner.setOutlineProvider(OutlineProviders.bottomRoundedRect(16)); + banner.setClipToOutline(true); + ViewImageLoader.loadWithoutAnimation(banner, getResources().getDrawable(R.drawable.image_placeholder, getActivity().getTheme()), new UrlImageLoaderRequest(instance.thumbnail)); + LinearLayout.LayoutParams blp=new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT); + blp.bottomMargin=V.dp(24); + scrollingLayout.addView(banner, blp); + }else{ + scrollingLayout.setPadding(0, V.dp(24), 0, 0); + } boolean needDivider=false; if(instance.contactAccount!=null){ diff --git a/mastodon/src/main/java/org/joinmastodon/android/ui/displayitems/MediaGridStatusDisplayItem.java b/mastodon/src/main/java/org/joinmastodon/android/ui/displayitems/MediaGridStatusDisplayItem.java index e21d557e..e3e3d7fe 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/ui/displayitems/MediaGridStatusDisplayItem.java +++ b/mastodon/src/main/java/org/joinmastodon/android/ui/displayitems/MediaGridStatusDisplayItem.java @@ -173,7 +173,7 @@ public class MediaGridStatusDisplayItem extends StatusDisplayItem{ } controllers.add(c); - if (item.status.translation != null){ + if (item.status.translation!=null && item.status.translation.mediaAttachments!=null){ if(item.status.translationState==Status.TranslationState.SHOWN){ if(!item.translatedAttachments.containsKey(att.id)){ Optional translatedAttachment=Arrays.stream(item.status.translation.mediaAttachments).filter(mediaAttachment->mediaAttachment.id.equals(att.id)).findFirst(); diff --git a/mastodon/src/main/java/org/joinmastodon/android/ui/viewcontrollers/ComposeMediaViewController.java b/mastodon/src/main/java/org/joinmastodon/android/ui/viewcontrollers/ComposeMediaViewController.java index 94170fd6..e3930971 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/ui/viewcontrollers/ComposeMediaViewController.java +++ b/mastodon/src/main/java/org/joinmastodon/android/ui/viewcontrollers/ComposeMediaViewController.java @@ -313,7 +313,12 @@ public class ComposeMediaViewController{ int maxSize=0; String contentType=fragment.getActivity().getContentResolver().getType(attachment.uri); if(contentType!=null && contentType.startsWith("image/")){ - maxSize=2_073_600; // TODO get this from instance configuration when it gets added there + Instance instance=fragment.instance; + if(instance.configuration!=null && instance.configuration.mediaAttachments!=null && instance.configuration.mediaAttachments.imageMatrixLimit>0){ + maxSize=instance.configuration.mediaAttachments.imageMatrixLimit; + }else{ + maxSize=2_073_600; + } } attachment.progressBar.setProgress(0); attachment.speedTracker.reset(); diff --git a/mastodon/src/main/res/layout/sheet_photo_viewer_info.xml b/mastodon/src/main/res/layout/sheet_photo_viewer_info.xml index b588e173..560f85d6 100644 --- a/mastodon/src/main/res/layout/sheet_photo_viewer_info.xml +++ b/mastodon/src/main/res/layout/sheet_photo_viewer_info.xml @@ -141,6 +141,7 @@ android:layout_marginHorizontal="16dp" android:textAppearance="@style/m3_body_large" android:textColor="?colorM3OnSurface" + android:textIsSelectable="true" tools:text="A cute black cat"/> diff --git a/mastodon/src/main/res/values/strings.xml b/mastodon/src/main/res/values/strings.xml index 19f7552a..61cf2fd8 100644 --- a/mastodon/src/main/res/values/strings.xml +++ b/mastodon/src/main/res/values/strings.xml @@ -314,7 +314,7 @@ This server does not accept new registrations. Copied to clipboard Bookmark - Remove Bookmark + Remove bookmark Bookmarks Your favorites Welcome back @@ -751,10 +751,14 @@ Fewer algorithmic fanfares Only your followers Everyone mentioned in the post - View Boosts - View Favorites - Undo Boost - Undo Favorite + View boosts + View favorites + Undo boost + Undo favorite + Couldn’t reach the server. Check your connection and try again? + The request timed out. Check your connection and try again? + Something went wrong talking with your server. It’s probably not your fault. Try again? + It could’ve been deleted, or maybe it never existed at all. Dismiss Just once Monthly