|
@@ -24,14 +24,20 @@ import androidx.recyclerview.widget.LinearLayoutManager;
|
|
|
import androidx.recyclerview.widget.RecyclerView;
|
|
|
|
|
|
import com.compdfkit.core.annotation.form.CPDFWidgetItem;
|
|
|
+import com.compdfkit.core.annotation.form.CPDFWidgetItems;
|
|
|
import com.compdfkit.tools.R;
|
|
|
+import com.compdfkit.tools.common.utils.dialog.CCommonInputDialog;
|
|
|
import com.compdfkit.tools.common.utils.dialog.CDialogFragmentUtil;
|
|
|
+import com.compdfkit.tools.common.utils.dialog.CEditDialog;
|
|
|
+import com.compdfkit.tools.common.utils.viewutils.CViewUtils;
|
|
|
+import com.compdfkit.tools.common.utils.window.CPopupMenuWindow;
|
|
|
import com.compdfkit.tools.common.views.CToolBar;
|
|
|
import com.google.android.material.bottomsheet.BottomSheetBehavior;
|
|
|
import com.google.android.material.bottomsheet.BottomSheetDialogFragment;
|
|
|
import com.google.android.material.floatingactionbutton.FloatingActionButton;
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
+import java.util.Arrays;
|
|
|
import java.util.List;
|
|
|
import java.util.UUID;
|
|
|
|
|
@@ -45,7 +51,7 @@ public class CListBoxEditFragment extends BottomSheetDialogFragment {
|
|
|
|
|
|
private AppCompatButton btnDone;
|
|
|
|
|
|
- private List<CPDFWidgetItem> listBoxItems = new ArrayList<>();
|
|
|
+ private CPDFWidgetItems pdfWidgetItems;
|
|
|
|
|
|
private CListBoxItemsAdapter itemsAdapter;
|
|
|
|
|
@@ -58,8 +64,8 @@ public class CListBoxEditFragment extends BottomSheetDialogFragment {
|
|
|
return fragment;
|
|
|
}
|
|
|
|
|
|
- public void setListBoxItems(List<CPDFWidgetItem> list) {
|
|
|
- this.listBoxItems.addAll(list);
|
|
|
+ public void setPdfWidgetItems(CPDFWidgetItems pdfWidgetItems) {
|
|
|
+ this.pdfWidgetItems = pdfWidgetItems;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
@@ -67,7 +73,11 @@ public class CListBoxEditFragment extends BottomSheetDialogFragment {
|
|
|
super.onStart();
|
|
|
BottomSheetBehavior<View> behavior = BottomSheetBehavior.from((View) getView().getParent());
|
|
|
CDialogFragmentUtil.setBottomSheetDialogFragmentFullScreen(getDialog(), behavior);
|
|
|
- CDialogFragmentUtil.setDimAmount(getDialog(), 0F);
|
|
|
+ if (CViewUtils.isLandScape(getContext())){
|
|
|
+ CDialogFragmentUtil.setDimAmount(getDialog(), 2F);
|
|
|
+ }else {
|
|
|
+ CDialogFragmentUtil.setDimAmount(getDialog(), 0F);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
@Nullable
|
|
@@ -85,13 +95,47 @@ public class CListBoxEditFragment extends BottomSheetDialogFragment {
|
|
|
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
|
|
|
super.onViewCreated(view, savedInstanceState);
|
|
|
itemsAdapter = new CListBoxItemsAdapter();
|
|
|
- itemsAdapter.setList(listBoxItems);
|
|
|
+ itemsAdapter.setList(getItems());
|
|
|
+ itemsAdapter.addOnItemChildClickListener(R.id.iv_more, (adapter, view1, position) -> {
|
|
|
+ CPDFWidgetItem item = adapter.list.get(position);
|
|
|
+ CPopupMenuWindow menuWindow = new CPopupMenuWindow(getContext());
|
|
|
+ menuWindow.addItem(R.string.tools_edit, v1 -> {
|
|
|
+ CEditDialog editDialog = CEditDialog.newInstance(item.text);
|
|
|
+ editDialog.setEditListener(text -> {
|
|
|
+ item.text = text;
|
|
|
+ item.value = text;
|
|
|
+ itemsAdapter.notifyItemChanged(position, "REFRESH");
|
|
|
+ editDialog.dismiss();
|
|
|
+ });
|
|
|
+ editDialog.show(getChildFragmentManager(), "editDialog");
|
|
|
+ });
|
|
|
+ menuWindow.addItem(R.string.tools_delete, v1 -> {
|
|
|
+ itemsAdapter.remove(position);
|
|
|
+ menuWindow.dismiss();
|
|
|
+ });
|
|
|
+ menuWindow.showAsDropDown(view1);
|
|
|
+ });
|
|
|
+
|
|
|
+
|
|
|
rvList.setLayoutManager(new LinearLayoutManager(getContext()));
|
|
|
rvList.setAdapter(itemsAdapter);
|
|
|
toolBar.setBackBtnClickListener(v -> dismiss());
|
|
|
btnDone.setOnClickListener(v -> {
|
|
|
if (editListListener != null) {
|
|
|
- editListListener.widgets(itemsAdapter.list);
|
|
|
+ CPDFWidgetItem[] items = new CPDFWidgetItem[itemsAdapter.getItemCount()];
|
|
|
+ itemsAdapter.list.toArray(items);
|
|
|
+ int[] selectedIndexs = null;
|
|
|
+ CPDFWidgetItem selectedItem = getSelectedItem();
|
|
|
+ if (selectedItem != null){
|
|
|
+ for (int i = 0; i < items.length; i++) {
|
|
|
+ CPDFWidgetItem widgetItem = items[i];
|
|
|
+ if (widgetItem.text.equals(selectedItem.text)){
|
|
|
+ selectedIndexs = new int[1];
|
|
|
+ selectedIndexs[0] = i;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ editListListener.widgets(items, selectedIndexs);
|
|
|
}
|
|
|
dismiss();
|
|
|
});
|
|
@@ -105,11 +149,27 @@ public class CListBoxEditFragment extends BottomSheetDialogFragment {
|
|
|
});
|
|
|
}
|
|
|
|
|
|
+ private CPDFWidgetItem getSelectedItem(){
|
|
|
+ int[] selectedIndexs = pdfWidgetItems.getSelectedIndexes();
|
|
|
+ CPDFWidgetItem selectedItem = null;
|
|
|
+ if (selectedIndexs != null && selectedIndexs.length > 0){
|
|
|
+ selectedItem = pdfWidgetItems.getOptionByIndex(selectedIndexs[0]);
|
|
|
+ }
|
|
|
+ return selectedItem;
|
|
|
+ }
|
|
|
+
|
|
|
+ private List<CPDFWidgetItem> getItems(){
|
|
|
+ if (pdfWidgetItems == null || pdfWidgetItems.getOptions() == null){
|
|
|
+ return new ArrayList<>();
|
|
|
+ }
|
|
|
+ return Arrays.asList(pdfWidgetItems.getOptions());
|
|
|
+ }
|
|
|
+
|
|
|
public void setEditListListener(OnEditListListener editListListener) {
|
|
|
this.editListListener = editListListener;
|
|
|
}
|
|
|
|
|
|
- public interface OnEditListListener{
|
|
|
- void widgets(List<CPDFWidgetItem> widgetItems);
|
|
|
+ public interface OnEditListListener {
|
|
|
+ void widgets(CPDFWidgetItem[] widgetItems, int[] selectedIndexs);
|
|
|
}
|
|
|
}
|