forked from mirrors/Fedilab
ViewPager2 - end
This commit is contained in:
parent
91c0f0de75
commit
5ddc756440
18 changed files with 101 additions and 175 deletions
|
@ -21,7 +21,6 @@ import android.content.ContentResolver;
|
|||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
import android.content.SharedPreferences;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.graphics.Point;
|
||||
import android.graphics.drawable.ColorDrawable;
|
||||
|
@ -34,20 +33,15 @@ import android.view.Menu;
|
|||
import android.view.MenuItem;
|
||||
import android.view.MotionEvent;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.view.Window;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.core.app.ActivityCompat;
|
||||
import androidx.core.content.ContextCompat;
|
||||
import androidx.fragment.app.Fragment;
|
||||
import androidx.fragment.app.FragmentManager;
|
||||
import androidx.fragment.app.FragmentStatePagerAdapter;
|
||||
import androidx.preference.PreferenceManager;
|
||||
import androidx.viewpager.widget.PagerAdapter;
|
||||
import androidx.viewpager.widget.ViewPager;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import androidx.fragment.app.FragmentActivity;
|
||||
import androidx.viewpager2.adapter.FragmentStateAdapter;
|
||||
import androidx.viewpager2.widget.ViewPager2;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
|
@ -99,7 +93,6 @@ public class MediaActivity extends BaseActivity implements OnDownloadInterface {
|
|||
private int minTouch, maxTouch;
|
||||
private float startX;
|
||||
private float startY;
|
||||
private FragmentMedia mCurrentFragment;
|
||||
private ActivityMediaPagerBinding binding;
|
||||
|
||||
@Override
|
||||
|
@ -113,8 +106,6 @@ public class MediaActivity extends BaseActivity implements OnDownloadInterface {
|
|||
|
||||
|
||||
fullscreen = false;
|
||||
SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(MediaActivity.this);
|
||||
final int med_desc_timeout = sharedpreferences.getInt(getString(R.string.SET_MED_DESC_TIMEOUT), 3) * 1000;
|
||||
flags = getWindow().getDecorView().getSystemUiVisibility();
|
||||
Bundle b = getIntent().getExtras();
|
||||
if (b != null) {
|
||||
|
@ -132,11 +123,10 @@ public class MediaActivity extends BaseActivity implements OnDownloadInterface {
|
|||
|
||||
setTitle("");
|
||||
|
||||
PagerAdapter mPagerAdapter = new ScreenSlidePagerAdapter(getSupportFragmentManager());
|
||||
ScreenSlidePagerAdapter mPagerAdapter = new ScreenSlidePagerAdapter(MediaActivity.this);
|
||||
binding.mediaViewpager.setAdapter(mPagerAdapter);
|
||||
|
||||
binding.mediaViewpager.setCurrentItem(mediaPosition - 1);
|
||||
binding.mediaViewpager.setOffscreenPageLimit(0);
|
||||
binding.haulerView.setOnDragDismissedListener(dragDirection -> ActivityCompat.finishAfterTransition(MediaActivity.this));
|
||||
registerReceiver(onDownloadComplete, new IntentFilter(DownloadManager.ACTION_DOWNLOAD_COMPLETE));
|
||||
String description = attachments.get(mediaPosition - 1).description;
|
||||
|
@ -145,14 +135,15 @@ public class MediaActivity extends BaseActivity implements OnDownloadInterface {
|
|||
binding.mediaDescription.setText(description);
|
||||
|
||||
}
|
||||
binding.mediaViewpager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
|
||||
public void onPageScrollStateChanged(int state) {
|
||||
}
|
||||
|
||||
binding.mediaViewpager.registerOnPageChangeCallback(new ViewPager2.OnPageChangeCallback() {
|
||||
@Override
|
||||
public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
|
||||
super.onPageScrolled(position, positionOffset, positionOffsetPixels);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPageSelected(int position) {
|
||||
super.onPageSelected(position);
|
||||
String description = attachments.get(position).description;
|
||||
if (handler != null) {
|
||||
handler.removeCallbacksAndMessages(null);
|
||||
|
@ -162,8 +153,12 @@ public class MediaActivity extends BaseActivity implements OnDownloadInterface {
|
|||
binding.mediaDescription.setText(description);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
@Override
|
||||
public void onPageScrollStateChanged(int state) {
|
||||
super.onPageScrollStateChanged(state);
|
||||
}
|
||||
});
|
||||
|
||||
setFullscreen(true);
|
||||
Display display = getWindowManager().getDefaultDisplay();
|
||||
|
@ -258,8 +253,6 @@ public class MediaActivity extends BaseActivity implements OnDownloadInterface {
|
|||
@Override
|
||||
public boolean dispatchTouchEvent(MotionEvent event) {
|
||||
|
||||
SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(MediaActivity.this);
|
||||
final int med_desc_timeout = sharedpreferences.getInt(getString(R.string.SET_MED_DESC_TIMEOUT), 3) * 1000;
|
||||
switch (event.getAction()) {
|
||||
case MotionEvent.ACTION_DOWN:
|
||||
startX = event.getX();
|
||||
|
@ -307,10 +300,6 @@ public class MediaActivity extends BaseActivity implements OnDownloadInterface {
|
|||
super.onDestroy();
|
||||
}
|
||||
|
||||
public FragmentMedia getCurrentFragment() {
|
||||
return mCurrentFragment;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDownloaded(String saveFilePath, String downloadUrl, Error error) {
|
||||
|
||||
|
@ -372,15 +361,15 @@ public class MediaActivity extends BaseActivity implements OnDownloadInterface {
|
|||
/**
|
||||
* Media Pager
|
||||
*/
|
||||
private class ScreenSlidePagerAdapter extends FragmentStatePagerAdapter {
|
||||
private class ScreenSlidePagerAdapter extends FragmentStateAdapter {
|
||||
|
||||
ScreenSlidePagerAdapter(FragmentManager fm) {
|
||||
super(fm, BEHAVIOR_RESUME_ONLY_CURRENT_FRAGMENT);
|
||||
ScreenSlidePagerAdapter(FragmentActivity fa) {
|
||||
super(fa);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@NonNull
|
||||
@Override
|
||||
public Fragment getItem(int position) {
|
||||
public Fragment createFragment(int position) {
|
||||
Bundle bundle = new Bundle();
|
||||
FragmentMedia mediaSliderFragment = new FragmentMedia();
|
||||
bundle.putInt(Helper.ARG_MEDIA_POSITION, position);
|
||||
|
@ -390,15 +379,7 @@ public class MediaActivity extends BaseActivity implements OnDownloadInterface {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void setPrimaryItem(@NotNull ViewGroup container, int position, @NotNull Object object) {
|
||||
if (getCurrentFragment() != object) {
|
||||
mCurrentFragment = ((FragmentMedia) object);
|
||||
}
|
||||
super.setPrimaryItem(container, position, object);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCount() {
|
||||
public int getItemCount() {
|
||||
return attachments.size();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -59,6 +59,7 @@ import androidx.localbroadcastmanager.content.LocalBroadcastManager;
|
|||
import androidx.preference.PreferenceManager;
|
||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
import androidx.viewpager2.widget.ViewPager2;
|
||||
|
||||
import com.bumptech.glide.Glide;
|
||||
import com.bumptech.glide.request.target.CustomTarget;
|
||||
|
@ -125,7 +126,7 @@ public class ProfileActivity extends BaseActivity {
|
|||
if (b != null) {
|
||||
Account accountReceived = (Account) b.getSerializable(Helper.ARG_ACCOUNT);
|
||||
if (b.getBoolean(Helper.RECEIVE_REDRAW_PROFILE, false) && accountReceived != null) {
|
||||
if (account != null && accountReceived.id.equalsIgnoreCase(account.id)) {
|
||||
if (account != null && accountReceived.id != null && account.id != null && accountReceived.id.equalsIgnoreCase(account.id)) {
|
||||
initializeView(accountReceived);
|
||||
}
|
||||
}
|
||||
|
@ -246,15 +247,20 @@ public class ProfileActivity extends BaseActivity {
|
|||
}
|
||||
binding.accountTabLayout.clearOnTabSelectedListeners();
|
||||
binding.accountTabLayout.removeAllTabs();
|
||||
binding.accountViewpager.clearOnPageChangeListeners();
|
||||
//Tablayout for timelines/following/followers
|
||||
FedilabProfileTLPageAdapter fedilabProfileTLPageAdapter = new FedilabProfileTLPageAdapter(getSupportFragmentManager(), account);
|
||||
FedilabProfileTLPageAdapter fedilabProfileTLPageAdapter = new FedilabProfileTLPageAdapter(ProfileActivity.this, account);
|
||||
binding.accountTabLayout.addTab(binding.accountTabLayout.newTab().setText(getString(R.string.status_cnt, Helper.withSuffix(account.statuses_count))));
|
||||
binding.accountTabLayout.addTab(binding.accountTabLayout.newTab().setText(getString(R.string.following_cnt, Helper.withSuffix(account.following_count))));
|
||||
binding.accountTabLayout.addTab(binding.accountTabLayout.newTab().setText(getString(R.string.followers_cnt, Helper.withSuffix(account.followers_count))));
|
||||
binding.accountViewpager.setAdapter(fedilabProfileTLPageAdapter);
|
||||
binding.accountViewpager.setOffscreenPageLimit(3);
|
||||
binding.accountViewpager.addOnPageChangeListener(new TabLayout.TabLayoutOnPageChangeListener(binding.accountTabLayout));
|
||||
binding.accountViewpager.registerOnPageChangeCallback(new ViewPager2.OnPageChangeCallback() {
|
||||
@Override
|
||||
public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
|
||||
super.onPageScrolled(position, positionOffset, positionOffsetPixels);
|
||||
binding.accountTabLayout.selectTab(binding.accountTabLayout.getTabAt(position));
|
||||
}
|
||||
});
|
||||
binding.accountTabLayout.addOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {
|
||||
@Override
|
||||
public void onTabSelected(TabLayout.Tab tab) {
|
||||
|
|
|
@ -60,10 +60,8 @@ public class ScheduledActivity extends BaseActivity {
|
|||
binding.scheduleTablayout.addTab(binding.scheduleTablayout.newTab().setText(getString(R.string.toots_client)));
|
||||
binding.scheduleTablayout.addTab(binding.scheduleTablayout.newTab().setText(getString(R.string.reblog)));
|
||||
|
||||
binding.scheduleViewpager.setAdapter(new FedilabScheduledPageAdapter(getSupportFragmentManager()));
|
||||
binding.scheduleViewpager.setAdapter(new FedilabScheduledPageAdapter(ScheduledActivity.this));
|
||||
binding.scheduleViewpager.setOffscreenPageLimit(3);
|
||||
binding.scheduleViewpager.addOnPageChangeListener(new TabLayout.TabLayoutOnPageChangeListener(binding.scheduleTablayout));
|
||||
|
||||
binding.scheduleTablayout.setTabTextColors(ThemeHelper.getAttColor(ScheduledActivity.this, R.attr.mTextColor), ContextCompat.getColor(ScheduledActivity.this, R.color.cyanea_accent_dark_reference));
|
||||
binding.scheduleTablayout.setTabIconTint(ThemeHelper.getColorStateList(ScheduledActivity.this));
|
||||
|
||||
|
|
|
@ -21,7 +21,6 @@ import android.os.Bundle;
|
|||
import android.view.Menu;
|
||||
import android.view.MenuInflater;
|
||||
import android.view.MenuItem;
|
||||
import android.view.ViewGroup;
|
||||
import android.view.inputmethod.InputMethodManager;
|
||||
import android.widget.Toast;
|
||||
|
||||
|
@ -29,10 +28,9 @@ import androidx.annotation.NonNull;
|
|||
import androidx.appcompat.widget.SearchView;
|
||||
import androidx.core.content.ContextCompat;
|
||||
import androidx.fragment.app.Fragment;
|
||||
import androidx.fragment.app.FragmentManager;
|
||||
import androidx.fragment.app.FragmentStatePagerAdapter;
|
||||
import androidx.viewpager.widget.PagerAdapter;
|
||||
import androidx.viewpager.widget.ViewPager;
|
||||
import androidx.fragment.app.FragmentActivity;
|
||||
import androidx.viewpager2.adapter.FragmentStateAdapter;
|
||||
import androidx.viewpager2.widget.ViewPager2;
|
||||
|
||||
import com.google.android.material.tabs.TabLayout;
|
||||
|
||||
|
@ -99,7 +97,7 @@ public class SearchResultTabActivity extends BaseActivity {
|
|||
public void onTabReselected(TabLayout.Tab tab) {
|
||||
Fragment fragment;
|
||||
if (binding.searchViewpager.getAdapter() != null) {
|
||||
fragment = (Fragment) binding.searchViewpager.getAdapter().instantiateItem(binding.searchViewpager, tab.getPosition());
|
||||
fragment = (Fragment) getSupportFragmentManager().findFragmentByTag("f" + binding.searchViewpager.getCurrentItem());
|
||||
if (fragment instanceof FragmentMastodonAccount) {
|
||||
FragmentMastodonAccount fragmentMastodonAccount = ((FragmentMastodonAccount) fragment);
|
||||
fragmentMastodonAccount.scrollToTop();
|
||||
|
@ -134,7 +132,7 @@ public class SearchResultTabActivity extends BaseActivity {
|
|||
imm.hideSoftInputFromWindow(binding.searchTabLayout.getWindowToken(), 0);
|
||||
query = query.replaceAll("^#+", "");
|
||||
search = query.trim();
|
||||
PagerAdapter mPagerAdapter = new ScreenSlidePagerAdapter(getSupportFragmentManager());
|
||||
ScreenSlidePagerAdapter mPagerAdapter = new ScreenSlidePagerAdapter(SearchResultTabActivity.this);
|
||||
binding.searchViewpager.setAdapter(mPagerAdapter);
|
||||
searchView.clearFocus();
|
||||
setTitle(search);
|
||||
|
@ -158,16 +156,19 @@ public class SearchResultTabActivity extends BaseActivity {
|
|||
});
|
||||
|
||||
|
||||
PagerAdapter mPagerAdapter = new ScreenSlidePagerAdapter(getSupportFragmentManager());
|
||||
ScreenSlidePagerAdapter mPagerAdapter = new ScreenSlidePagerAdapter(SearchResultTabActivity.this);
|
||||
binding.searchViewpager.setAdapter(mPagerAdapter);
|
||||
|
||||
binding.searchViewpager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
|
||||
binding.searchViewpager.registerOnPageChangeCallback(new ViewPager2.OnPageChangeCallback() {
|
||||
@Override
|
||||
public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
|
||||
super.onPageScrolled(position, positionOffset, positionOffsetPixels);
|
||||
binding.searchTabLayout.selectTab(binding.searchTabLayout.getTabAt(position));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPageSelected(int position) {
|
||||
super.onPageSelected(position);
|
||||
TabLayout.Tab tab = binding.searchTabLayout.getTabAt(position);
|
||||
if (tab != null)
|
||||
tab.select();
|
||||
|
@ -175,6 +176,7 @@ public class SearchResultTabActivity extends BaseActivity {
|
|||
|
||||
@Override
|
||||
public void onPageScrollStateChanged(int state) {
|
||||
super.onPageScrollStateChanged(state);
|
||||
}
|
||||
});
|
||||
return true;
|
||||
|
@ -196,15 +198,16 @@ public class SearchResultTabActivity extends BaseActivity {
|
|||
/**
|
||||
* Pager adapter for the 4 fragments
|
||||
*/
|
||||
private class ScreenSlidePagerAdapter extends FragmentStatePagerAdapter {
|
||||
private class ScreenSlidePagerAdapter extends FragmentStateAdapter {
|
||||
|
||||
ScreenSlidePagerAdapter(FragmentManager fm) {
|
||||
super(fm, BEHAVIOR_RESUME_ONLY_CURRENT_FRAGMENT);
|
||||
ScreenSlidePagerAdapter(FragmentActivity fa) {
|
||||
super(fa);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public Fragment getItem(int position) {
|
||||
public Fragment createFragment(int position) {
|
||||
Bundle bundle = new Bundle();
|
||||
switch (position) {
|
||||
case 0:
|
||||
|
@ -231,12 +234,7 @@ public class SearchResultTabActivity extends BaseActivity {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void destroyItem(@NonNull ViewGroup container, int position, @NonNull Object object) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCount() {
|
||||
public int getItemCount() {
|
||||
return 4;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -209,6 +209,7 @@ public class PinnedTimelineHelper {
|
|||
@Override
|
||||
public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
|
||||
super.onPageScrolled(position, positionOffset, positionOffsetPixels);
|
||||
activityMainBinding.tabLayout.selectTab(activityMainBinding.tabLayout.getTabAt(position));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -98,7 +98,7 @@ public class FragmentMastodonTimeline extends Fragment implements StatusAdapter.
|
|||
} else if (delete_statuses_for_user != null && statusAdapter != null) {
|
||||
List<Status> statusesToRemove = new ArrayList<>();
|
||||
for (Status status : statuses) {
|
||||
if (status.account.id.equals(delete_statuses_for_user)) {
|
||||
if (status != null && status.account != null && status.account.id != null && status.account.id.equals(delete_statuses_for_user)) {
|
||||
statusesToRemove.add(status);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -63,7 +63,7 @@ public class FragmentNotificationContainer extends Fragment {
|
|||
binding.tabLayout.addTab(binding.tabLayout.newTab().setText(getString(R.string.all)));
|
||||
binding.tabLayout.addTab(binding.tabLayout.newTab().setText(getString(R.string.mention)));
|
||||
binding.tabLayout.setTabMode(TabLayout.MODE_FIXED);
|
||||
binding.viewpager.setAdapter(new FedilabNotificationPageAdapter(getChildFragmentManager(), false));
|
||||
binding.viewpager.setAdapter(new FedilabNotificationPageAdapter(requireActivity(), false));
|
||||
} else {
|
||||
binding.tabLayout.setTabMode(TabLayout.MODE_SCROLLABLE);
|
||||
binding.tabLayout.addTab(binding.tabLayout.newTab().setText(getString(R.string.all)));
|
||||
|
@ -73,7 +73,7 @@ public class FragmentNotificationContainer extends Fragment {
|
|||
binding.tabLayout.addTab(binding.tabLayout.newTab().setIcon(R.drawable.ic_baseline_poll_24));
|
||||
binding.tabLayout.addTab(binding.tabLayout.newTab().setIcon(R.drawable.ic_baseline_home_24));
|
||||
binding.tabLayout.addTab(binding.tabLayout.newTab().setIcon(R.drawable.ic_baseline_person_add_alt_1_24));
|
||||
binding.viewpager.setAdapter(new FedilabNotificationPageAdapter(getChildFragmentManager(), true));
|
||||
binding.viewpager.setAdapter(new FedilabNotificationPageAdapter(requireActivity(), true));
|
||||
}
|
||||
AtomicBoolean changes = new AtomicBoolean(false);
|
||||
binding.settings.setOnClickListener(v -> {
|
||||
|
@ -214,7 +214,6 @@ public class FragmentNotificationContainer extends Fragment {
|
|||
|
||||
binding.tabLayout.setTabTextColors(ThemeHelper.getAttColor(requireActivity(), R.attr.mTextColor), ContextCompat.getColor(requireActivity(), R.color.cyanea_accent_dark_reference));
|
||||
binding.tabLayout.setTabIconTint(ThemeHelper.getColorStateList(requireActivity()));
|
||||
binding.viewpager.addOnPageChangeListener(new TabLayout.TabLayoutOnPageChangeListener(binding.tabLayout));
|
||||
binding.tabLayout.addOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {
|
||||
@Override
|
||||
public void onTabSelected(TabLayout.Tab tab) {
|
||||
|
@ -230,7 +229,7 @@ public class FragmentNotificationContainer extends Fragment {
|
|||
public void onTabReselected(TabLayout.Tab tab) {
|
||||
Fragment fragment;
|
||||
if (binding.viewpager.getAdapter() != null) {
|
||||
fragment = (Fragment) binding.viewpager.getAdapter().instantiateItem(binding.viewpager, tab.getPosition());
|
||||
fragment = (Fragment) requireActivity().getSupportFragmentManager().findFragmentByTag("f" + binding.viewpager.getCurrentItem());
|
||||
if (fragment instanceof FragmentMastodonNotification) {
|
||||
FragmentMastodonNotification fragmentMastodonNotification = ((FragmentMastodonNotification) fragment);
|
||||
fragmentMastodonNotification.scrollToTop();
|
||||
|
@ -245,15 +244,12 @@ public class FragmentNotificationContainer extends Fragment {
|
|||
|
||||
public void scrollToTop() {
|
||||
if (binding != null) {
|
||||
FedilabNotificationPageAdapter fedilabNotificationPageAdapter = ((FedilabNotificationPageAdapter) binding.viewpager.getAdapter());
|
||||
if (fedilabNotificationPageAdapter != null) {
|
||||
FragmentMastodonNotification fragmentMastodonNotification = (FragmentMastodonNotification) fedilabNotificationPageAdapter.getCurrentFragment();
|
||||
FragmentMastodonNotification fragmentMastodonNotification = (FragmentMastodonNotification) requireActivity().getSupportFragmentManager().findFragmentByTag("f" + binding.viewpager.getCurrentItem());
|
||||
if (fragmentMastodonNotification != null) {
|
||||
fragmentMastodonNotification.scrollToTop();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressLint("ApplySharedPref")
|
||||
@Override
|
||||
|
|
|
@ -57,10 +57,8 @@ public class FragmentProfileTimeline extends Fragment {
|
|||
binding.tabLayout.addTab(binding.tabLayout.newTab().setText(getString(R.string.media)));
|
||||
binding.tabLayout.setTabTextColors(ThemeHelper.getAttColor(requireActivity(), R.attr.mTextColor), ContextCompat.getColor(requireActivity(), R.color.cyanea_accent_dark_reference));
|
||||
binding.tabLayout.setTabIconTint(ThemeHelper.getColorStateList(requireActivity()));
|
||||
binding.viewpager.setAdapter(new FedilabProfilePageAdapter(
|
||||
getChildFragmentManager(), account));
|
||||
binding.viewpager.setAdapter(new FedilabProfilePageAdapter(requireActivity(), account));
|
||||
binding.viewpager.setOffscreenPageLimit(3);
|
||||
binding.viewpager.addOnPageChangeListener(new TabLayout.TabLayoutOnPageChangeListener(binding.tabLayout));
|
||||
binding.tabLayout.addOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {
|
||||
@Override
|
||||
public void onTabSelected(TabLayout.Tab tab) {
|
||||
|
@ -74,7 +72,6 @@ public class FragmentProfileTimeline extends Fragment {
|
|||
|
||||
@Override
|
||||
public void onTabReselected(TabLayout.Tab tab) {
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
|
|
|
@ -16,43 +16,33 @@ package app.fedilab.android.ui.pageadapter;
|
|||
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.fragment.app.Fragment;
|
||||
import androidx.fragment.app.FragmentManager;
|
||||
import androidx.fragment.app.FragmentStatePagerAdapter;
|
||||
import androidx.fragment.app.FragmentActivity;
|
||||
import androidx.viewpager2.adapter.FragmentStateAdapter;
|
||||
|
||||
import app.fedilab.android.helper.Helper;
|
||||
import app.fedilab.android.ui.fragment.timeline.FragmentMastodonNotification;
|
||||
|
||||
public class FedilabNotificationPageAdapter extends FragmentStatePagerAdapter {
|
||||
public class FedilabNotificationPageAdapter extends FragmentStateAdapter {
|
||||
|
||||
private final boolean extended;
|
||||
private Fragment mCurrentFragment;
|
||||
|
||||
|
||||
public FedilabNotificationPageAdapter(FragmentManager fm, boolean extended) {
|
||||
super(fm, BEHAVIOR_RESUME_ONLY_CURRENT_FRAGMENT);
|
||||
|
||||
public FedilabNotificationPageAdapter(FragmentActivity fa, boolean extended) {
|
||||
super(fa);
|
||||
this.extended = extended;
|
||||
}
|
||||
|
||||
public Fragment getCurrentFragment() {
|
||||
return mCurrentFragment;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPrimaryItem(@NonNull ViewGroup container, int position, @NonNull Object object) {
|
||||
if (getCurrentFragment() != object) {
|
||||
mCurrentFragment = ((Fragment) object);
|
||||
}
|
||||
super.setPrimaryItem(container, position, object);
|
||||
public int getItemCount() {
|
||||
return extended ? 7 : 2;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public Fragment getItem(int position) {
|
||||
public Fragment createFragment(int position) {
|
||||
Bundle bundle = new Bundle();
|
||||
FragmentMastodonNotification fragmentMastodonNotification = new FragmentMastodonNotification();
|
||||
if (!extended) {
|
||||
|
@ -93,8 +83,5 @@ public class FedilabNotificationPageAdapter extends FragmentStatePagerAdapter {
|
|||
return fragmentMastodonNotification;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCount() {
|
||||
return extended ? 7 : 2;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -15,43 +15,35 @@ package app.fedilab.android.ui.pageadapter;
|
|||
* see <http://www.gnu.org/licenses>. */
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.fragment.app.Fragment;
|
||||
import androidx.fragment.app.FragmentManager;
|
||||
import androidx.fragment.app.FragmentStatePagerAdapter;
|
||||
import androidx.fragment.app.FragmentActivity;
|
||||
import androidx.viewpager2.adapter.FragmentStateAdapter;
|
||||
|
||||
import app.fedilab.android.client.entities.api.Account;
|
||||
import app.fedilab.android.client.entities.app.Timeline;
|
||||
import app.fedilab.android.helper.Helper;
|
||||
import app.fedilab.android.ui.fragment.timeline.FragmentMastodonTimeline;
|
||||
|
||||
public class FedilabProfilePageAdapter extends FragmentStatePagerAdapter {
|
||||
public class FedilabProfilePageAdapter extends FragmentStateAdapter {
|
||||
|
||||
private final Account account;
|
||||
private Fragment mCurrentFragment;
|
||||
|
||||
public FedilabProfilePageAdapter(FragmentManager fm, Account account) {
|
||||
super(fm, BEHAVIOR_RESUME_ONLY_CURRENT_FRAGMENT);
|
||||
public FedilabProfilePageAdapter(FragmentActivity fa, Account account) {
|
||||
super(fa);
|
||||
this.account = account;
|
||||
}
|
||||
|
||||
public Fragment getCurrentFragment() {
|
||||
return mCurrentFragment;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPrimaryItem(@NonNull ViewGroup container, int position, @NonNull Object object) {
|
||||
if (getCurrentFragment() != object) {
|
||||
mCurrentFragment = ((Fragment) object);
|
||||
}
|
||||
super.setPrimaryItem(container, position, object);
|
||||
public int getItemCount() {
|
||||
return 3;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public Fragment getItem(int position) {
|
||||
public Fragment createFragment(int position) {
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putString(Helper.ARG_VIEW_MODEL_KEY, "FEDILAB_" + position);
|
||||
switch (position) {
|
||||
|
@ -85,8 +77,5 @@ public class FedilabProfilePageAdapter extends FragmentStatePagerAdapter {
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCount() {
|
||||
return 3;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -15,12 +15,11 @@ package app.fedilab.android.ui.pageadapter;
|
|||
* see <http://www.gnu.org/licenses>. */
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.fragment.app.Fragment;
|
||||
import androidx.fragment.app.FragmentManager;
|
||||
import androidx.fragment.app.FragmentStatePagerAdapter;
|
||||
import androidx.fragment.app.FragmentActivity;
|
||||
import androidx.viewpager2.adapter.FragmentStateAdapter;
|
||||
|
||||
import app.fedilab.android.client.entities.api.Account;
|
||||
import app.fedilab.android.helper.Helper;
|
||||
|
@ -28,31 +27,19 @@ import app.fedilab.android.ui.fragment.timeline.FragmentMastodonAccount;
|
|||
import app.fedilab.android.ui.fragment.timeline.FragmentMastodonTimeline;
|
||||
import app.fedilab.android.ui.fragment.timeline.FragmentProfileTimeline;
|
||||
|
||||
public class FedilabProfileTLPageAdapter extends FragmentStatePagerAdapter {
|
||||
public class FedilabProfileTLPageAdapter extends FragmentStateAdapter {
|
||||
|
||||
private final Account account;
|
||||
private Fragment mCurrentFragment;
|
||||
|
||||
public FedilabProfileTLPageAdapter(FragmentManager fm, Account account) {
|
||||
super(fm, BEHAVIOR_RESUME_ONLY_CURRENT_FRAGMENT);
|
||||
public FedilabProfileTLPageAdapter(FragmentActivity fa, Account account) {
|
||||
super(fa);
|
||||
this.account = account;
|
||||
}
|
||||
|
||||
public Fragment getCurrentFragment() {
|
||||
return mCurrentFragment;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPrimaryItem(@NonNull ViewGroup container, int position, @NonNull Object object) {
|
||||
if (getCurrentFragment() != object) {
|
||||
mCurrentFragment = ((Fragment) object);
|
||||
}
|
||||
super.setPrimaryItem(container, position, object);
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public Fragment getItem(int position) {
|
||||
public Fragment createFragment(int position) {
|
||||
switch (position) {
|
||||
|
||||
case 0:
|
||||
|
@ -76,7 +63,7 @@ public class FedilabProfileTLPageAdapter extends FragmentStatePagerAdapter {
|
|||
}
|
||||
|
||||
@Override
|
||||
public int getCount() {
|
||||
public int getItemCount() {
|
||||
return 3;
|
||||
}
|
||||
|
||||
|
|
|
@ -15,40 +15,26 @@ package app.fedilab.android.ui.pageadapter;
|
|||
* see <http://www.gnu.org/licenses>. */
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.fragment.app.Fragment;
|
||||
import androidx.fragment.app.FragmentManager;
|
||||
import androidx.fragment.app.FragmentStatePagerAdapter;
|
||||
import androidx.fragment.app.FragmentActivity;
|
||||
import androidx.viewpager2.adapter.FragmentStateAdapter;
|
||||
|
||||
import app.fedilab.android.client.entities.app.Timeline;
|
||||
import app.fedilab.android.helper.Helper;
|
||||
import app.fedilab.android.ui.fragment.timeline.FragmentScheduled;
|
||||
|
||||
public class FedilabScheduledPageAdapter extends FragmentStatePagerAdapter {
|
||||
public class FedilabScheduledPageAdapter extends FragmentStateAdapter {
|
||||
|
||||
private Fragment mCurrentFragment;
|
||||
|
||||
public FedilabScheduledPageAdapter(FragmentManager fm) {
|
||||
super(fm, BEHAVIOR_RESUME_ONLY_CURRENT_FRAGMENT);
|
||||
}
|
||||
|
||||
public Fragment getCurrentFragment() {
|
||||
return mCurrentFragment;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPrimaryItem(@NonNull ViewGroup container, int position, @NonNull Object object) {
|
||||
if (getCurrentFragment() != object) {
|
||||
mCurrentFragment = ((Fragment) object);
|
||||
}
|
||||
super.setPrimaryItem(container, position, object);
|
||||
public FedilabScheduledPageAdapter(FragmentActivity fa) {
|
||||
super(fa);
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public Fragment getItem(int position) {
|
||||
public Fragment createFragment(int position) {
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putString(Helper.ARG_VIEW_MODEL_KEY, "FEDILAB_" + position);
|
||||
FragmentScheduled fragmentScheduled = new FragmentScheduled();
|
||||
|
@ -67,7 +53,7 @@ public class FedilabScheduledPageAdapter extends FragmentStatePagerAdapter {
|
|||
}
|
||||
|
||||
@Override
|
||||
public int getCount() {
|
||||
public int getItemCount() {
|
||||
return 3;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -29,7 +29,7 @@
|
|||
android:animateLayoutChanges="true"
|
||||
android:background="@android:color/transparent">
|
||||
|
||||
<androidx.viewpager.widget.ViewPager
|
||||
<androidx.viewpager2.widget.ViewPager2
|
||||
android:id="@+id/media_viewpager"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
|
|
|
@ -541,7 +541,7 @@
|
|||
app:tabMode="fixed" />
|
||||
</com.google.android.material.appbar.AppBarLayout>
|
||||
|
||||
<androidx.viewpager.widget.ViewPager
|
||||
<androidx.viewpager2.widget.ViewPager2
|
||||
android:id="@+id/account_viewpager"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
|
|
|
@ -63,7 +63,7 @@
|
|||
</com.google.android.material.appbar.AppBarLayout>
|
||||
|
||||
|
||||
<androidx.viewpager.widget.ViewPager
|
||||
<androidx.viewpager2.widget.ViewPager2
|
||||
android:id="@+id/schedule_viewpager"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
|
|
|
@ -30,7 +30,7 @@
|
|||
app:tabIndicatorColor="@color/cyanea_accent_dark_reference"
|
||||
app:tabMode="scrollable" />
|
||||
|
||||
<androidx.viewpager.widget.ViewPager
|
||||
<androidx.viewpager2.widget.ViewPager2
|
||||
android:id="@+id/search_viewpager"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
|
|
|
@ -47,7 +47,7 @@
|
|||
|
||||
</androidx.appcompat.widget.LinearLayoutCompat>
|
||||
|
||||
<androidx.viewpager.widget.ViewPager
|
||||
<androidx.viewpager2.widget.ViewPager2
|
||||
android:id="@+id/viewpager"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent" />
|
||||
|
|
|
@ -27,7 +27,7 @@
|
|||
app:tabGravity="fill"
|
||||
app:tabMaxWidth="0dp" />
|
||||
|
||||
<androidx.viewpager.widget.ViewPager
|
||||
<androidx.viewpager2.widget.ViewPager2
|
||||
android:id="@+id/viewpager"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent" />
|
||||
|
|
Loading…
Reference in a new issue