Commit b1603894 authored by Thomas's avatar Thomas
Browse files

Fix issue with pagination

parent 1ac365be
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -18,12 +18,14 @@
        android:icon="@mipmap/ic_launcher"
        android:usesCleartextTraffic="true"
        android:label="@string/app_name"
        android:configChanges="orientation|screenSize"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/AppThemeDark"
       >
        <activity
            android:name=".activities.MainActivity"
            android:configChanges="orientation|screenSize"
            android:exported="true"
            >
            <intent-filter>
+8 −2
Original line number Diff line number Diff line
@@ -55,6 +55,7 @@ import androidx.core.app.ActivityOptionsCompat;
import androidx.core.content.ContextCompat;
import androidx.core.view.GravityCompat;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentTransaction;
import androidx.lifecycle.ViewModelProvider;
import androidx.localbroadcastmanager.content.LocalBroadcastManager;
import androidx.navigation.NavController;
@@ -838,8 +839,13 @@ public abstract class BaseMainActivity extends BaseActivity implements NetworkSt
    }

    public void refreshFragment() {
        if (binding.viewPager.getAdapter() != null) {
            binding.viewPager.getAdapter().notifyDataSetChanged();
        Fragment fragment = getSupportFragmentManager().findFragmentByTag("f" + binding.viewPager.getCurrentItem());
        if (fragment instanceof FragmentNotificationContainer) {
            FragmentTransaction fragTransaction = getSupportFragmentManager().beginTransaction();
            fragTransaction.detach(fragment).commit();
            FragmentTransaction fragTransaction2 = getSupportFragmentManager().beginTransaction();
            fragTransaction2.attach(fragment);
            fragTransaction2.commit();
        }
    }

+20 −27
Original line number Diff line number Diff line
@@ -59,12 +59,11 @@ 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;
import com.bumptech.glide.request.transition.Transition;
import com.google.android.material.tabs.TabLayout;
import com.google.android.material.tabs.TabLayoutMediator;

import java.util.ArrayList;
import java.util.Date;
@@ -249,34 +248,28 @@ public class ProfileActivity extends BaseActivity {
        binding.accountTabLayout.removeAllTabs();
        //Tablayout for timelines/following/followers
        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.accountTabLayout.addTab(binding.accountTabLayout.newTab());
        binding.accountTabLayout.addTab(binding.accountTabLayout.newTab());
        binding.accountTabLayout.addTab(binding.accountTabLayout.newTab());
        binding.accountViewpager.setAdapter(fedilabProfileTLPageAdapter);
        binding.accountViewpager.setOffscreenPageLimit(3);
        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) {
                binding.accountViewpager.setCurrentItem(tab.getPosition());
            }

            @Override
            public void onTabUnselected(TabLayout.Tab tab) {

        new TabLayoutMediator(binding.accountTabLayout, binding.accountViewpager,
                (tab, position) -> {
                    binding.accountViewpager.setCurrentItem(tab.getPosition(), true);
                    switch (position) {
                        case 0:
                            tab.setText(getString(R.string.status_cnt, Helper.withSuffix(account.statuses_count)));
                            break;
                        case 1:
                            tab.setText(getString(R.string.following_cnt, Helper.withSuffix(account.statuses_count)));
                            break;
                        case 2:
                            tab.setText(getString(R.string.followers_cnt, Helper.withSuffix(account.statuses_count)));
                            break;
                    }

            @Override
            public void onTabReselected(TabLayout.Tab tab) {

                }
        });
        ).attach();
        binding.accountTabLayout.setTabTextColors(ThemeHelper.getAttColor(ProfileActivity.this, R.attr.mTextColor), ContextCompat.getColor(ProfileActivity.this, R.color.cyanea_accent_dark_reference));
        binding.accountTabLayout.setTabIconTint(ThemeHelper.getColorStateList(ProfileActivity.this));
        boolean disableGif = sharedpreferences.getBoolean(getString(R.string.SET_DISABLE_GIF), false);
+20 −20
Original line number Diff line number Diff line
@@ -24,7 +24,7 @@ import androidx.annotation.Nullable;
import androidx.appcompat.app.ActionBar;
import androidx.core.content.ContextCompat;

import com.google.android.material.tabs.TabLayout;
import com.google.android.material.tabs.TabLayoutMediator;

import app.fedilab.android.R;
import app.fedilab.android.databinding.ActivityScheduledBinding;
@@ -56,31 +56,31 @@ public class ScheduledActivity extends BaseActivity {

        MastodonHelper.loadPPMastodon(binding.profilePicture, currentAccount.mastodon_account);
        binding.title.setText(R.string.scheduled);
        binding.scheduleTablayout.addTab(binding.scheduleTablayout.newTab().setText(getString(R.string.toots_server)));
        binding.scheduleTablayout.addTab(binding.scheduleTablayout.newTab().setText(getString(R.string.toots_client)));
        binding.scheduleTablayout.addTab(binding.scheduleTablayout.newTab().setText(getString(R.string.reblog)));
        binding.scheduleTablayout.addTab(binding.scheduleTablayout.newTab());
        binding.scheduleTablayout.addTab(binding.scheduleTablayout.newTab());
        binding.scheduleTablayout.addTab(binding.scheduleTablayout.newTab());

        binding.scheduleViewpager.setAdapter(new FedilabScheduledPageAdapter(ScheduledActivity.this));
        binding.scheduleViewpager.setOffscreenPageLimit(3);
        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));

        binding.scheduleTablayout.addOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {
            @Override
            public void onTabSelected(TabLayout.Tab tab) {
                binding.scheduleViewpager.setCurrentItem(tab.getPosition());
            }

            @Override
            public void onTabUnselected(TabLayout.Tab tab) {

        new TabLayoutMediator(binding.scheduleTablayout, binding.scheduleViewpager,
                (tab, position) -> {
                    binding.scheduleViewpager.setCurrentItem(tab.getPosition(), true);
                    switch (position) {
                        case 0:
                            tab.setText(getString(R.string.toots_server));
                            break;
                        case 1:
                            tab.setText(getString(R.string.toots_client));
                            break;
                        case 2:
                            tab.setText(getString(R.string.reblog));
                            break;
                    }

            @Override
            public void onTabReselected(TabLayout.Tab tab) {

                }
        });
        ).attach();
    }

    @Override
