Reorganize presentation package

This commit is contained in:
Moez Bhatti
2018-01-04 01:03:08 -05:00
parent 2d90791a9f
commit f02bdde618
40 changed files with 81 additions and 79 deletions
@@ -0,0 +1,50 @@
/*
* Copyright (C) 2017 Moez Bhatti <moez.bhatti@gmail.com>
*
* This file is part of QKSMS.
*
* QKSMS is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* QKSMS is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with QKSMS. If not, see <http://www.gnu.org/licenses/>.
*/
package presentation.receiver
import android.content.BroadcastReceiver
import android.content.Context
import android.content.Intent
import android.os.Build
import android.provider.Telephony
import android.support.annotation.RequiresApi
import common.di.appComponent
import common.util.Preferences
import interactor.PartialSync
import javax.inject.Inject
class DefaultSmsChangedReceiver : BroadcastReceiver() {
@Inject lateinit var partialSync: PartialSync
@Inject lateinit var prefs: Preferences
@RequiresApi(Build.VERSION_CODES.N)
override fun onReceive(context: Context, intent: Intent) {
appComponent.inject(this)
val isDefaultSmsApp = intent.getBooleanExtra(Telephony.Sms.Intents.EXTRA_IS_DEFAULT_SMS_APP, false)
prefs.defaultSms.set(isDefaultSmsApp)
if (isDefaultSmsApp) {
val pendingResult = goAsync()
partialSync.execute(Unit, { pendingResult.finish() })
}
}
}
@@ -0,0 +1,39 @@
/*
* Copyright (C) 2017 Moez Bhatti <moez.bhatti@gmail.com>
*
* This file is part of QKSMS.
*
* QKSMS is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* QKSMS is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with QKSMS. If not, see <http://www.gnu.org/licenses/>.
*/
package presentation.receiver
import android.content.BroadcastReceiver
import android.content.Context
import android.content.Intent
import common.di.appComponent
import interactor.MarkRead
import javax.inject.Inject
class MarkReadReceiver : BroadcastReceiver() {
@Inject lateinit var markRead: MarkRead
override fun onReceive(context: Context, intent: Intent) {
appComponent.inject(this)
val threadId = intent.getLongExtra("threadId", 0)
markRead.execute(threadId)
}
}
@@ -0,0 +1,39 @@
/*
* Copyright (C) 2017 Moez Bhatti <moez.bhatti@gmail.com>
*
* This file is part of QKSMS.
*
* QKSMS is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* QKSMS is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with QKSMS. If not, see <http://www.gnu.org/licenses/>.
*/
package presentation.receiver
import android.content.BroadcastReceiver
import android.content.Context
import android.content.Intent
import common.di.appComponent
import interactor.MarkSeen
import javax.inject.Inject
class MarkSeenReceiver : BroadcastReceiver() {
@Inject lateinit var markSeen: MarkSeen
override fun onReceive(context: Context, intent: Intent) {
appComponent.inject(this)
val threadId = intent.getLongExtra("threadId", 0)
markSeen.execute(threadId)
}
}
@@ -0,0 +1,57 @@
/*
* Copyright (C) 2017 Moez Bhatti <moez.bhatti@gmail.com>
*
* This file is part of QKSMS.
*
* QKSMS is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* QKSMS is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with QKSMS. If not, see <http://www.gnu.org/licenses/>.
*/
package presentation.receiver
import android.app.Activity
import android.content.BroadcastReceiver
import android.content.Context
import android.content.Intent
import common.di.appComponent
import interactor.MarkDelivered
import interactor.MarkDeliveryFailed
import javax.inject.Inject
class MessageDeliveredReceiver : BroadcastReceiver() {
@Inject lateinit var markDelivered: MarkDelivered
@Inject lateinit var markDeliveryFailed: MarkDeliveryFailed
init {
appComponent.inject(this)
}
override fun onReceive(context: Context, intent: Intent) {
val id = intent.getLongExtra("id", 0L)
when (resultCode) {
// TODO notify about delivery
Activity.RESULT_OK -> {
val pendingResult = goAsync()
markDelivered.execute(id) { pendingResult.finish() }
}
// TODO notify about delivery failure
Activity.RESULT_CANCELED -> {
val pendingResult = goAsync()
markDeliveryFailed.execute(MarkDeliveryFailed.Params(id, resultCode)) { pendingResult.finish() }
}
}
}
}
@@ -0,0 +1,56 @@
/*
* Copyright (C) 2017 Moez Bhatti <moez.bhatti@gmail.com>
*
* This file is part of QKSMS.
*
* QKSMS is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* QKSMS is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with QKSMS. If not, see <http://www.gnu.org/licenses/>.
*/
package presentation.receiver
import android.app.Activity
import android.content.BroadcastReceiver
import android.content.Context
import android.content.Intent
import android.telephony.SmsManager
import common.di.appComponent
import interactor.MarkFailed
import interactor.MarkSent
import javax.inject.Inject
class MessageSentReceiver : BroadcastReceiver() {
@Inject lateinit var markSent: MarkSent
@Inject lateinit var markFailed: MarkFailed
override fun onReceive(context: Context, intent: Intent) {
appComponent.inject(this)
val id = intent.getLongExtra("id", 0L)
when (resultCode) {
Activity.RESULT_OK -> {
val pendingResult = goAsync()
markSent.execute(id) { pendingResult.finish() }
}
SmsManager.RESULT_ERROR_GENERIC_FAILURE,
SmsManager.RESULT_ERROR_NO_SERVICE,
SmsManager.RESULT_ERROR_NULL_PDU,
SmsManager.RESULT_ERROR_RADIO_OFF -> {
val pendingResult = goAsync()
markFailed.execute(MarkFailed.Params(id, resultCode)) { pendingResult.finish() }
}
}
}
}
@@ -0,0 +1,69 @@
/*
* Copyright (C) 2017 Moez Bhatti <moez.bhatti@gmail.com>
*
* This file is part of QKSMS.
*
* QKSMS is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* QKSMS is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with QKSMS. If not, see <http://www.gnu.org/licenses/>.
*/
package presentation.receiver
import android.content.BroadcastReceiver
import android.content.Context
import android.content.Intent
import android.provider.Telephony
import com.google.android.mms.ContentType
import com.google.android.mms.pdu.GenericPdu
import com.google.android.mms.pdu.NotificationInd
import com.google.android.mms.pdu.PduHeaders
import com.google.android.mms.pdu.PduParser
import timber.log.Timber
class MmsReceiver : BroadcastReceiver() {
override fun onReceive(context: Context, intent: Intent) {
if (Telephony.Sms.Intents.WAP_PUSH_RECEIVED_ACTION == intent.action && ContentType.MMS_MESSAGE == intent.type) {
val data = intent.getByteArrayExtra("data")
val parser = PduParser(data)
var pdu: GenericPdu? = null
try {
pdu = parser.parse()
} catch (e: RuntimeException) {
Timber.e("Invalid MMS WAP push", e)
}
if (pdu == null) {
Timber.e("Invalid WAP push data")
return
}
when (pdu.messageType) {
PduHeaders.MESSAGE_TYPE_NOTIFICATION_IND -> {
val notificationInd = pdu as NotificationInd
val location = String(notificationInd.contentLocation)
Timber.v("Received MMS notification: " + location)
}
PduHeaders.MESSAGE_TYPE_DELIVERY_IND -> {
Timber.v("Received delivery report")
}
PduHeaders.MESSAGE_TYPE_READ_ORIG_IND -> {
Timber.v("Received read report")
}
}
}
}
}
@@ -0,0 +1,48 @@
/*
* Copyright (C) 2017 Moez Bhatti <moez.bhatti@gmail.com>
*
* This file is part of QKSMS.
*
* QKSMS is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* QKSMS is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with QKSMS. If not, see <http://www.gnu.org/licenses/>.
*/
package presentation.receiver
import android.content.BroadcastReceiver
import android.content.Context
import android.content.Intent
import android.support.v4.app.RemoteInput
import common.di.appComponent
import interactor.MarkRead
import interactor.SendMessage
import javax.inject.Inject
class RemoteMessagingReceiver : BroadcastReceiver() {
@Inject lateinit var sendMessage: SendMessage
@Inject lateinit var markRead: MarkRead
override fun onReceive(context: Context, intent: Intent) {
appComponent.inject(this)
val remoteInput = RemoteInput.getResultsFromIntent(intent)
val bundle = intent.extras
if (remoteInput != null && bundle != null) {
val address = bundle.getString("address")
val threadId = bundle.getLong("threadId")
val body = remoteInput.getCharSequence("body").toString()
markRead.execute(threadId)
sendMessage.execute(SendMessage.Params(threadId, address, body))
}
}
}
@@ -0,0 +1,51 @@
/*
* Copyright (C) 2017 Moez Bhatti <moez.bhatti@gmail.com>
*
* This file is part of QKSMS.
*
* QKSMS is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* QKSMS is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with QKSMS. If not, see <http://www.gnu.org/licenses/>.
*/
package presentation.receiver
import android.content.BroadcastReceiver
import android.content.Context
import android.content.Intent
import android.provider.Telephony.Sms
import common.di.appComponent
import interactor.ReceiveMessage
import timber.log.Timber
import javax.inject.Inject
class SmsReceiver : BroadcastReceiver() {
@Inject lateinit var receiveMessage: ReceiveMessage
override fun onReceive(context: Context, intent: Intent) {
Timber.v("Received SMS: $intent")
appComponent.inject(this)
val messages = Sms.Intents.getMessagesFromIntent(intent)
messages?.takeIf { it.isNotEmpty() }?.let { messages ->
val address = messages[0].displayOriginatingAddress
val time = messages[0].timestampMillis
val body: String = messages
.map { message -> message.displayMessageBody }
.reduce { body, new -> body + new }
val pendingResult = goAsync()
receiveMessage.execute(ReceiveMessage.Params(address, body, time), { pendingResult.finish() })
}
}
}