use of org.telegram.ui.ChatActivity in project Telegram-FOSS by Telegram-FOSS-Team.
the class MediaController method cleanupPlayer.
public void cleanupPlayer(boolean notify, boolean stopService, boolean byVoiceEnd, boolean transferPlayerToPhotoViewer) {
if (audioPlayer != null) {
if (audioVolumeAnimator != null) {
audioVolumeAnimator.removeAllUpdateListeners();
audioVolumeAnimator.cancel();
}
if (audioPlayer.isPlaying() && playingMessageObject != null && !playingMessageObject.isVoice()) {
VideoPlayer playerFinal = audioPlayer;
ValueAnimator valueAnimator = ValueAnimator.ofFloat(audioVolume, 0);
valueAnimator.addUpdateListener(valueAnimator1 -> {
float volume;
if (audioFocus != AUDIO_NO_FOCUS_CAN_DUCK) {
volume = VOLUME_NORMAL;
} else {
volume = VOLUME_DUCK;
}
playerFinal.setVolume(volume * (float) valueAnimator1.getAnimatedValue());
});
valueAnimator.addListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator animation) {
try {
playerFinal.releasePlayer(true);
} catch (Exception e) {
FileLog.e(e);
}
}
});
valueAnimator.setDuration(300);
valueAnimator.start();
} else {
try {
audioPlayer.releasePlayer(true);
} catch (Exception e) {
FileLog.e(e);
}
}
audioPlayer = null;
Theme.unrefAudioVisualizeDrawable(playingMessageObject);
} else if (videoPlayer != null) {
currentAspectRatioFrameLayout = null;
currentTextureViewContainer = null;
currentAspectRatioFrameLayoutReady = false;
isDrawingWasReady = false;
currentTextureView = null;
goingToShowMessageObject = null;
if (transferPlayerToPhotoViewer) {
PhotoViewer.getInstance().injectVideoPlayer(videoPlayer);
goingToShowMessageObject = playingMessageObject;
NotificationCenter.getInstance(playingMessageObject.currentAccount).postNotificationName(NotificationCenter.messagePlayingGoingToStop, playingMessageObject, true);
} else {
long position = videoPlayer.getCurrentPosition();
if (playingMessageObject != null && playingMessageObject.isVideo() && position > 0) {
playingMessageObject.audioProgressMs = (int) position;
NotificationCenter.getInstance(playingMessageObject.currentAccount).postNotificationName(NotificationCenter.messagePlayingGoingToStop, playingMessageObject, false);
}
videoPlayer.releasePlayer(true);
videoPlayer = null;
}
try {
baseActivity.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
} catch (Exception e) {
FileLog.e(e);
}
if (playingMessageObject != null && !transferPlayerToPhotoViewer) {
AndroidUtilities.cancelRunOnUIThread(setLoadingRunnable);
FileLoader.getInstance(playingMessageObject.currentAccount).removeLoadingVideo(playingMessageObject.getDocument(), true, false);
}
}
stopProgressTimer();
lastProgress = 0;
isPaused = false;
if (!useFrontSpeaker && !SharedConfig.raiseToSpeak) {
ChatActivity chat = raiseChat;
stopRaiseToEarSensors(raiseChat, false);
raiseChat = chat;
}
if (proximityWakeLock != null && proximityWakeLock.isHeld() && !proximityTouched) {
proximityWakeLock.release();
}
if (playingMessageObject != null) {
if (downloadingCurrentMessage) {
FileLoader.getInstance(playingMessageObject.currentAccount).cancelLoadFile(playingMessageObject.getDocument());
}
MessageObject lastFile = playingMessageObject;
if (notify) {
playingMessageObject.resetPlayingProgress();
NotificationCenter.getInstance(lastFile.currentAccount).postNotificationName(NotificationCenter.messagePlayingProgressDidChanged, playingMessageObject.getId(), 0);
}
playingMessageObject = null;
downloadingCurrentMessage = false;
if (notify) {
NotificationsController.audioManager.abandonAudioFocus(this);
hasAudioFocus = 0;
int index = -1;
if (voiceMessagesPlaylist != null) {
if (byVoiceEnd && (index = voiceMessagesPlaylist.indexOf(lastFile)) >= 0) {
voiceMessagesPlaylist.remove(index);
voiceMessagesPlaylistMap.remove(lastFile.getId());
if (voiceMessagesPlaylist.isEmpty()) {
voiceMessagesPlaylist = null;
voiceMessagesPlaylistMap = null;
}
} else {
voiceMessagesPlaylist = null;
voiceMessagesPlaylistMap = null;
}
}
boolean next = false;
if (voiceMessagesPlaylist != null && index < voiceMessagesPlaylist.size()) {
MessageObject nextVoiceMessage = voiceMessagesPlaylist.get(index);
playMessage(nextVoiceMessage);
if (!nextVoiceMessage.isRoundVideo() && pipRoundVideoView != null) {
pipRoundVideoView.close(true);
pipRoundVideoView = null;
}
} else {
if ((lastFile.isVoice() || lastFile.isRoundVideo()) && lastFile.getId() != 0) {
startRecordingIfFromSpeaker();
}
NotificationCenter.getInstance(lastFile.currentAccount).postNotificationName(NotificationCenter.messagePlayingDidReset, lastFile.getId(), stopService);
pipSwitchingState = 0;
if (pipRoundVideoView != null) {
pipRoundVideoView.close(true);
pipRoundVideoView = null;
}
}
}
if (stopService) {
Intent intent = new Intent(ApplicationLoader.applicationContext, MusicPlayerService.class);
ApplicationLoader.applicationContext.stopService(intent);
}
}
}
use of org.telegram.ui.ChatActivity in project Telegram-FOSS by Telegram-FOSS-Team.
the class FragmentContextView method checkPlayer.
private void checkPlayer(boolean create) {
if (visible && (currentStyle == 1 || currentStyle == 3 || (currentStyle == 4 || currentStyle == 5) && !isPlayingVoice())) {
return;
}
MessageObject messageObject = MediaController.getInstance().getPlayingMessageObject();
View fragmentView = fragment.getFragmentView();
if (!create && fragmentView != null) {
if (fragmentView.getParent() == null || ((View) fragmentView.getParent()).getVisibility() != VISIBLE) {
create = true;
}
}
boolean wasVisible = visible;
if (messageObject == null || messageObject.getId() == 0 || messageObject.isVideo()) {
lastMessageObject = null;
boolean callAvailable = supportsCalls && VoIPService.getSharedInstance() != null && !VoIPService.getSharedInstance().isHangingUp() && VoIPService.getSharedInstance().getCallState() != VoIPService.STATE_WAITING_INCOMING && !GroupCallPip.isShowing();
if (!isPlayingVoice() && !callAvailable && fragment instanceof ChatActivity && !GroupCallPip.isShowing()) {
ChatObject.Call call = ((ChatActivity) fragment).getGroupCall();
callAvailable = call != null && call.shouldShowPanel();
}
if (callAvailable) {
checkCall(false);
return;
}
if (visible) {
if (playbackSpeedButton != null && playbackSpeedButton.isSubMenuShowing()) {
playbackSpeedButton.toggleSubMenu();
}
visible = false;
if (create) {
if (getVisibility() != GONE) {
setVisibility(GONE);
}
setTopPadding(0);
} else {
if (animatorSet != null) {
animatorSet.cancel();
animatorSet = null;
}
animationIndex = NotificationCenter.getInstance(account).setAnimationInProgress(animationIndex, null);
animatorSet = new AnimatorSet();
animatorSet.playTogether(ObjectAnimator.ofFloat(this, "topPadding", 0));
animatorSet.setDuration(200);
if (delegate != null) {
delegate.onAnimation(true, false);
}
animatorSet.addListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator animation) {
NotificationCenter.getInstance(account).onAnimationFinish(animationIndex);
if (animatorSet != null && animatorSet.equals(animation)) {
setVisibility(GONE);
if (delegate != null) {
delegate.onAnimation(false, false);
}
animatorSet = null;
if (checkCallAfterAnimation) {
checkCall(false);
} else if (checkPlayerAfterAnimation) {
checkPlayer(false);
} else if (checkImportAfterAnimation) {
checkImport(false);
}
checkCallAfterAnimation = false;
checkPlayerAfterAnimation = false;
checkImportAfterAnimation = false;
}
}
});
animatorSet.start();
}
} else {
setVisibility(View.GONE);
}
} else {
if (currentStyle != 0 && animatorSet != null && !create) {
checkPlayerAfterAnimation = true;
return;
}
int prevStyle = currentStyle;
updateStyle(0);
if (create && topPadding == 0) {
updatePaddings();
setTopPadding(AndroidUtilities.dp2(getStyleHeight()));
if (delegate != null) {
delegate.onAnimation(true, true);
delegate.onAnimation(false, true);
}
}
if (!visible) {
if (!create) {
if (animatorSet != null) {
animatorSet.cancel();
animatorSet = null;
}
animationIndex = NotificationCenter.getInstance(account).setAnimationInProgress(animationIndex, null);
animatorSet = new AnimatorSet();
if (additionalContextView != null && additionalContextView.getVisibility() == VISIBLE) {
((LayoutParams) getLayoutParams()).topMargin = -AndroidUtilities.dp(getStyleHeight() + additionalContextView.getStyleHeight());
} else {
((LayoutParams) getLayoutParams()).topMargin = -AndroidUtilities.dp(getStyleHeight());
}
if (delegate != null) {
delegate.onAnimation(true, true);
}
animatorSet.playTogether(ObjectAnimator.ofFloat(this, "topPadding", AndroidUtilities.dp2(getStyleHeight())));
animatorSet.setDuration(200);
animatorSet.addListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator animation) {
NotificationCenter.getInstance(account).onAnimationFinish(animationIndex);
if (animatorSet != null && animatorSet.equals(animation)) {
if (delegate != null) {
delegate.onAnimation(false, true);
}
animatorSet = null;
if (checkCallAfterAnimation) {
checkCall(false);
} else if (checkPlayerAfterAnimation) {
checkPlayer(false);
} else if (checkImportAfterAnimation) {
checkImport(false);
}
checkCallAfterAnimation = false;
checkPlayerAfterAnimation = false;
checkImportAfterAnimation = false;
}
}
});
animatorSet.start();
}
visible = true;
setVisibility(VISIBLE);
}
if (MediaController.getInstance().isMessagePaused()) {
playPauseDrawable.setPause(false, !create);
playButton.setContentDescription(LocaleController.getString("AccActionPlay", R.string.AccActionPlay));
} else {
playPauseDrawable.setPause(true, !create);
playButton.setContentDescription(LocaleController.getString("AccActionPause", R.string.AccActionPause));
}
if (lastMessageObject != messageObject || prevStyle != 0) {
lastMessageObject = messageObject;
SpannableStringBuilder stringBuilder;
if (lastMessageObject.isVoice() || lastMessageObject.isRoundVideo()) {
isMusic = false;
if (playbackSpeedButton != null) {
playbackSpeedButton.setAlpha(1.0f);
playbackSpeedButton.setEnabled(true);
}
titleTextView.setPadding(0, 0, AndroidUtilities.dp(44), 0);
stringBuilder = new SpannableStringBuilder(String.format("%s %s", messageObject.getMusicAuthor(), messageObject.getMusicTitle()));
for (int i = 0; i < 2; i++) {
TextView textView = i == 0 ? titleTextView.getTextView() : titleTextView.getNextTextView();
if (textView == null) {
continue;
}
textView.setEllipsize(TextUtils.TruncateAt.MIDDLE);
}
updatePlaybackButton();
} else {
isMusic = true;
if (playbackSpeedButton != null) {
if (messageObject.getDuration() >= 10 * 60) {
playbackSpeedButton.setAlpha(1.0f);
playbackSpeedButton.setEnabled(true);
titleTextView.setPadding(0, 0, AndroidUtilities.dp(44), 0);
updatePlaybackButton();
} else {
playbackSpeedButton.setAlpha(0.0f);
playbackSpeedButton.setEnabled(false);
titleTextView.setPadding(0, 0, 0, 0);
}
} else {
titleTextView.setPadding(0, 0, 0, 0);
}
stringBuilder = new SpannableStringBuilder(String.format("%s - %s", messageObject.getMusicAuthor(), messageObject.getMusicTitle()));
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, 0, messageObject.getMusicAuthor().length(), Spanned.SPAN_INCLUSIVE_INCLUSIVE);
titleTextView.setText(stringBuilder, !create && wasVisible && isMusic);
}
}
}
use of org.telegram.ui.ChatActivity in project Telegram-FOSS by Telegram-FOSS-Team.
the class MessagesController method openChatOrProfileWith.
public static void openChatOrProfileWith(TLRPC.User user, TLRPC.Chat chat, BaseFragment fragment, int type, boolean closeLast) {
if (user == null && chat == null || fragment == null) {
return;
}
String reason;
if (chat != null) {
reason = getRestrictionReason(chat.restriction_reason);
} else {
reason = getRestrictionReason(user.restriction_reason);
if (type != 3 && user.bot) {
type = 1;
closeLast = true;
}
}
if (reason != null) {
showCantOpenAlert(fragment, reason);
} else {
Bundle args = new Bundle();
if (chat != null) {
args.putLong("chat_id", chat.id);
} else {
args.putLong("user_id", user.id);
}
if (type == 0) {
fragment.presentFragment(new ProfileActivity(args));
} else if (type == 2) {
fragment.presentFragment(new ChatActivity(args), true, true);
} else {
fragment.presentFragment(new ChatActivity(args), closeLast);
}
}
}
use of org.telegram.ui.ChatActivity 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.ChatActivity 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;
}
Aggregations