androidx.lifecycle.ViewModelProviders Java Examples

The following examples show how to use androidx.lifecycle.ViewModelProviders. 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: PlaceAutocompleteFragment.java    From mapbox-plugins-android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
@Override
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
  super.onActivityCreated(savedInstanceState);

  // View model
  PlaceAutocompleteViewModel.Factory factory = new PlaceAutocompleteViewModel.Factory(
    getActivity().getApplication(), placeOptions
  );
  viewModel = ViewModelProviders.of(this, factory).get(PlaceAutocompleteViewModel.class);
  if (accessToken != null) {
    viewModel.buildGeocodingRequest(accessToken);
  }

  updateFavoritePlacesView();
  subscribe();
}
 
Example #2
Source File: ConversationActivity.java    From mollyim-android with GNU General Public License v3.0 6 votes vote down vote up
private void initializeLinkPreviewObserver() {
  linkPreviewViewModel = ViewModelProviders.of(this, new LinkPreviewViewModel.Factory(new LinkPreviewRepository())).get(LinkPreviewViewModel.class);

  if (!TextSecurePreferences.isLinkPreviewsEnabled(this)) {
    linkPreviewViewModel.onUserCancel();
    return;
  }

  linkPreviewViewModel.getLinkPreviewState().observe(this, previewState -> {
    if (previewState == null) return;

    if (previewState.isLoading()) {
      Log.d(TAG, "Loading link preview.");
      inputPanel.setLinkPreviewLoading();
    } else {
      Log.d(TAG, "Setting link preview: " + previewState.getLinkPreview().isPresent());
      inputPanel.setLinkPreview(glideRequests, previewState.getLinkPreview());
    }

    updateToggleButtonState();
  });
}
 
Example #3
Source File: PhotoActivity.java    From Mysplash with GNU Lesser General Public License v3.0 6 votes vote down vote up
private void initModel() {
    Photo photo = getIntent().getParcelableExtra(KEY_PHOTO_ACTIVITY_PHOTO);
    int currentIndex = getIntent().getIntExtra(KEY_PHOTO_ACTIVITY_CURRENT_INDEX, -1);
    String photoId = getIntent().getStringExtra(KEY_PHOTO_ACTIVITY_ID);
    List<Photo> photoList = MysplashApplication.getInstance().loadMorePhotos(this, 0);
    if (photoList == null) {
        photoList = new ArrayList<>();
    }

    activityModel = ViewModelProviders.of(this, viewModelFactory).get(PhotoActivityModel.class);
    if (photoList.size() != 0) {
        if (currentIndex < 0 || currentIndex >= photoList.size()) {
            currentIndex = 0;
        }
        activityModel.init(photoList, currentIndex);
    } else if (photo != null) {
        activityModel.init(photo);
    } else if (!TextUtils.isEmpty(photoId)) {
        activityModel.init(photoId);
    } else {
        activityModel.init("0TFBD0R75n4");
    }
}
 
Example #4
Source File: SearchActivity.java    From Mysplash with GNU Lesser General Public License v3.0 6 votes vote down vote up
private void initModel() {
    String query = getIntent().getStringExtra(KEY_SEARCH_ACTIVITY_QUERY);
    if (query == null) {
        query = "";
    }

    activityModel = ViewModelProviders.of(this, viewModelFactory).get(SearchActivityModel.class);
    activityModel.init(photoPage(), query);

    pagerModels[photoPage()] = ViewModelProviders.of(this, viewModelFactory).get(
            PhotoSearchPageViewModel.class);
    ((PhotoSearchPageViewModel) pagerModels[photoPage()]).init(
            ListResource.error(0, ListPager.DEFAULT_PER_PAGE), query);

    pagerModels[collectionPage()] = ViewModelProviders.of(this, viewModelFactory).get(
            CollectionSearchPageViewModel.class);
    ((CollectionSearchPageViewModel) pagerModels[collectionPage()]).init(
            ListResource.error(0, ListPager.DEFAULT_PER_PAGE), query);

    pagerModels[userPage()] = ViewModelProviders.of(this, viewModelFactory).get(
            UserSearchPageViewModel.class);
    ((UserSearchPageViewModel) pagerModels[userPage()]).init(
            ListResource.error(0, ListPager.DEFAULT_PER_PAGE), query);
}
 
