Search in sources :

Example 1 with OnComplete

use of net.iGap.observers.interfaces.OnComplete in project iGap-Android by KianIranian-STDG.

the class FragmentMediaPlayerViewModel method getInfo.

private void getInfo() {
    FragmentMediaPlayer.onComplete = new OnComplete() {

        @Override
        public void complete(boolean result, String messageOne, final String MessageTwo) {
            if (messageOne.equals("play")) {
                callBackBtnPlayMusic.set(G.fragmentActivity.getResources().getString(R.string.icon_play));
                if (rippleVisualizerView != null) {
                    rippleVisualizerView.setEnabled(false);
                    rippleVisualizerView.pauseVisualizer();
                }
            } else if (messageOne.equals("pause")) {
                callBackBtnPlayMusic.set(G.fragmentActivity.getResources().getString(R.string.icon_pause));
                if (rippleVisualizerView != null) {
                    rippleVisualizerView.setEnabled(true);
                    rippleVisualizerView.startVisualizer();
                }
            } else if (messageOne.equals("update")) {
                G.handler.post(new Runnable() {

                    @Override
                    public void run() {
                        updateUi();
                    }
                });
            } else if (messageOne.equals("updateTime")) {
                G.handler.post(new Runnable() {

                    @Override
                    public void run() {
                        callBackTxtTimer.set(MessageTwo);
                        seekBar1.set(MusicPlayer.musicProgress);
                    }
                });
            } else if (messageOne.equals("RepeatMode")) {
                setReplayButton();
            } else if (messageOne.equals("Shuffel")) {
                setShuffleButton();
            } else if (messageOne.equals("finish")) {
                if (FragmentMediaPlayer.onBackFragment != null) {
                    FragmentMediaPlayer.onBackFragment.onBack();
                }
            }
        }
    };
    setMusicInfo();
    initVisualizer(v);
    setShuffleButton();
    setReplayButton();
    if (HelperCalander.isPersianUnicode) {
        callBackTxtTimer.set(HelperCalander.convertToUnicodeFarsiNumber(callBackTxtTimer.get()));
        callBackTxtMusicTime.set(HelperCalander.convertToUnicodeFarsiNumber(callBackTxtMusicTime.get()));
    }
}
Also used : OnComplete(net.iGap.observers.interfaces.OnComplete)

Example 2 with OnComplete

use of net.iGap.observers.interfaces.OnComplete in project iGap-Android by KianIranian-STDG.

the class FragmentChat method initCallbacks.

/**
 * initialize some callbacks that used in this page
 */
