Fix synchronization menu for generic build

pull/685/merge
Alex Baker 7 years ago
parent 70d308fa8d
commit 738208efbd

@ -44,11 +44,6 @@
android:name="com.todoroo.astrid.gtasks.auth.GtasksLoginActivity"
android:theme="@style/TranslucentDialog"/>
<activity
android:label="@string/synchronization"
android:name=".sync.SynchronizationPreferences"
android:theme="@style/Tasks"/>
<!-- Google Analytics -->
<receiver

@ -127,6 +127,11 @@
android:name=".activities.CameraActivity"
android:theme="@style/TranslucentDialog"/>
<activity
android:label="@string/synchronization"
android:name=".sync.SynchronizationPreferences"
android:theme="@style/Tasks"/>
<!-- Activity that displays task list -->
<activity
android:launchMode="singleTask"

@ -17,6 +17,7 @@ import android.support.v7.app.AlertDialog;
import com.todoroo.astrid.gtasks.auth.GtasksLoginActivity;
import com.todoroo.astrid.service.TaskDeleter;
import javax.inject.Inject;
import org.tasks.BuildConfig;
import org.tasks.R;
import org.tasks.analytics.Tracker;
import org.tasks.analytics.Tracking;
@ -69,58 +70,13 @@ public class SynchronizationPreferences extends InjectingPreferenceActivity {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.preferences_synchronization);
PreferenceCategory caldavPreferences =
(PreferenceCategory) findPreference(getString(R.string.CalDAV));
for (CaldavAccount caldavAccount : caldavDao.getAccounts()) {
Preference accountPreferences = new Preference(this);
accountPreferences.setTitle(caldavAccount.getName());
accountPreferences.setSummary(caldavAccount.getError());
accountPreferences.setOnPreferenceClickListener(
preference -> {
Intent intent = new Intent(this, CaldavAccountSettingsActivity.class);
intent.putExtra(CaldavAccountSettingsActivity.EXTRA_CALDAV_DATA, caldavAccount);
startActivityForResult(intent, REQUEST_CALDAV_SETTINGS);
return false;
});
caldavPreferences.addPreference(accountPreferences);
setTitle(R.string.synchronization);
//noinspection ConstantConditions
if (BuildConfig.FLAVOR.equals("googleplay")) {
addPreferencesFromResource(R.xml.preferences_google_tasks);
}
Preference addCaldavAccount = new Preference(this);
addCaldavAccount.setKey(KEY_ADD_CALDAV);
addCaldavAccount.setTitle(R.string.add_account);
caldavPreferences.addPreference(addCaldavAccount);
PreferenceCategory googleTaskPreferences =
(PreferenceCategory) findPreference(getString(R.string.gtasks_GPr_header));
for (GoogleTaskAccount googleTaskAccount : googleTaskListDao.getAccounts()) {
String account = googleTaskAccount.getAccount();
Preference accountPreferences = new Preference(this);
accountPreferences.setTitle(account);
accountPreferences.setSummary(googleTaskAccount.getError());
accountPreferences.setOnPreferenceClickListener(
preference -> {
dialogBuilder
.newDialog()
.setTitle(account)
.setItems(
asList(getString(R.string.reinitialize_account), getString(R.string.logout)),
(dialog, which) -> {
if (which == 0) {
addGoogleTaskAccount();
} else {
logoutConfirmation(googleTaskAccount);
}
})
.showThemedListView();
return false;
});
googleTaskPreferences.addPreference(accountPreferences);
}
Preference addGoogleTaskAccount = new Preference(this);
addGoogleTaskAccount.setKey(KEY_ADD_GOOGLE_TASKS);
addGoogleTaskAccount.setTitle(R.string.add_account);
googleTaskPreferences.addPreference(addGoogleTaskAccount);
addPreferencesFromResource(R.xml.preferences_synchronization);
findPreference(getString(R.string.p_background_sync_unmetered_only))
.setOnPreferenceChangeListener(
@ -163,19 +119,94 @@ public class SynchronizationPreferences extends InjectingPreferenceActivity {
protected void onResume() {
super.onResume();
Preference addCaldavAccount = findPreference(KEY_ADD_CALDAV);
Preference addGoogleTasks = findPreference(KEY_ADD_GOOGLE_TASKS);
if (inventory.hasPro()) {
addCaldavAccount.setSummary(null);
addGoogleTasks.setSummary(null);
addCaldavAccount.setOnPreferenceClickListener(
//noinspection ConstantConditions
if (BuildConfig.FLAVOR.equals("googleplay")) {
addGoogleTasksAccounts();
}
addCaldavAccounts();
}
private void addGoogleTasksAccounts() {
PreferenceCategory googleTaskPreferences =
(PreferenceCategory) findPreference(getString(R.string.gtasks_GPr_header));
googleTaskPreferences.removeAll();
for (GoogleTaskAccount googleTaskAccount : googleTaskListDao.getAccounts()) {
String account = googleTaskAccount.getAccount();
Preference accountPreferences = new Preference(this);
accountPreferences.setTitle(account);
accountPreferences.setSummary(googleTaskAccount.getError());
accountPreferences.setOnPreferenceClickListener(
preference -> {
addCaldavAccount();
dialogBuilder
.newDialog()
.setTitle(account)
.setItems(
asList(getString(R.string.reinitialize_account), getString(R.string.logout)),
(dialog, which) -> {
if (which == 0) {
addGoogleTaskAccount();
} else {
logoutConfirmation(googleTaskAccount);
}
})
.showThemedListView();
return false;
});
googleTaskPreferences.addPreference(accountPreferences);
}
Preference addGoogleTaskAccount = new Preference(this);
addGoogleTaskAccount.setKey(KEY_ADD_GOOGLE_TASKS);
addGoogleTaskAccount.setTitle(R.string.add_account);
if (inventory.hasPro() || googleTaskListDao.getAccounts().isEmpty()) {
addGoogleTaskAccount.setOnPreferenceClickListener(preference -> {
addGoogleTaskAccount();
return false;
});
} else {
addGoogleTaskAccount.setSummary(R.string.requires_pro_subscription);
addGoogleTaskAccount.setOnPreferenceClickListener(preference -> {
startActivityForResult(
new Intent(this, PurchaseActivity.class), REQUEST_GOOGLE_TASKS_SUBSCRIBE);
return false;
});
}
googleTaskPreferences.addPreference(addGoogleTaskAccount);
}
private void addGoogleTaskAccount() {
if (!playServices.refreshAndCheck()) {
playServices.resolve(this);
} else if (permissionRequestor.requestAccountPermissions()) {
requestLogin();
}
}
private void addCaldavAccounts() {
PreferenceCategory caldavPreferences =
(PreferenceCategory) findPreference(getString(R.string.CalDAV));
caldavPreferences.removeAll();
for (CaldavAccount caldavAccount : caldavDao.getAccounts()) {
Preference accountPreferences = new Preference(this);
accountPreferences.setTitle(caldavAccount.getName());
accountPreferences.setSummary(caldavAccount.getError());
accountPreferences.setOnPreferenceClickListener(
preference -> {
Intent intent = new Intent(this, CaldavAccountSettingsActivity.class);
intent.putExtra(CaldavAccountSettingsActivity.EXTRA_CALDAV_DATA, caldavAccount);
startActivityForResult(intent, REQUEST_CALDAV_SETTINGS);
return false;
});
addGoogleTasks.setOnPreferenceClickListener(
caldavPreferences.addPreference(accountPreferences);
}
Preference addCaldavAccount = new Preference(this);
addCaldavAccount.setKey(KEY_ADD_CALDAV);
addCaldavAccount.setTitle(R.string.add_account);
if (inventory.hasPro()) {
addCaldavAccount.setOnPreferenceClickListener(
preference -> {
addGoogleTaskAccount();
addCaldavAccount();
return false;
});
} else {
@ -186,35 +217,8 @@ public class SynchronizationPreferences extends InjectingPreferenceActivity {
new Intent(this, PurchaseActivity.class), REQUEST_CALDAV_SUBSCRIBE);
return false;
});
if (googleTaskListDao.getAccounts().isEmpty()) {
addGoogleTasks.setSummary(null);
addGoogleTasks.setOnPreferenceClickListener(
preference -> {
addGoogleTaskAccount();
return false;
});
} else {
addGoogleTasks.setSummary(R.string.requires_pro_subscription);
addGoogleTasks.setOnPreferenceClickListener(
preference -> {
startActivityForResult(
new Intent(this, PurchaseActivity.class), REQUEST_GOOGLE_TASKS_SUBSCRIBE);
return false;
});
}
}
if (!permissionChecker.canAccessAccounts()) {
// TODO: clear google task preference category
}
}
private void addGoogleTaskAccount() {
if (!playServices.refreshAndCheck()) {
playServices.resolve(this);
} else if (permissionRequestor.requestAccountPermissions()) {
requestLogin();
}
caldavPreferences.addPreference(addCaldavAccount);
}
private void addCaldavAccount() {

@ -0,0 +1,12 @@
<?xml version="1.0" encoding="utf-8"?><!--
** Copyright (c) 2012 Todoroo Inc
**
** See the file "LICENSE" for the full license governing this code.
-->
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
<PreferenceCategory
android:key="@string/gtasks_GPr_header"
android:title="@string/gtasks_GPr_header"/>
</PreferenceScreen>

@ -3,12 +3,7 @@
**
** See the file "LICENSE" for the full license governing this code.
-->
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
android:title="@string/synchronization">
<PreferenceCategory
android:key="@string/gtasks_GPr_header"
android:title="@string/gtasks_GPr_header"/>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
<PreferenceCategory
android:key="@string/CalDAV"

Loading…
Cancel
Save