Example #5
Source File: SecondFragment.java    From ui with Apache License 2.0 6 votes vote down vote up
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {
    // Inflate the layout for this fragment
    View myView = inflater.inflate(R.layout.fragment_second, container, false);

    mViewModel = ViewModelProviders.of(getActivity()).get(DataViewModel.class);


    tv1 = myView.findViewById(R.id.sf_tv1);
    tv2 = myView.findViewById(R.id.sf_tv2);
    btn1 = myView.findViewById(R.id.sf_btn1);
    btn1.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            //this is calling the interface, which call into the activity, so it
            mViewModel.num_one++;
            mViewModel.setItem("Called by SecondFragment");
            Navigation.findNavController(v).navigate(R.id.action_second_to_first);
        }
    });
    tv1.setText("Parameter1: " +mViewModel.num_two);
    tv2.setText("Parameter1: " +mViewModel.getItem());
    return myView;
}
 
Example #6
Source File: EpisodeHistoryFragment.java    From cathode with Apache License 2.0 6 votes vote down vote up
@Override public void onCreate(@Nullable Bundle inState) {
  super.onCreate(inState);
  Bundle args = getArguments();
  episodeId = args.getLong(ARG_EPISODEID);
  showTitle = args.getString(ARG_SHOW_TITLE);
  setTitle(showTitle);

  viewModel = ViewModelProviders.of(this, viewModelFactory).get(EpisodeHistoryViewModel.class);
  viewModel.setEpisodeId(episodeId);
  viewModel.getEpisode().observe(this, new Observer<Episode>() {
    @Override public void onChanged(Episode episode) {
      setEpisode(episode);
    }
  });
  viewModel.getHistory().observe(this, new Observer<EpisodeHistoryLiveData.Result>() {
    @Override public void onChanged(EpisodeHistoryLiveData.Result result) {
      setResult(result);
      setRefreshing(false);
    }
  });
}
 
Example #7
Source File: PendingMemberInvitesFragment.java    From mollyim-android with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
  super.onActivityCreated(savedInstanceState);

  GroupId.V2 groupId = GroupId.parseOrThrow(Objects.requireNonNull(requireArguments().getString(GROUP_ID))).requireV2();

  PendingMemberInvitesViewModel.Factory factory = new PendingMemberInvitesViewModel.Factory(requireContext(), groupId);

  viewModel = ViewModelProviders.of(requireActivity(), factory).get(PendingMemberInvitesViewModel.class);

  viewModel.getWhoYouInvited().observe(getViewLifecycleOwner(), invitees -> {
    youInvited.setMembers(invitees);
    youInvitedEmptyState.setVisibility(invitees.isEmpty() ? View.VISIBLE : View.GONE);
  });

  viewModel.getWhoOthersInvited().observe(getViewLifecycleOwner(), invitees -> {
    othersInvited.setMembers(invitees);
    othersInvitedEmptyState.setVisibility(invitees.isEmpty() ? View.VISIBLE : View.GONE);
  });
}
 
Example #8
Source File: StickerKeyboardProvider.java    From mollyim-android with GNU General Public License v3.0 6 votes vote down vote up
private void initViewModel(@NonNull FragmentActivity activity) {
  StickerKeyboardRepository repository = new StickerKeyboardRepository(DatabaseFactory.getStickerDatabase(activity));
  viewModel = ViewModelProviders.of(activity, new StickerKeyboardViewModel.Factory(activity.getApplication(), repository)).get(StickerKeyboardViewModel.class);

  viewModel.getPacks().observe(activity, result -> {
    if (result == null) return;

    int previousCount = pagerAdapter.getCount();

    pagerAdapter.setPacks(result.getPacks());

    if (presenter != null) {
      present(presenter, result, previousCount != pagerAdapter.getCount());
    }
  });
}
 
