summaryrefslogtreecommitdiff
path: root/src/com/android/calendar/alerts/QuickResponseActivity.kt
blob: afccaffd895aeb0656dc6f103ef4ba752c4654ae (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
/*
 * Copyright (C) 2021 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.android.calendar.alerts

import android.app.ListActivity
import android.content.Intent
import android.os.Bundle
import android.view.View
import android.widget.AdapterView
import android.widget.AdapterView.OnItemClickListener
import android.widget.ArrayAdapter
import com.android.calendar.R
import com.android.calendar.Utils
import java.util.Arrays

/**
 * Activity which displays when the user wants to email guests from notifications.
 *
 * This presents the user with list if quick responses to be populated in an email
 * to minimize typing.
 *
 */
class QuickResponseActivity : ListActivity(), OnItemClickListener {
    private var mResponses: Array<String?>? = null
    @Override
    protected override fun onCreate(icicle: Bundle?) {
        super.onCreate(icicle)
        val intent: Intent? = getIntent()
        if (intent == null) {
            finish()
            return
        }
        mEventId = intent?.getLongExtra(EXTRA_EVENT_ID, -1) as Long
        if (mEventId == -1L) {
            finish()
            return
        }

        // Set listener
        getListView().setOnItemClickListener(this@QuickResponseActivity)

        // Populate responses
        val responses: Array<String> = Utils.getQuickResponses(this)
        Arrays.sort(responses)

        // Add "Custom response..."
        mResponses = arrayOfNulls(responses.size + 1)
        var i: Int
        i = 0
        while (i < responses.size) {
            mResponses!![i] = responses[i]
            i++
        }
        mResponses!![i] = getResources().getString(R.string.quick_response_custom_msg)
        setListAdapter(ArrayAdapter<String>(this, R.layout.quick_response_item,
                                                mResponses as Array<String?>))
    }

    // implements OnItemClickListener
    @Override
    override fun onItemClick(parent: AdapterView<*>?, view: View?, position: Int, id: Long) {
        var body: String? = null
        if (mResponses != null && position < mResponses!!.size - 1) {
            body = mResponses!![position]
        }

        // Start thread to query provider and send mail
        QueryThread(mEventId, body).start()
    }

    private inner class QueryThread internal constructor(var mEventId: Long, var mBody: String?) :
        Thread() {
        @Override
        override fun run() {
        }
    }

    companion object {
        private const val TAG = "QuickResponseActivity"
        const val EXTRA_EVENT_ID = "eventId"
        var mEventId: Long = 0
    }
}