org.telegram.tgnet.ConnectionsManager Java Examples

The following examples show how to use org.telegram.tgnet.ConnectionsManager. 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: ProfileActivity.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
private void updateOnlineCount()
{
    onlineCount = 0;
    if (info instanceof TLRPC.TL_chatFull || info instanceof TLRPC.TL_channelFull && info.participants_count <= 200 && info.participants != null)
    {
        sortParticipants(chatOnlineParticipantsList);
        int currentTime = ConnectionsManager.getInstance(currentAccount).getCurrentTime();
        for (TLRPC.ChatParticipant participant : chatOnlineParticipantsList)
        {
            if (!isParticipantOnline(participant, currentTime))
                break;

            onlineCount++;
        }
    }
}
 
Example #2
Source File: IntroActivity.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
@Override
protected void onResume()
{
    super.onResume();
    if (justCreated)
    {
        if (LocaleController.isRTL)
        {
            viewPager.setCurrentItem(6);
            lastPage = 6;
        }
        else
        {
            viewPager.setCurrentItem(0);
            lastPage = 0;
        }
        justCreated = false;
    }
    AndroidUtilities.checkForCrashes(this);
    AndroidUtilities.checkForUpdates(this);
    ConnectionsManager.getInstance(currentAccount).setAppPaused(false, false);
}
 
Example #3
Source File: TwoStepVerificationActivity.java    From Telegram with GNU General Public License v2.0 6 votes vote down vote up
private void loadPasswordInfo(final boolean silent) {
    if (!silent) {
        loading = true;
        if (listAdapter != null) {
            listAdapter.notifyDataSetChanged();
        }
    }
    TLRPC.TL_account_getPassword req = new TLRPC.TL_account_getPassword();
    ConnectionsManager.getInstance(currentAccount).sendRequest(req, (response, error) -> AndroidUtilities.runOnUIThread(() -> {
        if (error == null) {
            loading = false;
            currentPassword = (TLRPC.TL_account_password) response;
            if (!canHandleCurrentPassword(currentPassword, false)) {
                AlertsCreator.showUpdateAppAlert(getParentActivity(), LocaleController.getString("UpdateAppAlert", R.string.UpdateAppAlert), true);
                return;
            }
            if (!silent) {
                passwordEntered = currentPasswordHash != null && currentPasswordHash.length > 0 || !currentPassword.has_password;
            }
            initPasswordNewAlgo(currentPassword);
            NotificationCenter.getInstance(currentAccount).postNotificationName(NotificationCenter.didSetOrRemoveTwoStepPassword, currentPassword);
        }
        updateRows();
    }), ConnectionsManager.RequestFlagFailOnServerErrors | ConnectionsManager.RequestFlagWithoutLogin);
}
 
Example #4
Source File: FileUploadOperation.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
public void cancel() {
    if (state == 3) {
        return;
    }
    state = 2;
    Utilities.stageQueue.postRunnable(new Runnable() {
        @Override
        public void run() {
            for (int a = 0; a < requestTokens.size(); a++) {
                ConnectionsManager.getInstance(currentAccount).cancelRequest(requestTokens.valueAt(a), true);
            }
        }
    });
    delegate.didFailedUploadingFile(this);
    cleanup();
}
 
Example #5
Source File: GroupInviteActivity.java    From Telegram-FOSS with GNU General Public License v2.0 6 votes vote down vote up
private void generateLink(final boolean newRequest) {
    loading = true;
    TLRPC.TL_messages_exportChatInvite req = new TLRPC.TL_messages_exportChatInvite();
    req.peer = MessagesController.getInstance(currentAccount).getInputPeer(-chat_id);
    final int reqId = ConnectionsManager.getInstance(currentAccount).sendRequest(req, (response, error) -> AndroidUtilities.runOnUIThread(() -> {
        if (error == null) {
            invite = (TLRPC.ExportedChatInvite) response;
            if (newRequest) {
                if (getParentActivity() == null) {
                    return;
                }
                AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
                builder.setMessage(LocaleController.getString("RevokeAlertNewLink", R.string.RevokeAlertNewLink));
                builder.setTitle(LocaleController.getString("RevokeLink", R.string.RevokeLink));
                builder.setNegativeButton(LocaleController.getString("OK", R.string.OK), null);
                showDialog(builder.create());
            }
        }
        loading = false;
        listAdapter.notifyDataSetChanged();
    }));
    ConnectionsManager.getInstance(currentAccount).bindRequestToGuid(reqId, classGuid);
    if (listAdapter != null) {
        listAdapter.notifyDataSetChanged();
    }
}
 
