use of org.telegram.ui.DialogsActivity in project Telegram-FOSS by Telegram-FOSS-Team.
the class FragmentContextView method checkLiveLocation.
private void checkLiveLocation(boolean create) {
View fragmentView = fragment.getFragmentView();
if (!create && fragmentView != null) {
if (fragmentView.getParent() == null || ((View) fragmentView.getParent()).getVisibility() != VISIBLE) {
create = true;
}
}
boolean show;
if (fragment instanceof DialogsActivity) {
show = LocationController.getLocationsCount() != 0;
} else {
show = LocationController.getInstance(fragment.getCurrentAccount()).isSharingLocation(((ChatActivity) fragment).getDialogId());
}
if (!show) {
lastLocationSharingCount = -1;
AndroidUtilities.cancelRunOnUIThread(checkLocationRunnable);
if (visible) {
visible = false;
if (create) {
if (getVisibility() != GONE) {
setVisibility(GONE);
}
setTopPadding(0);
} else {
if (animatorSet != null) {
animatorSet.cancel();
animatorSet = null;
}
animatorSet = new AnimatorSet();
animatorSet.playTogether(ObjectAnimator.ofFloat(this, "topPadding", 0));
animatorSet.setDuration(200);
animatorSet.addListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator animation) {
if (animatorSet != null && animatorSet.equals(animation)) {
setVisibility(GONE);
animatorSet = null;
}
}
});
animatorSet.start();
}
}
} else {
updateStyle(2);
playButton.setImageDrawable(new ShareLocationDrawable(getContext(), 1));
if (create && topPadding == 0) {
setTopPadding(AndroidUtilities.dp2(getStyleHeight()));
}
if (!visible) {
if (!create) {
if (animatorSet != null) {
animatorSet.cancel();
animatorSet = null;
}
animatorSet = new AnimatorSet();
animatorSet.playTogether(ObjectAnimator.ofFloat(this, "topPadding", AndroidUtilities.dp2(getStyleHeight())));
animatorSet.setDuration(200);
animatorSet.addListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator animation) {
if (animatorSet != null && animatorSet.equals(animation)) {
animatorSet = null;
}
}
});
animatorSet.start();
}
visible = true;
setVisibility(VISIBLE);
}
if (fragment instanceof DialogsActivity) {
String liveLocation = LocaleController.getString("LiveLocationContext", R.string.LiveLocationContext);
String param;
String str;
ArrayList<LocationController.SharingLocationInfo> infos = new ArrayList<>();
for (int a = 0; a < UserConfig.MAX_ACCOUNT_COUNT; a++) {
infos.addAll(LocationController.getInstance(a).sharingLocationsUI);
}
if (infos.size() == 1) {
LocationController.SharingLocationInfo info = infos.get(0);
long dialogId = info.messageObject.getDialogId();
if (DialogObject.isUserDialog(dialogId)) {
TLRPC.User user = MessagesController.getInstance(info.messageObject.currentAccount).getUser(dialogId);
param = UserObject.getFirstName(user);
str = LocaleController.getString("AttachLiveLocationIsSharing", R.string.AttachLiveLocationIsSharing);
} else {
TLRPC.Chat chat = MessagesController.getInstance(info.messageObject.currentAccount).getChat(-dialogId);
if (chat != null) {
param = chat.title;
} else {
param = "";
}
str = LocaleController.getString("AttachLiveLocationIsSharingChat", R.string.AttachLiveLocationIsSharingChat);
}
} else {
param = LocaleController.formatPluralString("Chats", infos.size());
str = LocaleController.getString("AttachLiveLocationIsSharingChats", R.string.AttachLiveLocationIsSharingChats);
}
String fullString = String.format(str, liveLocation, param);
int start = fullString.indexOf(liveLocation);
SpannableStringBuilder stringBuilder = new SpannableStringBuilder(fullString);
for (int i = 0; i < 2; i++) {
TextView textView = i == 0 ? titleTextView.getTextView() : titleTextView.getNextTextView();
if (textView == null) {
continue;
}
textView.setEllipsize(TextUtils.TruncateAt.END);
}
TypefaceSpan span = new TypefaceSpan(AndroidUtilities.getTypeface("fonts/rmedium.ttf"), 0, getThemedColor(Theme.key_inappPlayerPerformer));
stringBuilder.setSpan(span, start, start + liveLocation.length(), Spanned.SPAN_INCLUSIVE_INCLUSIVE);
titleTextView.setText(stringBuilder, false);
} else {
checkLocationRunnable.run();
checkLocationString();
}
}
}
use of org.telegram.ui.DialogsActivity in project Telegram-FOSS by Telegram-FOSS-Team.
the class FragmentContextView method checkVisibility.
private void checkVisibility() {
boolean show = false;
if (isLocation) {
if (fragment instanceof DialogsActivity) {
show = LocationController.getLocationsCount() != 0;
} else {
show = LocationController.getInstance(fragment.getCurrentAccount()).isSharingLocation(((ChatActivity) fragment).getDialogId());
}
} else {
if (VoIPService.getSharedInstance() != null && !VoIPService.getSharedInstance().isHangingUp() && VoIPService.getSharedInstance().getCallState() != VoIPService.STATE_WAITING_INCOMING) {
show = true;
} else if (fragment instanceof ChatActivity && fragment.getSendMessagesHelper().getImportingHistory(((ChatActivity) fragment).getDialogId()) != null && !isPlayingVoice()) {
show = true;
} else if (fragment instanceof ChatActivity && ((ChatActivity) fragment).getGroupCall() != null && ((ChatActivity) fragment).getGroupCall().shouldShowPanel() && !GroupCallPip.isShowing() && !isPlayingVoice()) {
show = true;
} else {
MessageObject messageObject = MediaController.getInstance().getPlayingMessageObject();
if (messageObject != null && messageObject.getId() != 0) {
show = true;
}
}
}
setVisibility(show ? VISIBLE : GONE);
}
use of org.telegram.ui.DialogsActivity in project Telegram-FOSS by Telegram-FOSS-Team.
the class SearchViewPager method onActionBarItemClick.
public void onActionBarItemClick(int id) {
if (id == gotoItemId) {
if (selectedFiles.size() != 1) {
return;
}
MessageObject messageObject = selectedFiles.values().iterator().next();
goToMessage(messageObject);
} else if (id == forwardItemId) {
Bundle args = new Bundle();
args.putBoolean("onlySelect", true);
args.putInt("dialogsType", 3);
DialogsActivity fragment = new DialogsActivity(args);
fragment.setDelegate((fragment1, dids, message, param) -> {
ArrayList<MessageObject> fmessages = new ArrayList<>();
Iterator<FilteredSearchView.MessageHashId> idIterator = selectedFiles.keySet().iterator();
while (idIterator.hasNext()) {
FilteredSearchView.MessageHashId hashId = idIterator.next();
fmessages.add(selectedFiles.get(hashId));
}
selectedFiles.clear();
showActionMode(false);
if (dids.size() > 1 || dids.get(0) == AccountInstance.getInstance(currentAccount).getUserConfig().getClientUserId() || message != null) {
for (int a = 0; a < dids.size(); a++) {
long did = dids.get(a);
if (message != null) {
AccountInstance.getInstance(currentAccount).getSendMessagesHelper().sendMessage(message.toString(), did, null, null, null, true, null, null, null, true, 0, null);
}
AccountInstance.getInstance(currentAccount).getSendMessagesHelper().sendMessage(fmessages, did, false, false, true, 0);
}
fragment1.finishFragment();
} else {
long did = dids.get(0);
Bundle args1 = new Bundle();
args1.putBoolean("scrollToTopOnResume", true);
if (DialogObject.isEncryptedDialog(did)) {
args1.putInt("enc_id", DialogObject.getEncryptedChatId(did));
} else {
if (DialogObject.isUserDialog(did)) {
args1.putLong("user_id", did);
} else {
args1.putLong("chat_id", -did);
}
if (!AccountInstance.getInstance(currentAccount).getMessagesController().checkCanOpenChat(args1, fragment1)) {
return;
}
}
ChatActivity chatActivity = new ChatActivity(args1);
fragment1.presentFragment(chatActivity, true);
chatActivity.showFieldPanelForForward(true, fmessages);
}
});
parent.presentFragment(fragment);
}
}
use of org.telegram.ui.DialogsActivity in project Telegram-FOSS by Telegram-FOSS-Team.
the class ChatActivityEnterView method didPressedBotButton.
public boolean didPressedBotButton(final TLRPC.KeyboardButton button, final MessageObject replyMessageObject, final MessageObject messageObject) {
if (button == null || messageObject == null) {
return false;
}
if (button instanceof TLRPC.TL_keyboardButton) {
SendMessagesHelper.getInstance(currentAccount).sendMessage(button.text, dialog_id, replyMessageObject, getThreadMessage(), null, false, null, null, null, true, 0, null);
} else if (button instanceof TLRPC.TL_keyboardButtonUrl) {
AlertsCreator.showOpenUrlAlert(parentFragment, button.url, false, true, resourcesProvider);
} else if (button instanceof TLRPC.TL_keyboardButtonRequestPhone) {
parentFragment.shareMyContact(2, messageObject);
} else if (button instanceof TLRPC.TL_keyboardButtonRequestPoll) {
parentFragment.openPollCreate((button.flags & 1) != 0 ? button.quiz : null);
return false;
} else if (button instanceof TLRPC.TL_keyboardButtonRequestGeoLocation) {
AlertDialog.Builder builder = new AlertDialog.Builder(parentActivity);
builder.setTitle(LocaleController.getString("ShareYouLocationTitle", R.string.ShareYouLocationTitle));
builder.setMessage(LocaleController.getString("ShareYouLocationInfo", R.string.ShareYouLocationInfo));
builder.setPositiveButton(LocaleController.getString("OK", R.string.OK), (dialogInterface, i) -> {
if (Build.VERSION.SDK_INT >= 23 && parentActivity.checkSelfPermission(Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
parentActivity.requestPermissions(new String[] { Manifest.permission.ACCESS_COARSE_LOCATION, Manifest.permission.ACCESS_FINE_LOCATION }, 2);
pendingMessageObject = messageObject;
pendingLocationButton = button;
return;
}
SendMessagesHelper.getInstance(currentAccount).sendCurrentLocation(messageObject, button);
});
builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
parentFragment.showDialog(builder.create());
} else if (button instanceof TLRPC.TL_keyboardButtonCallback || button instanceof TLRPC.TL_keyboardButtonGame || button instanceof TLRPC.TL_keyboardButtonBuy || button instanceof TLRPC.TL_keyboardButtonUrlAuth) {
SendMessagesHelper.getInstance(currentAccount).sendCallback(true, messageObject, button, parentFragment);
} else if (button instanceof TLRPC.TL_keyboardButtonSwitchInline) {
if (parentFragment.processSwitchButton((TLRPC.TL_keyboardButtonSwitchInline) button)) {
return true;
}
if (button.same_peer) {
long uid = messageObject.messageOwner.from_id.user_id;
if (messageObject.messageOwner.via_bot_id != 0) {
uid = messageObject.messageOwner.via_bot_id;
}
TLRPC.User user = accountInstance.getMessagesController().getUser(uid);
if (user == null) {
return true;
}
setFieldText("@" + user.username + " " + button.query);
} else {
Bundle args = new Bundle();
args.putBoolean("onlySelect", true);
args.putInt("dialogsType", 1);
DialogsActivity fragment = new DialogsActivity(args);
fragment.setDelegate((fragment1, dids, message, param) -> {
long uid = messageObject.messageOwner.from_id.user_id;
if (messageObject.messageOwner.via_bot_id != 0) {
uid = messageObject.messageOwner.via_bot_id;
}
TLRPC.User user = accountInstance.getMessagesController().getUser(uid);
if (user == null) {
fragment1.finishFragment();
return;
}
long did = dids.get(0);
MediaDataController.getInstance(currentAccount).saveDraft(did, 0, "@" + user.username + " " + button.query, null, null, true);
if (did != dialog_id) {
if (!DialogObject.isEncryptedDialog(did)) {
Bundle args1 = new Bundle();
if (DialogObject.isUserDialog(did)) {
args1.putLong("user_id", did);
} else {
args1.putLong("chat_id", -did);
}
if (!accountInstance.getMessagesController().checkCanOpenChat(args1, fragment1)) {
return;
}
ChatActivity chatActivity = new ChatActivity(args1);
if (parentFragment.presentFragment(chatActivity, true)) {
if (!AndroidUtilities.isTablet()) {
parentFragment.removeSelfFromStack();
}
} else {
fragment1.finishFragment();
}
} else {
fragment1.finishFragment();
}
} else {
fragment1.finishFragment();
}
});
parentFragment.presentFragment(fragment);
}
} else if (button instanceof TLRPC.TL_keyboardButtonUserProfile) {
if (MessagesController.getInstance(currentAccount).getUser(button.user_id) != null) {
Bundle args = new Bundle();
args.putLong("user_id", button.user_id);
ProfileActivity fragment = new ProfileActivity(args);
parentFragment.presentFragment(fragment);
}
}
return true;
}
use of org.telegram.ui.DialogsActivity in project Telegram-FOSS by Telegram-FOSS-Team.
the class AudioPlayerAlert method onSubItemClick.
private void onSubItemClick(int id) {
final MessageObject messageObject = MediaController.getInstance().getPlayingMessageObject();
if (messageObject == null || parentActivity == null) {
return;
}
if (id == 1) {
if (UserConfig.selectedAccount != currentAccount) {
parentActivity.switchToAccount(currentAccount, true);
}
Bundle args = new Bundle();
args.putBoolean("onlySelect", true);
args.putInt("dialogsType", 3);
DialogsActivity fragment = new DialogsActivity(args);
final ArrayList<MessageObject> fmessages = new ArrayList<>();
fmessages.add(messageObject);
fragment.setDelegate((fragment1, dids, message, param) -> {
if (dids.size() > 1 || dids.get(0) == UserConfig.getInstance(currentAccount).getClientUserId() || message != null) {
for (int a = 0; a < dids.size(); a++) {
long did = dids.get(a);
if (message != null) {
SendMessagesHelper.getInstance(currentAccount).sendMessage(message.toString(), did, null, null, null, true, null, null, null, true, 0, null);
}
SendMessagesHelper.getInstance(currentAccount).sendMessage(fmessages, did, false, false, true, 0);
}
fragment1.finishFragment();
} else {
long did = dids.get(0);
Bundle args1 = new Bundle();
args1.putBoolean("scrollToTopOnResume", true);
if (DialogObject.isEncryptedDialog(did)) {
args1.putInt("enc_id", DialogObject.getEncryptedChatId(did));
} else if (DialogObject.isUserDialog(did)) {
args1.putLong("user_id", did);
} else {
args1.putLong("chat_id", -did);
}
NotificationCenter.getInstance(currentAccount).postNotificationName(NotificationCenter.closeChats);
ChatActivity chatActivity = new ChatActivity(args1);
if (parentActivity.presentFragment(chatActivity, true, false)) {
chatActivity.showFieldPanelForForward(true, fmessages);
} else {
fragment1.finishFragment();
}
}
});
parentActivity.presentFragment(fragment);
dismiss();
} else if (id == 2) {
try {
File f = null;
boolean isVideo = false;
if (!TextUtils.isEmpty(messageObject.messageOwner.attachPath)) {
f = new File(messageObject.messageOwner.attachPath);
if (!f.exists()) {
f = null;
}
}
if (f == null) {
f = FileLoader.getPathToMessage(messageObject.messageOwner);
}
if (f.exists()) {
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType(messageObject.getMimeType());
if (Build.VERSION.SDK_INT >= 24) {
try {
intent.putExtra(Intent.EXTRA_STREAM, FileProvider.getUriForFile(ApplicationLoader.applicationContext, BuildConfig.APPLICATION_ID + ".provider", f));
intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
} catch (Exception ignore) {
intent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(f));
}
} else {
intent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(f));
}
parentActivity.startActivityForResult(Intent.createChooser(intent, LocaleController.getString("ShareFile", R.string.ShareFile)), 500);
} else {
AlertDialog.Builder builder = new AlertDialog.Builder(parentActivity);
builder.setTitle(LocaleController.getString("AppName", R.string.AppName));
builder.setPositiveButton(LocaleController.getString("OK", R.string.OK), null);
builder.setMessage(LocaleController.getString("PleaseDownload", R.string.PleaseDownload));
builder.show();
}
} catch (Exception e) {
FileLog.e(e);
}
} else if (id == 4) {
if (UserConfig.selectedAccount != currentAccount) {
parentActivity.switchToAccount(currentAccount, true);
}
Bundle args = new Bundle();
long did = messageObject.getDialogId();
if (DialogObject.isEncryptedDialog(did)) {
args.putInt("enc_id", DialogObject.getEncryptedChatId(did));
} else if (DialogObject.isUserDialog(did)) {
args.putLong("user_id", did);
} else {
TLRPC.Chat chat = MessagesController.getInstance(currentAccount).getChat(-did);
if (chat != null && chat.migrated_to != null) {
args.putLong("migrated_to", did);
did = -chat.migrated_to.channel_id;
}
args.putLong("chat_id", -did);
}
args.putInt("message_id", messageObject.getId());
NotificationCenter.getInstance(currentAccount).postNotificationName(NotificationCenter.closeChats);
parentActivity.presentFragment(new ChatActivity(args), false, false);
dismiss();
} else if (id == 5) {
if (Build.VERSION.SDK_INT >= 23 && (Build.VERSION.SDK_INT <= 28 || BuildVars.NO_SCOPED_STORAGE) && parentActivity.checkSelfPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
parentActivity.requestPermissions(new String[] { Manifest.permission.WRITE_EXTERNAL_STORAGE }, 4);
return;
}
String fileName = FileLoader.getDocumentFileName(messageObject.getDocument());
if (TextUtils.isEmpty(fileName)) {
fileName = messageObject.getFileName();
}
String path = messageObject.messageOwner.attachPath;
if (path != null && path.length() > 0) {
File temp = new File(path);
if (!temp.exists()) {
path = null;
}
}
if (path == null || path.length() == 0) {
path = FileLoader.getPathToMessage(messageObject.messageOwner).toString();
}
MediaController.saveFile(path, parentActivity, 3, fileName, messageObject.getDocument() != null ? messageObject.getDocument().mime_type : "", () -> BulletinFactory.of((FrameLayout) containerView, resourcesProvider).createDownloadBulletin(BulletinFactory.FileType.AUDIO).show());
}
}
Aggregations