summaryrefslogtreecommitdiff
path: root/src/com/android/dialer/calllog/BlockReportSpamListener.java
blob: 92cbc804b3770129908f735605159d267654e3a7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
package com.android.dialer.calllog;

import android.app.Activity;
import android.app.FragmentManager;
import android.content.ContentValues;
import android.content.DialogInterface;
import android.net.Uri;
import android.support.v7.widget.RecyclerView;

import com.android.dialer.util.BlockReportSpamDialogs;
import com.android.dialer.database.FilteredNumberAsyncQueryHandler;
import com.android.dialer.service.ExtendedCallInfoService;

/**
 * Listener to show dialogs for block and report spam actions.
 */
public class BlockReportSpamListener implements CallLogListItemViewHolder.OnClickListener {

    private final FragmentManager mFragmentManager;
    private final RecyclerView.Adapter mAdapter;
    private final ExtendedCallInfoService mExtendedCallInfoService;
    private final FilteredNumberAsyncQueryHandler mFilteredNumberAsyncQueryHandler;

    public BlockReportSpamListener(FragmentManager fragmentManager, RecyclerView.Adapter adapter,
                                   ExtendedCallInfoService extendedCallInfoService,
                                   FilteredNumberAsyncQueryHandler filteredNumberAsyncQueryHandler) {
        mFragmentManager = fragmentManager;
        mAdapter = adapter;
        mExtendedCallInfoService = extendedCallInfoService;
        mFilteredNumberAsyncQueryHandler = filteredNumberAsyncQueryHandler;
    }

    @Override
    public void onBlockReportSpam(String displayNumber, final String number,
                                  final String countryIso, final int callType) {
        BlockReportSpamDialogs.BlockReportSpamDialogFragment.newInstance(
                displayNumber,
                false,
                new BlockReportSpamDialogs.OnSpamDialogClickListener() {
                    @Override
                    public void onClick(boolean isSpamChecked) {
                        if (isSpamChecked) {
                            mExtendedCallInfoService.reportSpam(
                                    number, countryIso, callType,
                                    ExtendedCallInfoService.REPORTING_LOCATION_CALL_LOG_HISTORY);
                        }
                        mFilteredNumberAsyncQueryHandler.blockNumber(
                                new FilteredNumberAsyncQueryHandler.OnBlockNumberListener() {
                                    @Override
                                    public void onBlockComplete(Uri uri) {
                                        mAdapter.notifyDataSetChanged();
                                    }
                                },
                                number,
                                countryIso);
                    }
                }, null)
                .show(mFragmentManager, BlockReportSpamDialogs.BLOCK_REPORT_SPAM_DIALOG_TAG);
    }

    @Override
    public void onBlock(String displayNumber, final String number, final String countryIso,
                        final int callType) {
        BlockReportSpamDialogs.BlockDialogFragment.newInstance(displayNumber,
                new BlockReportSpamDialogs.OnConfirmListener() {
                    @Override
                    public void onClick() {
                        mExtendedCallInfoService.reportSpam(number, countryIso, callType,
                                ExtendedCallInfoService.REPORTING_LOCATION_CALL_LOG_HISTORY);
                        mFilteredNumberAsyncQueryHandler.blockNumber(
                                new FilteredNumberAsyncQueryHandler.OnBlockNumberListener() {
                                    @Override
                                    public void onBlockComplete(Uri uri) {
                                        mAdapter.notifyDataSetChanged();
                                    }
                                },
                                number,
                                countryIso);
                    }
                }, null)
                .show(mFragmentManager, BlockReportSpamDialogs.BLOCK_DIALOG_TAG);
    }

    @Override
    public void onUnblock(String displayNumber, final String number, final String countryIso,
                          final Integer blockId, final boolean isSpam, final int callType) {
        BlockReportSpamDialogs.UnblockDialogFragment.newInstance(displayNumber, isSpam,
                new BlockReportSpamDialogs.OnConfirmListener() {
                    @Override
                    public void onClick() {
                        if (isSpam) {
                            mExtendedCallInfoService.reportNotSpam(
                                    number, countryIso, callType,
                                    ExtendedCallInfoService.REPORTING_LOCATION_CALL_LOG_HISTORY);
                        }
                        mFilteredNumberAsyncQueryHandler.unblock(
                                new FilteredNumberAsyncQueryHandler.OnUnblockNumberListener() {
                                    @Override
                                    public void onUnblockComplete(int rows, ContentValues values) {
                                        mAdapter.notifyDataSetChanged();
                                    }
                                },
                                blockId);
                    }
                }, null)
                .show(mFragmentManager, BlockReportSpamDialogs.UNBLOCK_DIALOG_TAG);
    }

    @Override
    public void onReportNotSpam(String displayNumber, final String number, final String countryIso,
                                final int callType) {
        BlockReportSpamDialogs.ReportNotSpamDialogFragment.newInstance(displayNumber,
                new BlockReportSpamDialogs.OnConfirmListener() {
                    @Override
                    public void onClick() {
                        mExtendedCallInfoService.reportNotSpam(
                                number, countryIso, callType,
                                ExtendedCallInfoService.REPORTING_LOCATION_CALL_LOG_HISTORY);
                        mAdapter.notifyDataSetChanged();
                    }
                }, null)
                .show(mFragmentManager, BlockReportSpamDialogs.NOT_SPAM_DIALOG_TAG);
    }
}