Skip to content

Commit

Permalink
Add automatic send message
Browse files Browse the repository at this point in the history
  • Loading branch information
J-Jamet committed Aug 21, 2017
1 parent e4fddf1 commit 93ec3c1
Show file tree
Hide file tree
Showing 13 changed files with 122 additions and 22 deletions.
25 changes: 21 additions & 4 deletions RememBirthday-UI/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,15 @@
android:label="@string/about_title">
</activity>

<!-- Custom Notification -->
<receiver android:name=".notifications.NotificationEventReceiver" />
<receiver android:name=".notifications.NotificationServiceStarterReceiver">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
<action android:name="android.intent.action.TIMEZONE_CHANGED" />
<action android:name="android.intent.action.TIME_SET" />
</intent-filter>
</receiver>
<service
android:name=".notifications.NotificationIntentService"
android:enabled="true"
Expand All @@ -80,6 +89,7 @@
android:enabled="true"
android:exported="false" />

<!-- Calendar -->
<service android:name=".service.MainIntentService" />
<service
android:name=".service.AccountAuthenticatorService"
Expand All @@ -106,14 +116,21 @@
android:resource="@xml/sync_calendar" />
</service>

<receiver android:name=".notifications.NotificationEventReceiver" />
<receiver android:name=".notifications.NotificationServiceStarterReceiver">
<!-- Auto SMS -->
<receiver android:name="com.kunzisoft.autosms.receiver.BootReceiver" android:exported="false">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
<action android:name="android.intent.action.TIMEZONE_CHANGED" />
<action android:name="android.intent.action.TIME_SET" />
</intent-filter>
</receiver>
<receiver android:name="com.kunzisoft.autosms.receiver.ReminderReceiver"/>
<receiver android:name="com.kunzisoft.autosms.receiver.SmsSenderReceiver"/>
<receiver android:name="com.kunzisoft.autosms.receiver.SmsSentReceiver"/>
<receiver android:name="com.kunzisoft.autosms.receiver.SmsDeliveredReceiver"/>
<service android:name="com.kunzisoft.autosms.service.ReminderService"/>
<service android:name="com.kunzisoft.autosms.service.SmsSenderService" />
<service android:name="com.kunzisoft.autosms.service.SmsSentService" />
<service android:name="com.kunzisoft.autosms.service.SmsDeliveredService" />
<service android:name="com.kunzisoft.autosms.service.UnscheduleService"/>

