mirror of
https://github.com/iSoron/uhabits.git
synced 2025-12-06 09:08:52 -06:00
Implement auto backups
This commit is contained in:
@@ -5,13 +5,15 @@
|
|||||||
android:versionCode="2"
|
android:versionCode="2"
|
||||||
android:versionName="1.0.0">
|
android:versionName="1.0.0">
|
||||||
|
|
||||||
<uses-permission android:name="android.permission.VIBRATE"/>
|
<uses-permission
|
||||||
|
android:name="android.permission.VIBRATE"/>
|
||||||
|
|
||||||
<application
|
<application
|
||||||
android:name="com.activeandroid.app.Application"
|
android:name="com.activeandroid.app.Application"
|
||||||
android:icon="@mipmap/ic_launcher"
|
android:icon="@mipmap/ic_launcher"
|
||||||
android:label="@string/app_name"
|
android:label="@string/app_name"
|
||||||
android:theme="@style/AppTheme">
|
android:theme="@style/AppBaseTheme"
|
||||||
|
android:backupAgent=".HabitsBackupAgent">
|
||||||
|
|
||||||
<meta-data
|
<meta-data
|
||||||
android:name="AA_DB_NAME"
|
android:name="AA_DB_NAME"
|
||||||
@@ -21,6 +23,10 @@
|
|||||||
android:name="AA_DB_VERSION"
|
android:name="AA_DB_VERSION"
|
||||||
android:value="7"/>
|
android:value="7"/>
|
||||||
|
|
||||||
|
<meta-data
|
||||||
|
android:name="com.google.android.backup.api_key"
|
||||||
|
android:value="AEdPqrEAAAAI6aeWncbnMNo8E5GWeZ44dlc5cQ7tCROwFhOtiw" />
|
||||||
|
|
||||||
<activity
|
<activity
|
||||||
android:name=".MainActivity"
|
android:name=".MainActivity"
|
||||||
android:label="@string/app_name">
|
android:label="@string/app_name">
|
||||||
@@ -30,8 +36,8 @@
|
|||||||
</intent-filter>
|
</intent-filter>
|
||||||
</activity>
|
</activity>
|
||||||
|
|
||||||
<receiver android:name=".ReminderAlarmReceiver">
|
<receiver
|
||||||
</receiver>
|
android:name=".ReminderAlarmReceiver" />
|
||||||
|
|
||||||
<activity
|
<activity
|
||||||
android:name=".ShowHabitActivity"
|
android:name=".ShowHabitActivity"
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package org.isoron.helpers;
|
package org.isoron.helpers;
|
||||||
|
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
|
import android.app.backup.BackupManager;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
|
||||||
@@ -28,6 +29,7 @@ abstract public class ReplayableActivity extends Activity
|
|||||||
public void executeCommand(Command command)
|
public void executeCommand(Command command)
|
||||||
{
|
{
|
||||||
executeCommand(command, false);
|
executeCommand(command, false);
|
||||||
|
BackupManager.dataChanged("org.isoron.uhabits");
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void undo()
|
protected void undo()
|
||||||
|
|||||||
15
app/src/main/java/org/isoron/uhabits/HabitsBackupAgent.java
Normal file
15
app/src/main/java/org/isoron/uhabits/HabitsBackupAgent.java
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
package org.isoron.uhabits;
|
||||||
|
|
||||||
|
import android.app.backup.BackupAgentHelper;
|
||||||
|
import android.app.backup.FileBackupHelper;
|
||||||
|
import android.app.backup.SharedPreferencesBackupHelper;
|
||||||
|
|
||||||
|
public class HabitsBackupAgent extends BackupAgentHelper
|
||||||
|
{
|
||||||
|
@Override
|
||||||
|
public void onCreate()
|
||||||
|
{
|
||||||
|
addHelper("preferences", new SharedPreferencesBackupHelper(this, "preferences"));
|
||||||
|
addHelper("database", new FileBackupHelper(this, "../databases/uhabits.db"));
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,12 +1,14 @@
|
|||||||
package org.isoron.uhabits.dialogs;
|
package org.isoron.uhabits.dialogs;
|
||||||
|
|
||||||
|
|
||||||
|
import android.app.backup.BackupManager;
|
||||||
|
import android.content.SharedPreferences;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.preference.PreferenceFragment;
|
import android.preference.PreferenceFragment;
|
||||||
|
|
||||||
import org.isoron.uhabits.R;
|
import org.isoron.uhabits.R;
|
||||||
|
|
||||||
public class SettingsFragment extends PreferenceFragment
|
public class SettingsFragment extends PreferenceFragment implements SharedPreferences.OnSharedPreferenceChangeListener
|
||||||
{
|
{
|
||||||
@Override
|
@Override
|
||||||
public void onCreate(Bundle savedInstanceState)
|
public void onCreate(Bundle savedInstanceState)
|
||||||
@@ -14,4 +16,26 @@ public class SettingsFragment extends PreferenceFragment
|
|||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
addPreferencesFromResource(R.xml.preferences);
|
addPreferencesFromResource(R.xml.preferences);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onResume()
|
||||||
|
{
|
||||||
|
super.onResume();
|
||||||
|
getPreferenceManager().getSharedPreferences().
|
||||||
|
registerOnSharedPreferenceChangeListener(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onPause()
|
||||||
|
{
|
||||||
|
getPreferenceManager().getSharedPreferences().
|
||||||
|
unregisterOnSharedPreferenceChangeListener(this);
|
||||||
|
super.onPause();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key)
|
||||||
|
{
|
||||||
|
BackupManager.dataChanged("org.isoron.uhabits");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user