mirror of https://github.com/iSoron/uhabits.git
parent
3783fd8506
commit
efcb5710c0
@ -1,130 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) 2016 Álinson Santos Xavier <isoron@gmail.com>
|
|
||||||
*
|
|
||||||
* This file is part of Loop Habit Tracker.
|
|
||||||
*
|
|
||||||
* Loop Habit Tracker is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by the
|
|
||||||
* Free Software Foundation, either version 3 of the License, or (at your
|
|
||||||
* option) any later version.
|
|
||||||
*
|
|
||||||
* Loop Habit Tracker is distributed in the hope that it will be useful, but
|
|
||||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
|
||||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
|
||||||
* more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License along
|
|
||||||
* with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package org.isoron.uhabits;
|
|
||||||
|
|
||||||
import android.app.*;
|
|
||||||
import android.content.*;
|
|
||||||
|
|
||||||
import org.isoron.androidbase.*;
|
|
||||||
import org.isoron.uhabits.core.database.*;
|
|
||||||
import org.isoron.uhabits.core.preferences.*;
|
|
||||||
import org.isoron.uhabits.core.reminders.*;
|
|
||||||
import org.isoron.uhabits.core.tasks.*;
|
|
||||||
import org.isoron.uhabits.core.ui.*;
|
|
||||||
import org.isoron.uhabits.utils.*;
|
|
||||||
import org.isoron.uhabits.widgets.*;
|
|
||||||
|
|
||||||
import java.io.*;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The Android application for Loop Habit Tracker.
|
|
||||||
*/
|
|
||||||
public class HabitsApplication extends Application
|
|
||||||
{
|
|
||||||
private Context context;
|
|
||||||
|
|
||||||
private static HabitsApplicationComponent component;
|
|
||||||
|
|
||||||
private WidgetUpdater widgetUpdater;
|
|
||||||
|
|
||||||
private ReminderScheduler reminderScheduler;
|
|
||||||
|
|
||||||
private NotificationTray notificationTray;
|
|
||||||
|
|
||||||
public HabitsApplicationComponent getComponent()
|
|
||||||
{
|
|
||||||
return component;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void setComponent(HabitsApplicationComponent component)
|
|
||||||
{
|
|
||||||
HabitsApplication.component = component;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static boolean isTestMode()
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
Class.forName("org.isoron.uhabits.BaseAndroidTest");
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
catch (final ClassNotFoundException e)
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onCreate()
|
|
||||||
{
|
|
||||||
super.onCreate();
|
|
||||||
context = this;
|
|
||||||
|
|
||||||
component = DaggerHabitsApplicationComponent
|
|
||||||
.builder()
|
|
||||||
.appContextModule(new AppContextModule(context))
|
|
||||||
.build();
|
|
||||||
|
|
||||||
if (isTestMode())
|
|
||||||
{
|
|
||||||
File db = DatabaseUtils.getDatabaseFile(context);
|
|
||||||
if (db.exists()) db.delete();
|
|
||||||
}
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
DatabaseUtils.initializeDatabase(context);
|
|
||||||
}
|
|
||||||
catch (UnsupportedDatabaseVersionException e)
|
|
||||||
{
|
|
||||||
File db = DatabaseUtils.getDatabaseFile(context);
|
|
||||||
db.renameTo(new File(db.getAbsolutePath() + ".invalid"));
|
|
||||||
DatabaseUtils.initializeDatabase(context);
|
|
||||||
}
|
|
||||||
|
|
||||||
widgetUpdater = component.getWidgetUpdater();
|
|
||||||
widgetUpdater.startListening();
|
|
||||||
|
|
||||||
reminderScheduler = component.getReminderScheduler();
|
|
||||||
reminderScheduler.startListening();
|
|
||||||
|
|
||||||
notificationTray = component.getNotificationTray();
|
|
||||||
notificationTray.startListening();
|
|
||||||
|
|
||||||
Preferences prefs = component.getPreferences();
|
|
||||||
prefs.setLastAppVersion(BuildConfig.VERSION_CODE);
|
|
||||||
|
|
||||||
TaskRunner taskRunner = component.getTaskRunner();
|
|
||||||
taskRunner.execute(() -> {
|
|
||||||
reminderScheduler.scheduleAll();
|
|
||||||
widgetUpdater.updateWidgets();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onTerminate()
|
|
||||||
{
|
|
||||||
context = null;
|
|
||||||
reminderScheduler.stopListening();
|
|
||||||
widgetUpdater.stopListening();
|
|
||||||
notificationTray.stopListening();
|
|
||||||
super.onTerminate();
|
|
||||||
}
|
|
||||||
}
|
|
@ -0,0 +1,104 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2016 Álinson Santos Xavier <isoron@gmail.com>
|
||||||
|
*
|
||||||
|
* This file is part of Loop Habit Tracker.
|
||||||
|
*
|
||||||
|
* Loop Habit Tracker is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by the
|
||||||
|
* Free Software Foundation, either version 3 of the License, or (at your
|
||||||
|
* option) any later version.
|
||||||
|
*
|
||||||
|
* Loop Habit Tracker is distributed in the hope that it will be useful, but
|
||||||
|
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||||
|
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||||
|
* more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License along
|
||||||
|
* with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.isoron.uhabits
|
||||||
|
|
||||||
|
import android.app.*
|
||||||
|
import android.content.*
|
||||||
|
import org.isoron.androidbase.*
|
||||||
|
import org.isoron.uhabits.core.database.*
|
||||||
|
import org.isoron.uhabits.core.reminders.*
|
||||||
|
import org.isoron.uhabits.core.ui.*
|
||||||
|
import org.isoron.uhabits.utils.*
|
||||||
|
import org.isoron.uhabits.widgets.*
|
||||||
|
import java.io.*
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The Android application for Loop Habit Tracker.
|
||||||
|
*/
|
||||||
|
class HabitsApplication : Application() {
|
||||||
|
|
||||||
|
private lateinit var context: Context
|
||||||
|
private lateinit var widgetUpdater: WidgetUpdater
|
||||||
|
private lateinit var reminderScheduler: ReminderScheduler
|
||||||
|
private lateinit var notificationTray: NotificationTray
|
||||||
|
|
||||||
|
override fun onCreate() {
|
||||||
|
super.onCreate()
|
||||||
|
context = this
|
||||||
|
HabitsApplication.component = DaggerHabitsApplicationComponent
|
||||||
|
.builder()
|
||||||
|
.appContextModule(AppContextModule(context))
|
||||||
|
.build()
|
||||||
|
|
||||||
|
if (isTestMode()) {
|
||||||
|
val db = DatabaseUtils.getDatabaseFile(context)
|
||||||
|
if (db.exists()) db.delete()
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
DatabaseUtils.initializeDatabase(context)
|
||||||
|
} catch (e: UnsupportedDatabaseVersionException) {
|
||||||
|
val db = DatabaseUtils.getDatabaseFile(context)
|
||||||
|
db.renameTo(File(db.absolutePath + ".invalid"))
|
||||||
|
DatabaseUtils.initializeDatabase(context)
|
||||||
|
}
|
||||||
|
|
||||||
|
widgetUpdater = component.widgetUpdater
|
||||||
|
widgetUpdater.startListening()
|
||||||
|
|
||||||
|
reminderScheduler = component.reminderScheduler
|
||||||
|
reminderScheduler.startListening()
|
||||||
|
|
||||||
|
notificationTray = component.notificationTray
|
||||||
|
notificationTray.startListening()
|
||||||
|
|
||||||
|
val prefs = component.preferences
|
||||||
|
prefs.setLastAppVersion(BuildConfig.VERSION_CODE)
|
||||||
|
|
||||||
|
val taskRunner = component.taskRunner
|
||||||
|
taskRunner.execute {
|
||||||
|
reminderScheduler.scheduleAll()
|
||||||
|
widgetUpdater.updateWidgets()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onTerminate() {
|
||||||
|
reminderScheduler.stopListening()
|
||||||
|
widgetUpdater.stopListening()
|
||||||
|
notificationTray.stopListening()
|
||||||
|
super.onTerminate()
|
||||||
|
}
|
||||||
|
|
||||||
|
val component: HabitsApplicationComponent
|
||||||
|
get() = HabitsApplication.component
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
lateinit var component: HabitsApplicationComponent
|
||||||
|
|
||||||
|
fun isTestMode(): Boolean {
|
||||||
|
try {
|
||||||
|
Class.forName("org.isoron.uhabits.BaseAndroidTest")
|
||||||
|
return true
|
||||||
|
} catch (e: ClassNotFoundException) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -1,65 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) 2017 Álinson Santos Xavier <isoron@gmail.com>
|
|
||||||
*
|
|
||||||
* This file is part of Loop Habit Tracker.
|
|
||||||
*
|
|
||||||
* Loop Habit Tracker is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by the
|
|
||||||
* Free Software Foundation, either version 3 of the License, or (at your
|
|
||||||
* option) any later version.
|
|
||||||
*
|
|
||||||
* Loop Habit Tracker is distributed in the hope that it will be useful, but
|
|
||||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
|
||||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
|
||||||
* more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License along
|
|
||||||
* with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
package org.isoron.uhabits;
|
|
||||||
|
|
||||||
import android.content.*;
|
|
||||||
import android.database.sqlite.*;
|
|
||||||
|
|
||||||
import org.isoron.uhabits.core.database.*;
|
|
||||||
import org.isoron.uhabits.database.*;
|
|
||||||
|
|
||||||
|
|
||||||
public class HabitsDatabaseOpener extends SQLiteOpenHelper
|
|
||||||
{
|
|
||||||
private final int version;
|
|
||||||
|
|
||||||
private MigrationHelper helper;
|
|
||||||
|
|
||||||
public HabitsDatabaseOpener(Context context,
|
|
||||||
String databaseFilename,
|
|
||||||
int version)
|
|
||||||
{
|
|
||||||
super(context, databaseFilename, null, version);
|
|
||||||
this.version = version;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onCreate(SQLiteDatabase db)
|
|
||||||
{
|
|
||||||
db.setVersion(8);
|
|
||||||
onUpgrade(db, -1, version);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion)
|
|
||||||
{
|
|
||||||
if(db.getVersion() < 8) throw new UnsupportedDatabaseVersionException();
|
|
||||||
helper = new MigrationHelper(new AndroidDatabase(db));
|
|
||||||
helper.migrateTo(newVersion);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onDowngrade(SQLiteDatabase db, int oldVersion, int newVersion)
|
|
||||||
{
|
|
||||||
throw new UnsupportedDatabaseVersionException();
|
|
||||||
}
|
|
||||||
}
|
|
@ -0,0 +1,54 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2017 Álinson Santos Xavier <isoron@gmail.com>
|
||||||
|
*
|
||||||
|
* This file is part of Loop Habit Tracker.
|
||||||
|
*
|
||||||
|
* Loop Habit Tracker is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by the
|
||||||
|
* Free Software Foundation, either version 3 of the License, or (at your
|
||||||
|
* option) any later version.
|
||||||
|
*
|
||||||
|
* Loop Habit Tracker is distributed in the hope that it will be useful, but
|
||||||
|
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||||
|
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||||
|
* more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License along
|
||||||
|
* with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.isoron.uhabits
|
||||||
|
|
||||||
|
import android.content.*
|
||||||
|
import android.database.sqlite.*
|
||||||
|
|
||||||
|
import org.isoron.uhabits.core.database.*
|
||||||
|
import org.isoron.uhabits.database.*
|
||||||
|
|
||||||
|
class HabitsDatabaseOpener(
|
||||||
|
context: Context,
|
||||||
|
databaseFilename: String,
|
||||||
|
private val version: Int
|
||||||
|
) : SQLiteOpenHelper(context, databaseFilename, null, version) {
|
||||||
|
|
||||||
|
override fun onCreate(db: SQLiteDatabase) {
|
||||||
|
db.version = 8
|
||||||
|
onUpgrade(db, -1, version)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onUpgrade(db: SQLiteDatabase,
|
||||||
|
oldVersion: Int,
|
||||||
|
newVersion: Int) {
|
||||||
|
if (db.version < 8) throw UnsupportedDatabaseVersionException()
|
||||||
|
val helper = MigrationHelper(AndroidDatabase(db))
|
||||||
|
helper.migrateTo(newVersion)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onDowngrade(db: SQLiteDatabase,
|
||||||
|
oldVersion: Int,
|
||||||
|
newVersion: Int) {
|
||||||
|
throw UnsupportedDatabaseVersionException()
|
||||||
|
}
|
||||||
|
}
|
@ -1,98 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) 2017 Álinson Santos Xavier <isoron@gmail.com>
|
|
||||||
*
|
|
||||||
* This file is part of Loop Habit Tracker.
|
|
||||||
*
|
|
||||||
* Loop Habit Tracker is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by the
|
|
||||||
* Free Software Foundation, either version 3 of the License, or (at your
|
|
||||||
* option) any later version.
|
|
||||||
*
|
|
||||||
* Loop Habit Tracker is distributed in the hope that it will be useful, but
|
|
||||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
|
||||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
|
||||||
* more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License along
|
|
||||||
* with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package org.isoron.uhabits;
|
|
||||||
|
|
||||||
import org.isoron.uhabits.core.*;
|
|
||||||
import org.isoron.uhabits.core.commands.*;
|
|
||||||
import org.isoron.uhabits.core.database.*;
|
|
||||||
import org.isoron.uhabits.core.models.*;
|
|
||||||
import org.isoron.uhabits.core.models.sqlite.*;
|
|
||||||
import org.isoron.uhabits.core.preferences.*;
|
|
||||||
import org.isoron.uhabits.core.reminders.*;
|
|
||||||
import org.isoron.uhabits.core.tasks.*;
|
|
||||||
import org.isoron.uhabits.core.ui.*;
|
|
||||||
import org.isoron.uhabits.database.*;
|
|
||||||
import org.isoron.uhabits.intents.*;
|
|
||||||
import org.isoron.uhabits.notifications.*;
|
|
||||||
import org.isoron.uhabits.preferences.*;
|
|
||||||
import org.isoron.uhabits.utils.*;
|
|
||||||
|
|
||||||
import dagger.*;
|
|
||||||
|
|
||||||
@Module
|
|
||||||
public class HabitsModule
|
|
||||||
{
|
|
||||||
@Provides
|
|
||||||
@AppScope
|
|
||||||
public static Preferences getPreferences(SharedPreferencesStorage storage)
|
|
||||||
{
|
|
||||||
return new Preferences(storage);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Provides
|
|
||||||
@AppScope
|
|
||||||
public static ReminderScheduler getReminderScheduler(IntentScheduler sys,
|
|
||||||
CommandRunner commandRunner,
|
|
||||||
HabitList habitList)
|
|
||||||
{
|
|
||||||
return new ReminderScheduler(commandRunner, habitList, sys);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Provides
|
|
||||||
@AppScope
|
|
||||||
public static NotificationTray getTray(TaskRunner taskRunner,
|
|
||||||
CommandRunner commandRunner,
|
|
||||||
Preferences preferences,
|
|
||||||
AndroidNotificationTray screen)
|
|
||||||
{
|
|
||||||
return new NotificationTray(taskRunner, commandRunner, preferences,
|
|
||||||
screen);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Provides
|
|
||||||
@AppScope
|
|
||||||
public static WidgetPreferences getWidgetPreferences(
|
|
||||||
SharedPreferencesStorage storage)
|
|
||||||
{
|
|
||||||
return new WidgetPreferences(storage);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Provides
|
|
||||||
public ModelFactory getModelFactory()
|
|
||||||
{
|
|
||||||
return new SQLModelFactory(
|
|
||||||
new AndroidDatabase(DatabaseUtils.openDatabase()));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Provides
|
|
||||||
@AppScope
|
|
||||||
public HabitList getHabitList(SQLiteHabitList list)
|
|
||||||
{
|
|
||||||
return list;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Provides
|
|
||||||
@AppScope
|
|
||||||
public DatabaseOpener getDatabaseOpener(AndroidDatabaseOpener opener)
|
|
||||||
{
|
|
||||||
return opener;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -0,0 +1,93 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2017 Álinson Santos Xavier <isoron@gmail.com>
|
||||||
|
*
|
||||||
|
* This file is part of Loop Habit Tracker.
|
||||||
|
*
|
||||||
|
* Loop Habit Tracker is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by the
|
||||||
|
* Free Software Foundation, either version 3 of the License, or (at your
|
||||||
|
* option) any later version.
|
||||||
|
*
|
||||||
|
* Loop Habit Tracker is distributed in the hope that it will be useful, but
|
||||||
|
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||||
|
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||||
|
* more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License along
|
||||||
|
* with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.isoron.uhabits
|
||||||
|
|
||||||
|
import dagger.*
|
||||||
|
import org.isoron.uhabits.core.*
|
||||||
|
import org.isoron.uhabits.core.commands.*
|
||||||
|
import org.isoron.uhabits.core.database.*
|
||||||
|
import org.isoron.uhabits.core.models.*
|
||||||
|
import org.isoron.uhabits.core.models.sqlite.*
|
||||||
|
import org.isoron.uhabits.core.preferences.*
|
||||||
|
import org.isoron.uhabits.core.reminders.*
|
||||||
|
import org.isoron.uhabits.core.tasks.*
|
||||||
|
import org.isoron.uhabits.core.ui.*
|
||||||
|
import org.isoron.uhabits.database.*
|
||||||
|
import org.isoron.uhabits.intents.*
|
||||||
|
import org.isoron.uhabits.notifications.*
|
||||||
|
import org.isoron.uhabits.preferences.*
|
||||||
|
import org.isoron.uhabits.utils.*
|
||||||
|
|
||||||
|
@Module
|
||||||
|
class HabitsModule {
|
||||||
|
@Provides
|
||||||
|
@AppScope
|
||||||
|
fun getPreferences(storage: SharedPreferencesStorage): Preferences {
|
||||||
|
return Preferences(storage)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Provides
|
||||||
|
@AppScope
|
||||||
|
fun getReminderScheduler(
|
||||||
|
sys: IntentScheduler,
|
||||||
|
commandRunner: CommandRunner,
|
||||||
|
habitList: HabitList
|
||||||
|
): ReminderScheduler {
|
||||||
|
return ReminderScheduler(commandRunner, habitList, sys)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Provides
|
||||||
|
@AppScope
|
||||||
|
fun getTray(
|
||||||
|
taskRunner: TaskRunner,
|
||||||
|
commandRunner: CommandRunner,
|
||||||
|
preferences: Preferences,
|
||||||
|
screen: AndroidNotificationTray
|
||||||
|
): NotificationTray {
|
||||||
|
return NotificationTray(taskRunner, commandRunner, preferences, screen)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Provides
|
||||||
|
@AppScope
|
||||||
|
fun getWidgetPreferences(
|
||||||
|
storage: SharedPreferencesStorage
|
||||||
|
): WidgetPreferences {
|
||||||
|
return WidgetPreferences(storage)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Provides
|
||||||
|
@AppScope
|
||||||
|
fun getModelFactory(): ModelFactory {
|
||||||
|
return SQLModelFactory(AndroidDatabase(DatabaseUtils.openDatabase()))
|
||||||
|
}
|
||||||
|
|
||||||
|
@Provides
|
||||||
|
@AppScope
|
||||||
|
fun getHabitList(list: SQLiteHabitList): HabitList {
|
||||||
|
return list
|
||||||
|
}
|
||||||
|
|
||||||
|
@Provides
|
||||||
|
@AppScope
|
||||||
|
fun getDatabaseOpener(opener: AndroidDatabaseOpener): DatabaseOpener {
|
||||||
|
return opener
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -1,139 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) 2016 Álinson Santos Xavier <isoron@gmail.com>
|
|
||||||
*
|
|
||||||
* This file is part of Loop Habit Tracker.
|
|
||||||
*
|
|
||||||
* Loop Habit Tracker is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by the
|
|
||||||
* Free Software Foundation, either version 3 of the License, or (at your
|
|
||||||
* option) any later version.
|
|
||||||
*
|
|
||||||
* Loop Habit Tracker is distributed in the hope that it will be useful, but
|
|
||||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
|
||||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
|
||||||
* more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License along
|
|
||||||
* with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package org.isoron.uhabits.preferences;
|
|
||||||
|
|
||||||
import android.content.*;
|
|
||||||
import android.preference.*;
|
|
||||||
import android.support.annotation.*;
|
|
||||||
|
|
||||||
import org.isoron.androidbase.*;
|
|
||||||
import org.isoron.uhabits.R;
|
|
||||||
import org.isoron.uhabits.core.*;
|
|
||||||
import org.isoron.uhabits.core.preferences.*;
|
|
||||||
|
|
||||||
import javax.inject.*;
|
|
||||||
|
|
||||||
@AppScope
|
|
||||||
public class SharedPreferencesStorage
|
|
||||||
implements SharedPreferences.OnSharedPreferenceChangeListener,
|
|
||||||
Preferences.Storage
|
|
||||||
{
|
|
||||||
@NonNull
|
|
||||||
private SharedPreferences sharedPrefs;
|
|
||||||
|
|
||||||
@Nullable
|
|
||||||
private Preferences preferences;
|
|
||||||
|
|
||||||
@Inject
|
|
||||||
public SharedPreferencesStorage(@AppContext Context context)
|
|
||||||
{
|
|
||||||
sharedPrefs = PreferenceManager.getDefaultSharedPreferences(context);
|
|
||||||
sharedPrefs.registerOnSharedPreferenceChangeListener(this);
|
|
||||||
PreferenceManager.setDefaultValues(context, R.xml.preferences, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void clear()
|
|
||||||
{
|
|
||||||
sharedPrefs.edit().clear().apply();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean getBoolean(String key, boolean defValue)
|
|
||||||
{
|
|
||||||
return sharedPrefs.getBoolean(key, defValue);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getInt(String key, int defValue)
|
|
||||||
{
|
|
||||||
return sharedPrefs.getInt(key, defValue);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public long getLong(String key, int defValue)
|
|
||||||
{
|
|
||||||
return sharedPrefs.getLong(key, defValue);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getString(String key, String defValue)
|
|
||||||
{
|
|
||||||
return sharedPrefs.getString(key, defValue);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onAttached(Preferences preferences)
|
|
||||||
{
|
|
||||||
this.preferences = preferences;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences,
|
|
||||||
String key)
|
|
||||||
{
|
|
||||||
if(preferences == null) return;
|
|
||||||
sharedPreferences.unregisterOnSharedPreferenceChangeListener(this);
|
|
||||||
switch (key)
|
|
||||||
{
|
|
||||||
case "pref_checkmark_reverse_order":
|
|
||||||
preferences.setCheckmarkSequenceReversed(getBoolean(key, false));
|
|
||||||
break;
|
|
||||||
|
|
||||||
case "pref_sticky_notifications":
|
|
||||||
preferences.setNotificationsSticky(getBoolean(key, false));
|
|
||||||
break;
|
|
||||||
|
|
||||||
case "pref_feature_sync":
|
|
||||||
preferences.setSyncEnabled(getBoolean(key, false));
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
sharedPreferences.registerOnSharedPreferenceChangeListener(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void putBoolean(String key, boolean value)
|
|
||||||
{
|
|
||||||
sharedPrefs.edit().putBoolean(key, value).apply();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void putInt(String key, int value)
|
|
||||||
{
|
|
||||||
sharedPrefs.edit().putInt(key, value).apply();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void putLong(String key, long value)
|
|
||||||
{
|
|
||||||
sharedPrefs.edit().putLong(key, value).apply();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void putString(String key, String value)
|
|
||||||
{
|
|
||||||
sharedPrefs.edit().putString(key, value).apply();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void remove(String key)
|
|
||||||
{
|
|
||||||
sharedPrefs.edit().remove(key).apply();
|
|
||||||
}
|
|
||||||
}
|
|
@ -0,0 +1,93 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2016 Álinson Santos Xavier <isoron@gmail.com>
|
||||||
|
*
|
||||||
|
* This file is part of Loop Habit Tracker.
|
||||||
|
*
|
||||||
|
* Loop Habit Tracker is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by the
|
||||||
|
* Free Software Foundation, either version 3 of the License, or (at your
|
||||||
|
* option) any later version.
|
||||||
|
*
|
||||||
|
* Loop Habit Tracker is distributed in the hope that it will be useful, but
|
||||||
|
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||||
|
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||||
|
* more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License along
|
||||||
|
* with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.isoron.uhabits.preferences
|
||||||
|
|
||||||
|
import android.content.*
|
||||||
|
import android.preference.*
|
||||||
|
import org.isoron.androidbase.*
|
||||||
|
import org.isoron.uhabits.R
|
||||||
|
import org.isoron.uhabits.core.*
|
||||||
|
import org.isoron.uhabits.core.preferences.*
|
||||||
|
import javax.inject.*
|
||||||
|
|
||||||
|
@AppScope
|
||||||
|
class SharedPreferencesStorage
|
||||||
|
@Inject constructor(
|
||||||
|
@AppContext context: Context
|
||||||
|
) : SharedPreferences.OnSharedPreferenceChangeListener, Preferences.Storage {
|
||||||
|
|
||||||
|
private val sharedPrefs: SharedPreferences =
|
||||||
|
PreferenceManager.getDefaultSharedPreferences(context)
|
||||||
|
|
||||||
|
private var preferences: Preferences? = null
|
||||||
|
|
||||||
|
init {
|
||||||
|
sharedPrefs.registerOnSharedPreferenceChangeListener(this)
|
||||||
|
PreferenceManager.setDefaultValues(context, R.xml.preferences, false)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun clear() = sharedPrefs.edit().clear().apply()
|
||||||
|
|
||||||
|
override fun getBoolean(key: String, defValue: Boolean) =
|
||||||
|
sharedPrefs.getBoolean(key, defValue)
|
||||||
|
|
||||||
|
override fun getInt(key: String, defValue: Int) =
|
||||||
|
sharedPrefs.getInt(key, defValue)
|
||||||
|
|
||||||
|
override fun getLong(key: String, defValue: Int) =
|
||||||
|
sharedPrefs.getLong(key, defValue.toLong())
|
||||||
|
|
||||||
|
override fun getString(key: String, defValue: String): String =
|
||||||
|
sharedPrefs.getString(key, defValue)
|
||||||
|
|
||||||
|
override fun onAttached(preferences: Preferences) {
|
||||||
|
this.preferences = preferences
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun putBoolean(key: String, value: Boolean) =
|
||||||
|
sharedPrefs.edit().putBoolean(key, value).apply()
|
||||||
|
|
||||||
|
override fun putInt(key: String, value: Int) =
|
||||||
|
sharedPrefs.edit().putInt(key, value).apply()
|
||||||
|
|
||||||
|
override fun putLong(key: String, value: Long) =
|
||||||
|
sharedPrefs.edit().putLong(key, value).apply()
|
||||||
|
|
||||||
|
override fun putString(key: String, value: String) =
|
||||||
|
sharedPrefs.edit().putString(key, value).apply()
|
||||||
|
|
||||||
|
override fun remove(key: String) =
|
||||||
|
sharedPrefs.edit().remove(key).apply()
|
||||||
|
|
||||||
|
override fun onSharedPreferenceChanged(sharedPreferences: SharedPreferences,
|
||||||
|
key: String) {
|
||||||
|
val preferences = this.preferences ?: return
|
||||||
|
sharedPreferences.unregisterOnSharedPreferenceChangeListener(this)
|
||||||
|
when (key) {
|
||||||
|
"pref_checkmark_reverse_order" ->
|
||||||
|
preferences.isCheckmarkSequenceReversed = getBoolean(key, false)
|
||||||
|
"pref_sticky_notifications" ->
|
||||||
|
preferences.setNotificationsSticky(getBoolean(key, false))
|
||||||
|
"pref_feature_sync" ->
|
||||||
|
preferences.isSyncEnabled = getBoolean(key, false)
|
||||||
|
}
|
||||||
|
sharedPreferences.registerOnSharedPreferenceChangeListener(this)
|
||||||
|
}
|
||||||
|
}
|
@ -1,52 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) 2016 Álinson Santos Xavier <isoron@gmail.com>
|
|
||||||
*
|
|
||||||
* This file is part of Loop Habit Tracker.
|
|
||||||
*
|
|
||||||
* Loop Habit Tracker is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by the
|
|
||||||
* Free Software Foundation, either version 3 of the License, or (at your
|
|
||||||
* option) any later version.
|
|
||||||
*
|
|
||||||
* Loop Habit Tracker is distributed in the hope that it will be useful, but
|
|
||||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
|
||||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
|
||||||
* more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License along
|
|
||||||
* with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package org.isoron.uhabits.receivers;
|
|
||||||
|
|
||||||
import android.content.*;
|
|
||||||
import android.net.*;
|
|
||||||
import android.support.annotation.*;
|
|
||||||
|
|
||||||
import org.isoron.uhabits.*;
|
|
||||||
import org.isoron.uhabits.sync.*;
|
|
||||||
|
|
||||||
import static android.content.Context.*;
|
|
||||||
|
|
||||||
public class ConnectivityReceiver extends BroadcastReceiver
|
|
||||||
{
|
|
||||||
@Override
|
|
||||||
public void onReceive(@Nullable Context context, @Nullable Intent intent)
|
|
||||||
{
|
|
||||||
if (context == null) return;
|
|
||||||
if (intent == null) return;
|
|
||||||
|
|
||||||
HabitsApplicationComponent component =
|
|
||||||
((HabitsApplication) context.getApplicationContext()).getComponent();
|
|
||||||
|
|
||||||
NetworkInfo networkInfo =
|
|
||||||
((ConnectivityManager) context.getSystemService(
|
|
||||||
CONNECTIVITY_SERVICE)).getActiveNetworkInfo();
|
|
||||||
|
|
||||||
boolean isConnected =
|
|
||||||
(networkInfo != null && networkInfo.isConnectedOrConnecting());
|
|
||||||
|
|
||||||
SyncManager syncManager = component.getSyncManager();
|
|
||||||
syncManager.onNetworkStatusChanged(isConnected);
|
|
||||||
}
|
|
||||||
}
|
|
@ -0,0 +1,38 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2016 Álinson Santos Xavier <isoron@gmail.com>
|
||||||
|
*
|
||||||
|
* This file is part of Loop Habit Tracker.
|
||||||
|
*
|
||||||
|
* Loop Habit Tracker is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by the
|
||||||
|
* Free Software Foundation, either version 3 of the License, or (at your
|
||||||
|
* option) any later version.
|
||||||
|
*
|
||||||
|
* Loop Habit Tracker is distributed in the hope that it will be useful, but
|
||||||
|
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||||
|
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||||
|
* more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License along
|
||||||
|
* with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.isoron.uhabits.receivers
|
||||||
|
|
||||||
|
import android.content.*
|
||||||
|
import android.content.Context.*
|
||||||
|
import android.net.*
|
||||||
|
import org.isoron.uhabits.*
|
||||||
|
|
||||||
|
class ConnectivityReceiver : BroadcastReceiver() {
|
||||||
|
override fun onReceive(context: Context?, intent: Intent?) {
|
||||||
|
if (context == null || intent == null) return
|
||||||
|
val app = context.applicationContext as HabitsApplication
|
||||||
|
val networkInfo = (context.getSystemService(CONNECTIVITY_SERVICE)
|
||||||
|
as ConnectivityManager).activeNetworkInfo
|
||||||
|
val isConnected = (networkInfo != null) &&
|
||||||
|
networkInfo.isConnectedOrConnecting
|
||||||
|
val syncManager = app.component.syncManager
|
||||||
|
syncManager.onNetworkStatusChanged(isConnected)
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in new issue