Update widgets for Android 12
This commit is contained in:
@@ -7,6 +7,8 @@ import android.widget.RemoteViewsService
|
||||
import coil.ImageLoader
|
||||
import coil.executeBlocking
|
||||
import coil.request.ImageRequest
|
||||
import coil.size.Size
|
||||
import coil.transform.RoundedCornersTransformation
|
||||
import kotlinx.coroutines.runBlocking
|
||||
import org.koitharu.kotatsu.R
|
||||
import org.koitharu.kotatsu.base.domain.MangaIntent
|
||||
@@ -22,9 +24,15 @@ class RecentListFactory(
|
||||
) : RemoteViewsService.RemoteViewsFactory {
|
||||
|
||||
private val dataSet = ArrayList<Manga>()
|
||||
private val transformation = RoundedCornersTransformation(
|
||||
context.resources.getDimension(R.dimen.appwidget_corner_radius_inner)
|
||||
)
|
||||
private val coverSize = Size(
|
||||
context.resources.getDimensionPixelSize(R.dimen.widget_cover_width),
|
||||
context.resources.getDimensionPixelSize(R.dimen.widget_cover_height),
|
||||
)
|
||||
|
||||
override fun onCreate() {
|
||||
}
|
||||
override fun onCreate() = Unit
|
||||
|
||||
override fun getLoadingView() = null
|
||||
|
||||
@@ -45,6 +53,8 @@ class RecentListFactory(
|
||||
val cover = coil.executeBlocking(
|
||||
ImageRequest.Builder(context)
|
||||
.data(item.coverUrl)
|
||||
.size(coverSize)
|
||||
.transformations(transformation)
|
||||
.build()
|
||||
).requireBitmap()
|
||||
views.setImageViewBitmap(R.id.imageView_cover, cover)
|
||||
@@ -61,6 +71,5 @@ class RecentListFactory(
|
||||
|
||||
override fun getViewTypeCount() = 1
|
||||
|
||||
override fun onDestroy() {
|
||||
}
|
||||
override fun onDestroy() = Unit
|
||||
}
|
||||
@@ -10,8 +10,6 @@ import androidx.core.graphics.Insets
|
||||
import androidx.core.view.isVisible
|
||||
import androidx.core.view.updateLayoutParams
|
||||
import androidx.core.view.updatePadding
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import com.google.android.material.divider.MaterialDividerItemDecoration
|
||||
import com.google.android.material.snackbar.Snackbar
|
||||
import org.koin.androidx.viewmodel.ext.android.viewModel
|
||||
import org.koitharu.kotatsu.R
|
||||
@@ -40,9 +38,6 @@ class ShelfConfigActivity : BaseActivity<ActivityCategoriesBinding>(),
|
||||
setHomeAsUpIndicator(materialR.drawable.abc_ic_clear_material)
|
||||
}
|
||||
adapter = CategorySelectAdapter(this)
|
||||
binding.recyclerView.addItemDecoration(
|
||||
MaterialDividerItemDecoration(this, RecyclerView.VERTICAL)
|
||||
)
|
||||
binding.recyclerView.adapter = adapter
|
||||
binding.buttonDone.isVisible = true
|
||||
binding.buttonDone.setOnClickListener(this)
|
||||
|
||||
@@ -7,6 +7,8 @@ import android.widget.RemoteViewsService
|
||||
import coil.ImageLoader
|
||||
import coil.executeBlocking
|
||||
import coil.request.ImageRequest
|
||||
import coil.size.Size
|
||||
import coil.transform.RoundedCornersTransformation
|
||||
import kotlinx.coroutines.runBlocking
|
||||
import org.koitharu.kotatsu.R
|
||||
import org.koitharu.kotatsu.base.domain.MangaIntent
|
||||
@@ -20,14 +22,20 @@ class ShelfListFactory(
|
||||
private val context: Context,
|
||||
private val favouritesRepository: FavouritesRepository,
|
||||
private val coil: ImageLoader,
|
||||
widgetId: Int
|
||||
widgetId: Int,
|
||||
) : RemoteViewsService.RemoteViewsFactory {
|
||||
|
||||
private val dataSet = ArrayList<Manga>()
|
||||
private val config = AppWidgetConfig(context, widgetId)
|
||||
private val transformation = RoundedCornersTransformation(
|
||||
context.resources.getDimension(R.dimen.appwidget_corner_radius_inner)
|
||||
)
|
||||
private val coverSize = Size(
|
||||
context.resources.getDimensionPixelSize(R.dimen.widget_cover_width),
|
||||
context.resources.getDimensionPixelSize(R.dimen.widget_cover_height),
|
||||
)
|
||||
|
||||
override fun onCreate() {
|
||||
}
|
||||
override fun onCreate() = Unit
|
||||
|
||||
override fun getLoadingView() = null
|
||||
|
||||
@@ -56,6 +64,8 @@ class ShelfListFactory(
|
||||
val cover = coil.executeBlocking(
|
||||
ImageRequest.Builder(context)
|
||||
.data(item.coverUrl)
|
||||
.size(coverSize)
|
||||
.transformations(transformation)
|
||||
.build()
|
||||
).requireBitmap()
|
||||
views.setImageViewBitmap(R.id.imageView_cover, cover)
|
||||
|
||||
7
app/src/main/res/drawable/bg_appwidget_card.xml
Normal file
7
app/src/main/res/drawable/bg_appwidget_card.xml
Normal file
@@ -0,0 +1,7 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<shape
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:shape="rectangle">
|
||||
<corners android:radius="@dimen/appwidget_corner_radius_inner" />
|
||||
<solid android:color="?android:panelColorBackground" />
|
||||
</shape>
|
||||
@@ -3,7 +3,7 @@
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:id="@+id/imageView_cover"
|
||||
android:layout_width="92dp"
|
||||
android:layout_height="128dp"
|
||||
android:layout_width="@dimen/widget_cover_width"
|
||||
android:layout_height="@dimen/widget_cover_height"
|
||||
android:scaleType="centerCrop"
|
||||
tools:ignore="ContentDescription" />
|
||||
@@ -3,21 +3,24 @@
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content">
|
||||
android:layout_height="wrap_content"
|
||||
android:padding="4dp"
|
||||
android:theme="@style/Theme.Kotatsu.AppWidgetContainer">
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/rootLayout"
|
||||
android:layout_width="92dp"
|
||||
android:layout_width="@dimen/widget_cover_width"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center_horizontal"
|
||||
android:background="@drawable/bg_appwidget_card"
|
||||
android:foreground="?android:selectableItemBackground"
|
||||
android:orientation="vertical"
|
||||
android:paddingBottom="4dp"
|
||||
tools:ignore="UselessParent">
|
||||
tools:ignore="UnusedAttribute,UselessParent">
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/imageView_cover"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="128dp"
|
||||
android:layout_height="@dimen/widget_cover_height"
|
||||
android:scaleType="centerCrop"
|
||||
tools:ignore="ContentDescription" />
|
||||
|
||||
@@ -25,12 +28,12 @@
|
||||
android:id="@+id/textView_title"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:elegantTextHeight="false"
|
||||
android:ellipsize="end"
|
||||
android:gravity="center"
|
||||
android:lines="2"
|
||||
android:shadowColor="@android:color/black"
|
||||
android:shadowRadius="1"
|
||||
android:textColor="@android:color/white" />
|
||||
android:paddingHorizontal="4dp"
|
||||
android:paddingBottom="4dp"
|
||||
android:textColor="?android:attr/textColorPrimary" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
android:id="@+id/stackView"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
tools:listitem="@layout/item_shelf" />
|
||||
tools:listitem="@layout/item_recent" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/textView_holder"
|
||||
|
||||
@@ -2,7 +2,10 @@
|
||||
<FrameLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
android:layout_height="match_parent"
|
||||
android:background="?android:attr/colorBackground"
|
||||
android:padding="4dp"
|
||||
android:theme="@style/Theme.Kotatsu.AppWidgetContainer">
|
||||
|
||||
<GridView
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
@@ -21,9 +24,7 @@
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center"
|
||||
android:gravity="center"
|
||||
android:shadowColor="@android:color/black"
|
||||
android:shadowRadius="1"
|
||||
android:text="@string/you_have_not_favourites_yet"
|
||||
android:textColor="@android:color/white" />
|
||||
android:textColor="?android:attr/textColorPrimary" />
|
||||
|
||||
</FrameLayout>
|
||||
4
app/src/main/res/values-v31/dimens.xml
Normal file
4
app/src/main/res/values-v31/dimens.xml
Normal file
@@ -0,0 +1,4 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
<dimen name="appwidget_corner_radius_inner">@android:dimen/system_app_widget_inner_radius</dimen>
|
||||
</resources>
|
||||
@@ -41,4 +41,10 @@
|
||||
<item name="android:textColorHighlightInverse">@color/m3_dynamic_dark_highlighted_text</item>
|
||||
<item name="android:textColorAlertDialogListItem">@color/m3_dynamic_default_color_primary_text</item>
|
||||
</style>
|
||||
|
||||
<style name="Theme.Kotatsu.AppWidgetContainer" parent="@android:style/Theme.DeviceDefault.DayNight">
|
||||
<item name="android:colorBackground">@android:color/system_accent1_50</item>
|
||||
<item name="android:panelColorBackground">@android:color/system_accent1_100</item>
|
||||
</style>
|
||||
|
||||
</resources>
|
||||
@@ -24,10 +24,14 @@
|
||||
<dimen name="selection_stroke_width">2dp</dimen>
|
||||
<dimen name="list_selector_corner">12dp</dimen>
|
||||
<dimen name="toolbar_button_margin">10dp</dimen>
|
||||
<dimen name="widget_cover_height">116dp</dimen>
|
||||
<dimen name="widget_cover_width">84dp</dimen>
|
||||
|
||||
<dimen name="search_suggestions_manga_height">124dp</dimen>
|
||||
<dimen name="search_suggestions_manga_spacing">4dp</dimen>
|
||||
|
||||
<dimen name="bottom_sheet_width">0dp</dimen>
|
||||
<dimen name="dialog_radius">8dp</dimen>
|
||||
|
||||
<dimen name="appwidget_corner_radius_inner">8dp</dimen>
|
||||
</resources>
|
||||
@@ -302,4 +302,6 @@
|
||||
<string name="send">Send</string>
|
||||
<string name="disable_all">Disable all</string>
|
||||
<string name="use_fingerprint">Use fingerprint if available</string>
|
||||
<string name="appwidget_shelf_description">Manga from your favourites</string>
|
||||
<string name="appwidget_recent_description">Your recently read manga</string>
|
||||
</resources>
|
||||
@@ -103,4 +103,8 @@
|
||||
<item name="toolbarNavigationButtonStyle">@style/Theme.Kotatsu.ActionMode.CloseButton</item>
|
||||
</style>
|
||||
|
||||
<style name="Theme.Kotatsu.AppWidgetContainer" parent="@style/Theme.MaterialComponents.Light">
|
||||
<item name="android:colorBackground">@color/kotatsu_background</item>
|
||||
<item name="android:panelColorBackground">@color/kotatsu_primaryContainer</item>
|
||||
</style>
|
||||
</resources>
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<appwidget-provider
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:description="@string/appwidget_recent_description"
|
||||
android:initialLayout="@layout/widget_recent"
|
||||
android:minWidth="110dp"
|
||||
android:minHeight="110dp"
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<appwidget-provider
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:configure="org.koitharu.kotatsu.widget.shelf.ShelfConfigActivity"
|
||||
android:description="@string/appwidget_shelf_description"
|
||||
android:initialLayout="@layout/widget_shelf"
|
||||
android:minWidth="110dp"
|
||||
android:minHeight="110dp"
|
||||
@@ -10,4 +12,6 @@
|
||||
android:previewImage="@drawable/ic_appwidget_shelf"
|
||||
android:resizeMode="horizontal|vertical"
|
||||
android:updatePeriodMillis="0"
|
||||
android:widgetCategory="home_screen" />
|
||||
android:widgetCategory="home_screen"
|
||||
android:widgetFeatures="reconfigurable"
|
||||
tools:ignore="UnusedAttribute" />
|
||||
|
||||
Reference in New Issue
Block a user