Search in sources :

Example 1 with AttachFile

use of net.iGap.module.AttachFile in project iGap-Android by KianIranian-STDG.

the class CameraStoryFragment method onViewCreated.

@Override
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);
    getEventManager().addObserver(EventManager.ON_VOLUME_DOWN_KEY, this);
    galleryIcon.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            onGalleryIconClicked.onGalleryIconClicked();
        }
    });
    checkFlashMode();
    flashModeButton = new ImageView(context);
    flashModeButton.setScaleType(ImageView.ScaleType.CENTER);
    topToolPanel.addView(flashModeButton, LayoutCreator.createFrame(48, 48, Gravity.LEFT | Gravity.CENTER_VERTICAL));
    flashModeButton.setOnClickListener(currentImage -> {
        if (cameraView == null || !cameraView.isInitied()) {
            return;
        }
        String current = cameraView.getCameraSession().getCurrentFlashMode();
        String next = cameraView.getCameraSession().getNextFlashMode();
        if (current.equals(next)) {
            return;
        }
        cameraView.getCameraSession().setCurrentFlashMode(next);
        setCameraFlashModeIcon(flashModeButton, next);
    });
    flashModeButton.setContentDescription("flash mode ");
    takePicture.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            String fileName = "story_" + HelperString.getRandomFileName(3) + ".jpg";
            File cameraFile = null;
            try {
                cameraFile = new AttachFile(getActivity()).createImageFile();
            } catch (IOException e) {
                e.printStackTrace();
            }
            File finalCameraFile = cameraFile;
            CameraController.getInstance().takePicture(cameraFile, cameraView.getCameraSession(), () -> {
                if (finalCameraFile == null || getActivity() == null) {
                    return;
                }
                int orientation = 0;
                try {
                    ExifInterface ei = new ExifInterface(finalCameraFile.getAbsolutePath());
                    int exif = ei.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL);
                    switch(exif) {
                        case ExifInterface.ORIENTATION_ROTATE_90:
                            orientation = 90;
                            break;
                        case ExifInterface.ORIENTATION_ROTATE_180:
                            orientation = 180;
                            break;
                        case ExifInterface.ORIENTATION_ROTATE_270:
                            orientation = 270;
                            break;
                    }
                } catch (Exception e) {
                    FileLog.e(e);
                }
                // CameraController.getInstance().initCamera(null);
                cameraView.initCamera();
                ImageHelper.correctRotateImage(finalCameraFile.getAbsolutePath(), true);
                FragmentEditImage.checkItemGalleryList();
                FragmentEditImage.insertItemList(finalCameraFile.getAbsolutePath(), true);
                if (getActivity() != null) {
                    new HelperFragment(getActivity().getSupportFragmentManager(), PhotoViewer.newInstance(finalCameraFile.getAbsolutePath(), isForRoom, roomId, listMode, roomTitle)).setReplace(false).load();
                }
            });
        }
    });
    switchCamera.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            cameraView.switchCamera();
            ObjectAnimator animator = ObjectAnimator.ofFloat(switchCamera, View.SCALE_X, 0.0f).setDuration(100);
            animator.addListener(new AnimatorListenerAdapter() {

                @Override
                public void onAnimationEnd(Animator animator) {
                    switchCamera.setImageResource(cameraView != null && cameraView.isFrontface() ? R.drawable.camera_revert1 : R.drawable.camera_revert2);
                    ObjectAnimator.ofFloat(switchCamera, View.SCALE_X, 1.0f).setDuration(100).start();
                }
            });
            animator.start();
        }
    });
    if (checkCameraHardware(getContext())) {
        if (allPermissionsGranted()) {
            CameraController.getInstance().initCamera(null);
            // switchCamera.setVisibility(cameraView.hasFrontFaceCamera() ? View.VISIBLE : View.INVISIBLE);
            showCamera();
        } else {
            try {
                HelperPermission.getCameraPermission(getContext(), new OnGetPermission() {

                    @Override
                    public void Allow() throws IOException {
                        HelperPermission.getStoragePermission(getContext(), new OnGetPermission() {

                            @Override
                            public void Allow() throws IOException {
                                if (checkCameraHardware(getContext())) {
                                    CameraController.getInstance().initCamera(null);
                                    // switchCamera.setVisibility(cameraView.hasFrontFaceCamera() ? View.VISIBLE : View.INVISIBLE);
                                    showCamera();
                                }
                            }

                            @Override
                            public void deny() {
                            }
                        });
                    }

                    @Override
                    public void deny() {
                    }
                });
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    } else {
        Toast.makeText(getContext(), getString(R.string.your_device_does_not_have_a_camera), Toast.LENGTH_LONG).show();
    }
    closeButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            new HelperFragment(Objects.requireNonNull(getActivity()).getSupportFragmentManager(), CameraStoryFragment.this).popBackStack();
        }
    });
}
Also used : ObjectAnimator(android.animation.ObjectAnimator) ExifInterface(androidx.exifinterface.media.ExifInterface) HelperString(net.iGap.helper.HelperString) IOException(java.io.IOException) ImageView(android.widget.ImageView) View(android.view.View) CircleImageView(net.iGap.module.CircleImageView) TextView(android.widget.TextView) IOException(java.io.IOException) OnGetPermission(net.iGap.observers.interfaces.OnGetPermission) Animator(android.animation.Animator) ObjectAnimator(android.animation.ObjectAnimator) AttachFile(net.iGap.module.AttachFile) AnimatorListenerAdapter(android.animation.AnimatorListenerAdapter) ImageView(android.widget.ImageView) CircleImageView(net.iGap.module.CircleImageView) HelperFragment(net.iGap.helper.HelperFragment) AttachFile(net.iGap.module.AttachFile) File(java.io.File)

