Search in sources :

Example 1 with R

use of org.thoughtcrime.securesms.R in project Signal-Android by WhisperSystems.

the class DeactivateWalletFragment method onViewCreated.

@Override
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
    Toolbar toolbar = view.findViewById(R.id.deactivate_wallet_fragment_toolbar);
    MoneyView balance = view.findViewById(R.id.deactivate_wallet_fragment_balance);
    View transferRemainingBalance = view.findViewById(R.id.deactivate_wallet_fragment_transfer);
    View deactivateWithoutTransfer = view.findViewById(R.id.deactivate_wallet_fragment_deactivate);
    LearnMoreTextView notice = view.findViewById(R.id.deactivate_wallet_fragment_notice);
    notice.setLearnMoreVisible(true);
    notice.setLink(getString(R.string.DeactivateWalletFragment__learn_more__we_recommend_transferring_your_funds));
    DeactivateWalletViewModel viewModel = ViewModelProviders.of(this).get(DeactivateWalletViewModel.class);
    viewModel.getBalance().observe(getViewLifecycleOwner(), balance::setMoney);
    viewModel.getDeactivationResults().observe(getViewLifecycleOwner(), r -> {
        if (r == DeactivateWalletViewModel.Result.SUCCESS) {
            Navigation.findNavController(requireView()).popBackStack();
        } else {
            Toast.makeText(requireContext(), R.string.DeactivateWalletFragment__error_deactivating_wallet, Toast.LENGTH_SHORT).show();
        }
    });
    transferRemainingBalance.setOnClickListener(v -> SafeNavigation.safeNavigate(Navigation.findNavController(requireView()), R.id.action_deactivateWallet_to_paymentsTransfer));
    toolbar.setNavigationOnClickListener(v -> Navigation.findNavController(requireView()).popBackStack());
    // noinspection CodeBlock2Expr
    deactivateWithoutTransfer.setOnClickListener(v -> {
        new AlertDialog.Builder(requireContext()).setTitle(R.string.DeactivateWalletFragment__deactivate_without_transferring_question).setMessage(R.string.DeactivateWalletFragment__your_balance_will_remain).setNegativeButton(android.R.string.cancel, (dialog, which) -> dialog.dismiss()).setPositiveButton(SpanUtil.color(ContextCompat.getColor(requireContext(), R.color.signal_alert_primary), getString(R.string.DeactivateWalletFragment__deactivate)), (dialog, which) -> {
            viewModel.deactivateWallet();
            dialog.dismiss();
        }).show();
    });
}
Also used : AlertDialog(android.app.AlertDialog) Bundle(android.os.Bundle) LayoutInflater(android.view.LayoutInflater) NonNull(androidx.annotation.NonNull) MoneyView(org.thoughtcrime.securesms.payments.MoneyView) SpanUtil(org.thoughtcrime.securesms.util.SpanUtil) R(org.thoughtcrime.securesms.R) ViewGroup(android.view.ViewGroup) AlertDialog(android.app.AlertDialog) Nullable(androidx.annotation.Nullable) SafeNavigation(org.thoughtcrime.securesms.util.navigation.SafeNavigation) Toast(android.widget.Toast) Fragment(androidx.fragment.app.Fragment) LearnMoreTextView(org.thoughtcrime.securesms.util.views.LearnMoreTextView) View(android.view.View) Toolbar(androidx.appcompat.widget.Toolbar) ViewModelProviders(androidx.lifecycle.ViewModelProviders) Navigation(androidx.navigation.Navigation) ContextCompat(androidx.core.content.ContextCompat) MoneyView(org.thoughtcrime.securesms.payments.MoneyView) LearnMoreTextView(org.thoughtcrime.securesms.util.views.LearnMoreTextView) MoneyView(org.thoughtcrime.securesms.payments.MoneyView) LearnMoreTextView(org.thoughtcrime.securesms.util.views.LearnMoreTextView) View(android.view.View) Toolbar(androidx.appcompat.widget.Toolbar)

Example 2 with R

use of org.thoughtcrime.securesms.R in project Signal-Android by WhisperSystems.

the class DirectoryHelper method filterForUnlistedUsers.

/**
 * Users can mark themselves as 'unlisted' in CDS, meaning that even if CDS says they're
 * unregistered, they might actually be registered. We need to double-check users who we already
 * have UUIDs for. Also, we only want to bother doing this for users we have conversations for,
 * so we will also only check for users that have a thread.
 */
