Search in sources :

Example 76 with Fragment

use of androidx.fragment.app.Fragment in project bitcoin-wallet by bitcoin-wallet.

the class SweepWalletFragment method onCreate.

@Override
public void onCreate(final Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    this.fragmentManager = getChildFragmentManager();
    setHasOptionsMenu(true);
    if (!Constants.ENABLE_SWEEP_WALLET)
        throw new IllegalStateException("ENABLE_SWEEP_WALLET is disabled");
    walletActivityViewModel = new ViewModelProvider(activity).get(AbstractWalletActivityViewModel.class);
    walletActivityViewModel.wallet.observe(this, wallet -> updateView());
    viewModel = new ViewModelProvider(this).get(SweepWalletViewModel.class);
    viewModel.getDynamicFees().observe(this, dynamicFees -> updateView());
    viewModel.progress.observe(this, new ProgressDialogFragment.Observer(fragmentManager));
    viewModel.privateKeyToSweep.observe(this, privateKeyToSweep -> updateView());
    viewModel.walletToSweep.observe(this, walletToSweep -> {
        if (walletToSweep != null) {
            balanceView.setVisibility(View.VISIBLE);
            final MonetaryFormat btcFormat = config.getFormat();
            final MonetarySpannable balanceSpannable = new MonetarySpannable(btcFormat, walletToSweep.getBalance(BalanceType.ESTIMATED));
            balanceSpannable.applyMarkup(null, null);
            final SpannableStringBuilder balance = new SpannableStringBuilder(balanceSpannable);
            balance.insert(0, ": ");
            balance.insert(0, getString(R.string.sweep_wallet_fragment_balance));
            balanceView.setText(balance);
        } else {
            balanceView.setVisibility(View.GONE);
        }
        updateView();
    });
    viewModel.sentTransaction.observe(this, transaction -> {
        if (viewModel.state == SweepWalletViewModel.State.SENDING) {
            final TransactionConfidence confidence = transaction.getConfidence();
            final ConfidenceType confidenceType = confidence.getConfidenceType();
            final int numBroadcastPeers = confidence.numBroadcastPeers();
            if (confidenceType == ConfidenceType.DEAD)
                setState(SweepWalletViewModel.State.FAILED);
            else if (numBroadcastPeers > 1 || confidenceType == ConfidenceType.BUILDING)
                setState(SweepWalletViewModel.State.SENT);
        }
        updateView();
    });
    viewModel.showDialog.observe(this, new DialogEvent.Observer(activity));
    viewModel.showDialogWithRetryRequestBalance.observe(this, new DialogEvent.Observer(activity) {

        @Override
        protected void onBuildButtons(final DialogBuilder dialog) {
            dialog.setPositiveButton(R.string.button_retry, (d, which) -> requestWalletBalance());
            dialog.setNegativeButton(R.string.button_dismiss, null);
        }
    });
    backgroundThread = new HandlerThread("backgroundThread", Process.THREAD_PRIORITY_BACKGROUND);
    backgroundThread.start();
    backgroundHandler = new Handler(backgroundThread.getLooper());
    if (savedInstanceState == null) {
        final Intent intent = activity.getIntent();
        if (intent.hasExtra(SweepWalletActivity.INTENT_EXTRA_KEY)) {
            final PrefixedChecksummedBytes privateKeyToSweep = (PrefixedChecksummedBytes) intent.getSerializableExtra(SweepWalletActivity.INTENT_EXTRA_KEY);
            viewModel.privateKeyToSweep.setValue(privateKeyToSweep);
            // delay until fragment is resumed
            handler.post(maybeDecodeKeyRunnable);
        }
    }
}
Also used : MonetarySpannable(de.schildbach.wallet.util.MonetarySpannable) Bundle(android.os.Bundle) DumpedPrivateKey(org.bitcoinj.core.DumpedPrivateKey) Transaction(org.bitcoinj.core.Transaction) PackageManager(android.content.pm.PackageManager) Coin(org.bitcoinj.core.Coin) WalletTransaction(org.bitcoinj.wallet.WalletTransaction) LoggerFactory(org.slf4j.LoggerFactory) ScanActivity(de.schildbach.wallet.ui.scan.ScanActivity) AbstractWalletActivityViewModel(de.schildbach.wallet.ui.AbstractWalletActivityViewModel) Process(android.os.Process) NetworkParameters(org.bitcoinj.core.NetworkParameters) PrefixedChecksummedBytes(org.bitcoinj.core.PrefixedChecksummedBytes) SendRequest(org.bitcoinj.wallet.SendRequest) Handler(android.os.Handler) Map(java.util.Map) Fragment(androidx.fragment.app.Fragment) View(android.view.View) Button(android.widget.Button) R(de.schildbach.wallet.R) Configuration(de.schildbach.wallet.Configuration) Constants(de.schildbach.wallet.Constants) PaymentIntent(de.schildbach.wallet.data.PaymentIntent) BalanceType(org.bitcoinj.wallet.Wallet.BalanceType) ConfidenceType(org.bitcoinj.core.TransactionConfidence.ConfidenceType) Set(java.util.Set) ComparisonChain(com.google.common.collect.ComparisonChain) ViewGroup(android.view.ViewGroup) Preconditions.checkState(androidx.core.util.Preconditions.checkState) ECKey(org.bitcoinj.core.ECKey) TextView(android.widget.TextView) Nullable(androidx.annotation.Nullable) TransactionsAdapter(de.schildbach.wallet.ui.TransactionsAdapter) TransactionOutput(org.bitcoinj.core.TransactionOutput) UTXO(org.bitcoinj.core.UTXO) Context(android.content.Context) TransactionConfidence(org.bitcoinj.core.TransactionConfidence) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) Wallet(org.bitcoinj.wallet.Wallet) Intent(android.content.Intent) HashMap(java.util.HashMap) TreeSet(java.util.TreeSet) MenuItem(android.view.MenuItem) AnimationUtils(android.view.animation.AnimationUtils) ProgressDialogFragment(de.schildbach.wallet.ui.ProgressDialogFragment) SpannableStringBuilder(android.text.SpannableStringBuilder) VerificationException(org.bitcoinj.core.VerificationException) MenuInflater(android.view.MenuInflater) Menu(android.view.Menu) DialogEvent(de.schildbach.wallet.ui.DialogEvent) Sha256Hash(org.bitcoinj.core.Sha256Hash) BIP38PrivateKey(org.bitcoinj.crypto.BIP38PrivateKey) FragmentManager(androidx.fragment.app.FragmentManager) TransactionOutPoint(org.bitcoinj.core.TransactionOutPoint) Logger(org.slf4j.Logger) ViewModelProvider(androidx.lifecycle.ViewModelProvider) LayoutInflater(android.view.LayoutInflater) MonetaryFormat(org.bitcoinj.utils.MonetaryFormat) Threading(org.bitcoinj.utils.Threading) AbstractWalletActivity(de.schildbach.wallet.ui.AbstractWalletActivity) DialogBuilder(de.schildbach.wallet.ui.DialogBuilder) HandlerThread(android.os.HandlerThread) TransactionInput(org.bitcoinj.core.TransactionInput) StringInputParser(de.schildbach.wallet.ui.InputParser.StringInputParser) WalletApplication(de.schildbach.wallet.WalletApplication) Comparator(java.util.Comparator) Activity(android.app.Activity) EditText(android.widget.EditText) MonetaryFormat(org.bitcoinj.utils.MonetaryFormat) PrefixedChecksummedBytes(org.bitcoinj.core.PrefixedChecksummedBytes) ProgressDialogFragment(de.schildbach.wallet.ui.ProgressDialogFragment) Handler(android.os.Handler) PaymentIntent(de.schildbach.wallet.data.PaymentIntent) Intent(android.content.Intent) MonetarySpannable(de.schildbach.wallet.util.MonetarySpannable) TransactionOutPoint(org.bitcoinj.core.TransactionOutPoint) ConfidenceType(org.bitcoinj.core.TransactionConfidence.ConfidenceType) DialogEvent(de.schildbach.wallet.ui.DialogEvent) HandlerThread(android.os.HandlerThread) AbstractWalletActivityViewModel(de.schildbach.wallet.ui.AbstractWalletActivityViewModel) DialogBuilder(de.schildbach.wallet.ui.DialogBuilder) TransactionConfidence(org.bitcoinj.core.TransactionConfidence) SpannableStringBuilder(android.text.SpannableStringBuilder) ViewModelProvider(androidx.lifecycle.ViewModelProvider)

