androidx.lifecycle.ViewModelProvider Java Examples

The following examples show how to use androidx.lifecycle.ViewModelProvider. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source Project: LicenseAdapter   Author: yshrsmz   File: LicenseAdapter.java    License: Apache License 2.0 7 votes vote down vote up
@Override
public ViewHolderBase onCreateViewHolder(ViewGroup parent, int viewType) {
  Context context = parent.getContext();

  if (holder == null) {
    if (context instanceof FragmentActivity) {
      ViewModelProvider.AndroidViewModelFactory factory = ViewModelProvider.AndroidViewModelFactory.getInstance(((FragmentActivity) context).getApplication());
      holder = new ViewModelProvider((FragmentActivity) context, factory).get(LibrariesHolder.class);
    } else if (context instanceof Activity) {
      holder = new LibrariesHolder(((Activity) context).getApplication());
    } else {
      holder = new LibrariesHolder((Application) context.getApplicationContext());
    }
  }

  if (viewType == TYPE_LIBRARY) {
    return new LibraryViewHolder(LayoutInflater.from(context)
        .inflate(R.layout.library, parent, false));
  } else if (viewType == TYPE_LICENSE) {
    return new LicenseViewHolder(LayoutInflater.from(context)
        .inflate(R.layout.license, parent, false), holder);
  } else {
    throw new IllegalStateException("Unknown view type: " + viewType);
  }
}
 
Example #2
Source Project: Pixiv-Shaft   Author: CeuiLiSA   File: ListFragment.java    License: MIT License 6 votes vote down vote up
@Override
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);
    //获取viewmodel
    mModel = (BaseModel<Item>) new ViewModelProvider(this).get(modelClass());
    allItems = mModel.getContent().getValue();

    //为recyclerView设置Adapter
    mAdapter = adapter();
    if (mAdapter != null) {
        mRecyclerView.setAdapter(mAdapter);
    }

    onAdapterPrepared();

    //进页面主动刷新
    if (autoRefresh() && !mModel.isLoaded()) {
        mRefreshLayout.autoRefresh();
    }
}
 
Example #3
Source Project: Hentoid   Author: avluis   File: SearchBottomSheetFragment.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void onAttach(@NonNull Context context) {
    super.onAttach(context);

    Bundle bundle = getArguments();
    if (bundle != null) {
        SearchActivityBundle.Parser parser = new SearchActivityBundle.Parser(bundle);
        selectedAttributeTypes = parser.getAttributeTypes();
        currentPage = 1;

        if (selectedAttributeTypes.isEmpty()) {
            throw new IllegalArgumentException("Initialization failed");
        }

        ViewModelFactory vmFactory = new ViewModelFactory(requireActivity().getApplication());
        viewModel = new ViewModelProvider(requireActivity(), vmFactory).get(SearchViewModel.class);
        viewModel.setAttributeTypes(selectedAttributeTypes);
    }
}
 
Example #4
Source Project: Bluefruit_LE_Connect_Android_V2   Author: adafruit   File: DfuFragment.java    License: MIT License 6 votes vote down vote up
@Override
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);

    // ViewModel
    FragmentActivity activity = getActivity();
    if (activity != null) {
        mDfuViewModel = new ViewModelProvider(activity).get(DfuViewModel.class);

        // Dfu Update
        mDfuViewModel.getDfuCheckResult().observe(this, dfuCheckResult -> {
            if (dfuCheckResult != null) {
                onDfuUpdateCheckResultReceived(dfuCheckResult.blePeripheral, dfuCheckResult.isUpdateAvailable, dfuCheckResult.dfuInfo, dfuCheckResult.firmwareInfo);
            }
        });

        // Check updates if needed
        Log.d(TAG, "Check firmware updates");
        mWaitView.setVisibility(View.VISIBLE);
        mDfuViewModel.startUpdatesCheck(activity, mBlePeripheral);
    }
}
 
Example #5
Source Project: Hentoid   Author: avluis   File: LibraryFragment.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
    View rootView = inflater.inflate(R.layout.fragment_library, container, false);

    Preferences.registerPrefsChangedListener(prefsListener);

    ViewModelFactory vmFactory = new ViewModelFactory(requireActivity().getApplication());
    viewModel = new ViewModelProvider(this, vmFactory).get(LibraryViewModel.class);

    initUI(rootView);

    initToolbar(rootView);
    initSelectionToolbar(rootView);
    toolbar.setOnMenuItemClickListener(this::toolbarOnItemClicked);
    selectionToolbar.setOnMenuItemClickListener(this::selectionToolbarOnItemClicked);

    return rootView;
}
 