Example 2 with AttachFile

use of net.iGap.module.AttachFile in project iGap-Android by KianIranian-STDG.

the class ActivityCrop method onCreate.

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_crop);
    attachFile = new AttachFile(this);
    ProgressBar prgWaiting = (ProgressBar) findViewById(R.id.crop_prgWaiting);
    AppUtils.setProgresColler(prgWaiting);
    imgPic = (ImageView) findViewById(R.id.pu_img_imageBefore);
    TextView txtAgreeImage = (TextView) findViewById(R.id.pu_txt_agreeImage);
    TextView txtCancel = (TextView) findViewById(R.id.pu_txt_cancel_crop);
    txtSet = (TextView) findViewById(R.id.pu_txt_set_crop);
    final Bundle bundle = getIntent().getExtras();
    if (bundle != null) {
        path = bundle.getString("IMAGE_CAMERA");
        String newPath = "file://" + path;
        uri = Uri.parse(newPath);
        page = bundle.getString("PAGE");
        type = bundle.getString("TYPE");
        id = bundle.getInt("ID");
    }
    if (uri != null || path != null) {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
            G.imageLoader.displayImage(AndroidUtils.suitablePath(path), imgPic);
        } else {
            G.imageLoader.displayImage(AndroidUtils.suitablePath(uri.getPath()), imgPic);
        }
        prgWaiting.setVisibility(View.GONE);
    }
    RippleView rippleCrop = (RippleView) findViewById(R.id.pu_ripple_crop);
    TextView txtCrop = (TextView) findViewById(R.id.pu_txt_crop);
    /*
        open crop page
         */
    if (uri != null && !uri.toString().equals("")) {
        rippleCrop.setOnRippleCompleteListener(new RippleView.OnRippleCompleteListener() {

            @Override
            public void onComplete(RippleView rippleView) {
                nzmeFile = path.substring(path.lastIndexOf("/"));
                String newPath = "file://" + path;
                Uri uri = Uri.parse(newPath);
                UCrop.Options options = new UCrop.Options();
                options.setStatusBarColor(ContextCompat.getColor(G.context, R.color.black));
                options.setToolbarColor(ContextCompat.getColor(G.context, R.color.black));
                options.setCompressionQuality(80);
                UCrop.of(uri, Uri.fromFile(new File(G.context.getExternalFilesDir(Environment.DIRECTORY_PICTURES).getAbsolutePath(), nzmeFile))).withAspectRatio(16, 9).withOptions(options).start(ActivityCrop.this);
            }
        });
    }
    RippleView rippleBack = (RippleView) findViewById(R.id.pu_ripple_back);
    rippleBack.setOnRippleCompleteListener(new RippleView.OnRippleCompleteListener() {

        @Override
        public void onComplete(RippleView rippleView) throws IOException {
            if (type.equals("camera") || type.equals("crop_camera")) {
                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
                    new AttachFile(ActivityCrop.this).dispatchTakePictureIntent();
                } else {
                    new AttachFile(ActivityCrop.this).requestTakePicture();
                }
            } else if (type.equals("gallery")) {
                attachFile.requestOpenGalleryForImageMultipleSelect();
            }
        }
    });
    txtCancel.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            finish();
        }
    });
    txtSet.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            if (uri != null && type.equals("crop_camera")) {
                pathImageUser = getRealPathFromURI(uri);
                result = G.imageFile.toString() + "_" + id + ".jpg";
                HelperCopyFile.copyFile(pathImageUser, result);
            } else {
                result = getRealPathFromURI(uri);
            }
            if (page != null) {
                Intent data = new Intent();
                data.setData(Uri.parse(result));
                setResult(Activity.RESULT_OK, data);
                finish();
            }
        }
    });
}
Also used : Bundle(android.os.Bundle) UCrop(com.yalantis.ucrop.UCrop) Intent(android.content.Intent) IOException(java.io.IOException) RippleView(net.iGap.libs.rippleeffect.RippleView) Uri(android.net.Uri) RippleView(net.iGap.libs.rippleeffect.RippleView) ImageView(android.widget.ImageView) View(android.view.View) TextView(android.widget.TextView) AttachFile(net.iGap.module.AttachFile) TextView(android.widget.TextView) ProgressBar(android.widget.ProgressBar) HelperCopyFile(net.iGap.module.HelperCopyFile) AttachFile(net.iGap.module.AttachFile) File(java.io.File)