public void initCallbacks() {
    getSendMessageUtil().setOnChatSendMessageResponseChatPage(this);
    // G.chatUpdateStatusUtil.setOnChatUpdateStatusResponse(this);
    G.onChatSendMessage = new OnChatSendMessage() {

        @Override
        public void Error(int majorCode, int minorCode, final int waitTime, long messageId) {
            if (majorCode == 234) {
                G.handler.post(new Runnable() {

                    @Override
                    public void run() {
                        try {
                            if (G.fragmentActivity.hasWindowFocus()) {
                                showErrorDialog(waitTime);
                            }
                        } catch (Exception e) {
                        }
                    }
                });
            } else if (majorCode == 233 && minorCode == 1) {
                G.handler.post(new Runnable() {

                    @Override
                    public void run() {
                        if (getContext() != null && mAdapter != null) {
                            mAdapter.removeMessage(messageId);
                        }
                    }
                });
            }
        }
    };
    G.onChatEditMessageResponse = new OnChatEditMessageResponse() {

        @Override
        public void onChatEditMessage(long roomId, final long messageId, long messageVersion, final String message, ProtoResponse.Response response) {
            if (mRoomId == roomId && mAdapter != null) {
                // I'm in the room
                G.handler.post(new Runnable() {

                    @Override
                    public void run() {
                        // update message text in adapter
                        mAdapter.updateMessageText(messageId, message);
                    }
                });
            }
        }

        @Override
        public void onError(int majorCode, int minorCode) {
        }
    };
    onMusicListener = new OnComplete() {

        @Override
        public void complete(boolean result, String messageID, String MessageTwo) {
            if (result) {
                updateShowItemInScreen();
            } else {
                onPlayMusic(messageID);
            }
        }
    };
    iUpdateLogItem = new // TODO: 12/29/20 MESSAGE_REFACTOR_NEED_TEST
    IUpdateLogItem() {

        @Override
        public void onUpdate(byte[] log, long messageId) {
            if (getActivity() == null || getActivity().isFinishing())
                return;
            getActivity().runOnUiThread(new Runnable() {

                @Override
                public void run() {
                    if (mAdapter == null) {
                        return;
                    }
                    for (int i = mAdapter.getAdapterItemCount() - 1; i >= 0; i--) {
                        try {
                            AbstractMessage item = mAdapter.getAdapterItem(i);
                            if (item.messageObject != null && item.messageObject.id == messageId) {
                                // bagi May crash
                                item.messageObject.log.data = log;
                                mAdapter.notifyAdapterItemChanged(i);
                                break;
                            }
                        } catch (Exception e) {
                            e.printStackTrace();
                            HelperLog.getInstance().setErrorLog(e);
                        }
                    }
                }
            });
        }
    };
    /**
     * after get position from gps
     */
    complete = new OnComplete() {

        @Override
        public void complete(boolean result, final String messageOne, String MessageTwo) {
            try {
                if (getActivity() != null) {
                    String[] split = messageOne.split(",");
                    Double latitude = Double.parseDouble(split[0]);
                    Double longitude = Double.parseDouble(split[1]);
                    NewFragmentMap fragment = NewFragmentMap.newInstance(latitude, longitude);
                    new HelperFragment(getActivity().getSupportFragmentManager(), fragment).setReplace(false).load();
                }
            } catch (Exception e) {
                HelperLog.getInstance().setErrorLog(e);
            }
        }
    };
    G.onHelperSetAction = new OnHelperSetAction() {

        @Override
        public void onAction(ProtoGlobal.ClientAction ClientAction) {
            HelperSetAction.setActionFiles(mRoomId, messageId, ClientAction, chatType);
        }
    };
    G.onDeleteChatFinishActivity = new OnDeleteChatFinishActivity() {

        @Override
        public void onFinish() {
            G.handler.post(new Runnable() {

                @Override
                public void run() {
                    // finish();
                    finishChat();
                }
            });
        }
    };
    G.onUpdateUserStatusInChangePage = (peerId, status, lastSeen) -> {
        if (chatType == CHAT) {
            setUserStatus(status, lastSeen);
            new RequestUserInfo().userInfo(peerId);
        }
    };
}
Also used : OnChatEditMessageResponse(net.iGap.observers.interfaces.OnChatEditMessageResponse) OnHelperSetAction(net.iGap.observers.interfaces.OnHelperSetAction) AbstractMessage(net.iGap.adapter.items.chat.AbstractMessage) OnComplete(net.iGap.observers.interfaces.OnComplete) ProtoGlobal(net.iGap.proto.ProtoGlobal) RealmString(net.iGap.realm.RealmString) HelperString(net.iGap.helper.HelperString) OnChatSendMessage(net.iGap.observers.interfaces.OnChatSendMessage) SuppressLint(android.annotation.SuppressLint) IOException(java.io.IOException) JsonSyntaxException(com.google.gson.JsonSyntaxException) OnDeleteChatFinishActivity(net.iGap.observers.interfaces.OnDeleteChatFinishActivity) RequestUserInfo(net.iGap.request.RequestUserInfo) ProtoResponse(net.iGap.proto.ProtoResponse) HelperFragment(net.iGap.helper.HelperFragment)

Example 3 with OnComplete

use of net.iGap.observers.interfaces.OnComplete in project iGap-Android by KianIranian-STDG.

the class FragmentGroupProfile method initComponent.

/**
 * ************************************** methods **************************************
 */
