Search in sources :

Example 6 with AbstractObject

use of net.iGap.network.AbstractObject in project iGap-Android by KianIranian-STDG.

the class StoryDisplayFragment method updateStory.

private void updateStory() {
    storyDisplayImage.setVisibility(View.VISIBLE);
    storyProgress.setVisibility(View.VISIBLE);
    storyVideoProgress.setVisibility(View.GONE);
    if (stories.get(counter).getTxt() == null || stories.get(counter).getTxt().trim().equals("") || stories.get(counter).getTxt().trim().isEmpty()) {
        captionRootView.setVisibility(View.GONE);
    } else if (stories.get(counter).getTxt() != null) {
        captionRootView.setVisibility(View.VISIBLE);
        if (stories.get(counter).getTxt().length() >= 100) {
            captionRootView.setTextSize(20);
        } else if (stories.get(counter).getTxt().length() >= 17) {
            captionRootView.setTextSize(28);
        } else {
            captionRootView.setTextSize(40);
        }
        captionRootView.setMovementMethod(ScrollingMovementMethod.getInstance());
        captionRootView.setText(stories.get(counter).getTxt());
    }
    storyTime.setText(LastSeenTimeUtil.computeTime(context, stories.get(counter).getUserId(), stories.get(counter).getStoryData() / 1000L, false, false));
    nickName.setText(stories.get(counter).getDisplayName());
    if (stories.get(counter).isRoom()) {
        chatIconTv.setVisibility(View.VISIBLE);
    } else {
        chatIconTv.setVisibility(View.GONE);
    }
    if (stories.get(counter).isVerified()) {
        verifyIconTv.setVisibility(View.VISIBLE);
    } else {
        verifyIconTv.setVisibility(View.GONE);
    }
    replyTo.setText(EmojiManager.getInstance().replaceEmoji(storyUser.getUserName(), replyTo.getPaint().getFontMetricsInt()) + " \u25CF " + context.getString(R.string.moments_string));
    replyCaption.setText(stories.get(counter).getTxt() != null ? stories.get(counter).getTxt() : "Photo");
    AttachmentObject attachmentObject = stories.get(counter).getAttachment();
    String path = attachmentObject.filePath != null ? attachmentObject.filePath : attachmentObject.thumbnailPath;
    if (stories.get(counter).getStoryId() != 0 && !getMessageDataStorage().isStorySeen(stories.get(counter).getStoryId())) {
        AbstractObject req = null;
        IG_RPC.Story_Add_View story_add_view = new IG_RPC.Story_Add_View();
        story_add_view.storyId = String.valueOf(stories.get(counter).getStoryId());
        req = story_add_view;
        getRequestManager().sendRequest(req, (response, error) -> {
            if (error == null) {
                IG_RPC.Res_Story_Add_View res = (IG_RPC.Res_Story_Add_View) response;
                getMessageDataStorage().storySetSeen(res.storyId);
            } else {
                storyVideoProgress.setVisibility(View.GONE);
            }
        });
    }
    if (counter == (stories.size() - 1) && !getMessageDataStorage().isAllStorySeen(storyUser.getRoomId() == 0, storyUser.getRoomId() == 0 ? storyUser.getUserId() : storyUser.getRoomId())) {
        getMessageDataStorage().storySetSeenAll(storyUser.getRoomId() == 0 ? storyUser.getUserId() : storyUser.getRoomId(), true, storyUser.getRoomId() == 0);
        int storyUnSeenCount = getMessageDataStorage().getUnSeenStoryCount();
        if (storyUnSeenCount > 0) {
            G.onUnreadChange.onChange(storyUnSeenCount, true);
        } else {
            G.onUnreadChange.onChange(0, true);
        }
        EventManager.getInstance(AccountManager.selectedAccount).postEvent(EventManager.STORY_ALL_SEEN);
    }
    File file = new File(path != null ? path : "");
    storyDisplayImage.setImageBitmap(null);
    if (file.exists()) {
        loadImage(path);
    } else {
        path = attachmentObject.thumbnailPath != null ? attachmentObject.thumbnailPath : "";
        file = new File(path);
        if (file.exists()) {
            Story story = stories.get(counter);
            if (story.getAttachment().filePath != null && (new File(story.getAttachment().filePath).exists())) {
                return;
            }
            Bitmap bitmap = AndroidUtils.blurImage(BitmapFactory.decodeFile(path));
            storyDisplayImage.setImageBitmap(bitmap);
        } else {
            ProtoFileDownload.FileDownload.Selector selector;
            if (attachmentObject.largeThumbnail != null) {
                selector = ProtoFileDownload.FileDownload.Selector.LARGE_THUMBNAIL;
                path = AndroidUtils.getFilePathWithCashId(attachmentObject.smallThumbnail.cacheId, attachmentObject.name, G.context.getExternalFilesDir(Environment.DIRECTORY_PICTURES).getAbsolutePath(), true);
                if (new File(path).exists()) {
                    Story story = stories.get(counter);
                    if (story.getAttachment().filePath != null && (new File(story.getAttachment().filePath).exists())) {
                        return;
                    }
                    Bitmap bitmap = AndroidUtils.blurImage(BitmapFactory.decodeFile(path));
                    storyDisplayImage.setImageBitmap(bitmap);
                } else {
                    DownloadObject downloadObject = DownloadObject.createForThumb(attachmentObject, ProtoGlobal.RoomMessageType.STORY.getNumber(), false);
                    if (downloadObject != null) {
                        downloadObject.downloadId = stories.get(counter).getStoryId();
                        getDownloader().download(downloadObject, selector, arg -> {
                            if (arg.status == Status.SUCCESS) {
                                if (arg.data != null) {
                                    String filePath = arg.data.getFilePath();
                                    Story story = stories.get(counter);
                                    if (story.getStoryId() == arg.data.getDownloadObject().downloadId) {
                                        if (story.getAttachment().filePath != null && (new File(story.getAttachment().filePath).exists())) {
                                            return;
                                        }
                                        Bitmap bitmap = AndroidUtils.blurImage(BitmapFactory.decodeFile(filePath));
                                        G.runOnUiThread(() -> storyDisplayImage.setImageBitmap(bitmap));
                                    }
                                }
                            }
                        });
                    }
                }
            } else if (attachmentObject.smallThumbnail != null) {
                selector = ProtoFileDownload.FileDownload.Selector.SMALL_THUMBNAIL;
                path = AndroidUtils.getFilePathWithCashId(attachmentObject.smallThumbnail.cacheId, attachmentObject.name, G.context.getExternalFilesDir(Environment.DIRECTORY_PICTURES).getAbsolutePath(), true);
                if (new File(path).exists()) {
                    Story story = stories.get(counter);
                    if (story.getAttachment().filePath != null && (new File(story.getAttachment().filePath).exists())) {
                        return;
                    }
                    Bitmap bitmap = AndroidUtils.blurImage(BitmapFactory.decodeFile(path));
                    storyDisplayImage.setImageBitmap(bitmap);
                } else {
                    DownloadObject downloadObject = DownloadObject.createForThumb(attachmentObject, ProtoGlobal.RoomMessageType.STORY.getNumber(), false);
                    if (downloadObject != null) {
                        downloadObject.downloadId = stories.get(counter).getStoryId();
                        getDownloader().download(downloadObject, selector, arg -> {
                            if (arg.status == Status.SUCCESS) {
                                if (arg.data != null) {
                                    String filePath = arg.data.getFilePath();
                                    Story story = stories.get(counter);
                                    if (story.getStoryId() == arg.data.getDownloadObject().downloadId) {
                                        if (story.getAttachment().filePath != null && (new File(story.getAttachment().filePath).exists())) {
                                            return;
                                        }
                                        Bitmap bitmap = AndroidUtils.blurImage(BitmapFactory.decodeFile(filePath));
                                        G.runOnUiThread(() -> storyDisplayImage.setImageBitmap(bitmap));
                                    }
                                }
                            }
                        });
                    }
                }
            }
        }
        DownloadObject object = DownloadObject.createForStory(attachmentObject, stories.get(counter).getStoryId(), true);
        if (object != null) {
            ProtoFileDownload.FileDownload.Selector imageSelector = ProtoFileDownload.FileDownload.Selector.FILE;
            Downloader.getInstance(AccountManager.selectedAccount).download(object, imageSelector, HttpRequest.PRIORITY.PRIORITY_HIGH, arg -> {
                if (arg.status == Status.SUCCESS && arg.data != null) {
                    String filepath = arg.data.getFilePath();
                    long downloadId = arg.data.getDownloadObject().downloadId;
                    Story story = stories.get(counter);
                    if (downloadId == story.getStoryId()) {
                        story.getAttachment().filePath = filepath;
                        G.runOnUiThread(() -> loadImage(filepath));
                    }
                }
            });
        }
    }
}
Also used : AnticipateInterpolator(android.view.animation.AnticipateInterpolator) Bundle(android.os.Bundle) ProgressBar(android.widget.ProgressBar) NonNull(androidx.annotation.NonNull) ProtoFileDownload(net.iGap.proto.ProtoFileDownload) FrameLayout(android.widget.FrameLayout) ImageView(android.widget.ImageView) LastSeenTimeUtil(net.iGap.module.LastSeenTimeUtil) Drawable(android.graphics.drawable.Drawable) AdditionalType(net.iGap.module.additionalData.AdditionalType) HelperFragment(net.iGap.helper.HelperFragment) HelperCalander(net.iGap.helper.HelperCalander) ScrollingMovementMethod(android.text.method.ScrollingMovementMethod) ChatSendMessageUtil(net.iGap.module.ChatSendMessageUtil) RealmRoom(net.iGap.realm.RealmRoom) BaseFragment(net.iGap.fragments.BaseFragment) Downloader(net.iGap.module.downloader.Downloader) StringRes(androidx.annotation.StringRes) FontIconTextView(net.iGap.module.FontIconTextView) Nullable(androidx.annotation.Nullable) SHP_SETTING(net.iGap.module.SHP_SETTING) LinearLayoutManager(androidx.recyclerview.widget.LinearLayoutManager) EventManager(net.iGap.observers.eventbus.EventManager) AbstractObject(net.iGap.network.AbstractObject) DownloadObject(net.iGap.module.downloader.DownloadObject) SuggestedStickerAdapter(net.iGap.fragments.emoji.SuggestedStickerAdapter) EmojiManager(net.iGap.libs.emojiKeyboard.emoji.EmojiManager) LayerDrawable(android.graphics.drawable.LayerDrawable) AttachmentObject(net.iGap.structs.AttachmentObject) ViewMaker.setTextSize(net.iGap.adapter.items.chat.ViewMaker.setTextSize) Environment(android.os.Environment) AccountManager(net.iGap.module.accountManager.AccountManager) BitmapFactory(android.graphics.BitmapFactory) PlayerView(com.google.android.exoplayer2.ui.PlayerView) ViewUserDialogFragment(net.iGap.story.ViewUserDialogFragment) GradientDrawable(android.graphics.drawable.GradientDrawable) Toast(android.widget.Toast) LayoutCreator(net.iGap.helper.LayoutCreator) AvatarHandler(net.iGap.helper.avatar.AvatarHandler) StickerSettingFragment(net.iGap.fragments.emoji.remove.StickerSettingFragment) MessageObject(net.iGap.structs.MessageObject) TextUtils(android.text.TextUtils) RecyclerListView(net.iGap.module.customView.RecyclerListView) File(java.io.File) Gravity(android.view.Gravity) StructIGSticker(net.iGap.fragments.emoji.struct.StructIGSticker) EventEditText(net.iGap.module.customView.EventEditText) SharedPreferences(android.content.SharedPreferences) TypedValue(android.util.TypedValue) NotifyFrameLayout(net.iGap.libs.emojiKeyboard.NotifyFrameLayout) DbManager(net.iGap.module.accountManager.DbManager) EditText(android.widget.EditText) Rect(android.graphics.Rect) LinearLayout(android.widget.LinearLayout) AppUtils(net.iGap.module.AppUtils) StoryCell(net.iGap.story.storyviews.StoryCell) Animator(android.animation.Animator) Theme(net.iGap.module.Theme) G(net.iGap.G) RealmUserInfo(net.iGap.realm.RealmUserInfo) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Gson(com.google.gson.Gson) ActivityInfo(android.content.pm.ActivityInfo) View(android.view.View) KeyboardView(net.iGap.libs.emojiKeyboard.KeyboardView) RecyclerView(androidx.recyclerview.widget.RecyclerView) ParamWithAvatarType(net.iGap.helper.avatar.ParamWithAvatarType) Status(net.iGap.module.downloader.Status) ObjectAnimator(android.animation.ObjectAnimator) RealmStory(net.iGap.realm.RealmStory) DisplayMetrics(android.util.DisplayMetrics) ViewGroup(android.view.ViewGroup) Objects(java.util.Objects) List(java.util.List) CompositeDisposable(io.reactivex.disposables.CompositeDisposable) Disposable(io.reactivex.disposables.Disposable) TextView(android.widget.TextView) FragmentSettingAddStickers(net.iGap.fragments.emoji.add.FragmentSettingAddStickers) HttpRequest(net.iGap.module.downloader.HttpRequest) StickerRepository(net.iGap.repository.StickerRepository) Typeface(android.graphics.Typeface) Context(android.content.Context) AndroidUtils(net.iGap.module.AndroidUtils) KeyEvent(android.view.KeyEvent) ResourcesCompat(androidx.core.content.res.ResourcesCompat) TimeUtils(net.iGap.module.TimeUtils) RealmStickerItem(net.iGap.realm.RealmStickerItem) MotionEvent(android.view.MotionEvent) ExpandableTextView(net.iGap.story.ExpandableTextView) MODE_PRIVATE(android.content.Context.MODE_PRIVATE) AnimatorSet(android.animation.AnimatorSet) RealmRoomMessage(net.iGap.realm.RealmRoomMessage) EmojiView(net.iGap.libs.emojiKeyboard.EmojiView) IG_RPC(net.iGap.network.IG_RPC) ImageLoadingView(net.iGap.story.liststories.ImageLoadingView) RealmAdditional(net.iGap.realm.RealmAdditional) InsetDrawable(android.graphics.drawable.InsetDrawable) CircleImageView(net.iGap.module.CircleImageView) Color(android.graphics.Color) Glide(com.bumptech.glide.Glide) Bitmap(android.graphics.Bitmap) ProtoGlobal(net.iGap.proto.ProtoGlobal) R(net.iGap.R) RealmAttachment(net.iGap.realm.RealmAttachment) IG_RPC(net.iGap.network.IG_RPC) DownloadObject(net.iGap.module.downloader.DownloadObject) Bitmap(android.graphics.Bitmap) ProtoFileDownload(net.iGap.proto.ProtoFileDownload) AttachmentObject(net.iGap.structs.AttachmentObject) AbstractObject(net.iGap.network.AbstractObject) File(java.io.File) RealmStory(net.iGap.realm.RealmStory)

