Some cleaning

This commit is contained in:
Thomas 2023-01-12 14:55:53 +01:00
parent d5a5f08727
commit 1ef01af199
3 changed files with 67 additions and 70 deletions

View File

@ -32,7 +32,6 @@ public class DirectoryActivity extends BaseBarActivity {
private static boolean local = false;
private static String order = "active";
private FragmentMastodonAccount fragmentMastodonAccount;
@Override
protected void onCreate(Bundle savedInstanceState) {
@ -43,12 +42,11 @@ public class DirectoryActivity extends BaseBarActivity {
if (getSupportActionBar() != null) {
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
}
fragmentMastodonAccount = new FragmentMastodonAccount();
Bundle bundle = new Bundle();
bundle.putBoolean(Helper.ARG_DIRECTORY_LOCAL, local);
bundle.putString(Helper.ARG_DIRECTORY_ORDER, order);
bundle.putSerializable(Helper.ARG_TIMELINE_TYPE, ACCOUNT_DIRECTORY);
Helper.addFragment(getSupportFragmentManager(), R.id.nav_host_fragment_directory, fragmentMastodonAccount, bundle, null, null);
Helper.addFragment(getSupportFragmentManager(), R.id.nav_host_fragment_directory, new FragmentMastodonAccount(), bundle, null, null);
}
@Override

View File

@ -163,6 +163,8 @@ public class StatusAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
public static final int STATUS_FILTERED = 3;
public static final int STATUS_FILTERED_HIDE = 4;
public static final int STATUS_PIXELFED = 5;
private static float measuredWidth = -1;
private static float measuredWidthArt = -1;
private final List<Status> statusList;
private final boolean minified;
private final Timeline.TimeLineEnum timelineType;
@ -171,10 +173,7 @@ public class StatusAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
public FetchMoreCallBack fetchMoreCallBack;
private Context context;
private boolean visiblePixelfed;
private RecyclerView mRecyclerView;
private static float measuredWidth = -1;
private static float measuredWidthArt = -1;
public StatusAdapter(List<Status> statuses, Timeline.TimeLineEnum timelineType, boolean minified, boolean canBeFederated, boolean checkRemotely) {
this.statusList = statuses;
@ -2246,53 +2245,6 @@ public class StatusAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
}
@NonNull
@Override
public List<Attachment> getPreloadItems(int position) {
List<Attachment> attachments = new ArrayList<>();
if (position == 0 && statusList.size() > 0) {
for (Status status : statusList.subList(0, 1)) {
Status statusToDeal = status.reblog != null ? status.reblog : status;
if (statusToDeal.media_attachments != null && statusToDeal.media_attachments.size() > 0) {
attachments.addAll(statusToDeal.media_attachments);
}
}
} else if (position > 0 && position < (statusList.size() - 1)) {
for (Status status : statusList.subList(position - 1, position + 1)) {
Status statusToDeal = status.reblog != null ? status.reblog : status;
if (statusToDeal.media_attachments != null && statusToDeal.media_attachments.size() > 0) {
attachments.addAll(statusToDeal.media_attachments);
}
}
} else {
for (Status status : statusList.subList(position, position)) {
Status statusToDeal = status.reblog != null ? status.reblog : status;
if (statusToDeal.media_attachments != null && statusToDeal.media_attachments.size() > 0) {
attachments.addAll(statusToDeal.media_attachments);
}
}
}
return attachments;
}
@Nullable
@Override
public RequestBuilder<Drawable> getPreloadRequestBuilder(@NonNull Attachment attachment) {
float focusX = 0.f;
float focusY = 0.f;
if (attachment.meta != null && attachment.meta.focus != null) {
focusX = attachment.meta.focus.x;
focusY = attachment.meta.focus.y;
}
int mediaH = 0;
int mediaW = 0;
if (attachment.meta != null && attachment.meta.small != null) {
mediaH = attachment.meta.small.height;
mediaW = attachment.meta.small.width;
}
return prepareRequestBuilder(context, attachment, mediaW, mediaH, focusX, focusY, attachment.sensitive, timelineType == Timeline.TimeLineEnum.ART).load(attachment);
}
/**
* Send a broadcast to other open fragments that content a timeline
*
@ -2317,21 +2269,6 @@ public class StatusAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
LocalBroadcastManager.getInstance(context).sendBroadcast(intentBC);
}
/* private static boolean mediaObfuscated(Status status) {
//Media is not sensitive and doesn't have a spoiler text
if (!status.isMediaObfuscated) {
return false;
}
if (!status.sensitive && (status.spoiler_text == null || status.spoiler_text.trim().isEmpty())) {
return false;
}
if (status.isMediaObfuscated && status.spoiler_text != null && !status.spoiler_text.trim().isEmpty()) {
return true;
} else {
return status.sensitive;
}
}*/
public static void applyColor(Context context, StatusViewHolder holder) {
SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(context);
int currentNightMode = context.getResources().getConfiguration().uiMode & Configuration.UI_MODE_NIGHT_MASK;
@ -2418,6 +2355,68 @@ public class StatusAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
}
}
@NonNull
@Override
public List<Attachment> getPreloadItems(int position) {
List<Attachment> attachments = new ArrayList<>();
if (position == 0 && statusList.size() > 0) {
for (Status status : statusList.subList(0, 1)) {
Status statusToDeal = status.reblog != null ? status.reblog : status;
if (statusToDeal.media_attachments != null && statusToDeal.media_attachments.size() > 0) {
attachments.addAll(statusToDeal.media_attachments);
}
}
} else if (position > 0 && position < (statusList.size() - 1)) {
for (Status status : statusList.subList(position - 1, position + 1)) {
Status statusToDeal = status.reblog != null ? status.reblog : status;
if (statusToDeal.media_attachments != null && statusToDeal.media_attachments.size() > 0) {
attachments.addAll(statusToDeal.media_attachments);
}
}
} else {
for (Status status : statusList.subList(position, position)) {
Status statusToDeal = status.reblog != null ? status.reblog : status;
if (statusToDeal.media_attachments != null && statusToDeal.media_attachments.size() > 0) {
attachments.addAll(statusToDeal.media_attachments);
}
}
}
return attachments;
}
/* private static boolean mediaObfuscated(Status status) {
//Media is not sensitive and doesn't have a spoiler text
if (!status.isMediaObfuscated) {
return false;
}
if (!status.sensitive && (status.spoiler_text == null || status.spoiler_text.trim().isEmpty())) {
return false;
}
if (status.isMediaObfuscated && status.spoiler_text != null && !status.spoiler_text.trim().isEmpty()) {
return true;
} else {
return status.sensitive;
}
}*/
@Nullable
@Override
public RequestBuilder<Drawable> getPreloadRequestBuilder(@NonNull Attachment attachment) {
float focusX = 0.f;
float focusY = 0.f;
if (attachment.meta != null && attachment.meta.focus != null) {
focusX = attachment.meta.focus.x;
focusY = attachment.meta.focus.y;
}
int mediaH = 0;
int mediaW = 0;
if (attachment.meta != null && attachment.meta.small != null) {
mediaH = attachment.meta.small.height;
mediaW = attachment.meta.small.width;
}
return prepareRequestBuilder(context, attachment, mediaW, mediaH, focusX, focusY, attachment.sensitive, timelineType == Timeline.TimeLineEnum.ART).load(attachment);
}
@Override
public void onAttachedToRecyclerView(RecyclerView recyclerView) {
super.onAttachedToRecyclerView(recyclerView);

View File

@ -76,6 +76,7 @@ import es.dmoral.toasty.Toasty;
public class FragmentMastodonTimeline extends Fragment implements StatusAdapter.FetchMoreCallBack {
private static final int PRELOAD_AHEAD_ITEMS = 10;
public UpdateCounters update;
private FragmentPaginationBinding binding;
private TimelinesVM timelinesVM;
@ -88,8 +89,6 @@ public class FragmentMastodonTimeline extends Fragment implements StatusAdapter.
private StatusAdapter statusAdapter;
private Timeline.TimeLineEnum timelineType;
private List<Status> timelineStatuses;
private static final int PRELOAD_AHEAD_ITEMS = 10;
private ViewPreloadSizeProvider<Attachment> preloadSizeProvider;
//Handle actions that can be done in other fragments
private final BroadcastReceiver receive_action = new BroadcastReceiver() {
@Override
@ -179,6 +178,7 @@ public class FragmentMastodonTimeline extends Fragment implements StatusAdapter.
}
}
};
private ViewPreloadSizeProvider<Attachment> preloadSizeProvider;
private boolean checkRemotely;
private String accountIDInRemoteInstance;
private boolean isViewInitialized;