Example #6
Source Project: ArchPackages   Author: rascarlo   File: DetailsFragment.java    License: GNU General Public License v3.0 6 votes vote down vote up
@Override
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);
    if (fragmentDetailsBinding != null) {
        // details
        DetailsViewModelFactory detailsViewModelFactory = new DetailsViewModelFactory(bundleRepo, bundleArch, bundlePkgname);
        DetailsViewModel detailsViewModel = new ViewModelProvider(this, detailsViewModelFactory).get(DetailsViewModel.class);
        detailsViewModel.getDetailsLiveData().observe(getViewLifecycleOwner(), details -> {
            if (details != null && fragmentDetailsBinding != null) {
                fragmentDetailsBinding.setDetails(details);
                fragmentDetailsBinding.executePendingBindings();
                bindDetailsViewModel(details);
            }
        });
        // files
        FilesViewModelFactory filesViewModelFactory = new FilesViewModelFactory(bundleRepo, bundleArch, bundlePkgname);
        FilesViewModel filesViewModel = new ViewModelProvider(this, filesViewModelFactory).get(FilesViewModel.class);
        filesViewModel.getFilesLiveData().observe(getViewLifecycleOwner(), files -> {
            if (files != null && fragmentDetailsBinding != null) {
                fragmentDetailsBinding.detailsFilesLayout.setFiles(files);
                bindFilesViewModel(files);
            }
        });
    }
}
 
Example #7
Source Project: FirefoxReality   Author: MozillaReality   File: HistoryView.java    License: Mozilla Public License 2.0 6 votes vote down vote up
protected void initialize() {
    super.initialize();

    mAccounts = ((VRBrowserApplication) getContext().getApplicationContext()).getAccounts();
    if (ACCOUNTS_UI_ENABLED) {
        mAccounts.addAccountListener(mAccountListener);
        mAccounts.addSyncListener(mSyncListener);
    }

    mViewModel = new ViewModelProvider(
            (VRBrowserActivity) getContext(),
            ViewModelProvider.AndroidViewModelFactory.getInstance(((VRBrowserActivity) getContext()).getApplication()))
            .get(HistoryViewModel.class);

    SessionStore.get().getHistoryStore().addListener(this);

    updateUI();
}
 
Example #8
Source Project: FirefoxReality   Author: MozillaReality   File: TrayWidget.java    License: Mozilla Public License 2.0 6 votes vote down vote up
private void initialize(Context aContext) {
    // Downloads icon progress clipping doesn't work if HW acceleration is enabled.
    setIsHardwareAccelerationEnabled(false);

    mTrayViewModel = new ViewModelProvider(
            (VRBrowserActivity)getContext(),
            ViewModelProvider.AndroidViewModelFactory.getInstance(((VRBrowserActivity) getContext()).getApplication()))
            .get(TrayViewModel.class);
    mTrayViewModel.getIsVisible().observe((VRBrowserActivity) getContext(), mIsVisibleObserver);

    updateUI();

    mIsWindowAttached = false;

    mTrayListeners = new ArrayList<>();

    mMinPadding = WidgetPlacement.pixelDimension(getContext(), R.dimen.tray_icon_padding_min);
    mMaxPadding = WidgetPlacement.pixelDimension(getContext(), R.dimen.tray_icon_padding_max);

    mAudio = AudioEngine.fromContext(aContext);

    mWidgetManager.addUpdateListener(this);
    mWidgetManager.getServicesProvider().getDownloadsManager().addListener(this);
}
 
Example #9
Source Project: FirefoxReality   Author: MozillaReality   File: TitleBarWidget.java    License: Mozilla Public License 2.0 6 votes vote down vote up
@Override
public void attachToWindow(@NonNull WindowWidget aWindow) {
    if (aWindow == mAttachedWindow) {
        return;
    }
    detachFromWindow();

    mWidgetPlacement.parentHandle = aWindow.getHandle();
    mAttachedWindow = aWindow;

    // ModelView creation and observers setup
    mViewModel = new ViewModelProvider(
            (VRBrowserActivity)getContext(),
            ViewModelProvider.AndroidViewModelFactory.getInstance(((VRBrowserActivity) getContext()).getApplication()))
            .get(String.valueOf(mAttachedWindow.hashCode()), WindowViewModel.class);

    mBinding.setViewmodel(mViewModel);

    mViewModel.getIsTitleBarVisible().observe((VRBrowserActivity)getContext(), mIsVisibleObserver);
}
 