Example 7 with AbstractObject

use of net.iGap.network.AbstractObject in project iGap-Android by KianIranian-STDG.

the class ViewUserDialogFragment method onViewCreated.

@Override
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);
    EventManager.getInstance(AccountManager.selectedAccount).addObserver(EventManager.STORY_USER_INFO, this);
    EventManager.getInstance(AccountManager.selectedAccount).addObserver(EventManager.STORY_VIEWS_FETCHED, this);
    userId = new ArrayList<>();
    storyIdList = new ArrayList<>();
    createdAtList = new ArrayList<>();
    displayNameList = new ArrayList<>();
    Collections.sort(userIdList);
    for (int i = 0; i < userIdList.size(); i++) {
        userId.add(userIdList.get(i).userId);
        storyIdList.add(userIdList.get(i).id);
        createdAtList.add(userIdList.get(i).createdTime);
        displayNameList.add(userIdList.get(i).displayName);
    }
    mOffset = userId.size();
    this.storyId = userIdList.get(0).id;
    G.onUserInfoResponse = new OnUserInfoResponse() {

        @Override
        public void onUserInfo(ProtoGlobal.RegisteredUser user, String identity) {
        }

        @Override
        public void onUserInfoTimeOut() {
        }

        @Override
        public void onUserInfoError(int majorCode, int minorCode) {
        }
    };
    recyclerView.setAdapter(listAdapter);
    listAdapter.addRow();
    LinearLayoutManager layoutManager = new LinearLayoutManager(getActivity());
    layoutManager.setOrientation(LinearLayoutManager.VERTICAL);
    recyclerView.setLayoutManager(layoutManager);
    EndlessRecyclerViewScrollListener scrollListener = new EndlessRecyclerViewScrollListener(layoutManager) {

        @Override
        public void onLoadMore(int iPage, int totalItemsCount, RecyclerView view) {
            Log.e("fkldsjfklsjjf", "onLoadMore: ");
            if (!storyViewListFetched && mOffset > 0 && userIdList.size() < count) {
                progressBar.setVisibility(View.VISIBLE);
                AbstractObject req = null;
                IG_RPC.Story_Get_Own_Story_Views story_get_own_story_views = new IG_RPC.Story_Get_Own_Story_Views();
                story_get_own_story_views.offset = mOffset;
                story_get_own_story_views.limit = 50;
                req = story_get_own_story_views;
                MessageDataStorage.getInstance(AccountManager.selectedAccount).getRequestManager().sendRequest(req, (response, error) -> {
                    if (error == null) {
                        IG_RPC.Res_Story_Get_Own_Story_Views res = (IG_RPC.Res_Story_Get_Own_Story_Views) response;
                        mOffset += 50;
                        if (res.groupedViews.size() > 0) {
                            MessageDataStorage.getInstance(AccountManager.selectedAccount).updateOwnViews(res.groupedViews);
                        } else if (userIdList.size() >= count) {
                            storyViewListFetched = true;
                        } else {
                            progressBar.setVisibility(View.GONE);
                        }
                    } else {
                        progressBar.setVisibility(View.GONE);
                    }
                });
            }
        }
    };
    recyclerView.addOnScrollListener(scrollListener);
// recyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {
// private boolean scrollUpdated;
// private boolean scrollingManually;
// private int prevTop;
// private int prevPosition;
// 
// @Override
// public void onScrollStateChanged(@NonNull RecyclerView recyclerView, int newState) {
// super.onScrollStateChanged(recyclerView, newState);
// scrollingManually = newState == RecyclerView.SCROLL_STATE_DRAGGING;
// }
// 
// @Override
// public void onScrolled(@NonNull RecyclerView recyclerView, int dx, int dy) {
// super.onScrolled(recyclerView, dx, dy);
// 
// LinearLayoutManager layoutManager = (LinearLayoutManager) recyclerView.getLayoutManager();
// firstVisibleItemPosition = layoutManager.findFirstVisibleItemPosition();
// View view = layoutManager.getChildAt(0);
// if (firstVisibleItemPosition > 0 && view != null) {
// firstVisibleItemPositionOffset = view.getTop();
// }
// 
// if (!storyListFetched) {
// if (mOffset > 0) {
// int lastVisiblePosition = ((LinearLayoutManager) recyclerView.getLayoutManager()).findLastVisibleItemPosition();
// if (lastVisiblePosition + 10 >= mOffset) {
// AbstractObject req = null;
// IG_RPC.Story_Get_Own_Story_Views story_get_own_story_views = new IG_RPC.Story_Get_Own_Story_Views();
// story_get_own_story_views.offset = mOffset;
// story_get_own_story_views.limit = 50;
// req = story_get_own_story_views;
// MessageDataStorage.getInstance(AccountManager.selectedAccount).getRequestManager().sendRequest(req, (response, error) -> {
// if (error == null) {
// IG_RPC.Res_Story_Get_Own_Story_Views res = (IG_RPC.Res_Story_Get_Own_Story_Views) response;
// mOffset += res.groupedViews.size();
// MessageDataStorage.getInstance(AccountManager.selectedAccount).updateOwnViews(res.groupedViews);
// 
// } else {
// }
// });
// }
// }
// }
// 
// int firstVisibleItem = layoutManager.findFirstVisibleItemPosition();
// if (firstVisibleItem != RecyclerView.NO_POSITION) {
// RecyclerView.ViewHolder holder = recyclerView.findViewHolderForAdapterPosition(firstVisibleItem);
// if (holder != null && holder.getAdapterPosition() != 0) {
// int firstViewTop = holder.itemView.getTop();
// boolean goingDown;
// boolean changed = true;
// if (prevPosition == firstVisibleItem) {
// final int topDelta = prevTop - firstViewTop;
// goingDown = firstViewTop < prevTop;
// changed = Math.abs(topDelta) > 1;
// } else {
// goingDown = firstVisibleItem > prevPosition;
// }
// prevPosition = firstVisibleItem;
// prevTop = firstViewTop;
// scrollUpdated = true;
// }
// }
// }
// });
}
Also used : IG_RPC(net.iGap.network.IG_RPC) ProtoGlobal(net.iGap.proto.ProtoGlobal) LinearLayoutManager(androidx.recyclerview.widget.LinearLayoutManager) OnUserInfoResponse(net.iGap.observers.interfaces.OnUserInfoResponse) EndlessRecyclerViewScrollListener(net.iGap.module.EndlessRecyclerViewScrollListener) AbstractObject(net.iGap.network.AbstractObject) RecyclerView(androidx.recyclerview.widget.RecyclerView)

