feat: add Android sync client
- Add Kotlin/Material 3 Android project with SQLite outbox and LWW\n- Implement registration, push/pull, WebSocket notifications, and settings\n- Add schedule list, date navigation, create/edit/delete, and completion\n- Add JVM LWW/time tests and build a debug APK\n- Document Android v1 scope and validation
This commit is contained in:
@@ -0,0 +1,65 @@
|
||||
package com.misaki.schedule.ui
|
||||
|
||||
import android.graphics.Paint
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.widget.CheckBox
|
||||
import android.widget.TextView
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import com.misaki.schedule.R
|
||||
import com.misaki.schedule.data.ScheduleItem
|
||||
import com.misaki.schedule.data.TimeUtils
|
||||
import com.misaki.schedule.data.statusLabel
|
||||
|
||||
class ScheduleAdapter(
|
||||
private val onEdit: (ScheduleItem) -> Unit,
|
||||
private val onLongPress: (ScheduleItem) -> Unit,
|
||||
private val onDoneChanged: (ScheduleItem, Boolean) -> Unit,
|
||||
) : RecyclerView.Adapter<ScheduleAdapter.ViewHolder>() {
|
||||
|
||||
private var items: List<ScheduleItem> = emptyList()
|
||||
|
||||
fun submit(newItems: List<ScheduleItem>) {
|
||||
items = newItems
|
||||
notifyDataSetChanged()
|
||||
}
|
||||
|
||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
|
||||
val view = LayoutInflater.from(parent.context).inflate(R.layout.item_schedule, parent, false)
|
||||
return ViewHolder(view)
|
||||
}
|
||||
|
||||
override fun onBindViewHolder(holder: ViewHolder, position: Int) {
|
||||
holder.bind(items[position])
|
||||
}
|
||||
|
||||
override fun getItemCount(): Int = items.size
|
||||
|
||||
inner class ViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
|
||||
private val title: TextView = itemView.findViewById(R.id.titleText)
|
||||
private val time: TextView = itemView.findViewById(R.id.timeText)
|
||||
private val status: TextView = itemView.findViewById(R.id.statusText)
|
||||
private val done: CheckBox = itemView.findViewById(R.id.doneCheck)
|
||||
|
||||
fun bind(item: ScheduleItem) {
|
||||
title.text = item.task.title
|
||||
time.text = TimeUtils.formatRange(item.block.startAt, item.block.endAt)
|
||||
status.text = statusLabel(item.block.status)
|
||||
val isDone = item.isDone()
|
||||
done.setOnCheckedChangeListener(null)
|
||||
done.isChecked = isDone
|
||||
done.setOnCheckedChangeListener { _, checked -> onDoneChanged(item, checked) }
|
||||
title.paintFlags = if (isDone) {
|
||||
title.paintFlags or Paint.STRIKE_THRU_TEXT_FLAG
|
||||
} else {
|
||||
title.paintFlags and Paint.STRIKE_THRU_TEXT_FLAG.inv()
|
||||
}
|
||||
itemView.setOnClickListener { onEdit(item) }
|
||||
itemView.setOnLongClickListener {
|
||||
onLongPress(item)
|
||||
true
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,105 @@
|
||||
package com.misaki.schedule.ui
|
||||
|
||||
import android.app.DatePickerDialog
|
||||
import android.app.Dialog
|
||||
import android.app.TimePickerDialog
|
||||
import android.content.Context
|
||||
import android.view.View
|
||||
import android.view.WindowManager
|
||||
import android.widget.TextView
|
||||
import com.google.android.material.button.MaterialButton
|
||||
import com.google.android.material.textfield.TextInputEditText
|
||||
import com.misaki.schedule.R
|
||||
import com.misaki.schedule.data.TimeUtils
|
||||
import java.time.LocalDateTime
|
||||
import java.time.format.DateTimeFormatter
|
||||
|
||||
class ScheduleDialog(
|
||||
context: Context,
|
||||
dialogTitle: String,
|
||||
private val initialTitle: String,
|
||||
initialStart: LocalDateTime,
|
||||
initialEnd: LocalDateTime,
|
||||
private val onSave: (String, LocalDateTime, LocalDateTime) -> Unit,
|
||||
) : Dialog(context) {
|
||||
private var start: LocalDateTime = initialStart
|
||||
private var end: LocalDateTime = initialEnd
|
||||
private val titleInput: TextInputEditText
|
||||
private val startButton: MaterialButton
|
||||
private val endButton: MaterialButton
|
||||
private val errorText: TextView
|
||||
private val formatter = DateTimeFormatter.ofPattern("M月d日 HH:mm")
|
||||
|
||||
init {
|
||||
setContentView(R.layout.dialog_schedule)
|
||||
setTitle(dialogTitle)
|
||||
window?.setLayout(WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.WRAP_CONTENT)
|
||||
|
||||
titleInput = findViewById(R.id.titleInput)
|
||||
startButton = findViewById(R.id.startButton)
|
||||
endButton = findViewById(R.id.endButton)
|
||||
errorText = findViewById(R.id.errorText)
|
||||
titleInput.setText(initialTitle)
|
||||
updateButtons()
|
||||
|
||||
findViewById<MaterialButton>(R.id.cancelButton).setOnClickListener { dismiss() }
|
||||
findViewById<MaterialButton>(R.id.saveButton).setOnClickListener { save() }
|
||||
startButton.setOnClickListener {
|
||||
pickDateTime(start) { picked ->
|
||||
start = picked
|
||||
if (end <= start) end = start.plusHours(1)
|
||||
updateButtons()
|
||||
}
|
||||
}
|
||||
endButton.setOnClickListener {
|
||||
pickDateTime(end) { picked ->
|
||||
end = picked
|
||||
updateButtons()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun updateButtons() {
|
||||
startButton.text = formatter.format(start)
|
||||
endButton.text = formatter.format(end)
|
||||
}
|
||||
|
||||
private fun pickDateTime(initial: LocalDateTime, onPicked: (LocalDateTime) -> Unit) {
|
||||
DatePickerDialog(
|
||||
context,
|
||||
{ _, year, month, day ->
|
||||
TimePickerDialog(
|
||||
context,
|
||||
{ _, hour, minute ->
|
||||
onPicked(LocalDateTime.of(year, month + 1, day, hour, minute))
|
||||
},
|
||||
initial.hour,
|
||||
initial.minute,
|
||||
true,
|
||||
).show()
|
||||
},
|
||||
initial.year,
|
||||
initial.monthValue - 1,
|
||||
initial.dayOfMonth,
|
||||
).show()
|
||||
}
|
||||
|
||||
private fun save() {
|
||||
val title = titleInput.text?.toString()?.trim().orEmpty()
|
||||
if (title.isEmpty()) {
|
||||
showError(context.getString(R.string.title_required))
|
||||
return
|
||||
}
|
||||
if (end <= start) {
|
||||
showError(context.getString(R.string.start_after_end))
|
||||
return
|
||||
}
|
||||
onSave(title, start, end)
|
||||
dismiss()
|
||||
}
|
||||
|
||||
private fun showError(message: String) {
|
||||
errorText.text = message
|
||||
errorText.visibility = View.VISIBLE
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
package com.misaki.schedule.ui
|
||||
|
||||
import android.content.Context
|
||||
import android.view.LayoutInflater
|
||||
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
||||
import com.google.android.material.materialswitch.MaterialSwitch
|
||||
import com.google.android.material.textfield.TextInputEditText
|
||||
import com.misaki.schedule.R
|
||||
import com.misaki.schedule.data.Prefs
|
||||
import com.misaki.schedule.sync.SyncManager
|
||||
|
||||
object SettingsDialog {
|
||||
fun show(context: Context, prefs: Prefs, syncManager: SyncManager) {
|
||||
val view = LayoutInflater.from(context).inflate(R.layout.dialog_settings, null)
|
||||
val url = view.findViewById<TextInputEditText>(R.id.serverUrlInput)
|
||||
val enabled = view.findViewById<MaterialSwitch>(R.id.syncSwitch)
|
||||
url.setText(prefs.serverUrl)
|
||||
enabled.isChecked = prefs.enabled
|
||||
|
||||
MaterialAlertDialogBuilder(context)
|
||||
.setTitle(R.string.settings)
|
||||
.setView(view)
|
||||
.setNegativeButton(R.string.cancel, null)
|
||||
.setPositiveButton(R.string.save) { _, _ ->
|
||||
prefs.serverUrl = url.text?.toString().orEmpty()
|
||||
prefs.enabled = enabled.isChecked
|
||||
syncManager.reload()
|
||||
}
|
||||
.show()
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user