Java Code Examples for android.databinding.Observable#OnPropertyChangedCallback

The following examples show how to use android.databinding.Observable#OnPropertyChangedCallback . 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 File: MvvmDialogFragmentTest.java    From android-mvvm with Apache License 2.0 7 votes vote down vote up
@Test
public void testOnPropertyChangedCallbacksAddedToViewModel() {
    final Observable.OnPropertyChangedCallback firstCallback = mock(Observable.OnPropertyChangedCallback.class);
    final Observable.OnPropertyChangedCallback secondCallback = mock(Observable.OnPropertyChangedCallback.class);
    fragment.setViewModel(fragment.createViewModel());

    fragment.addOnPropertyChangedCallback(firstCallback);
    fragment.addOnPropertyChangedCallback(secondCallback);

    verify(fragment.getViewModel()).addOnPropertyChangedCallback(firstCallback);
    verify(fragment.getViewModel()).addOnPropertyChangedCallback(secondCallback);
}
 
Example 2
Source File: MvvmDialogFragmentTest.java    From android-mvvm with Apache License 2.0 6 votes vote down vote up
@Test
public void testRemoveOnPropertyChangedCallbacksOnActivityDestroy() {
    final Observable.OnPropertyChangedCallback firstCallback = mock(Observable.OnPropertyChangedCallback.class);
    final Observable.OnPropertyChangedCallback secondCallback = mock(Observable.OnPropertyChangedCallback.class);
    fragment.setViewModel(fragment.createViewModel());
    fragment.addOnPropertyChangedCallback(firstCallback);
    fragment.addOnPropertyChangedCallback(secondCallback);

    SupportFragmentTestUtil.startFragment(fragment);
    fragment.onDestroy();
    verify(fragment.getViewModel()).removeOnPropertyChangedCallback(firstCallback);
    verify(fragment.getViewModel()).removeOnPropertyChangedCallback(secondCallback);
}
 
Example 3
Source File: BaseMusicFragment.java    From vk_music_android with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    currentAudioCallback = new Observable.OnPropertyChangedCallback() {
        @Override
        public void onPropertyChanged(Observable observable, int i) {
            onCurrentAudioChanged(currentAudio.get());
        }
    };
    currentAlbumArtCallback = new Observable.OnPropertyChangedCallback() {
        @Override
        public void onPropertyChanged(Observable observable, int i) {
            getActivity().runOnUiThread(() -> {
                onCurrentAlbumArtChanged(currentAlbumArt.get());
            });
        }
    };
}
 
Example 4
Source File: ItemRepoViewModelTest.java    From archi with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldNotifyPropertyChangeWhenSetRepository() {
    Repository repository = new Repository();
    ItemRepoViewModel itemRepoViewModel = new ItemRepoViewModel(application, repository);
    Observable.OnPropertyChangedCallback mockCallback =
            mock(Observable.OnPropertyChangedCallback.class);
    itemRepoViewModel.addOnPropertyChangedCallback(mockCallback);

    itemRepoViewModel.setRepository(repository);
    verify(mockCallback).onPropertyChanged(any(Observable.class), anyInt());
}
 
Example 5
Source File: MvvmFragmentTest.java    From android-mvvm with Apache License 2.0 5 votes vote down vote up
@Test
public void testRemoveOnPropertyChangedCallbacksOnActivityDestroy() {
    final Observable.OnPropertyChangedCallback firstCallback = mock(Observable.OnPropertyChangedCallback.class);
    final Observable.OnPropertyChangedCallback secondCallback = mock(Observable.OnPropertyChangedCallback.class);
    fragment.setViewModel(fragment.createViewModel());
    fragment.addOnPropertyChangedCallback(firstCallback);
    fragment.addOnPropertyChangedCallback(secondCallback);

    SupportFragmentTestUtil.startFragment(fragment);
    fragment.onDestroy();
    verify(fragment.getViewModel()).removeOnPropertyChangedCallback(firstCallback);
    verify(fragment.getViewModel()).removeOnPropertyChangedCallback(secondCallback);
}
 
