use of androidx.lifecycle.ViewModelProvider in project J2ME-Loader by nikita36078.
the class MainActivity method onCreate.
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
if (FileUtils.isExternalStorageLegacy()) {
permissionsLauncher.launch(STORAGE_PERMISSIONS);
}
appListModel = new ViewModelProvider(this).get(AppListModel.class);
if (savedInstanceState == null) {
Intent intent = getIntent();
Uri uri = null;
if ((intent.getFlags() & Intent.FLAG_ACTIVITY_LAUNCHED_FROM_HISTORY) == 0) {
uri = intent.getData();
}
AppsListFragment fragment = AppsListFragment.newInstance(uri);
getSupportFragmentManager().beginTransaction().replace(R.id.container, fragment).commit();
}
preferences = PreferenceManager.getDefaultSharedPreferences(this);
if (!preferences.contains(PREF_TOOLBAR)) {
boolean enable = !ViewConfiguration.get(this).hasPermanentMenuKey();
preferences.edit().putBoolean(PREF_TOOLBAR, enable).apply();
}
boolean warningShown = preferences.getBoolean(PREF_STORAGE_WARNING_SHOWN, false);
if (!FileUtils.isExternalStorageLegacy() && !warningShown) {
showScopedStorageDialog();
preferences.edit().putBoolean(PREF_STORAGE_WARNING_SHOWN, true).apply();
}
setVolumeControlStream(AudioManager.STREAM_MUSIC);
}
use of androidx.lifecycle.ViewModelProvider in project J2ME-Loader by nikita36078.
the class AppsListFragment method onCreate.
@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Bundle args = requireArguments();
appUri = args.getParcelable(KEY_APP_URI);
args.remove(KEY_APP_URI);
preferences = PreferenceManager.getDefaultSharedPreferences(requireActivity());
AppListModel appListModel = new ViewModelProvider(requireActivity()).get(AppListModel.class);
appRepository = appListModel.getAppRepository();
appRepository.observeErrors(this, this::alertDbError);
appRepository.observeApps(this, this::onDbUpdated);
}
use of androidx.lifecycle.ViewModelProvider in project bitcoin-wallet by bitcoin-wallet.
the class WalletAddressDialogFragment method onCreate.
@Override
public void onCreate(final Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
log.info("opening dialog {}", getClass().getName());
viewModel = new ViewModelProvider(getParentFragment()).get(WalletAddressViewModel.class);
viewModel.qrCode.observe(this, qrCode -> {
final BitmapDrawable qrDrawable = new BitmapDrawable(getResources(), qrCode);
qrDrawable.setFilterBitmap(false);
imageView.setImageDrawable(qrDrawable);
});
viewModel.currentAddress.observe(this, currentAddress -> {
final CharSequence label = WalletUtils.formatAddress(currentAddress, Constants.ADDRESS_FORMAT_GROUP_SIZE, Constants.ADDRESS_FORMAT_LINE_SIZE);
labelView.setText(label);
});
}
use of androidx.lifecycle.ViewModelProvider in project bitcoin-wallet by bitcoin-wallet.
the class AddressBookActivity method onCreate.
@Override
protected void onCreate(final Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
final FragmentManager fragmentManager = getSupportFragmentManager();
setContentView(R.layout.address_book_content);
final ViewPager2 pager = findViewById(R.id.address_book_pager);
final ViewPagerTabs pagerTabs = findViewById(R.id.address_book_pager_tabs);
pagerTabs.addTabLabels(TAB_LABELS);
final boolean twoPanes = getResources().getBoolean(R.bool.address_book_two_panes);
walletActivityViewModel = new ViewModelProvider(this).get(AbstractWalletActivityViewModel.class);
walletActivityViewModel.wallet.observe(this, wallet -> invalidateOptionsMenu());
viewModel = new ViewModelProvider(this).get(AddressBookViewModel.class);
viewModel.pageTo.observe(this, new Event.Observer<Integer>() {
@Override
protected void onEvent(final Integer position) {
if (!twoPanes)
pager.setCurrentItem(position, true);
}
});
viewModel.showEditAddressBookEntryDialog.observe(this, new Event.Observer<Address>() {
@Override
protected void onEvent(final Address address) {
EditAddressBookEntryFragment.edit(fragmentManager, address);
}
});
viewModel.showScanOwnAddressDialog.observe(this, new Event.Observer<Void>() {
@Override
protected void onEvent(final Void v) {
final DialogBuilder dialog = DialogBuilder.dialog(AddressBookActivity.this, R.string.address_book_options_scan_title, R.string.address_book_options_scan_own_address);
dialog.singleDismissButton(null);
dialog.show();
}
});
viewModel.showScanInvalidDialog.observe(this, new Event.Observer<Void>() {
@Override
protected void onEvent(final Void v) {
final DialogBuilder dialog = DialogBuilder.dialog(AddressBookActivity.this, R.string.address_book_options_scan_title, R.string.address_book_options_scan_invalid);
dialog.singleDismissButton(null);
dialog.show();
}
});
if (twoPanes) {
final RecyclerView recyclerView = (RecyclerView) pager.getChildAt(0);
recyclerView.setClipToPadding(false);
recyclerView.getViewTreeObserver().addOnGlobalLayoutListener(() -> {
final int width = recyclerView.getWidth();
recyclerView.setPadding(0, 0, width / 2, 0);
pager.setCurrentItem(0);
});
pager.setUserInputEnabled(false);
pagerTabs.setMode(ViewPagerTabs.Mode.STATIC);
} else {
pager.setPageTransformer(new ZoomOutPageTransformer());
pager.registerOnPageChangeCallback(pagerTabs.getPageChangeCallback());
pagerTabs.setMode(ViewPagerTabs.Mode.DYNAMIC);
}
pager.setOffscreenPageLimit(1);
pager.setAdapter(new AddressBookActivity.PagerAdapter());
}
use of androidx.lifecycle.ViewModelProvider in project bitcoin-wallet by bitcoin-wallet.
the class BlockListFragment method onCreate.
@Override
public void onCreate(final Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
walletActivityViewModel = new ViewModelProvider(activity).get(AbstractWalletActivityViewModel.class);
walletActivityViewModel.wallet.observe(this, wallet -> maybeSubmitList());
activityViewModel = new ViewModelProvider(activity).get(NetworkMonitorViewModel.class);
activityViewModel.selectedItem.observe(this, item -> {
if (item instanceof Sha256Hash) {
final Sha256Hash blockHash = (Sha256Hash) item;
adapter.setSelectedBlock(blockHash);
final int position = adapter.positionOf(blockHash);
if (position != RecyclerView.NO_POSITION)
recyclerView.smoothScrollToPosition(position);
} else {
adapter.setSelectedBlock(null);
}
});
viewModel = new ViewModelProvider(this).get(BlockListViewModel.class);
viewModel.blocks.observe(this, blocks -> {
maybeSubmitList();
viewGroup.setDisplayedChild(1);
viewModel.getTransactions().loadTransactions();
});
viewModel.getTransactions().observe(this, transactions -> maybeSubmitList());
viewModel.getTime().observe(this, time -> maybeSubmitList());
adapter = new BlockListAdapter(activity, this, this);
}
Aggregations