org.telegram.ui.ChatActivity Java Examples

The following examples show how to use org.telegram.ui.ChatActivity. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ChatAttachAlert.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
private MediaController.PhotoEntry getPhotoEntryAtPosition(int position) {
    if (position < 0) {
        return null;
    }
    int cameraCount = cameraPhotos.size();
    if (position < cameraCount) {
        return (MediaController.PhotoEntry) cameraPhotos.get(position);
    }
    position -= cameraCount;
    MediaController.AlbumEntry albumEntry;
    if (baseFragment instanceof ChatActivity) {
        albumEntry = MediaController.allMediaAlbumEntry;
    } else {
        albumEntry = MediaController.allPhotosAlbumEntry;
    }
    if (position < albumEntry.photos.size()) {
        return albumEntry.photos.get(position);
    }
    return null;
}
 
Example #2
Source File: FragmentContextView.java    From Telegram with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void didReceivedNotification(int id, int account, Object... args) {
    if (id == NotificationCenter.liveLocationsChanged) {
        checkLiveLocation(false);
    } else if (id == NotificationCenter.liveLocationsCacheChanged) {
        if (fragment instanceof ChatActivity) {
            long did = (Long) args[0];
            if (((ChatActivity) fragment).getDialogId() == did) {
                checkLocationString();
            }
        }
    } else if (id == NotificationCenter.messagePlayingDidStart || id == NotificationCenter.messagePlayingPlayStateChanged || id == NotificationCenter.messagePlayingDidReset || id == NotificationCenter.didEndCall) {
        checkPlayer(false);
    } else if (id == NotificationCenter.didStartedCall) {
        checkCall(false);
    } else if (id == NotificationCenter.messagePlayingSpeedChanged) {
        updatePlaybackButton();
    }
}
 
Example #3
Source File: FragmentContextView.java    From Telegram with GNU General Public License v2.0 6 votes vote down vote up
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().getCallState() != VoIPService.STATE_WAITING_INCOMING) {
            show = true;
        } else {
            MessageObject messageObject = MediaController.getInstance().getPlayingMessageObject();
            if (messageObject != null && messageObject.getId() != 0) {
                show = true;
            }
        }
    }
    setVisibility(show ? VISIBLE : GONE);
}
 
Example #4
Source File: ChatAttachAlert.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
    if (!needCamera || !deviceHasGoodCamera || position != 0) {
        if (needCamera && deviceHasGoodCamera) {
            position--;
        }
        PhotoAttachPhotoCell cell = (PhotoAttachPhotoCell) holder.itemView;
        MediaController.PhotoEntry photoEntry = getPhotoEntryAtPosition(position);
        cell.setPhotoEntry(photoEntry, needCamera, position == getItemCount() - 1);
        if (baseFragment instanceof ChatActivity && maxSelectedPhotos < 0) {
            cell.setChecked(selectedPhotosOrder.indexOf(photoEntry.imageId), selectedPhotos.containsKey(photoEntry.imageId), false);
        } else {
            cell.setChecked(-1, selectedPhotos.containsKey(photoEntry.imageId), false);
        }
        cell.getImageView().setTag(position);
        cell.setTag(position);
        cell.setIsVertical(this == cameraAttachAdapter && cameraPhotoLayoutManager.getOrientation() == LinearLayoutManager.VERTICAL);
    } else if (needCamera && deviceHasGoodCamera && position == 0) {
        if (cameraView != null && cameraView.isInitied()) {
            holder.itemView.setVisibility(View.INVISIBLE);
        } else {
            holder.itemView.setVisibility(View.VISIBLE);
        }
    }
}
 
Example #5
Source File: ChatAttachAlert.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
private void onRevealAnimationEnd(boolean open) {
    NotificationCenter.getInstance(currentAccount).setAnimationInProgress(false);
    revealAnimationInProgress = false;
    MediaController.AlbumEntry albumEntry;
    if (baseFragment instanceof ChatActivity) {
        albumEntry = MediaController.allMediaAlbumEntry;
    } else {
        albumEntry = MediaController.allPhotosAlbumEntry;
    }
    if (open && Build.VERSION.SDK_INT <= 19 && albumEntry == null) {
        MediaController.loadGalleryPhotosAlbums(0);
    }
    if (open) {
        checkCamera(true);
        showHint();
    }
}
 