Example #10
Source Project: FirefoxReality   Author: MozillaReality   File: SettingsWidget.java    License: Mozilla Public License 2.0 6 votes vote down vote up
@SuppressLint("ClickableViewAccessibility")
private void initialize() {
    mSettingsViewModel = new ViewModelProvider(
            (VRBrowserActivity)getContext(),
            ViewModelProvider.AndroidViewModelFactory.getInstance(((VRBrowserActivity) getContext()).getApplication()))
            .get(SettingsViewModel.class);

    updateUI();

    mOpenDialog = SettingsView.SettingViewType.MAIN;

    mAccounts = ((VRBrowserApplication)getContext().getApplicationContext()).getAccounts();
    mAccounts.addAccountListener(mAccountObserver);

    mUIThreadExecutor = ((VRBrowserApplication)getContext().getApplicationContext()).getExecutors().mainThread();

    mAudio = AudioEngine.fromContext(getContext());

    mViewMarginH = mWidgetPlacement.width - WidgetPlacement.dpDimension(getContext(), R.dimen.options_width);
    mViewMarginH = WidgetPlacement.convertDpToPixel(getContext(), mViewMarginH);
    mViewMarginV = mWidgetPlacement.height - WidgetPlacement.dpDimension(getContext(), R.dimen.options_height);
    mViewMarginV = WidgetPlacement.convertDpToPixel(getContext(), mViewMarginV);
}
 
Example #11
Source Project: FirefoxReality   Author: MozillaReality   File: TopBarWidget.java    License: Mozilla Public License 2.0 6 votes vote down vote up
@Override
public void attachToWindow(@NonNull WindowWidget aWindow) {
    if (mAttachedWindow == aWindow) {
        return;
    }
    detachFromWindow();

    mWidgetPlacement.parentHandle = aWindow.getHandle();
    mAttachedWindow = aWindow;

    // ModelView creation and observers setup
    mViewModel = new ViewModelProvider(
            (VRBrowserActivity)getContext(),
            ViewModelProvider.AndroidViewModelFactory.getInstance(((VRBrowserActivity) getContext()).getApplication()))
            .get(String.valueOf(mAttachedWindow.hashCode()), WindowViewModel.class);

    mBinding.setViewmodel(mViewModel);

    mViewModel.getIsTopBarVisible().observe((VRBrowserActivity)getContext(), mIsVisible);
}
 
Example #12
Source Project: SAI   Author: Aefyr   File: LicensesActivity.java    License: GNU General Public License v3.0 6 votes vote down vote up
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_licenses);

    RecyclerView recyclerView = findViewById(R.id.rv_licenses);

    recyclerView.setLayoutManager(new LinearLayoutManager(this));
    recyclerView.getRecycledViewPool().setMaxRecycledViews(0, 16);

    LicensesAdapter adapter = new LicensesAdapter(this);
    recyclerView.setAdapter(adapter);

    LicensesViewModel viewModel = new ViewModelProvider(this).get(LicensesViewModel.class);
    viewModel.getLicenses().observe(this, adapter::setLicenses);
}
 
Example #13
Source Project: SAI   Author: Aefyr   File: BatchBackupDialogFragment.java    License: GNU General Public License v3.0 6 votes vote down vote up
@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setCancelable(false);

    Bundle args = getArguments();
    ArrayList<String> packages = null;
    if (args != null) {
        packages = args.getStringArrayList(ARG_PACKAGES);
    }

    mViewModel = new ViewModelProvider(this, new BatchBackupDialogViewModelFactory(requireContext().getApplicationContext(), packages)).get(BatchBackupDialogViewModel.class);
    mViewModel.getIsBackupEnqueued().observe(this, (isBackupEnqueued) -> {
        if (isBackupEnqueued) {

            OnBatchBackupEnqueuedListener listener = Utils.getParentAs(this, OnBatchBackupEnqueuedListener.class);
            if (listener != null)
                listener.onBatchBackupEnqueued(getTag());

            dismiss();
        }

    });
}
 
Example #14
Source Project: android-popular-movies-app   Author: sooshin   File: DetailActivity.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * When offline, display runtime, release year, and genre of the movie.
 */
