diff --git a/android/src/main/java/com/ahmedadeltito/photoeditor/ImageFragment.java b/android/src/main/java/com/ahmedadeltito/photoeditor/ImageFragment.java index 7cd9ea99..6428d171 100755 --- a/android/src/main/java/com/ahmedadeltito/photoeditor/ImageFragment.java +++ b/android/src/main/java/com/ahmedadeltito/photoeditor/ImageFragment.java @@ -12,6 +12,7 @@ import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; +import android.widget.TextView; import java.util.ArrayList; import ui.photoeditor.R; @@ -22,17 +23,24 @@ public class ImageFragment extends Fragment implements ImageAdapter.OnImageClickListener { private ArrayList stickerBitmaps; + private String stickersTitle; private PhotoEditorActivity photoEditorActivity; RecyclerView imageRecyclerView; + TextView stickersTitleText; @Override public void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); photoEditorActivity = (PhotoEditorActivity) getActivity(); + final Bundle bdl = getArguments(); + TypedArray images = getResources().obtainTypedArray(R.array.photo_editor_photos); + Boolean mulptipleStickers = getActivity().getIntent().getExtras().getBoolean("mulptipleStickers"); - ArrayList stickers = (ArrayList) getActivity().getIntent().getExtras().getSerializable("stickers"); + ArrayList stickers = bdl.getIntegerArrayList("stickers"); + String title = bdl.getString("stickersTitle"); + stickersTitle = title; if (stickers != null && stickers.size() > 0) { stickerBitmaps = new ArrayList<>(); @@ -54,10 +62,13 @@ public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, View rootView = inflater.inflate(R.layout.fragment_main_photo_edit_image, container, false); imageRecyclerView = (RecyclerView) rootView.findViewById(R.id.fragment_main_photo_edit_image_rv); + stickersTitleText = (TextView) rootView.findViewById(R.id.stickersTitleText); imageRecyclerView.setLayoutManager(new GridLayoutManager(photoEditorActivity, 3)); ImageAdapter adapter = new ImageAdapter(photoEditorActivity, stickerBitmaps); adapter.setOnImageClickListener(this); imageRecyclerView.setAdapter(adapter); + if(stickersTitle != null) + stickersTitleText.setText(stickersTitle); return rootView; } diff --git a/android/src/main/java/com/ahmedadeltito/photoeditor/PhotoEditorActivity.java b/android/src/main/java/com/ahmedadeltito/photoeditor/PhotoEditorActivity.java index 9bf2eb71..624ad9c7 100755 --- a/android/src/main/java/com/ahmedadeltito/photoeditor/PhotoEditorActivity.java +++ b/android/src/main/java/com/ahmedadeltito/photoeditor/PhotoEditorActivity.java @@ -57,6 +57,7 @@ import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; +import java.io.Serializable; import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Date; @@ -90,6 +91,7 @@ public class PhotoEditorActivity extends AppCompatActivity implements View.OnCli private PhotoEditorSDK photoEditorSDK; private String selectedImagePath; private int imageOrientation; + private boolean isMulptipleStickers; // CROP OPTION private boolean cropperCircleOverlay = false; @@ -179,19 +181,38 @@ protected void onCreate(Bundle savedInstanceState) { final List fragmentsList = new ArrayList<>(); - ImageFragment imageFragment = new ImageFragment(); ArrayList stickers = (ArrayList) getIntent().getExtras().getSerializable("stickers"); - if (stickers != null && stickers.size() > 0) { + ArrayList stickersTitle = getIntent().getExtras().getStringArrayList("stickersTitle"); + + Boolean mulptipleStickers = getIntent().getExtras().getBoolean("mulptipleStickers"); + isMulptipleStickers = mulptipleStickers; + + if (stickers != null && stickers.size() > 0 && mulptipleStickers) { + + + for (int k = 0;k < stickers.size();k++) { + ImageFragment imageFragment = new ImageFragment(); + + Bundle bundle = new Bundle(); + bundle.putSerializable("stickers", (Serializable) stickers.get(k)); + if(!stickersTitle.isEmpty() && stickersTitle.size() > k) { + bundle.putSerializable("stickersTitle", stickersTitle.get(k)); + } + + imageFragment.setArguments(bundle); + fragmentsList.add(imageFragment); + } + } else { + ImageFragment imageFragment = new ImageFragment(); + Bundle bundle = new Bundle(); bundle.putSerializable("stickers", stickers); - imageFragment.setArguments(bundle); - } + fragmentsList.add(imageFragment); - fragmentsList.add(imageFragment); - - EmojiFragment emojiFragment = new EmojiFragment(); - fragmentsList.add(emojiFragment); + EmojiFragment emojiFragment = new EmojiFragment(); + fragmentsList.add(emojiFragment); + } PreviewSlidePagerAdapter adapter = new PreviewSlidePagerAdapter(getSupportFragmentManager(), fragmentsList); pager.setAdapter(adapter); @@ -215,10 +236,14 @@ public void onPageScrolled(int position, float positionOffset, int positionOffse @Override public void onPageSelected(int position) { - if (position == 0) + if(isMulptipleStickers) { mLayout.setScrollableView(((ImageFragment) fragmentsList.get(position)).imageRecyclerView); - else if (position == 1) - mLayout.setScrollableView(((EmojiFragment) fragmentsList.get(position)).emojiRecyclerView); + } else { + if (position == 0) + mLayout.setScrollableView(((ImageFragment) fragmentsList.get(position)).imageRecyclerView); + else if (position == 1) + mLayout.setScrollableView(((EmojiFragment) fragmentsList.get(position)).emojiRecyclerView); + } } @Override @@ -691,7 +716,7 @@ public Fragment getItem(int position) { @Override public int getCount() { - return 2; + return mFragments.size(); } } diff --git a/android/src/main/java/ui/photoeditor/RNPhotoEditorModule.java b/android/src/main/java/ui/photoeditor/RNPhotoEditorModule.java index 658956f6..e3579b73 100644 --- a/android/src/main/java/ui/photoeditor/RNPhotoEditorModule.java +++ b/android/src/main/java/ui/photoeditor/RNPhotoEditorModule.java @@ -65,17 +65,29 @@ public String getName() { @ReactMethod public void Edit(final ReadableMap props, final Callback onDone, final Callback onCancel) { String path = props.getString("path"); + Boolean mulptipleStickers = props.getBoolean("mulptipleStickers"); //Process Stickers ReadableArray stickers = props.getArray("stickers"); ArrayList stickersIntent = new ArrayList(); + ArrayList mulptipleStickersIntentMain = new ArrayList(); for (int i = 0;i < stickers.size();i++) { - int drawableId = getReactApplicationContext().getResources().getIdentifier(stickers.getString(i), "drawable", getReactApplicationContext().getPackageName()); - stickersIntent.add(drawableId); - } + if(mulptipleStickers) { + ArrayList mulptipleStickersIntent = new ArrayList(); + for (int k = 0;k < stickers.getArray(i).size();k++) { + int drawableId = getReactApplicationContext().getResources().getIdentifier(stickers.getArray(i).getString(k), "drawable", getReactApplicationContext().getPackageName()); + mulptipleStickersIntent.add(drawableId); + } + mulptipleStickersIntentMain.add(mulptipleStickersIntent); + } else { + int drawableId = getReactApplicationContext().getResources().getIdentifier(stickers.getString(i), "drawable", getReactApplicationContext().getPackageName()); + stickersIntent.add(drawableId); + } + + } //Process Hidden Controls ReadableArray hiddenControls = props.getArray("hiddenControls"); ArrayList hiddenControlsIntent = new ArrayList<>(); @@ -87,17 +99,30 @@ public void Edit(final ReadableMap props, final Callback onDone, final Callback //Process Colors ReadableArray colors = props.getArray("colors"); ArrayList colorPickerColors = new ArrayList<>(); - for (int i = 0;i < colors.size();i++) { colorPickerColors.add(Color.parseColor(colors.getString(i))); } + //Process stickersTitle + ReadableArray stickersTitle = props.getArray("stickersTitle"); + ArrayList stickersTitles = new ArrayList<>(); + for (int i = 0;i < stickersTitle.size();i++) { + stickersTitles.add(stickersTitle.getString(i)); + } + + Intent intent = new Intent(getCurrentActivity(), PhotoEditorActivity.class); intent.putExtra("selectedImagePath", path); intent.putExtra("colorPickerColors", colorPickerColors); + intent.putExtra("stickersTitle", stickersTitles); intent.putExtra("hiddenControls", hiddenControlsIntent); - intent.putExtra("stickers", stickersIntent); + if(mulptipleStickers) { + intent.putExtra("stickers", mulptipleStickersIntentMain); + } else { + intent.putExtra("stickers", stickersIntent); + } + intent.putExtra("mulptipleStickers", mulptipleStickers); mCancelCallback = onCancel; diff --git a/android/src/main/res/layout/fragment_main_photo_edit_image.xml b/android/src/main/res/layout/fragment_main_photo_edit_image.xml index 4c683f3c..82a068f8 100644 --- a/android/src/main/res/layout/fragment_main_photo_edit_image.xml +++ b/android/src/main/res/layout/fragment_main_photo_edit_image.xml @@ -2,9 +2,24 @@ android:layout_width="match_parent" android:layout_height="match_parent"> - + android:layout_height="match_parent" + android:orientation="vertical"> + + + + + \ No newline at end of file diff --git a/index.d.ts b/index.d.ts index bf48b405..f5734c1d 100644 --- a/index.d.ts +++ b/index.d.ts @@ -1,7 +1,8 @@ export interface PhotoEditorProps { path: string + stickersTitle?: string[] colors?: string[] - stickers?: string[] + stickers?: any[] hiddenControls?: ('text' | 'clear' | 'draw' | 'save' | 'share' | 'sticker' | 'crop')[] onDone?: (imagePath: string) => void @@ -12,6 +13,7 @@ export default class PhotoEditor { static Edit({ stickers, hiddenControls, + stickersTitle, colors, onDone, onCancel, diff --git a/index.tsx b/index.tsx index 7a866f8d..774424b2 100644 --- a/index.tsx +++ b/index.tsx @@ -5,7 +5,8 @@ const { RNPhotoEditor } = NativeModules export interface PhotoEditorProps { path: string colors?: string[] - stickers?: string[] + stickersTitle?: string[] + stickers?: any[] hiddenControls?: ('text' | 'clear' | 'draw' | 'save' | 'share' | 'sticker' | 'crop')[] onDone?: (imagePath: string) => void @@ -16,6 +17,7 @@ export default class PhotoEditor { private static defaultProps = { stickers: [], hiddenControls: [], + stickersTitle: [], colors: [ '#000000', '#808080', @@ -39,10 +41,14 @@ export default class PhotoEditor { colors, onDone, onCancel, + stickersTitle, ...props }: PhotoEditorProps) { + let mulptipleStickers = false; if (stickers === undefined) { stickers = this.defaultProps.stickers + } else { + mulptipleStickers = Array.isArray(stickers?.[0]); } if (hiddenControls === undefined) { hiddenControls = this.defaultProps.hiddenControls @@ -50,9 +56,12 @@ export default class PhotoEditor { if (colors === undefined) { colors = this.defaultProps.colors } + if (stickersTitle === undefined) { + stickersTitle = this.defaultProps.stickersTitle + } RNPhotoEditor.Edit( - { colors, hiddenControls, stickers, ...props }, + { colors, hiddenControls, stickers, mulptipleStickers, stickersTitle, ...props }, (imagePath: string) => { onDone && onDone(imagePath) },