Example 77 with Fragment

use of androidx.fragment.app.Fragment in project bitcoin-wallet by bitcoin-wallet.

the class MaybeMaintenanceFragment method add.

public static void add(final FragmentManager fm) {
    Fragment fragment = fm.findFragmentByTag(FRAGMENT_TAG);
    if (fragment == null) {
        fragment = new MaybeMaintenanceFragment();
        fm.beginTransaction().add(fragment, FRAGMENT_TAG).commit();
    }
}
Also used : Fragment(androidx.fragment.app.Fragment) MaintenanceDialogFragment(de.schildbach.wallet.ui.send.MaintenanceDialogFragment)

Example 78 with Fragment

use of androidx.fragment.app.Fragment in project bitcoin-wallet by bitcoin-wallet.

the class AlertDialogsFragment method add.

public static void add(final FragmentManager fm) {
    Fragment fragment = fm.findFragmentByTag(FRAGMENT_TAG);
    if (fragment == null) {
        fragment = new AlertDialogsFragment();
        fm.beginTransaction().add(fragment, FRAGMENT_TAG).commit();
    }
}
Also used : Fragment(androidx.fragment.app.Fragment)

Example 79 with Fragment

use of androidx.fragment.app.Fragment in project android by nextcloud.

the class FileDisplayActivity method onBackPressed.

