Flatten hierarchy in presentation module

This commit is contained in:
Moez Bhatti
2018-03-22 01:43:09 -04:00
parent 2e4d96059a
commit 7212983ffe
95 changed files with 51 additions and 65 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 injection.appComponent
import 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 injection.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 injection.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,40 @@
/*
* 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.net.Uri
import com.klinker.android.send_message.MmsReceivedReceiver
import injection.appComponent
import interactor.ReceiveMms
import javax.inject.Inject
class MmsReceivedReceiver : MmsReceivedReceiver() {
@Inject lateinit var receiveMms: ReceiveMms
override fun onMessageReceived(messageUri: Uri?) {
appComponent.inject(this)
messageUri?.let { uri ->
val pendingResult = goAsync()
receiveMms.execute(uri) { pendingResult.finish() }
}
}
}
@@ -0,0 +1,23 @@
/*
* 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 com.android.mms.transaction.PushReceiver
class MmsReceiver : PushReceiver()
@@ -0,0 +1,43 @@
/*
* 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.Context
import android.content.Intent
import android.net.Uri
import com.klinker.android.send_message.MmsSentReceiver
import injection.appComponent
import interactor.SyncMessage
import javax.inject.Inject
class MmsSentReceiver : MmsSentReceiver() {
@Inject lateinit var syncMessage: SyncMessage
override fun onReceive(context: Context, intent: Intent) {
super.onReceive(context, intent)
appComponent.inject(this)
Uri.parse(intent.getStringExtra("content_uri"))?.let { uri ->
val pendingResult = goAsync()
syncMessage.execute(uri) { pendingResult.finish() }
}
}
}
@@ -0,0 +1,45 @@
/*
* 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.net.Uri
import injection.appComponent
import interactor.SyncMessage
import javax.inject.Inject
class MmsUpdatedReceiver : BroadcastReceiver() {
companion object {
const val URI = "uri"
}
@Inject lateinit var syncMessage: SyncMessage
override fun onReceive(context: Context, intent: Intent) {
appComponent.inject(this)
intent.getStringExtra(URI)?.let { uriString ->
val pendingResult = goAsync()
syncMessage.execute(Uri.parse(uriString)) { 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 injection.appComponent
import common.util.NightModeManager
import javax.inject.Inject
class NightModeReceiver : BroadcastReceiver() {
@Inject lateinit var nightModeManager: NightModeManager
init {
appComponent.inject(this)
}
override fun onReceive(context: Context, intent: Intent) {
nightModeManager.updateCurrentTheme()
}
}
@@ -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 injection.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, listOf(address), body))
}
}
}
@@ -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 injection.appComponent
import interactor.MarkDelivered
import interactor.MarkDeliveryFailed
import javax.inject.Inject
class SmsDeliveredReceiver : 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,54 @@
/*
* 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 injection.appComponent
import interactor.SyncMessage
import javax.inject.Inject
/**
* When the SMS contentprovider is changed by a process other than us, we need to sync the Uri that
* was changed.
*
* This can happen if a message is sent through something like Pushbullet or Google Assistant.
*
* This only works on API 24+, so to fully solve this problem we'll need a smarter way of running
* partial syncs on older devices.
*
* https://developer.android.com/reference/android/provider/Telephony.Sms.Intents.html#ACTION_EXTERNAL_PROVIDER_CHANGE
*/
class SmsProviderChangedReceiver : BroadcastReceiver() {
@Inject lateinit var syncMessage: SyncMessage
override fun onReceive(context: Context, intent: Intent) {
appComponent.inject(this)
// Obtain the uri for the changed data
val uri = intent.data
// Sync the message to our realm
val pendingResult = goAsync()
syncMessage.execute(uri) { pendingResult.finish() }
}
}
@@ -0,0 +1,42 @@
/*
* 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 injection.appComponent
import interactor.ReceiveSms
import javax.inject.Inject
class SmsReceiver : BroadcastReceiver() {
@Inject lateinit var receiveMessage: ReceiveSms
override fun onReceive(context: Context, intent: Intent) {
appComponent.inject(this)
Sms.Intents.getMessagesFromIntent(intent)?.let { messages ->
val pendingResult = goAsync()
receiveMessage.execute(messages, { 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 injection.appComponent
import interactor.MarkFailed
import interactor.MarkSent
import javax.inject.Inject
class SmsSentReceiver : 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() }
}
}
}
}