Example #6
Source File: ChatAttachAlert.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
@Override
public int getItemCount() {
    int count = 0;
    if (needCamera && deviceHasGoodCamera) {
        count++;
    }
    count += cameraPhotos.size();
    MediaController.AlbumEntry albumEntry;
    if (baseFragment instanceof ChatActivity) {
        albumEntry = MediaController.allMediaAlbumEntry;
    } else {
        albumEntry = MediaController.allPhotosAlbumEntry;
    }
    if (albumEntry != null) {
        count += albumEntry.photos.size();
    }
    return count;
}
 
Example #7
Source File: ChatAttachAlert.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
public void init() {
    MediaController.AlbumEntry albumEntry;
    if (baseFragment instanceof ChatActivity) {
        albumEntry = MediaController.allMediaAlbumEntry;
    } else {
        albumEntry = MediaController.allPhotosAlbumEntry;
    }
    if (albumEntry != null) {
        for (int a = 0; a < Math.min(100, albumEntry.photos.size()); a++) {
            MediaController.PhotoEntry photoEntry = albumEntry.photos.get(a);
            photoEntry.reset();
        }
    }
    if (currentHintAnimation != null) {
        currentHintAnimation.cancel();
        currentHintAnimation = null;
    }
    hintTextView.setAlpha(0.0f);
    hintTextView.setVisibility(View.INVISIBLE);
    attachPhotoLayoutManager.scrollToPositionWithOffset(0, 1000000);
    cameraPhotoLayoutManager.scrollToPositionWithOffset(0, 1000000);
    clearSelectedPhotos();
    layoutManager.scrollToPositionWithOffset(0, 1000000);
    updatePhotosButton();
}
 
Example #8
Source File: ChatAttachAlert.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
private MediaController.PhotoEntry getPhotoEntryAtPosition(int position) {
    if (position < 0) {
        return null;
    }
    int cameraCount = cameraPhotos.size();
    if (position < cameraCount) {
        return (MediaController.PhotoEntry) cameraPhotos.get(position);
    }
    position -= cameraCount;
    MediaController.AlbumEntry albumEntry;
    if (baseFragment instanceof ChatActivity) {
        albumEntry = MediaController.allMediaAlbumEntry;
    } else {
        albumEntry = MediaController.allPhotosAlbumEntry;
    }
    if (position < albumEntry.photos.size()) {
        return albumEntry.photos.get(position);
    }
    return null;
}
 
Example #9
Source File: ChatAttachAlert.java    From Telegram with GNU General Public License v2.0 6 votes vote down vote up
private void sendPressed(boolean notify, int scheduleDate) {
    if (buttonPressed) {
        return;
    }
    if (baseFragment instanceof ChatActivity) {
        ChatActivity chatActivity = (ChatActivity) baseFragment;
        TLRPC.Chat chat = chatActivity.getCurrentChat();
        TLRPC.User user = chatActivity.getCurrentUser();
        if (user != null || ChatObject.isChannel(chat) && chat.megagroup || !ChatObject.isChannel(chat)) {
            MessagesController.getNotificationsSettings(currentAccount).edit().putBoolean("silent_" + chatActivity.getDialogId(), !notify).commit();
        }
    }
    applyCaption();
    buttonPressed = true;
    delegate.didPressedButton(7, true, notify, scheduleDate);
}
 
Example #10
Source File: ChatAttachAlert.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
public void init() {
    MediaController.AlbumEntry albumEntry;
    if (baseFragment instanceof ChatActivity) {
        albumEntry = MediaController.allMediaAlbumEntry;
    } else {
        albumEntry = MediaController.allPhotosAlbumEntry;
    }
    if (albumEntry != null) {
        for (int a = 0; a < Math.min(100, albumEntry.photos.size()); a++) {
            MediaController.PhotoEntry photoEntry = albumEntry.photos.get(a);
            photoEntry.reset();
        }
    }
    if (currentHintAnimation != null) {
        currentHintAnimation.cancel();
        currentHintAnimation = null;
    }
    hintTextView.setAlpha(0.0f);
    hintTextView.setVisibility(View.INVISIBLE);
    attachPhotoLayoutManager.scrollToPositionWithOffset(0, 1000000);
    cameraPhotoLayoutManager.scrollToPositionWithOffset(0, 1000000);
    clearSelectedPhotos();
    layoutManager.scrollToPositionWithOffset(0, 1000000);
    updatePhotosButton();
}
 
