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));
}
}
});
}
}
}
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;
// }
// }
// }
// });
}
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();
});
}
}
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();
});
}
}
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 {
}
});
}
Aggregations