Example 3 with AttachFile

use of net.iGap.module.AttachFile in project iGap-Android by KianIranian-STDG.

the class FragmentGroupProfile method onViewCreated.

@Override
public void onViewCreated(@NotNull View view, @Nullable Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);
    isNeedResume = true;
    // because actionbar not in this view do that and not correct in viewModel
    imvGroupAvatar = binding.toolbarAvatar;
    imvGroupAvatar.setOnClickListener(v -> viewModel.onClickRippleGroupAvatar());
    if (currentRoomAccess != null) {
        checkRoomAccess(currentRoomAccess);
        roomAccessChangeListener = (realmRoomAccess, changeSet) -> checkRoomAccess(realmRoomAccess);
        currentRoomAccess.addChangeListener(roomAccessChangeListener);
    }
    binding.toolbarMore.setOnClickListener(v -> viewModel.onClickRippleMenu());
    binding.toolbarBack.setOnClickListener(v -> popBackStackFragment());
    binding.toolbarEdit.setOnClickListener(v -> {
        if (getActivity() != null && currentRoomAccess != null && currentRoomAccess.isCanModifyRoom()) {
            new HelperFragment(getActivity().getSupportFragmentManager(), EditGroupFragment.newInstance(viewModel.roomId)).setReplace(false).load();
        }
    });
    viewModel.groupName.observe(getViewLifecycleOwner(), s -> {
        binding.toolbarTxtNameCollapsed.setText(EmojiManager.getInstance().replaceEmoji(s, binding.toolbarTxtNameCollapsed.getPaint().getFontMetricsInt()));
        binding.toolbarTxtNameExpanded.setText(EmojiManager.getInstance().replaceEmoji(s, binding.toolbarTxtNameExpanded.getPaint().getFontMetricsInt()));
    });
    viewModel.groupNumber.observe(getViewLifecycleOwner(), s -> binding.toolbarTxtStatusExpanded.setText(String.format("%s %s", s, getString(R.string.member))));
    viewModel.showMoreMenu.observe(getViewLifecycleOwner(), isShow -> {
        if (isShow != null) {
            binding.toolbarMore.setVisibility(isShow ? View.VISIBLE : View.GONE);
        }
    });
    viewModel.goToShearedMediaPage.observe(getViewLifecycleOwner(), model -> {
        if (getActivity() != null && model != null) {
            new HelperFragment(getActivity().getSupportFragmentManager(), FragmentShearedMedia.newInstance(model)).setReplace(false).load();
        }
    });
    viewModel.goToShowAvatarPage.observe(getViewLifecycleOwner(), roomId -> {
        if (getActivity() != null && roomId != null) {
            new HelperFragment(getActivity().getSupportFragmentManager(), FragmentShowAvatars.newInstance(roomId, FragmentShowAvatars.From.group)).setReplace(false).load();
        }
    });
    viewModel.showMenu.observe(getViewLifecycleOwner(), menuList -> {
        if (getActivity() != null && menuList != null) {
            new TopSheetDialog(getActivity()).setListDataWithResourceId(menuList, -1, position -> {
                if (menuList.get(position) == R.string.clear_history) {
                    new MaterialDialog.Builder(getActivity()).title(R.string.clear_history).content(R.string.clear_history_content).positiveText(R.string.yes).onPositive(new MaterialDialog.SingleButtonCallback() {

                        @Override
                        public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
                            getMessageController().clearHistoryMessage(viewModel.roomId);
                        }
                    }).negativeText(R.string.no).show();
                } else if (menuList.get(position) == R.string.group_title_convert_to_public || menuList.get(position) == R.string.group_title_convert_to_private) {
                    viewModel.convertMenuClick();
                }
            }).show();
        }
    });
    viewModel.goToShowMemberPage.observe(getViewLifecycleOwner(), type -> {
        if (getActivity() != null && type != null) {
            FragmentShowMember fragment = FragmentShowMember.newInstance2(this, viewModel.roomId, viewModel.role.toString(), AccountManager.getInstance().getCurrentUser().getId(), type, viewModel.isNeedgetContactlist, true);
            new HelperFragment(getActivity().getSupportFragmentManager(), fragment).setReplace(false).load();
        }
    });
    viewModel.showDialogConvertToPublic.observe(getViewLifecycleOwner(), isShow -> {
        if (getActivity() != null && isShow != null && isShow) {
            new MaterialDialog.Builder(getActivity()).title(getString(R.string.group_title_convert_to_public)).content(getString(R.string.group_text_convert_to_public)).positiveText(R.string.yes).onPositive(new MaterialDialog.SingleButtonCallback() {

                @Override
                public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
                    dialog.dismiss();
                    setUsername();
                }
            }).negativeText(R.string.no).show();
        }
    });
    viewModel.showDialogConvertToPrivate.observe(getViewLifecycleOwner(), isShow -> {
        if (getActivity() != null && isShow != null && isShow) {
            new MaterialDialog.Builder(getActivity()).title(R.string.group_title_convert_to_private).content(R.string.group_text_convert_to_private).positiveText(R.string.yes).onPositive(new MaterialDialog.SingleButtonCallback() {

                @Override
                public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
                    viewModel.sendRequestRemoveGroupUsername();
                }
            }).negativeText(R.string.no).show();
        }
    });
    viewModel.showRequestError.observe(getViewLifecycleOwner(), errorMessage -> {
        if (errorMessage != null) {
            HelperError.showSnackMessage(getString(errorMessage), false);
        }
    });
    viewModel.goToShowCustomListPage.observe(getViewLifecycleOwner(), listItem -> {
        if (getActivity() != null && listItem != null) {
            ShowCustomList showCustomListFragment = new ShowCustomList();
            showCustomListFragment.setFields(ProtoGlobal.Room.Type.GROUP, listItem, (result, message, countForShowLastMessage, list) -> {
                for (int i = 0; i < list.size(); i++) {
                    new RequestGroupAddMember().groupAddMember(viewModel.roomId, list.get(i).peerId, RealmRoomMessage.findCustomMessageId(viewModel.roomId, countForShowLastMessage));
                }
            });
            Bundle bundle = new Bundle();
            bundle.putBoolean("DIALOG_SHOWING", true);
            bundle.putLong("COUNT_MESSAGE", 0);
            showCustomListFragment.setArguments(bundle);
            new HelperFragment(getActivity().getSupportFragmentManager(), showCustomListFragment).setReplace(false).load();
        }
    });
    viewModel.goBack.observe(getViewLifecycleOwner(), isGoBack -> {
        if (isGoBack != null && isGoBack) {
            popBackStackFragment();
        }
    });
    BetterLinkMovementMethod.linkify(Linkify.ALL, binding.description).setOnLinkClickListener((tv, url) -> {
        return false;
    }).setOnLinkLongClickListener((tv, url) -> {
        if (HelperUrl.isTextLink(url)) {
            G.isLinkClicked = true;
            HelperUrl.openLinkDialog(getActivity(), url);
        }
        return true;
    });
    viewModel.groupDescription.observe(getViewLifecycleOwner(), groupDescription -> {
        if (getActivity() != null && groupDescription != null) {
            binding.description.setText(EmojiManager.getInstance().replaceEmoji(HelperUrl.setUrlLink(getActivity(), groupDescription, true, false, null, true), binding.description.getPaint().getFontMetricsInt()));
        }
    });
    viewModel.goToRoomListPage.observe(getViewLifecycleOwner(), isGo -> {
        if (getActivity() instanceof ActivityMain && isGo != null) {
            Log.wtf(this.getClass().getName(), "goToRoomListPage observe");
            ((ActivityMain) getActivity()).removeAllFragmentFromMain();
        /*new HelperFragment(getActivity().getSupportFragmentManager()).popBackStack(2);*/
        }
    });
    viewModel.showDialogEditLink.observe(getViewLifecycleOwner(), link -> {
        if (getActivity() != null && link != null) {
            MaterialDialog dialog = new MaterialDialog.Builder(getActivity()).title(R.string.group_link).positiveText(R.string.array_Copy).customView(createDialogLayout(link), true).widgetColor(new Theme().getPrimaryColor(getContext())).negativeText(R.string.edit).onPositive((dialog1, which) -> {
                ClipboardManager clipboard = (ClipboardManager) getActivity().getSystemService(CLIPBOARD_SERVICE);
                ClipData clip = ClipData.newPlainText("LINK_GROUP", link);
                clipboard.setPrimaryClip(clip);
            }).onNegative((dialog12, which) -> {
                if (viewModel.isPrivate) {
                    viewModel.sendRequestRevokeGroupUsername();
                } else {
                    setUsername();
                }
            }).build();
            dialog.show();
        }
    });
    viewModel.showDialogCopyLink.observe(getViewLifecycleOwner(), link -> {
        if (getActivity() != null && link != null) {
            MaterialDialog dialog = new MaterialDialog.Builder(getActivity()).title(R.string.group_link).positiveText(R.string.array_Copy).customView(createDialogLayout(link), true).widgetColor(new Theme().getPrimaryColor(getContext())).onPositive((dialog1, which) -> {
                ClipboardManager clipboard = (ClipboardManager) getActivity().getSystemService(CLIPBOARD_SERVICE);
                ClipData clip = ClipData.newPlainText("LINK_GROUP", link);
                clipboard.setPrimaryClip(clip);
                Toast.makeText(getActivity(), R.string.copied, Toast.LENGTH_SHORT).show();
            }).build();
            dialog.show();
        }
    });
    viewModel.goToCustomNotificationPage.observe(getViewLifecycleOwner(), roomId -> {
        if (getActivity() != null && roomId != null) {
            FragmentNotification fragmentNotification = new FragmentNotification();
            Bundle bundle = new Bundle();
            bundle.putLong("ID", roomId);
            fragmentNotification.setArguments(bundle);
            new HelperFragment(getActivity().getSupportFragmentManager(), fragmentNotification).setReplace(false).load();
        }
    });
    viewModel.showDialogLeaveGroup.observe(getViewLifecycleOwner(), isShow -> {
        if (isShow != null && isShow) {
            groupLeft();
        }
    });
    if (viewModel.role.equals(GroupChatRole.OWNER)) {
        binding.editGroupPermission.setVisibility(View.VISIBLE);
        binding.editGroupPermission.setOnClickListener(v -> {
            openChatEditRightsFragment(viewModel.getRealmRoom());
        });
    }
    initComponent();
    attachFile = new AttachFile(getActivity());
    G.onGroupAvatarDelete = this;
    initialToolbar();
}
Also used : TopSheetDialog(net.iGap.module.dialog.topsheet.TopSheetDialog) LinearLayout(android.widget.LinearLayout) Bundle(android.os.Bundle) AppUtils(net.iGap.module.AppUtils) OnGroupAvatarDelete(net.iGap.observers.interfaces.OnGroupAvatarDelete) ProgressBar(android.widget.ProgressBar) NonNull(androidx.annotation.NonNull) WindowManager(android.view.WindowManager) AttachFile(net.iGap.module.AttachFile) Theme(net.iGap.module.Theme) OnGroupCheckUsername(net.iGap.observers.interfaces.OnGroupCheckUsername) Selection(android.text.Selection) G(net.iGap.G) GroupChatRole(net.iGap.module.enums.GroupChatRole) RequestGroupUpdateUsername(net.iGap.request.RequestGroupUpdateUsername) Fragment(androidx.fragment.app.Fragment) ActivityGroupProfileBinding(net.iGap.databinding.ActivityGroupProfileBinding) ClipboardManager(android.content.ClipboardManager) View(android.view.View) ViewModelProviders(androidx.lifecycle.ViewModelProviders) HelperError(net.iGap.helper.HelperError) HelperFragment(net.iGap.helper.HelperFragment) RequestGroupAddMember(net.iGap.request.RequestGroupAddMember) Log(android.util.Log) DataBindingUtil(androidx.databinding.DataBindingUtil) ParamWithAvatarType(net.iGap.helper.avatar.ParamWithAvatarType) OnComplete(net.iGap.observers.interfaces.OnComplete) MEditText(net.iGap.module.MEditText) RealmObjectChangeListener(io.realm.RealmObjectChangeListener) RealmRoom(net.iGap.realm.RealmRoom) ViewGroup(android.view.ViewGroup) TextView(android.widget.TextView) Nullable(androidx.annotation.Nullable) ProtoGroupCheckUsername(net.iGap.proto.ProtoGroupCheckUsername) AlphaAnimation(android.view.animation.AlphaAnimation) CLIPBOARD_SERVICE(android.content.Context.CLIPBOARD_SERVICE) MaterialDialog(com.afollestad.materialdialogs.MaterialDialog) EventManager(net.iGap.observers.eventbus.EventManager) NotNull(org.jetbrains.annotations.NotNull) TextWatcher(android.text.TextWatcher) EmojiManager(net.iGap.libs.emojiKeyboard.emoji.EmojiManager) Context(android.content.Context) Config(net.iGap.Config) ResourcesCompat(androidx.core.content.res.ResourcesCompat) ActivityMain(net.iGap.activities.ActivityMain) HelperUrl(net.iGap.helper.HelperUrl) TextInputLayout(com.google.android.material.textfield.TextInputLayout) AccountManager(net.iGap.module.accountManager.AccountManager) Linkify(android.text.util.Linkify) Editable(android.text.Editable) InputMethodManager(android.view.inputmethod.InputMethodManager) ClipData(android.content.ClipData) Toast(android.widget.Toast) RequestGroupCheckUsername(net.iGap.request.RequestGroupCheckUsername) RealmRoomMessage(net.iGap.realm.RealmRoomMessage) Build(android.os.Build) AvatarHandler(net.iGap.helper.avatar.AvatarHandler) RealmRoomAccess(net.iGap.realm.RealmRoomAccess) LayoutInflater(android.view.LayoutInflater) FragmentGroupProfileViewModel(net.iGap.viewmodel.FragmentGroupProfileViewModel) DialogAction(com.afollestad.materialdialogs.DialogAction) TopSheetDialog(net.iGap.module.dialog.topsheet.TopSheetDialog) CircleImageView(net.iGap.module.CircleImageView) Gravity(android.view.Gravity) CountDownTimer(android.os.CountDownTimer) TypedValue(android.util.TypedValue) HelperString(net.iGap.helper.HelperString) OnGroupUpdateUsername(net.iGap.observers.interfaces.OnGroupUpdateUsername) ProtoGlobal(net.iGap.proto.ProtoGlobal) R(net.iGap.R) BetterLinkMovementMethod(me.saket.bettermovementmethod.BetterLinkMovementMethod) DbManager(net.iGap.module.accountManager.DbManager) ClipboardManager(android.content.ClipboardManager) MaterialDialog(com.afollestad.materialdialogs.MaterialDialog) Bundle(android.os.Bundle) RequestGroupAddMember(net.iGap.request.RequestGroupAddMember) ActivityMain(net.iGap.activities.ActivityMain) DialogAction(com.afollestad.materialdialogs.DialogAction) AttachFile(net.iGap.module.AttachFile) NonNull(androidx.annotation.NonNull) Theme(net.iGap.module.Theme) HelperFragment(net.iGap.helper.HelperFragment) ClipData(android.content.ClipData)

