Dark mode, proper alignment

This commit is contained in:
Philipp Heckel 2022-04-28 22:04:46 -04:00
parent 0d790a447f
commit 523bf092db
8 changed files with 116 additions and 127 deletions

View file

@ -5,7 +5,6 @@ import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import androidx.cardview.widget.CardView
import androidx.recyclerview.widget.DiffUtil
import androidx.recyclerview.widget.ListAdapter
import androidx.recyclerview.widget.RecyclerView
@ -48,7 +47,6 @@ class MainAdapter(private val repository: Repository, private val onClick: (Subs
RecyclerView.ViewHolder(itemView) {
private var subscription: Subscription? = null
private val context: Context = itemView.context
private val cardView: CardView = itemView.findViewById(R.id.main_item_card)
private val nameView: TextView = itemView.findViewById(R.id.main_item_text)
private val statusView: TextView = itemView.findViewById(R.id.main_item_status)
private val dateView: TextView = itemView.findViewById(R.id.main_item_date)
@ -99,10 +97,10 @@ class MainAdapter(private val repository: Repository, private val onClick: (Subs
newItemsView.visibility = View.VISIBLE
newItemsView.text = if (subscription.newCount <= 99) subscription.newCount.toString() else "99+"
}
cardView.setOnClickListener { onClick(subscription) }
cardView.setOnLongClickListener { onLongClick(subscription); true }
itemView.setOnClickListener { onClick(subscription) }
itemView.setOnLongClickListener { onLongClick(subscription); true }
if (selected.contains(subscription.id)) {
cardView.setCardBackgroundColor(Colors.itemSelectedBackgroundColor(context))
itemView.setBackgroundResource(Colors.itemSelectedBackground(context))
}
}
}

View file

@ -8,6 +8,7 @@
tools:context=".ui.DetailActivity"
>
<androidx.swiperefreshlayout.widget.SwipeRefreshLayout
style="@style/SwipeRefreshLayoutWithCards"
android:id="@+id/detail_notification_list_container"
android:layout_width="match_parent"
android:layout_height="match_parent"

View file

@ -1,18 +1,19 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
android:layout_height="match_parent">
<com.google.android.material.card.MaterialCardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:shapeAppearance="?shapeAppearanceLargeComponent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintTop_toTopOf="parent"
android:id="@+id/main_banner_battery" android:visibility="visible">
app:shapeAppearance="?shapeAppearanceLargeComponent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent"
android:id="@+id/main_banner_battery"
android:visibility="visible"
>
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
@ -136,6 +137,7 @@
android:text="@string/main_banner_json_stream_button_dismiss"
tools:layout_editor_absoluteX="260dp" tools:layout_editor_absoluteY="83dp"/>
<com.google.android.material.button.MaterialButton
android:id="@+id/main_banner_json_stream_learn_mode"
style="@style/Widget.MaterialComponents.Button.TextButton"
@ -158,11 +160,11 @@
android:id="@+id/main_subscriptions_list"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clickable="true"
android:focusable="true"
android:paddingTop="5dp"
android:paddingBottom="5dp"
android:clipToPadding="false"
android:clickable="true"
android:focusable="true"
android:background="?android:attr/selectableItemBackground"
app:layoutManager="LinearLayoutManager"/>
</androidx.swiperefreshlayout.widget.SwipeRefreshLayout>

View file

@ -2,6 +2,7 @@
<androidx.cardview.widget.CardView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
style="@style/CardView"
android:id="@+id/detail_item_card"
android:background="?android:attr/selectableItemBackground"
android:clickable="true"
@ -11,10 +12,8 @@
android:layout_marginTop="0dp"
android:layout_marginStart="6dp"
android:layout_marginEnd="6dp"
android:layout_marginBottom="0dp"
android:layout_marginBottom="1dp"
android:padding="3dp"
android:paddingBottom="3dp"
app:cardBackgroundColor="@color/white"
app:cardCornerRadius="3dp"
app:cardElevation="2dp"
app:cardMaxElevation="2dp"
@ -26,7 +25,7 @@
android:orientation="horizontal"
android:background="?android:attr/selectableItemBackground"
android:focusable="true"
android:paddingBottom="5dp">
android:paddingBottom="6dp" android:paddingTop="6dp">
<TextView
android:text="Sun, October 31, 2021, 10:43:12"
android:layout_width="wrap_content"
@ -34,7 +33,7 @@
android:id="@+id/detail_item_date_text"
android:textAppearance="@style/TextAppearance.AppCompat.Small"
app:layout_constraintTop_toTopOf="parent"
android:layout_marginTop="10dp" app:layout_constraintStart_toStartOf="parent"
android:layout_marginTop="5dp" app:layout_constraintStart_toStartOf="parent"
android:layout_marginStart="10dp"/>
<TextView
android:layout_width="10dp"
@ -54,7 +53,7 @@
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintEnd_toEndOf="parent" android:layout_marginEnd="5dp"
android:background="?android:attr/selectableItemBackground" android:paddingTop="-5dp"
android:layout_marginTop="5dp"/>
/>
<TextView
android:text="This is a very very very long message. It could be as long as 1024 charaters, which is a lot more than you'd think. No, really so far this message is barely 180 characters long. I can't believe how long 1024 bytes are. This is outrageous. Oh you know what, I think I won't type the whole thing. This seems a little too long for a sample text. Well, anyway, it was nice chatting. So far this message is about 400 bytes long. So maybe just double what you see and that's that."
android:layout_width="0dp"

View file

@ -1,33 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.cardview.widget.CardView
xmlns:android="http://schemas.android.com/apk/res/android"
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/main_item_card"
android:background="?android:attr/selectableItemBackground"
android:clickable="true"
android:focusable="true"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="0dp"
android:layout_marginStart="6dp"
android:layout_marginEnd="6dp"
android:layout_marginBottom="0dp"
android:padding="0dp"
app:cardBackgroundColor="@color/white"
app:cardCornerRadius="3dp"
app:cardElevation="2dp"
app:cardMaxElevation="2dp"
app:cardPreventCornerOverlap="true"
app:cardUseCompatPadding="true">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:paddingEnd="15dp"
android:paddingStart="15dp"
android:background="?android:attr/selectableItemBackground"
android:focusable="true"
android:paddingBottom="3dp">
android:orientation="horizontal" android:clickable="true"
android:focusable="true" android:paddingEnd="18dp"
android:paddingStart="18dp">
<ImageView
android:layout_width="35dp"
android:layout_height="35dp" app:srcCompat="@drawable/ic_sms_gray_24dp"
@ -40,7 +19,7 @@
android:layout_height="wrap_content" android:id="@+id/main_item_text"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toTopOf="@+id/main_item_status"
android:layout_marginStart="10dp" app:layout_constraintStart_toEndOf="@+id/main_item_image"
android:layout_marginStart="12dp" app:layout_constraintStart_toEndOf="@+id/main_item_image"
app:layout_constraintVertical_bias="0.0" android:textAppearance="@style/TextAppearance.AppCompat.Medium"
android:textColor="?android:attr/textColorPrimary" android:layout_marginTop="10dp"
app:layout_constraintEnd_toStartOf="@+id/main_item_instant_image"/>
@ -92,5 +71,5 @@
app:layout_constraintEnd_toEndOf="@+id/main_item_date"
app:layout_constraintStart_toEndOf="@+id/main_item_instant_image"
android:textSize="10sp" android:textStyle="bold"/>
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.cardview.widget.CardView>
</androidx.constraintlayout.widget.ConstraintLayout>

View file

@ -30,4 +30,12 @@
<item name="tint">@color/black_light</item>
<item name="backgroundTint">@color/teal_light</item>
</style>
<style name="CardView" parent="@style/Widget.MaterialComponents.CardView">
<item name="cardBackgroundColor">@color/gray_darker</item>
</style>
<style name="SwipeRefreshLayoutWithCards">
<item name="android:background">@color/black_light</item>
</style>
</resources>

View file

@ -12,5 +12,6 @@
<color name="gray_light">#eeeeee</color> <!-- Light theme item selection -->
<color name="gray_dark">#282828</color> <!-- Dark mode action bar & item selection -->
<color name="gray_darker">#202020</color> <!-- Dark mode cards -->
</resources>

View file

@ -3,30 +3,31 @@
<style name="AppTheme" parent="Theme.MaterialComponents.DayNight.DarkActionBar">
<item name="colorPrimary">@color/teal</item>
<item name="colorAccent">@color/teal</item> <!-- checkboxes, text fields -->
<item name="android:colorBackground">@color/gray_light</item> <!-- background -->
<item name="android:colorBackground">@color/white</item> <!-- background -->
<item name="android:statusBarColor">@color/teal</item>
<item name="actionModeBackground">@color/teal_dark</item>
<item name="android:popupMenuStyle">@style/PopupMenu</item>
</style>
<!-- Danger buttons & text -->
<style name="DangerText" parent="@android:style/TextAppearance">
<item name="android:textColor">@color/red_dark</item>
</style>
<!-- Floating action button -->
<style name="FloatingActionButton" parent="@style/Widget.MaterialComponents.FloatingActionButton">
<item name="tint">@color/white</item>
<item name="backgroundTint">@color/teal</item>
</style>
<style name="CardView" parent="@style/Widget.MaterialComponents.CardView">
<item name="cardBackgroundColor">@color/white</item>
</style>
<style name="SwipeRefreshLayoutWithCards">
<item name="android:background">@color/gray_light</item>
</style>
<!-- Rounded corners in images, see https://stackoverflow.com/a/61960983/1440785 -->
<style name="roundedCornersImageView" parent="">
<item name="cornerFamily">rounded</item>
<item name="cornerSize">5dp</item>
</style>
<style name="PopupMenu" parent="@style/Widget.Material3.PopupMenu">
<item name="android:popupBackground">@color/white</item>
</style>
</resources>