Example #6
Source File: BaseLocationAdapter.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
private void searchBotUser()
{
    if (searchingUser)
    {
        return;
    }
    searchingUser = true;
    TLRPC.TL_contacts_resolveUsername req = new TLRPC.TL_contacts_resolveUsername();
    req.username = MessagesController.getInstance(currentAccount).venueSearchBot;
    ConnectionsManager.getInstance(currentAccount).sendRequest(req, (response, error) ->
    {
        if (response != null)
        {
            AndroidUtilities.runOnUIThread(() ->
            {
                TLRPC.TL_contacts_resolvedPeer res = (TLRPC.TL_contacts_resolvedPeer) response;
                MessagesController.getInstance(currentAccount).putUsers(res.users, false);
                MessagesController.getInstance(currentAccount).putChats(res.chats, false);
                MessagesStorage.getInstance(currentAccount).putUsersAndChats(res.users, res.chats, true, true);
                Location coord = lastSearchLocation;
                lastSearchLocation = null;
                searchPlacesWithQuery(lastSearchQuery, coord, false);
            });
        }
    });
}
 
Example #7
Source File: BaseLocationAdapter.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
private void searchBotUser()
{
    if (searchingUser)
    {
        return;
    }
    searchingUser = true;
    TLRPC.TL_contacts_resolveUsername req = new TLRPC.TL_contacts_resolveUsername();
    req.username = MessagesController.getInstance(currentAccount).venueSearchBot;
    ConnectionsManager.getInstance(currentAccount).sendRequest(req, (response, error) ->
    {
        if (response != null)
        {
            AndroidUtilities.runOnUIThread(() ->
            {
                TLRPC.TL_contacts_resolvedPeer res = (TLRPC.TL_contacts_resolvedPeer) response;
                MessagesController.getInstance(currentAccount).putUsers(res.users, false);
                MessagesController.getInstance(currentAccount).putChats(res.chats, false);
                MessagesStorage.getInstance(currentAccount).putUsersAndChats(res.users, res.chats, true, true);
                Location coord = lastSearchLocation;
                lastSearchLocation = null;
                searchPlacesWithQuery(lastSearchQuery, coord, false);
            });
        }
    });
}
 
Example #8
Source File: NotificationsSettingsActivity.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
public void updateServerNotificationsSettings(boolean group) {
    SharedPreferences preferences = MessagesController.getNotificationsSettings(currentAccount);
    TLRPC.TL_account_updateNotifySettings req = new TLRPC.TL_account_updateNotifySettings();
    req.settings = new TLRPC.TL_inputPeerNotifySettings();
    req.settings.flags = 5;
    if (!group) {
        req.peer = new TLRPC.TL_inputNotifyUsers();
        req.settings.mute_until = preferences.getBoolean("EnableAll", true) ? 0 : Integer.MAX_VALUE;
        req.settings.show_previews = preferences.getBoolean("EnablePreviewAll", true);
    } else {
        req.peer = new TLRPC.TL_inputNotifyChats();
        req.settings.mute_until = preferences.getBoolean("EnableGroup", true) ? 0 : Integer.MAX_VALUE;
        req.settings.show_previews = preferences.getBoolean("EnablePreviewGroup", true);
    }
    ConnectionsManager.getInstance(currentAccount).sendRequest(req, (response, error) -> {

    });
}
 
