fedilab-Android-App/app/src/main/java/app/fedilab/android/mastodon/ui/pageadapter/FedilabProfilePageAdapter.java

100 lines
4.2 KiB
Java
Raw Normal View History

2023-01-22 15:22:59 +01:00
package app.fedilab.android.mastodon.ui.pageadapter;
2022-04-27 15:20:42 +02:00
/* Copyright 2022 Thomas Schneider
*
* This file is a part of Fedilab
*
* This program is free software; you can redistribute it and/or modify it under the terms of the
* GNU General Public License as published by the Free Software Foundation; either version 3 of the
* License, or (at your option) any later version.
*
* Fedilab is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
* the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
* Public License for more details.
*
* You should have received a copy of the GNU General Public License along with Fedilab; if not,
* see <http://www.gnu.org/licenses>. */
import android.os.Bundle;
2022-07-09 15:30:39 +02:00
import android.view.ViewGroup;
2022-04-27 15:20:42 +02:00
import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment;
2022-07-09 15:30:39 +02:00
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentStatePagerAdapter;
2022-04-27 15:20:42 +02:00
2023-01-22 15:22:59 +01:00
import app.fedilab.android.mastodon.client.entities.api.Account;
import app.fedilab.android.mastodon.client.entities.app.Timeline;
import app.fedilab.android.mastodon.helper.Helper;
import app.fedilab.android.mastodon.ui.fragment.media.FragmentMediaProfile;
import app.fedilab.android.mastodon.ui.fragment.timeline.FragmentMastodonTimeline;
2022-04-27 15:20:42 +02:00
2022-07-09 15:30:39 +02:00
public class FedilabProfilePageAdapter extends FragmentStatePagerAdapter {
2022-04-27 15:20:42 +02:00
private final Account account;
private final boolean checkRemotely;
2023-01-01 11:55:32 +01:00
private Fragment mCurrentFragment;
2022-04-27 15:20:42 +02:00
public FedilabProfilePageAdapter(FragmentManager fm, Account account, boolean remotely) {
2022-07-09 15:30:39 +02:00
super(fm, BEHAVIOR_RESUME_ONLY_CURRENT_FRAGMENT);
2022-04-27 15:20:42 +02:00
this.account = account;
this.checkRemotely = remotely;
2022-04-27 15:20:42 +02:00
}
2022-07-09 15:30:39 +02:00
public Fragment getCurrentFragment() {
return mCurrentFragment;
}
2022-04-27 15:20:42 +02:00
@Override
2022-07-09 15:30:39 +02:00
public void setPrimaryItem(@NonNull ViewGroup container, int position, @NonNull Object object) {
if (getCurrentFragment() != object) {
mCurrentFragment = ((Fragment) object);
}
super.setPrimaryItem(container, position, object);
2022-04-27 15:20:42 +02:00
}
@NonNull
@Override
2022-07-09 15:30:39 +02:00
public Fragment getItem(int position) {
2022-04-27 15:20:42 +02:00
Bundle bundle = new Bundle();
bundle.putString(Helper.ARG_VIEW_MODEL_KEY, "FEDILAB_" + position);
2024-01-11 10:58:22 +01:00
FragmentMastodonTimeline fragmentMastodonTimeline;
2022-04-27 15:20:42 +02:00
switch (position) {
case 0 -> {
2024-01-11 10:58:22 +01:00
fragmentMastodonTimeline = new FragmentMastodonTimeline();
2022-04-27 15:20:42 +02:00
bundle.putSerializable(Helper.ARG_TIMELINE_TYPE, Timeline.TimeLineEnum.ACCOUNT_TIMELINE);
bundle.putSerializable(Helper.ARG_CACHED_ACCOUNT_ID, account.id);
2022-04-27 15:20:42 +02:00
bundle.putBoolean(Helper.ARG_SHOW_PINNED, true);
2022-04-29 17:12:03 +02:00
bundle.putBoolean(Helper.ARG_SHOW_REPLIES, false);
bundle.putBoolean(Helper.ARG_SHOW_REBLOGS, true);
bundle.putBoolean(Helper.ARG_CHECK_REMOTELY, checkRemotely);
2024-01-11 10:58:22 +01:00
fragmentMastodonTimeline.setArguments(bundle);
return fragmentMastodonTimeline;
}
case 1 -> {
2024-01-11 10:58:22 +01:00
fragmentMastodonTimeline = new FragmentMastodonTimeline();
2022-04-27 15:20:42 +02:00
bundle.putSerializable(Helper.ARG_TIMELINE_TYPE, Timeline.TimeLineEnum.ACCOUNT_TIMELINE);
bundle.putSerializable(Helper.ARG_CACHED_ACCOUNT_ID, account.id);
2022-04-29 17:12:03 +02:00
bundle.putBoolean(Helper.ARG_SHOW_PINNED, false);
2022-04-27 15:20:42 +02:00
bundle.putBoolean(Helper.ARG_SHOW_REPLIES, true);
2022-04-29 17:12:03 +02:00
bundle.putBoolean(Helper.ARG_SHOW_REBLOGS, false);
bundle.putBoolean(Helper.ARG_CHECK_REMOTELY, checkRemotely);
2024-01-11 10:58:22 +01:00
fragmentMastodonTimeline.setArguments(bundle);
return fragmentMastodonTimeline;
}
case 2 -> {
2022-09-09 17:24:57 +02:00
FragmentMediaProfile fragmentMediaProfile = new FragmentMediaProfile();
bundle.putSerializable(Helper.ARG_CACHED_ACCOUNT_ID, account.id);
bundle.putBoolean(Helper.ARG_CHECK_REMOTELY, checkRemotely);
2022-09-09 17:24:57 +02:00
fragmentMediaProfile.setArguments(bundle);
return fragmentMediaProfile;
}
default -> {
2022-04-27 15:20:42 +02:00
return new FragmentMastodonTimeline();
}
2022-04-27 15:20:42 +02:00
}
}
2022-07-09 15:30:39 +02:00
@Override
public int getCount() {
return 3;
}
}