Move BT error LiveData and ViewModel to ui.warning

Rename NoHfpActivityViewModel to NoHfpViewModel.

Bug: 161998213
Test: build and run dialer
Change-Id: I87875069d915f9c050422bb88e7080e507846457
diff --git a/src/com/android/car/dialer/livedata/BluetoothErrorStringLiveData.java b/src/com/android/car/dialer/ui/warning/BluetoothErrorStringLiveData.java
similarity index 91%
rename from src/com/android/car/dialer/livedata/BluetoothErrorStringLiveData.java
rename to src/com/android/car/dialer/ui/warning/BluetoothErrorStringLiveData.java
index 2b474dc..b93c3c9 100644
--- a/src/com/android/car/dialer/livedata/BluetoothErrorStringLiveData.java
+++ b/src/com/android/car/dialer/ui/warning/BluetoothErrorStringLiveData.java
@@ -14,7 +14,7 @@
  * limitations under the License.
  */
 
-package com.android.car.dialer.livedata;
+package com.android.car.dialer.ui.warning;
 
 import android.bluetooth.BluetoothAdapter;
 import android.bluetooth.BluetoothDevice;
@@ -24,6 +24,9 @@
 
 import com.android.car.dialer.R;
 import com.android.car.dialer.bluetooth.UiBluetoothMonitor;
+import com.android.car.dialer.livedata.BluetoothPairListLiveData;
+import com.android.car.dialer.livedata.BluetoothStateLiveData;
+import com.android.car.dialer.livedata.HfpDeviceListLiveData;
 import com.android.car.dialer.log.L;
 
 import java.util.List;
@@ -44,16 +47,7 @@
     private BluetoothPairListLiveData mPairListLiveData;
     private BluetoothStateLiveData mBluetoothStateLiveData;
 
