Remove upgrade "service"

pull/384/head
Alex Baker 9 years ago
parent 6543b9d376
commit e8d61b1916

@ -223,7 +223,7 @@
</activity>
<activity
android:name="com.todoroo.astrid.service.UpgradeService$UpgradeActivity"
android:name="com.todoroo.astrid.service.UpgradeActivity"
android:screenOrientation="portrait" />
<!-- ======================================================= Receivers = -->

@ -8,6 +8,7 @@ package com.todoroo.astrid.service;
import android.app.Activity;
import android.content.ContentValues;
import android.content.Context;
import android.content.Intent;
import android.database.sqlite.SQLiteException;
import android.preference.PreferenceManager;
@ -54,7 +55,6 @@ public class StartupService {
// --- application startup
private final UpgradeService upgradeService;
private final TagDataDao tagDataDao;
private final Database database;
private final GtasksPreferenceService gtasksPreferenceService;
@ -67,12 +67,10 @@ public class StartupService {
private DialogBuilder dialogBuilder;
@Inject
public StartupService(UpgradeService upgradeService, TagDataDao tagDataDao, Database database,
GtasksPreferenceService gtasksPreferenceService,
public StartupService(TagDataDao tagDataDao, Database database, GtasksPreferenceService gtasksPreferenceService,
GtasksSyncService gtasksSyncService, MetadataDao metadataDao,
Preferences preferences, TasksXmlImporter xmlImporter,
TaskDeleter taskDeleter, Broadcaster broadcaster, DialogBuilder dialogBuilder) {
this.upgradeService = upgradeService;
this.tagDataDao = tagDataDao;
this.database = database;
this.gtasksPreferenceService = gtasksPreferenceService;
@ -115,26 +113,21 @@ public class StartupService {
}
// read current version
int latestSetVersion = 0;
try {
latestSetVersion = preferences.getLastSetVersion();
} catch (Exception e) {
log.error(e.getMessage(), e);
}
int version = BuildConfig.VERSION_CODE;
final int lastVersion = preferences.getLastSetVersion();
int currentVersion = BuildConfig.VERSION_CODE;
log.info("Astrid Startup. {} => {}", latestSetVersion, version);
log.info("Astrid Startup. {} => {}", lastVersion, currentVersion);
databaseRestoreIfEmpty(activity);
// invoke upgrade service
boolean justUpgraded = latestSetVersion != version;
if(justUpgraded) {
if(latestSetVersion > 0) {
upgradeService.performUpgrade(activity, latestSetVersion);
if(lastVersion != currentVersion) {
if(lastVersion > 0) {
activity.startActivityForResult(new Intent(activity, UpgradeActivity.class) {{
putExtra(UpgradeActivity.TOKEN_FROM_VERSION, lastVersion);
}}, 0);
}
preferences.setCurrentVersion(version);
preferences.setCurrentVersion(currentVersion);
}
initializeDatabaseListeners();
@ -156,7 +149,7 @@ public class StartupService {
preferences.setDefaults();
}
if (latestSetVersion == 0) {
if (lastVersion == 0) {
broadcaster.firstLaunch();
}
@ -187,7 +180,7 @@ public class StartupService {
*/
private void databaseRestoreIfEmpty(Context context) {
try {
if(preferences.getLastSetVersion() >= UpgradeService.V3_0_0 &&
if(preferences.getLastSetVersion() > UpgradeActivity.V3_0_0 &&
!context.getDatabasePath(database.getName()).exists()) {
// we didn't have a database! restore latest file
File directory = preferences.getBackupDirectory();

@ -0,0 +1,92 @@
/**
* Copyright (c) 2012 Todoroo Inc
* <p/>
* See the file "LICENSE" for the full license governing this code.
*/
package com.todoroo.astrid.service;
import android.app.ProgressDialog;
import android.content.Intent;
import android.os.Bundle;
import android.os.Environment;
import com.todoroo.andlib.utility.DialogUtilities;
import com.todoroo.astrid.activity.AstridActivity;
import com.todoroo.astrid.api.AstridApiConstants;
import org.tasks.R;
import org.tasks.activities.PrivacyActivity;
import org.tasks.dialogs.DialogBuilder;
import org.tasks.injection.InjectingAppCompatActivity;
import org.tasks.preferences.Preferences;
import java.io.File;
import javax.inject.Inject;
public class UpgradeActivity extends InjectingAppCompatActivity {
public static final String TOKEN_FROM_VERSION = "from_version"; //$NON-NLS-1$
public static final int V4_8_0 = 380;
public static final int V3_0_0 = 136;
@Inject DialogBuilder dialogBuilder;
@Inject Preferences preferences;
private ProgressDialog dialog;
private int from;
private boolean finished = false;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
from = getIntent().getIntExtra(TOKEN_FROM_VERSION, -1);
if (from > 0) {
dialog = dialogBuilder.newProgressDialog(R.string.DLG_upgrading);
new Thread() {
@Override
public void run() {
try {
if (from < V4_8_0) {
performMarshmallowMigration();
}
} finally {
finished = true;
DialogUtilities.dismissDialog(UpgradeActivity.this, dialog);
sendBroadcast(new Intent(AstridApiConstants.BROADCAST_EVENT_REFRESH));
setResult(AstridActivity.RESULT_RESTART_ACTIVITY);
finish();
}
}
}.start();
} else {
finished = true;
finish();
}
}
@Override
public void onBackPressed() {
// Don't allow the back button to finish this activity before things are done
if (finished) {
super.onBackPressed();
}
}
private void performMarshmallowMigration() {
// preserve pre-marshmallow default backup location
if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) {
if (!preferences.isStringValueSet(R.string.p_backup_dir)) {
String directory = String.format("%s/astrid",
Environment.getExternalStorageDirectory());
File file = new File(directory);
if (file.exists() && file.isDirectory()) {
preferences.setString(R.string.p_backup_dir, directory);
}
}
}
// notify existing users of analytics
startActivity(new Intent(this, PrivacyActivity.class));
}
}

@ -1,117 +0,0 @@
/**
* Copyright (c) 2012 Todoroo Inc
*
* See the file "LICENSE" for the full license governing this code.
*/
package com.todoroo.astrid.service;
import android.app.Activity;
import android.app.ProgressDialog;
import android.content.Intent;
import android.os.Bundle;
import android.os.Environment;
import com.todoroo.andlib.utility.DialogUtilities;
import com.todoroo.astrid.activity.AstridActivity;
import com.todoroo.astrid.api.AstridApiConstants;
import com.todoroo.astrid.data.TaskAttachment;
import org.tasks.BuildConfig;
import org.tasks.R;
import org.tasks.activities.PrivacyActivity;
import org.tasks.dialogs.DialogBuilder;
import org.tasks.injection.InjectingAppCompatActivity;
import org.tasks.preferences.Preferences;
import java.io.File;
import javax.inject.Inject;
import javax.inject.Singleton;
@Singleton
public final class UpgradeService {
public static final int CURRENT = BuildConfig.VERSION_CODE;
public static final int V4_8_0 = 376;
public static final int V3_0_0 = 136;
@Inject
public UpgradeService() {
}
/**
* Perform upgrade from one version to the next. Needs to be called
* on the UI thread so it can display a progress bar and then
* show users a change log.
*/
public void performUpgrade(final Activity context, final int from) {
if(from < CURRENT) {
Intent upgrade = new Intent(context, UpgradeActivity.class);
upgrade.putExtra(UpgradeActivity.TOKEN_FROM_VERSION, from);
context.startActivityForResult(upgrade, 0);
}
}
public static class UpgradeActivity extends InjectingAppCompatActivity {
private ProgressDialog dialog;
public static final String TOKEN_FROM_VERSION = "from_version"; //$NON-NLS-1$
private int from;
private boolean finished = false;
@Inject DialogBuilder dialogBuilder;
@Inject Preferences preferences;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
from = getIntent().getIntExtra(TOKEN_FROM_VERSION, -1);
if (from > 0) {
dialog = dialogBuilder.newProgressDialog(R.string.DLG_upgrading);
new Thread() {
@Override
public void run() {
try {
if (from < V4_8_0) {
performMarshmallowMigration();
}
} finally {
finished = true;
DialogUtilities.dismissDialog(UpgradeActivity.this, dialog);
sendBroadcast(new Intent(AstridApiConstants.BROADCAST_EVENT_REFRESH));
setResult(AstridActivity.RESULT_RESTART_ACTIVITY);
finish();
}
}
}.start();
} else {
finished = true;
finish();
}
}
@Override
public void onBackPressed() {
// Don't allow the back button to finish this activity before things are done
if (finished) {
super.onBackPressed();
}
}
private void performMarshmallowMigration() {
// preserve pre-marshmallow default backup location
if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) {
if (!preferences.isStringValueSet(R.string.p_backup_dir)) {
String directory = String.format("%s/astrid",
Environment.getExternalStorageDirectory());
File file = new File(directory);
if (file.exists() && file.isDirectory()) {
preferences.setString(R.string.p_backup_dir, directory);
}
}
}
// notify existing users of analytics
startActivity(new Intent(this, PrivacyActivity.class));
}
}
}

@ -15,7 +15,6 @@ import com.todoroo.astrid.gtasks.GtasksTaskListUpdater;
import com.todoroo.astrid.gtasks.sync.GtasksSyncService;
import com.todoroo.astrid.service.SyncV2Service;
import com.todoroo.astrid.service.TaskService;
import com.todoroo.astrid.service.UpgradeService;
import com.todoroo.astrid.tags.TagService;
import org.tasks.analytics.Tracker;
@ -39,7 +38,6 @@ public class Tasks extends InjectingApplication {
@Inject TaskAttachmentDao taskAttachmentDao;
@Inject TaskListMetadataDao taskListMetadataDao;
@Inject TaskService taskService;
@Inject UpgradeService upgradeService;
@Inject SyncV2Service syncV2Service;
@Inject GtasksPreferenceService gtasksPreferenceService;
@Inject GtasksListService gtasksListService;

@ -20,7 +20,7 @@ import com.todoroo.astrid.gcal.CalendarReminderActivity;
import com.todoroo.astrid.gtasks.GtasksPreferences;
import com.todoroo.astrid.gtasks.auth.GtasksLoginActivity;
import com.todoroo.astrid.reminders.ReminderPreferences;
import com.todoroo.astrid.service.UpgradeService;
import com.todoroo.astrid.service.UpgradeActivity;
import com.todoroo.astrid.widget.WidgetConfigActivity;
import org.tasks.activities.AddAttachmentActivity;
@ -98,7 +98,7 @@ import dagger.Provides;
FilterSelectionActivity.class,
FileExplore.class,
DonationActivity.class,
UpgradeService.UpgradeActivity.class,
UpgradeActivity.class,
CalendarSelectionActivity.class,
AddAttachmentActivity.class,
ShortcutActivity.class,

Loading…
Cancel
Save