@ -599,9 +599,8 @@ public class ActFmLoginActivity extends FragmentActivity implements AuthListener
}
}
// Successful login, create outstanding entries
// Successful login, create outstanding entries
long lastId = Preferences . getLong ( ActFmPreferenceService . PREF_USER_ID , 0 ) ;
long lastId = Preferences . getLong ( ActFmPreferenceService . PREF_USER_ID , 0 ) ;
long newUser = result . optLong ( "id" ) ;
if ( ! TextUtils . isEmpty ( token ) & & ( lastId = = 0 | | lastId = = newUser ) ) {
if ( ! TextUtils . isEmpty ( token ) & & lastId = = 0 ) {
constructOutstandingTables ( ) ;
constructOutstandingTables ( ) ;
}
}
runOnUiThread ( new Runnable ( ) {
runOnUiThread ( new Runnable ( ) {
@ -636,7 +635,10 @@ public class ActFmLoginActivity extends FragmentActivity implements AuthListener
@SuppressWarnings ( "nls" )
@SuppressWarnings ( "nls" )
private void postAuthenticate ( final JSONObject result , final String token ) {
private void postAuthenticate ( final JSONObject result , final String token ) {
long lastLoggedInUser = Preferences . getLong ( ActFmPreferenceService . PREF_USER_ID , 0 ) ;
long lastLoggedInUser = Preferences . getLong ( ActFmPreferenceService . PREF_USER_ID , 0 ) ;
if ( lastLoggedInUser > 0 ) {
boolean clearedOnLastLogOut = Preferences . getBoolean ( ActFmPreferenceService . PREF_CLEARED_TASKS_ON_LOGOUT , false ) ;
Preferences . setBoolean ( ActFmPreferenceService . PREF_CLEARED_TASKS_ON_LOGOUT , false ) ;
if ( lastLoggedInUser > 0 & & ! clearedOnLastLogOut ) {
long newUserId = result . optLong ( "id" ) ;
long newUserId = result . optLong ( "id" ) ;
if ( lastLoggedInUser ! = newUserId ) {
if ( lastLoggedInUser ! = newUserId ) {
// In this case, we need to either make all data private or clear all data
// In this case, we need to either make all data private or clear all data
@ -650,12 +652,39 @@ public class ActFmLoginActivity extends FragmentActivity implements AuthListener
new DialogInterface . OnClickListener ( ) {
new DialogInterface . OnClickListener ( ) {
@Override
@Override
public void onClick ( DialogInterface dialog , int which ) {
public void onClick ( DialogInterface dialog , int which ) {
// TODO: Make all data private
final ProgressDialog pd = DialogUtilities . progressDialog ( ActFmLoginActivity . this , getString ( R . string . actfm_logged_in_different_user_processing ) ) ;
final ProgressDialog pd = DialogUtilities . progressDialog ( ActFmLoginActivity . this , getString ( R . string . actfm_logged_in_different_user_processing ) ) ;
new Thread ( new Runnable ( ) {
new Thread ( new Runnable ( ) {
@Override
@Override
public void run ( ) {
public void run ( ) {
rebuildAllSyncData ( ) ;
runOnUiThread ( new Runnable ( ) {
@Override
public void run ( ) {
finishSignIn ( result , token , true ) ;
}
} ) ;
pd . dismiss ( ) ;
}
} ) . start ( ) ;
}
} ,
new DialogInterface . OnClickListener ( ) {
@Override
public void onClick ( DialogInterface dialog , int which ) {
deleteDatabase ( database . getName ( ) ) ;
finishSignIn ( result , token , true ) ;
}
} ) ;
} else {
finishSignIn ( result , token , false ) ;
}
} else {
finishSignIn ( result , token , false ) ;
}
}
private void rebuildAllSyncData ( ) {
// Delete all tasks not assigned to self
// Delete all tasks not assigned to self
taskService . deleteWhere ( Criterion . or ( Task . USER_ID . neq ( 0 ) , Task . DELETION_DATE . gt ( 0 ) ) ) ;
taskService . deleteWhere ( Criterion . or ( Task . USER_ID . neq ( 0 ) , Task . DELETION_DATE . gt ( 0 ) ) ) ;
// Delete user table
// Delete user table
@ -682,30 +711,6 @@ public class ActFmLoginActivity extends FragmentActivity implements AuthListener
clearTablePushedAtValues ( ) ;
clearTablePushedAtValues ( ) ;
constructOutstandingTables ( ) ;
constructOutstandingTables ( ) ;
runOnUiThread ( new Runnable ( ) {
@Override
public void run ( ) {
finishSignIn ( result , token , true ) ;
}
} ) ;
pd . dismiss ( ) ;
}
} ) . start ( ) ;
}
} ,
new DialogInterface . OnClickListener ( ) {
@Override
public void onClick ( DialogInterface dialog , int which ) {
deleteDatabase ( database . getName ( ) ) ;
finishSignIn ( result , token , true ) ;
}
} ) ;
} else {
finishSignIn ( result , token , false ) ;
}
} else {
finishSignIn ( result , token , false ) ;
}
}
}
private void generateNewUuids ( ) {
private void generateNewUuids ( ) {