Example #11
Source File: ChatAttachAlert.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
private void onRevealAnimationEnd(boolean open) {
    NotificationCenter.getInstance(currentAccount).setAnimationInProgress(false);
    revealAnimationInProgress = false;
    MediaController.AlbumEntry albumEntry;
    if (baseFragment instanceof ChatActivity) {
        albumEntry = MediaController.allMediaAlbumEntry;
    } else {
        albumEntry = MediaController.allPhotosAlbumEntry;
    }
    if (open && Build.VERSION.SDK_INT <= 19 && albumEntry == null) {
        MediaController.loadGalleryPhotosAlbums(0);
    }
    if (open) {
        checkCamera(true);
        showHint();
    }
}
 
Example #12
Source File: ChatAttachAlert.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
    if (!needCamera || !deviceHasGoodCamera || position != 0) {
        if (needCamera && deviceHasGoodCamera) {
            position--;
        }
        PhotoAttachPhotoCell cell = (PhotoAttachPhotoCell) holder.itemView;
        MediaController.PhotoEntry photoEntry = getPhotoEntryAtPosition(position);
        cell.setPhotoEntry(photoEntry, needCamera, position == getItemCount() - 1);
        if (baseFragment instanceof ChatActivity && maxSelectedPhotos < 0) {
            cell.setChecked(selectedPhotosOrder.indexOf(photoEntry.imageId), selectedPhotos.containsKey(photoEntry.imageId), false);
        } else {
            cell.setChecked(-1, selectedPhotos.containsKey(photoEntry.imageId), false);
        }
        cell.getImageView().setTag(position);
        cell.setTag(position);
        cell.setIsVertical(this == cameraAttachAdapter && cameraPhotoLayoutManager.getOrientation() == LinearLayoutManager.VERTICAL);
    } else if (needCamera && deviceHasGoodCamera && position == 0) {
        if (cameraView != null && cameraView.isInitied()) {
            holder.itemView.setVisibility(View.INVISIBLE);
        } else {
            holder.itemView.setVisibility(View.VISIBLE);
        }
    }
}
 
Example #13
Source File: ChatAttachAlert.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
@Override
public int getItemCount() {
    int count = 0;
    if (needCamera && deviceHasGoodCamera) {
        count++;
    }
    count += cameraPhotos.size();
    MediaController.AlbumEntry albumEntry;
    if (baseFragment instanceof ChatActivity) {
        albumEntry = MediaController.allMediaAlbumEntry;
    } else {
        albumEntry = MediaController.allPhotosAlbumEntry;
    }
    if (albumEntry != null) {
        count += albumEntry.photos.size();
    }
    return count;
}
 
Example #14
Source File: FragmentContextView.java    From Telegram-FOSS with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void didReceivedNotification(int id, int account, Object... args) {
    if (id == NotificationCenter.liveLocationsChanged) {
        checkLiveLocation(false);
    } else if (id == NotificationCenter.liveLocationsCacheChanged) {
        if (fragment instanceof ChatActivity) {
            long did = (Long) args[0];
            if (((ChatActivity) fragment).getDialogId() == did) {
                checkLocationString();
            }
        }
    } else if (id == NotificationCenter.messagePlayingDidStart || id == NotificationCenter.messagePlayingPlayStateChanged || id == NotificationCenter.messagePlayingDidReset || id == NotificationCenter.didEndCall) {
        checkPlayer(false);
    } else if (id == NotificationCenter.didStartedCall) {
        checkCall(false);
    } else if (id == NotificationCenter.messagePlayingSpeedChanged) {
        updatePlaybackButton();
    }
}
 
Example #15
Source File: FragmentContextView.java    From Telegram-FOSS with GNU General Public License v2.0 6 votes vote down vote up
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().getCallState() != VoIPService.STATE_WAITING_INCOMING) {
            show = true;
        } else {
            MessageObject messageObject = MediaController.getInstance().getPlayingMessageObject();
            if (messageObject != null && messageObject.getId() != 0) {
                show = true;
            }
        }
    }
    setVisibility(show ? VISIBLE : GONE);
}
 
