@Override public void onLoad() { final NestedMap<GroupConfiguration> groupConfigurations = new NestedMap<GroupConfiguration>(); Cursor cursor = GroupTable.getInstance().list(); try { if (cursor.moveToFirst()) { do { GroupConfiguration rosterConfiguration = new GroupConfiguration(); rosterConfiguration.setExpanded(GroupTable.isExpanded(cursor)); rosterConfiguration.setShowOfflineMode(GroupTable.getShowOfflineMode(cursor)); groupConfigurations.put( GroupTable.getAccount(cursor), GroupTable.getGroup(cursor), rosterConfiguration); } while (cursor.moveToNext()); } } finally { cursor.close(); } Application.getInstance() .runOnUiThread( new Runnable() { @Override public void run() { onLoaded(groupConfigurations); } }); }
@Override public void setShowOfflineMode(String account, String group, ShowOfflineMode showOfflineMode) { GroupConfiguration configuration = groupConfigurations.get(account, group); if (configuration == null) { configuration = new GroupConfiguration(); groupConfigurations.put(account, group, configuration); } configuration.setShowOfflineMode(showOfflineMode); requestToWriteGroup( account, group, configuration.isExpanded(), configuration.getShowOfflineMode()); }
@Override public void onAccountRemoved(AccountItem accountItem) { groupConfigurations.clear(accountItem.getAccount()); }
@Override public ShowOfflineMode getShowOfflineMode(String account, String group) { GroupConfiguration configuration = groupConfigurations.get(account, group); if (configuration == null) return ShowOfflineMode.normal; return configuration.getShowOfflineMode(); }
@Override public boolean isExpanded(String account, String group) { GroupConfiguration configuration = groupConfigurations.get(account, group); if (configuration == null) return true; return configuration.isExpanded(); }