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);
}
}
}
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();
}
}
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();
}
}
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();
}
}
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();
}
}
Aggregations