Example #9
Source File: MoodleAssignmentsActivity.java    From ETSMobile-Android2 with Apache License 2.0 6 votes vote down vote up
public void subscribeUIList() {
    assignmentsCoursesObserver = listRemoteResource -> {
        if (listRemoteResource != null) {
            if (listRemoteResource.status == RemoteResource.SUCCESS) {
                requestInProgress = false;
                refreshUI();
            } else if (listRemoteResource.status == RemoteResource.ERROR) {
                requestInProgress = false;
                loadingView.hideProgessBar();
                displayErrorMessage(getString(R.string.toast_Sync_Fail));
            } else if (listRemoteResource.status == RemoteResource.LOADING) {
                requestInProgress = true;
                if (listRemoteResource.data != null) {
                    refreshUI();
                }
            }
        }

    };

    // Get the view model factory
    ApplicationManager.getAppComponent().inject(this);

    moodleViewModel = ViewModelProviders.of(this, moodleViewModelFactory).get(MoodleViewModel.class);
    moodleViewModel.getAssignmentCourses().observe(this, assignmentsCoursesObserver);
}
 
Example #10
Source File: ViewOnceMessageActivity.java    From mollyim-android with GNU General Public License v3.0 6 votes vote down vote up
private void initViewModel(long messageId, @NonNull Uri uri) {
  ViewOnceMessageRepository repository = new ViewOnceMessageRepository(this);

  viewModel = ViewModelProviders.of(this, new ViewOnceMessageViewModel.Factory(getApplication(), messageId, repository))
                                .get(ViewOnceMessageViewModel.class);

  viewModel.getMessage().observe(this, (message) -> {
    if (message == null) return;

    if (message.isPresent()) {
      displayMedia(uri);
    } else {
      image.setImageDrawable(null);
      finish();
    }
  });
}
 
Example #11
Source File: TestResultsActivity.java    From prebid-mobile-android with Apache License 2.0 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_test_results);

    mListView = findViewById(R.id.list_results);
    setupResultsList();

    mAdServerValidationViewModel = ViewModelProviders.of(this).get(AdServerValidationViewModel.class);
    mDemandValidationViewModel = ViewModelProviders.of(this).get(PrebidServerValidationViewModel.class);
    mSdkValidationViewModel = ViewModelProviders.of(this).get(SdkValidationViewModel.class);

    AdServerSettings adServerSettings = SettingsManager.getInstance(this).getAdServerSettings();

    if (adServerSettings.getAdServer() == AdServer.MOPUB) {
        initMoPub(adServerSettings.getAdUnitId());
    } else {
        initGoogleAdsManager();
    }
}
 
Example #12
Source File: MainActivity.java    From ui with Apache License 2.0 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    mViewModel = ViewModelProviders.of(this).get(DataViewModel.class);

    leftfrag = new FragLeft();
    midfrag = new FragMid();
    rightfrag = new FragRight();
    FragmentManager fragmentManager = getSupportFragmentManager();

    viewPager = findViewById(R.id.pager);
    if (viewPager != null) {
        //in portrait mode, so setup the viewpager with the fragments, using the adapter
        viewPager.setAdapter(new ThreeFragmentPagerAdapter(fragmentManager));
    } else {
        //in landscape mode  //so no viewpager.
        fragmentManager.beginTransaction()
            .add(R.id.frag_left, leftfrag)
            .add(R.id.frag_mid, midfrag)
            .add(R.id.frag_right, rightfrag)
            .commit();
    }

}
 