Example 6
Source File: MvvmFragmentTest.java    From android-mvvm with Apache License 2.0 5 votes vote down vote up
@Test
public void testOnPropertyChangedCallbacksAddedToViewModel() {
    final Observable.OnPropertyChangedCallback firstCallback = mock(Observable.OnPropertyChangedCallback.class);
    final Observable.OnPropertyChangedCallback secondCallback = mock(Observable.OnPropertyChangedCallback.class);
    fragment.setViewModel(fragment.createViewModel());

    fragment.addOnPropertyChangedCallback(firstCallback);
    fragment.addOnPropertyChangedCallback(secondCallback);

    verify(fragment.getViewModel()).addOnPropertyChangedCallback(firstCallback);
    verify(fragment.getViewModel()).addOnPropertyChangedCallback(secondCallback);
}
 
Example 7
Source File: MvvmActivityTest.java    From android-mvvm with Apache License 2.0 5 votes vote down vote up
@Test
public void testRemoveOnPropertyChangedCallbacksOnActivityDestroy() {
    final Observable.OnPropertyChangedCallback firstCallback = mock(Observable.OnPropertyChangedCallback.class);
    final Observable.OnPropertyChangedCallback secondCallback = mock(Observable.OnPropertyChangedCallback.class);
    activityController.create();
    activity.setViewModel(activity.createViewModel());
    activity.addOnPropertyChangedCallback(firstCallback);
    activity.addOnPropertyChangedCallback(secondCallback);

    activity.onDestroy();
    verify(activity.getViewModel()).removeOnPropertyChangedCallback(firstCallback);
    verify(activity.getViewModel()).removeOnPropertyChangedCallback(secondCallback);
}
 
Example 8
Source File: MvvmActivityTest.java    From android-mvvm with Apache License 2.0 5 votes vote down vote up
@Test
public void testOnPropertyChangedCallbacksAddedToViewModel() {
    final Observable.OnPropertyChangedCallback firstCallback = mock(Observable.OnPropertyChangedCallback.class);
    final Observable.OnPropertyChangedCallback secondCallback = mock(Observable.OnPropertyChangedCallback.class);
    activityController.create();
    activity.setViewModel(activity.createViewModel());

    activity.addOnPropertyChangedCallback(firstCallback);
    activity.addOnPropertyChangedCallback(secondCallback);

    verify(activity.getViewModel()).addOnPropertyChangedCallback(firstCallback);
    verify(activity.getViewModel()).addOnPropertyChangedCallback(secondCallback);
}
 
Example 9
Source File: MvvmActivity.java    From android-mvvm with Apache License 2.0 4 votes vote down vote up
private void removeOnPropertyChangedCallbacks() {
    for (Observable.OnPropertyChangedCallback callback : onPropertyChangedCallbacks) {
        getViewModel().removeOnPropertyChangedCallback(callback);
    }
}
 
Example 10
Source File: MvvmDialogFragment.java    From android-mvvm with Apache License 2.0 4 votes vote down vote up
private void removeOnPropertyChangedCallbacks() {
    for (Observable.OnPropertyChangedCallback callback : onPropertyChangedCallbacks) {
        getViewModel().removeOnPropertyChangedCallback(callback);
    }
}
 
Example 11
Source File: DocumentView.java    From spline with Apache License 2.0 4 votes vote down vote up
public void init(Context context) {
    DisplayMetrics metrics = context.getResources().getDisplayMetrics();
    mDensity = metrics.density;

    ViewConfiguration vc = ViewConfiguration.get(context);
    mTouchSlop = vc.getScaledTouchSlop();
    mLongPressTimeout = vc.getLongPressTimeout();

    mScroller = new OverScroller(context);

    mTouchRadius = TOUCH_RADIUS_DP * mDensity;
    mEditCtrlStrokeWidth = EDIT_CTRL_STROKE_DP * mDensity;
    mEditColor = getResources().getColor(R.color.colorAccent, context.getTheme());

    mOnListChangedCallback = new ObservableList
            .OnListChangedCallback<ObservableList<Layer>>() {
        @Override
        public void onChanged(ObservableList<Layer> layers) {
            invalidate();
        }

        @Override
        public void onItemRangeChanged(ObservableList<Layer> layers, int i, int i1) {
            invalidate();
        }

        @Override
        public void onItemRangeInserted(ObservableList<Layer> layers, int start, int count) {
            invalidate();
            addPropertyChangedCallbacks(layers, start, start + count);
        }

        @Override
        public void onItemRangeMoved(ObservableList<Layer> layers, int i, int i1, int i2) {
            invalidate();
        }

        @Override
        public void onItemRangeRemoved(ObservableList<Layer> layers, int i, int i1) {
            invalidate();
        }
    };

    mOnPropertyChangedCallback = new Observable.OnPropertyChangedCallback() {
        @Override
        public void onPropertyChanged(Observable observable, int i) {
            invalidate();
        }
    };
}
 