Example 4 with AttachFile

use of net.iGap.module.AttachFile in project iGap-Android by KianIranian-STDG.

the class ChatAttachmentPopup method build.

public ChatAttachmentPopup build() {
    if (mRootView == null)
        throw new IllegalArgumentException(TAG + " : set root view!");
    // inflate layout
    LayoutInflater inflater = LayoutInflater.from(mFrgActivity);
    viewRoot = inflater.inflate(R.layout.attachment_popup_view, null, false);
    attachFile = new AttachFile(mFrgActivity);
    initViews(viewRoot);
    // setup popup
    mPopup = new PopupWindow(mFrgActivity);
    mPopup.setContentView(viewRoot);
    mPopup.setWidth(ViewGroup.LayoutParams.MATCH_PARENT);
    mPopup.setHeight(ViewGroup.LayoutParams.MATCH_PARENT);
    mPopup.setInputMethodMode(PopupWindow.INPUT_METHOD_NOT_NEEDED);
    mPopup.setBackgroundDrawable(new BitmapDrawable());
    mPopup.setFocusable(true);
    mPopup.setOutsideTouchable(true);
    privacyView = viewRoot.findViewById(R.id.fl_attachment_privacyView);
    mPopup.setOnDismissListener(() -> {
        isNewBottomSheet = true;
        isShowing = false;
        disableCamera();
    });
    EventManager.getInstance(AccountManager.selectedAccount).addObserver(EventManager.ON_CAMERA_PERMISSION_GRANTED, ChatAttachmentPopup.this);
    return this;
}
Also used : AttachFile(net.iGap.module.AttachFile) LayoutInflater(android.view.LayoutInflater) PopupWindow(android.widget.PopupWindow) BitmapDrawable(android.graphics.drawable.BitmapDrawable)