private void initComponent() {
    AppUtils.setProgresColler(binding.loading);
    FragmentShowAvatars.onComplete = new OnComplete() {

        @Override
        public void complete(boolean result, String messageOne, String MessageTwo) {
            long mAvatarId = 0;
            if (messageOne != null && !messageOne.equals("")) {
                mAvatarId = Long.parseLong(messageOne);
            }
            avatarHandler.avatarDelete(new ParamWithAvatarType(imvGroupAvatar, viewModel.roomId).avatarType(AvatarHandler.AvatarType.ROOM), mAvatarId);
        }
    };
    showAvatar();
}
Also used : OnComplete(net.iGap.observers.interfaces.OnComplete) HelperString(net.iGap.helper.HelperString) ParamWithAvatarType(net.iGap.helper.avatar.ParamWithAvatarType)

Example 4 with OnComplete

use of net.iGap.observers.interfaces.OnComplete in project iGap-Android by KianIranian-STDG.

the class FragmentShowAvatars method initComponent.

private void initComponent(View view) {
    // ViewGroup rooShowImage = (ViewGroup) view.findViewById(R.id.rooShowImage);
    // rooShowImage.setBackgroundColor(G.fragmentActivity.getResources().getColor(R.color.black));
    RippleView rippleBack = view.findViewById(R.id.asi_ripple_back);
    rippleBack.setOnRippleCompleteListener(new RippleView.OnRippleCompleteListener() {

        @Override
        public void onComplete(RippleView rippleView) {
            G.fragmentActivity.onBackPressed();
        }
    });
    RippleView rippleMenu = view.findViewById(R.id.asi_ripple_menu);
    rippleMenu.setOnRippleCompleteListener(rippleView -> {
        if (getContext() == null)
            return;
        List<Integer> items = new ArrayList<>();
        items.add(R.string.save_to_gallery);
        switch(from) {
            case setting:
                items.add(R.string.array_Delete_photo);
                break;
            case group:
                if (roleGroup == GroupChatRole.OWNER || roleGroup == GroupChatRole.ADMIN) {
                    items.add(R.string.array_Delete_photo);
                }
                break;
            case channel:
                if (roleChannel == ChannelChatRole.OWNER || roleChannel == ChannelChatRole.ADMIN) {
                    items.add(R.string.array_Delete_photo);
                }
                break;
        }
        new TopSheetDialog(getContext()).setListDataWithResourceId(items, -1, position -> {
            if (items.get(position) == R.string.save_to_gallery) {
                saveToGallery();
            } else if (items.get(position) == array_Delete_photo) {
                switch(from) {
                    case setting:
                        deletePhotoSetting();
                        break;
                    case group:
                        deletePhotoGroup();
                        break;
                    case channel:
                        deletePhotoChannel();
                        break;
                    case chat:
                        deletePhotoChat();
                        break;
                }
            }
        }).show();
    });
    viewPager = view.findViewById(R.id.asi_view_pager);
    txtImageNumber = view.findViewById(R.id.asi_txt_image_number);
    toolbarShowImage = view.findViewById(R.id.showAvatarToolbar);
    initViewPager();
}
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) RequestGroupAvatarGetList(net.iGap.request.RequestGroupAvatarGetList) ProtoFileDownload(net.iGap.proto.ProtoFileDownload) MessageProgress(net.iGap.messageprogress.MessageProgress) OnUserAvatarDelete(net.iGap.observers.interfaces.OnUserAvatarDelete) G(net.iGap.G) GroupChatRole(net.iGap.module.enums.GroupChatRole) DialogAnimation(net.iGap.module.DialogAnimation) R.string.array_Delete_photo(net.iGap.R.string.array_Delete_photo) View(android.view.View) Log(android.util.Log) HelperImageBackColor(net.iGap.helper.HelperImageBackColor) RequestUserAvatarGetList(net.iGap.request.RequestUserAvatarGetList) HelperCalander(net.iGap.helper.HelperCalander) Status(net.iGap.module.downloader.Status) OnComplete(net.iGap.observers.interfaces.OnComplete) RealmRoom(net.iGap.realm.RealmRoom) BitmapDrawable(android.graphics.drawable.BitmapDrawable) Downloader(net.iGap.module.downloader.Downloader) RealmStory(net.iGap.realm.RealmStory) ViewGroup(android.view.ViewGroup) HelperLog(net.iGap.helper.HelperLog) List(java.util.List) TextView(android.widget.TextView) Nullable(androidx.annotation.Nullable) RealmRegisteredInfo(net.iGap.realm.RealmRegisteredInfo) Sort(io.realm.Sort) MaterialDialog(com.afollestad.materialdialogs.MaterialDialog) NotNull(org.jetbrains.annotations.NotNull) DownloadObject(net.iGap.module.downloader.DownloadObject) RealmChangeListener(io.realm.RealmChangeListener) Context(android.content.Context) AttachmentObject(net.iGap.structs.AttachmentObject) RippleView(net.iGap.libs.rippleeffect.RippleView) AndroidUtils(net.iGap.module.AndroidUtils) PagerAdapter(androidx.viewpager.widget.PagerAdapter) AccountManager(net.iGap.module.accountManager.AccountManager) ViewPager(androidx.viewpager.widget.ViewPager) ArrayList(java.util.ArrayList) Toast(android.widget.Toast) LayoutCreator(net.iGap.helper.LayoutCreator) AvatarHandler(net.iGap.helper.avatar.AvatarHandler) RequestChannelAvatarGetList(net.iGap.request.RequestChannelAvatarGetList) RequestChannelAvatarDelete(net.iGap.request.RequestChannelAvatarDelete) HelperDownloadFile(net.iGap.helper.HelperDownloadFile) LayoutInflater(android.view.LayoutInflater) PhotoView(com.github.chrisbanes.photoview.PhotoView) RealmResults(io.realm.RealmResults) RequestUserAvatarDelete(net.iGap.request.RequestUserAvatarDelete) TopSheetDialog(net.iGap.module.dialog.topsheet.TopSheetDialog) RequestGroupAvatarDelete(net.iGap.request.RequestGroupAvatarDelete) File(java.io.File) OnChannelAvatarDelete(net.iGap.observers.interfaces.OnChannelAvatarDelete) Color(android.graphics.Color) RealmAvatar(net.iGap.realm.RealmAvatar) Glide(com.bumptech.glide.Glide) HelperSaveFile(net.iGap.helper.HelperSaveFile) ProtoGlobal(net.iGap.proto.ProtoGlobal) R(net.iGap.R) ChannelChatRole(net.iGap.module.enums.ChannelChatRole) DbManager(net.iGap.module.accountManager.DbManager) RealmAttachment(net.iGap.realm.RealmAttachment) ArrayList(java.util.ArrayList) RippleView(net.iGap.libs.rippleeffect.RippleView)