private void loadMovieDetailData() {
    FavViewModelFactory factory = InjectorUtils.provideFavViewModelFactory(
            DetailActivity.this, mMovie.getId());
    mFavViewModel = new ViewModelProvider(this, factory).get(FavViewModel.class);

    mFavViewModel.getMovieEntry().observe(this, new Observer<MovieEntry>() {
        @Override
        public void onChanged(@Nullable MovieEntry movieEntry) {
            if (movieEntry != null) {
                mDetailBinding.tvRuntime.setText(movieEntry.getRuntime());
                mDetailBinding.tvReleaseYear.setText(movieEntry.getReleaseYear());
                mDetailBinding.tvGenre.setText(movieEntry.getGenre());
            }
        }
    });
}
 
Example #15
Source Project: android-popular-movies-app   Author: sooshin   File: DetailActivity.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Return true and set a favoriteFab image to full heart image if the movie is in favorites collection.
 * Otherwise return false and set favoriteFab image to border heart image.
 */
private boolean isInFavoritesCollection() {
    // Get the FavViewModel from the factory
    FavViewModelFactory factory = InjectorUtils.provideFavViewModelFactory(
            DetailActivity.this, mMovie.getId());
    mFavViewModel = new ViewModelProvider(this, factory).get(FavViewModel.class);

    // Changes the favoriteFab image based on whether or not the movie exists
    mFavViewModel.getMovieEntry().observe(this, new Observer<MovieEntry>() {
        @Override
        public void onChanged(@Nullable MovieEntry movieEntry) {
            if (mFavViewModel.getMovieEntry().getValue() == null) {
                mDetailBinding.fab.setImageResource(R.drawable.favorite_border);
                mIsInFavorites = false;
            } else {
                mDetailBinding.fab.setImageResource(R.drawable.favorite);
                mIsInFavorites = true;
            }
        }
    });
    return mIsInFavorites;
}
 
Example #16
Source Project: webrtc_android   Author: ddssingsong   File: SettingFragment.java    License: MIT License 5 votes vote down vote up
public View onCreateView(@NonNull LayoutInflater inflater,
                         ViewGroup container, Bundle savedInstanceState) {
    notificationsViewModel = new ViewModelProvider(requireActivity()).get(SettingViewModel.class);
    View root = inflater.inflate(R.layout.fragment_setting, container, false);
    final TextView textView = root.findViewById(R.id.text_notifications);
    button = root.findViewById(R.id.exit);
    button.setOnClickListener(view -> {
        SocketManager.getInstance().unConnect();
    });
    notificationsViewModel.getText().observe(getViewLifecycleOwner(), textView::setText);
    return root;
}
 
Example #17
Source Project: webrtc_android   Author: ddssingsong   File: UserListFragment.java    License: MIT License 5 votes vote down vote up
public View onCreateView(@NonNull LayoutInflater inflater,
                         ViewGroup container, Bundle savedInstanceState) {
    homeViewModel = new ViewModelProvider(requireActivity()).get(UserListViewModel.class);
    View root = inflater.inflate(R.layout.fragment_home, container, false);
    initView(root);
    initData();
    return root;
}
 
Example #18
Source Project: webrtc_android   Author: ddssingsong   File: RoomFragment.java    License: MIT License 5 votes vote down vote up
public View onCreateView(@NonNull LayoutInflater inflater,
                         ViewGroup container, Bundle savedInstanceState) {

    roomViewModel = new ViewModelProvider(requireActivity()).get(RoomViewModel.class);
    View root = inflater.inflate(R.layout.fragment_room, container, false);
    initView(root);
    initData();

    return root;
}
 
Example #19
Source Project: tv-samples   Author: android   File: PresenterModule.java    License: Apache License 2.0 5 votes vote down vote up
@PerFragment
@Provides
public LiveDataRowPresenter provideLiveDataRowPresenter(ViewModelProvider.Factory factory,
        DataLoadedListener activity) {
    LiveDataRowPresenter rowPresenter = new LiveDataRowPresenter(factory);

    rowPresenter.registerDataLoadedListener(activity);
    return rowPresenter;
}
 