Example 8 with AbstractObject

use of net.iGap.network.AbstractObject in project iGap-Android by KianIranian-STDG.

the class MyStatusStoryListFragment method onLongClick.

@Override
public void onLongClick(View itemView, int position) {
    StoryCell storyCell = (StoryCell) itemView;
    if ((storyCell.getSendStatus() == MessageObject.STATUS_FAILED || storyCell.getSendStatus() == MessageObject.STATUS_SENT) && (!storyCell.isRoom() || listMode == 1)) {
        MaterialDialog dialog = new MaterialDialog.Builder(getContext()).title(getResources().getString(R.string.delete_status_update)).titleGravity(GravityEnum.START).negativeText(R.string.cansel).positiveText(R.string.ok).onNegative((dialog1, which) -> dialog1.dismiss()).show();
        dialog.getActionButton(DialogAction.POSITIVE).setOnClickListener(view -> {
            progressBar.setVisibility(View.VISIBLE);
            recyclerListView.setVisibility(View.GONE);
            if (storyCell.getSendStatus() == MessageObject.STATUS_FAILED) {
                getMessageDataStorage().deleteUserStoryWithUploadId(storyCell.getUploadId(), storyCell.getUserId());
            } else {
                AbstractObject req = null;
                IG_RPC.Story_Delete story_delete = new IG_RPC.Story_Delete();
                story_delete.storyId = storyCell.getStoryId();
                req = story_delete;
                getRequestManager().sendRequest(req, (response, error) -> {
                    if (error == null) {
                        IG_RPC.Res_Story_Delete res = (IG_RPC.Res_Story_Delete) response;
                        getMessageDataStorage().deleteUserStoryWithStoryId(res.storyId, res.userId);
                    } else {
                    }
                });
            }
            dialog.dismiss();
        });
    }
}
Also used : LinearLayout(android.widget.LinearLayout) Bundle(android.os.Bundle) ToolbarListener(net.iGap.observers.interfaces.ToolbarListener) ProgressBar(android.widget.ProgressBar) NonNull(androidx.annotation.NonNull) UploadObject(net.iGap.module.upload.UploadObject) FrameLayout(android.widget.FrameLayout) StoryCell(net.iGap.story.storyviews.StoryCell) Theme(net.iGap.module.Theme) WALLET_REQUEST_CODE(net.iGap.activities.ActivityMain.WALLET_REQUEST_CODE) Drawable(android.graphics.drawable.Drawable) G(net.iGap.G) StatusTextFragment(net.iGap.story.StatusTextFragment) G.isAppRtl(net.iGap.G.isAppRtl) AccelerateDecelerateInterpolator(android.view.animation.AccelerateDecelerateInterpolator) HttpUploader(net.iGap.helper.upload.ApiBased.HttpUploader) RealmUserInfo(net.iGap.realm.RealmUserInfo) ContextThemeWrapper(android.view.ContextThemeWrapper) View(android.view.View) RecyclerView(androidx.recyclerview.widget.RecyclerView) HelperFragment(net.iGap.helper.HelperFragment) StoryPagerFragment(net.iGap.story.StoryPagerFragment) MainStoryObject(net.iGap.story.MainStoryObject) MessageController(net.iGap.controllers.MessageController) PhotoViewer(net.iGap.story.PhotoViewer) BaseFragment(net.iGap.fragments.BaseFragment) ViewGroup(android.view.ViewGroup) Uploader(net.iGap.module.upload.Uploader) Objects(java.util.Objects) List(java.util.List) Nullable(androidx.annotation.Nullable) BackDrawable(net.iGap.messenger.ui.toolBar.BackDrawable) HttpRequest(net.iGap.module.downloader.HttpRequest) LinearLayoutManager(androidx.recyclerview.widget.LinearLayoutManager) MaterialDialog(com.afollestad.materialdialogs.MaterialDialog) EventManager(net.iGap.observers.eventbus.EventManager) AbstractObject(net.iGap.network.AbstractObject) AndroidUtils(net.iGap.module.AndroidUtils) StoryViewFragment(net.iGap.story.viewPager.StoryViewFragment) GravityEnum(com.afollestad.materialdialogs.GravityEnum) AccountManager(net.iGap.module.accountManager.AccountManager) Intent(android.content.Intent) StoryObject(net.iGap.story.StoryObject) SUID(net.iGap.module.SUID) ArrayList(java.util.ArrayList) AnimatorSet(android.animation.AnimatorSet) LayoutCreator(net.iGap.helper.LayoutCreator) Toolbar(net.iGap.messenger.ui.toolBar.Toolbar) IG_RPC(net.iGap.network.IG_RPC) ToolbarItems(net.iGap.messenger.ui.toolBar.ToolbarItems) ActivityMain.setMediaLayout(net.iGap.activities.ActivityMain.setMediaLayout) LayoutInflater(android.view.LayoutInflater) MessageObject(net.iGap.structs.MessageObject) DialogAction(com.afollestad.materialdialogs.DialogAction) RecyclerListView(net.iGap.module.customView.RecyclerListView) IconView(net.iGap.messenger.ui.components.IconView) Color(android.graphics.Color) Gravity(android.view.Gravity) StructBottomSheet(net.iGap.module.structs.StructBottomSheet) ProtoGlobal(net.iGap.proto.ProtoGlobal) R(net.iGap.R) HeaderCell(net.iGap.story.liststories.cells.HeaderCell) DbManager(net.iGap.module.accountManager.DbManager) RealmAttachment(net.iGap.realm.RealmAttachment) ValueAnimator(android.animation.ValueAnimator) IG_RPC(net.iGap.network.IG_RPC) MaterialDialog(com.afollestad.materialdialogs.MaterialDialog) AbstractObject(net.iGap.network.AbstractObject) StoryCell(net.iGap.story.storyviews.StoryCell)