Example #13
Source File: ReactionsBottomSheetDialogFragment.java    From mollyim-android with GNU General Public License v3.0 6 votes vote down vote up
private void setUpViewModel() {
  reactionsLoader = new ReactionsLoader(requireContext(),
                                        getArguments().getLong(ARGS_MESSAGE_ID),
                                        getArguments().getBoolean(ARGS_IS_MMS));

  ReactionsViewModel.Factory factory = new ReactionsViewModel.Factory(reactionsLoader);
  viewModel = ViewModelProviders.of(this, factory).get(ReactionsViewModel.class);

  viewModel.getRecipients().observe(getViewLifecycleOwner(), reactions -> {
    if (reactions.size() == 0) dismiss();

    recipientsAdapter.updateData(reactions);
  });

  viewModel.getEmojiCounts().observe(getViewLifecycleOwner(), emojiCounts -> {
    if (emojiCounts.size() == 0) dismiss();

    emojiCountAdapter.updateData(emojiCounts);
  });
}
 
Example #14
Source File: ContactNameEditActivity.java    From mollyim-android with GNU General Public License v3.0 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState, boolean ready) {
  super.onCreate(savedInstanceState, ready);

  if (getIntent() == null) {
    throw new IllegalStateException("You must supply extras to this activity. Please use the #getIntent() method.");
  }

  Name name = getIntent().getParcelableExtra(KEY_NAME);
  if (name == null) {
    throw new IllegalStateException("You must supply a name to this activity. Please use the #getIntent() method.");
  }

  setContentView(R.layout.activity_contact_name_edit);

  initializeToolbar();
  initializeViews(name);

  viewModel = ViewModelProviders.of(this).get(ContactNameEditViewModel.class);
  viewModel.setName(name);
  viewModel.getDisplayName().observe(this, displayNameView::setText);
}
 
Example #15
Source File: VideoCardPresenter.java    From tv-samples with Apache License 2.0 6 votes vote down vote up
CardViewHolder(ImageCardView view, Context context) {
    super(view);
    mContext = context;
    Context wrapper = new ContextThemeWrapper(mContext, R.style.MyPopupMenu);
    mPopupMenu = new PopupMenu(wrapper, view);
    mPopupMenu.inflate(R.menu.popup_menu);

    mPopupMenu.setOnMenuItemClickListener(this);
    view.setOnLongClickListener(this);

    mOwner = (LifecycleOwner) mContext;

    mDefaultBackground = mContext.getResources().getDrawable(R.drawable.no_cache_no_internet, null);
    mDefaultPlaceHolder = new RequestOptions().
            placeholder(mDefaultBackground);

    mCardView = (ImageCardView) CardViewHolder.this.view;
    Resources resources = mCardView.getContext().getResources();
    mCardView.setMainImageDimensions(Math.round(
            resources.getDimensionPixelSize(R.dimen.card_width)),
            resources.getDimensionPixelSize(R.dimen.card_height));

    mFragmentActivity = (FragmentActivity) context;
    mViewModel = ViewModelProviders.of(mFragmentActivity).get(VideosViewModel.class);
}
 
Example #16
Source File: LiveDataDetailViewWithVideoBackgroundFragment.java    From tv-samples with Apache License 2.0 6 votes vote down vote up
@Override
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);

    mDetailsBgController.enableParallax();

    // First loading "cached" data to finish transition animation
    mActionAdapter.clear();
    mActionAdapter.add(mActionLoading);

    mDescriptionOverviewRow.setItem(mObservedVideo);
    loadAndSetVideoCardImage();

    mViewModel = ViewModelProviders.of(getActivity(), viewModelFactory)
            .get(VideosViewModel.class);
    subscribeToModel(mViewModel);
    subscribeToNetworkLiveData();
}
 
Example #17
Source File: MovieHistoryFragment.java    From cathode with Apache License 2.0 6 votes vote down vote up
@Override public void onCreate(@Nullable Bundle inState) {
  super.onCreate(inState);
  Bundle args = getArguments();
  movieId = args.getLong(ARG_MOVIEID);
  movieTitle = args.getString(ARG_MOVIETITLE);
  setTitle(movieTitle);

  viewModel = ViewModelProviders.of(this, viewModelFactory).get(MovieHistoryViewModel.class);
  viewModel.setMovieId(movieId);
  viewModel.getMovie().observe(this, new Observer<Movie>() {
    @Override public void onChanged(Movie movie) {
      setMovie(movie);
    }
  });
  viewModel.getHistory().observe(this, new Observer<MovieHistoryLiveData.Result>() {
    @Override public void onChanged(MovieHistoryLiveData.Result result) {
      setResult(result);
      setRefreshing(false);
    }
  });
}
 
