Some fixes

This commit is contained in:
Thomas 2022-07-02 17:25:06 +02:00
parent 13575706de
commit b7265d6de3
7 changed files with 64 additions and 90 deletions

View File

@ -121,7 +121,6 @@ import app.fedilab.android.helper.PinnedTimelineHelper;
import app.fedilab.android.helper.PushHelper;
import app.fedilab.android.helper.ThemeHelper;
import app.fedilab.android.ui.fragment.timeline.FragmentMastodonConversation;
import app.fedilab.android.ui.fragment.timeline.FragmentMastodonNotification;
import app.fedilab.android.ui.fragment.timeline.FragmentMastodonTimeline;
import app.fedilab.android.ui.fragment.timeline.FragmentNotificationContainer;
import app.fedilab.android.viewmodel.mastodon.AccountsVM;
@ -883,13 +882,11 @@ public abstract class BaseMainActivity extends BaseActivity implements NetworkSt
* Allow to scroll to top for bottom navigation items
*/
private void scrollToTop() {
Fragment fragment = getSupportFragmentManager().findFragmentByTag("f" + binding.viewPager.getCurrentItem());
if (fragment instanceof FragmentMastodonTimeline) {
FragmentMastodonTimeline fragmentMastodonTimeline = ((FragmentMastodonTimeline) fragment);
fragmentMastodonTimeline.scrollToTop();
} else if (fragment instanceof FragmentMastodonNotification) {
FragmentMastodonNotification fragmentMastodonNotification = ((FragmentMastodonNotification) fragment);
fragmentMastodonNotification.scrollToTop();
} else if (fragment instanceof FragmentMastodonConversation) {
FragmentMastodonConversation fragmentMastodonConversation = ((FragmentMastodonConversation) fragment);
fragmentMastodonConversation.scrollToTop();

View File

@ -252,7 +252,6 @@ public class FragmentLoginMain extends Fragment {
}
String scopes = ((LoginActivity) requireActivity()).requestedAdmin() ? Helper.OAUTH_SCOPES_ADMIN : Helper.OAUTH_SCOPES;
AppsVM appsVM = new ViewModelProvider(requireActivity()).get(AppsVM.class);
String finalInstance = instance;
appsVM.createApp(currentInstanceLogin, getString(R.string.app_name),
Helper.REDIRECT_CONTENT_WEB,
scopes,

View File

@ -70,8 +70,8 @@ public class FragmentLoginRegisterMastodon extends Fragment {
} else {
binding.loginInstance.setOnFocusChangeListener((v, hasFocus) -> {
if (!hasFocus) {
nodeInfoVM.getNodeInfo(binding.loginInstance.getText().toString()).observe(requireActivity(), nodeInfo -> {
if (nodeInfo != null && (nodeInfo.software.name.trim().toLowerCase().compareTo("mastodon") == 0 || nodeInfo.software.name.trim().toLowerCase().compareTo("pleroma") == 0)) {
nodeInfoVM.getNodeInfo(binding.loginInstance.getText().toString().trim()).observe(requireActivity(), nodeInfo -> {
if (nodeInfo != null) {
String tos = getString(R.string.tos);
String serverrules = getString(R.string.server_rules);
String content_agreement = getString(R.string.agreement_check,

View File

@ -33,7 +33,6 @@ import androidx.preference.PreferenceManager;
import com.google.android.material.button.MaterialButton;
import com.google.android.material.tabs.TabLayout;
import com.google.android.material.tabs.TabLayoutMediator;
import java.util.ArrayList;
import java.util.List;
@ -61,20 +60,20 @@ public class FragmentNotificationContainer extends Fragment {
SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(requireActivity());
boolean display_all_notification = sharedpreferences.getBoolean(getString(R.string.SET_DISPLAY_ALL_NOTIFICATIONS_TYPE) + BaseMainActivity.currentUserID + BaseMainActivity.currentInstance, false);
if (!display_all_notification) {
binding.tabLayout.addTab(binding.tabLayout.newTab());
binding.tabLayout.addTab(binding.tabLayout.newTab());
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(requireActivity(), false));
binding.viewpagerNotificationContainer.setAdapter(new FedilabNotificationPageAdapter(getChildFragmentManager(), false));
} else {
binding.tabLayout.setTabMode(TabLayout.MODE_SCROLLABLE);
binding.tabLayout.addTab(binding.tabLayout.newTab());
binding.tabLayout.addTab(binding.tabLayout.newTab());
binding.tabLayout.addTab(binding.tabLayout.newTab());
binding.tabLayout.addTab(binding.tabLayout.newTab());
binding.tabLayout.addTab(binding.tabLayout.newTab());
binding.tabLayout.addTab(binding.tabLayout.newTab());
binding.tabLayout.addTab(binding.tabLayout.newTab());
binding.viewpager.setAdapter(new FedilabNotificationPageAdapter(requireActivity(), true));
binding.tabLayout.addTab(binding.tabLayout.newTab().setText(getString(R.string.all)));
binding.tabLayout.addTab(binding.tabLayout.newTab().setIcon(R.drawable.ic_baseline_reply_24));
binding.tabLayout.addTab(binding.tabLayout.newTab().setIcon(R.drawable.ic_baseline_star_24));
binding.tabLayout.addTab(binding.tabLayout.newTab().setIcon(R.drawable.ic_repeat));
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.viewpagerNotificationContainer.setAdapter(new FedilabNotificationPageAdapter(getChildFragmentManager(), true));
}
AtomicBoolean changes = new AtomicBoolean(false);
binding.settings.setOnClickListener(v -> {
@ -213,76 +212,41 @@ 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.viewpagerNotificationContainer.addOnPageChangeListener(new TabLayout.TabLayoutOnPageChangeListener(binding.tabLayout));
binding.tabLayout.addOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {
@Override
public void onTabSelected(TabLayout.Tab tab) {
binding.viewpager.setCurrentItem(tab.getPosition());
binding.viewpagerNotificationContainer.setCurrentItem(tab.getPosition());
}
@Override
public void onTabUnselected(TabLayout.Tab tab) {
}
@Override
public void onTabReselected(TabLayout.Tab tab) {
Fragment fragment = getParentFragmentManager().findFragmentByTag("f" + binding.viewpager.getCurrentItem());
Fragment fragment;
if (binding.viewpagerNotificationContainer.getAdapter() != null) {
fragment = (Fragment) binding.viewpagerNotificationContainer.getAdapter().instantiateItem(binding.viewpagerNotificationContainer, tab.getPosition());
if (fragment instanceof FragmentMastodonNotification) {
FragmentMastodonNotification fragmentMastodonNotification = ((FragmentMastodonNotification) fragment);
fragmentMastodonNotification.scrollToTop();
}
}
}
});
new TabLayoutMediator(binding.tabLayout, binding.viewpager,
(tab, position) -> {
binding.viewpager.setCurrentItem(tab.getPosition(), true);
if (!display_all_notification) {
switch (position) {
case 0:
tab.setText(getString(R.string.all));
break;
case 1:
tab.setText(getString(R.string.mention));
break;
}
} else {
switch (position) {
case 0:
tab.setText(getString(R.string.all));
break;
case 1:
tab.setIcon(R.drawable.ic_baseline_reply_24);
break;
case 2:
tab.setIcon(R.drawable.ic_baseline_star_24);
break;
case 3:
tab.setIcon(R.drawable.ic_repeat);
break;
case 4:
tab.setIcon(R.drawable.ic_baseline_poll_24);
break;
case 5:
tab.setIcon(R.drawable.ic_baseline_home_24);
break;
case 6:
tab.setIcon(R.drawable.ic_baseline_person_add_alt_1_24);
break;
}
}
}
).attach();
return binding.getRoot();
}
public void scrollToTop() {
if (binding != null) {
Fragment fragment = getParentFragmentManager().findFragmentByTag("f" + binding.viewpager.getCurrentItem());
if (fragment instanceof FragmentMastodonNotification) {
((FragmentMastodonNotification) fragment).scrollToTop();
FedilabNotificationPageAdapter fedilabNotificationPageAdapter = ((FedilabNotificationPageAdapter) binding.viewpagerNotificationContainer.getAdapter());
if (fedilabNotificationPageAdapter != null) {
FragmentMastodonNotification fragmentMastodonNotification = (FragmentMastodonNotification) fedilabNotificationPageAdapter.getCurrentFragment();
if (fragmentMastodonNotification != null) {
fragmentMastodonNotification.scrollToTop();
}
}
}
}

View File

@ -14,35 +14,41 @@ package app.fedilab.android.ui.pageadapter;
* 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;
import android.view.ViewGroup;
import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentActivity;
import androidx.viewpager2.adapter.FragmentStateAdapter;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentStatePagerAdapter;
import app.fedilab.android.helper.Helper;
import app.fedilab.android.ui.fragment.timeline.FragmentMastodonNotification;
public class FedilabNotificationPageAdapter extends FragmentStateAdapter {
public class FedilabNotificationPageAdapter extends FragmentStatePagerAdapter {
private final boolean extended;
private Fragment mCurrentFragment;
public FedilabNotificationPageAdapter(FragmentActivity fa, boolean extended) {
super(fa);
public FedilabNotificationPageAdapter(FragmentManager fm, boolean extended) {
super(fm, BEHAVIOR_RESUME_ONLY_CURRENT_FRAGMENT);
this.extended = extended;
}
public Fragment getCurrentFragment() {
return mCurrentFragment;
}
@Override
public int getItemCount() {
return extended ? 7 : 2;
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 createFragment(int position) {
public Fragment getItem(int position) {
Bundle bundle = new Bundle();
FragmentMastodonNotification fragmentMastodonNotification = new FragmentMastodonNotification();
if (!extended) {
@ -83,5 +89,8 @@ public class FedilabNotificationPageAdapter extends FragmentStateAdapter {
return fragmentMastodonNotification;
}
@Override
public int getCount() {
return extended ? 7 : 2;
}
}

View File

@ -75,14 +75,19 @@
</com.google.android.material.appbar.AppBarLayout>
<app.fedilab.android.helper.NestedScrollableHost
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
<androidx.viewpager2.widget.ViewPager2
android:id="@+id/view_pager"
android:name="androidx.navigation.fragment.NavHostFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginBottom="?attr/actionBarSize"
app:defaultNavHost="true"
app:layout_behavior="@string/appbar_scrolling_view_behavior" />
app:defaultNavHost="true" />
</app.fedilab.android.helper.NestedScrollableHost>
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"

View File

@ -47,8 +47,8 @@
</androidx.appcompat.widget.LinearLayoutCompat>
<androidx.viewpager2.widget.ViewPager2
android:id="@+id/viewpager"
<androidx.viewpager.widget.ViewPager
android:id="@+id/viewpagerNotificationContainer"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>