Search in sources :

Example 41 with ViewModelProvider

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);
}
Also used : AppsListFragment(ru.playsoftware.j2meloader.applist.AppsListFragment) Intent(android.content.Intent) AppListModel(ru.playsoftware.j2meloader.applist.AppListModel) Uri(android.net.Uri) ViewModelProvider(androidx.lifecycle.ViewModelProvider)

Example 42 with ViewModelProvider

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);
}
Also used : Bundle(android.os.Bundle) ViewModelProvider(androidx.lifecycle.ViewModelProvider)

Example 43 with ViewModelProvider

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);
    });
}
Also used : BitmapDrawable(android.graphics.drawable.BitmapDrawable) ViewModelProvider(androidx.lifecycle.ViewModelProvider)

Example 44 with ViewModelProvider

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());
}
Also used : ViewPagerTabs(de.schildbach.wallet.util.ViewPagerTabs) Address(org.bitcoinj.core.Address) FragmentManager(androidx.fragment.app.FragmentManager) ViewPager2(androidx.viewpager2.widget.ViewPager2) RecyclerView(androidx.recyclerview.widget.RecyclerView) ViewModelProvider(androidx.lifecycle.ViewModelProvider) ZoomOutPageTransformer(de.schildbach.wallet.util.ZoomOutPageTransformer)

Example 45 with ViewModelProvider

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);
}
Also used : Sha256Hash(org.bitcoinj.core.Sha256Hash) AbstractWalletActivityViewModel(de.schildbach.wallet.ui.AbstractWalletActivityViewModel) ViewModelProvider(androidx.lifecycle.ViewModelProvider)

Aggregations

ViewModelProvider (androidx.lifecycle.ViewModelProvider)56 TextView (android.widget.TextView)13 Intent (android.content.Intent)12 View (android.view.View)11 FirebaseUiException (com.firebase.ui.auth.FirebaseUiException)8 IdpResponse (com.firebase.ui.auth.IdpResponse)8 Bundle (android.os.Bundle)7 Toolbar (androidx.appcompat.widget.Toolbar)7 FirebaseAuthAnonymousUpgradeException (com.firebase.ui.auth.FirebaseAuthAnonymousUpgradeException)7 Handler (android.os.Handler)6 HandlerThread (android.os.HandlerThread)5 SpannableStringBuilder (android.text.SpannableStringBuilder)5 Nullable (androidx.annotation.Nullable)5 RecyclerView (androidx.recyclerview.widget.RecyclerView)5 LinearLayoutManager (androidx.recyclerview.widget.LinearLayoutManager)4 Animator (android.animation.Animator)3 Bitmap (android.graphics.Bitmap)3 BitmapDrawable (android.graphics.drawable.BitmapDrawable)3 Uri (android.net.Uri)3 FragmentManager (androidx.fragment.app.FragmentManager)3