Example #9
Source File: ChannelAdminLogActivity.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
private void loadAdmins() {
    TLRPC.TL_channels_getParticipants req = new TLRPC.TL_channels_getParticipants();
    req.channel = MessagesController.getInputChannel(currentChat);
    req.filter = new TLRPC.TL_channelParticipantsAdmins();
    req.offset = 0;
    req.limit = 200;
    int reqId = ConnectionsManager.getInstance(currentAccount).sendRequest(req, new RequestDelegate() {
        @Override
        public void run(final TLObject response, final TLRPC.TL_error error) {
            AndroidUtilities.runOnUIThread(new Runnable() {
                @Override
                public void run() {
                    if (error == null) {
                        TLRPC.TL_channels_channelParticipants res = (TLRPC.TL_channels_channelParticipants) response;
                        MessagesController.getInstance(currentAccount).putUsers(res.users, false);
                        admins = res.participants;
                        if (visibleDialog instanceof AdminLogFilterAlert) {
                            ((AdminLogFilterAlert) visibleDialog).setCurrentAdmins(admins);
                        }
                    }
                }
            });
        }
    });
    ConnectionsManager.getInstance(currentAccount).bindRequestToGuid(reqId, classGuid);
}
 
Example #10
Source File: StickersAdapter.java    From Telegram-FOSS with GNU General Public License v2.0 6 votes vote down vote up
public void clearStickers() {
    if (delayLocalResults || lastReqId != 0) {
        return;
    }
    if (stickersToLoad.isEmpty()) {
        lastSticker = null;
        stickers = null;
        stickersMap = null;
    }
    keywordResults = null;
    notifyDataSetChanged();
    if (lastReqId != 0) {
        ConnectionsManager.getInstance(currentAccount).cancelRequest(lastReqId, true);
        lastReqId = 0;
    }
}
 
Example #11
Source File: ProxyListActivity.java    From Telegram with GNU General Public License v2.0 6 votes vote down vote up
@Override
public boolean onFragmentCreate() {
    super.onFragmentCreate();

    SharedConfig.loadProxyList();
    currentConnectionState = ConnectionsManager.getInstance(currentAccount).getConnectionState();

    NotificationCenter.getGlobalInstance().addObserver(this, NotificationCenter.proxySettingsChanged);
    NotificationCenter.getGlobalInstance().addObserver(this, NotificationCenter.proxyCheckDone);
    NotificationCenter.getInstance(currentAccount).addObserver(this, NotificationCenter.didUpdateConnectionState);

    final SharedPreferences preferences = MessagesController.getGlobalMainSettings();
    useProxySettings = preferences.getBoolean("proxy_enabled", false) && !SharedConfig.proxyList.isEmpty();
    useProxyForCalls = preferences.getBoolean("proxy_enabled_calls", false);

    updateRows(true);

    return true;
}
 
Example #12
Source File: ProfileActivity.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
private void updateOnlineCount()
{
    onlineCount = 0;
    if (info instanceof TLRPC.TL_chatFull || info instanceof TLRPC.TL_channelFull && info.participants_count <= 200 && info.participants != null)
    {
        sortParticipants(chatOnlineParticipantsList);
        int currentTime = ConnectionsManager.getInstance(currentAccount).getCurrentTime();
        for (TLRPC.ChatParticipant participant : chatOnlineParticipantsList)
        {
            if (!isParticipantOnline(participant, currentTime))
                break;

            onlineCount++;
        }
    }
}
 
Example #13
Source File: StickersSearchAdapter.java    From Telegram-FOSS with GNU General Public License v2.0 6 votes vote down vote up
public void search(String text) {
    if (reqId != 0) {
        ConnectionsManager.getInstance(currentAccount).cancelRequest(reqId, true);
        reqId = 0;
    }
    if (reqId2 != 0) {
        ConnectionsManager.getInstance(currentAccount).cancelRequest(reqId2, true);
        reqId2 = 0;
    }
    if (TextUtils.isEmpty(text)) {
        searchQuery = null;
        localPacks.clear();
        emojiStickers.clear();
        serverPacks.clear();
        delegate.setAdapterVisible(false);
        notifyDataSetChanged();
    } else {
        searchQuery = text.toLowerCase();
    }
    AndroidUtilities.cancelRunOnUIThread(searchRunnable);
    AndroidUtilities.runOnUIThread(searchRunnable, 300);
}
 
Example #14
Source File: GcmPushListenerService.java    From Telegram with GNU General Public License v2.0 6 votes vote down vote up
public static void sendRegistrationToServer(final String token) {
    Utilities.stageQueue.postRunnable(() -> {
        ConnectionsManager.setRegId(token, SharedConfig.pushStringStatus);
        if (token == null) {
            return;
        }
        SharedConfig.pushString = token;
        for (int a = 0; a < UserConfig.MAX_ACCOUNT_COUNT; a++) {
            UserConfig userConfig = UserConfig.getInstance(a);
            userConfig.registeredForPush = false;
            userConfig.saveConfig(false);
            if (userConfig.getClientUserId() != 0) {
                final int currentAccount = a;
                AndroidUtilities.runOnUIThread(() -> MessagesController.getInstance(currentAccount).registerForPush(token));
            }
        }
    });
}
 
