This commit is contained in:
Grishka 2024-02-24 03:57:43 +03:00
parent d0e33c8a12
commit b3e53bc48d
4 changed files with 72 additions and 17 deletions

View File

@ -37,14 +37,14 @@ import me.grishka.appkit.fragments.OnBackPressedListener;
import me.grishka.appkit.utils.V;
public class FilterWordsFragment extends BaseSettingsFragment<FilterKeyword> implements OnBackPressedListener{
private ImageButton fab;
private Button fab;
private ActionMode actionMode;
private ArrayList<ListItem<FilterKeyword>> selectedItems=new ArrayList<>();
private ArrayList<String> deletedItemIDs=new ArrayList<>();
private MenuItem deleteItem;
public FilterWordsFragment(){
setListLayoutId(R.layout.recycler_fragment_with_fab);
setListLayoutId(R.layout.recycler_fragment_with_text_fab);
}
@Override
@ -92,18 +92,14 @@ public class FilterWordsFragment extends BaseSettingsFragment<FilterKeyword> imp
public void onViewCreated(View view, Bundle savedInstanceState){
super.onViewCreated(view, savedInstanceState);
fab=view.findViewById(R.id.fab);
fab.setImageResource(R.drawable.ic_add_24px);
fab.setContentDescription(getString(R.string.add_muted_word));
fab.setCompoundDrawablesRelativeWithIntrinsicBounds(R.drawable.ic_add_24px, 0, 0, 0);
fab.setText(R.string.add_muted_word_short);
fab.setOnClickListener(v->onFabClick());
}
@Override
public void onApplyWindowInsets(WindowInsets insets){
int fabInset=0;
if(Build.VERSION.SDK_INT>=29 && insets.getTappableElementInsets().bottom==0){
fabInset=insets.getSystemWindowInsetBottom();
}
((ViewGroup.MarginLayoutParams) fab.getLayoutParams()).bottomMargin=V.dp(16)+fabInset;
UiUtils.applyBottomInsetToFAB(fab, insets);
super.onApplyWindowInsets(insets);
}

View File

@ -1,6 +1,9 @@
package org.joinmastodon.android.fragments.settings;
import android.os.Bundle;
import android.view.View;
import android.view.WindowInsets;
import android.widget.Button;
import com.squareup.otto.Subscribe;
@ -12,6 +15,7 @@ import org.joinmastodon.android.events.SettingsFilterDeletedEvent;
import org.joinmastodon.android.model.Filter;
import org.joinmastodon.android.model.viewmodel.ListItem;
import org.joinmastodon.android.ui.adapters.GenericListItemsAdapter;
import org.joinmastodon.android.ui.utils.UiUtils;
import org.parceler.Parcels;
import java.util.Collections;
@ -24,6 +28,12 @@ import me.grishka.appkit.api.SimpleCallback;
import me.grishka.appkit.utils.MergeRecyclerAdapter;
public class SettingsFiltersFragment extends BaseSettingsFragment<Filter>{
private Button fab;
public SettingsFiltersFragment(){
setListLayoutId(R.layout.recycler_fragment_with_text_fab);
}
@Override
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
@ -53,13 +63,12 @@ public class SettingsFiltersFragment extends BaseSettingsFragment<Filter>{
}
@Override
protected RecyclerView.Adapter<?> getAdapter(){
MergeRecyclerAdapter adapter=new MergeRecyclerAdapter();
adapter.addAdapter(super.getAdapter());
adapter.addAdapter(new GenericListItemsAdapter<>(Collections.singletonList(
new ListItem<Void>(R.string.settings_add_filter, 0, R.drawable.ic_add_24px, this::onAddFilterClick)
)));
return adapter;
public void onViewCreated(View view, Bundle savedInstanceState){
super.onViewCreated(view, savedInstanceState);
fab=view.findViewById(R.id.fab);
fab.setText(R.string.settings_add_filter);
fab.setCompoundDrawablesRelativeWithIntrinsicBounds(R.drawable.ic_add_24px, 0, 0, 0);
fab.setOnClickListener(v->onAddFilterClick());
}
private void onFilterClick(ListItem<Filter> filter){
@ -69,7 +78,7 @@ public class SettingsFiltersFragment extends BaseSettingsFragment<Filter>{
Nav.go(getActivity(), EditFilterFragment.class, args);
}
private void onAddFilterClick(ListItem<?> item){
private void onAddFilterClick(){
Bundle args=new Bundle();
args.putString("account", accountID);
Nav.go(getActivity(), EditFilterFragment.class, args);
@ -109,4 +118,10 @@ public class SettingsFiltersFragment extends BaseSettingsFragment<Filter>{
data.add(makeListItem(ev.filter));
itemsAdapter.notifyItemInserted(data.size()-1);
}
@Override
public void onApplyWindowInsets(WindowInsets insets){
UiUtils.applyBottomInsetToFAB(fab, insets);
super.onApplyWindowInsets(insets);
}
}

View File

@ -0,0 +1,43 @@
<?xml version="1.0" encoding="utf-8"?>
<me.grishka.appkit.views.RecursiveSwipeRefreshLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/refresh_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<FrameLayout
android:id="@+id/content_wrap"
android:layout_width="match_parent"
android:layout_height="match_parent">
<me.grishka.appkit.views.UsableRecyclerView
android:id="@+id/list"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scrollbars="vertical"
android:clipToPadding="false"/>
<ViewStub android:layout="?emptyViewLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/empty"/>
<Button
android:id="@+id/fab"
android:layout_width="wrap_content"
android:layout_height="56dp"
android:layout_gravity="end|bottom"
android:layout_marginEnd="16dp"
android:layout_marginBottom="16dp"
android:background="@drawable/bg_fab"
android:textColor="?colorM3Primary"
android:drawableTint="?colorM3Primary"
android:stateListAnimator="@animator/fab_shadow"
android:paddingStart="16dp"
android:paddingEnd="20dp"
android:drawablePadding="12dp"
android:textAppearance="@style/m3_label_large"
tools:text="Some text"
tools:drawableStart="@drawable/ic_edit_24px"/>
</FrameLayout>
</me.grishka.appkit.views.RecursiveSwipeRefreshLayout>

View File

@ -712,4 +712,5 @@
<string name="copy_profile_link">Copy link to profile</string>
<string name="in_app_browser">In-app browser</string>
<string name="system_browser">System browser</string>
<string name="add_muted_word_short">Add word</string>
</resources>