-    /**
-     * Creates {@link BluetoothErrorStringLiveData}.
-     *
-     * @param context A context for getting strings.
-     */
-    public static BluetoothErrorStringLiveData get(Context context) {
-        return new BluetoothErrorStringLiveData(context);
-    }
-
-    private BluetoothErrorStringLiveData(Context context) {
+    BluetoothErrorStringLiveData(Context context) {
         mContext = context.getApplicationContext();
 
         if (BluetoothAdapter.getDefaultAdapter() == null) {
diff --git a/src/com/android/car/dialer/ui/warning/NoHfpFragment.java b/src/com/android/car/dialer/ui/warning/NoHfpFragment.java
index a704656..a84a37e 100644
--- a/src/com/android/car/dialer/ui/warning/NoHfpFragment.java
+++ b/src/com/android/car/dialer/ui/warning/NoHfpFragment.java
@@ -34,9 +34,7 @@
 import com.android.car.apps.common.util.CarPackageManagerUtils;
 import com.android.car.apps.common.util.ViewUtils;
 import com.android.car.dialer.R;
-import com.android.car.dialer.livedata.BluetoothErrorStringLiveData;
 import com.android.car.dialer.telecom.UiCallManager;
-import com.android.car.dialer.ui.NoHfpActivityViewModel;
 import com.android.car.dialer.ui.dialpad.DialpadFragment;
 
 /**
@@ -73,7 +71,7 @@
         mErrorMessageView = view.findViewById(R.id.error_string);
 
         LiveData<String> errorStringLiveData = new ViewModelProvider(getActivity())
-                .get(NoHfpActivityViewModel.class)
+                .get(NoHfpViewModel.class)
                 .getBluetoothErrorStringLiveData();
 
         errorStringLiveData.observe(this, error -> {
diff --git a/src/com/android/car/dialer/ui/NoHfpActivityViewModel.java b/src/com/android/car/dialer/ui/warning/NoHfpViewModel.java
similarity index 81%
rename from src/com/android/car/dialer/ui/NoHfpActivityViewModel.java
rename to src/com/android/car/dialer/ui/warning/NoHfpViewModel.java
index 40e55eb..42d6471 100644
--- a/src/com/android/car/dialer/ui/NoHfpActivityViewModel.java
+++ b/src/com/android/car/dialer/ui/warning/NoHfpViewModel.java
@@ -14,7 +14,7 @@
  * limitations under the License.
  */
 
-package com.android.car.dialer.ui;
+package com.android.car.dialer.ui.warning;
 
 import android.app.Application;
 
@@ -23,18 +23,17 @@
 import androidx.lifecycle.LiveData;
 
 import com.android.car.dialer.bluetooth.UiBluetoothMonitor;
-import com.android.car.dialer.livedata.BluetoothErrorStringLiveData;
 
 /** View model for {@link NoHfpFragment} */
-public class NoHfpActivityViewModel extends AndroidViewModel {
+public class NoHfpViewModel extends AndroidViewModel {
 
     private final LiveData<Boolean> mHasHfpDeviceConnectedLiveData;
     private final LiveData<String> mBluetoothErrorStringLiveData;
 
-    public NoHfpActivityViewModel(@NonNull Application application) {
+    public NoHfpViewModel(@NonNull Application application) {
         super(application);
         mHasHfpDeviceConnectedLiveData = UiBluetoothMonitor.get().hasHfpDeviceConnected();
-        mBluetoothErrorStringLiveData = BluetoothErrorStringLiveData.get(application);
+        mBluetoothErrorStringLiveData = new BluetoothErrorStringLiveData(application);
     }
 
     public LiveData<String> getBluetoothErrorStringLiveData() {
diff --git a/tests/robotests/src/com/android/car/dialer/ui/NoHfpActivityViewModelTest.java b/tests/robotests/src/com/android/car/dialer/ui/warning/NoHfpViewModelTest.java
similarity index 87%
rename from tests/robotests/src/com/android/car/dialer/ui/NoHfpActivityViewModelTest.java
rename to tests/robotests/src/com/android/car/dialer/ui/warning/NoHfpViewModelTest.java
index 780156e..f8b5f57 100644
--- a/tests/robotests/src/com/android/car/dialer/ui/NoHfpActivityViewModelTest.java
+++ b/tests/robotests/src/com/android/car/dialer/ui/warning/NoHfpViewModelTest.java
@@ -14,7 +14,7 @@
  * limitations under the License.
  */
 
-package com.android.car.dialer.ui;
+package com.android.car.dialer.ui.warning;
 
 import static com.google.common.truth.Truth.assertThat;
 
@@ -30,7 +30,6 @@
 import com.android.car.dialer.R;
 import com.android.car.dialer.TestDialerApplication;
 import com.android.car.dialer.bluetooth.UiBluetoothMonitor;
-import com.android.car.dialer.livedata.BluetoothErrorStringLiveData;
 import com.android.car.dialer.livedata.BluetoothPairListLiveData;
 import com.android.car.dialer.livedata.BluetoothStateLiveData;
 import com.android.car.dialer.livedata.HfpDeviceListLiveData;
@@ -49,9 +48,9 @@
 
 @RunWith(CarDialerRobolectricTestRunner.class)
 @Config(shadows = ShadowBluetoothAdapterForDialer.class)
-public class NoHfpActivityViewModelTest {
+public class NoHfpViewModelTest {
 
-    private NoHfpActivityViewModel mNoHfpActivityViewModel;
+    private NoHfpViewModel mNoHfpViewModel;
     private Context mContext;
     private HfpDeviceListLiveData mHfpDeviceListLiveData;
     private BluetoothPairListLiveData mPairedListLiveData;
@@ -74,7 +73,7 @@
         ShadowBluetoothAdapterForDialer.setBluetoothAvailable(false);
         initializeViewModel();
 
-        assertThat(mNoHfpActivityViewModel.getBluetoothErrorStringLiveData().getValue()).isEqualTo(
+        assertThat(mNoHfpViewModel.getBluetoothErrorStringLiveData().getValue()).isEqualTo(
                 mContext.getString(R.string.bluetooth_unavailable));
     }
 
@@ -88,7 +87,7 @@
 
         assertThat(mBluetoothStateLiveData.getValue()).isEqualTo(
                 BluetoothStateLiveData.BluetoothState.DISABLED);
-        assertThat(mNoHfpActivityViewModel.getBluetoothErrorStringLiveData().getValue()).isEqualTo(
+        assertThat(mNoHfpViewModel.getBluetoothErrorStringLiveData().getValue()).isEqualTo(
                 mContext.getString(R.string.bluetooth_disabled));
     }
 
@@ -105,7 +104,7 @@
                 BluetoothStateLiveData.BluetoothState.ENABLED);
 
         assertThat(mPairedListLiveData.getValue().isEmpty()).isTrue();
-        assertThat(mNoHfpActivityViewModel.getBluetoothErrorStringLiveData().getValue()).isEqualTo(
+        assertThat(mNoHfpViewModel.getBluetoothErrorStringLiveData().getValue()).isEqualTo(
                 mContext.getString(R.string.bluetooth_unpaired));
     }
 
@@ -125,7 +124,7 @@
         assertThat(mPairedListLiveData.getValue().isEmpty()).isFalse();
 
         assertThat(mHfpDeviceListLiveData.getValue().isEmpty()).isTrue();
-        assertThat(mNoHfpActivityViewModel.getBluetoothErrorStringLiveData().getValue()).isEqualTo(
+        assertThat(mNoHfpViewModel.getBluetoothErrorStringLiveData().getValue()).isEqualTo(
                 mContext.getString(R.string.no_hfp));
     }
 
@@ -144,7 +143,7 @@
 
         initializeViewModel();
 
-        assertThat(mNoHfpActivityViewModel.getBluetoothErrorStringLiveData().getValue()).isEqualTo(
+        assertThat(mNoHfpViewModel.getBluetoothErrorStringLiveData().getValue()).isEqualTo(
                 BluetoothErrorStringLiveData.NO_BT_ERROR);
     }
 
@@ -153,9 +152,9 @@
         mHfpDeviceListLiveData = UiBluetoothMonitor.get().getHfpDeviceListLiveData();
         mPairedListLiveData = UiBluetoothMonitor.get().getPairListLiveData();
         mBluetoothStateLiveData = UiBluetoothMonitor.get().getBluetoothStateLiveData();
-        mNoHfpActivityViewModel = new NoHfpActivityViewModel((Application) mContext);
+        mNoHfpViewModel = new NoHfpViewModel((Application) mContext);
         // Observers needed so that the liveData's internal initialization is triggered
-        mNoHfpActivityViewModel.getBluetoothErrorStringLiveData().observeForever(o -> {
+        mNoHfpViewModel.getBluetoothErrorStringLiveData().observeForever(o -> {
         });
     }
 }