1 /*
2  * Copyright (C) 2022 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 package com.android.adservices.ui.settings.activities;
17 
18 import static com.android.adservices.ui.UxUtil.isUxStatesReady;
19 
20 import android.os.Build;
21 import android.os.Bundle;
22 
23 import androidx.annotation.RequiresApi;
24 import androidx.lifecycle.ViewModelProvider;
25 
26 import com.android.adservices.api.R;
27 import com.android.adservices.ui.settings.activitydelegates.AppsActivityActionDelegate;
28 import com.android.adservices.ui.settings.delegates.AppsActionDelegate;
29 import com.android.adservices.ui.settings.fragments.AdServicesSettingsAppsFragment;
30 import com.android.adservices.ui.settings.viewmodels.AppsViewModel;
31 
32 /**
33  * Android application activity for controlling applications which interacted with FLEDGE
34  * (Remarketing) APIs.
35  */
36 @RequiresApi(Build.VERSION_CODES.S)
37 public class AppsActivity extends AdServicesBaseActivity {
38     private AppsActionDelegate mActionDelegate;
39 
40     /** @return the action delegate for the activity. */
getActionDelegate()41     public AppsActionDelegate getActionDelegate() {
42         return mActionDelegate;
43     }
44 
45     @Override
onCreate(Bundle savedInstanceState)46     protected void onCreate(Bundle savedInstanceState) {
47         super.onCreate(savedInstanceState);
48         if (!isUxStatesReady(this)) {
49             initFragment();
50         }
51     }
52 
53     @Override
onResume()54     public void onResume() {
55         super.onResume();
56         AppsViewModel viewModel = new ViewModelProvider(this).get(AppsViewModel.class);
57         viewModel.refresh();
58     }
59 
60     @Override
initGA()61     public void initGA() {
62         initActivity();
63     }
64 
65     @Override
initU18()66     public void initU18() {}
67 
68     @Override
initRvc()69     public void initRvc() {}
70 
initFragment()71     private void initFragment() {
72         setContentView(R.layout.adservices_settings_main_activity);
73         getSupportFragmentManager()
74                 .beginTransaction()
75                 .replace(R.id.fragment_container_view, AdServicesSettingsAppsFragment.class, null)
76                 .setReorderingAllowed(true)
77                 .commit();
78         mActionDelegate =
79                 new AppsActionDelegate(this, new ViewModelProvider(this).get(AppsViewModel.class));
80     }
81 
initActivity()82     private void initActivity() {
83         setContentView(R.layout.apps_activity);
84         // no need to store since not using
85         new AppsActivityActionDelegate(this, new ViewModelProvider(this).get(AppsViewModel.class));
86     }
87 }
88