mirror of
https://github.com/iSoron/uhabits.git
synced 2025-12-06 09:08:52 -06:00
Merge branch 'dev' into feature/custom-snooze
This commit is contained in:
@@ -5,7 +5,7 @@ buildscript {
|
|||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
classpath 'com.android.tools.build:gradle:3.0.0-beta6'
|
classpath 'com.android.tools.build:gradle:3.0.0'
|
||||||
classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8'
|
classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8'
|
||||||
classpath 'com.getkeepsafe.dexcount:dexcount-gradle-plugin:0.6.4'
|
classpath 'com.getkeepsafe.dexcount:dexcount-gradle-plugin:0.6.4'
|
||||||
classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8'
|
classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8'
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ TARGET_SDK_VERSION = 25
|
|||||||
COMPILE_SDK_VERSION = 25
|
COMPILE_SDK_VERSION = 25
|
||||||
|
|
||||||
DAGGER_VERSION = 2.9
|
DAGGER_VERSION = 2.9
|
||||||
BUILD_TOOLS_VERSION = 26.0.0
|
BUILD_TOOLS_VERSION = 26.0.2
|
||||||
KOTLIN_VERSION = 1.1.2-4
|
KOTLIN_VERSION = 1.1.2-4
|
||||||
SUPPORT_LIBRARY_VERSION = 25.3.1
|
SUPPORT_LIBRARY_VERSION = 25.3.1
|
||||||
|
|
||||||
|
|||||||
@@ -54,6 +54,15 @@ class PendingIntentFactory
|
|||||||
},
|
},
|
||||||
FLAG_UPDATE_CURRENT)
|
FLAG_UPDATE_CURRENT)
|
||||||
|
|
||||||
|
fun removeRepetition(habit: Habit): PendingIntent =
|
||||||
|
PendingIntent.getBroadcast(
|
||||||
|
context, 3,
|
||||||
|
Intent(context, WidgetReceiver::class.java).apply {
|
||||||
|
action = WidgetReceiver.ACTION_REMOVE_REPETITION
|
||||||
|
data = Uri.parse(habit.uriString)
|
||||||
|
},
|
||||||
|
FLAG_UPDATE_CURRENT)
|
||||||
|
|
||||||
fun showHabit(habit: Habit): PendingIntent =
|
fun showHabit(habit: Habit): PendingIntent =
|
||||||
android.support.v4.app.TaskStackBuilder
|
android.support.v4.app.TaskStackBuilder
|
||||||
.create(context)
|
.create(context)
|
||||||
|
|||||||
@@ -23,6 +23,7 @@ import android.app.*
|
|||||||
import android.content.*
|
import android.content.*
|
||||||
import android.graphics.*
|
import android.graphics.*
|
||||||
import android.graphics.BitmapFactory.*
|
import android.graphics.BitmapFactory.*
|
||||||
|
import android.support.annotation.*
|
||||||
import android.support.v4.app.*
|
import android.support.v4.app.*
|
||||||
import android.support.v4.app.NotificationCompat.*
|
import android.support.v4.app.NotificationCompat.*
|
||||||
import org.isoron.androidbase.*
|
import org.isoron.androidbase.*
|
||||||
@@ -50,11 +51,24 @@ class AndroidNotificationTray
|
|||||||
override fun showNotification(habit: Habit,
|
override fun showNotification(habit: Habit,
|
||||||
notificationId: Int,
|
notificationId: Int,
|
||||||
timestamp: Timestamp,
|
timestamp: Timestamp,
|
||||||
reminderTime: Long) {
|
reminderTime: Long)
|
||||||
|
{
|
||||||
|
val notificationManager = NotificationManagerCompat.from(context)
|
||||||
|
val summary = buildSummary(reminderTime)
|
||||||
|
notificationManager.notify(Int.MAX_VALUE, summary)
|
||||||
|
val notification = buildNotification(habit, reminderTime, timestamp)
|
||||||
|
notificationManager.notify(notificationId, notification)
|
||||||
|
}
|
||||||
|
|
||||||
val checkAction = Action(
|
@NonNull
|
||||||
|
fun buildNotification(@NonNull habit: Habit,
|
||||||
|
@NonNull reminderTime: Long,
|
||||||
|
@NonNull timestamp: Timestamp) : Notification
|
||||||
|
{
|
||||||
|
|
||||||
|
val addRepetitionAction = Action(
|
||||||
R.drawable.ic_action_check,
|
R.drawable.ic_action_check,
|
||||||
context.getString(R.string.check),
|
context.getString(R.string.yes),
|
||||||
pendingIntents.addCheckmark(habit, timestamp))
|
pendingIntents.addCheckmark(habit, timestamp))
|
||||||
|
|
||||||
val snoozeAction = Action(
|
val snoozeAction = Action(
|
||||||
@@ -62,6 +76,12 @@ class AndroidNotificationTray
|
|||||||
context.getString(R.string.snooze),
|
context.getString(R.string.snooze),
|
||||||
pendingIntents.snoozeNotification(habit))
|
pendingIntents.snoozeNotification(habit))
|
||||||
|
|
||||||
|
val removeRepetitionAction = Action(
|
||||||
|
R.drawable.ic_action_cancel,
|
||||||
|
context.getString(R.string.no),
|
||||||
|
pendingIntents.removeRepetition(habit)
|
||||||
|
)
|
||||||
|
|
||||||
val wearableBg = decodeResource(context.resources, R.drawable.stripe)
|
val wearableBg = decodeResource(context.resources, R.drawable.stripe)
|
||||||
|
|
||||||
// Even though the set of actions is the same on the phone and
|
// Even though the set of actions is the same on the phone and
|
||||||
@@ -69,7 +89,8 @@ class AndroidNotificationTray
|
|||||||
// WearableExtender.
|
// WearableExtender.
|
||||||
val wearableExtender = WearableExtender()
|
val wearableExtender = WearableExtender()
|
||||||
.setBackground(wearableBg)
|
.setBackground(wearableBg)
|
||||||
.addAction(checkAction)
|
.addAction(addRepetitionAction)
|
||||||
|
.addAction(removeRepetitionAction)
|
||||||
.addAction(snoozeAction)
|
.addAction(snoozeAction)
|
||||||
|
|
||||||
val builder = NotificationCompat.Builder(context)
|
val builder = NotificationCompat.Builder(context)
|
||||||
@@ -78,20 +99,32 @@ class AndroidNotificationTray
|
|||||||
.setContentText(habit.description)
|
.setContentText(habit.description)
|
||||||
.setContentIntent(pendingIntents.showHabit(habit))
|
.setContentIntent(pendingIntents.showHabit(habit))
|
||||||
.setDeleteIntent(pendingIntents.dismissNotification(habit))
|
.setDeleteIntent(pendingIntents.dismissNotification(habit))
|
||||||
.addAction(checkAction)
|
.addAction(addRepetitionAction)
|
||||||
|
.addAction(removeRepetitionAction)
|
||||||
.addAction(snoozeAction)
|
.addAction(snoozeAction)
|
||||||
.setSound(ringtoneManager.getURI())
|
.setSound(ringtoneManager.getURI())
|
||||||
.extend(wearableExtender)
|
.extend(wearableExtender)
|
||||||
.setWhen(reminderTime)
|
.setWhen(reminderTime)
|
||||||
.setShowWhen(true)
|
.setShowWhen(true)
|
||||||
.setOngoing(preferences.shouldMakeNotificationsSticky())
|
.setOngoing(preferences.shouldMakeNotificationsSticky())
|
||||||
|
.setGroup("default")
|
||||||
|
|
||||||
if (preferences.shouldMakeNotificationsLed())
|
if (preferences.shouldMakeNotificationsLed())
|
||||||
builder.setLights(Color.RED, 1000, 1000)
|
builder.setLights(Color.RED, 1000, 1000)
|
||||||
|
|
||||||
val notificationManager = context.getSystemService(
|
return builder.build()
|
||||||
Activity.NOTIFICATION_SERVICE) as NotificationManager
|
}
|
||||||
|
|
||||||
notificationManager.notify(notificationId, builder.build())
|
@NonNull
|
||||||
|
private fun buildSummary(@NonNull reminderTime: Long) : Notification
|
||||||
|
{
|
||||||
|
return NotificationCompat.Builder(context)
|
||||||
|
.setSmallIcon(R.drawable.ic_notification)
|
||||||
|
.setContentTitle(context.getString(R.string.app_name))
|
||||||
|
.setWhen(reminderTime)
|
||||||
|
.setShowWhen(true)
|
||||||
|
.setGroup("default")
|
||||||
|
.setGroupSummary(true)
|
||||||
|
.build()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
BIN
uhabits-android/src/main/res/drawable-hdpi/ic_action_cancel.png
Normal file
BIN
uhabits-android/src/main/res/drawable-hdpi/ic_action_cancel.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 266 B |
BIN
uhabits-android/src/main/res/drawable-mdpi/ic_action_cancel.png
Normal file
BIN
uhabits-android/src/main/res/drawable-mdpi/ic_action_cancel.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 198 B |
BIN
uhabits-android/src/main/res/drawable-xhdpi/ic_action_cancel.png
Normal file
BIN
uhabits-android/src/main/res/drawable-xhdpi/ic_action_cancel.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 323 B |
Binary file not shown.
|
After Width: | Height: | Size: 531 B |
@@ -220,4 +220,6 @@
|
|||||||
<string name="example_question_boolean">e.g. Did you exercise today?</string>
|
<string name="example_question_boolean">e.g. Did you exercise today?</string>
|
||||||
<string name="question">Question</string>
|
<string name="question">Question</string>
|
||||||
<string name="target">Target</string>
|
<string name="target">Target</string>
|
||||||
|
<string name="yes">Yes</string>
|
||||||
|
<string name="no">No</string>
|
||||||
</resources>
|
</resources>
|
||||||
@@ -155,14 +155,14 @@ public class MemoryHabitList extends HabitList
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int indexOf(@NonNull Habit h)
|
public synchronized int indexOf(@NonNull Habit h)
|
||||||
{
|
{
|
||||||
return list.indexOf(h);
|
return list.indexOf(h);
|
||||||
}
|
}
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
@Override
|
@Override
|
||||||
public Iterator<Habit> iterator()
|
public synchronized Iterator<Habit> iterator()
|
||||||
{
|
{
|
||||||
return Collections.unmodifiableCollection(list).iterator();
|
return Collections.unmodifiableCollection(list).iterator();
|
||||||
}
|
}
|
||||||
@@ -200,13 +200,13 @@ public class MemoryHabitList extends HabitList
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int size()
|
public synchronized int size()
|
||||||
{
|
{
|
||||||
return list.size();
|
return list.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void update(List<Habit> habits)
|
public synchronized void update(List<Habit> habits)
|
||||||
{
|
{
|
||||||
resort();
|
resort();
|
||||||
getObservable().notifyListeners();
|
getObservable().notifyListeners();
|
||||||
|
|||||||
@@ -91,7 +91,7 @@ public class SQLiteHabitList extends HabitList
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Nullable
|
@Nullable
|
||||||
public Habit getById(long id)
|
public synchronized Habit getById(long id)
|
||||||
{
|
{
|
||||||
loadRecords();
|
loadRecords();
|
||||||
return list.getById(id);
|
return list.getById(id);
|
||||||
@@ -99,7 +99,7 @@ public class SQLiteHabitList extends HabitList
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
@NonNull
|
@NonNull
|
||||||
public Habit getByPosition(int position)
|
public synchronized Habit getByPosition(int position)
|
||||||
{
|
{
|
||||||
loadRecords();
|
loadRecords();
|
||||||
return list.getByPosition(position);
|
return list.getByPosition(position);
|
||||||
@@ -107,7 +107,7 @@ public class SQLiteHabitList extends HabitList
|
|||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
@Override
|
@Override
|
||||||
public HabitList getFiltered(HabitMatcher filter)
|
public synchronized HabitList getFiltered(HabitMatcher filter)
|
||||||
{
|
{
|
||||||
loadRecords();
|
loadRecords();
|
||||||
return list.getFiltered(filter);
|
return list.getFiltered(filter);
|
||||||
@@ -121,21 +121,21 @@ public class SQLiteHabitList extends HabitList
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setOrder(@NonNull Order order)
|
public synchronized void setOrder(@NonNull Order order)
|
||||||
{
|
{
|
||||||
list.setOrder(order);
|
list.setOrder(order);
|
||||||
getObservable().notifyListeners();
|
getObservable().notifyListeners();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int indexOf(@NonNull Habit h)
|
public synchronized int indexOf(@NonNull Habit h)
|
||||||
{
|
{
|
||||||
loadRecords();
|
loadRecords();
|
||||||
return list.indexOf(h);
|
return list.indexOf(h);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Iterator<Habit> iterator()
|
public synchronized Iterator<Habit> iterator()
|
||||||
{
|
{
|
||||||
loadRecords();
|
loadRecords();
|
||||||
return list.iterator();
|
return list.iterator();
|
||||||
@@ -214,7 +214,7 @@ public class SQLiteHabitList extends HabitList
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void repair()
|
public synchronized void repair()
|
||||||
{
|
{
|
||||||
loadRecords();
|
loadRecords();
|
||||||
rebuildOrder();
|
rebuildOrder();
|
||||||
@@ -222,7 +222,7 @@ public class SQLiteHabitList extends HabitList
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int size()
|
public synchronized int size()
|
||||||
{
|
{
|
||||||
loadRecords();
|
loadRecords();
|
||||||
return list.size();
|
return list.size();
|
||||||
@@ -245,7 +245,7 @@ public class SQLiteHabitList extends HabitList
|
|||||||
getObservable().notifyListeners();
|
getObservable().notifyListeners();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void reload()
|
public synchronized void reload()
|
||||||
{
|
{
|
||||||
loaded = false;
|
loaded = false;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -48,14 +48,15 @@ public class WidgetBehavior
|
|||||||
|
|
||||||
public void onAddRepetition(@NonNull Habit habit, Timestamp timestamp)
|
public void onAddRepetition(@NonNull Habit habit, Timestamp timestamp)
|
||||||
{
|
{
|
||||||
|
notificationTray.cancel(habit);
|
||||||
Repetition rep = habit.getRepetitions().getByTimestamp(timestamp);
|
Repetition rep = habit.getRepetitions().getByTimestamp(timestamp);
|
||||||
if (rep != null) return;
|
if (rep != null) return;
|
||||||
performToggle(habit, timestamp);
|
performToggle(habit, timestamp);
|
||||||
notificationTray.cancel(habit);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onRemoveRepetition(@NonNull Habit habit, Timestamp timestamp)
|
public void onRemoveRepetition(@NonNull Habit habit, Timestamp timestamp)
|
||||||
{
|
{
|
||||||
|
notificationTray.cancel(habit);
|
||||||
Repetition rep = habit.getRepetitions().getByTimestamp(timestamp);
|
Repetition rep = habit.getRepetitions().getByTimestamp(timestamp);
|
||||||
if (rep == null) return;
|
if (rep == null) return;
|
||||||
performToggle(habit, timestamp);
|
performToggle(habit, timestamp);
|
||||||
|
|||||||
Reference in New Issue
Block a user