mirror of
https://github.com/SimpleMobileTools/Simple-Notes.git
synced 2025-03-23 20:10:07 +01:00
Merge pull request #501 from Aga-C/fix-checklist-widget-style
Fixed text styling in checklist widget (#347)
This commit is contained in:
commit
a7cb229a7a
@ -13,7 +13,6 @@ import com.simplemobiletools.commons.extensions.setText
|
|||||||
import com.simplemobiletools.commons.extensions.setTextSize
|
import com.simplemobiletools.commons.extensions.setTextSize
|
||||||
import com.simplemobiletools.commons.helpers.WIDGET_TEXT_COLOR
|
import com.simplemobiletools.commons.helpers.WIDGET_TEXT_COLOR
|
||||||
import com.simplemobiletools.notes.pro.R
|
import com.simplemobiletools.notes.pro.R
|
||||||
import com.simplemobiletools.notes.pro.R.id.checklist_title
|
|
||||||
import com.simplemobiletools.notes.pro.R.id.widget_text_holder
|
import com.simplemobiletools.notes.pro.R.id.widget_text_holder
|
||||||
import com.simplemobiletools.notes.pro.extensions.config
|
import com.simplemobiletools.notes.pro.extensions.config
|
||||||
import com.simplemobiletools.notes.pro.extensions.getPercentageFontSize
|
import com.simplemobiletools.notes.pro.extensions.getPercentageFontSize
|
||||||
@ -23,8 +22,14 @@ import com.simplemobiletools.notes.pro.models.ChecklistItem
|
|||||||
import com.simplemobiletools.notes.pro.models.Note
|
import com.simplemobiletools.notes.pro.models.Note
|
||||||
|
|
||||||
class WidgetAdapter(val context: Context, val intent: Intent) : RemoteViewsService.RemoteViewsFactory {
|
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,
|
private val textIds = arrayOf(
|
||||||
R.id.widget_text_left_monospace, R.id.widget_text_center_monospace, R.id.widget_text_right_monospace)
|
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 widgetTextColor = DEFAULT_WIDGET_TEXT_COLOR
|
||||||
private var note: Note? = null
|
private var note: Note? = null
|
||||||
private var checklistItems = ArrayList<ChecklistItem>()
|
private var checklistItems = ArrayList<ChecklistItem>()
|
||||||
@ -41,18 +46,22 @@ class WidgetAdapter(val context: Context, val intent: Intent) : RemoteViewsServi
|
|||||||
if (note!!.type == NoteType.TYPE_CHECKLIST.value) {
|
if (note!!.type == NoteType.TYPE_CHECKLIST.value) {
|
||||||
remoteView = RemoteViews(context.packageName, R.layout.item_checklist_widget).apply {
|
remoteView = RemoteViews(context.packageName, R.layout.item_checklist_widget).apply {
|
||||||
val checklistItem = checklistItems.getOrNull(position) ?: return@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
|
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
|
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 {
|
Intent().apply {
|
||||||
putExtra(OPEN_NOTE_ID, noteId)
|
putExtra(OPEN_NOTE_ID, noteId)
|
||||||
setOnClickFillInIntent(checklist_title, this)
|
setOnClickFillInIntent(R.id.checklist_text_holder, this)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@ -90,6 +99,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 onCreate() {}
|
||||||
|
|
||||||
override fun getLoadingView() = null
|
override fun getLoadingView() = null
|
||||||
|
@ -1,14 +1,83 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
|
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
xmlns:tools="http://schemas.android.com/tools"
|
android:id="@+id/checklist_text_holder"
|
||||||
android:id="@+id/checklist_title"
|
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="match_parent"
|
||||||
android:layout_centerVertical="true"
|
android:layout_toStartOf="@+id/checklist_image">
|
||||||
android:layout_toStartOf="@+id/checklist_image"
|
|
||||||
android:paddingStart="@dimen/activity_margin"
|
<TextView
|
||||||
android:paddingTop="@dimen/medium_margin"
|
android:id="@+id/checklist_text_left"
|
||||||
android:paddingEnd="@dimen/medium_margin"
|
android:layout_width="match_parent"
|
||||||
android:paddingBottom="@dimen/medium_margin"
|
android:layout_height="match_parent"
|
||||||
android:textSize="@dimen/bigger_text_size"
|
android:background="@null"
|
||||||
tools:text="Butter" />
|
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>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user