Example #18
Source File: UsernameEditFragment.java    From mollyim-android with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
  usernameInput   = view.findViewById(R.id.username_text);
  usernameSubtext = view.findViewById(R.id.username_subtext);
  submitButton    = view.findViewById(R.id.username_submit_button);
  deleteButton    = view.findViewById(R.id.username_delete_button);

  viewModel = ViewModelProviders.of(this, new UsernameEditViewModel.Factory()).get(UsernameEditViewModel.class);

  viewModel.getUiState().observe(getViewLifecycleOwner(), this::onUiStateChanged);
  viewModel.getEvents().observe(getViewLifecycleOwner(), this::onEvent);

  submitButton.setOnClickListener(v -> viewModel.onUsernameSubmitted(usernameInput.getText().toString()));
  deleteButton.setOnClickListener(v -> viewModel.onUsernameDeleted());

  usernameInput.setText(TextSecurePreferences.getLocalUsername(requireContext()));
  usernameInput.addTextChangedListener(new SimpleTextWatcher() {
    @Override
    public void onTextChanged(String text) {
      viewModel.onUsernameUpdated(text);
    }
  });
}
 
Example #19
Source File: EnabledApplicationsPreferenceFragment.java    From an2linuxclient with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);
    EnabledApplicationsViewModel viewModel = ViewModelProviders.of(getActivity()).get(EnabledApplicationsViewModel.class);
    viewModel.getFilteredCheckBoxPrefsData().observe(getViewLifecycleOwner(), checkBoxPreferencesData -> {
        setPreferencesFromResource(R.xml.enabled_applications_preferences, null);
        PreferenceScreen prefScreen = (PreferenceScreen) findPreference(getString(R.string.enabled_apps_pref_screen));
        for (CheckBoxPreferenceData checkBoxPreferenceData : checkBoxPreferencesData) {
            CheckBoxPreference c = new CheckBoxPreference(getPreferenceScreen().getContext());
            c.setKey(checkBoxPreferenceData.key);
            c.setTitle(checkBoxPreferenceData.title);
            c.setSummary(checkBoxPreferenceData.summary);
            c.setIcon(checkBoxPreferenceData.icon);
            prefScreen.addPreference(c);
        }
    });
}
 
Example #20
Source File: Camera1Fragment.java    From mollyim-android with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  if (!(getActivity() instanceof Controller)) {
    throw new IllegalStateException("Parent activity must implement the Controller interface.");
  }

  WindowManager windowManager = ServiceUtil.getWindowManager(getActivity());
  Display       display       = windowManager.getDefaultDisplay();
  Point         displaySize   = new Point();

  display.getSize(displaySize);

  controller    = (Controller) getActivity();
  camera        = new Camera1Controller(TextSecurePreferences.getDirectCaptureCameraId(getContext()), displaySize.x, displaySize.y, this);
  orderEnforcer = new OrderEnforcer<>(Stage.SURFACE_AVAILABLE, Stage.CAMERA_PROPERTIES_AVAILABLE);
  viewModel     = ViewModelProviders.of(requireActivity(), new MediaSendViewModel.Factory(requireActivity().getApplication(), new MediaRepository())).get(MediaSendViewModel.class);
}
 
