• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2018 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.dialer.historyitemactions;
18 
19 import android.content.Context;
20 import com.android.dialer.blockreportspam.BlockReportSpamDialogInfo;
21 import com.android.dialer.blockreportspam.ShowBlockReportSpamDialogNotifier;
22 import com.android.dialer.logging.DialerImpression;
23 import com.android.dialer.logging.Logger;
24 import java.util.Optional;
25 
26 /** Modules for blocking/unblocking a number and/or reporting it as spam/not spam. */
27 final class BlockReportSpamModules {
28 
BlockReportSpamModules()29   private BlockReportSpamModules() {}
30 
moduleForMarkingNumberAsNotSpam( Context context, BlockReportSpamDialogInfo blockReportSpamDialogInfo, Optional<DialerImpression.Type> impression)31   static HistoryItemActionModule moduleForMarkingNumberAsNotSpam(
32       Context context,
33       BlockReportSpamDialogInfo blockReportSpamDialogInfo,
34       Optional<DialerImpression.Type> impression) {
35 
36     return new HistoryItemActionModule() {
37       @Override
38       public int getStringId() {
39         return R.string.not_spam;
40       }
41 
42       @Override
43       public int getDrawableId() {
44         return R.drawable.quantum_ic_report_off_vd_theme_24;
45       }
46 
47       @Override
48       public boolean onClick() {
49         ShowBlockReportSpamDialogNotifier.notifyShowDialogToReportNotSpam(
50             context, blockReportSpamDialogInfo);
51 
52         impression.ifPresent(Logger.get(context)::logImpression);
53         return true; // Close the bottom sheet.
54       }
55     };
56   }
57 
58   static HistoryItemActionModule moduleForBlockingNumber(
59       Context context,
60       BlockReportSpamDialogInfo blockReportSpamDialogInfo,
61       Optional<DialerImpression.Type> impression) {
62 
63     return new HistoryItemActionModule() {
64       @Override
65       public int getStringId() {
66         return R.string.block_number;
67       }
68 
69       @Override
70       public int getDrawableId() {
71         return R.drawable.quantum_ic_block_vd_theme_24;
72       }
73 
74       @Override
75       public boolean onClick() {
76         ShowBlockReportSpamDialogNotifier.notifyShowDialogToBlockNumber(
77             context, blockReportSpamDialogInfo);
78 
79         impression.ifPresent(Logger.get(context)::logImpression);
80         return true; // Close the bottom sheet.
81       }
82     };
83   }
84 
85   static HistoryItemActionModule moduleForUnblockingNumber(
86       Context context,
87       BlockReportSpamDialogInfo blockReportSpamDialogInfo,
88       Optional<DialerImpression.Type> impression) {
89 
90     return new HistoryItemActionModule() {
91       @Override
92       public int getStringId() {
93         return R.string.unblock_number;
94       }
95 
96       @Override
97       public int getDrawableId() {
98         return R.drawable.quantum_ic_unblock_vd_theme_24;
99       }
100 
101       @Override
102       public boolean onClick() {
103         ShowBlockReportSpamDialogNotifier.notifyShowDialogToUnblockNumber(
104             context, blockReportSpamDialogInfo);
105 
106         impression.ifPresent(Logger.get(context)::logImpression);
107         return true; // Close the bottom sheet.
108       }
109     };
110   }
111 
112   static HistoryItemActionModule moduleForBlockingNumberAndOptionallyReportingSpam(
113       Context context,
114       BlockReportSpamDialogInfo blockReportSpamDialogInfo,
115       Optional<DialerImpression.Type> impression) {
116 
117     return new HistoryItemActionModule() {
118       @Override
119       public int getStringId() {
120         return R.string.block_and_optionally_report_spam;
121       }
122 
123       @Override
124       public int getDrawableId() {
125         return R.drawable.quantum_ic_block_vd_theme_24;
126       }
127 
128       @Override
129       public boolean onClick() {
130         ShowBlockReportSpamDialogNotifier.notifyShowDialogToBlockNumberAndOptionallyReportSpam(
131             context, blockReportSpamDialogInfo);
132 
133         impression.ifPresent(Logger.get(context)::logImpression);
134         return true; // Close the bottom sheet.
135       }
136     };
137   }
138 }
139