Fixed text styling in checklist widget (#347)

This commit is contained in:
Agnieszka C 2022-02-01 18:28:48 +01:00
parent c4bdeb9b76
commit 61a606f0ae
2 changed files with 108 additions and 19 deletions

View File

@ -25,6 +25,8 @@ import com.simplemobiletools.notes.pro.models.Note
class WidgetAdapter(val context: Context, val intent: Intent) : RemoteViewsService.RemoteViewsFactory {
private val textIds = arrayOf(R.id.widget_text_left, R.id.widget_text_center, R.id.widget_text_right,
R.id.widget_text_left_monospace, R.id.widget_text_center_monospace, R.id.widget_text_right_monospace)
private val checklistIds = arrayOf(R.id.checklist_text_left, R.id.checklist_text_center, R.id.checklist_text_right,
R.id.checklist_text_left_monospace, R.id.checklist_text_center_monospace, R.id.checklist_text_right_monospace)
private var widgetTextColor = DEFAULT_WIDGET_TEXT_COLOR
private var note: Note? = null
private var checklistItems = ArrayList<ChecklistItem>()
@ -41,18 +43,22 @@ class WidgetAdapter(val context: Context, val intent: Intent) : RemoteViewsServi
if (note!!.type == NoteType.TYPE_CHECKLIST.value) {
remoteView = RemoteViews(context.packageName, R.layout.item_checklist_widget).apply {
val checklistItem = checklistItems.getOrNull(position) ?: return@apply
setText(checklist_title, checklistItem.title)
val widgetNewTextColor = if (checklistItem.isDone) widgetTextColor.adjustAlpha(DONE_CHECKLIST_ITEM_ALPHA) else widgetTextColor
setTextColor(checklist_title, widgetNewTextColor)
setTextSize(checklist_title, textSize)
val paintFlags = if (checklistItem.isDone) Paint.STRIKE_THRU_TEXT_FLAG or Paint.ANTI_ALIAS_FLAG else Paint.ANTI_ALIAS_FLAG
setInt(checklist_title, "setPaintFlags", paintFlags)
for (id in checklistIds) {
setText(id, checklistItem.title)
setTextColor(id, widgetNewTextColor)
setTextSize(id, textSize)
setInt(id, "setPaintFlags", paintFlags)
setViewVisibility(id, View.GONE)
}
setViewVisibility(getProperChecklistTextView(context), View.VISIBLE)
Intent().apply {
putExtra(OPEN_NOTE_ID, noteId)
setOnClickFillInIntent(checklist_title, this)
setOnClickFillInIntent(R.id.checklist_text_holder, this)
}
}
} else {
@ -90,6 +96,20 @@ class WidgetAdapter(val context: Context, val intent: Intent) : RemoteViewsServi
}
}
private fun getProperChecklistTextView(context: Context): Int {
val gravity = context.config.gravity
val isMonospaced = context.config.monospacedFont
return when {
gravity == GRAVITY_CENTER && isMonospaced -> R.id.checklist_text_center_monospace
gravity == GRAVITY_CENTER -> R.id.checklist_text_center
gravity == GRAVITY_RIGHT && isMonospaced -> R.id.checklist_text_right_monospace
gravity == GRAVITY_RIGHT -> R.id.checklist_text_right
isMonospaced -> R.id.checklist_text_left_monospace
else -> R.id.checklist_text_left
}
}
override fun onCreate() {}
override fun getLoadingView() = null

View File

@ -1,14 +1,83 @@
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/checklist_title"
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/checklist_text_holder"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_toStartOf="@+id/checklist_image"
android:paddingStart="@dimen/activity_margin"
android:paddingTop="@dimen/medium_margin"
android:paddingEnd="@dimen/medium_margin"
android:paddingBottom="@dimen/medium_margin"
android:textSize="@dimen/bigger_text_size"
tools:text="Butter" />
android:layout_height="match_parent"
android:layout_toStartOf="@+id/checklist_image">
<TextView
android:id="@+id/checklist_text_left"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@null"
android:gravity="start"
android:paddingStart="@dimen/activity_margin"
android:paddingTop="@dimen/medium_margin"
android:paddingEnd="@dimen/medium_margin"
android:paddingBottom="@dimen/medium_margin"
android:visibility="gone" />
<TextView
android:id="@+id/checklist_text_center"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@null"
android:gravity="center_horizontal"
android:paddingStart="@dimen/activity_margin"
android:paddingTop="@dimen/medium_margin"
android:paddingEnd="@dimen/medium_margin"
android:paddingBottom="@dimen/medium_margin"
android:visibility="gone" />
<TextView
android:id="@+id/checklist_text_right"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@null"
android:gravity="end"
android:paddingStart="@dimen/activity_margin"
android:paddingTop="@dimen/medium_margin"
android:paddingEnd="@dimen/medium_margin"
android:paddingBottom="@dimen/medium_margin"
android:visibility="gone" />
<TextView
android:id="@+id/checklist_text_left_monospace"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@null"
android:fontFamily="monospace"
android:gravity="start"
android:paddingStart="@dimen/activity_margin"
android:paddingTop="@dimen/medium_margin"
android:paddingEnd="@dimen/medium_margin"
android:paddingBottom="@dimen/medium_margin"
android:visibility="gone" />
<TextView
android:id="@+id/checklist_text_center_monospace"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@null"
android:fontFamily="monospace"
android:gravity="center_horizontal"
android:paddingStart="@dimen/activity_margin"
android:paddingTop="@dimen/medium_margin"
android:paddingEnd="@dimen/medium_margin"
android:paddingBottom="@dimen/medium_margin"
android:visibility="gone" />
<TextView
android:id="@+id/checklist_text_right_monospace"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@null"
android:fontFamily="monospace"
android:gravity="end"
android:paddingStart="@dimen/activity_margin"
android:paddingTop="@dimen/medium_margin"
android:paddingEnd="@dimen/medium_margin"
android:paddingBottom="@dimen/medium_margin"
android:visibility="gone" />
</RelativeLayout>