Example #21
Source File: AppListFragment.java    From MaxLock with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void onAttach(Context context) {
    super.onAttach(context);
    if (getActivity() != null) {
        appListModel = ViewModelProviders.of(getActivity()).get(AppListModel.class);
        appListModel.getAppsLoadedListener().observe(this, o ->
                rootView.findViewById(android.R.id.progress).setVisibility(View.GONE));
        appListModel.getDialogDispatcher().observe(this, dialog -> {
            if (dialog != null)
                UtilKt.showWithLifecycle(dialog, this);
        });
        appListModel.getFragmentFunctionDispatcher().observe(this, f -> {
            if (f != null) {
                f.invoke(this);
                appListModel.getFragmentFunctionDispatcher().setValue(null);
            }
        });
    }
}
 
Example #22
Source File: MainActivity.java    From Android-Developer-Fundamentals-Version-2 with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    Toolbar toolbar = findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);

    FloatingActionButton fab = findViewById(R.id.fab);
    fab.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            Intent intent = new Intent(MainActivity.this, AddNoteActivity.class);
            startActivity(intent);
        }
    });

    // recyclerView setup
    RecyclerView recyclerView = findViewById(R.id.recyclerView);
    final NoteListAdapter adapter = new NoteListAdapter(this);
    recyclerView.setAdapter(adapter);
    recyclerView.setLayoutManager(new LinearLayoutManager(this));

    NoteViewModel viewModel = ViewModelProviders.of(this).get(NoteViewModel.class);
    viewModel.getAllNotes().observe(this, new Observer<List<Note>>() {
        @Override
        public void onChanged(List<Note> notes) {
            adapter.setNotes(notes);
        }
    });

}
 
Example #23
Source File: ViewModelFactory.java    From ground-android with Apache License 2.0 5 votes vote down vote up
/**
 * Returns an instance of the specified view model, which is scoped to the activity if annotated
 * with {@link SharedViewModel}, or scoped to the Fragment if not.
 */
public <T extends ViewModel> T get(Fragment fragment, Class<T> modelClass) {
  if (modelClass.getAnnotation(SharedViewModel.class) == null) {
    return ViewModelProviders.of(fragment, this).get(modelClass);
  } else {
    return get(fragment.getActivity(), modelClass);
  }
}
 
Example #24
Source File: WebRtcCallActivity.java    From mollyim-android with GNU General Public License v3.0 5 votes vote down vote up
private void initializeViewModel() {
  viewModel = ViewModelProviders.of(this).get(WebRtcCallViewModel.class);
  viewModel.setIsInPipMode(isInPipMode());
  viewModel.getRemoteVideoEnabled().observe(this,callScreen::setRemoteVideoEnabled);
  viewModel.getMicrophoneEnabled().observe(this, callScreen::setMicEnabled);
  viewModel.getCameraDirection().observe(this, callScreen::setCameraDirection);
  viewModel.getLocalRenderState().observe(this, callScreen::setLocalRenderState);
  viewModel.getWebRtcControls().observe(this, callScreen::setWebRtcControls);
  viewModel.getEvents().observe(this, this::handleViewModelEvent);
  viewModel.getCallTime().observe(this, this::handleCallTime);
  viewModel.displaySquareCallCard().observe(this, callScreen::showCallCard);
}
 
Example #25
Source File: EventsFragment.java    From Deadline with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);

    mViewModel = ViewModelProviders.of(getActivity()).get(EventsViewModel.class);
    mBinding = FragmentEventsBinding.bind(getView());
    mBinding.setViewmodel(mViewModel);
    mBinding.setLifecycleOwner(this);

    mViewModel.getAllEvents().observe(this, new Observer<List<Event>>() {
        @Override
        public void onChanged(List<Event> events) {
            if (events != null) {
                mViewModel.hasLoadedEvents = true;
                updateShowedEventList();
                mViewModel.updateEventStateNum();
                mViewModel.updateTodayEventNum();
                mViewModel.updateQuickViewTitle();
            }
        }
    });

    setupSystemUI();
    setupActionBar();
    setupEventList();
    setupDrawer();
    setupSnackbar();
    setupQuickView();

    setupDrawerFilterList();
    setupDrawerCategoryList();
    setupDateProgress();

    setupEventsDataUpdateListener();

}
 