Example #16
Source File: ChatAttachAlert.java    From Telegram-FOSS with GNU General Public License v2.0 6 votes vote down vote up
private void sendPressed(boolean notify, int scheduleDate) {
    if (buttonPressed) {
        return;
    }
    if (baseFragment instanceof ChatActivity) {
        ChatActivity chatActivity = (ChatActivity) baseFragment;
        TLRPC.Chat chat = chatActivity.getCurrentChat();
        TLRPC.User user = chatActivity.getCurrentUser();
        if (user != null || ChatObject.isChannel(chat) && chat.megagroup || !ChatObject.isChannel(chat)) {
            MessagesController.getNotificationsSettings(currentAccount).edit().putBoolean("silent_" + chatActivity.getDialogId(), !notify).commit();
        }
    }
    applyCaption();
    buttonPressed = true;
    delegate.didPressedButton(7, true, notify, scheduleDate);
}
 
Example #17
Source File: ChatAttachAlert.java    From Telegram with GNU General Public License v2.0 5 votes vote down vote up
private void openContactsLayout() {
    if (contactsLayout == null) {
        layouts[2] = contactsLayout = new ChatAttachAlertContactsLayout(this, getContext());
        contactsLayout.setDelegate((user, notify, scheduleDate) -> ((ChatActivity) baseFragment).sendContact(user, notify, scheduleDate));
    }
    showLayout(contactsLayout);
}
 
Example #18
Source File: ChatAttachAlert.java    From Telegram with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void onOpenAnimationEnd() {
    MediaController.AlbumEntry albumEntry;
    if (baseFragment instanceof ChatActivity) {
        albumEntry = MediaController.allMediaAlbumEntry;
    } else {
        albumEntry = MediaController.allPhotosAlbumEntry;
    }
    if (Build.VERSION.SDK_INT <= 19 && albumEntry == null) {
        MediaController.loadGalleryPhotosAlbums(0);
    }
    currentAttachLayout.onOpenAnimationEnd();
    AndroidUtilities.makeAccessibilityAnnouncement(LocaleController.getString("AccDescrAttachButton", R.string.AccDescrAttachButton));
}
 
Example #19
Source File: ChatAttachAlert.java    From Telegram with GNU General Public License v2.0 5 votes vote down vote up
private void openAudioLayout() {
    if (audioLayout == null) {
        layouts[3] = audioLayout = new ChatAttachAlertAudioLayout(this, getContext());
        audioLayout.setDelegate((audios, caption, notify, scheduleDate) -> ((ChatActivity) baseFragment).sendAudio(audios, caption, notify, scheduleDate));
    }
    if (baseFragment instanceof ChatActivity) {
        ChatActivity chatActivity = (ChatActivity) baseFragment;
        TLRPC.Chat currentChat = chatActivity.getCurrentChat();
        audioLayout.setMaxSelectedFiles(currentChat != null && !ChatObject.hasAdminRights(currentChat) && currentChat.slowmode_enabled || editingMessageObject != null ? 1 : -1);
    }
    showLayout(audioLayout);
}
 
Example #20
Source File: ChatAttachAlert.java    From Telegram with GNU General Public License v2.0 5 votes vote down vote up
@Override
public int getItemCount() {
    int count = buttonsCount;
    if (editingMessageObject == null && baseFragment instanceof ChatActivity) {
        count += MediaDataController.getInstance(currentAccount).inlineBots.size();
    }
    return count;
}
 
