androidx.lifecycle.LifecycleRegistry Java Examples

The following examples show how to use androidx.lifecycle.LifecycleRegistry. 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: Gander   Author: Ashok-Varma   File: TransactionArchComponentLiveDataTest.java    License: Apache License 2.0 6 votes vote down vote up
@Before
public void setUp() {
    MockitoAnnotations.initMocks(this);
    doAnswer(new Answer() {
        @Override
        public Object answer(InvocationOnMock invocation) throws Throwable {
            return dataChangeListener = invocation.getArgument(0);
        }
    }).when(transactionDataStore).addDataChangeListener(any(TransactionDataStore.DataChangeListener.class));


    httpTransactionWithId1 = getHttpTransactionWithIndex(1);
    when(transactionDataStore.getTransactionWithId(1)).thenReturn(httpTransactionWithId1);

    httpTransactionLiveData = new TransactionArchComponentProvider().getLiveData(transactionDataStore, 1);
    LifecycleOwner lifecycleOwner = mock(LifecycleOwner.class);
    lifecycleRegistry = new LifecycleRegistry(lifecycleOwner);
    when(lifecycleOwner.getLifecycle()).thenReturn(lifecycleRegistry);
    httpTransactionLiveData.observe(lifecycleOwner, testObserver);
}
 
Example #2
Source Project: android_9.0.0_r45   Author: lulululbj   File: NoPackageTest.java    License: Apache License 2.0 5 votes vote down vote up
@Before
public void init() {
    mLifecycleOwner = mock(LifecycleOwner.class);
    mLifecycle = mock(Lifecycle.class);
    when(mLifecycleOwner.getLifecycle()).thenReturn(mLifecycle);
    mRegistry = new LifecycleRegistry(mLifecycleOwner);
}
 
Example #3
Source Project: FairEmail   Author: M66B   File: TwoStateOwner.java    License: GNU General Public License v3.0 5 votes vote down vote up
private void create() {
    // Initialize
    registry = new LifecycleRegistry(this);
    registry.addObserver(new LifecycleObserver() {
        @OnLifecycleEvent(Lifecycle.Event.ON_ANY)
        public void onAny() {
            Log.d("LifeCycle " + name + " state=" + registry.getCurrentState() + " " + registry);
        }
    });

    setState(Lifecycle.State.CREATED);
}
 
Example #4
Source Project: FirefoxReality   Author: MozillaReality   File: DataRepository.java    License: Mozilla Public License 2.0 5 votes vote down vote up
private DataRepository(final @NonNull AppDatabase database, final @NonNull AppExecutors executors) {
    mDatabase = database;
    mExecutors = executors;
    mLifeCycle = new LifecycleRegistry(this);
    mLifeCycle.setCurrentState(Lifecycle.State.STARTED);
    mObservablePopUps = new MediatorLiveData<>();

    mObservablePopUps.addSource(mDatabase.sitePermissionDao().loadAll(),
            sites -> {
                if (mDatabase.getDatabaseCreated().getValue() != null) {
                    mObservablePopUps.postValue(sites);
                }
            });
}
 
Example #5
Source Project: mollyim-android   Author: mollyim   File: LifecycleViewHolder.java    License: GNU General Public License v3.0 4 votes vote down vote up
public LifecycleViewHolder(@NonNull View itemView) {
  super(itemView);

  lifecycleRegistry = new LifecycleRegistry(this);
}
 
Example #6
Source Project: android_9.0.0_r45   Author: lulululbj   File: FrameworkLifecycleRegistryActivity.java    License: Apache License 2.0 4 votes vote down vote up
@NonNull
@Override
public LifecycleRegistry getLifecycle() {
    return mLifecycleRegistry;
}
 
Example #7
Source Project: Android-Keyboard   Author: NlptechProduct   File: KeyboardWidget.java    License: Apache License 2.0 4 votes vote down vote up
public void onCreate(@Nullable Intent intent) {
    mLifecycleRegistry = new LifecycleRegistry(this);
    mLifecycleRegistry.handleLifecycleEvent(Lifecycle.Event.ON_CREATE);
}
 
Example #8
Source Project: mobius   Author: spotify   File: FakeLifecycleOwner.java    License: Apache License 2.0 4 votes vote down vote up
FakeLifecycleOwner() {
  owner = mock(LifecycleOwner.class);
  lifecycle = new LifecycleRegistry(owner);
  Mockito.when(owner.getLifecycle()).thenReturn(lifecycle);
}
 
Example #9
Source Project: FirefoxReality   Author: MozillaReality   File: VRBrowserActivity.java    License: Mozilla Public License 2.0 4 votes vote down vote up
public VRBrowserActivity() {
    mLifeCycle = new LifecycleRegistry(this);
    mLifeCycle.setCurrentState(Lifecycle.State.INITIALIZED);

    mViewModelStore = new ViewModelStore();
}
 
Example #10
Source Project: SugarAdapter   Author: zhihu   File: SugarHolder.java    License: Apache License 2.0 4 votes vote down vote up
@NonNull
final LifecycleRegistry getLifecycleRegistry() {
    return mLifecycleRegistry;
}
 
Example #11
Source Project: firefox-echo-show   Author: mozilla-mobile   File: SessionTest.java    License: Mozilla Public License 2.0 3 votes vote down vote up
private LifecycleOwner mockLifecycleOwner() {
    final LifecycleOwner lifecycleOwner = mock(LifecycleOwner.class);

    LifecycleRegistry registry = new LifecycleRegistry(lifecycleOwner);
    registry.handleLifecycleEvent(Lifecycle.Event.ON_RESUME);

    doReturn(registry).when(lifecycleOwner).getLifecycle();

    return lifecycleOwner;
}