|
@@ -20,14 +20,13 @@ import androidx.activity.result.ActivityResultLauncher;
|
|
|
import androidx.activity.result.contract.ActivityResultContracts;
|
|
|
import androidx.annotation.NonNull;
|
|
|
import androidx.annotation.Nullable;
|
|
|
-import androidx.appcompat.widget.AppCompatTextView;
|
|
|
import androidx.recyclerview.widget.GridLayoutManager;
|
|
|
import androidx.recyclerview.widget.RecyclerView;
|
|
|
|
|
|
import com.compdfkit.core.annotation.CPDFStampAnnotation;
|
|
|
import com.compdfkit.tools.R;
|
|
|
-import com.compdfkit.tools.annotation.pdfproperties.pdfstamp.adapter.CImageStampListAdapter;
|
|
|
-import com.compdfkit.tools.annotation.pdfproperties.pdfstamp.adapter.CTextStampAdapter;
|
|
|
+import com.compdfkit.tools.annotation.pdfproperties.pdfstamp.adapter.CustomStampAdapter;
|
|
|
+import com.compdfkit.tools.annotation.pdfproperties.pdfstamp.bean.CCustomStampBean;
|
|
|
import com.compdfkit.tools.annotation.pdfproperties.pdfstamp.bean.CTextStampBean;
|
|
|
import com.compdfkit.tools.annotation.pdfproperties.pdfstamp.data.CStampDatas;
|
|
|
import com.compdfkit.tools.common.utils.dialog.CAlertDialog;
|
|
@@ -36,22 +35,15 @@ import com.compdfkit.tools.common.utils.threadpools.CThreadPoolUtils;
|
|
|
import com.compdfkit.tools.common.views.pdfproperties.basic.CBasicPropertiesFragment;
|
|
|
import com.google.android.material.floatingactionbutton.FloatingActionButton;
|
|
|
|
|
|
+import java.util.ArrayList;
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
|
public class CStampCustomFragment extends CBasicPropertiesFragment {
|
|
|
|
|
|
- private RecyclerView rvTextStamp;
|
|
|
+ private RecyclerView rvCustomStamp;
|
|
|
|
|
|
- private AppCompatTextView tvTextStampTitle;
|
|
|
-
|
|
|
- private RecyclerView rvImageStamp;
|
|
|
-
|
|
|
- private AppCompatTextView tvImageStampTitle;
|
|
|
-
|
|
|
- private CTextStampAdapter textStampAdapter;
|
|
|
-
|
|
|
- private CImageStampListAdapter imageStampListAdapter;
|
|
|
+ private CustomStampAdapter customStampAdapter;
|
|
|
|
|
|
private ActivityResultLauncher<Intent> addStampLauncher = registerForActivityResult(new ActivityResultContracts.StartActivityForResult(), result -> {
|
|
|
if (result.getData() != null && result.getData().getStringExtra("file_path") != null) {
|
|
@@ -71,10 +63,7 @@ public class CStampCustomFragment extends CBasicPropertiesFragment {
|
|
|
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
|
|
|
View rootView = inflater.inflate(R.layout.tools_properties_stamp_custom_list_fragment, container, false);
|
|
|
FloatingActionButton fabAdd = rootView.findViewById(R.id.fab_add_custom_stamp);
|
|
|
- rvTextStamp = rootView.findViewById(R.id.rv_custom_text_stamp);
|
|
|
- tvTextStampTitle = rootView.findViewById(R.id.tv_custom_text_stamp_title);
|
|
|
- rvImageStamp = rootView.findViewById(R.id.rv_custom_image_stamp);
|
|
|
- tvImageStampTitle = rootView.findViewById(R.id.tv_custom_image_stamp_title);
|
|
|
+ rvCustomStamp = rootView.findViewById(R.id.rv_custom_stamp);
|
|
|
fabAdd.setOnClickListener(v -> {
|
|
|
CAddStampSwichDialogFragment addStampDialog = CAddStampSwichDialogFragment.newInstance();
|
|
|
addStampDialog.setAddTextStampClickListener(v1 -> {
|
|
@@ -86,6 +75,7 @@ public class CStampCustomFragment extends CBasicPropertiesFragment {
|
|
|
importImageDialogFragment.setImportImageListener(imageUri -> {
|
|
|
if (imageUri != null) {
|
|
|
CStampDatas.saveStampImage(getContext(), imageUri);
|
|
|
+
|
|
|
refreshStampList();
|
|
|
}
|
|
|
importImageDialogFragment.dismiss();
|
|
@@ -102,7 +92,6 @@ public class CStampCustomFragment extends CBasicPropertiesFragment {
|
|
|
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
|
|
|
super.onViewCreated(view, savedInstanceState);
|
|
|
initTextStampList();
|
|
|
- initImageStampList();
|
|
|
refreshStampList();
|
|
|
}
|
|
|
|
|
@@ -111,119 +100,96 @@ public class CStampCustomFragment extends CBasicPropertiesFragment {
|
|
|
gridLayoutManager.setSpanSizeLookup(new GridLayoutManager.SpanSizeLookup() {
|
|
|
@Override
|
|
|
public int getSpanSize(int position) {
|
|
|
- boolean isPortrait = getContext().getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT;
|
|
|
- return isPortrait ? 2 : 1;
|
|
|
- }
|
|
|
- });
|
|
|
- rvTextStamp.setLayoutManager(gridLayoutManager);
|
|
|
- rvTextStamp.setNestedScrollingEnabled(false);
|
|
|
- textStampAdapter = new CTextStampAdapter();
|
|
|
- textStampAdapter.setOnItemClickListener((adapter, view, position) -> {
|
|
|
- if (viewModel != null) {
|
|
|
- CTextStampBean bean = adapter.list.get(position);
|
|
|
- CPDFStampAnnotation.TextStamp textStamp = new CPDFStampAnnotation.TextStamp(
|
|
|
- bean.getTextContent(),
|
|
|
- bean.getDateStr(),
|
|
|
- bean.getTextStampShapeId(),
|
|
|
- bean.getTextStampColorId());
|
|
|
- viewModel.getStyle().setTextStamp(textStamp);
|
|
|
- dismissStyleDialog();
|
|
|
- }
|
|
|
- });
|
|
|
- textStampAdapter.addOnItemChildClickListener(R.id.iv_delete, (adapter, view, position) -> {
|
|
|
- CAlertDialog alertDialog = CAlertDialog.newInstance(getString(R.string.tools_warning), getString(R.string.tools_are_you_sure_to_delete));
|
|
|
- alertDialog.setCancelClickListener(v -> alertDialog.dismiss());
|
|
|
- alertDialog.setConfirmClickListener(v -> {
|
|
|
- CTextStampBean bean = adapter.list.get(position);
|
|
|
- CStampDatas.removeStamp(bean.getFilePath());
|
|
|
- textStampAdapter.remove(position);
|
|
|
- if (textStampAdapter.list.size() == 0){
|
|
|
- tvTextStampTitle.setVisibility(View.GONE);
|
|
|
+ int itemType = customStampAdapter.getItemViewType(position);
|
|
|
+ switch (itemType){
|
|
|
+ case CCustomStampBean.ITEM_TEXT_STAMP_TITLE:
|
|
|
+ case CCustomStampBean.ITEM_IMAGE_STAMP_TITLE:
|
|
|
+ return 2;
|
|
|
+ default:
|
|
|
+ boolean isPortrait = getContext().getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT;
|
|
|
+ return isPortrait ? 2 : 1;
|
|
|
}
|
|
|
- alertDialog.dismiss();
|
|
|
- });
|
|
|
- alertDialog.show(getChildFragmentManager(), "alertDialog");
|
|
|
- });
|
|
|
- rvTextStamp.setAdapter(textStampAdapter);
|
|
|
- }
|
|
|
-
|
|
|
- private void initImageStampList() {
|
|
|
- GridLayoutManager gridLayoutManager = new GridLayoutManager(getContext(), 2);
|
|
|
- gridLayoutManager.setSpanSizeLookup(new GridLayoutManager.SpanSizeLookup() {
|
|
|
- @Override
|
|
|
- public int getSpanSize(int position) {
|
|
|
- boolean isPortrait = getContext().getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT;
|
|
|
- return isPortrait ? 2 : 1;
|
|
|
}
|
|
|
});
|
|
|
- rvImageStamp.setLayoutManager(gridLayoutManager);
|
|
|
- rvImageStamp.setNestedScrollingEnabled(false);
|
|
|
- imageStampListAdapter = new CImageStampListAdapter();
|
|
|
- imageStampListAdapter.setOnItemClickListener((adapter, view, position) -> {
|
|
|
+ rvCustomStamp.setLayoutManager(gridLayoutManager);
|
|
|
+ customStampAdapter = new CustomStampAdapter();
|
|
|
+ customStampAdapter.setOnItemClickListener((adapter, view, position) -> {
|
|
|
if (viewModel != null) {
|
|
|
- String imagePath = adapter.list.get(position);
|
|
|
- viewModel.getStyle().setImagePath(imagePath);
|
|
|
- dismissStyleDialog();
|
|
|
+ CCustomStampBean bean = adapter.list.get(position);
|
|
|
+ switch (bean.getItemType()) {
|
|
|
+ case CCustomStampBean.ITEM_TEXT_STAMP:
|
|
|
+ CTextStampBean textStampBean = bean.getTextStampBean();
|
|
|
+ CPDFStampAnnotation.TextStamp textStamp = new CPDFStampAnnotation.TextStamp(
|
|
|
+ textStampBean.getTextContent(),
|
|
|
+ textStampBean.getDateStr(),
|
|
|
+ textStampBean.getTextStampShapeId(),
|
|
|
+ textStampBean.getTextStampColorId());
|
|
|
+ viewModel.getStyle().setTextStamp(textStamp);
|
|
|
+ dismissStyleDialog();
|
|
|
+ break;
|
|
|
+ case CCustomStampBean.ITEM_IMAGE_STAMP:
|
|
|
+ String imagePath = adapter.list.get(position).getImageStampPath();
|
|
|
+ viewModel.getStyle().setImagePath(imagePath);
|
|
|
+ dismissStyleDialog();
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ break;
|
|
|
+ }
|
|
|
}
|
|
|
});
|
|
|
- imageStampListAdapter.addOnItemChildClickListener(R.id.iv_delete, (adapter, view, position) -> {
|
|
|
+ customStampAdapter.addOnItemChildClickListener(R.id.iv_delete, (adapter, view, position) -> {
|
|
|
CAlertDialog alertDialog = CAlertDialog.newInstance(getString(R.string.tools_warning), getString(R.string.tools_are_you_sure_to_delete));
|
|
|
alertDialog.setCancelClickListener(v -> alertDialog.dismiss());
|
|
|
alertDialog.setConfirmClickListener(v -> {
|
|
|
- String imagePath = adapter.list.get(position);
|
|
|
- CStampDatas.removeStamp(imagePath);
|
|
|
- imageStampListAdapter.remove(position);
|
|
|
- if (imageStampListAdapter.list.size() == 0){
|
|
|
- tvImageStampTitle.setVisibility(View.GONE);
|
|
|
+ CCustomStampBean bean = adapter.list.get(position);
|
|
|
+ switch (bean.getItemType()) {
|
|
|
+ case CCustomStampBean.ITEM_TEXT_STAMP:
|
|
|
+ CStampDatas.removeStamp(bean.getTextStampBean().getFilePath());
|
|
|
+ customStampAdapter.remove(position);
|
|
|
+ customStampAdapter.checkRemoveTextStampTitle();
|
|
|
+ alertDialog.dismiss();
|
|
|
+ break;
|
|
|
+ case CCustomStampBean.ITEM_IMAGE_STAMP:
|
|
|
+ String imagePath = adapter.list.get(position).getImageStampPath();
|
|
|
+ CStampDatas.removeStamp(imagePath);
|
|
|
+ customStampAdapter.remove(position);
|
|
|
+ customStampAdapter.checkRemoveImageStampTitle();
|
|
|
+ alertDialog.dismiss();
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ break;
|
|
|
}
|
|
|
- alertDialog.dismiss();
|
|
|
});
|
|
|
alertDialog.show(getChildFragmentManager(), "alertDialog");
|
|
|
});
|
|
|
- rvImageStamp.setAdapter(imageStampListAdapter);
|
|
|
+ rvCustomStamp.setAdapter(customStampAdapter);
|
|
|
}
|
|
|
|
|
|
private void refreshStampList() {
|
|
|
CThreadPoolUtils.getInstance().executeIO(() -> {
|
|
|
try {
|
|
|
if (getContext() != null) {
|
|
|
- List<CTextStampBean> list = CStampDatas.getTextStampList(getContext());
|
|
|
- if (textStampAdapter != null) {
|
|
|
- textStampAdapter.setList(list);
|
|
|
+ List<CCustomStampBean> lists = new ArrayList<>();
|
|
|
+ List<CTextStampBean> textStampList = CStampDatas.getTextStampList(getContext());
|
|
|
+ for (int i = 0; i < textStampList.size(); i++) {
|
|
|
+ if (i == 0){
|
|
|
+ lists.add(CCustomStampBean.headItem(getString(R.string.tools_text_stamp), CCustomStampBean.ITEM_TEXT_STAMP_TITLE));
|
|
|
+ }
|
|
|
+ lists.add(new CCustomStampBean(textStampList.get(i)));
|
|
|
}
|
|
|
- checkShowStampTitle();
|
|
|
- }
|
|
|
- }catch (Exception e){
|
|
|
-
|
|
|
- }
|
|
|
- });
|
|
|
- CThreadPoolUtils.getInstance().executeIO(() -> {
|
|
|
- try {
|
|
|
- if (getContext() != null) {
|
|
|
- List<String> list = CStampDatas.getImageStampList(getContext());
|
|
|
- if (imageStampListAdapter != null) {
|
|
|
- imageStampListAdapter.setList(list);
|
|
|
+ List<String> imageStampList = CStampDatas.getImageStampList(getContext());
|
|
|
+ for (int i = 0; i < imageStampList.size(); i++) {
|
|
|
+ if (i == 0){
|
|
|
+ lists.add(CCustomStampBean.headItem(getString(R.string.tools_image_stamp), CCustomStampBean.ITEM_IMAGE_STAMP_TITLE));
|
|
|
+ }
|
|
|
+ lists.add(new CCustomStampBean(imageStampList.get(i)));
|
|
|
}
|
|
|
- checkShowStampTitle();
|
|
|
+ CThreadPoolUtils.getInstance().executeMain(()->{
|
|
|
+ customStampAdapter.setList(lists);
|
|
|
+ });
|
|
|
}
|
|
|
- }catch (Exception e){
|
|
|
-
|
|
|
+ } catch (Exception e) {
|
|
|
}
|
|
|
});
|
|
|
}
|
|
|
-
|
|
|
- private void checkShowStampTitle() {
|
|
|
- if (getActivity() != null) {
|
|
|
- getActivity().runOnUiThread(()->{
|
|
|
- if (tvTextStampTitle != null) {
|
|
|
- boolean show = textStampAdapter != null && textStampAdapter.list.size() > 0;
|
|
|
- tvTextStampTitle.setVisibility(show ? View.VISIBLE : View.GONE);
|
|
|
- }
|
|
|
- if (tvImageStampTitle != null) {
|
|
|
- boolean show = imageStampListAdapter != null && imageStampListAdapter.list.size() > 0;
|
|
|
- tvImageStampTitle.setVisibility(show ? View.VISIBLE : View.GONE);
|
|
|
- }
|
|
|
- });
|
|
|
- }
|
|
|
- }
|
|
|
}
|