Show friends view if friends exist, hide it if not

pull/14/head
Sam Bosley 13 years ago
parent 6f733f7e5b
commit 688c608e54

@ -26,6 +26,7 @@ import android.os.ConditionVariable;
import android.text.TextUtils;
import android.util.Log;
import com.timsu.astrid.R;
import com.todoroo.andlib.data.AbstractModel;
import com.todoroo.andlib.data.DatabaseDao;
import com.todoroo.andlib.data.DatabaseDao.ModelUpdateListener;
@ -702,6 +703,9 @@ public final class ActFmSyncService {
"token", token, "modified_after", serverTime);
JSONArray users = result.getJSONArray("list");
HashSet<Long> ids = new HashSet<Long>();
if (users.length() > 0)
Preferences.setBoolean(R.string.p_show_friends_view, true);
for (int i = 0; i < users.length(); i++) {
JSONObject userObject = users.getJSONObject(i);
ids.add(userObject.optLong("id"));

@ -44,10 +44,6 @@ public class LabsPreferences extends TodorooPreferenceActivity {
String name = r.getStringArray(R.array.EPr_swipe_lists_performance_mode)[index];
String desc = r.getStringArray(R.array.EPr_swipe_lists_performance_desc)[index];
preference.setSummary(r.getString(R.string.EPr_swipe_lists_display, name, desc));
} else if (r.getString(R.string.p_show_friends_view).equals(key)) {
preference.setOnPreferenceChangeListener(settingChangedListener);
setEnabledSummary(preference, value,
R.string.EPr_show_friends_view_desc_enabled, R.string.EPr_show_friends_view_desc_disabled);
} else if (r.getString(R.string.p_field_missed_calls).equals(key)) {
setEnabledSummary(preference, value,
R.string.MCA_missed_calls_pref_desc_enabled, R.string.MCA_missed_calls_pref_desc_disabled);

@ -609,11 +609,6 @@
<string name="EPr_use_contact_picker_desc_enabled">The system contact picker option will be displayed in the task assignment window</string>
<string name="EPr_use_contact_picker_desc_disabled">The system contact picker option will not be displayed</string>
<!-- Preferences: show the friends view -->
<string name="EPr_show_friends_view">Show Friends View</string>
<string name="EPr_show_friends_view_desc_enabled">Friends menu item will be shown</string>
<string name="EPr_show_friends_view_desc_disabled">Friends menu item will be hidden</string>
<!-- Preferences: Third party addons -->
<string name="EPr_third_party_addons">Enable Third Party Add-ons</string>
<string name="EPr_third_party_addons_desc_enabled">Third party add-ons will be enabled</string>

@ -15,9 +15,6 @@
<CheckBoxPreference
android:key="@string/p_field_missed_calls"
android:title="@string/MCA_missed_calls_pref_title"/>
<CheckBoxPreference
android:key="@string/p_show_friends_view"
android:title="@string/EPr_show_friends_view"/>
<CheckBoxPreference
android:key="@string/p_third_party_addons"
android:title="@string/EPr_third_party_addons" />

@ -115,14 +115,11 @@ public class ABTests {
}
private void initialize() { // Set up
addTest(AB_TEST_FRIENDS_VIEW_AVAILABLE, new int[] { 1, 1 },
new int[] { 8, 2 }, new String[] { "friends-view-disabled", "friends-view-enabled" }); //$NON-NLS-1$ //$NON-NLS-2$
addTest(AB_TEST_PRODUCTEEV_ENABLED, new int[] { 1, 1 },
new int[] { 1, 0 }, new String[] { "producteev-disabled", "producteev-enabled" }); //$NON-NLS-1$ //$NON-NLS-2$
}
public static final String AB_TEST_FRIENDS_VIEW_AVAILABLE = "friends-view"; //$NON-NLS-1$
public static final String AB_TEST_PRODUCTEEV_ENABLED = "producteev"; //$NON-NLS-1$
}

@ -6,10 +6,14 @@ import android.content.SharedPreferences.Editor;
import android.content.res.Resources;
import com.timsu.astrid.R;
import com.todoroo.andlib.data.TodorooCursor;
import com.todoroo.andlib.service.ContextManager;
import com.todoroo.andlib.sql.Query;
import com.todoroo.andlib.utility.Preferences;
import com.todoroo.astrid.api.AstridApiConstants;
import com.todoroo.astrid.core.PluginServices;
import com.todoroo.astrid.data.Task;
import com.todoroo.astrid.data.User;
import com.todoroo.astrid.producteev.ProducteevUtilities;
import com.todoroo.astrid.service.ThemeService;
import com.todoroo.astrid.service.abtesting.ABChooser;
@ -54,9 +58,6 @@ public class AstridPreferences {
Preferences.setIfUnset(prefs, editor, r, R.string.p_use_contact_picker, true);
Preferences.setIfUnset(prefs, editor, r, R.string.p_field_missed_calls, true);
boolean friendsViewEnabled = (ABChooser.readChoiceForTest(ABTests.AB_TEST_FRIENDS_VIEW_AVAILABLE) == 1);
Preferences.setIfUnset(prefs, editor, r, R.string.p_show_friends_view, friendsViewEnabled);
boolean thirdPartyAddons = (ABChooser.readChoiceForTest(ABTests.AB_TEST_PRODUCTEEV_ENABLED) == 1) || ProducteevUtilities.INSTANCE.isLoggedIn();
Preferences.setIfUnset(prefs, editor, r, R.string.p_third_party_addons, thirdPartyAddons);
@ -64,6 +65,16 @@ public class AstridPreferences {
Preferences.setString(R.string.p_theme, ThemeService.THEME_WHITE);
}
// Show friends view if necessary
boolean showFriends = false;
TodorooCursor<User> users = PluginServices.getUserDao().query(Query.select(User.ID).limit(1));
try {
showFriends = users.getCount() > 0;
} finally {
users.close();
}
Preferences.setBoolean(R.string.p_show_friends_view, showFriends);
editor.commit();
}

Loading…
Cancel
Save