Example #20
Source Project: lttrs-android   Author: iNPUTmice   File: SearchQueryFragment.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    final Bundle bundle = getArguments();
    final String term = SearchQueryFragmentArgs.fromBundle(bundle == null ? new Bundle() : bundle).getText();
    final ViewModelProvider viewModelProvider = new ViewModelProvider(
            getViewModelStore(),
            new SearchQueryViewModelFactory(
                    requireActivity().getApplication(),
                    getLttrsViewModel().getAccount(),
                    term
            )
    );
    this.searchQueryViewModel = viewModelProvider.get(SearchQueryViewModel.class);
    return super.onCreateView(inflater, container, savedInstanceState);
}
 
Example #21
Source Project: lttrs-android   Author: iNPUTmice   File: AbstractMailboxQueryFragment.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    final ViewModelProvider viewModelProvider = new ViewModelProvider(
            getViewModelStore(),
            new MailboxQueryViewModelFactory(
                    requireActivity().getApplication(),
                    getLttrsViewModel().getAccount(),
                    getMailboxId()
            )
    );
    this.mailboxQueryViewModel = viewModelProvider.get(MailboxQueryViewModel.class);
    return super.onCreateView(inflater, container, savedInstanceState);
}
 
Example #22
Source Project: lttrs-android   Author: iNPUTmice   File: AbstractLttrsFragment.java    License: Apache License 2.0 5 votes vote down vote up
LttrsViewModel getLttrsViewModel() {
    final ViewModelProvider viewModelProvider = new ViewModelProvider(
            requireActivity(),
            getDefaultViewModelProviderFactory()
    );
    return viewModelProvider.get(LttrsViewModel.class);
}
 
Example #23
Source Project: Hentoid   Author: avluis   File: ImageBottomSheetFragment.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void onAttach(@NonNull Context context) {
    super.onAttach(context);

    Bundle bundle = getArguments();
    if (bundle != null) {
        ImageViewerActivityBundle.Parser parser = new ImageViewerActivityBundle.Parser(bundle);
        imageIndex = parser.getImageIndex();
        if (-1 == imageIndex) throw new IllegalArgumentException("Initialization failed");
        scale = parser.getScale();
    }

    ViewModelFactory vmFactory = new ViewModelFactory(requireActivity().getApplication());
    viewModel = new ViewModelProvider(requireActivity(), vmFactory).get(ImageViewerViewModel.class);
}
 
Example #24
Source Project: lttrs-android   Author: iNPUTmice   File: SetupActivity.java    License: Apache License 2.0 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    final ActivitySetupBinding binding = DataBindingUtil.setContentView(this, R.layout.activity_setup);
    final NavController navController = Navigation.findNavController(
            this,
            R.id.nav_host_fragment
    );
    final ViewModelProvider viewModelProvider = new ViewModelProvider(
            this,
            getDefaultViewModelProviderFactory()
    );
    final SetupViewModel setupViewModel = viewModelProvider.get(SetupViewModel.class);
    setupViewModel.getRedirection().observe(this, targetEvent -> {
        if (targetEvent.isConsumable()) {
            final SetupViewModel.Target target = targetEvent.consume();
            switch (target) {
                case LTTRS:
                    redirectToLttrs();
                    break;
                case ENTER_PASSWORD:
                    navController.navigate(SetupNavigationDirections.enterPassword());
                    break;
                case ENTER_URL:
                    navController.navigate(SetupNavigationDirections.enterSessionResource());
                    break;
                default:
                    throw new IllegalStateException(String.format("Unable to navigate to target %s", target));

            }
        }
    });
    setupViewModel.getWarningMessage().observe(this, event -> {
        if (event.isConsumable()) {
            Snackbar.make(binding.getRoot(), event.consume(), Snackbar.LENGTH_LONG).show();
        }
    });
}
 
Example #25
Source Project: mcumgr-android   Author: JuulLabs-OSS   File: EchoFragment.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void onCreate(@Nullable final Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    mViewModel = new ViewModelProvider(this, mViewModelFactory)
            .get(EchoViewModel.class);
    mImm = (InputMethodManager) requireContext().getSystemService(Context.INPUT_METHOD_SERVICE);
}
 
Example #26
Source Project: Pixiv-Shaft   Author: CeuiLiSA   File: FragmentSearchIllust.java    License: MIT License 5 votes vote down vote up
@Override
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
    searchModel = new ViewModelProvider(requireActivity()).get(SearchModel.class);
    searchModel.getNowGo().observe(getViewLifecycleOwner(), new Observer<String>() {
        @Override
        public void onChanged(String s) {
            mRefreshLayout.autoRefresh();
        }
    });
    super.onActivityCreated(savedInstanceState);
}
 