+37 −43
Original line number Diff line number Diff line
@@ -30,9 +30,9 @@ import androidx.core.content.ContextCompat;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentActivity;
import androidx.viewpager2.adapter.FragmentStateAdapter;
import androidx.viewpager2.widget.ViewPager2;

import com.google.android.material.tabs.TabLayout;
import com.google.android.material.tabs.TabLayoutMediator;

import org.jetbrains.annotations.NotNull;

@@ -75,13 +75,34 @@ public class SearchResultTabActivity extends BaseActivity {
            getSupportActionBar().setBackgroundDrawable(new ColorDrawable(ContextCompat.getColor(this, R.color.cyanea_primary)));
        }
        setTitle(search);
        binding.searchTabLayout.addTab(binding.searchTabLayout.newTab().setText(getString(R.string.tags)));
        binding.searchTabLayout.addTab(binding.searchTabLayout.newTab().setText(getString(R.string.accounts)));
        binding.searchTabLayout.addTab(binding.searchTabLayout.newTab().setText(getString(R.string.toots)));
        binding.searchTabLayout.addTab(binding.searchTabLayout.newTab().setText(getString(R.string.action_cache)));
        binding.searchTabLayout.addTab(binding.searchTabLayout.newTab());
        binding.searchTabLayout.addTab(binding.searchTabLayout.newTab());
        binding.searchTabLayout.addTab(binding.searchTabLayout.newTab());
        binding.searchTabLayout.addTab(binding.searchTabLayout.newTab());
        binding.searchTabLayout.setTabTextColors(ThemeHelper.getAttColor(SearchResultTabActivity.this, R.attr.mTextColor), ContextCompat.getColor(SearchResultTabActivity.this, R.color.cyanea_accent_dark_reference));
        binding.searchTabLayout.setTabIconTint(ThemeHelper.getColorStateList(SearchResultTabActivity.this));

        ScreenSlidePagerAdapter mPagerAdapter = new ScreenSlidePagerAdapter(SearchResultTabActivity.this);
        binding.searchViewpager.setAdapter(mPagerAdapter);
        binding.searchViewpager.setOffscreenPageLimit(3);
        new TabLayoutMediator(binding.searchTabLayout, binding.searchViewpager,
                (tab, position) -> {
                    binding.searchViewpager.setCurrentItem(tab.getPosition(), true);
                    switch (position) {
                        case 0:
                            tab.setText(getString(R.string.tags));
                            break;
                        case 1:
                            tab.setText(getString(R.string.accounts));
                            break;
                        case 2:
                            tab.setText(getString(R.string.toots));
                            break;
                        case 3:
                            tab.setText(getString(R.string.action_cache));
                            break;
                    }
                }
        ).attach();
        binding.searchTabLayout.addOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {
            @Override
            public void onTabSelected(TabLayout.Tab tab) {
@@ -95,9 +116,7 @@ public class SearchResultTabActivity extends BaseActivity {

            @Override
            public void onTabReselected(TabLayout.Tab tab) {
                Fragment fragment;
                if (binding.searchViewpager.getAdapter() != null) {
                    fragment = (Fragment) getSupportFragmentManager().findFragmentByTag("f" + binding.searchViewpager.getCurrentItem());
                Fragment fragment = getSupportFragmentManager().findFragmentByTag("f" + binding.searchViewpager.getCurrentItem());
                if (fragment instanceof FragmentMastodonAccount) {
                    FragmentMastodonAccount fragmentMastodonAccount = ((FragmentMastodonAccount) fragment);
                    fragmentMastodonAccount.scrollToTop();
@@ -109,7 +128,6 @@ public class SearchResultTabActivity extends BaseActivity {
                    fragmentMastodonTag.scrollToTop();
                }
            }
            }
        });
    }

@@ -122,8 +140,6 @@ public class SearchResultTabActivity extends BaseActivity {
        SearchView searchView = (SearchView) menu.findItem(R.id.action_search).getActionView();
        searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));
        searchView.setIconifiedByDefault(false);


        searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
            @Override
            public boolean onQueryTextSubmit(String query) {
@@ -156,29 +172,7 @@ public class SearchResultTabActivity extends BaseActivity {
        });


        ScreenSlidePagerAdapter mPagerAdapter = new ScreenSlidePagerAdapter(SearchResultTabActivity.this);
        binding.searchViewpager.setAdapter(mPagerAdapter);

        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();
            }

            @Override
            public void onPageScrollStateChanged(int state) {
                super.onPageScrollStateChanged(state);
            }
        });
        return true;
    }

Loading