public SSLessonsViewModel(Context context, DataListener dataListener, String ssQuarterlyIndex) { this.context = context; this.dataListener = dataListener; this.ssQuarterlyIndex = ssQuarterlyIndex; mDatabase = FirebaseDatabase.getInstance().getReference(); mDatabase.keepSynced(true); ssLessonsLoadingVisibility = new ObservableInt(View.INVISIBLE); ssLessonsEmptyStateVisibility = new ObservableInt(View.INVISIBLE); ssLessonsErrorStateVisibility = new ObservableInt(View.INVISIBLE); ssLessonsCoordinatorVisibility = new ObservableInt(View.INVISIBLE); shared = PreferenceManager.getDefaultSharedPreferences(context); loadQuarterlyInfo(); }
@Test public void takeTakesCorrectTimes() throws Exception { int int1 = 123; int int2 = 32; ObservableInt observed = new ObservableInt(int1); ObservableInt observing = Cinder.computeInt(()-> observed.get() , observed).take(2).immediate(); assertTrue(observing.get() == int1); observed.set(int2); assertTrue(observing.get() == int2); observed.set(int1); assertTrue(observing.get() == int2); }
@Test public void skipSkipsCorrectTimes() throws Exception { int int1 = 123; int int2 = 32; ObservableInt observed = new ObservableInt(); ObservableInt observing = Cinder.computeInt(()-> observed.get() , observed).skip(1); observed.set(int1); assertTrue(observing.get() == 0); observed.set(int2); assertTrue(observing.get() == int2); observed.set(int1); assertTrue(observing.get() == int1); }
public RepositoryViewModel(Context context, final Repository repository) { this.repository = repository; this.context = context; this.ownerName = new ObservableField<>(); this.ownerEmail = new ObservableField<>(); this.ownerLocation = new ObservableField<>(); this.ownerLayoutVisibility = new ObservableInt(View.INVISIBLE); this.ownerEmailVisibility = new ObservableInt(View.VISIBLE); this.ownerLocationVisibility = new ObservableInt(View.VISIBLE); // Trigger loading the rest of the user data as soon as the view model is created. // It's odd having to trigger this from here. Cases where accessing to the data model // needs to happen because of a change in the Activity/Fragment lifecycle // (i.e. an activity created) don't work very well with this MVVM pattern. // It also makes this class more difficult to test. Hopefully a better solution will be found loadFullUser(repository.owner.url); }
public BaseLibraryActivityViewModel(Context context, boolean fitSystemWindows) { super(context); mFitSystemWindows = fitSystemWindows; mExpandedHeight = getDimensionPixelSize(R.dimen.miniplayer_height); mAnimateSlideInOut = false; mMiniplayerHeight = new ObservableInt(0); mMiniplayerAlpha = new ObservableFloat(1.0f); mNowPlayingToolbarAlpha = new ObservableFloat(0.0f); int backgroundColor = getColor(R.color.background); mNowPlayingBackground = new ColorDrawable(backgroundColor); setPlaybackOngoing(false); }
@Inject public SignInViewModel(@SuppressWarnings("UnusedParameters") EventBus eventBus) { displayedChild = new ObservableInt(0); onNavigationItemSelectedListener = new BottomNavigationView.OnNavigationItemSelectedListener() { @Override public boolean onNavigationItemSelected(@NonNull MenuItem item) { displayedChild.set(item.getItemId() == R.id.tab_signin ? 0 : 1); return true; } }; }
Listener(final ObservableInt observableInt, final Observer<? super Integer> observer) { this.observableInt = observableInt; this.onPropertyChangedCallback = new android.databinding.Observable.OnPropertyChangedCallback() { @Override public void onPropertyChanged(android.databinding.Observable observable, int ignoredPropertyId) { if (!isDisposed()) { ObservableInt observableInt = (ObservableInt) observable; observer.onNext(observableInt.get()); } } }; }
public FollowersInfoViewModel(@NonNull DataListener dataListener, @NonNull Context context, Session session, User user) { this.dataListener = dataListener; this.context = context; this.session = session; this.user = user; activityFollowersInfoRecyclerView = new ObservableInt(View.GONE); initializeViews(); fetchTweetsList(); }
public FollowersViewModel(@NonNull DataListener dataListener, @NonNull Context context, TwitterSession session, Long userId) { this.dataListener = dataListener; this.context = context; this.session = session; this.userId = userId; activityFollowerProgressBar = new ObservableInt(View.VISIBLE); activityFollowerSwipeRefreshLayout = new ObservableInt(View.GONE); activityFollowerRecyclerView = new ObservableInt(View.GONE); activityFollowerIsPullToRefresh = new ObservableBoolean(false); initializeViews(); fetchFollowersList(false, false, cursor); }
public SSLoginViewModel(Context context) { this.context = context; this.ssLoginLoadingVisibility = new ObservableInt(View.INVISIBLE); this.ssLoginControlsVisibility = new ObservableInt(View.VISIBLE); this.configureGoogleLogin(); this.configureFacebookLogin(); this.configureFirebase(); }
public SSQuarterliesViewModel(Context context, final DataListener dataListener, SsQuarterliesActivityBinding ssQuarterliesActivityBinding) { this.context = context; this.dataListener = dataListener; this.ssQuarterliesActivityBinding = ssQuarterliesActivityBinding; ssQuarterliesLoadingVisibility = new ObservableInt(View.INVISIBLE); ssQuarterliesListVisibility = new ObservableInt(View.INVISIBLE); ssQuarterliesLanguageFilterVisibility = new ObservableInt(View.GONE); ssQuarterliesErrorMessageVisibility = new ObservableInt(View.INVISIBLE); ssQuarterliesEmptyStateVisibility = new ObservableInt(View.INVISIBLE); ssQuarterliesErrorStateVisibility = new ObservableInt(View.INVISIBLE); ssQuarterliesListMarginTop = new ObservableFloat(0); ssFirebaseDatabase = FirebaseDatabase.getInstance().getReference(); ssFirebaseDatabase.keepSynced(true); this.ssQuarterlyLanguages = new ArrayList<>(); this.ssQuarterlies = new ArrayList<>(); SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); String ssLastLanguageSelected = prefs.getString(SSConstants.SS_LAST_LANGUAGE_INDEX, ""); ssDefaultLanguage = Locale.getDefault().getLanguage(); if (!ssLastLanguageSelected.isEmpty()){ ssDefaultLanguage = ssLastLanguageSelected; } ssQuarterlyLanguage = new SSQuarterlyLanguage(ssDefaultLanguage, getDisplayLanguageByCode(ssDefaultLanguage), 1); loadLanguages(); }
/** * Default constructor. * @param context The context of the current activity. */ public ExplorerViewModel(Context context) { this.context = context; this.isLoading = new ObservableBoolean(false); this.isRefreshing = new ObservableBoolean(false); this.files = new ObservableArrayList<FileViewModel>(); this.isSelectionMode = new ObservableBoolean(false); this.numberSelectedItems = new ObservableInt(0); this.changeDirectory("/"); }
public BrowseThingViewModel(Context context, LoaderManager loaderManager, DataListener<T> dataListener) { this.context = context; this.loaderManager = loaderManager; this.dataListener = dataListener; infoMessageVisibility = new ObservableInt(View.VISIBLE); progressVisibility = new ObservableInt(View.INVISIBLE); recyclerViewVisibility = new ObservableInt(View.INVISIBLE); searchButtonVisibility = new ObservableInt(View.GONE); infoMessage = getInfoObservableField(context); }
@Test public void computesArrayList() throws Exception { final int NUMBER_1 = 23; final int NUMBER_2 = 56; final ObservableInt number = new ObservableInt(NUMBER_1); final ObservableArrayList<Integer> ints = Cinder.<Integer>computeArrayList((list)->list.add(number.get()), number).immediate(); assertEquals(ints.get(0).longValue(), NUMBER_1); number.set(NUMBER_2); assertEquals(ints.get(1).longValue(), NUMBER_2); }
@Test public void computesInt() throws Exception { int int1 = 4321; int int2 = 23; ObservableInt obsInt = new ObservableInt(int1); ObservableInt computedInt = Cinder.computeInt(()->obsInt.get(), obsInt).immediate(); assertEquals(computedInt.get(), int1); obsInt.set(int2); assertEquals(computedInt.get(), int2); }
@Test public void computableMapsAreComputable() throws Exception { String key1 = "KEY 1"; String key2 = "KEY 2"; String value1 = "VALUE 1"; String value2 = "VALUE 2"; ObservableArrayMap<String, String> strings = new ObservableArrayMap<>(); strings.put(key1, value1); ObservableInt computedCount = Cinder.computeInt(()->strings.size(), Cinder.observable(strings)).immediate(); assertEquals(computedCount.get(), 1); strings.put(key2, value2); assertEquals(computedCount.get(), 2); }
@Test public void observesObservables() throws Exception { int int1 = 4321; int int2 = 23; ObservableInt observedInt = new ObservableInt(); ObservableInt observingInt = new ObservableInt(); Cinder.observe(()->observingInt.set(observedInt.get()), observedInt); observedInt.set(int1); assertEquals(observingInt.get(), int1); observedInt.set(int2); assertEquals(observingInt.get(), int2); }
@Test public void onceTakesOnce() throws Exception { int int1 = 123; int int2 = 43; ObservableInt observed = new ObservableInt(int1); ObservableInt observing = Cinder.computeInt(()-> observed.get(), observed).once().immediate(); assertTrue(observing.get() == int1); observed.set(int2); assertTrue(observing.get() == int1); }
@Test public void filterFilters() throws Exception { int int1 = 123; int int2 = 32; ObservableInt observed = new ObservableInt(); ObservableInt observing = Cinder.computeInt(()-> observed.get() , observed).filter(()->observed.get() == int1); observed.set(int2); assertTrue(observing.get() == 0); observed.set(int1); assertTrue(observing.get() == int1); }
@Test public void takeWhileTakesWhileTrue() throws Exception { int int1 = 123; int int2 = 32; ObservableInt observed = new ObservableInt(); ObservableInt observing = Cinder.computeInt(()-> observed.get() , observed).takeWhile(()->observed.get() == int1); observed.set(int1); assertTrue(observing.get() == int1); observed.set(int2); assertTrue(observing.get() == int1); }
@Test public void skipWhileSkipsWhileTrue() throws Exception { int int1 = 123; int int2 = 32; ObservableInt observed = new ObservableInt(); ObservableInt observing = Cinder.computeInt(()-> observed.get() , observed).skipWhile(()->observed.get() == int1); observed.set(int1); assertTrue(observing.get() == 0); observed.set(int2); assertTrue(observing.get() == int2); }
@Test public void withDefaultAssignsDefault() throws Exception { int int1 = 12; ObservableInt observing = Cinder.computeInt(()->0 ).withDefault(int1); assertTrue(observing.get() == int1); }
@Test public void stopStops() throws Exception { int int1 = 123; int int2 = 43; ObservableInt observed = new ObservableInt(int1); CinderInt observing = Cinder.computeInt(()-> observed.get(), observed).immediate(); assertTrue(observing.get() == int1); observing.stop(); observed.set(int2); assertTrue(observing.get() == int1); }
@Test public void convertsObservableIntToRx() throws Exception { ObservableInt observableInt = new ObservableInt(); Observable<Integer> rxInt = RxCinder.convert(observableInt); final String TEST_KEY = "TEST_KEY"; final ArrayMap<String, Integer> testMap = new ArrayMap<>(); rxInt.subscribe((c)->{ testMap.put(TEST_KEY, c);}); final int TEST_INT = 23; observableInt.set(TEST_INT); assertTrue(testMap.get(TEST_KEY).equals(TEST_INT)); }
@Test public void convertsRxIntToObservable() throws Exception { int TEST_INT = 234; Observable<Integer> rxInt = Observable.just(TEST_INT); ObservableInt observableInt = RxCinder.convertInt(rxInt); assertTrue(observableInt.get() == TEST_INT); }
PasswordItemViewModel(Navigator navigator, int id, String icon, String name, String username) { this.navigator = navigator; this.id = new ObservableInt(id); this.icon = new ObservableField<>(icon); this.name = new ObservableField<>(name); this.userName = new ObservableField<>(username); }
public MainViewModel(){ getRepos(); loading = new ObservableInt(View.VISIBLE); progressBarVisible = new ObservableInt(View.VISIBLE); retryBtnVisible = new ObservableInt(View.INVISIBLE); message = new ObservableField<>("loading..."); }
public MainViewModel(@NonNull DataListener dataListener, @NonNull List<String> keyStore , @NonNull DeleteFeedUseCaseFactory deleteFeedUseCaseFactory , @NonNull FeedChangedUseCase feedChangedUseCase , @NonNull FeedModelMapper mapper, List<FeedModel> model) { this.mDataListener = dataListener; this.mKeyStore = keyStore; this.mDeleteFeedUseCaseFactory = deleteFeedUseCaseFactory; this.mMapper = mapper; this.mFeedChangedUseCase = feedChangedUseCase; mRecyclerViewVisibility = new ObservableInt(View.INVISIBLE); this.mFeeds = model; }
public MainViewModel(Context context, DataListener dataListener) { this.context = context; this.dataListener = dataListener; infoMessageVisibility = new ObservableInt(View.VISIBLE); progressVisibility = new ObservableInt(View.INVISIBLE); recyclerViewVisibility = new ObservableInt(View.INVISIBLE); searchButtonVisibility = new ObservableInt(View.GONE); infoMessage = new ObservableField<>(context.getString(R.string.default_info_message)); }
protected NoteModel(Parcel in) { noteId = in.readString(); title = in.readParcelable(ObservableString.class.getClassLoader()); text = in.readParcelable(ObservableString.class.getClassLoader()); titleError = in.readParcelable(ObservableInt.class.getClassLoader()); textError = in.readParcelable(ObservableInt.class.getClassLoader()); }
public NowPlayingControllerViewModel(Context context, FragmentManager fragmentManager, PlayerController playerController, MusicStore musicStore, ThemeStore themeStore) { super(context); mFragmentManager = fragmentManager; mPlayerController = playerController; mMusicStore = musicStore; mThemeStore = themeStore; mCurrentPositionObservable = new ObservableInt(); mSeekbarPosition = new ObservableInt(); }
public MiniplayerViewModel(Context context, PlayerController playerController) { super(context); mPlayerController = playerController; mArtwork = new ObservableField<>(); mProgress = new ObservableInt(); mDuration = new ObservableInt(); setSong(null); }
public void setAlbum(Album album) { mAlbum = album; mArtistImage = new ObservableField<>(); mTitleTextColor = new ObservableInt(); mArtistTextColor = new ObservableInt(); mBackgroundColor = new ObservableInt(); defaultColors(); if (mAlbum.getArtUri() != null) { int imageSize = mContext.getResources().getDimensionPixelSize(R.dimen.grid_width); Glide.with(mContext) .load(new File(mAlbum.getArtUri())) .placeholder(R.drawable.art_default) .error(R.drawable.art_default) .listener(new PaletteListener(mTitleTextColor, mArtistTextColor, mBackgroundColor)) .into(new ObservableTarget(imageSize, mArtistImage)); } else { Drawable fallback = ResourcesCompat.getDrawable(mContext.getResources(), R.drawable.art_default, mContext.getTheme()); mArtistImage.set(fallback); } notifyChange(); }
private static void defaultColors(Context context, ObservableInt title, ObservableInt artist, ObservableInt background) { Resources res = context.getResources(); Resources.Theme theme = context.getTheme(); title.set(ResourcesCompat.getColor(res, R.color.grid_text, theme)); artist.set(ResourcesCompat.getColor(res, R.color.grid_detail_text, theme)); background.set(ResourcesCompat.getColor(res, R.color.grid_background_default, theme)); }
public ObservableInt getName() { return name; }
public void setName(ObservableInt name) { this.name = name; }
@Inject public RegistrationViewModel(final Zerokit zerokit, AdminApi adminApi, final EventBus eventBus, SharedPreferences sharedPreferences, final Resources resources) { this.zerokit = zerokit; this.adminApi = adminApi; this.eventBus = eventBus; this.sharedPreferences = sharedPreferences; inProgress = new ObservableField<>(false); userName = new ObservableField<>(""); passwordError = new ObservableField<>(""); passwordConfirmError = new ObservableField<>(""); userNameError = new ObservableField<>(""); passwordStrength = new ObservableInt(); seekbarColor = new ObservableField<>(resources.getDrawable(R.drawable.progress)); colorRes = new int[]{R.color.red, R.color.deep_orange, R.color.orange, R.color.light_green, R.color.green}; clickListenerRegistration = new View.OnClickListener() { @Override public void onClick(View view) { attemptRegistration(); } }; errorResponseHandlerAdmin = new Action<ResponseAdminApiError>() { @Override public void call(ResponseAdminApiError responseAdminApiError) { inProgress.set(false); eventBus.post(new ShowMessageMessage(responseAdminApiError.getMessage())); } }; errorResponseHandlerSdk = new Action<ResponseZerokitError>() { @Override public void call(ResponseZerokitError errorResponse) { inProgress.set(false); eventBus.post(new ShowMessageMessage(errorResponse.getDescription())); } }; focusChangeListener = new View.OnFocusChangeListener() { @Override public void onFocusChange(View v, boolean hasFocus) { passwordError.set(""); userNameError.set(""); passwordConfirmError.set(""); } }; passwordExporter = new PasswordEditText.PasswordExporter(); passwordExporterConfirm = new PasswordEditText.PasswordExporter(); passwordExporter.setOnChangeListener(new PasswordEditText.OnChangeListener() { @Override public void onChanged() { zerokit.getPasswordStrength(passwordExporter).enqueue(new Action<ResponseZerokitPasswordStrength>() { @Override public void call(ResponseZerokitPasswordStrength responseZerokitPasswordStrength) { int score = responseZerokitPasswordStrength.getScore(); passwordStrength.set((score + 1) * 20); ((LayerDrawable) seekbarColor.get()).findDrawableByLayerId(android.R.id.progress).setColorFilter(resources.getColor(colorRes[score]), PorterDuff.Mode.SRC_IN); } }); } }); }
ObservableIntObservable(ObservableInt observableInt) { this.observableInt = observableInt; }