Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions app/src/main/java/com/omgodse/notally/ReminderReceiver.kt
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import com.omgodse.notally.activities.TakeNote
import com.omgodse.notally.miscellaneous.Constants
import com.omgodse.notally.miscellaneous.Operations
import com.omgodse.notally.room.BaseNote
import com.omgodse.notally.room.Folder
import com.omgodse.notally.room.Frequency
import com.omgodse.notally.room.IdReminder
import com.omgodse.notally.room.NotallyDatabase
Expand Down Expand Up @@ -73,6 +74,11 @@ class ReminderReceiver : BroadcastReceiver() {


private fun sendNotification(context: Context, baseNote: BaseNote) {
if (baseNote.folder == Folder.DELETED) {
// ignore showing notifications for deleted reminders
return
}

val manager = context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
val builder = Notification.Builder(context)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,9 @@ class ConfigureWidget : AppCompatActivity(), ItemListener {
val textSize = preferences.textSize.value
val dateFormat = preferences.dateFormat.value
val fullFormat = DateFormat.getDateInstance(DateFormat.FULL)
val shortFormat = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT)
val mediaRoot = IO.getExternalImagesDirectory(application)

adapter = BaseNoteAdapter(Collections.emptySet(), dateFormat, textSize, maxItems, maxLines, maxTitle, fullFormat, shortFormat, mediaRoot, this)
adapter = BaseNoteAdapter(Collections.emptySet(), dateFormat, textSize, maxItems, maxLines, maxTitle, fullFormat, mediaRoot, this)

binding.RecyclerView.adapter = adapter
binding.RecyclerView.setHasFixedSize(true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,13 @@ import android.content.Context
import android.content.Intent
import android.content.pm.PackageManager
import android.content.res.ColorStateList
import android.graphics.Paint
import android.net.Uri
import android.os.Build
import android.os.Bundle
import android.provider.Settings
import android.text.Editable
import android.text.format.DateUtils
import android.util.TypedValue
import android.view.MenuItem
import android.view.View
Expand Down Expand Up @@ -425,15 +427,23 @@ abstract class NotallyActivity(private val type: Type) : AppCompatActivity() {

private fun setupReminder() {
val padding = (resources.displayMetrics.density * 16).toInt()
val formatter = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT)

model.reminder.observe(this) { reminder ->
if (reminder != null) {
val date = formatter.format(reminder.timestamp)
val dateFormat = Operations.getReminderDateFormat(reminder.timestamp)
val date = DateUtils.formatDateTime(binding.root.context, reminder.timestamp, dateFormat)
binding.Reminder.text = when (reminder.frequency) {
Frequency.ONCE -> date
Frequency.DAILY -> getString(R.string.repeats_daily, date)
Frequency.MONTHLY -> getString(R.string.repeats_monthly, date)
}

if (Operations.isReminderInPast(reminder)) {
binding.Reminder.paintFlags = binding.Reminder.paintFlags or Paint.STRIKE_THRU_TEXT_FLAG
} else {
binding.Reminder.paintFlags = binding.Reminder.paintFlags and Paint.STRIKE_THRU_TEXT_FLAG.inv()
}

binding.Reminder.visibility = View.VISIBLE
binding.DateCreated.updatePadding(bottom = 0)
} else {
Expand Down Expand Up @@ -497,7 +507,8 @@ abstract class NotallyActivity(private val type: Type) : AppCompatActivity() {
val calendar = Calendar.getInstance()
val hour = calendar.get(Calendar.HOUR_OF_DAY)
val minute = calendar.get(Calendar.MINUTE)
TimePickerDialog(this, timeListener, hour, minute, false).show()
val is24HourView = android.text.format.DateFormat.is24HourFormat(applicationContext);
TimePickerDialog(this, timeListener, hour, minute, is24HourView).show()
}

var selectedFrequency = 0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,8 @@ abstract class NotallyFragment : Fragment(), ItemListener {
val maxTitle = model.preferences.maxTitle
val dateFormat = model.preferences.dateFormat.value
val fullFormat = DateFormat.getDateInstance(DateFormat.FULL)
val shortFormat = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT)

adapter = BaseNoteAdapter(model.actionMode.selectedIds, dateFormat, textSize, maxItems, maxLines, maxTitle, fullFormat, shortFormat, model.mediaRoot, this)
adapter = BaseNoteAdapter(model.actionMode.selectedIds, dateFormat, textSize, maxItems, maxLines, maxTitle, fullFormat, model.mediaRoot, this)
adapter?.registerAdapterDataObserver(object : RecyclerView.AdapterDataObserver() {

override fun onItemRangeInserted(positionStart: Int, itemCount: Int) {
Expand Down
24 changes: 24 additions & 0 deletions app/src/main/java/com/omgodse/notally/miscellaneous/Operations.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import android.content.Intent
import android.content.res.ColorStateList
import android.net.Uri
import android.os.Build
import android.text.format.DateUtils
import android.util.TypedValue
import android.view.LayoutInflater
import android.view.View
Expand All @@ -20,12 +21,15 @@ import com.omgodse.notally.R
import com.omgodse.notally.databinding.LabelBinding
import com.omgodse.notally.preferences.TextSize
import com.omgodse.notally.room.Color
import com.omgodse.notally.room.Frequency
import com.omgodse.notally.room.ListItem
import com.omgodse.notally.room.Reminder
import java.io.File
import java.io.FileOutputStream
import java.io.OutputStreamWriter
import java.io.PrintWriter
import java.text.DateFormat
import java.util.Calendar

object Operations {

Expand Down Expand Up @@ -104,6 +108,26 @@ object Operations {
}
}

fun getReminderDateFormat(timestamp: Long): Int {
var dateFormat = DateUtils.FORMAT_SHOW_DATE or DateUtils.FORMAT_SHOW_TIME or DateUtils.FORMAT_ABBREV_MONTH
val future = Calendar.getInstance()
val now = Calendar.getInstance()

// If reminder is not in next year, omit the year display.
future.timeInMillis = timestamp
if (future.get(Calendar.YEAR) == now.get(Calendar.YEAR)) {
dateFormat = dateFormat or DateUtils.FORMAT_NO_YEAR
}

return dateFormat
}

fun isReminderInPast(reminder: Reminder): Boolean {
val future = Calendar.getInstance()
val now = Calendar.getInstance()
future.timeInMillis = reminder.timestamp
return (future < now) and (reminder.frequency == Frequency.ONCE)
}

fun bindLabels(group: ChipGroup, labels: List<String>, textSize: String) {
if (labels.isEmpty()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ class BaseNoteAdapter(
private val maxLines: Int,
private val maxTitle: Int,
private val fullFormat: DateFormat,
private val shortFormat: DateFormat,
private val mediaRoot: File?,
private val listener: ItemListener
) : ListAdapter<Item, RecyclerView.ViewHolder>(DiffCallback) {
Expand Down Expand Up @@ -61,7 +60,7 @@ class BaseNoteAdapter(
}
else -> {
val binding = RecyclerBaseNoteBinding.inflate(inflater, parent, false)
BaseNoteVH(binding, dateFormat, textSize, maxItems, maxLines, maxTitle, listener, prettyTime, fullFormat, shortFormat)
BaseNoteVH(binding, dateFormat, textSize, maxItems, maxLines, maxTitle, listener, prettyTime, fullFormat)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.omgodse.notally.recyclerview.viewholder

import android.graphics.Paint
import android.graphics.drawable.Drawable
import android.text.format.DateUtils
import android.util.TypedValue
import android.view.View
import android.widget.TextView
Expand Down Expand Up @@ -32,6 +34,7 @@ import com.omgodse.notally.room.SpanRepresentation
import com.omgodse.notally.room.Type
import org.ocpsoft.prettytime.PrettyTime
import java.io.File
import java.util.Calendar
import java.util.Date

class BaseNoteVH(
Expand All @@ -43,8 +46,7 @@ class BaseNoteVH(
maxTitle: Int,
listener: ItemListener,
private val prettyTime: PrettyTime,
private val fullFormat: java.text.DateFormat,
private val shortFormat: java.text.DateFormat
private val fullFormat: java.text.DateFormat
) : RecyclerView.ViewHolder(binding.root) {

init {
Expand Down Expand Up @@ -208,13 +210,21 @@ class BaseNoteVH(

private fun setReminder(reminder: Reminder?) {
if (reminder != null) {
val date = shortFormat.format(reminder.timestamp)
val dateFormat = Operations.getReminderDateFormat(reminder.timestamp)
val context = binding.root.context
val date = DateUtils.formatDateTime(context, reminder.timestamp, dateFormat)
binding.Reminder.text = when (reminder.frequency) {
Frequency.ONCE -> date
Frequency.DAILY -> context.getString(R.string.repeats_daily, date)
Frequency.MONTHLY -> context.getString(R.string.repeats_monthly, date)
}

if (Operations.isReminderInPast(reminder)) {
binding.Reminder.paintFlags = binding.Reminder.paintFlags or Paint.STRIKE_THRU_TEXT_FLAG
} else {
binding.Reminder.paintFlags = binding.Reminder.paintFlags and Paint.STRIKE_THRU_TEXT_FLAG.inv()
}

binding.Reminder.visibility = View.VISIBLE
} else binding.Reminder.visibility = View.GONE
}
Expand Down