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.TopicsActivityActionDelegate;
28 import com.android.adservices.ui.settings.delegates.TopicsActionDelegate;
29 import com.android.adservices.ui.settings.fragments.AdServicesSettingsTopicsFragment;
30 import com.android.adservices.ui.settings.viewmodels.TopicsViewModel;
31 
32 /** Android application activity for controlling topics generated by Topics API. */
33 @RequiresApi(Build.VERSION_CODES.S)
34 public class TopicsActivity extends AdServicesBaseActivity {
35     private TopicsActionDelegate mActionDelegate;
36     private TopicsActivityActionDelegate mActivityActionDelegate;
37 
38     /** @return the action delegate for the activity. */
getActionDelegate()39     public TopicsActionDelegate getActionDelegate() {
40         return mActionDelegate;
41     }
42 
43     @Override
onCreate(Bundle savedInstanceState)44     protected void onCreate(Bundle savedInstanceState) {
45         super.onCreate(savedInstanceState);
46         if (!isUxStatesReady(this)) {
47             initFragment();
48         }
49     }
50 
51     @Override
onResume()52     protected void onResume() {
53         super.onResume();
54         TopicsViewModel viewModel = new ViewModelProvider(this).get(TopicsViewModel.class);
55         viewModel.refresh();
56     }
57 
58     @Override
initGA()59     public void initGA() {
60         initActivity();
61     }
62 
63     @Override
initU18()64     public void initU18() {}
65 
66     @Override
initRvc()67     public void initRvc() {}
68 
initFragment()69     private void initFragment() {
70         setContentView(R.layout.adservices_settings_main_activity);
71         getSupportFragmentManager()
72                 .beginTransaction()
73                 .replace(R.id.fragment_container_view, AdServicesSettingsTopicsFragment.class, null)
74                 .setReorderingAllowed(true)
75                 .commit();
76         mActionDelegate =
77                 new TopicsActionDelegate(
78                         this, new ViewModelProvider(this).get(TopicsViewModel.class));
79     }
80 
initActivity()81     private void initActivity() {
82         setContentView(R.layout.topics_activity);
83         // no need to store since not using
84         mActivityActionDelegate =
85                 new TopicsActivityActionDelegate(
86                         this, new ViewModelProvider(this).get(TopicsViewModel.class));
87     }
88 }
89