Example 5 with OnComplete

use of net.iGap.observers.interfaces.OnComplete in project iGap-Android by KianIranian-STDG.

the class FragmentShearedMedia method initComponent.

private void initComponent(View view) {
    FrameLayout toolbarLayout = view.findViewById(R.id.frg_shared_media_ll_toolbar_layout);
    FragmentMediaContainer mediaContainer = new FragmentMediaContainer(getContext(), this);
    mediaContainer.setListener(i -> {
        switch(i) {
            case FragmentMediaContainer.CALL_TAG:
                getActivity().startActivity(new Intent(getContext(), CallActivity.class));
                break;
            case FragmentMediaContainer.MEDIA_TAG:
                if (!MusicPlayer.isVoice) {
                    Intent intent = new Intent(context, ActivityMain.class);
                    intent.putExtra(ActivityMain.openMediaPlayer, true);
                    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                    getActivity().startActivity(intent);
                }
                break;
            case FragmentMediaContainer.PLAY_TAG:
                break;
        }
    });
    sharedMediaToolbar = new Toolbar(getContext());
    sharedMediaToolbar.setBackIcon(new BackDrawable(false));
    sharedMediaToolbar.createToolbarItems();
    sharedMediaToolbar.setTitle(getString(R.string.shared_media));
    sharedMediaToolbar.setListener(i -> {
        switch(i) {
            case -1:
                if (isSelectedMode) {
                    adapter.resetSelected();
                    sharedMediaToolbar.hideActionToolbar();
                    return;
                }
                popBackStackFragment();
                break;
            case deleteTag:
                DbManager.getInstance().doRealmTask(realm -> {
                    String count = SelectedList.size() + "";
                    final RealmRoom realmRoom = RealmRoom.getRealmRoom(realm, roomId);
                    if (roomType == ProtoGlobal.Room.Type.CHAT && bothDeleteMessageId != null && bothDeleteMessageId.size() > 0) {
                        // TODO: 1/10/21 OPTIMAZE CODE
                        // show both Delete check box
                        String delete;
                        if (HelperCalander.isPersianUnicode) {
                            delete = HelperCalander.convertToUnicodeFarsiNumber(requireContext().getResources().getString(R.string.st_desc_delete) + count);
                        } else {
                            delete = HelperCalander.convertToUnicodeFarsiNumber(requireContext().getResources().getString(R.string.st_desc_delete) + "the");
                        }
                        new MaterialDialog.Builder(getContext()).limitIconToDefaultSize().content(delete).title(R.string.message).positiveText(R.string.ok).negativeText(R.string.cancel).onPositive((dialog, which) -> {
                            if (!dialog.isPromptCheckBoxChecked()) {
                                bothDeleteMessageId = null;
                            }
                            if (realmRoom != null) {
                                ArrayList<Long> selectedListForDel = new ArrayList<>();
                                ArrayList<Long> selectedDocumentListForDel = new ArrayList<>();
                                for (StructShearedMedia item : SelectedList) {
                                    selectedListForDel.add(item.messageId);
                                    selectedDocumentListForDel.add(item.documentId);
                                }
                                getMessageController().deleteSelectedMessage(roomType.getNumber(), roomId, selectedListForDel, selectedDocumentListForDel, bothDeleteMessageId);
                            }
                            resetItems();
                        }).checkBoxPromptRes(R.string.delete_item_dialog, false, null).show();
                    } else {
                        new MaterialDialog.Builder(requireContext()).title(R.string.message).content(getContext().getResources().getString(R.string.st_desc_delete) + count).positiveText(R.string.ok).negativeText(R.string.cancel).onPositive(new MaterialDialog.SingleButtonCallback() {

                            @Override
                            public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
                                bothDeleteMessageId = null;
                                if (realmRoom != null) {
                                    ArrayList<Long> messageIds = new ArrayList<>();
                                    ArrayList<Long> documentIds = new ArrayList<>();
                                    for (StructShearedMedia item : SelectedList) {
                                        messageIds.add(item.messageId);
                                        documentIds.add(item.documentId);
                                    }
                                    getMessageController().deleteSelectedMessage(roomType.getNumber(), roomId, messageIds, documentIds, bothDeleteMessageId);
                                }
                                resetItems();
                            }
                        }).show();
                    }
                });
                break;
            case forwardTag:
                ArrayList<MessageObject> messageInfos = new ArrayList<>(SelectedList.size());
                for (StructShearedMedia media : SelectedList) {
                    messageInfos.add(MessageObject.create(media.item));
                }
                FragmentChat.mForwardMessages = messageInfos;
                adapter.resetSelected();
                if (getActivity() instanceof ActivityMain) {
                    ((ActivityMain) getActivity()).setForwardMessage(true);
                    ((ActivityMain) getActivity()).removeAllFragmentFromMain();
                /*new HelperFragment(getActivity().getSupportFragmentManager()).popBackStack(3);*/
                }
                break;
            case seeInChatTag:
                if (SelectedList.size() == 1) {
                    long messageId = SelectedList.get(0).messageId;
                    long documentId = SelectedList.get(0).documentId;
                    RealmRoomMessage.setGap(messageId, documentId);
                    goToPositionFromShardMedia.goToPosition(messageId, documentId);
                    goToPosition = true;
                    popBackStackFragment();
                    adapter.resetSelected();
                    popBackStackFragment();
                }
                break;
        }
    });
    createActionMode();
    toolbarLayout.addView(mediaContainer, LayoutCreator.createFrame(LayoutCreator.MATCH_PARENT, 39, Gravity.BOTTOM, 0, 60, 0, 0));
    toolbarLayout.addView(sharedMediaToolbar);
    progressBar = view.findViewById(R.id.asm_progress_bar_waiting);
    AppUtils.setProgresColler(progressBar);
    mediaTypesLayout = view.findViewById(R.id.asm_ll_media_types_buttons);
    complete = new OnComplete() {

        @Override
        public void complete(boolean result, String messageOne, String MessageTwo) {
            int whatAction = 0;
            String number = "0";
            if (messageOne != null) {
                if (messageOne.length() > 0)
                    whatAction = Integer.parseInt(messageOne);
            }
            if (MessageTwo != null)
                if (MessageTwo.length() > 0)
                    number = MessageTwo;
            callBack(result, whatAction, number);
        }
    };
    recyclerView = view.findViewById(R.id.asm_recycler_view_sheared_media);
    recyclerView.setItemViewCacheSize(400);
    recyclerView.setItemAnimator(null);
    onScrollListener = new RecyclerView.OnScrollListener() {

        @Override
        public void onScrollStateChanged(final RecyclerView recyclerView, int newState) {
            super.onScrollStateChanged(recyclerView, newState);
            if (isThereAnyMoreItemToLoad) {
                if (!isSendRequestForLoading) {
                    int lastVisiblePosition = ((LinearLayoutManager) recyclerView.getLayoutManager()).findLastVisibleItemPosition();
                    if (lastVisiblePosition + 30 >= offset) {
                        new RequestClientSearchRoomHistory().clientSearchRoomHistory(roomId, nextMessageId, nextDocumentId, mFilter);
                        isSendRequestForLoading = true;
                        progressBar.setVisibility(View.VISIBLE);
                    }
                }
            }
        }
    };
    recyclerView.addOnScrollListener(onScrollListener);
    checkSelectedDefaultTab();
    makeSharedTypesViews();
    checkSharedButtonsBackgrounds();
}
Also used : ArrayList(java.util.ArrayList) BackDrawable(net.iGap.messenger.ui.toolBar.BackDrawable) CallActivity(net.iGap.activities.CallActivity) ActivityMain(net.iGap.activities.ActivityMain) NonNull(androidx.annotation.NonNull) RealmRoom(net.iGap.realm.RealmRoom) Toolbar(net.iGap.messenger.ui.toolBar.Toolbar) MaterialDialog(com.afollestad.materialdialogs.MaterialDialog) FragmentMediaContainer(net.iGap.messenger.ui.components.FragmentMediaContainer) RequestClientSearchRoomHistory(net.iGap.request.RequestClientSearchRoomHistory) OnComplete(net.iGap.observers.interfaces.OnComplete) Intent(android.content.Intent) DialogAction(com.afollestad.materialdialogs.DialogAction) FrameLayout(android.widget.FrameLayout) RecyclerView(androidx.recyclerview.widget.RecyclerView) MessageObject(net.iGap.structs.MessageObject)

Aggregations

OnComplete (net.iGap.observers.interfaces.OnComplete)6 ArrayList (java.util.ArrayList)3 ProtoGlobal (net.iGap.proto.ProtoGlobal)3 RealmRoom (net.iGap.realm.RealmRoom)3 MaterialDialog (com.afollestad.materialdialogs.MaterialDialog)2 File (java.io.File)2 G (net.iGap.G)2 HelperImageBackColor (net.iGap.helper.HelperImageBackColor)2 HelperLog (net.iGap.helper.HelperLog)2 AndroidUtils (net.iGap.module.AndroidUtils)2 AccountManager (net.iGap.module.accountManager.AccountManager)2 DbManager (net.iGap.module.accountManager.DbManager)2 DownloadObject (net.iGap.module.downloader.DownloadObject)2 Downloader (net.iGap.module.downloader.Downloader)2 Status (net.iGap.module.downloader.Status)2 RealmAvatar (net.iGap.realm.RealmAvatar)2 RealmRegisteredInfo (net.iGap.realm.RealmRegisteredInfo)2 SuppressLint (android.annotation.SuppressLint)1 Context (android.content.Context)1 Intent (android.content.Intent)1