Search in sources :

Example 1 with SharedViewModel

use of com.googletest.firebase.perf.testapp.SharedViewModel in project firebase-android-sdk by firebase.

the class DashboardFragment method onCreateView.

public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    dashboardViewModel = new ViewModelProvider(this, new ViewModelProvider.NewInstanceFactory()).get(DashboardViewModel.class);
    View root = inflater.inflate(R.layout.fragment_dashboard, container, false);
    final TextView textView = root.findViewById(R.id.text_dashboard);
    dashboardViewModel.getText().observe(getViewLifecycleOwner(), new Observer<String>() {

        @Override
        public void onChanged(@Nullable String s) {
            textView.setText(s);
        }
    });
    // Gif loading for testing
    sharedViewModel = new ViewModelProvider(requireActivity()).get(SharedViewModel.class);
    final ImageView imageView = root.findViewById(R.id.img_dashboard);
    sharedViewModel.getImageSrc().observe(getViewLifecycleOwner(), new Observer<String>() {

        @Override
        public void onChanged(String s) {
            Glide.with(requireActivity()).load(s).diskCacheStrategy(DiskCacheStrategy.NONE).skipMemoryCache(true).into(imageView);
        }
    });
    return root;
}
Also used : SharedViewModel(com.googletest.firebase.perf.testapp.SharedViewModel) TextView(android.widget.TextView) ImageView(android.widget.ImageView) ImageView(android.widget.ImageView) TextView(android.widget.TextView) View(android.view.View) ViewModelProvider(androidx.lifecycle.ViewModelProvider)

Example 2 with SharedViewModel

use of com.googletest.firebase.perf.testapp.SharedViewModel in project firebase-android-sdk by firebase.

the class NotificationsFragment method onCreateView.

public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    notificationsViewModel = new ViewModelProvider(this, new ViewModelProvider.NewInstanceFactory()).get(NotificationsViewModel.class);
    View root = inflater.inflate(R.layout.fragment_notifications, container, false);
    final TextView textView = root.findViewById(R.id.text_notifications);
    notificationsViewModel.getText().observe(getViewLifecycleOwner(), new Observer<String>() {

        @Override
        public void onChanged(@Nullable String s) {
            textView.setText(s);
        }
    });
    // Gif loading for testing
    sharedViewModel = new ViewModelProvider(requireActivity()).get(SharedViewModel.class);
    final ImageView imageView = root.findViewById(R.id.img_notifications);
    sharedViewModel.getImageSrc().observe(getViewLifecycleOwner(), new Observer<String>() {

        @Override
        public void onChanged(String s) {
            Glide.with(requireActivity()).load(s).diskCacheStrategy(DiskCacheStrategy.NONE).skipMemoryCache(true).into(imageView);
        }
    });
    // Recycler View setup
    RecyclerView numbersList = root.findViewById(R.id.rv_fragment_notifications);
    LinearLayoutManager layoutManager = new LinearLayoutManager(requireActivity());
    ListAdapter listAdapter = new ListAdapter(NUM_LIST_ITEMS);
    numbersList.setLayoutManager(layoutManager);
    numbersList.setHasFixedSize(true);
    numbersList.setAdapter(listAdapter);
    return root;
}
Also used : SharedViewModel(com.googletest.firebase.perf.testapp.SharedViewModel) LinearLayoutManager(androidx.recyclerview.widget.LinearLayoutManager) ImageView(android.widget.ImageView) TextView(android.widget.TextView) View(android.view.View) RecyclerView(androidx.recyclerview.widget.RecyclerView) TextView(android.widget.TextView) RecyclerView(androidx.recyclerview.widget.RecyclerView) ImageView(android.widget.ImageView) ListAdapter(com.googletest.firebase.perf.testapp.ListAdapter) ViewModelProvider(androidx.lifecycle.ViewModelProvider)

Example 3 with SharedViewModel

use of com.googletest.firebase.perf.testapp.SharedViewModel in project firebase-android-sdk by firebase.

the class HomeFragment method onCreateView.

public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    homeViewModel = new ViewModelProvider(this, new ViewModelProvider.NewInstanceFactory()).get(HomeViewModel.class);
    View root = inflater.inflate(R.layout.fragment_home, container, false);
    final TextView textView = root.findViewById(R.id.text_home);
    homeViewModel.getText().observe(getViewLifecycleOwner(), new Observer<String>() {

        @Override
        public void onChanged(@Nullable String s) {
            textView.setText(s);
        }
    });
    // Gif loading for testing
    sharedViewModel = new ViewModelProvider(requireActivity()).get(SharedViewModel.class);
    final ImageView imageView = root.findViewById(R.id.img_home);
    sharedViewModel.getImageSrc().observe(getViewLifecycleOwner(), new Observer<String>() {

        @Override
        public void onChanged(String s) {
            Glide.with(requireActivity()).load(s).diskCacheStrategy(DiskCacheStrategy.NONE).skipMemoryCache(true).into(imageView);
        }
    });
    return root;
}
Also used : SharedViewModel(com.googletest.firebase.perf.testapp.SharedViewModel) TextView(android.widget.TextView) ImageView(android.widget.ImageView) ImageView(android.widget.ImageView) TextView(android.widget.TextView) View(android.view.View) ViewModelProvider(androidx.lifecycle.ViewModelProvider)

Aggregations

View (android.view.View)3 ImageView (android.widget.ImageView)3 TextView (android.widget.TextView)3 ViewModelProvider (androidx.lifecycle.ViewModelProvider)3 SharedViewModel (com.googletest.firebase.perf.testapp.SharedViewModel)3 LinearLayoutManager (androidx.recyclerview.widget.LinearLayoutManager)1 RecyclerView (androidx.recyclerview.widget.RecyclerView)1 ListAdapter (com.googletest.firebase.perf.testapp.ListAdapter)1