/*
     * BackPressed priority/hierarchy:
     *    1. close search view if opened
     *    2. close drawer if opened
     *    3. close FAB if open (only if drawer isn't open)
     *    4. navigate up (only if drawer and FAB aren't open)
     */
@SuppressFBWarnings("ITC_INHERITANCE_TYPE_CHECKING")
@Override
public void onBackPressed() {
    final boolean isDrawerOpen = isDrawerOpen();
    final boolean isSearchOpen = isSearchOpen();
    final Fragment leftFragment = getLeftFragment();
    if (leftFragment instanceof OCFileListFragment) {
        OCFileListFragment listOfFiles = (OCFileListFragment) leftFragment;
        if (isSearchOpen && searchView != null) {
            searchView.setQuery("", true);
            searchView.onActionViewCollapsed();
            searchView.clearFocus();
            // Remove the list to the original state
            listOfFiles.performSearch("", true);
            hideSearchView(getCurrentDir());
            setDrawerIndicatorEnabled(isDrawerIndicatorAvailable());
        } else if (isDrawerOpen) {
            // close drawer first
            super.onBackPressed();
        } else {
            // all closed
            if (mDualPane || getSecondFragment() == null) {
                OCFile currentDir = getCurrentDir();
                if (currentDir == null || currentDir.getParentId() == FileDataStorageManager.ROOT_PARENT_ID) {
                    finish();
                    return;
                }
                listOfFiles.onBrowseUp();
            }
            setFile(listOfFiles.getCurrentFile());
            listOfFiles.setFabVisible(true);
            listOfFiles.registerFabListener();
            showSortListGroup(true);
            cleanSecondFragment();
        }
    } else if (leftFragment instanceof PreviewTextStringFragment) {
        createMinFragments(null);
    } else {
        // pop back
        ((CoordinatorLayout.LayoutParams) binding.rootLayout.getLayoutParams()).setBehavior(new AppBarLayout.ScrollingViewBehavior());
        hideSearchView(getCurrentDir());
        showSortListGroup(true);
        super.onBackPressed();
    }
}
Also used : OCFile(com.owncloud.android.datamodel.OCFile) CoordinatorLayout(androidx.coordinatorlayout.widget.CoordinatorLayout) PreviewTextStringFragment(com.owncloud.android.ui.preview.PreviewTextStringFragment) OCFileListFragment(com.owncloud.android.ui.fragment.OCFileListFragment) OCFileListFragment(com.owncloud.android.ui.fragment.OCFileListFragment) UnifiedSearchFragment(com.owncloud.android.ui.fragment.UnifiedSearchFragment) Fragment(androidx.fragment.app.Fragment) TaskRetainerFragment(com.owncloud.android.ui.fragment.TaskRetainerFragment) FileFragment(com.owncloud.android.ui.fragment.FileFragment) PreviewTextStringFragment(com.owncloud.android.ui.preview.PreviewTextStringFragment) PreviewTextFragment(com.owncloud.android.ui.preview.PreviewTextFragment) PreviewTextFileFragment(com.owncloud.android.ui.preview.PreviewTextFileFragment) GalleryFragment(com.owncloud.android.ui.fragment.GalleryFragment) SortingOrderDialogFragment(com.owncloud.android.ui.dialog.SortingOrderDialogFragment) PreviewImageFragment(com.owncloud.android.ui.preview.PreviewImageFragment) PreviewMediaFragment(com.owncloud.android.ui.preview.PreviewMediaFragment) FileDetailFragment(com.owncloud.android.ui.fragment.FileDetailFragment) PreviewPdfFragment(com.owncloud.android.ui.preview.pdf.PreviewPdfFragment) SuppressFBWarnings(edu.umd.cs.findbugs.annotations.SuppressFBWarnings)