</application>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,6 @@ public void onActivityCreated(Bundle savedInstanceState) {
// Add elements in database
List<AutoSms> autoSmsList = AutoSmsDbHelper.getDbHelper(getContext())
.getListAutoSmsByLookupKeyAndStatus(contact.getLookUpKey(), AutoSms.Status.PENDING);
Log.e(TAG, autoSmsList.toString());
autoMessagesAdapter.addReminders(
ProxyAutoMessage.getFromAutoSmsList(contact.getNextBirthdayWithoutHour(), autoSmsList)
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public AutoMessage(Date anniversary, int minutes) {

private void init() {
type = Type.SMS;
content = "";
content = " ";
}

public AutoMessage(Parcel in) {
Expand All @@ -55,7 +55,10 @@ public String getContent() {
}

public void setContent(String content) {
this.content = content;
if(content.isEmpty())
this.content = " ";
else
this.content = content;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@ public static AutoMessage getFromAutoSms(Date anniversary, AutoSms autoSms) {

int minutes = Minutes.minutesBetween(dateTimeScheduled, dateTimeAnniversary).getMinutes();

Log.e(TAG, "dateTime : " + dateTimeScheduled + " dateTimeAnniversary " + dateTimeAnniversary + " minutes " + minutes);

AutoMessage autoMessage = new AutoMessage(anniversary, minutes);
autoMessage.setId(autoSms.getDateCreated().getTime());
autoMessage.setContent(autoSms.getMessage());
Expand Down
6 changes: 3 additions & 3 deletions RememBirthday-UI/src/main/res/values-fr/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -133,15 +133,15 @@
<string name="pref_category_reminders_title">Rappels</string>

<string name="pref_reminders_days_title">Jours par défaut</string>
<string name="pref_reminders_days_summary">Ex : "0#2#7" Notification de démon visible pour le jour, 2 et 7 jours avant l\'événement.</string>
<string name="pref_reminders_days_summary">Ex : "0#2#7" Notification visible pour le jour, 2 et 7 jours avant l\'événement.</string>

<string name="pref_reminders_time_title">Heure par défaut</string>
<string name="pref_reminders_time_summary">Heure de l\événement du démon : [time]</string>

<string name="pref_category_special_title">Special</string>

<string name="pref_special_service_title">Puissants démons</string>
<string name="pref_special_service_summary">Créer des démons pour la gestion de cadeaux ou l\'envoie automatique de messages.</string>
<string name="pref_special_service_title">Services Spéciaux</string>
<string name="pref_special_service_summary">Créer des services spéciaux pour la gestion de cadeaux ou l\'envoie automatique de messages.</string>

<string name="pref_auto_sms_reminders_title">Rappels Auto-SMS</string>
<string name="pref_auto_sms_reminders_summary">Rappelle avant l\'envoi d\'un auto-SMS.</string>
Expand Down
8 changes: 3 additions & 5 deletions RememBirthday-UI/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@

<string name="pref_reminders_days_key" translatable="false">notifications_day_enable</string>
<string name="pref_reminders_days_title">Default days</string>
<string name="pref_reminders_days_summary">Ex : "0#2#7" Daemon notification visible on the day, 2 and 7 days before the event.</string>
<string name="pref_reminders_days_summary">Ex : "0#2#7" Notification visible on the day, 2 and 7 days before the event.</string>
<string name="pref_reminders_days_default" translatable="false">0</string>

<string name="pref_reminders_time_key" translatable="false">notifications_time_enable</string>
Expand All @@ -154,14 +154,12 @@
<string name="pref_category_special_title">Special</string>

<string name="pref_special_service_key" translatable="false">notifications_service_enable</string>
<string name="pref_special_service_title">Powerful daemons</string>
<string name="pref_special_service_summary">Creates daemons for gift management or automatic message sending.</string>
<string name="pref_special_service_title">Special Services</string>
<string name="pref_special_service_summary">Creates special services for gift management or automatic message sending.</string>
<string name="pref_special_service_default" translatable="false">false</string>

<string name="pref_auto_sms_reminders_key" translatable="false">auto_sms_reminders</string>
<string name="pref_auto_sms_reminders_title">Auto-SMS Reminders</string>
<string name="pref_auto_sms_reminders_summary">Remind before sending SMS.</string>
<string name="pref_auto_sms_reminders_default" translatable="false">false</string>

<string name="pref_hide_inactive_features_key" translatable="false">hide_inactive_feature</string>
<string name="pref_hide_inactive_features_title">Hide inactive features</string>
Expand Down
3 changes: 1 addition & 2 deletions auto-sms/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.kunzisoft.scratchecklib">
package="com.kunzisoft.autosms">

<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<application android:allowBackup="true" android:label="@string/app_name"
android:supportsRtl="true">

</application>

</manifest>
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ public Scheduler(Context context) {
alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
}


public void schedule(AutoSms sms, boolean remindersActive) {
if (null == alarmManager) {
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,23 @@ public List<AutoSms> getListAutoSmsByLookupKeyAndStatus(String lookupKey, AutoSm
if (cursor != null) {
List<AutoSms> results = getListAutoSms(cursor);
cursor.close();
Log.e(TAG, "LIST AutoSMS" + results);
return results;
}
return null;
}

public List<AutoSms> getListAutoSmsByStatus(AutoSms.Status status) {
Cursor cursor = AutoSmsDbHelper.getReadableDatabase().query(
TABLE_SMS,
new String[] { "*", COLUMN_TIMESTAMP_CREATED + " AS _id" },
COLUMN_STATUS + "=?",
new String[] {status.name()},
null,
null,
COLUMN_TIMESTAMP_CREATED + " DESC");
if (cursor != null) {
List<AutoSms> results = getListAutoSms(cursor);
cursor.close();
return results;
}
return null;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package com.kunzisoft.autosms.receiver;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.text.TextUtils;
import android.util.Log;

import com.kunzisoft.autosms.Scheduler;
import com.kunzisoft.autosms.database.AutoSmsDbHelper;
import com.kunzisoft.autosms.model.AutoSms;


import java.util.Iterator;
import java.util.List;

public class BootReceiver extends BroadcastReceiver {

@Override
public void onReceive(Context context, Intent intent) {
Log.i(getClass().getName(), "Rescheduling all the sms");
String action = intent.getAction();
if (TextUtils.isEmpty(action) || !action.equals(Intent.ACTION_BOOT_COMPLETED)) {
return;
}
List<AutoSms> pendingSms = AutoSmsDbHelper.getDbHelper(context).getListAutoSmsByStatus(AutoSms.Status.PENDING);
Iterator<AutoSms> i = pendingSms.iterator();

// TODO preference notifications

Scheduler scheduler = new Scheduler(context);
while (i.hasNext()) {
scheduler.schedule(i.next(), true);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,6 @@ private SmsManager getSmsManager(int subscriptionId) {
private void scheduleNextSms(AutoSms sms) {
new CalendarResolver().initCalendar(sms.getDateScheduled()).setRecurringMode(sms.getRecurringMode()).advance();
AutoSmsDbHelper.getDbHelper(this).insert(sms);
new Scheduler(getApplicationContext()).schedule(sms, false);
new Scheduler(getApplicationContext()).schedule(sms, true);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package com.kunzisoft.autosms.service;

import android.content.Context;
import android.content.Intent;
import android.util.Log;

import com.kunzisoft.autosms.Scheduler;
import com.kunzisoft.autosms.database.AutoSmsDbHelper;

public class UnscheduleService extends SmsIntentService {

public UnscheduleService() {
super("UnscheduleService");
}

@Override
protected void onHandleIntent(Intent intent) {
super.onHandleIntent(intent);
if (timestampCreated == 0) {
return;
}
Log.i(getClass().getName(), "Removing sms " + timestampCreated);
unschedule(getApplicationContext(), timestampCreated);
}

static private void unschedule(Context context, long timestampCreated) {
new Scheduler(context).unschedule(timestampCreated);
AutoSmsDbHelper.getDbHelper(context).deleteById(timestampCreated);
Log.i(UnscheduleService.class.getName(), "Deleting notification with id " + timestampCreated);
//new NotificationManagerWrapper(context).cancel(id);
}
}
3 changes: 3 additions & 0 deletions auto-sms/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
<resources>
<string name="app_name" translatable="false">Auto-SMS-Libraries</string>

<string name="pref_auto_sms_reminders_key" translatable="false">auto_sms_reminders</string>
<string name="pref_auto_sms_reminders_default" translatable="false">false</string>
</resources>

0 comments on commit 93ec3c1

Please sign in to comment.