Example #15
Source File: FileLoadOperation.java    From Telegram with GNU General Public License v2.0 6 votes vote down vote up
public void cancel() {
    Utilities.stageQueue.postRunnable(() -> {
        if (state == stateFinished || state == stateFailed) {
            return;
        }
        if (requestInfos != null) {
            for (int a = 0; a < requestInfos.size(); a++) {
                RequestInfo requestInfo = requestInfos.get(a);
                if (requestInfo.requestToken != 0) {
                    ConnectionsManager.getInstance(currentAccount).cancelRequest(requestInfo.requestToken, true);
                }
            }
        }
        onFail(false, 1);
    });
}
 
Example #16
Source File: VoIPService.java    From Telegram with GNU General Public License v2.0 6 votes vote down vote up
@Override
protected void onTgVoipStop(TgVoip.FinalState finalState) {
	if (needRateCall || forceRating || finalState.isRatingSuggested) {
		startRatingActivity();
		needRateCall = false;
	}
	if (needSendDebugLog && finalState.debugLog != null) {
		TLRPC.TL_phone_saveCallDebug req = new TLRPC.TL_phone_saveCallDebug();
		req.debug = new TLRPC.TL_dataJSON();
		req.debug.data = finalState.debugLog;
		req.peer = new TLRPC.TL_inputPhoneCall();
		req.peer.access_hash = call.access_hash;
		req.peer.id = call.id;
		ConnectionsManager.getInstance(currentAccount).sendRequest(req, (response, error) -> {
			if (BuildVars.LOGS_ENABLED) {
				FileLog.d("Sent debug logs, response = " + response);
			}
		});
		needSendDebugLog = false;
	}
}
 
Example #17
Source File: LoginActivity.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
private void updateTimeText()
{
    int timeLeft = Math.max(0, waitTime - (ConnectionsManager.getInstance(currentAccount).getCurrentTime() - startTime));
    int days = timeLeft / 86400;
    int hours = (timeLeft - days * 86400) / 3600;
    int minutes = (timeLeft - days * 86400 - hours * 3600) / 60;
    int seconds = timeLeft % 60;
    if (days != 0)
    {
        resetAccountTime.setText(AndroidUtilities.replaceTags(LocaleController.formatPluralString("DaysBold", days) + " " + LocaleController.formatPluralString("HoursBold", hours) + " " + LocaleController.formatPluralString("MinutesBold", minutes)));
    }
    else
    {
        resetAccountTime.setText(AndroidUtilities.replaceTags(LocaleController.formatPluralString("HoursBold", hours) + " " + LocaleController.formatPluralString("MinutesBold", minutes) + " " + LocaleController.formatPluralString("SecondsBold", seconds)));
    }
    if (timeLeft > 0)
    {
        resetAccountButton.setTag(Theme.key_windowBackgroundWhiteGrayText6);
        resetAccountButton.setTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteGrayText6));
    }
    else
    {
        resetAccountButton.setTag(Theme.key_windowBackgroundWhiteRedText6);
        resetAccountButton.setTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteRedText6));
    }
}
 
Example #18
Source File: MentionsAdapter.java    From Telegram with GNU General Public License v2.0 6 votes vote down vote up
public void onDestroy() {
    if (locationProvider != null) {
        locationProvider.stop();
    }
    if (contextQueryRunnable != null) {
        AndroidUtilities.cancelRunOnUIThread(contextQueryRunnable);
        contextQueryRunnable = null;
    }
    if (contextUsernameReqid != 0) {
        ConnectionsManager.getInstance(currentAccount).cancelRequest(contextUsernameReqid, true);
        contextUsernameReqid = 0;
    }
    if (contextQueryReqid != 0) {
        ConnectionsManager.getInstance(currentAccount).cancelRequest(contextQueryReqid, true);
        contextQueryReqid = 0;
    }
    foundContextBot = null;
    inlineMediaEnabled = true;
    searchingContextUsername = null;
    searchingContextQuery = null;
    noUserName = false;
}
 