Example 9 with AbstractObject

use of net.iGap.network.AbstractObject in project iGap-Android by KianIranian-STDG.

the class MyStatusStoryListFragment method deleteStory.

@Override
public void deleteStory(StoryCell storyCell, long storyId, long roomId, boolean isRoom) {
    if (isRoom && listMode == 0) {
        getActivity().getSupportFragmentManager().beginTransaction().addToBackStack(null).add(R.id.mainFrame, new MyStatusStoryListFragment(roomId, 1)).commit();
    // new HelperFragment(getActivity().getSupportFragmentManager(), new MyStatusStoryListFragment(1)).setReplace(false).load();
    } else {
        MaterialDialog dialog = new MaterialDialog.Builder(getContext()).title(getResources().getString(R.string.delete_status_update)).titleGravity(GravityEnum.START).negativeText(R.string.cansel).positiveText(R.string.ok).onNegative((dialog1, which) -> dialog1.dismiss()).show();
        dialog.getActionButton(DialogAction.POSITIVE).setOnClickListener(view -> {
            progressBar.setVisibility(View.VISIBLE);
            recyclerListView.setVisibility(View.GONE);
            if (storyCell.getSendStatus() == MessageObject.STATUS_FAILED) {
                getMessageDataStorage().deleteUserStoryWithUploadId(storyCell.getUploadId(), storyCell.getUserId());
            } else {
                AbstractObject req = null;
                IG_RPC.Story_Delete story_delete = new IG_RPC.Story_Delete();
                story_delete.storyId = storyId;
                req = story_delete;
                getRequestManager().sendRequest(req, (response, error) -> {
                    if (error == null) {
                        IG_RPC.Res_Story_Delete res = (IG_RPC.Res_Story_Delete) response;
                        getMessageDataStorage().deleteUserStoryWithStoryId(res.storyId, res.userId);
                    } else {
                    }
                });
            }
            dialog.dismiss();
        });
    }
}
Also used : LinearLayout(android.widget.LinearLayout) Bundle(android.os.Bundle) ToolbarListener(net.iGap.observers.interfaces.ToolbarListener) ProgressBar(android.widget.ProgressBar) NonNull(androidx.annotation.NonNull) UploadObject(net.iGap.module.upload.UploadObject) FrameLayout(android.widget.FrameLayout) StoryCell(net.iGap.story.storyviews.StoryCell) Theme(net.iGap.module.Theme) WALLET_REQUEST_CODE(net.iGap.activities.ActivityMain.WALLET_REQUEST_CODE) Drawable(android.graphics.drawable.Drawable) G(net.iGap.G) StatusTextFragment(net.iGap.story.StatusTextFragment) G.isAppRtl(net.iGap.G.isAppRtl) AccelerateDecelerateInterpolator(android.view.animation.AccelerateDecelerateInterpolator) HttpUploader(net.iGap.helper.upload.ApiBased.HttpUploader) RealmUserInfo(net.iGap.realm.RealmUserInfo) ContextThemeWrapper(android.view.ContextThemeWrapper) View(android.view.View) RecyclerView(androidx.recyclerview.widget.RecyclerView) HelperFragment(net.iGap.helper.HelperFragment) StoryPagerFragment(net.iGap.story.StoryPagerFragment) MainStoryObject(net.iGap.story.MainStoryObject) MessageController(net.iGap.controllers.MessageController) PhotoViewer(net.iGap.story.PhotoViewer) BaseFragment(net.iGap.fragments.BaseFragment) ViewGroup(android.view.ViewGroup) Uploader(net.iGap.module.upload.Uploader) Objects(java.util.Objects) List(java.util.List) Nullable(androidx.annotation.Nullable) BackDrawable(net.iGap.messenger.ui.toolBar.BackDrawable) HttpRequest(net.iGap.module.downloader.HttpRequest) LinearLayoutManager(androidx.recyclerview.widget.LinearLayoutManager) MaterialDialog(com.afollestad.materialdialogs.MaterialDialog) EventManager(net.iGap.observers.eventbus.EventManager) AbstractObject(net.iGap.network.AbstractObject) AndroidUtils(net.iGap.module.AndroidUtils) StoryViewFragment(net.iGap.story.viewPager.StoryViewFragment) GravityEnum(com.afollestad.materialdialogs.GravityEnum) AccountManager(net.iGap.module.accountManager.AccountManager) Intent(android.content.Intent) StoryObject(net.iGap.story.StoryObject) SUID(net.iGap.module.SUID) ArrayList(java.util.ArrayList) AnimatorSet(android.animation.AnimatorSet) LayoutCreator(net.iGap.helper.LayoutCreator) Toolbar(net.iGap.messenger.ui.toolBar.Toolbar) IG_RPC(net.iGap.network.IG_RPC) ToolbarItems(net.iGap.messenger.ui.toolBar.ToolbarItems) ActivityMain.setMediaLayout(net.iGap.activities.ActivityMain.setMediaLayout) LayoutInflater(android.view.LayoutInflater) MessageObject(net.iGap.structs.MessageObject) DialogAction(com.afollestad.materialdialogs.DialogAction) RecyclerListView(net.iGap.module.customView.RecyclerListView) IconView(net.iGap.messenger.ui.components.IconView) Color(android.graphics.Color) Gravity(android.view.Gravity) StructBottomSheet(net.iGap.module.structs.StructBottomSheet) ProtoGlobal(net.iGap.proto.ProtoGlobal) R(net.iGap.R) HeaderCell(net.iGap.story.liststories.cells.HeaderCell) DbManager(net.iGap.module.accountManager.DbManager) RealmAttachment(net.iGap.realm.RealmAttachment) ValueAnimator(android.animation.ValueAnimator) IG_RPC(net.iGap.network.IG_RPC) MaterialDialog(com.afollestad.materialdialogs.MaterialDialog) AbstractObject(net.iGap.network.AbstractObject)