Example #27
Source Project: Pixiv-Shaft   Author: CeuiLiSA   File: FragmentSearchNovel.java    License: MIT License 5 votes vote down vote up
@Override
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
    searchModel = new ViewModelProvider(requireActivity()).get(SearchModel.class);
    searchModel.getNowGo().observe(this, new Observer<String>() {
        @Override
        public void onChanged(String s) {
            mRefreshLayout.autoRefresh();
        }
    });
    super.onActivityCreated(savedInstanceState);
}
 
Example #28
Source Project: Pixiv-Shaft   Author: CeuiLiSA   File: SearchActivity.java    License: MIT License 5 votes vote down vote up
@Override
protected void initBundle(Bundle bundle) {
    keyWord = bundle.getString(Params.KEY_WORD);
    index = bundle.getInt(Params.INDEX);
    searchModel = new ViewModelProvider(this).get(SearchModel.class);
    searchModel.getKeyword().setValue(keyWord);
    searchModel.getNowGo().observe(this, new Observer<String>() {
        @Override
        public void onChanged(String s) {
            baseBind.drawerlayout.closeMenu(true);
        }
    });
}
 
Example #29
Source Project: graphics-samples   Author: android   File: PdfRendererBasicFragment.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void onViewCreated(@NonNull View view, Bundle savedInstanceState) {
    // View references.
    final ImageView image = view.findViewById(R.id.image);
    final Button buttonPrevious = view.findViewById(R.id.previous);
    final Button buttonNext = view.findViewById(R.id.next);

    // Bind data.
    mViewModel = new ViewModelProvider(this).get(PdfRendererBasicViewModel.class);
    final LifecycleOwner viewLifecycleOwner = getViewLifecycleOwner();
    mViewModel.getPageInfo().observe(viewLifecycleOwner, pageInfo -> {
        if (pageInfo == null) {
            return;
        }
        final Activity activity = getActivity();
        if (activity != null) {
            activity.setTitle(getString(R.string.app_name_with_index,
                    pageInfo.index + 1, pageInfo.count));
        }
    });
    mViewModel.getPageBitmap().observe(viewLifecycleOwner, image::setImageBitmap);
    mViewModel.getPreviousEnabled().observe(viewLifecycleOwner, buttonPrevious::setEnabled);
    mViewModel.getNextEnabled().observe(viewLifecycleOwner, buttonNext::setEnabled);

    // Bind events.
    buttonPrevious.setOnClickListener(mOnClickListener);
    buttonNext.setOnClickListener(mOnClickListener);
}
 
Example #30
Source Project: FirebaseUI-Android   Author: firebase   File: AuthMethodPickerActivity.java    License: Apache License 2.0 5 votes vote down vote up
private void populateIdpList(List<IdpConfig> providerConfigs) {

        ViewModelProvider supplier = ViewModelProviders.of(this);
        mProviders = new ArrayList<>();
        for (IdpConfig idpConfig : providerConfigs) {
            @LayoutRes int buttonLayout;

            final String providerId = idpConfig.getProviderId();
            switch (providerId) {
                case GoogleAuthProvider.PROVIDER_ID:
                    buttonLayout = R.layout.fui_idp_button_google;
                    break;
                case FacebookAuthProvider.PROVIDER_ID:
                    buttonLayout = R.layout.fui_idp_button_facebook;
                    break;
                case EMAIL_LINK_PROVIDER:
                case EmailAuthProvider.PROVIDER_ID:
                    buttonLayout = R.layout.fui_provider_button_email;
                    break;
                case PhoneAuthProvider.PROVIDER_ID:
                    buttonLayout = R.layout.fui_provider_button_phone;
                    break;
                case AuthUI.ANONYMOUS_PROVIDER:
                    buttonLayout = R.layout.fui_provider_button_anonymous;
                    break;
                default:
                    if (!TextUtils.isEmpty(
                            idpConfig.getParams().getString(GENERIC_OAUTH_PROVIDER_ID))) {
                        buttonLayout = idpConfig.getParams().getInt(GENERIC_OAUTH_BUTTON_ID);
                        break;
                    }
                    throw new IllegalStateException("Unknown provider: " + providerId);
            }

            View loginButton = getLayoutInflater().inflate(buttonLayout, mProviderHolder, false);
            handleSignInOperation(idpConfig, loginButton);
            mProviderHolder.addView(loginButton);
        }
    }