Example #19
Source File: ChannelAdminLogActivity.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
private void loadAdmins() {
    TLRPC.TL_channels_getParticipants req = new TLRPC.TL_channels_getParticipants();
    req.channel = MessagesController.getInputChannel(currentChat);
    req.filter = new TLRPC.TL_channelParticipantsAdmins();
    req.offset = 0;
    req.limit = 200;
    int reqId = ConnectionsManager.getInstance(currentAccount).sendRequest(req, new RequestDelegate() {
        @Override
        public void run(final TLObject response, final TLRPC.TL_error error) {
            AndroidUtilities.runOnUIThread(new Runnable() {
                @Override
                public void run() {
                    if (error == null) {
                        TLRPC.TL_channels_channelParticipants res = (TLRPC.TL_channels_channelParticipants) response;
                        MessagesController.getInstance(currentAccount).putUsers(res.users, false);
                        admins = res.participants;
                        if (visibleDialog instanceof AdminLogFilterAlert) {
                            ((AdminLogFilterAlert) visibleDialog).setCurrentAdmins(admins);
                        }
                    }
                }
            });
        }
    });
    ConnectionsManager.getInstance(currentAccount).bindRequestToGuid(reqId, classGuid);
}
 
Example #20
Source File: LoginActivity.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void onPause()
{
    super.onPause();
    AndroidUtilities.removeAdjustResize(getParentActivity(), classGuid);
    if (newAccount)
    {
        ConnectionsManager.getInstance(currentAccount).setAppPaused(true, false);
    }
}
 
Example #21
Source File: StickersAdapter.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
public void clearStickers() {
    lastSticker = null;
    stickers = null;
    stickersMap = null;
    stickersToLoad.clear();
    notifyDataSetChanged();
    if (lastReqId != 0) {
        ConnectionsManager.getInstance(currentAccount).cancelRequest(lastReqId, true);
        lastReqId = 0;
    }
}
 
Example #22
Source File: ApplicationLoader.java    From Telegram-FOSS with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void onCreate() {
    try {
        applicationContext = getApplicationContext();
    } catch (Throwable ignore) {

    }

    super.onCreate();

    if (applicationContext == null) {
        applicationContext = getApplicationContext();
    }

    NativeLoader.initNativeLibs(ApplicationLoader.applicationContext);
    ConnectionsManager.native_setJava(false);
    new ForegroundDetector(this) {
        @Override
        public void onActivityStarted(Activity activity) {
            boolean wasInBackground = isBackground();
            super.onActivityStarted(activity);
            if (wasInBackground) {
                ensureCurrentNetworkGet(true);
            }
        }
    };

    applicationHandler = new Handler(applicationContext.getMainLooper());

    AndroidUtilities.runOnUIThread(ApplicationLoader::startPushService);

    // SET TFOSS USERAGENT FOR OSM SERVERS
    org.osmdroid.config.Configuration.getInstance().setUserAgentValue("Telegram-FOSS(F-Droid) "+BuildConfig.VERSION_NAME);
    org.osmdroid.config.Configuration.getInstance().setOsmdroidBasePath(new File(getCacheDir(),"osmdroid"));

}
 
Example #23
Source File: TermsOfServiceView.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
private void accept()
{
    delegate.onAcceptTerms(currentAccount);
    TLRPC.TL_help_acceptTermsOfService req = new TLRPC.TL_help_acceptTermsOfService();
    req.id = currentTos.id;
    ConnectionsManager.getInstance(currentAccount).sendRequest(req, (response, error) ->
    {

    });
}
 
