mirror of
https://github.com/quik-sms/quik.git
synced 2026-11-23 06:08:52 +01:00
changes to allow individual widget conversations to launch corresponding compose activity in thread of conversation. widget footer item 'view more conversations' launches main activity/conversations view.
This commit is contained in:
@@ -0,0 +1,60 @@
|
|||||||
|
/*
|
||||||
|
* 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 dev.octoshrimpy.quik.receiver
|
||||||
|
|
||||||
|
import android.content.BroadcastReceiver
|
||||||
|
import android.content.Context
|
||||||
|
import android.content.Intent
|
||||||
|
import android.content.Intent.FLAG_ACTIVITY_NEW_TASK
|
||||||
|
import dagger.android.AndroidInjection
|
||||||
|
|
||||||
|
class StartActivityFromWidgetReceiver : BroadcastReceiver() {
|
||||||
|
// why does this shim class exist rather than the widget launching activities more directly?
|
||||||
|
// the main widget listview items all need to launch the compose activity at an existing
|
||||||
|
// threadId *except* the 'view more conversations' footer item, which needs to launch
|
||||||
|
// the main activity. a listview in a widget *must* use a single pending intent template
|
||||||
|
// for all items which doesn't allow for more than one component/class. this shim class
|
||||||
|
// allows a single component/class for the widget listview pending intent template that, based
|
||||||
|
// on the activityToStart value, launches the appropriate activity
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
const val COMPOSE_ACTIVITY = ".feature.compose.ComposeActivity"
|
||||||
|
const val MAIN_ACTIVITY = ".feature.main.MainActivity"
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onReceive(context: Context, intent: Intent) {
|
||||||
|
AndroidInjection.inject(this, context)
|
||||||
|
|
||||||
|
var activityToStartName = intent.getStringExtra("activityToStart")
|
||||||
|
|
||||||
|
// protect against invalid launch activity
|
||||||
|
activityToStartName = when (activityToStartName) {
|
||||||
|
COMPOSE_ACTIVITY -> activityToStartName
|
||||||
|
MAIN_ACTIVITY -> activityToStartName
|
||||||
|
else -> return
|
||||||
|
}
|
||||||
|
|
||||||
|
context.startActivity(
|
||||||
|
Intent(context, Class.forName(context.packageName + activityToStartName))
|
||||||
|
.setFlags(FLAG_ACTIVITY_NEW_TASK)
|
||||||
|
.putExtra("threadId", intent.getLongExtra("threadId", 0L))
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -219,6 +219,7 @@
|
|||||||
android:resource="@xml/widget_info" />
|
android:resource="@xml/widget_info" />
|
||||||
</receiver>
|
</receiver>
|
||||||
<receiver android:name=".receiver.SendSmsReceiver" />
|
<receiver android:name=".receiver.SendSmsReceiver" />
|
||||||
|
<receiver android:name=".receiver.StartActivityFromWidgetReceiver" />
|
||||||
|
|
||||||
<service android:name="com.android.mms.transaction.TransactionService" />
|
<service android:name="com.android.mms.transaction.TransactionService" />
|
||||||
<service android:name=".feature.backup.RestoreBackupService" />
|
<service android:name=".feature.backup.RestoreBackupService" />
|
||||||
|
|||||||
@@ -19,7 +19,6 @@
|
|||||||
package dev.octoshrimpy.quik.feature.widget
|
package dev.octoshrimpy.quik.feature.widget
|
||||||
|
|
||||||
import android.appwidget.AppWidgetManager
|
import android.appwidget.AppWidgetManager
|
||||||
import android.content.ComponentName
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import android.text.SpannableStringBuilder
|
import android.text.SpannableStringBuilder
|
||||||
@@ -34,12 +33,11 @@ import dev.octoshrimpy.quik.common.util.Colors
|
|||||||
import dev.octoshrimpy.quik.common.util.DateFormatter
|
import dev.octoshrimpy.quik.common.util.DateFormatter
|
||||||
import dev.octoshrimpy.quik.common.util.extensions.dpToPx
|
import dev.octoshrimpy.quik.common.util.extensions.dpToPx
|
||||||
import dev.octoshrimpy.quik.common.util.extensions.getColorCompat
|
import dev.octoshrimpy.quik.common.util.extensions.getColorCompat
|
||||||
import dev.octoshrimpy.quik.feature.compose.ComposeActivity
|
|
||||||
import dev.octoshrimpy.quik.feature.main.MainActivity
|
|
||||||
import dev.octoshrimpy.quik.injection.appComponent
|
import dev.octoshrimpy.quik.injection.appComponent
|
||||||
import dev.octoshrimpy.quik.model.Contact
|
import dev.octoshrimpy.quik.model.Contact
|
||||||
import dev.octoshrimpy.quik.model.Conversation
|
import dev.octoshrimpy.quik.model.Conversation
|
||||||
import dev.octoshrimpy.quik.model.PhoneNumber
|
import dev.octoshrimpy.quik.model.PhoneNumber
|
||||||
|
import dev.octoshrimpy.quik.receiver.StartActivityFromWidgetReceiver
|
||||||
import dev.octoshrimpy.quik.repository.ConversationRepository
|
import dev.octoshrimpy.quik.repository.ConversationRepository
|
||||||
import dev.octoshrimpy.quik.util.GlideApp
|
import dev.octoshrimpy.quik.util.GlideApp
|
||||||
import dev.octoshrimpy.quik.util.Preferences
|
import dev.octoshrimpy.quik.util.Preferences
|
||||||
@@ -163,11 +161,13 @@ class WidgetAdapter(intent: Intent) : RemoteViewsService.RemoteViewsFactory {
|
|||||||
remoteViews.setTextColor(R.id.snippet, if (conversation.unread) textPrimary else textTertiary)
|
remoteViews.setTextColor(R.id.snippet, if (conversation.unread) textPrimary else textTertiary)
|
||||||
remoteViews.setTextViewText(R.id.snippet, boldText(snippet, conversation.unread))
|
remoteViews.setTextViewText(R.id.snippet, boldText(snippet, conversation.unread))
|
||||||
|
|
||||||
// Launch conversation on click
|
// set fill-in intent to be used for current item
|
||||||
val clickIntent = Intent()
|
remoteViews.setOnClickFillInIntent(
|
||||||
.putExtra("screen", "compose")
|
R.id.conversation,
|
||||||
|
Intent()
|
||||||
|
.putExtra("activityToStart", StartActivityFromWidgetReceiver.COMPOSE_ACTIVITY)
|
||||||
.putExtra("threadId", conversation.id)
|
.putExtra("threadId", conversation.id)
|
||||||
remoteViews.setOnClickFillInIntent(R.id.conversation, clickIntent)
|
)
|
||||||
|
|
||||||
return remoteViews
|
return remoteViews
|
||||||
}
|
}
|
||||||
@@ -176,7 +176,11 @@ class WidgetAdapter(intent: Intent) : RemoteViewsService.RemoteViewsFactory {
|
|||||||
val view = RemoteViews(context.packageName, R.layout.widget_loading)
|
val view = RemoteViews(context.packageName, R.layout.widget_loading)
|
||||||
view.setTextColor(R.id.loadingText, textSecondary)
|
view.setTextColor(R.id.loadingText, textSecondary)
|
||||||
view.setTextViewText(R.id.loadingText, context.getString(R.string.widget_more))
|
view.setTextViewText(R.id.loadingText, context.getString(R.string.widget_more))
|
||||||
view.setOnClickFillInIntent(R.id.loading, Intent())
|
view.setOnClickFillInIntent(
|
||||||
|
R.id.loadingText,
|
||||||
|
Intent()
|
||||||
|
.putExtra("activityToStart", StartActivityFromWidgetReceiver.MAIN_ACTIVITY)
|
||||||
|
)
|
||||||
return view
|
return view
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -35,6 +35,7 @@ import dev.octoshrimpy.quik.common.util.extensions.getColorCompat
|
|||||||
import dev.octoshrimpy.quik.feature.compose.ComposeActivity
|
import dev.octoshrimpy.quik.feature.compose.ComposeActivity
|
||||||
import dev.octoshrimpy.quik.feature.main.MainActivity
|
import dev.octoshrimpy.quik.feature.main.MainActivity
|
||||||
import dev.octoshrimpy.quik.manager.WidgetManager
|
import dev.octoshrimpy.quik.manager.WidgetManager
|
||||||
|
import dev.octoshrimpy.quik.receiver.StartActivityFromWidgetReceiver
|
||||||
import dev.octoshrimpy.quik.util.Preferences
|
import dev.octoshrimpy.quik.util.Preferences
|
||||||
import timber.log.Timber
|
import timber.log.Timber
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
@@ -129,8 +130,6 @@ class WidgetProvider : AppWidgetProvider() {
|
|||||||
false -> R.color.textPrimary
|
false -> R.color.textPrimary
|
||||||
}))
|
}))
|
||||||
|
|
||||||
remoteViews.setInt(R.id.compose, "setColorFilter", colors.theme().theme)
|
|
||||||
|
|
||||||
// Set adapter for conversations
|
// Set adapter for conversations
|
||||||
val intent = Intent(context, WidgetService::class.java)
|
val intent = Intent(context, WidgetService::class.java)
|
||||||
.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId)
|
.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId)
|
||||||
@@ -138,20 +137,40 @@ class WidgetProvider : AppWidgetProvider() {
|
|||||||
intent.data = Uri.parse(intent.toUri(Intent.URI_INTENT_SCHEME))
|
intent.data = Uri.parse(intent.toUri(Intent.URI_INTENT_SCHEME))
|
||||||
remoteViews.setRemoteAdapter(R.id.conversations, intent)
|
remoteViews.setRemoteAdapter(R.id.conversations, intent)
|
||||||
|
|
||||||
// Main intent
|
// compose new message image color and on click intent
|
||||||
val mainIntent = Intent(context, MainActivity::class.java)
|
remoteViews.setInt(R.id.compose, "setColorFilter", colors.theme().theme)
|
||||||
val mainPI = PendingIntent.getActivity(context, 0, mainIntent, PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_IMMUTABLE)
|
remoteViews.setOnClickPendingIntent(
|
||||||
remoteViews.setOnClickPendingIntent(R.id.title, mainPI)
|
R.id.compose,
|
||||||
|
PendingIntent.getActivity(
|
||||||
|
context,
|
||||||
|
0,
|
||||||
|
Intent(context, ComposeActivity::class.java),
|
||||||
|
PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_IMMUTABLE
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
// Compose intent
|
// use a single pending intent for launching main activity because they
|
||||||
val composeIntent = Intent(context, ComposeActivity::class.java)
|
// can sometimes be in short supply in the OS
|
||||||
val composePI = PendingIntent.getActivity(context, 0, composeIntent, PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_IMMUTABLE)
|
val mainActivityPendingIntent = PendingIntent.getActivity(
|
||||||
remoteViews.setOnClickPendingIntent(R.id.compose, composePI)
|
context,
|
||||||
|
99,
|
||||||
|
Intent(context, MainActivity::class.java),
|
||||||
|
PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_IMMUTABLE
|
||||||
|
)
|
||||||
|
|
||||||
// Conversation intent
|
// title click to load app main activity / conversation view
|
||||||
val startActivityIntent = Intent(context, MainActivity::class.java)
|
remoteViews.setOnClickPendingIntent(R.id.title, mainActivityPendingIntent)
|
||||||
val startActivityPendingIntent = PendingIntent.getActivity(context, 0, startActivityIntent, PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_IMMUTABLE)
|
|
||||||
remoteViews.setPendingIntentTemplate(R.id.conversations, startActivityPendingIntent)
|
// pending intent template to be used for all list items
|
||||||
|
remoteViews.setPendingIntentTemplate(
|
||||||
|
R.id.conversations,
|
||||||
|
PendingIntent.getBroadcast(
|
||||||
|
context,
|
||||||
|
1,
|
||||||
|
Intent(context, StartActivityFromWidgetReceiver::class.java),
|
||||||
|
PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_MUTABLE
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
AppWidgetManager.getInstance(context).updateAppWidget(appWidgetId, remoteViews)
|
AppWidgetManager.getInstance(context).updateAppWidget(appWidgetId, remoteViews)
|
||||||
}
|
}
|
||||||
|
|||||||
+5
@@ -41,6 +41,7 @@ import dev.octoshrimpy.quik.receiver.SmsSentReceiver
|
|||||||
import dagger.Module
|
import dagger.Module
|
||||||
import dagger.android.ContributesAndroidInjector
|
import dagger.android.ContributesAndroidInjector
|
||||||
import dev.octoshrimpy.quik.receiver.SpeakThreadsReceiver
|
import dev.octoshrimpy.quik.receiver.SpeakThreadsReceiver
|
||||||
|
import dev.octoshrimpy.quik.receiver.StartActivityFromWidgetReceiver
|
||||||
|
|
||||||
@Module
|
@Module
|
||||||
abstract class BroadcastReceiverBuilderModule {
|
abstract class BroadcastReceiverBuilderModule {
|
||||||
@@ -73,6 +74,10 @@ abstract class BroadcastReceiverBuilderModule {
|
|||||||
@ContributesAndroidInjector()
|
@ContributesAndroidInjector()
|
||||||
abstract fun bindSpeakThreadsReceiver(): SpeakThreadsReceiver
|
abstract fun bindSpeakThreadsReceiver(): SpeakThreadsReceiver
|
||||||
|
|
||||||
|
@ActivityScope
|
||||||
|
@ContributesAndroidInjector()
|
||||||
|
abstract fun bindStartActivityFromWidgetReceiver(): StartActivityFromWidgetReceiver
|
||||||
|
|
||||||
@ActivityScope
|
@ActivityScope
|
||||||
@ContributesAndroidInjector()
|
@ContributesAndroidInjector()
|
||||||
abstract fun bindMarkSeenReceiver(): MarkSeenReceiver
|
abstract fun bindMarkSeenReceiver(): MarkSeenReceiver
|
||||||
|
|||||||
@@ -24,6 +24,7 @@
|
|||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:background="@drawable/ripple"
|
android:background="@drawable/ripple"
|
||||||
|
android:clickable="false"
|
||||||
android:gravity="center_vertical|start"
|
android:gravity="center_vertical|start"
|
||||||
android:orientation="horizontal"
|
android:orientation="horizontal"
|
||||||
android:paddingLeft="16dp"
|
android:paddingLeft="16dp"
|
||||||
@@ -36,12 +37,14 @@
|
|||||||
android:layout_width="48dp"
|
android:layout_width="48dp"
|
||||||
android:layout_height="48dp"
|
android:layout_height="48dp"
|
||||||
android:layout_marginEnd="16dp"
|
android:layout_marginEnd="16dp"
|
||||||
|
android:clickable="false"
|
||||||
tools:background="@color/tools_theme">
|
tools:background="@color/tools_theme">
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/initial"
|
android:id="@+id/initial"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
|
android:clickable="false"
|
||||||
android:gravity="center"
|
android:gravity="center"
|
||||||
android:textAllCaps="true"
|
android:textAllCaps="true"
|
||||||
android:textSize="20sp"
|
android:textSize="20sp"
|
||||||
@@ -53,6 +56,7 @@
|
|||||||
android:layout_width="24dp"
|
android:layout_width="24dp"
|
||||||
android:layout_height="24dp"
|
android:layout_height="24dp"
|
||||||
android:layout_gravity="center"
|
android:layout_gravity="center"
|
||||||
|
android:clickable="false"
|
||||||
android:src="@drawable/ic_person_black_24dp"
|
android:src="@drawable/ic_person_black_24dp"
|
||||||
tools:tint="@color/textPrimaryDark" />
|
tools:tint="@color/textPrimaryDark" />
|
||||||
|
|
||||||
@@ -60,19 +64,22 @@
|
|||||||
android:id="@+id/photo"
|
android:id="@+id/photo"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
|
android:clickable="false"
|
||||||
tools:src="@tools:sample/avatars" />
|
tools:src="@tools:sample/avatars" />
|
||||||
|
|
||||||
<ImageView
|
<ImageView
|
||||||
android:id="@+id/avatarMask"
|
android:id="@+id/avatarMask"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
|
android:clickable="false"
|
||||||
android:src="@drawable/circle_mask" />
|
android:src="@drawable/circle_mask" />
|
||||||
|
|
||||||
</FrameLayout>
|
</FrameLayout>
|
||||||
|
|
||||||
<RelativeLayout
|
<RelativeLayout
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content">
|
android:layout_height="wrap_content"
|
||||||
|
android:clickable="false">
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/name"
|
android:id="@+id/name"
|
||||||
@@ -80,6 +87,7 @@
|
|||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_alignParentStart="true"
|
android:layout_alignParentStart="true"
|
||||||
android:layout_toStartOf="@+id/date"
|
android:layout_toStartOf="@+id/date"
|
||||||
|
android:clickable="false"
|
||||||
android:singleLine="true"
|
android:singleLine="true"
|
||||||
android:textSize="16sp"
|
android:textSize="16sp"
|
||||||
tools:text="@tools:sample/full_names" />
|
tools:text="@tools:sample/full_names" />
|
||||||
@@ -91,6 +99,7 @@
|
|||||||
android:layout_alignParentTop="true"
|
android:layout_alignParentTop="true"
|
||||||
android:layout_alignParentEnd="true"
|
android:layout_alignParentEnd="true"
|
||||||
android:layout_marginStart="16dp"
|
android:layout_marginStart="16dp"
|
||||||
|
android:clickable="false"
|
||||||
android:textSize="12sp"
|
android:textSize="12sp"
|
||||||
tools:text="@tools:sample/date/day_of_week" />
|
tools:text="@tools:sample/date/day_of_week" />
|
||||||
|
|
||||||
@@ -100,6 +109,7 @@
|
|||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_below="@id/name"
|
android:layout_below="@id/name"
|
||||||
android:layout_alignParentStart="true"
|
android:layout_alignParentStart="true"
|
||||||
|
android:clickable="false"
|
||||||
android:lines="1"
|
android:lines="1"
|
||||||
android:singleLine="true"
|
android:singleLine="true"
|
||||||
android:textSize="14sp"
|
android:textSize="14sp"
|
||||||
|
|||||||
Reference in New Issue
Block a user