@ -3,8 +3,7 @@
* /
package com.todoroo.astrid.producteev ;
import java.util.TreeMap ;
import java.util.Map.Entry ;
import java.util.TreeSet ;
import android.content.BroadcastReceiver ;
import android.content.ContentValues ;
@ -14,7 +13,6 @@ import android.content.Intent;
import com.timsu.astrid.R ;
import com.todoroo.andlib.sql.Criterion ;
import com.todoroo.andlib.sql.QueryTemplate ;
import com.todoroo.andlib.utility.Pair ;
import com.todoroo.astrid.api.AstridApiConstants ;
import com.todoroo.astrid.api.Filter ;
import com.todoroo.astrid.api.FilterCategory ;
@ -27,6 +25,7 @@ import com.todoroo.astrid.data.StoreObject;
import com.todoroo.astrid.producteev.sync.ProducteevDashboard ;
import com.todoroo.astrid.producteev.sync.ProducteevDataService ;
import com.todoroo.astrid.producteev.sync.ProducteevTask ;
import com.todoroo.astrid.producteev.sync.ProducteevUser ;
/ * *
* Exposes filters based on Producteev Dashboards
@ -59,20 +58,19 @@ public class ProducteevFilterExposer extends BroadcastReceiver {
return filter ;
}
private Filter filterFromUser ( Context context , String user , Pair < Long , String > ids ) {
String title = context . getString ( R . string . producteev_FEx_responsible_title , user );
private Filter filterFromUser ( Context context , ProducteevUser user ) {
String title = context . getString ( R . string . producteev_FEx_responsible_title , user .toString ( ) );
ContentValues values = new ContentValues ( ) ;
values . put ( Metadata . KEY . name , ProducteevTask . METADATA_KEY ) ;
values . put ( ProducteevTask . DASHBOARD_ID . name , ids . getLeft ( ) ) ;
values . put ( ProducteevTask . ID . name , 0 ) ;
values . put ( ProducteevTask . CREATOR_ID . name , 0 ) ;
values . put ( ProducteevTask . RESPONSIBLE_ID . name , ids. getRight ( ) ) ;
Filter filter = new Filter ( user , title , new QueryTemplate ( ) . join (
values . put ( ProducteevTask . RESPONSIBLE_ID . name , user. getId ( ) ) ;
Filter filter = new Filter ( user .toString ( ) , title , new QueryTemplate ( ) . join (
ProducteevDataService . METADATA_JOIN ) . where ( Criterion . and (
MetadataCriteria . withKey ( ProducteevTask . METADATA_KEY ) ,
TaskCriteria . isActive ( ) ,
TaskCriteria . isVisible ( ) ,
ProducteevTask . RESPONSIBLE_ID . eq ( ids. getRight ( ) ) ) ) ,
ProducteevTask . RESPONSIBLE_ID . eq ( user. getId ( ) ) ) ) ,
values ) ;
return filter ;
@ -100,11 +98,11 @@ public class ProducteevFilterExposer extends BroadcastReceiver {
dashboardFilters ) ;
// load responsible people
Tree Map< String , Pair < Long , String > > people = loadResponsiblePeople ( dashboards ) ;
Tree Set< ProducteevUser > people = loadResponsiblePeople ( dashboards ) ;
Filter [ ] peopleFilters = new Filter [ people . size ( ) ] ;
int index = 0 ;
for ( Entry < String , Pair < Long , String > > person : people . entrySet ( ) )
peopleFilters [ index + + ] = filterFromUser ( context , person .getKey ( ) , person . getValue ( ) );
for ( ProducteevUser person : people )
peopleFilters [ index + + ] = filterFromUser ( context , person );
FilterCategory producteevUsers = new FilterCategory ( context . getString ( R . string . producteev_FEx_responsible ) ,
peopleFilters ) ;
@ -124,22 +122,14 @@ public class ProducteevFilterExposer extends BroadcastReceiver {
* @return people in a map of name = > pair ( dashboard id , user id )
* /
@SuppressWarnings ( "nls" )
private TreeMap < String , Pair < Long , String > > loadResponsiblePeople (
StoreObject [ ] dashboards ) {
TreeMap < String , Pair < Long , String > > results = new TreeMap < String , Pair < Long , String > > ( ) ;
private TreeSet < ProducteevUser > loadResponsiblePeople ( StoreObject [ ] dashboards ) {
TreeSet < ProducteevUser > users = new TreeSet < ProducteevUser > ( ) ;
for ( StoreObject dashboard : dashboards ) {
String users = dashboard . getValue ( ProducteevDashboard . USERS ) ;
String [ ] entries = users . split ( ";" ) ;
for ( String entry : entries ) {
String [ ] data = entry . split ( "," ) ;
if ( data . length ! = 2 )
continue ;
results . put ( data [ 1 ] , new Pair < Long , String > (
dashboard . getValue ( ProducteevDashboard . REMOTE_ID ) , data [ 0 ] ) ) ; // name, id
}
ProducteevDashboard elDashboard = new ProducteevDashboard ( dashboard ) ;
users . addAll ( elDashboard . getUsers ( ) ) ;
}
return result s;
return users ;
}
}