private static UnlistedResult filterForUnlistedUsers(@NonNull Context context, @NonNull Set<RecipientId> inactiveIds) {
    List<Recipient> possiblyUnlisted = Stream.of(inactiveIds).map(Recipient::resolved).filter(Recipient::isRegistered).filter(Recipient::hasServiceId).filter(DirectoryHelper::hasCommunicatedWith).toList();
    ProfileService profileService = new ProfileService(ApplicationDependencies.getGroupsV2Operations().getProfileOperations(), ApplicationDependencies.getSignalServiceMessageReceiver(), ApplicationDependencies.getSignalWebSocket());
    List<Observable<Pair<Recipient, ServiceResponse<ProfileAndCredential>>>> requests = Stream.of(possiblyUnlisted).map(r -> ProfileUtil.retrieveProfile(context, r, SignalServiceProfile.RequestType.PROFILE, profileService).toObservable().timeout(5, TimeUnit.SECONDS).onErrorReturn(t -> new Pair<>(r, ServiceResponse.forUnknownError(t)))).toList();
    return Observable.mergeDelayError(requests).observeOn(Schedulers.io(), true).scan(new UnlistedResult.Builder(), (builder, pair) -> {
        Recipient recipient = pair.first();
        ProfileService.ProfileResponseProcessor processor = new ProfileService.ProfileResponseProcessor(pair.second());
        if (processor.hasResult()) {
            builder.potentiallyActiveIds.add(recipient.getId());
        } else if (processor.genericIoError() || !processor.notFound()) {
            builder.retries.add(recipient.getId());
            builder.potentiallyActiveIds.add(recipient.getId());
        }
        return builder;
    }).lastOrError().map(UnlistedResult.Builder::build).blockingGet();
}
Also used : SignalStore(org.thoughtcrime.securesms.keyvalue.SignalStore) NonNull(androidx.annotation.NonNull) R(org.thoughtcrime.securesms.R) SignalServiceAddress(org.whispersystems.signalservice.api.push.SignalServiceAddress) Manifest(android.Manifest) ProfileAndCredential(org.whispersystems.signalservice.api.profiles.ProfileAndCredential) ContactsContract(android.provider.ContactsContract) BulkOperationsHandle(org.thoughtcrime.securesms.database.RecipientDatabase.BulkOperationsHandle) RegisteredState(org.thoughtcrime.securesms.database.RecipientDatabase.RegisteredState) RecipientId(org.thoughtcrime.securesms.recipients.RecipientId) StorageSyncHelper(org.thoughtcrime.securesms.storage.StorageSyncHelper) ContentResolver(android.content.ContentResolver) Map(java.util.Map) SignalProtocolAddress(org.whispersystems.libsignal.SignalProtocolAddress) Recipient(org.thoughtcrime.securesms.recipients.Recipient) AccountManager(android.accounts.AccountManager) ACI(org.whispersystems.signalservice.api.push.ACI) Account(android.accounts.Account) ApplicationDependencies(org.thoughtcrime.securesms.dependencies.ApplicationDependencies) Collection(java.util.Collection) Set(java.util.Set) SetUtil(org.thoughtcrime.securesms.util.SetUtil) Objects(java.util.Objects) Log(org.signal.core.util.logging.Log) FeatureFlags(org.thoughtcrime.securesms.util.FeatureFlags) List(java.util.List) Nullable(androidx.annotation.Nullable) StorageSyncJob(org.thoughtcrime.securesms.jobs.StorageSyncJob) ProfileService(org.whispersystems.signalservice.api.services.ProfileService) BuildConfig(org.thoughtcrime.securesms.BuildConfig) InsertResult(org.thoughtcrime.securesms.database.MessageDatabase.InsertResult) Context(android.content.Context) SignalDatabase(org.thoughtcrime.securesms.database.SignalDatabase) Stream(com.annimon.stream.Stream) Util(org.thoughtcrime.securesms.util.Util) WorkerThread(androidx.annotation.WorkerThread) RemoteException(android.os.RemoteException) RetrieveProfileJob(org.thoughtcrime.securesms.jobs.RetrieveProfileJob) RecipientDatabase(org.thoughtcrime.securesms.database.RecipientDatabase) SignalServiceProfile(org.whispersystems.signalservice.api.profiles.SignalServiceProfile) TextSecurePreferences(org.thoughtcrime.securesms.util.TextSecurePreferences) HashSet(java.util.HashSet) Schedulers(io.reactivex.rxjava3.schedulers.Schedulers) Pair(org.whispersystems.libsignal.util.Pair) NotificationChannels(org.thoughtcrime.securesms.notifications.NotificationChannels) ProfileUtil(org.thoughtcrime.securesms.util.ProfileUtil) Calendar(java.util.Calendar) Observable(io.reactivex.rxjava3.core.Observable) RegistrationUtil(org.thoughtcrime.securesms.registration.RegistrationUtil) ContactsDatabase(org.thoughtcrime.securesms.contacts.ContactsDatabase) MultiDeviceContactUpdateJob(org.thoughtcrime.securesms.jobs.MultiDeviceContactUpdateJob) Cursor(android.database.Cursor) Collectors(com.annimon.stream.Collectors) Permissions(org.thoughtcrime.securesms.permissions.Permissions) UuidUtil(org.whispersystems.signalservice.api.util.UuidUtil) TextUtils(android.text.TextUtils) IOException(java.io.IOException) ServiceResponse(org.whispersystems.signalservice.internal.ServiceResponse) OperationApplicationException(android.content.OperationApplicationException) Optional(org.whispersystems.libsignal.util.guava.Optional) TimeUnit(java.util.concurrent.TimeUnit) CursorUtil(org.thoughtcrime.securesms.util.CursorUtil) IncomingJoinedMessage(org.thoughtcrime.securesms.sms.IncomingJoinedMessage) ContactAccessor(org.thoughtcrime.securesms.contacts.ContactAccessor) Stopwatch(org.thoughtcrime.securesms.util.Stopwatch) PhoneNumberFormatter(org.thoughtcrime.securesms.phonenumbers.PhoneNumberFormatter) Collections(java.util.Collections) ServiceResponse(org.whispersystems.signalservice.internal.ServiceResponse) ProfileService(org.whispersystems.signalservice.api.services.ProfileService) Recipient(org.thoughtcrime.securesms.recipients.Recipient) Observable(io.reactivex.rxjava3.core.Observable)

