Some fixes
This commit is contained in:
parent
13575706de
commit
b7265d6de3
|
@ -121,7 +121,6 @@ import app.fedilab.android.helper.PinnedTimelineHelper;
|
||||||
import app.fedilab.android.helper.PushHelper;
|
import app.fedilab.android.helper.PushHelper;
|
||||||
import app.fedilab.android.helper.ThemeHelper;
|
import app.fedilab.android.helper.ThemeHelper;
|
||||||
import app.fedilab.android.ui.fragment.timeline.FragmentMastodonConversation;
|
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.FragmentMastodonTimeline;
|
||||||
import app.fedilab.android.ui.fragment.timeline.FragmentNotificationContainer;
|
import app.fedilab.android.ui.fragment.timeline.FragmentNotificationContainer;
|
||||||
import app.fedilab.android.viewmodel.mastodon.AccountsVM;
|
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
|
* Allow to scroll to top for bottom navigation items
|
||||||
*/
|
*/
|
||||||
private void scrollToTop() {
|
private void scrollToTop() {
|
||||||
|
|
||||||
Fragment fragment = getSupportFragmentManager().findFragmentByTag("f" + binding.viewPager.getCurrentItem());
|
Fragment fragment = getSupportFragmentManager().findFragmentByTag("f" + binding.viewPager.getCurrentItem());
|
||||||
if (fragment instanceof FragmentMastodonTimeline) {
|
if (fragment instanceof FragmentMastodonTimeline) {
|
||||||
FragmentMastodonTimeline fragmentMastodonTimeline = ((FragmentMastodonTimeline) fragment);
|
FragmentMastodonTimeline fragmentMastodonTimeline = ((FragmentMastodonTimeline) fragment);
|
||||||
fragmentMastodonTimeline.scrollToTop();
|
fragmentMastodonTimeline.scrollToTop();
|
||||||
} else if (fragment instanceof FragmentMastodonNotification) {
|
|
||||||
FragmentMastodonNotification fragmentMastodonNotification = ((FragmentMastodonNotification) fragment);
|
|
||||||
fragmentMastodonNotification.scrollToTop();
|
|
||||||
} else if (fragment instanceof FragmentMastodonConversation) {
|
} else if (fragment instanceof FragmentMastodonConversation) {
|
||||||
FragmentMastodonConversation fragmentMastodonConversation = ((FragmentMastodonConversation) fragment);
|
FragmentMastodonConversation fragmentMastodonConversation = ((FragmentMastodonConversation) fragment);
|
||||||
fragmentMastodonConversation.scrollToTop();
|
fragmentMastodonConversation.scrollToTop();
|
||||||
|
|
|
@ -252,7 +252,6 @@ public class FragmentLoginMain extends Fragment {
|
||||||
}
|
}
|
||||||
String scopes = ((LoginActivity) requireActivity()).requestedAdmin() ? Helper.OAUTH_SCOPES_ADMIN : Helper.OAUTH_SCOPES;
|
String scopes = ((LoginActivity) requireActivity()).requestedAdmin() ? Helper.OAUTH_SCOPES_ADMIN : Helper.OAUTH_SCOPES;
|
||||||
AppsVM appsVM = new ViewModelProvider(requireActivity()).get(AppsVM.class);
|
AppsVM appsVM = new ViewModelProvider(requireActivity()).get(AppsVM.class);
|
||||||
String finalInstance = instance;
|
|
||||||
appsVM.createApp(currentInstanceLogin, getString(R.string.app_name),
|
appsVM.createApp(currentInstanceLogin, getString(R.string.app_name),
|
||||||
Helper.REDIRECT_CONTENT_WEB,
|
Helper.REDIRECT_CONTENT_WEB,
|
||||||
scopes,
|
scopes,
|
||||||
|
|
|
@ -70,8 +70,8 @@ public class FragmentLoginRegisterMastodon extends Fragment {
|
||||||
} else {
|
} else {
|
||||||
binding.loginInstance.setOnFocusChangeListener((v, hasFocus) -> {
|
binding.loginInstance.setOnFocusChangeListener((v, hasFocus) -> {
|
||||||
if (!hasFocus) {
|
if (!hasFocus) {
|
||||||
nodeInfoVM.getNodeInfo(binding.loginInstance.getText().toString()).observe(requireActivity(), nodeInfo -> {
|
nodeInfoVM.getNodeInfo(binding.loginInstance.getText().toString().trim()).observe(requireActivity(), nodeInfo -> {
|
||||||
if (nodeInfo != null && (nodeInfo.software.name.trim().toLowerCase().compareTo("mastodon") == 0 || nodeInfo.software.name.trim().toLowerCase().compareTo("pleroma") == 0)) {
|
if (nodeInfo != null) {
|
||||||
String tos = getString(R.string.tos);
|
String tos = getString(R.string.tos);
|
||||||
String serverrules = getString(R.string.server_rules);
|
String serverrules = getString(R.string.server_rules);
|
||||||
String content_agreement = getString(R.string.agreement_check,
|
String content_agreement = getString(R.string.agreement_check,
|
||||||
|
|
|
@ -33,7 +33,6 @@ import androidx.preference.PreferenceManager;
|
||||||
|
|
||||||
import com.google.android.material.button.MaterialButton;
|
import com.google.android.material.button.MaterialButton;
|
||||||
import com.google.android.material.tabs.TabLayout;
|
import com.google.android.material.tabs.TabLayout;
|
||||||
import com.google.android.material.tabs.TabLayoutMediator;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
@ -61,20 +60,20 @@ public class FragmentNotificationContainer extends Fragment {
|
||||||
SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(requireActivity());
|
SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(requireActivity());
|
||||||
boolean display_all_notification = sharedpreferences.getBoolean(getString(R.string.SET_DISPLAY_ALL_NOTIFICATIONS_TYPE) + BaseMainActivity.currentUserID + BaseMainActivity.currentInstance, false);
|
boolean display_all_notification = sharedpreferences.getBoolean(getString(R.string.SET_DISPLAY_ALL_NOTIFICATIONS_TYPE) + BaseMainActivity.currentUserID + BaseMainActivity.currentInstance, false);
|
||||||
if (!display_all_notification) {
|
if (!display_all_notification) {
|
||||||
binding.tabLayout.addTab(binding.tabLayout.newTab());
|
binding.tabLayout.addTab(binding.tabLayout.newTab().setText(getString(R.string.all)));
|
||||||
binding.tabLayout.addTab(binding.tabLayout.newTab());
|
binding.tabLayout.addTab(binding.tabLayout.newTab().setText(getString(R.string.mention)));
|
||||||
binding.tabLayout.setTabMode(TabLayout.MODE_FIXED);
|
binding.tabLayout.setTabMode(TabLayout.MODE_FIXED);
|
||||||
binding.viewpager.setAdapter(new FedilabNotificationPageAdapter(requireActivity(), false));
|
binding.viewpagerNotificationContainer.setAdapter(new FedilabNotificationPageAdapter(getChildFragmentManager(), false));
|
||||||
} else {
|
} else {
|
||||||
binding.tabLayout.setTabMode(TabLayout.MODE_SCROLLABLE);
|
binding.tabLayout.setTabMode(TabLayout.MODE_SCROLLABLE);
|
||||||
binding.tabLayout.addTab(binding.tabLayout.newTab());
|
binding.tabLayout.addTab(binding.tabLayout.newTab().setText(getString(R.string.all)));
|
||||||
binding.tabLayout.addTab(binding.tabLayout.newTab());
|
binding.tabLayout.addTab(binding.tabLayout.newTab().setIcon(R.drawable.ic_baseline_reply_24));
|
||||||
binding.tabLayout.addTab(binding.tabLayout.newTab());
|
binding.tabLayout.addTab(binding.tabLayout.newTab().setIcon(R.drawable.ic_baseline_star_24));
|
||||||
binding.tabLayout.addTab(binding.tabLayout.newTab());
|
binding.tabLayout.addTab(binding.tabLayout.newTab().setIcon(R.drawable.ic_repeat));
|
||||||
binding.tabLayout.addTab(binding.tabLayout.newTab());
|
binding.tabLayout.addTab(binding.tabLayout.newTab().setIcon(R.drawable.ic_baseline_poll_24));
|
||||||
binding.tabLayout.addTab(binding.tabLayout.newTab());
|
binding.tabLayout.addTab(binding.tabLayout.newTab().setIcon(R.drawable.ic_baseline_home_24));
|
||||||
binding.tabLayout.addTab(binding.tabLayout.newTab());
|
binding.tabLayout.addTab(binding.tabLayout.newTab().setIcon(R.drawable.ic_baseline_person_add_alt_1_24));
|
||||||
binding.viewpager.setAdapter(new FedilabNotificationPageAdapter(requireActivity(), true));
|
binding.viewpagerNotificationContainer.setAdapter(new FedilabNotificationPageAdapter(getChildFragmentManager(), true));
|
||||||
}
|
}
|
||||||
AtomicBoolean changes = new AtomicBoolean(false);
|
AtomicBoolean changes = new AtomicBoolean(false);
|
||||||
binding.settings.setOnClickListener(v -> {
|
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.setTabTextColors(ThemeHelper.getAttColor(requireActivity(), R.attr.mTextColor), ContextCompat.getColor(requireActivity(), R.color.cyanea_accent_dark_reference));
|
||||||
binding.tabLayout.setTabIconTint(ThemeHelper.getColorStateList(requireActivity()));
|
binding.tabLayout.setTabIconTint(ThemeHelper.getColorStateList(requireActivity()));
|
||||||
|
binding.viewpagerNotificationContainer.addOnPageChangeListener(new TabLayout.TabLayoutOnPageChangeListener(binding.tabLayout));
|
||||||
binding.tabLayout.addOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {
|
binding.tabLayout.addOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onTabSelected(TabLayout.Tab tab) {
|
public void onTabSelected(TabLayout.Tab tab) {
|
||||||
binding.viewpager.setCurrentItem(tab.getPosition());
|
binding.viewpagerNotificationContainer.setCurrentItem(tab.getPosition());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onTabUnselected(TabLayout.Tab tab) {
|
public void onTabUnselected(TabLayout.Tab tab) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onTabReselected(TabLayout.Tab tab) {
|
public void onTabReselected(TabLayout.Tab tab) {
|
||||||
Fragment fragment = getParentFragmentManager().findFragmentByTag("f" + binding.viewpager.getCurrentItem());
|
Fragment fragment;
|
||||||
if (fragment instanceof FragmentMastodonNotification) {
|
if (binding.viewpagerNotificationContainer.getAdapter() != null) {
|
||||||
FragmentMastodonNotification fragmentMastodonNotification = ((FragmentMastodonNotification) fragment);
|
fragment = (Fragment) binding.viewpagerNotificationContainer.getAdapter().instantiateItem(binding.viewpagerNotificationContainer, tab.getPosition());
|
||||||
fragmentMastodonNotification.scrollToTop();
|
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();
|
return binding.getRoot();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void scrollToTop() {
|
public void scrollToTop() {
|
||||||
if (binding != null) {
|
if (binding != null) {
|
||||||
Fragment fragment = getParentFragmentManager().findFragmentByTag("f" + binding.viewpager.getCurrentItem());
|
FedilabNotificationPageAdapter fedilabNotificationPageAdapter = ((FedilabNotificationPageAdapter) binding.viewpagerNotificationContainer.getAdapter());
|
||||||
if (fragment instanceof FragmentMastodonNotification) {
|
if (fedilabNotificationPageAdapter != null) {
|
||||||
((FragmentMastodonNotification) fragment).scrollToTop();
|
FragmentMastodonNotification fragmentMastodonNotification = (FragmentMastodonNotification) fedilabNotificationPageAdapter.getCurrentFragment();
|
||||||
|
if (fragmentMastodonNotification != null) {
|
||||||
|
fragmentMastodonNotification.scrollToTop();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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,
|
* You should have received a copy of the GNU General Public License along with Fedilab; if not,
|
||||||
* see <http://www.gnu.org/licenses>. */
|
* see <http://www.gnu.org/licenses>. */
|
||||||
|
|
||||||
|
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
import android.view.ViewGroup;
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
import androidx.fragment.app.Fragment;
|
import androidx.fragment.app.Fragment;
|
||||||
import androidx.fragment.app.FragmentActivity;
|
import androidx.fragment.app.FragmentManager;
|
||||||
import androidx.viewpager2.adapter.FragmentStateAdapter;
|
import androidx.fragment.app.FragmentStatePagerAdapter;
|
||||||
|
|
||||||
import app.fedilab.android.helper.Helper;
|
import app.fedilab.android.helper.Helper;
|
||||||
import app.fedilab.android.ui.fragment.timeline.FragmentMastodonNotification;
|
import app.fedilab.android.ui.fragment.timeline.FragmentMastodonNotification;
|
||||||
|
|
||||||
public class FedilabNotificationPageAdapter extends FragmentStateAdapter {
|
public class FedilabNotificationPageAdapter extends FragmentStatePagerAdapter {
|
||||||
|
|
||||||
private final boolean extended;
|
private final boolean extended;
|
||||||
|
private Fragment mCurrentFragment;
|
||||||
|
|
||||||
|
public FedilabNotificationPageAdapter(FragmentManager fm, boolean extended) {
|
||||||
public FedilabNotificationPageAdapter(FragmentActivity fa, boolean extended) {
|
super(fm, BEHAVIOR_RESUME_ONLY_CURRENT_FRAGMENT);
|
||||||
super(fa);
|
|
||||||
this.extended = extended;
|
this.extended = extended;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Fragment getCurrentFragment() {
|
||||||
|
return mCurrentFragment;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getItemCount() {
|
public void setPrimaryItem(@NonNull ViewGroup container, int position, @NonNull Object object) {
|
||||||
return extended ? 7 : 2;
|
if (getCurrentFragment() != object) {
|
||||||
|
mCurrentFragment = ((Fragment) object);
|
||||||
|
}
|
||||||
|
super.setPrimaryItem(container, position, object);
|
||||||
}
|
}
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
@Override
|
@Override
|
||||||
public Fragment createFragment(int position) {
|
public Fragment getItem(int position) {
|
||||||
Bundle bundle = new Bundle();
|
Bundle bundle = new Bundle();
|
||||||
FragmentMastodonNotification fragmentMastodonNotification = new FragmentMastodonNotification();
|
FragmentMastodonNotification fragmentMastodonNotification = new FragmentMastodonNotification();
|
||||||
if (!extended) {
|
if (!extended) {
|
||||||
|
@ -83,5 +89,8 @@ public class FedilabNotificationPageAdapter extends FragmentStateAdapter {
|
||||||
return fragmentMastodonNotification;
|
return fragmentMastodonNotification;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
}
|
public int getCount() {
|
||||||
|
return extended ? 7 : 2;
|
||||||
|
}
|
||||||
|
}
|
|
@ -75,14 +75,19 @@
|
||||||
|
|
||||||
</com.google.android.material.appbar.AppBarLayout>
|
</com.google.android.material.appbar.AppBarLayout>
|
||||||
|
|
||||||
<androidx.viewpager2.widget.ViewPager2
|
<app.fedilab.android.helper.NestedScrollableHost
|
||||||
android:id="@+id/view_pager"
|
|
||||||
android:name="androidx.navigation.fragment.NavHostFragment"
|
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
android:layout_marginBottom="?attr/actionBarSize"
|
app:layout_behavior="@string/appbar_scrolling_view_behavior">
|
||||||
app:defaultNavHost="true"
|
|
||||||
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.fedilab.android.helper.NestedScrollableHost>
|
||||||
|
|
||||||
<androidx.constraintlayout.widget.ConstraintLayout
|
<androidx.constraintlayout.widget.ConstraintLayout
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
|
|
|
@ -47,8 +47,8 @@
|
||||||
|
|
||||||
</androidx.appcompat.widget.LinearLayoutCompat>
|
</androidx.appcompat.widget.LinearLayoutCompat>
|
||||||
|
|
||||||
<androidx.viewpager2.widget.ViewPager2
|
<androidx.viewpager.widget.ViewPager
|
||||||
android:id="@+id/viewpager"
|
android:id="@+id/viewpagerNotificationContainer"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent" />
|
android:layout_height="match_parent" />
|
||||||
</LinearLayout>
|
</LinearLayout>
|
Loading…
Reference in New Issue