Example #24
Source File: LocationActivity.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
private void fetchRecentLocations(ArrayList<TLRPC.Message> messages) {
    LatLngBounds.Builder builder = null;
    if (firstFocus) {
        builder = new LatLngBounds.Builder();
    }
    int date = ConnectionsManager.getInstance(currentAccount).getCurrentTime();
    for (int a = 0; a < messages.size(); a++) {
        TLRPC.Message message = messages.get(a);
        if (message.date + message.media.period > date) {
            if (builder != null) {
                LatLng latLng = new LatLng(message.media.geo.lat, message.media.geo._long);
                builder.include(latLng);
            }
            addUserMarker(message);
        }
    }
    if (builder != null) {
        firstFocus = false;
        adapter.setLiveLocations(markers);
        if (messageObject.isLiveLocation()) {
            try {
                final LatLngBounds bounds = builder.build();
                if (messages.size() > 1) {
                    try {
                        googleMap.moveCamera(CameraUpdateFactory.newLatLngBounds(bounds, AndroidUtilities.dp(60)));
                    } catch (Exception e) {
                        FileLog.e(e);
                    }
                }
            } catch (Exception ignore) {

            }
        }
    }
}
 
Example #25
Source File: TwoStepVerificationSetupActivity.java    From Telegram with GNU General Public License v2.0 5 votes vote down vote up
private void loadPasswordInfo() {
    TLRPC.TL_account_getPassword req = new TLRPC.TL_account_getPassword();
    ConnectionsManager.getInstance(currentAccount).sendRequest(req, (response, error) -> AndroidUtilities.runOnUIThread(() -> {
        if (error == null) {
            currentPassword = (TLRPC.TL_account_password) response;
            if (!TwoStepVerificationActivity.canHandleCurrentPassword(currentPassword, false)) {
                AlertsCreator.showUpdateAppAlert(getParentActivity(), LocaleController.getString("UpdateAppAlert", R.string.UpdateAppAlert), true);
                return;
            }
            waitingForEmail = !TextUtils.isEmpty(currentPassword.email_unconfirmed_pattern);
            TwoStepVerificationActivity.initPasswordNewAlgo(currentPassword);
            if (!paused && closeAfterSet && currentPassword.has_password) {
                TLRPC.PasswordKdfAlgo pendingCurrentAlgo = currentPassword.current_algo;
                TLRPC.SecurePasswordKdfAlgo pendingNewSecureAlgo = currentPassword.new_secure_algo;
                byte[] pendingSecureRandom = currentPassword.secure_random;
                String pendingEmail = currentPassword.has_recovery ? "1" : null;
                String pendingHint = currentPassword.hint != null ? currentPassword.hint : "";

                if (!waitingForEmail && pendingCurrentAlgo != null) {
                    NotificationCenter.getInstance(currentAccount).postNotificationName(NotificationCenter.twoStepPasswordChanged, null, pendingCurrentAlgo, pendingNewSecureAlgo, pendingSecureRandom, pendingEmail, pendingHint, null, null);
                    finishFragment();
                }
            }
            if (doneAfterPasswordLoad) {
                needHideProgress();
                buttonTextView.callOnClick();
            }
            NotificationCenter.getInstance(currentAccount).postNotificationName(NotificationCenter.didSetOrRemoveTwoStepPassword, currentPassword);
        }
    }), ConnectionsManager.RequestFlagFailOnServerErrors | ConnectionsManager.RequestFlagWithoutLogin);
}
 
Example #26
Source File: ChangePhoneActivity.java    From Telegram with GNU General Public License v2.0 5 votes vote down vote up
@Override
public boolean onBackPressed(boolean force) {
    if (!force) {
        AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
        builder.setTitle(LocaleController.getString("AppName", R.string.AppName));
        builder.setMessage(LocaleController.getString("StopVerification", R.string.StopVerification));
        builder.setPositiveButton(LocaleController.getString("Continue", R.string.Continue), null);
        builder.setNegativeButton(LocaleController.getString("Stop", R.string.Stop), (dialogInterface, i) -> {
            onBackPressed(true);
            setPage(0, true, null, true);
        });
        showDialog(builder.create());
        return false;
    }
    TLRPC.TL_auth_cancelCode req = new TLRPC.TL_auth_cancelCode();
    req.phone_number = requestPhone;
    req.phone_code_hash = phoneHash;
    ConnectionsManager.getInstance(currentAccount).sendRequest(req, (response, error) -> {

    }, ConnectionsManager.RequestFlagFailOnServerErrors | ConnectionsManager.RequestFlagWithoutLogin);

    destroyTimer();
    destroyCodeTimer();
    currentParams = null;
    if (currentType == 2) {
        AndroidUtilities.setWaitingForSms(false);
        NotificationCenter.getGlobalInstance().removeObserver(this, NotificationCenter.didReceiveSmsCode);
    } else if (currentType == 3) {
        AndroidUtilities.setWaitingForCall(false);
        NotificationCenter.getGlobalInstance().removeObserver(this, NotificationCenter.didReceiveCall);
    }
    waitingForEvent = false;
    return true;
}
 