Example 10 with AbstractObject

use of net.iGap.network.AbstractObject in project iGap-Android by KianIranian-STDG.

the class StoryFragment method onViewCreated.

@Override
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);
    getEventManager().addObserver(EventManager.STORY_LIST_FETCHED, this);
    getEventManager().addObserver(EventManager.STORY_DELETED, this);
    getEventManager().addObserver(EventManager.STORY_ALL_SEEN, this);
    getEventManager().addObserver(EventManager.STORY_USER_ADD_NEW, this);
    getEventManager().addObserver(EventManager.STORY_SENDING, this);
    getEventManager().addObserver(EventManager.STORY_UPLOAD, this);
    getEventManager().addObserver(EventManager.STORY_UPLOADED_FAILED, this);
    getEventManager().addObserver(EventManager.STORY_USER_INFO, this);
    getEventManager().addObserver(EventManager.STORY_STATUS_UPLOAD, this);
    getEventManager().addObserver(EventManager.STORY_ROOM_UPLOAD, this);
    getEventManager().addObserver(EventManager.STORY_ROOM_IMAGE_UPLOAD, this);
    mOffset = 0;
    userIdList = new ArrayList<>();
    displayNameList = new ArrayList<>();
    progressBar.setVisibility(View.VISIBLE);
    loadStories();
    floatActionLayout.setOnClickListener(view1 -> {
        HelperTracker.sendTracker(HelperTracker.TRACKER_MOMENTS_CREATE_PICTURE_PAGE);
        new HelperFragment(getActivity().getSupportFragmentManager(), new StoryPagerFragment(false)).setReplace(false).load();
    });
    customStatusActionLayout.setOnClickListener(view12 -> {
        HelperTracker.sendTracker(HelperTracker.TRACKER_MOMENTS_CREATE_TEXT_PAGE);
        new HelperFragment(StoryFragment.this.getActivity().getSupportFragmentManager(), new StatusTextFragment(false)).setReplace(false).load();
    });
    swipeRefreshLayout.setOnRefreshListener(() -> {
        swipeRefreshLayout.setRefreshing(false);
        DbManager.getInstance().doRealmTransaction(realm -> {
            MessageController.getInstance(AccountManager.selectedAccount).getStories(realm.where(RealmContacts.class).findAll().size());
        });
    });
    recyclerListView.addOnScrollListener(new RecyclerView.OnScrollListener() {

        private boolean scrollUpdated;

        private boolean scrollingManually;

        private int prevTop;

        private int prevPosition;

        private int currentScrollPosition = 0;

        @Override
        public void onScrollStateChanged(@NonNull RecyclerView recyclerView, int newState) {
            super.onScrollStateChanged(recyclerView, newState);
            scrollingManually = newState == RecyclerView.SCROLL_STATE_DRAGGING;
        }

        @Override
        public void onScrolled(@NonNull RecyclerView recyclerView, int dx, int dy) {
            super.onScrolled(recyclerView, dx, dy);
            currentScrollPosition += dy;
            LinearLayoutManager layoutManager = (LinearLayoutManager) recyclerView.getLayoutManager();
            firstVisibleItemPosition = layoutManager.findFirstVisibleItemPosition();
            View view = layoutManager.getChildAt(0);
            if (firstVisibleItemPosition > 0 && view != null) {
                firstVisibleItemPositionOffset = view.getTop();
            }
            if (!storyListFetched) {
                if (mOffset > 0) {
                    int lastVisiblePosition = ((LinearLayoutManager) recyclerView.getLayoutManager()).findLastVisibleItemPosition();
                    if (lastVisiblePosition + 10 >= mOffset) {
                    // GetStoryList(mOffset, 50);
                    }
                }
            }
            // if (currentScrollPosition == 0) {
            // swipeRefreshLayout.setRefreshing(true);
            // }
            int firstVisibleItem = layoutManager.findFirstVisibleItemPosition();
            if (firstVisibleItem != RecyclerView.NO_POSITION) {
                RecyclerView.ViewHolder holder = recyclerView.findViewHolderForAdapterPosition(firstVisibleItem);
                if (holder != null && holder.getAdapterPosition() != 0) {
                    int firstViewTop = holder.itemView.getTop();
                    boolean goingDown;
                    boolean changed = true;
                    if (prevPosition == firstVisibleItem) {
                        final int topDelta = prevTop - firstViewTop;
                        goingDown = firstViewTop < prevTop;
                        changed = Math.abs(topDelta) > 1;
                    } else {
                        goingDown = firstVisibleItem > prevPosition;
                    }
                    if (changed && scrollUpdated && (goingDown || scrollingManually)) {
                        hideFloatingButton(goingDown);
                    }
                    prevPosition = firstVisibleItem;
                    prevTop = firstViewTop;
                    scrollUpdated = true;
                }
            }
        }
    });
    AbstractObject req = null;
    IG_RPC.Story_Get_Own_Story_Views story_get_own_story_views = new IG_RPC.Story_Get_Own_Story_Views();
    story_get_own_story_views.offset = 0;
    story_get_own_story_views.limit = 50;
    req = story_get_own_story_views;
    getRequestManager().sendRequest(req, (response, error) -> {
        if (error == null) {
            IG_RPC.Res_Story_Get_Own_Story_Views res = (IG_RPC.Res_Story_Get_Own_Story_Views) response;
            getMessageDataStorage().updateOwnViews(res.groupedViews);
        } else {
        }
    });
}
Also used : IG_RPC(net.iGap.network.IG_RPC) LinearLayoutManager(androidx.recyclerview.widget.LinearLayoutManager) View(android.view.View) RecyclerView(androidx.recyclerview.widget.RecyclerView) RecyclerListView(net.iGap.module.customView.RecyclerListView) IconView(net.iGap.messenger.ui.components.IconView) StatusTextFragment(net.iGap.story.StatusTextFragment) AbstractObject(net.iGap.network.AbstractObject) RecyclerView(androidx.recyclerview.widget.RecyclerView) HelperFragment(net.iGap.helper.HelperFragment) StoryPagerFragment(net.iGap.story.StoryPagerFragment) RealmContacts(net.iGap.realm.RealmContacts)

Aggregations

AbstractObject (net.iGap.network.AbstractObject)14 IG_RPC (net.iGap.network.IG_RPC)14 LinearLayoutManager (androidx.recyclerview.widget.LinearLayoutManager)6 RecyclerView (androidx.recyclerview.widget.RecyclerView)6 View (android.view.View)5 HelperFragment (net.iGap.helper.HelperFragment)5 RecyclerListView (net.iGap.module.customView.RecyclerListView)5 AnimatorSet (android.animation.AnimatorSet)3 Color (android.graphics.Color)3 Drawable (android.graphics.drawable.Drawable)3 Bundle (android.os.Bundle)3 Gravity (android.view.Gravity)3 ViewGroup (android.view.ViewGroup)3 FrameLayout (android.widget.FrameLayout)3 LinearLayout (android.widget.LinearLayout)3 IconView (net.iGap.messenger.ui.components.IconView)3 StatusTextFragment (net.iGap.story.StatusTextFragment)3 StoryPagerFragment (net.iGap.story.StoryPagerFragment)3 ValueAnimator (android.animation.ValueAnimator)2 Intent (android.content.Intent)2