add button "Add"

This commit is contained in:
veliymolfar 2020-05-20 16:34:08 +03:00
parent 1f8cb06786
commit 6be48dfaca
2 changed files with 64 additions and 13 deletions

View file

@ -109,9 +109,43 @@
<ListView
android:id="@+id/list"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:divider="@null"
android:dividerHeight="0dp"
android:drawSelectorOnTop="true" />
<include layout="@layout/divider" />
<FrameLayout
android:id="@+id/add_button"
android:layout_width="match_parent"
android:layout_height="@dimen/dialog_button_ex_height"
android:background="?attr/bg_color"
android:visibility="gone">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="@dimen/dialog_button_height"
android:layout_gravity="center"
android:layout_marginStart="@dimen/content_padding"
android:layout_marginEnd="@dimen/content_padding"
android:background="?attr/dlg_btn_primary"
android:gravity="center"
android:orientation="vertical">
<androidx.appcompat.widget.AppCompatTextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:background="?attr/selectableItemBackground"
android:gravity="center"
android:text="@string/shared_string_add"
android:textColor="@color/color_white"
android:textSize="@dimen/default_list_text_size" />
</LinearLayout>
</FrameLayout>
</LinearLayout>

View file

@ -10,6 +10,7 @@ import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.EditText;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;
@ -53,6 +54,7 @@ public class QuickSearchSubCategoriesFragment extends BaseOsmAndDialogFragment {
private View headerSelectAll;
private View headerShadow;
private View footerShadow;
private FrameLayout addButton;
private boolean selectAll;
private boolean nightMode;
@ -91,6 +93,7 @@ public class QuickSearchSubCategoriesFragment extends BaseOsmAndDialogFragment {
public void onCategoryClick(boolean allSelected) {
selectAll = allSelected;
selectAllSwitch.setChecked(allSelected);
updateAddBtnVisibility();
}
});
if (selectAll || acceptedCategories == null) {
@ -126,16 +129,19 @@ public class QuickSearchSubCategoriesFragment extends BaseOsmAndDialogFragment {
toolbar.setNavigationOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
LinkedHashSet<String> list = new LinkedHashSet<>();
for (PoiType poiType : adapter.getSelectedItems()) {
list.add(poiType.getKeyName());
}
listener.onFiltersSelected(poiCategory, list);
dismiss();
dismissFragment();
}
});
TextView title = root.findViewById(R.id.title);
title.setText(poiCategory.getTranslation());
addButton = root.findViewById(R.id.add_button);
updateAddBtnVisibility();
addButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
dismissFragment();
}
});
listView = root.findViewById(R.id.list);
headerShadow = inflater.inflate(R.layout.list_shadow_header, listView, false);
footerShadow = inflater.inflate(R.layout.list_shadow_footer, listView, false);
@ -148,6 +154,7 @@ public class QuickSearchSubCategoriesFragment extends BaseOsmAndDialogFragment {
selectAll = !selectAll;
selectAllSwitch.setChecked(selectAll);
adapter.selectAll(selectAll);
updateAddBtnVisibility();
}
});
listView.addFooterView(footerShadow);
@ -193,12 +200,7 @@ public class QuickSearchSubCategoriesFragment extends BaseOsmAndDialogFragment {
if (event.getAction() == KeyEvent.ACTION_DOWN) {
return true;
} else {
LinkedHashSet<String> list = new LinkedHashSet<>();
for (PoiType poiType : adapter.getSelectedItems()) {
list.add(poiType.getKeyName());
}
listener.onFiltersSelected(poiCategory, list);
dismiss();
dismissFragment();
return true;
}
}
@ -207,6 +209,21 @@ public class QuickSearchSubCategoriesFragment extends BaseOsmAndDialogFragment {
});
}
private void updateAddBtnVisibility() {
if (addButton != null) {
addButton.setVisibility(adapter.getSelectedItems().isEmpty() ? View.GONE : View.VISIBLE);
}
}
private void dismissFragment() {
LinkedHashSet<String> list = new LinkedHashSet<>();
for (PoiType poiType : adapter.getSelectedItems()) {
list.add(poiType.getKeyName());
}
listener.onFiltersSelected(poiCategory, list);
dismiss();
}
private void clearSearch() {
searchEditText.setText("");
AndroidUtils.hideSoftKeyboard(requireActivity(), searchEditText);