use of net.iGap.story.StoryObject in project iGap-Android by KianIranian-STDG.
the class MessageDataStorage method getStoryWithFileToken.
public StoryObject getStoryWithFileToken(String fileToken) {
CountDownLatch countDownLatch = new CountDownLatch(1);
StoryObject[] storyObjects = new StoryObject[1];
storageQueue.postRunnable(() -> {
try {
RealmStoryProto realmStoryProto = database.where(RealmStoryProto.class).equalTo("sessionId", AccountManager.getInstance().getCurrentUser().getId()).equalTo("isForReply", false).equalTo("fileToken", fileToken).findFirst();
if (realmStoryProto != null) {
storyObjects[0] = StoryObject.create(realmStoryProto);
}
countDownLatch.countDown();
} catch (Exception e) {
FileLog.e(e);
} finally {
countDownLatch.countDown();
}
});
try {
countDownLatch.await();
} catch (InterruptedException e) {
e.printStackTrace();
}
return storyObjects[0];
}
use of net.iGap.story.StoryObject in project iGap-Android by KianIranian-STDG.
the class MessageDataStorage method getStoryWithUploadId.
public StoryObject getStoryWithUploadId(long uploadId) {
CountDownLatch countDownLatch = new CountDownLatch(1);
StoryObject[] storyObjects = new StoryObject[1];
storageQueue.postRunnable(() -> {
try {
RealmStoryProto realmStoryProto = database.where(RealmStoryProto.class).equalTo("sessionId", AccountManager.getInstance().getCurrentUser().getId()).equalTo("isForReply", false).equalTo("id", uploadId).findFirst();
if (realmStoryProto != null) {
storyObjects[0] = StoryObject.create(realmStoryProto);
}
countDownLatch.countDown();
} catch (Exception e) {
FileLog.e(e);
} finally {
countDownLatch.countDown();
}
});
try {
countDownLatch.await();
} catch (InterruptedException e) {
e.printStackTrace();
}
return storyObjects[0];
}
use of net.iGap.story.StoryObject in project iGap-Android by KianIranian-STDG.
the class StoryViewFragment method setUpPager.
private void setUpPager() {
List<StoryUser> storyUserList = new ArrayList<>();
for (int i = 0; i < storyResults.size(); i++) {
List<StoryObject> realmStoryProtos = storyResults.get(i).storyObjects;
StoryUser storyUser = new StoryUser();
List<Story> stories = new ArrayList<>();
storyUser.setUserName(storyResults.get(i).displayName);
storyUser.setUserId(storyResults.get(i).userId);
storyUser.setRoomId(storyResults.get(i).roomId);
for (int j = 0; j < realmStoryProtos.size(); j++) {
StoryObject storyObject = realmStoryProtos.get(j);
if (storyResults.get(i).orginatorValue == 0 && storyObject.userId == userId) {
currentPage = i;
} else if (storyResults.get(i).orginatorValue == 1 && storyObject.roomId == roomId) {
currentPage = i;
}
if (isSingle) {
if (storyObject.storyId != 0 && storyObject.storyId == storyId) {
Story story = new Story(null, bitmap, storyObject.caption, storyObject.createdAt, storyObject.userId, storyObject.roomId, storyObject.displayName, storyObject.storyId, storyObject.attachmentObject, null, storyObject.viewCount, storyObject.isForRoom, storyObject.isVerified, storyObject.storyViewInfoObjects);
stories.add(story);
storyUser.setStories(stories);
break;
} else if (storyObject.index == storyId) {
Story story = new Story(null, bitmap, storyObject.caption, storyObject.createdAt, storyObject.userId, storyObject.roomId, storyObject.displayName, storyObject.storyId, storyObject.attachmentObject, null, storyObject.viewCount, storyObject.isForRoom, storyObject.isVerified, storyObject.storyViewInfoObjects);
stories.add(story);
storyUser.setStories(stories);
break;
}
} else {
Story story = new Story(null, bitmap, storyObject.caption, storyObject.createdAt, storyObject.userId, storyObject.roomId, storyObject.displayName, storyObject.storyId, storyObject.attachmentObject, null, storyObject.viewCount, storyObject.isForRoom, storyObject.isVerified, storyObject.storyViewInfoObjects);
stories.add(story);
storyUser.setStories(stories);
}
}
if (storyUser.getStories() != null && storyUser.getStories().size() > 0) {
storyUserList.add(storyUser);
}
}
pagerAdapter = new StoryPagerAdapter(getChildFragmentManager(), FragmentStatePagerAdapter.BEHAVIOR_RESUME_ONLY_CURRENT_FRAGMENT, storyUserList, this, myStory, isForReply);
viewPager.setAdapter(pagerAdapter);
viewPager.setCurrentItem(currentPage);
viewPager.setPageTransformer(true, new PageTransformer());
viewPager.addOnPageChangeListener(new PageChangeListener() {
@Override
void onPageScrollCanceled() {
StoryDisplayFragment fragment = (StoryDisplayFragment) pagerAdapter.findFragmentByPosition(viewPager, currentPage);
// Log.e("mmd", "onPageScrollCanceled resumeCurrentStory: " );
// fragment.resumeCurrentStory();
}
@Override
public void onPageSelected(int position) {
super.onPageSelected(position);
currentPage = position;
}
});
}
use of net.iGap.story.StoryObject in project iGap-Android by KianIranian-STDG.
the class StoryCell method initView.
public void initView(Context context, boolean needDivider, CircleStatus status, ImageLoadingView.Status imageLoadingStatus, IconClicked iconClicked, long createTime) {
removeAllViews();
if (G.themeColor == Theme.DARK) {
setBackground(Theme.getSelectorDrawable(Theme.getInstance().getDividerColor(context)));
} else {
setBackgroundColor(Color.WHITE);
}
this.status = status;
this.needDivider = needDivider;
this.iconClicked = iconClicked;
this.context = context;
setWillNotDraw(!needDivider);
View view;
switch(this.status) {
case CIRCLE_IMAGE:
circleImage = new CircleImageView(getContext());
circleImage.setLayoutParams(LayoutCreator.createFrame(56, 56, (isRtl ? Gravity.RIGHT : Gravity.LEFT) | Gravity.CENTER_VERTICAL, isRtl ? 0 : padding, 8, isRtl ? padding : 0, 8));
view = circleImage;
break;
case LOADING_CIRCLE_IMAGE:
circleImageLoading = new ImageLoadingView(context);
circleImageLoading.setStatus(imageLoadingStatus);
circleImageLoading.setLayoutParams(LayoutCreator.createFrame(72, 72, (isRtl ? Gravity.RIGHT : Gravity.LEFT) | Gravity.CENTER_VERTICAL, isRtl ? 0 : 8, 8, isRtl ? 8 : 0, 8));
view = circleImageLoading;
break;
default:
throw new IllegalStateException("Unexpected value: " + this.status);
}
addView(view);
addIcon = new MaterialDesignTextView(context);
addIcon.setText(R.string.icon_add_whit_circle);
addIcon.setTextColor(getResources().getColor(R.color.green));
addIcon.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 18);
addIcon.setGravity(isRtl ? Gravity.LEFT : Gravity.RIGHT);
addView(addIcon, LayoutCreator.createFrame(18, 18, (isRtl ? Gravity.RIGHT : Gravity.LEFT) | Gravity.BOTTOM, isRtl ? 0 : padding, 8, isRtl ? padding : 0, 8));
topViewRootView = new LinearLayout(context);
topViewRootView.setOrientation(LinearLayout.HORIZONTAL);
topViewRootView.setGravity(Gravity.CENTER);
addView(topViewRootView, LayoutCreator.createFrame(LayoutCreator.WRAP_CONTENT, LayoutCreator.WRAP_CONTENT, (isRtl ? Gravity.RIGHT : Gravity.LEFT) | Gravity.TOP, isRtl ? padding : ((padding * 2) + 56), 11.5f, isRtl ? ((padding * 2) + 56) : padding, 0));
channelIconTv = new FontIconTextView(getContext());
setTextSize(channelIconTv, R.dimen.dp14);
channelIconTv.setText(R.string.icon_channel);
channelIconTv.setTextColor(Theme.getInstance().getAccentColor(channelIconTv.getContext()));
channelIconTv.setVisibility(GONE);
topViewRootView.addView(channelIconTv, LayoutCreator.createLinear(LayoutCreator.WRAP_CONTENT, LayoutCreator.WRAP_CONTENT, Gravity.CENTER));
topText = new TextView(context);
topText.setSingleLine();
topText.setTypeface(ResourcesCompat.getFont(getContext(), R.font.main_font_bold));
ViewMaker.setTextSize(topText, R.dimen.dp15);
topText.setSingleLine(true);
topText.setEllipsize(TextUtils.TruncateAt.END);
topText.setTextColor(Theme.getInstance().getSendMessageTextColor(topText.getContext()));
topText.setGravity((isRtl ? Gravity.RIGHT : Gravity.LEFT) | Gravity.TOP);
topViewRootView.addView(topText, LayoutCreator.createLinear(LayoutCreator.WRAP_CONTENT, LayoutCreator.WRAP_CONTENT, Gravity.CENTER, !isRtl && roomId != 0 && userId != AccountManager.getInstance().getCurrentUser().getId() ? 4 : 0, 0, isRtl && roomId != 0 && userId != AccountManager.getInstance().getCurrentUser().getId() ? 4 : 0, 0));
verifyIconTv = new FontIconTextView(getContext());
verifyIconTv.setTextColor(getContext().getResources().getColor(R.color.verify_color));
verifyIconTv.setText(R.string.icon_blue_badge);
setTextSize(verifyIconTv, R.dimen.standardTextSize);
verifyIconTv.setVisibility(GONE);
topViewRootView.addView(verifyIconTv, LayoutCreator.createLinear(LayoutCreator.WRAP_CONTENT, LayoutCreator.WRAP_CONTENT, Gravity.CENTER, !isRtl && roomId != 0 && userId != AccountManager.getInstance().getCurrentUser().getId() ? 4 : 0, 0, isRtl && roomId != 0 && userId != AccountManager.getInstance().getCurrentUser().getId() ? 4 : 0, 0));
middleText = new TextView(context);
middleText.setSingleLine();
middleText.setTypeface(ResourcesCompat.getFont(getContext(), R.font.main_font_bold));
ViewMaker.setTextSize(middleText, R.dimen.dp15);
middleText.setSingleLine(true);
middleText.setEllipsize(TextUtils.TruncateAt.END);
middleText.setTextColor(Theme.getInstance().getPrimaryTextColor(context));
middleText.setGravity((isRtl ? Gravity.RIGHT : Gravity.LEFT) | Gravity.CENTER_VERTICAL);
middleText.setVisibility(GONE);
addView(middleText, LayoutCreator.createFrame(LayoutCreator.WRAP_CONTENT, LayoutCreator.WRAP_CONTENT, (isRtl ? Gravity.RIGHT : Gravity.LEFT) | Gravity.CENTER_VERTICAL, isRtl ? padding : ((padding * 2) + 56), 0, isRtl ? ((padding * 2) + 56) : padding, 0));
bottomText = new TextView(context);
bottomText.setSingleLine();
ViewMaker.setTypeFace(bottomText);
ViewMaker.setTextSize(bottomText, R.dimen.dp13);
bottomText.setGravity((isRtl ? Gravity.RIGHT : Gravity.LEFT) | Gravity.TOP);
bottomText.setTextColor(Color.GRAY);
addView(bottomText, LayoutCreator.createFrame(LayoutCreator.WRAP_CONTENT, LayoutCreator.WRAP_CONTENT, (isRtl ? Gravity.RIGHT : Gravity.LEFT) | Gravity.TOP, isRtl ? padding : ((padding * 2) + 56), 34.5f, isRtl ? ((padding * 2) + 56) : padding, 0));
icon = new IconView(getContext());
icon.setTypeface(ResourcesCompat.getFont(context, R.font.font_icons));
icon.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 20);
addView(icon, LayoutCreator.createFrame(LayoutCreator.WRAP_CONTENT, LayoutCreator.WRAP_CONTENT, (isRtl ? Gravity.LEFT : Gravity.RIGHT) | Gravity.CENTER_VERTICAL, padding, 0, padding, 0));
icon2 = new IconView(getContext());
icon2.setTypeface(ResourcesCompat.getFont(context, R.font.font_icons));
icon2.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 20);
addView(icon2, LayoutCreator.createFrame(LayoutCreator.WRAP_CONTENT, LayoutCreator.WRAP_CONTENT, (isRtl ? Gravity.LEFT : Gravity.RIGHT) | Gravity.CENTER_VERTICAL, isRtl ? (padding + 30) : padding, 0, isRtl ? padding : (30 + padding), 0));
LinearLayout iconsRootView = new LinearLayout(getContext());
iconsRootView.setOrientation(LinearLayout.HORIZONTAL);
iconsRootView.setGravity(Gravity.CENTER);
addView(iconsRootView, LayoutCreator.createFrame(LayoutCreator.WRAP_CONTENT, LayoutCreator.WRAP_CONTENT, (isRtl ? Gravity.LEFT : Gravity.RIGHT) | Gravity.CENTER_VERTICAL, isRtl ? 0 : 8, 8, isRtl ? 8 : 0, 8));
uploadIcon = new MaterialDesignTextView(getContext());
uploadIcon.setTypeface(ResourcesCompat.getFont(context, R.font.font_icons));
uploadIcon.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 23);
uploadIcon.setText(R.string.icon_upload);
uploadIcon.setVisibility(GONE);
uploadIcon.setTextColor(Theme.getInstance().getSendMessageTextColor(uploadIcon.getContext()));
uploadIcon.setGravity(Gravity.CENTER);
uploadIcon.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if ((circleImageLoading.getStatus() == ImageLoadingView.Status.FAILED && isFromMyStatus && !isRoom) || (circleImageLoading.getStatus() == ImageLoadingView.Status.FAILED && isFromMyStatus && isRoom && mode == 1)) {
deleteIcon.setVisibility(GONE);
uploadIcon.setVisibility(GONE);
middleText.setTextColor(Theme.getInstance().getTitleTextColor(context));
middleText.setText(context.getString(R.string.story_sending));
circleImageLoading.setStatus(ImageLoadingView.Status.LOADING);
StoryObject realmStoryProto;
if (fileToken != null) {
realmStoryProto = MessageDataStorage.getInstance(AccountManager.selectedAccount).getStoryWithFileToken(fileToken);
} else {
realmStoryProto = MessageDataStorage.getInstance(AccountManager.selectedAccount).getStoryWithUploadId(uploadId);
}
if (realmStoryProto != null && realmStoryProto.fileToken != null) {
MessageDataStorage.getInstance(AccountManager.selectedAccount).updateStoryStatus(realmStoryProto.id, MessageObject.STATUS_SENDING);
List<ProtoStoryUserAddNew.StoryAddRequest> storyAddRequests = new ArrayList<>();
ProtoStoryUserAddNew.StoryAddRequest.Builder storyAddRequest = ProtoStoryUserAddNew.StoryAddRequest.newBuilder();
storyAddRequest.setToken(realmStoryProto.fileToken);
storyAddRequest.setCaption(realmStoryProto.caption);
storyAddRequests.add(storyAddRequest.build());
if (isRoom) {
MessageController.getInstance(AccountManager.selectedAccount).addMyRoomStory(storyAddRequests, roomId);
} else {
MessageController.getInstance(AccountManager.selectedAccount).addMyStory(storyAddRequests);
}
} else if (realmStoryProto != null && !Uploader.getInstance().isCompressingOrUploading(String.valueOf(realmStoryProto.id))) {
MessageDataStorage.getInstance(AccountManager.selectedAccount).updateStoryStatus(realmStoryProto.id, MessageObject.STATUS_SENDING);
HttpUploader.isStoryUploading = true;
Uploader.getInstance().upload(UploadObject.createForStory(realmStoryProto.id, realmStoryProto.attachmentObject.filePath, null, realmStoryProto.caption, ProtoGlobal.RoomMessageType.STORY));
}
EventManager.getInstance(AccountManager.selectedAccount).postEvent(EventManager.STORY_SENDING);
} else {
deleteStory.deleteStory(StoryCell.this, storyId, roomId, isRoom);
}
}
});
deleteIcon = new MaterialDesignTextView(getContext());
deleteIcon.setTypeface(ResourcesCompat.getFont(context, R.font.font_icons));
deleteIcon.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 23);
deleteIcon.setText(R.string.icon_other_horizontal_dots);
deleteIcon.setVisibility(GONE);
deleteIcon.setTextColor(Theme.getInstance().getSendMessageTextColor(deleteIcon.getContext()));
deleteIcon.setGravity(Gravity.CENTER);
deleteIcon.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
deleteStory.deleteStory(StoryCell.this, storyId, roomId, isRoom);
}
});
iconsRootView.addView(uploadIcon, LayoutCreator.createLinear(72, 72, Gravity.CENTER_VERTICAL));
iconsRootView.addView(deleteIcon, LayoutCreator.createLinear(72, 72, Gravity.CENTER_VERTICAL));
if (status == CircleStatus.LOADING_CIRCLE_IMAGE) {
setOnClickListener(v -> {
deleteStory.onStoryClick(this);
});
circleImageLoading.setOnClickListener(v -> {
deleteStory.onStoryClick(this);
});
}
}
use of net.iGap.story.StoryObject in project iGap-Android by KianIranian-STDG.
the class StoryCell method setData.
public void setData(StoryObject storyObject, boolean isRoom, String displayName, String color, Context context, boolean needDivider, CircleStatus status, ImageLoadingView.Status imageLoadingStatus, IconClicked iconClicked) {
initView(context, needDivider, status, imageLoadingStatus, iconClicked, storyObject.createdAt);
this.userId = storyObject.userId;
this.roomId = storyObject.roomId;
this.isFromMyStatus = true;
String name = HelperImageBackColor.getFirstAlphabetName(storyObject.displayName != null ? storyObject.displayName : "");
if (circleImageLoading.getStatus() == ImageLoadingView.Status.FAILED) {
if (isRoom && mode == 0) {
deleteIcon.setTextColor(Color.RED);
topText.setText(storyObject.displayName);
bottomText.setText(context.getString(R.string.story_could_not_sent));
bottomText.setTextColor(Color.RED);
} else {
uploadIcon.setVisibility(VISIBLE);
deleteIcon.setVisibility(VISIBLE);
deleteIcon.setText(R.string.icon_delete);
topText.setVisibility(GONE);
bottomText.setVisibility(GONE);
middleText.setVisibility(VISIBLE);
middleText.setText(context.getString(R.string.story_could_not_sent));
middleText.setTextColor(Color.RED);
}
} else if (circleImageLoading.getStatus() == ImageLoadingView.Status.LOADING) {
if (isRoom && mode == 0) {
topText.setText(storyObject.displayName);
bottomText.setText(context.getString(R.string.story_sending));
} else {
uploadIcon.setVisibility(GONE);
deleteIcon.setVisibility(GONE);
topText.setVisibility(GONE);
middleText.setVisibility(VISIBLE);
middleText.setText(context.getString(R.string.story_sending));
middleText.setTextColor(Theme.getInstance().getTitleTextColor(context));
}
} else {
topText.setVisibility(VISIBLE);
bottomText.setVisibility(VISIBLE);
middleText.setVisibility(GONE);
uploadIcon.setVisibility(GONE);
deleteIcon.setVisibility(VISIBLE);
if (isRoom && mode == 0) {
topText.setText(storyObject.displayName);
} else {
if (G.selectedLanguage.equals("fa")) {
topText.setText(HelperCalander.convertToUnicodeFarsiNumber(String.valueOf(storyObject.viewCount)) + " " + context.getString(R.string.story_views));
} else {
topText.setText(storyObject.viewCount + " " + context.getString(R.string.story_views));
}
}
bottomText.setText(LastSeenTimeUtil.computeTime(context, storyObject.userId, storyObject.createdAt / 1000L, false, false));
}
AttachmentObject attachment = storyObject.attachmentObject;
if (attachment != null && (attachment.thumbnailPath != null || attachment.filePath != null)) {
try {
Glide.with(G.context).load(attachment.filePath != null ? attachment.filePath : attachment.thumbnailPath).placeholder(new BitmapDrawable(context.getResources(), HelperImageBackColor.drawAlphabetOnPicture(LayoutCreator.dp(64), name, color))).into(circleImageLoading);
} catch (Exception e) {
Glide.with(G.context).load(HelperImageBackColor.drawAlphabetOnPicture(LayoutCreator.dp(64), name, color)).into(circleImageLoading);
}
} else if (attachment != null) {
Glide.with(G.context).load(new BitmapDrawable(context.getResources(), HelperImageBackColor.drawAlphabetOnPicture(LayoutCreator.dp(64), name, color))).into(circleImageLoading);
DownloadObject object = DownloadObject.createForStory(attachment, storyObject.storyId, true);
Log.e("skfjskjfsd", "setData2: " + storyId + "/" + object.downloadId);
if (object != null) {
Downloader.getInstance(AccountManager.selectedAccount).download(object, arg -> {
if (arg.status == Status.SUCCESS && arg.data != null) {
String filepath = arg.data.getFilePath();
String downloadedFileToken = arg.data.getToken();
if (!(new File(filepath).exists())) {
HelperLog.getInstance().setErrorLog(new Exception("File Dont Exist After Download !!" + filepath));
}
if (arg.data.getDownloadObject().downloadId == storyId) {
DbManager.getInstance().doRealmTransaction(realm1 -> {
RealmStoryProto realmStoryProto = realm1.where(RealmStoryProto.class).equalTo("isForReply", false).equalTo("storyId", storyId).findFirst();
if (realmStoryProto != null) {
realmStoryProto.getFile().setLocalFilePath(filepath);
}
});
G.runOnUiThread(() -> Glide.with(G.context).load(filepath).placeholder(new BitmapDrawable(context.getResources(), HelperImageBackColor.drawAlphabetOnPicture(LayoutCreator.dp(64), name, color))).into(circleImageLoading));
}
}
});
}
} else {
Glide.with(G.context).load(new BitmapDrawable(context.getResources(), HelperImageBackColor.drawAlphabetOnPicture(LayoutCreator.dp(64), name, color))).into(circleImageLoading);
}
}
Aggregations