diff --git a/mastodon/src/main/java/org/joinmastodon/android/fragments/BaseStatusListFragment.java b/mastodon/src/main/java/org/joinmastodon/android/fragments/BaseStatusListFragment.java index 78f09102..e577f1bb 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/fragments/BaseStatusListFragment.java +++ b/mastodon/src/main/java/org/joinmastodon/android/fragments/BaseStatusListFragment.java @@ -150,9 +150,9 @@ public abstract class BaseStatusListFragment exten UsableRecyclerView list=(UsableRecyclerView) this.list; for(int i=0; i exten public void openPhotoViewer(String parentID, Status _status, int attachmentIndex){ final Status status=_status.reblog!=null ? _status.reblog : _status; currentPhotoViewer=new PhotoViewer(getActivity(), status.mediaAttachments, attachmentIndex, new PhotoViewer.Listener(){ - private ImageStatusDisplayItem.Holder transitioningHolder; + private ImageStatusDisplayItem.Holder transitioningHolder; @Override public void setPhotoViewVisibility(int index, boolean visible){ - ImageStatusDisplayItem.Holder holder=findPhotoViewHolder(index); + ImageStatusDisplayItem.Holder holder=findPhotoViewHolder(index); if(holder!=null) holder.photo.setAlpha(visible ? 1f : 0f); } @Override public boolean startPhotoViewTransition(int index, @NonNull Rect outRect, @NonNull int[] outCornerRadius){ - ImageStatusDisplayItem.Holder holder=findPhotoViewHolder(index); + ImageStatusDisplayItem.Holder holder=findPhotoViewHolder(index); if(holder!=null){ transitioningHolder=holder; View view=transitioningHolder.photo; @@ -223,7 +223,7 @@ public abstract class BaseStatusListFragment exten @Override public Drawable getPhotoViewCurrentDrawable(int index){ - ImageStatusDisplayItem.Holder holder=findPhotoViewHolder(index); + ImageStatusDisplayItem.Holder holder=findPhotoViewHolder(index); if(holder!=null) return holder.photo.getDrawable(); return null; @@ -234,14 +234,14 @@ public abstract class BaseStatusListFragment exten currentPhotoViewer=null; } - private ImageStatusDisplayItem.Holder findPhotoViewHolder(int index){ + private ImageStatusDisplayItem.Holder findPhotoViewHolder(int index){ int offset=0; for(StatusDisplayItem item:displayItems){ if(item.parentID.equals(parentID)){ if(item instanceof ImageStatusDisplayItem){ RecyclerView.ViewHolder holder=list.findViewHolderForAdapterPosition(getMainAdapterOffset()+offset+index); - if(holder instanceof ImageStatusDisplayItem.Holder){ - return (ImageStatusDisplayItem.Holder) holder; + if(holder instanceof ImageStatusDisplayItem.Holder imgHolder){ + return imgHolder; } return null; } @@ -303,9 +303,9 @@ public abstract class BaseStatusListFragment exten position-=getMainAdapterOffset(); if(position>=0 && position exten } for(int i=0;i exten protected > H findHolderOfType(String id, Class type){ for(int i=0;i) holder).getItemID().equals(id) && type.isInstance(holder)) + if(holder instanceof StatusDisplayItem.Holder itemHolder && itemHolder.getItemID().equals(id) && type.isInstance(holder)) return type.cast(holder); } return null; @@ -523,7 +522,7 @@ public abstract class BaseStatusListFragment exten ArrayList holders=new ArrayList<>(); for(int i=0;i) holder).getItemID().equals(id) && type.isInstance(holder)) + if(holder instanceof StatusDisplayItem.Holder itemHolder && itemHolder.getItemID().equals(id) && type.isInstance(holder)) holders.add(type.cast(holder)); } return holders; @@ -642,8 +641,7 @@ public abstract class BaseStatusListFragment exten for(int i=0;i imgHolder=(ImageStatusDisplayItem.Holder) holder; + if(holder instanceof ImageStatusDisplayItem.Holder imgHolder){ if(!imgHolder.getItem().status.spoilerRevealed && TextUtils.isEmpty(imgHolder.getItem().status.spoilerText)){ hiddenMediaPaint.setColor(0x80000000); PhotoLayoutHelper.TiledLayoutResult.Tile tile=imgHolder.getItem().thisTile; @@ -656,8 +654,7 @@ public abstract class BaseStatusListFragment exten for(int i=0;i imgHolder=(ImageStatusDisplayItem.Holder) holder; + if(holder instanceof ImageStatusDisplayItem.Holder imgHolder){ if(!imgHolder.getItem().status.spoilerRevealed){ PhotoLayoutHelper.TiledLayoutResult.Tile tile=imgHolder.getItem().thisTile; if(tile.startCol==0 && tile.startRow==0 && TextUtils.isEmpty(imgHolder.getItem().status.spoilerText)){ @@ -729,6 +726,7 @@ public abstract class BaseStatusListFragment exten } private void rebuildMediaHiddenLayouts(int width){ + currentMediaHiddenLayoutsWidth=width; String title=getString(R.string.sensitive_content); TextPaint titlePaint=new TextPaint(Paint.ANTI_ALIAS_FLAG); titlePaint.setColor(getResources().getColor(R.color.gray_50)); diff --git a/mastodon/src/main/java/org/joinmastodon/android/fragments/HomeFragment.java b/mastodon/src/main/java/org/joinmastodon/android/fragments/HomeFragment.java index c91b9795..3b2685ee 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/fragments/HomeFragment.java +++ b/mastodon/src/main/java/org/joinmastodon/android/fragments/HomeFragment.java @@ -212,8 +212,8 @@ public class HomeFragment extends AppKitFragment implements OnBackPressedListene private void onTabSelected(@IdRes int tab){ Fragment newFragment=fragmentForTab(tab); if(tab==currentTab){ - if(newFragment instanceof ScrollableToTop) - ((ScrollableToTop) newFragment).scrollToTop(); + if(newFragment instanceof ScrollableToTop scrollable) + scrollable.scrollToTop(); return; } getChildFragmentManager().beginTransaction().hide(fragmentForTab(currentTab)).show(newFragment).commit(); @@ -223,8 +223,7 @@ public class HomeFragment extends AppKitFragment implements OnBackPressedListene } private void maybeTriggerLoading(Fragment newFragment){ - if(newFragment instanceof LoaderFragment){ - LoaderFragment lf=(LoaderFragment) newFragment; + if(newFragment instanceof LoaderFragment lf){ if(!lf.loaded && !lf.dataLoading) lf.loadData(); }else if(newFragment instanceof DiscoverFragment){ diff --git a/mastodon/src/main/java/org/joinmastodon/android/fragments/NotificationsFragment.java b/mastodon/src/main/java/org/joinmastodon/android/fragments/NotificationsFragment.java index 1c84276c..77f1e59d 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/fragments/NotificationsFragment.java +++ b/mastodon/src/main/java/org/joinmastodon/android/fragments/NotificationsFragment.java @@ -81,8 +81,7 @@ public class NotificationsFragment extends ToolbarFragment implements Scrollable if(position==0) return; Fragment _page=getFragmentForPage(position); - if(_page instanceof BaseRecyclerFragment){ - BaseRecyclerFragment page=(BaseRecyclerFragment) _page; + if(_page instanceof BaseRecyclerFragment page){ if(!page.loaded && !page.isDataLoading()) page.loadData(); } diff --git a/mastodon/src/main/java/org/joinmastodon/android/fragments/NotificationsListFragment.java b/mastodon/src/main/java/org/joinmastodon/android/fragments/NotificationsListFragment.java index d744d063..8fcc9dc7 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/fragments/NotificationsListFragment.java +++ b/mastodon/src/main/java/org/joinmastodon/android/fragments/NotificationsListFragment.java @@ -76,8 +76,8 @@ public class NotificationsListFragment extends BaseStatusListFragment items=StatusDisplayItem.buildItems(this, n.status, accountID, n, knownAccounts, titleItem!=null, titleItem==null); if(titleItem!=null){ for(StatusDisplayItem item:items){ - if(item instanceof ImageStatusDisplayItem){ - ((ImageStatusDisplayItem) item).horizontalInset=V.dp(32); + if(item instanceof ImageStatusDisplayItem imgItem){ + imgItem.horizontalInset=V.dp(32); } } } @@ -126,8 +126,8 @@ public class NotificationsListFragment extends BaseStatusListFragment) holder).getItem().inset; + boolean inset=(holder instanceof StatusDisplayItem.Holder sdi) && sdi.getItem().inset; if(inset){ if(rect.isEmpty()){ rect.set(child.getX(), i==0 && pos>0 && displayItems.get(pos-1).inset ? V.dp(-10) : child.getY(), child.getX()+child.getWidth(), child.getY()+child.getHeight()); @@ -210,8 +210,8 @@ public class NotificationsListFragment extends BaseStatusListFragment) holder).getItem().inset; + if(holder instanceof StatusDisplayItem.Holder sdi){ + boolean inset=sdi.getItem().inset; int pos=holder.getAbsoluteAdapterPosition(); if(inset){ boolean topSiblingInset=pos>0 && displayItems.get(pos-1).inset; @@ -222,9 +222,9 @@ public class NotificationsListFragment extends BaseStatusListFragment) holder).getItem().tiledLayout; - PhotoLayoutHelper.TiledLayoutResult.Tile tile=((ImageStatusDisplayItem.Holder) holder).getItem().thisTile; + if(holder instanceof ImageStatusDisplayItem.Holder img){ + PhotoLayoutHelper.TiledLayoutResult layout=img.getItem().tiledLayout; + PhotoLayoutHelper.TiledLayoutResult.Tile tile=img.getItem().thisTile; // only inset those items that are on the edges of the layout insetLeft=tile.startCol==0; insetRight=tile.startCol+tile.colSpan==layout.columnSizes.length; diff --git a/mastodon/src/main/java/org/joinmastodon/android/fragments/ProfileAboutFragment.java b/mastodon/src/main/java/org/joinmastodon/android/fragments/ProfileAboutFragment.java index e9538f58..eaf12c9f 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/fragments/ProfileAboutFragment.java +++ b/mastodon/src/main/java/org/joinmastodon/android/fragments/ProfileAboutFragment.java @@ -1,9 +1,7 @@ package org.joinmastodon.android.fragments; import android.app.Fragment; -import android.content.Context; import android.graphics.Canvas; -import android.graphics.Outline; import android.graphics.Paint; import android.graphics.drawable.Drawable; import android.graphics.drawable.ShapeDrawable; @@ -13,8 +11,6 @@ import android.os.Bundle; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; -import android.view.ViewOutlineProvider; -import android.view.ViewTreeObserver; import android.view.WindowInsets; import android.widget.EditText; import android.widget.TextView; @@ -22,7 +18,6 @@ import android.widget.TextView; import org.joinmastodon.android.R; import org.joinmastodon.android.model.AccountField; import org.joinmastodon.android.ui.BetterItemAnimator; -import org.joinmastodon.android.ui.OutlineProviders; import org.joinmastodon.android.ui.text.CustomEmojiSpan; import org.joinmastodon.android.ui.utils.SimpleTextWatcher; import org.joinmastodon.android.ui.utils.UiUtils; diff --git a/mastodon/src/main/java/org/joinmastodon/android/fragments/ProfileFragment.java b/mastodon/src/main/java/org/joinmastodon/android/fragments/ProfileFragment.java index d36fe722..447088f5 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/fragments/ProfileFragment.java +++ b/mastodon/src/main/java/org/joinmastodon/android/fragments/ProfileFragment.java @@ -330,8 +330,7 @@ public class ProfileFragment extends LoaderFragment implements OnBackPressedList if(position==0) return; Fragment _page=getFragmentForPage(position); - if(_page instanceof BaseRecyclerFragment){ - BaseRecyclerFragment page=(BaseRecyclerFragment) _page; + if(_page instanceof BaseRecyclerFragment page){ if(!page.loaded && !page.isDataLoading()) page.loadData(); } diff --git a/mastodon/src/main/java/org/joinmastodon/android/fragments/SettingsFragment.java b/mastodon/src/main/java/org/joinmastodon/android/fragments/SettingsFragment.java index 0af61c2b..3a5db031 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/fragments/SettingsFragment.java +++ b/mastodon/src/main/java/org/joinmastodon/android/fragments/SettingsFragment.java @@ -2,9 +2,7 @@ package org.joinmastodon.android.fragments; import android.annotation.SuppressLint; import android.app.Activity; -import android.app.AlertDialog; import android.content.Intent; -import android.content.res.Configuration; import android.graphics.Bitmap; import android.graphics.Canvas; import android.graphics.Rect; @@ -240,8 +238,7 @@ public class SettingsFragment extends ToolbarFragment{ } if((prevPolicy==PushSubscription.Policy.NONE)!=(policy==PushSubscription.Policy.NONE)){ index++; - while(items.get(index) instanceof SwitchItem){ - SwitchItem si=(SwitchItem) items.get(index); + while(items.get(index) instanceof SwitchItem si){ si.enabled=si.checked=policy!=PushSubscription.Policy.NONE; RecyclerView.ViewHolder holder=list.findViewHolderForAdapterPosition(index); if(holder!=null) diff --git a/mastodon/src/main/java/org/joinmastodon/android/fragments/StatusListFragment.java b/mastodon/src/main/java/org/joinmastodon/android/fragments/StatusListFragment.java index f56b5c55..a1cf45c3 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/fragments/StatusListFragment.java +++ b/mastodon/src/main/java/org/joinmastodon/android/fragments/StatusListFragment.java @@ -9,7 +9,6 @@ import org.joinmastodon.android.events.PollUpdatedEvent; import org.joinmastodon.android.events.StatusCountersUpdatedEvent; import org.joinmastodon.android.events.StatusCreatedEvent; import org.joinmastodon.android.events.StatusDeletedEvent; -import org.joinmastodon.android.model.Poll; import org.joinmastodon.android.model.Status; import org.joinmastodon.android.ui.displayitems.FooterStatusDisplayItem; import org.joinmastodon.android.ui.displayitems.HeaderStatusDisplayItem; @@ -89,8 +88,8 @@ public abstract class StatusListFragment extends BaseStatusListFragment{ s.update(ev); for(int i=0;i items=super.buildDisplayItems(s); if(s==mainStatus){ for(StatusDisplayItem item:items){ - if(item instanceof TextStatusDisplayItem) - ((TextStatusDisplayItem) item).textSelectable=true; + if(item instanceof TextStatusDisplayItem text) + text.textSelectable=true; } } return items; diff --git a/mastodon/src/main/java/org/joinmastodon/android/fragments/discover/DiscoverAccountsFragment.java b/mastodon/src/main/java/org/joinmastodon/android/fragments/discover/DiscoverAccountsFragment.java index 05970bd0..9216cf54 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/fragments/discover/DiscoverAccountsFragment.java +++ b/mastodon/src/main/java/org/joinmastodon/android/fragments/discover/DiscoverAccountsFragment.java @@ -111,8 +111,8 @@ public class DiscoverAccountsFragment extends BaseRecyclerFragment page){ if(!page.loaded && !page.isDataLoading()) page.loadData(); } diff --git a/mastodon/src/main/java/org/joinmastodon/android/fragments/discover/SearchFragment.java b/mastodon/src/main/java/org/joinmastodon/android/fragments/discover/SearchFragment.java index ef68ef53..c7a1f0ab 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/fragments/discover/SearchFragment.java +++ b/mastodon/src/main/java/org/joinmastodon/android/fragments/discover/SearchFragment.java @@ -5,7 +5,6 @@ import android.os.Build; import android.os.Bundle; import android.text.TextUtils; import android.view.View; -import android.view.ViewTreeObserver; import android.view.inputmethod.InputMethodManager; import org.joinmastodon.android.R; @@ -13,7 +12,6 @@ import org.joinmastodon.android.api.requests.search.GetSearchResults; import org.joinmastodon.android.api.session.AccountSessionManager; import org.joinmastodon.android.fragments.BaseStatusListFragment; import org.joinmastodon.android.fragments.ProfileFragment; -import org.joinmastodon.android.fragments.StatusListFragment; import org.joinmastodon.android.fragments.ThreadFragment; import org.joinmastodon.android.model.Account; import org.joinmastodon.android.model.Hashtag; diff --git a/mastodon/src/main/java/org/joinmastodon/android/fragments/discover/TrendingHashtagsFragment.java b/mastodon/src/main/java/org/joinmastodon/android/fragments/discover/TrendingHashtagsFragment.java index 453ee5a5..6408e1e1 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/fragments/discover/TrendingHashtagsFragment.java +++ b/mastodon/src/main/java/org/joinmastodon/android/fragments/discover/TrendingHashtagsFragment.java @@ -1,7 +1,5 @@ package org.joinmastodon.android.fragments.discover; -import android.graphics.Canvas; -import android.graphics.Paint; import android.os.Bundle; import android.view.View; import android.view.ViewGroup; @@ -22,7 +20,6 @@ import androidx.recyclerview.widget.RecyclerView; import me.grishka.appkit.api.SimpleCallback; import me.grishka.appkit.fragments.BaseRecyclerFragment; import me.grishka.appkit.utils.BindableViewHolder; -import me.grishka.appkit.utils.V; import me.grishka.appkit.views.UsableRecyclerView; public class TrendingHashtagsFragment extends BaseRecyclerFragment implements ScrollableToTop{ diff --git a/mastodon/src/main/java/org/joinmastodon/android/fragments/onboarding/InstanceCatalogFragment.java b/mastodon/src/main/java/org/joinmastodon/android/fragments/onboarding/InstanceCatalogFragment.java index 729cbe94..cc2a4b6b 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/fragments/onboarding/InstanceCatalogFragment.java +++ b/mastodon/src/main/java/org/joinmastodon/android/fragments/onboarding/InstanceCatalogFragment.java @@ -545,8 +545,8 @@ public class InstanceCatalogFragment extends BaseRecyclerFragment> fieldErrors=((MastodonDetailedErrorResponse) error).detailedErrors; + if(error instanceof MastodonDetailedErrorResponse derr){ + Map> fieldErrors=derr.detailedErrors; boolean first=true; boolean anyFieldsSkipped=false; for(String fieldName:fieldErrors.keySet()){ diff --git a/mastodon/src/main/java/org/joinmastodon/android/fragments/report/BaseReportChoiceFragment.java b/mastodon/src/main/java/org/joinmastodon/android/fragments/report/BaseReportChoiceFragment.java index f2b8e33c..ff2f8b2b 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/fragments/report/BaseReportChoiceFragment.java +++ b/mastodon/src/main/java/org/joinmastodon/android/fragments/report/BaseReportChoiceFragment.java @@ -179,8 +179,8 @@ public abstract class BaseReportChoiceFragment extends ToolbarFragment{ String prev=selectedIDs.remove(0); for(int i=0;i imgHolder=(ImageStatusDisplayItem.Holder) holder; + if(holder instanceof ImageStatusDisplayItem.Holder imgHolder){ PhotoLayoutHelper.TiledLayoutResult layout=imgHolder.getItem().tiledLayout; PhotoLayoutHelper.TiledLayoutResult.Tile tile=imgHolder.getItem().thisTile; String siblingID; @@ -154,12 +152,11 @@ public class ReportAddPostsChoiceFragment extends StatusListFragment{ for(int i=0;i) holder).getItemID(); + String id=sdiHolder.getItemID(); int height=tmpRect.height(); - if(holder instanceof ImageStatusDisplayItem.Holder){ - ImageStatusDisplayItem.Holder imgHolder=(ImageStatusDisplayItem.Holder) holder; + if(holder instanceof ImageStatusDisplayItem.Holder imgHolder){ if(imgHolder.getItem().thisTile.startCol+imgHolder.getItem().thisTile.colSpan) holder).getItemID(); + if(holder instanceof StatusDisplayItem.Holder sdiHolder){ + String postID=sdiHolder.getItemID(); if(!postID.equals(lastPostID)){ lastPostID=postID; if(!postsWithKnownNonHeaderHeights.contains(postID)) @@ -233,8 +230,8 @@ public class ReportAddPostsChoiceFragment extends StatusListFragment{ protected List buildDisplayItems(Status s){ List items=StatusDisplayItem.buildItems(this, s, accountID, s, knownAccounts, true, false); for(StatusDisplayItem item:items){ - if(item instanceof ImageStatusDisplayItem){ - ((ImageStatusDisplayItem) item).horizontalInset=V.dp(40+32); + if(item instanceof ImageStatusDisplayItem isdi){ + isdi.horizontalInset=V.dp(40+32); } } return items; diff --git a/mastodon/src/main/java/org/joinmastodon/android/model/Instance.java b/mastodon/src/main/java/org/joinmastodon/android/model/Instance.java index 587ce94b..56a96d33 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/model/Instance.java +++ b/mastodon/src/main/java/org/joinmastodon/android/model/Instance.java @@ -32,7 +32,7 @@ public class Instance extends BaseModel{ /** * A shorter description defined by the admin. */ - @RequiredField +// @RequiredField public String shortDescription; /** * An email that may be contacted for any inquiries. @@ -89,6 +89,8 @@ public class Instance extends BaseModel{ contactAccount.postprocess(); if(rules==null) rules=Collections.emptyList(); + if(shortDescription==null) + shortDescription=""; } @Override diff --git a/mastodon/src/main/java/org/joinmastodon/android/ui/photoviewer/PhotoViewer.java b/mastodon/src/main/java/org/joinmastodon/android/ui/photoviewer/PhotoViewer.java index 3f4a118b..ec7a1afc 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/ui/photoviewer/PhotoViewer.java +++ b/mastodon/src/main/java/org/joinmastodon/android/ui/photoviewer/PhotoViewer.java @@ -277,16 +277,16 @@ public class PhotoViewer implements ZoomPanView.Listener{ @Override public void onViewDetachedFromWindow(@NonNull BaseHolder holder){ super.onViewDetachedFromWindow(holder); - if(holder instanceof GifVViewHolder){ - ((GifVViewHolder) holder).reset(); + if(holder instanceof GifVViewHolder gifHolder){ + gifHolder.reset(); } } @Override public void onViewAttachedToWindow(@NonNull BaseHolder holder){ super.onViewAttachedToWindow(holder); - if(holder instanceof GifVViewHolder){ - ((GifVViewHolder) holder).prepareAndStartPlayer(); + if(holder instanceof GifVViewHolder gifHolder){ + gifHolder.prepareAndStartPlayer(); } } } diff --git a/mastodon/src/main/java/org/joinmastodon/android/ui/photoviewer/ZoomPanView.java b/mastodon/src/main/java/org/joinmastodon/android/ui/photoviewer/ZoomPanView.java index 193393cd..aa210785 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/ui/photoviewer/ZoomPanView.java +++ b/mastodon/src/main/java/org/joinmastodon/android/ui/photoviewer/ZoomPanView.java @@ -1,11 +1,9 @@ package org.joinmastodon.android.ui.photoviewer; -import android.animation.ValueAnimator; import android.annotation.SuppressLint; import android.content.Context; import android.graphics.Canvas; import android.graphics.Matrix; -import android.graphics.Paint; import android.graphics.Rect; import android.graphics.RectF; import android.util.AttributeSet;