Skip to content

Commit

Permalink
Removed the DI pattern and added the unread messages in the FakeData.…
Browse files Browse the repository at this point in the history
…kt class as initially implemented. Also propagating the requiresApi check to WidgetDiscoverability composable.
  • Loading branch information
shangeethsivan committed Jan 9, 2025
1 parent 5ca6e31 commit 668120e
Show file tree
Hide file tree
Showing 6 changed files with 9 additions and 72 deletions.
1 change: 0 additions & 1 deletion Jetchat/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:name=".JetchatApplication"
android:theme="@style/Theme.Jetchat.NoActionBar">

<activity
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import android.content.Context
import android.os.Build
import androidx.annotation.ChecksSdkIntAtLeast
import androidx.annotation.DrawableRes
import androidx.annotation.RequiresApi
import androidx.compose.foundation.Image
import androidx.compose.foundation.background
import androidx.compose.foundation.clickable
Expand Down Expand Up @@ -226,6 +227,7 @@ fun DrawerPreviewDark() {
}
}

@RequiresApi(Build.VERSION_CODES.O)
@Composable
private fun WidgetDiscoverability() {
val context = LocalContext.current
Expand All @@ -249,6 +251,7 @@ private fun WidgetDiscoverability() {
}
}

@RequiresApi(Build.VERSION_CODES.O)
private fun addWidgetToHomeScreen(context: Context) {
val appWidgetManager = AppWidgetManager.getInstance(context)
val myProvider = ComponentName(context, WidgetReceiver::class.java)
Expand All @@ -259,7 +262,6 @@ private fun addWidgetToHomeScreen(context: Context) {

@ChecksSdkIntAtLeast(api = Build.VERSION_CODES.O)
private fun widgetAddingIsSupported(context: Context): Boolean {
val appWidgetManager = AppWidgetManager.getInstance(context)
return Build.VERSION.SDK_INT >=
Build.VERSION_CODES.O && appWidgetManager.isRequestPinAppWidgetSupported
return Build.VERSION.SDK_INT >= Build.VERSION_CODES.O
&& AppWidgetManager.getInstance(context).isRequestPinAppWidgetSupported
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ val initialMessages = listOf(
),
)

val unreadMessages = initialMessages.filter { it.author != "me" }

val exampleUiState = ConversationUiState(
initialMessages = initialMessages,
channelName = "#composers",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,15 @@ import androidx.glance.GlanceId
import androidx.glance.GlanceTheme
import androidx.glance.appwidget.GlanceAppWidget
import androidx.glance.appwidget.provideContent
import com.example.compose.jetchat.JetchatApplication
import com.example.compose.jetchat.data.unreadMessages
import com.example.compose.jetchat.widget.composables.MessagesWidget

class JetChatWidget : GlanceAppWidget() {

override suspend fun provideGlance(context: Context, id: GlanceId) {
val application = context.applicationContext as JetchatApplication
val messagesRepository = application.container.messagesRepository

provideContent {
val bookmarks = messagesRepository.observeUnReadMessages()
GlanceTheme {
MessagesWidget(bookmarks.toList())
MessagesWidget(unreadMessages.toList())
}
}
}
Expand Down

0 comments on commit 668120e

Please sign in to comment.