Example #21
Source File: AlertsCreator.java    From Telegram-FOSS with GNU General Public License v2.0 5 votes vote down vote up
public static void showOpenUrlAlert(BaseFragment fragment, String url, boolean punycode, boolean tryTelegraph, boolean ask) {
    if (fragment == null || fragment.getParentActivity() == null) {
        return;
    }
    long inlineReturn = (fragment instanceof ChatActivity) ? ((ChatActivity) fragment).getInlineReturn() : 0;
    if (Browser.isInternalUrl(url, null) || !ask) {
        Browser.openUrl(fragment.getParentActivity(), url, inlineReturn == 0, tryTelegraph);
    } else {
        String urlFinal;
        if (punycode) {
            try {
                Uri uri = Uri.parse(url);
                String host = IDN.toASCII(uri.getHost(), IDN.ALLOW_UNASSIGNED);
                urlFinal = uri.getScheme() + "://" + host + uri.getPath();
            } catch (Exception e) {
                FileLog.e(e);
                urlFinal = url;
            }
        } else {
            urlFinal = url;
        }
        AlertDialog.Builder builder = new AlertDialog.Builder(fragment.getParentActivity());
        builder.setTitle(LocaleController.getString("OpenUrlTitle", R.string.OpenUrlTitle));
        String format = LocaleController.getString("OpenUrlAlert2", R.string.OpenUrlAlert2);
        int index = format.indexOf("%");
        SpannableStringBuilder stringBuilder = new SpannableStringBuilder(String.format(format, urlFinal));
        if (index >= 0) {
            stringBuilder.setSpan(new URLSpan(urlFinal), index, index + urlFinal.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        }
        builder.setMessage(stringBuilder);
        builder.setMessageTextViewClickable(false);
        builder.setPositiveButton(LocaleController.getString("Open", R.string.Open), (dialogInterface, i) -> Browser.openUrl(fragment.getParentActivity(), url, inlineReturn == 0, tryTelegraph));
        builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
        fragment.showDialog(builder.create());
    }
}
 
Example #22
Source File: StickersAlert.java    From Telegram-FOSS with GNU General Public License v2.0 5 votes vote down vote up
@Override
public long getDialogId() {
    if (parentFragment instanceof ChatActivity) {
        return ((ChatActivity) parentFragment).getDialogId();
    }
    return 0;
}
 
Example #23
Source File: PollVotesAlert.java    From Telegram-FOSS with GNU General Public License v2.0 5 votes vote down vote up
public static void showForPoll(ChatActivity parentFragment, MessageObject messageObject) {
    if (parentFragment == null || parentFragment.getParentActivity() == null) {
        return;
    }
    PollVotesAlert alert = new PollVotesAlert(parentFragment, messageObject);
    parentFragment.showDialog(alert);
}
 
Example #24
Source File: ChatAttachAlertPhotoLayout.java    From Telegram-FOSS with GNU General Public License v2.0 5 votes vote down vote up
public void loadGalleryPhotos() {
    MediaController.AlbumEntry albumEntry;
    if (parentAlert.baseFragment instanceof ChatActivity) {
        albumEntry = MediaController.allMediaAlbumEntry;
    } else {
        albumEntry = MediaController.allPhotosAlbumEntry;
    }
    if (albumEntry == null && Build.VERSION.SDK_INT >= 21) {
        MediaController.loadGalleryPhotosAlbums(0);
    }
}
 
Example #25
Source File: ChatAttachAlertPhotoLayout.java    From Telegram-FOSS with GNU General Public License v2.0 5 votes vote down vote up
private void updateAlbumsDropDown() {
    dropDownContainer.removeAllSubItems();
    if (mediaEnabled) {
        ArrayList<MediaController.AlbumEntry> albums;
        if (parentAlert.baseFragment instanceof ChatActivity) {
            albums = MediaController.allMediaAlbums;
        } else {
            albums = MediaController.allPhotoAlbums;
        }
        dropDownAlbums = new ArrayList<>(albums);
        Collections.sort(dropDownAlbums, (o1, o2) -> {
            if (o1.bucketId == 0 && o2.bucketId != 0) {
                return -1;
            } else if (o1.bucketId != 0 && o2.bucketId == 0) {
                return 1;
            }
            int index1 = albums.indexOf(o1);
            int index2 = albums.indexOf(o2);
            if (index1 > index2) {
                return 1;
            } else if (index1 < index2) {
                return -1;
            } else {
                return 0;
            }

        });
    } else {
        dropDownAlbums = new ArrayList<>();
    }
    if (dropDownAlbums.isEmpty()) {
        dropDown.setCompoundDrawablesWithIntrinsicBounds(null, null, null, null);
    } else {
        dropDown.setCompoundDrawablesWithIntrinsicBounds(null, null, dropDownDrawable, null);
        for (int a = 0, N = dropDownAlbums.size(); a < N; a++) {
            dropDownContainer.addSubItem(10 + a, dropDownAlbums.get(a).bucketName);
        }
    }
}
 
Example #26
Source File: ChatAttachAlert.java    From Telegram-FOSS with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void notifyDataSetChanged() {
    buttonsCount = 0;
    galleryButton = -1;
    documentButton = -1;
    musicButton = -1;
    pollButton = -1;
    contactButton = -1;
    locationButton = -1;
    if (!(baseFragment instanceof ChatActivity)) {
        galleryButton = buttonsCount++;
        documentButton = buttonsCount++;
    } else if (editingMessageObject != null) {
        galleryButton = buttonsCount++;
        documentButton = buttonsCount++;
        musicButton = buttonsCount++;
    } else {
        if (mediaEnabled) {
            galleryButton = buttonsCount++;
            documentButton = buttonsCount++;
        }
        locationButton = buttonsCount++;
        if (pollsEnabled) {
            pollButton = buttonsCount++;
        } else {
            contactButton = buttonsCount++;
        }
        if (mediaEnabled) {
            musicButton = buttonsCount++;
        }
        TLRPC.User user = baseFragment instanceof ChatActivity ? ((ChatActivity) baseFragment).getCurrentUser() : null;
        if (user != null && user.bot) {
            contactButton = buttonsCount++;
        }
    }
    super.notifyDataSetChanged();
}
 
Example #27
Source File: AlertsCreator.java    From Telegram with GNU General Public License v2.0 5 votes vote down vote up
public static void showOpenUrlAlert(BaseFragment fragment, String url, boolean punycode, boolean tryTelegraph, boolean ask) {
    if (fragment == null || fragment.getParentActivity() == null) {
        return;
    }
    long inlineReturn = (fragment instanceof ChatActivity) ? ((ChatActivity) fragment).getInlineReturn() : 0;
    if (Browser.isInternalUrl(url, null) || !ask) {
        Browser.openUrl(fragment.getParentActivity(), url, inlineReturn == 0, tryTelegraph);
    } else {
        String urlFinal;
        if (punycode) {
            try {
                Uri uri = Uri.parse(url);
                String host = IDN.toASCII(uri.getHost(), IDN.ALLOW_UNASSIGNED);
                urlFinal = uri.getScheme() + "://" + host + uri.getPath();
            } catch (Exception e) {
                FileLog.e(e);
                urlFinal = url;
            }
        } else {
            urlFinal = url;
        }
        AlertDialog.Builder builder = new AlertDialog.Builder(fragment.getParentActivity());
        builder.setTitle(LocaleController.getString("OpenUrlTitle", R.string.OpenUrlTitle));
        String format = LocaleController.getString("OpenUrlAlert2", R.string.OpenUrlAlert2);
        int index = format.indexOf("%");
        SpannableStringBuilder stringBuilder = new SpannableStringBuilder(String.format(format, urlFinal));
        if (index >= 0) {
            stringBuilder.setSpan(new URLSpan(urlFinal), index, index + urlFinal.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        }
        builder.setMessage(stringBuilder);
        builder.setMessageTextViewClickable(false);
        builder.setPositiveButton(LocaleController.getString("Open", R.string.Open), (dialogInterface, i) -> Browser.openUrl(fragment.getParentActivity(), url, inlineReturn == 0, tryTelegraph));
        builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
        fragment.showDialog(builder.create());
    }
}
 
Example #28
Source File: ChatAttachAlert.java    From Telegram-FOSS with GNU General Public License v2.0 5 votes vote down vote up
@Override
public int getItemCount() {
    int count = buttonsCount;
    if (editingMessageObject == null && baseFragment instanceof ChatActivity) {
        count += MediaDataController.getInstance(currentAccount).inlineBots.size();
    }
    return count;
}
 
Example #29
Source File: ChatAttachAlertPhotoLayout.java    From Telegram with GNU General Public License v2.0 5 votes vote down vote up
public void loadGalleryPhotos() {
    MediaController.AlbumEntry albumEntry;
    if (parentAlert.baseFragment instanceof ChatActivity) {
        albumEntry = MediaController.allMediaAlbumEntry;
    } else {
        albumEntry = MediaController.allPhotosAlbumEntry;
    }
    if (albumEntry == null && Build.VERSION.SDK_INT >= 21) {
        MediaController.loadGalleryPhotosAlbums(0);
    }
}
 
Example #30
Source File: ChatAttachAlert.java    From Telegram-FOSS with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void onOpenAnimationEnd() {
    MediaController.AlbumEntry albumEntry;
    if (baseFragment instanceof ChatActivity) {
        albumEntry = MediaController.allMediaAlbumEntry;
    } else {
        albumEntry = MediaController.allPhotosAlbumEntry;
    }
    if (Build.VERSION.SDK_INT <= 19 && albumEntry == null) {
        MediaController.loadGalleryPhotosAlbums(0);
    }
    currentAttachLayout.onOpenAnimationEnd();
    AndroidUtilities.makeAccessibilityAnnouncement(LocaleController.getString("AccDescrAttachButton", R.string.AccDescrAttachButton));
}