Example 12
Source File: MvvmFragment.java    From android-mvvm with Apache License 2.0 4 votes vote down vote up
private void removeOnPropertyChangedCallbacks() {
    for (Observable.OnPropertyChangedCallback callback : onPropertyChangedCallbacks) {
        getViewModel().removeOnPropertyChangedCallback(callback);
    }
}
 
Example 13
Source File: ViewModel.java    From demo4Fish with MIT License 4 votes vote down vote up
protected void addObservableBinding(Observable observable, Observable.OnPropertyChangedCallback callback) {
    IBinding binding = ObservableBindingUtil.bind(observable, callback);
    mObservableBindingList.add(binding);
}
 
Example 14
Source File: PropertyBinding.java    From demo4Fish with MIT License 4 votes vote down vote up
public PropertyBinding(Observable observable, Observable.OnPropertyChangedCallback callback) {
    mObservable = observable;
    mCallback = callback;
}
 
Example 15
Source File: ObservableBindingUtil.java    From demo4Fish with MIT License 4 votes vote down vote up
public static IBinding bind(Observable observable, Observable.OnPropertyChangedCallback callback) {
    IBinding binding = new PropertyBinding(observable, callback);
    binding.bind();

    return binding;
}
 
Example 16
Source File: MainViewModel.java    From demo4Fish with MIT License 4 votes vote down vote up
@Override
public void addCurrentIndexChangedCallback(Observable.OnPropertyChangedCallback callback) {
    addObservableBinding(mCurrentIndex, callback);
}
 
Example 17
Source File: MvvmActivity.java    From android-mvvm with Apache License 2.0 2 votes vote down vote up
/**
 * Add an Observable.OnPropertyChangedCallback to ViewModel that will be removed on View destroy
 * <p>
 * Use this method to add Observable.OnPropertyChangedCallback to ViewModel. All callbacks will be removed on
 * View destroy. It helps avoid memory leaks via callbacks.
 *
 * @param callback the callback to start listening
 */
protected void addOnPropertyChangedCallback(Observable.OnPropertyChangedCallback callback) {
    onPropertyChangedCallbacks.add(callback);
    getViewModel().addOnPropertyChangedCallback(callback);
}
 
Example 18
Source File: MvvmDialogFragment.java    From android-mvvm with Apache License 2.0 2 votes vote down vote up
/**
 * Add an Observable.OnPropertyChangedCallback to ViewModel that will be removed on View destroy
 * <p>
 * Use this method to add Observable.OnPropertyChangedCallback to ViewModel. All callbacks will be removed on
 * View destroy. It helps avoid memory leaks via callbacks.
 *
 * @param callback the callback to start listening
 */
protected void addOnPropertyChangedCallback(Observable.OnPropertyChangedCallback callback) {
    onPropertyChangedCallbacks.add(callback);
    getViewModel().addOnPropertyChangedCallback(callback);
}
 
Example 19
Source File: IHomeViewModel.java    From demo4Fish with MIT License 2 votes vote down vote up
/**
 * 监听HomeFragment的数据
 *
 * @param callback
 */
void addHomeEntityChangedCallback(Observable.OnPropertyChangedCallback callback);
 
Example 20
Source File: IMainViewModel.java    From demo4Fish with MIT License votes vote down vote up
void addCurrentIndexChangedCallback(Observable.OnPropertyChangedCallback callback);