Example #27
Source File: ChatAvatarContainer.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
@Override
protected void onAttachedToWindow() {
    super.onAttachedToWindow();
    if (parentFragment != null) {
        NotificationCenter.getInstance(currentAccount).addObserver(this, NotificationCenter.didUpdatedConnectionState);
        currentConnectionState = ConnectionsManager.getInstance(currentAccount).getConnectionState();
        updateCurrentConnectionState();
    }
}
 
Example #28
Source File: SendLocationCell.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
@Override
protected void onDraw(Canvas canvas) {
    LocationController.SharingLocationInfo currentInfo = LocationController.getInstance(currentAccount).getSharingLocationInfo(dialogId);
    if (currentInfo == null) {
        return;
    }
    int currentTime = ConnectionsManager.getInstance(currentAccount).getCurrentTime();
    if (currentInfo.stopTime < currentTime) {
        return;
    }

    float progress = Math.abs(currentInfo.stopTime - currentTime) / (float) currentInfo.period;
    if (LocaleController.isRTL) {
        rect.set(AndroidUtilities.dp(13), AndroidUtilities.dp(18), AndroidUtilities.dp(43), AndroidUtilities.dp(48));
    } else {
        rect.set(getMeasuredWidth() - AndroidUtilities.dp(43), AndroidUtilities.dp(18), getMeasuredWidth() - AndroidUtilities.dp(13), AndroidUtilities.dp(48));
    }

    int color = Theme.getColor(Theme.key_location_liveLocationProgress);
    Theme.chat_radialProgress2Paint.setColor(color);
    Theme.chat_livePaint.setColor(color);

    canvas.drawArc(rect, -90, -360 * progress, false, Theme.chat_radialProgress2Paint);

    String text = LocaleController.formatLocationLeftTime(Math.abs(currentInfo.stopTime - currentTime));

    float size = Theme.chat_livePaint.measureText(text);

    canvas.drawText(text, rect.centerX() - size / 2, AndroidUtilities.dp(37), Theme.chat_livePaint);
}
 
Example #29
Source File: ChannelCreateActivity.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
public ChannelCreateActivity(Bundle args) {
    super(args);
    currentStep = args.getInt("step", 0);
    if (currentStep == 0) {
        avatarDrawable = new AvatarDrawable();
        imageUpdater = new ImageUpdater();

        TLRPC.TL_channels_checkUsername req = new TLRPC.TL_channels_checkUsername();
        req.username = "1";
        req.channel = new TLRPC.TL_inputChannelEmpty();
        ConnectionsManager.getInstance(currentAccount).sendRequest(req, new RequestDelegate() {
            @Override
            public void run(TLObject response, final TLRPC.TL_error error) {
                AndroidUtilities.runOnUIThread(new Runnable() {
                    @Override
                    public void run() {
                        canCreatePublic = error == null || !error.text.equals("CHANNELS_ADMIN_PUBLIC_TOO_MUCH");
                    }
                });
            }
        });
    } else {
        if (currentStep == 1) {
            canCreatePublic = args.getBoolean("canCreatePublic", true);
            isPrivate = !canCreatePublic;
            if (!canCreatePublic) {
                loadAdminedChannels();
            }
        }
        chatId = args.getInt("chat_id", 0);
    }
}
 
Example #30
Source File: PhotoPickerActivity.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void onFragmentDestroy() {
    NotificationCenter.getInstance(currentAccount).removeObserver(this, NotificationCenter.closeChats);
    NotificationCenter.getInstance(currentAccount).removeObserver(this, NotificationCenter.recentImagesDidLoaded);
    if (giphyReqId != 0) {
        ConnectionsManager.getInstance(currentAccount).cancelRequest(giphyReqId, true);
        giphyReqId = 0;
    }
    if (imageReqId != 0) {
        ConnectionsManager.getInstance(currentAccount).cancelRequest(imageReqId, true);
        imageReqId = 0;
    }
    super.onFragmentDestroy();
}