Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -22,17 +23,24 @@
public class ImageFragment extends Fragment implements ImageAdapter.OnImageClickListener {

private ArrayList<Bitmap> 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<Integer> stickers = (ArrayList<Integer>) getActivity().getIntent().getExtras().getSerializable("stickers");
ArrayList<Integer> stickers = bdl.getIntegerArrayList("stickers");
String title = bdl.getString("stickersTitle");
stickersTitle = title;

if (stickers != null && stickers.size() > 0) {
stickerBitmaps = new ArrayList<>();
Expand All @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -179,19 +181,38 @@ protected void onCreate(Bundle savedInstanceState) {

final List<Fragment> fragmentsList = new ArrayList<>();

ImageFragment imageFragment = new ImageFragment();
ArrayList stickers = (ArrayList<Integer>) getIntent().getExtras().getSerializable("stickers");
if (stickers != null && stickers.size() > 0) {
ArrayList<String> 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);
Expand All @@ -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
Expand Down Expand Up @@ -691,7 +716,7 @@ public Fragment getItem(int position) {

@Override
public int getCount() {
return 2;
return mFragments.size();
}
}

Expand Down
35 changes: 30 additions & 5 deletions android/src/main/java/ui/photoeditor/RNPhotoEditorModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<Integer> stickersIntent = new ArrayList<Integer>();
ArrayList<ArrayList> mulptipleStickersIntentMain = new ArrayList<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<Integer> mulptipleStickersIntent = new ArrayList<Integer>();
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<>();
Expand All @@ -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;
Expand Down
21 changes: 18 additions & 3 deletions android/src/main/res/layout/fragment_main_photo_edit_image.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,24 @@
android:layout_width="match_parent"
android:layout_height="match_parent">

<androidx.recyclerview.widget.RecyclerView
android:id="@+id/fragment_main_photo_edit_image_rv"
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" />
android:layout_height="match_parent"
android:orientation="vertical">

<TextView
android:id="@+id/stickersTitleText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:textColor="#FFFFFF"
android:textSize="16sp"
android:textStyle="bold" />

<androidx.recyclerview.widget.RecyclerView
android:id="@+id/fragment_main_photo_edit_image_rv"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>

</RelativeLayout>
4 changes: 3 additions & 1 deletion index.d.ts
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -12,6 +13,7 @@ export default class PhotoEditor {
static Edit({
stickers,
hiddenControls,
stickersTitle,
colors,
onDone,
onCancel,
Expand Down
13 changes: 11 additions & 2 deletions index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -16,6 +17,7 @@ export default class PhotoEditor {
private static defaultProps = {
stickers: [],
hiddenControls: [],
stickersTitle: [],
colors: [
'#000000',
'#808080',
Expand All @@ -39,20 +41,27 @@ 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
}
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)
},
Expand Down