Example 3 with R

use of org.thoughtcrime.securesms.R in project Signal-Android by WhisperSystems.

the class CreateGroupActivity method handleNextPressed.

private void handleNextPressed() {
    Stopwatch stopwatch = new Stopwatch("Recipient Refresh");
    SimpleProgressDialog.DismissibleDialog dismissibleDialog = SimpleProgressDialog.showDelayed(this);
    SimpleTask.run(getLifecycle(), () -> {
        List<RecipientId> ids = contactsFragment.getSelectedContacts().stream().map(selectedContact -> selectedContact.getOrCreateRecipientId(this)).collect(Collectors.toList());
        List<Recipient> resolved = Recipient.resolvedList(ids);
        stopwatch.split("resolve");
        Set<Recipient> registeredChecks = resolved.stream().filter(r -> r.getRegistered() == RecipientDatabase.RegisteredState.UNKNOWN).collect(Collectors.toSet());
        Log.i(TAG, "Need to do " + registeredChecks.size() + " registration checks.");
        for (Recipient recipient : registeredChecks) {
            try {
                DirectoryHelper.refreshDirectoryFor(this, recipient, false);
            } catch (IOException e) {
                Log.w(TAG, "Failed to refresh registered status for " + recipient.getId(), e);
            }
        }
        if (registeredChecks.size() > 0) {
            resolved = Recipient.resolvedList(ids);
        }
        stopwatch.split("registered");
        List<Recipient> recipientsAndSelf = new ArrayList<>(resolved);
        recipientsAndSelf.add(Recipient.self().resolve());
        boolean neededRefresh = false;
        if (!SignalStore.internalValues().gv2DoNotCreateGv2Groups()) {
            try {
                neededRefresh = GroupsV2CapabilityChecker.refreshCapabilitiesIfNecessary(recipientsAndSelf);
            } catch (IOException e) {
                Log.w(TAG, "Failed to refresh all recipient capabilities.", e);
            }
        }
        if (neededRefresh) {
            resolved = Recipient.resolvedList(ids);
        }
        stopwatch.split("capabilities");
        Pair<Boolean, List<RecipientId>> result;
        boolean gv2 = Stream.of(recipientsAndSelf).allMatch(r -> r.getGroupsV2Capability() == Recipient.Capability.SUPPORTED);
        if (!gv2 && Stream.of(resolved).anyMatch(r -> !r.hasE164())) {
            Log.w(TAG, "Invalid GV1 group...");
            ids = Collections.emptyList();
            result = Pair.create(false, ids);
        } else {
            result = Pair.create(true, ids);
        }
        stopwatch.split("gv1-check");
        return result;
    }, result -> {
        dismissibleDialog.dismiss();
        stopwatch.stop(TAG);
        if (result.first) {
            startActivityForResult(AddGroupDetailsActivity.newIntent(this, result.second), REQUEST_CODE_ADD_DETAILS);
        } else {
            new AlertDialog.Builder(this).setMessage(R.string.CreateGroupActivity_some_contacts_cannot_be_in_legacy_groups).setPositiveButton(android.R.string.ok, (d, w) -> d.dismiss()).show();
        }
    });
}
Also used : SignalStore(org.thoughtcrime.securesms.keyvalue.SignalStore) Context(android.content.Context) Bundle(android.os.Bundle) AlertDialog(androidx.appcompat.app.AlertDialog) Stream(com.annimon.stream.Stream) ContactsCursorLoader(org.thoughtcrime.securesms.contacts.ContactsCursorLoader) DirectoryHelper(org.thoughtcrime.securesms.contacts.sync.DirectoryHelper) Util(org.thoughtcrime.securesms.util.Util) NonNull(androidx.annotation.NonNull) ContactSelectionListFragment(org.thoughtcrime.securesms.ContactSelectionListFragment) SimpleProgressDialog(org.thoughtcrime.securesms.util.views.SimpleProgressDialog) Pair(android.util.Pair) Intent(android.content.Intent) ViewUtil(org.thoughtcrime.securesms.util.ViewUtil) R(org.thoughtcrime.securesms.R) RecipientDatabase(org.thoughtcrime.securesms.database.RecipientDatabase) MenuItem(android.view.MenuItem) ArrayList(java.util.ArrayList) RecipientId(org.thoughtcrime.securesms.recipients.RecipientId) MaterialButton(com.google.android.material.button.MaterialButton) Recipient(org.thoughtcrime.securesms.recipients.Recipient) GroupsV2CapabilityChecker(org.thoughtcrime.securesms.groups.GroupsV2CapabilityChecker) ExtendedFloatingActionButton(com.google.android.material.floatingactionbutton.ExtendedFloatingActionButton) SimpleTask(org.thoughtcrime.securesms.util.concurrent.SimpleTask) ContactSelectionActivity(org.thoughtcrime.securesms.ContactSelectionActivity) Set(java.util.Set) IOException(java.io.IOException) Collectors(java.util.stream.Collectors) AddGroupDetailsActivity(org.thoughtcrime.securesms.groups.ui.creategroup.details.AddGroupDetailsActivity) Optional(org.whispersystems.libsignal.util.guava.Optional) Consumer(java.util.function.Consumer) Log(org.signal.core.util.logging.Log) FeatureFlags(org.thoughtcrime.securesms.util.FeatureFlags) List(java.util.List) Nullable(androidx.annotation.Nullable) Stopwatch(org.thoughtcrime.securesms.util.Stopwatch) Collections(java.util.Collections) ValueAnimator(android.animation.ValueAnimator) AlertDialog(androidx.appcompat.app.AlertDialog) RecipientId(org.thoughtcrime.securesms.recipients.RecipientId) Stopwatch(org.thoughtcrime.securesms.util.Stopwatch) ArrayList(java.util.ArrayList) Recipient(org.thoughtcrime.securesms.recipients.Recipient) IOException(java.io.IOException) ArrayList(java.util.ArrayList) List(java.util.List) SimpleProgressDialog(org.thoughtcrime.securesms.util.views.SimpleProgressDialog)

Aggregations

NonNull (androidx.annotation.NonNull)3 Nullable (androidx.annotation.Nullable)3 R (org.thoughtcrime.securesms.R)3 Context (android.content.Context)2 Bundle (android.os.Bundle)2 Stream (com.annimon.stream.Stream)2 IOException (java.io.IOException)2 Collections (java.util.Collections)2 List (java.util.List)2 Set (java.util.Set)2 Log (org.signal.core.util.logging.Log)2 RecipientDatabase (org.thoughtcrime.securesms.database.RecipientDatabase)2 SignalStore (org.thoughtcrime.securesms.keyvalue.SignalStore)2 Recipient (org.thoughtcrime.securesms.recipients.Recipient)2 RecipientId (org.thoughtcrime.securesms.recipients.RecipientId)2 FeatureFlags (org.thoughtcrime.securesms.util.FeatureFlags)2 Stopwatch (org.thoughtcrime.securesms.util.Stopwatch)2 Util (org.thoughtcrime.securesms.util.Util)2 Optional (org.whispersystems.libsignal.util.guava.Optional)2 Manifest (android.Manifest)1