Example 5 with AttachFile

use of net.iGap.module.AttachFile in project iGap-Android by KianIranian-STDG.

the class ChatAttachmentPopup method initViews.

private void initViews(View view) {
    View camera, photo, video, music, file, contact, location;
    View root;
    camera = view.findViewById(R.id.camera);
    photo = view.findViewById(R.id.picture);
    video = view.findViewById(R.id.video);
    music = view.findViewById(R.id.music);
    file = view.findViewById(R.id.file);
    location = view.findViewById(R.id.location);
    contact = view.findViewById(R.id.contact);
    btnSend = view.findViewById(R.id.close);
    icoSend = view.findViewById(R.id.txtSend);
    lblSend = view.findViewById(R.id.txtNumberItem);
    root = view.findViewById(R.id.root);
    root.setOnClickListener(v -> {
        dismiss();
    });
    btnSend.setOnClickListener(v -> {
        if (animation != null)
            animation.cancel();
        if (FragmentEditImage.textImageList.size() > 0) {
            dismiss();
            clearRecyclerAdapter();
            lblSend.setText(mFrgActivity.getString(R.string.icon_close));
            lblSend.setText(mFrgActivity.getString(R.string.navigation_drawer_close));
            mPopupListener.onAttachPopupSendSelected();
        } else {
            dismiss();
        }
    });
    camera.setOnClickListener(v -> {
        dismiss();
        attachFile.showDialogOpenCamera(v, null, mFragment);
    });
    photo.setOnClickListener(v -> {
        dismiss();
        openPhotoGallery();
    });
    video.setOnClickListener(v -> {
        dismiss();
        openVideoGallery();
    });
    music.setOnClickListener(v -> {
        dismiss();
        openMusicGallery();
    });
    file.setOnClickListener(v -> {
        dismiss();
        try {
            attachFile.requestPickFile((selectedPathList, caption) -> {
                mPopupListener.onAttachPopupFilePicked(selectedPathList, caption);
            });
        } catch (IOException e) {
            e.printStackTrace();
        }
    });
    contact.setOnClickListener(v -> {
        dismiss();
        try {
            attachFile.requestPickContact(mFragment);
        } catch (IOException e) {
            e.printStackTrace();
        }
    });
    location.setOnClickListener(v -> {
        dismiss();
        try {
            attachFile.requestGetPosition((result, messageOne, MessageTow) -> {
                mPopupListener.onAttachPopupLocation(messageOne);
            }, mFragment);
        } catch (IOException e) {
            e.printStackTrace();
        }
    });
    // init local pictures
    fastItemAdapter = new FastItemAdapter();
    onClickCamera = () -> {
        try {
            dismiss();
            new AttachFile(mFrgActivity).requestTakePicture(mFragment);
        } catch (IOException e) {
            e.printStackTrace();
        }
    };
    onPathAdapterBottomSheet = (path, isCheck, isEdit, mList, id) -> {
        if (isEdit) {
            dismiss();
            new HelperFragment(mFrgActivity.getSupportFragmentManager(), FragmentEditImage.newInstance(null, true, false, id)).setReplace(false).load();
        } else {
            if (isCheck) {
                StructBottomSheet item = new StructBottomSheet();
                item.setPath(path);
                item.setText("");
                item.setId(id);
                FragmentEditImage.textImageList.put(path, item);
            } else {
                FragmentEditImage.textImageList.remove(path);
            }
            if (FragmentEditImage.textImageList.size() > 0) {
                icoSend.setText(mFrgActivity.getString(R.string.icon_send));
                lblSend.setText("" + FragmentEditImage.textImageList.size() + " " + mFrgActivity.getString(item));
            } else {
                icoSend.setText(mFrgActivity.getString(R.string.icon_close));
                lblSend.setText(mFrgActivity.getString(R.string.navigation_drawer_close));
            }
        }
    };
    mNoCameraPermission = view.findViewById(R.id.no_camera_permission);
    rcvBottomSheet = view.findViewById(R.id.rcvContent);
    rcvBottomSheet.setLayoutManager(new GridLayoutManager(mFrgActivity, 1, GridLayoutManager.HORIZONTAL, false));
    rcvBottomSheet.setAdapter(fastItemAdapter);
    mNoCameraPermission.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            try {
                HelperPermission.getCameraPermission(G.fragmentActivity, new OnGetPermission() {

                    @Override
                    public void Allow() throws IOException {
                        mNoCameraPermission.setVisibility(View.GONE);
                        rcvBottomSheet.setVisibility(View.VISIBLE);
                    }

                    @Override
                    public void deny() {
                        HelperPermission.showDeniedPermissionMessage(G.context.getString(R.string.permission_camera));
                    }
                });
            } catch (IOException ioException) {
                ioException.printStackTrace();
            }
        }
    });
    // disable and enable camera when user scroll on recycler view
    rcvBottomSheet.addOnChildAttachStateChangeListener(new RecyclerView.OnChildAttachStateChangeListener() {

        @Override
        public void onChildViewAttachedToWindow(final View view) {
            if (isPermissionCamera) {
                if (rcvBottomSheet.getChildAdapterPosition(view) == 0) {
                    isCameraAttached = true;
                }
                if (isCameraAttached) {
                    enableCamera();
                }
            }
        }

        @Override
        public void onChildViewDetachedFromWindow(final View view) {
            if (isPermissionCamera) {
                if (rcvBottomSheet.getChildAdapterPosition(view) == 0) {
                    isCameraAttached = false;
                }
                if (!isCameraAttached) {
                    disableCamera();
                }
            }
        }
    });
}
Also used : GridLayoutManager(androidx.recyclerview.widget.GridLayoutManager) FastItemAdapter(com.mikepenz.fastadapter.commons.adapters.FastItemAdapter) AttachFile(net.iGap.module.AttachFile) StructBottomSheet(net.iGap.module.structs.StructBottomSheet) RecyclerView(androidx.recyclerview.widget.RecyclerView) IOException(java.io.IOException) HelperFragment(net.iGap.helper.HelperFragment) View(android.view.View) RecyclerView(androidx.recyclerview.widget.RecyclerView) TextView(android.widget.TextView) OnGetPermission(net.iGap.observers.interfaces.OnGetPermission)

Aggregations

AttachFile (net.iGap.module.AttachFile)11 View (android.view.View)6 IOException (java.io.IOException)6 Intent (android.content.Intent)4 Bundle (android.os.Bundle)4 TextView (android.widget.TextView)4 OnGetPermission (net.iGap.observers.interfaces.OnGetPermission)4 Context (android.content.Context)3 Build (android.os.Build)3 LayoutInflater (android.view.LayoutInflater)3 File (java.io.File)3 ActivityMain (net.iGap.activities.ActivityMain)3 HelperFragment (net.iGap.helper.HelperFragment)3 Animator (android.animation.Animator)2 AnimatorListenerAdapter (android.animation.AnimatorListenerAdapter)2 ObjectAnimator (android.animation.ObjectAnimator)2 Activity (android.app.Activity)2 ClipData (android.content.ClipData)2 ClipboardManager (android.content.ClipboardManager)2 CLIPBOARD_SERVICE (android.content.Context.CLIPBOARD_SERVICE)2