• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2019 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package com.android.car.dialer.ui.favorite;
18 
19 import android.os.Bundle;
20 import android.view.LayoutInflater;
21 import android.view.View;
22 import android.view.ViewGroup;
23 import android.widget.Toast;
24 
25 import androidx.fragment.app.Fragment;
26 import androidx.lifecycle.ViewModelProviders;
27 
28 import com.android.car.dialer.R;
29 import com.android.car.dialer.ui.common.DialerBaseFragment;
30 
31 /** Contains either the "You haven't added any favorites yet" screen, or FavoriteListFragment */
32 public class FavoriteFragment extends DialerBaseFragment {
33 
newInstance()34     public static FavoriteFragment newInstance() {
35         return new FavoriteFragment();
36     }
37 
38     @Override
onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)39     public View onCreateView(LayoutInflater inflater, ViewGroup container,
40             Bundle savedInstanceState) {
41         View view = inflater.inflate(R.layout.favorite_fragment, container, false);
42         View emptyPage = view.findViewById(R.id.empty_page_container);
43         Fragment listFragment =
44                 getChildFragmentManager().findFragmentById(R.id.favorite_list_fragment);
45 
46         FavoriteViewModel favoriteViewModel = ViewModelProviders.of(getActivity()).get(
47                 FavoriteViewModel.class);
48         favoriteViewModel.getFavoriteContacts().observe(this, contacts -> {
49             if (contacts == null || contacts.isEmpty()) {
50                 emptyPage.setVisibility(View.VISIBLE);
51                 getChildFragmentManager().beginTransaction()
52                         .hide(listFragment)
53                         .commit();
54             } else {
55                 emptyPage.setVisibility(View.GONE);
56                 getChildFragmentManager().beginTransaction()
57                         .show(listFragment)
58                         .commit();
59             }
60         });
61 
62         emptyPage.findViewById(R.id.add_favorite_button).setOnClickListener(v ->
63                 Toast.makeText(getContext(), "Not yet implemented", Toast.LENGTH_LONG).show());
64 
65         return view;
66     }
67 }
68