Example #26
Source File: AvatarSelectionActivity.java    From mollyim-android with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.avatar_selection_activity);

  MediaSendViewModel viewModel = ViewModelProviders.of(this, new MediaSendViewModel.Factory(getApplication(), new MediaRepository())).get(MediaSendViewModel.class);
  viewModel.setTransport(TransportOptions.getPushTransportOption(this));

  if (isGalleryFirst()) {
    onGalleryClicked();
  } else {
    onCameraSelected();
  }
}
 
Example #27
Source File: ComponentActivity.java    From Aria with Apache License 2.0 5 votes vote down vote up
@Override protected void init(Bundle savedInstanceState) {
  super.init(savedInstanceState);
  NormalTo to = getIntent().getParcelableExtra(MainActivity.KEY_MAIN_DATA);
  setTitle(to.title);

  final List<NormalTo> data = new ArrayList<>();
  getBinding().list.setLayoutManager(new GridLayoutManager(this, 2));
  final NormalToAdapter adapter = new NormalToAdapter(this, data);
  getBinding().list.setAdapter(adapter);
  final CommonModule module = ViewModelProviders.of(this).get(CommonModule.class);

  module.getComponentData(this).observe(this,
      new Observer<List<NormalTo>>() {
        @Override public void onChanged(@Nullable List<NormalTo> normalTos) {
          if (normalTos != null) {
            data.addAll(normalTos);
            adapter.notifyDataSetChanged();
          }
        }
      });
  RvItemClickSupport.addTo(getBinding().list).setOnItemClickListener(
      new RvItemClickSupport.OnItemClickListener() {
        @Override public void onItemClicked(RecyclerView recyclerView, int position, View v) {
          switch (position) {
            case 0:
              module.startNextActivity(ComponentActivity.this, data.get(position),
                  FragmentActivity.class);
              break;
            case 1:
              DownloadDialog dialog = new DownloadDialog(ComponentActivity.this);
              dialog.show();
              break;
          }
        }
      });
}
 
Example #28
Source File: LiveDataFragment.java    From tv-samples with Apache License 2.0 5 votes vote down vote up
@Override
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);
    subscribeNetworkInfo();
    mViewModel = ViewModelProviders.of(getActivity(), viewModelFactory)
            .get(VideosViewModel.class);
    subscribeUi(mViewModel);
}
 
Example #29
Source File: ImageFragment.java    From mcumgr-android with Apache License 2.0 5 votes vote down vote up
@Override
public void onCreate(@Nullable final Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setHasOptionsMenu(true);

    mViewModel = ViewModelProviders.of(this, mViewModelFactory)
            .get(McuMgrViewModel.class);

    mModeAdvanced = savedInstanceState != null &&
            savedInstanceState.getBoolean(SIS_MODE_ADVANCED);
}
 
Example #30
Source File: MainActivity.java    From android-bluetooth-serial with Apache License 2.0 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    // Setup our activity
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    // Setup our ViewModel
    viewModel = ViewModelProviders.of(this).get(MainActivityViewModel.class);

    // This method return false if there is an error, so if it does, we should close.
    if (!viewModel.setupViewModel()) {
        finish();
        return;
    }

    // Setup our Views
    RecyclerView deviceList = findViewById(R.id.main_devices);
    SwipeRefreshLayout swipeRefreshLayout = findViewById(R.id.main_swiperefresh);

    // Setup the RecyclerView
    deviceList.setLayoutManager(new LinearLayoutManager(this));
    DeviceAdapter adapter = new DeviceAdapter();
    deviceList.setAdapter(adapter);

    // Setup the SwipeRefreshLayout
    swipeRefreshLayout.setOnRefreshListener(() -> {
        viewModel.refreshPairedDevices();
        swipeRefreshLayout.setRefreshing(false);
    });

    // Start observing the data sent to us by the ViewModel
    viewModel.getPairedDeviceList().observe(MainActivity.this, adapter::updateList);

    // Immediately refresh the paired devices list
    viewModel.refreshPairedDevices();
}