Example 80 with Fragment

use of androidx.fragment.app.Fragment in project android by nextcloud.

the class FileDisplayActivity method initFragmentsWithFile.

private void initFragmentsWithFile(User user, OCFile file) {
    // / First fragment
    OCFileListFragment listOfFiles = getListOfFilesFragment();
    if (listOfFiles != null && TextUtils.isEmpty(searchQuery)) {
        listOfFiles.listDirectory(getCurrentDir(), getFile(), MainApp.isOnlyOnDevice(), false);
    } else {
        Log_OC.e(TAG, "Still have a chance to lose the initialization of list fragment >(");
    }
    // / Second fragment
    if (mDualPane) {
        Fragment secondFragment = getSecondFragment();
        if (secondFragment == null) {
            secondFragment = chooseInitialSecondFragment(file, user);
        }
        if (secondFragment != null) {
            setSecondFragment(secondFragment);
            updateFragmentsVisibility(true);
            updateActionBarTitleAndHomeButton(file);
        } else {
            cleanSecondFragment();
            if (file.isDown() && MimeTypeUtil.isVCard(file.getMimeType())) {
                startContactListFragment(file);
            } else if (file.isDown() && PreviewTextFileFragment.canBePreviewed(file)) {
                startTextPreview(file, false);
            }
        }
    } else {
        cleanSecondFragment();
    }
}
Also used : OCFileListFragment(com.owncloud.android.ui.fragment.OCFileListFragment) OCFileListFragment(com.owncloud.android.ui.fragment.OCFileListFragment) UnifiedSearchFragment(com.owncloud.android.ui.fragment.UnifiedSearchFragment) Fragment(androidx.fragment.app.Fragment) TaskRetainerFragment(com.owncloud.android.ui.fragment.TaskRetainerFragment) FileFragment(com.owncloud.android.ui.fragment.FileFragment) PreviewTextStringFragment(com.owncloud.android.ui.preview.PreviewTextStringFragment) PreviewTextFragment(com.owncloud.android.ui.preview.PreviewTextFragment) PreviewTextFileFragment(com.owncloud.android.ui.preview.PreviewTextFileFragment) GalleryFragment(com.owncloud.android.ui.fragment.GalleryFragment) SortingOrderDialogFragment(com.owncloud.android.ui.dialog.SortingOrderDialogFragment) PreviewImageFragment(com.owncloud.android.ui.preview.PreviewImageFragment) PreviewMediaFragment(com.owncloud.android.ui.preview.PreviewMediaFragment) FileDetailFragment(com.owncloud.android.ui.fragment.FileDetailFragment) PreviewPdfFragment(com.owncloud.android.ui.preview.pdf.PreviewPdfFragment)

Aggregations

Fragment (androidx.fragment.app.Fragment)239 FragmentTransaction (androidx.fragment.app.FragmentTransaction)54 Bundle (android.os.Bundle)46 FragmentManager (androidx.fragment.app.FragmentManager)38 FileFragment (com.owncloud.android.ui.fragment.FileFragment)23 DialogFragment (androidx.fragment.app.DialogFragment)22 View (android.view.View)21 FileDetailFragment (com.owncloud.android.ui.fragment.FileDetailFragment)20 OCFileListFragment (com.owncloud.android.ui.fragment.OCFileListFragment)20 Intent (android.content.Intent)19 SortingOrderDialogFragment (com.owncloud.android.ui.dialog.SortingOrderDialogFragment)19 GalleryFragment (com.owncloud.android.ui.fragment.GalleryFragment)18 TaskRetainerFragment (com.owncloud.android.ui.fragment.TaskRetainerFragment)18 UnifiedSearchFragment (com.owncloud.android.ui.fragment.UnifiedSearchFragment)18 PreviewImageFragment (com.owncloud.android.ui.preview.PreviewImageFragment)18 PreviewMediaFragment (com.owncloud.android.ui.preview.PreviewMediaFragment)18 PreviewTextFileFragment (com.owncloud.android.ui.preview.PreviewTextFileFragment)18 PreviewTextFragment (com.owncloud.android.ui.preview.PreviewTextFragment)18 PreviewTextStringFragment (com.owncloud.android.ui.preview.PreviewTextStringFragment)18 PreviewPdfFragment (com.owncloud.android.ui.preview.pdf.PreviewPdfFragment)18