15
15
******************************************************************************/
16
16
package com .noshufou .android .su ;
17
17
18
+ import java .util .ArrayList ;
19
+
18
20
import android .app .Activity ;
19
21
import android .content .ContentResolver ;
20
22
import android .content .ContentUris ;
@@ -79,7 +81,11 @@ public class AppDetailsFragment extends SherlockListFragment
79
81
private static final int DETAILS_LOADER = 1 ;
80
82
private static final int LOG_LOADER = 2 ;
81
83
84
+ private int mShownUid = -1 ;
85
+ private int mShownAllow = 0 ;
82
86
private long mShownIndex = -1 ;
87
+
88
+ private ArrayList <Long > mShownIndexes = new ArrayList <Long >();
83
89
84
90
private boolean mReady = false ;
85
91
private boolean mDualPane = false ;
@@ -124,6 +130,13 @@ public void setShownIndex(long index) {
124
130
getLoaderManager ().restartLoader (LOG_LOADER , null , this );
125
131
}
126
132
133
+ public void setShownItem (long id , int uid , int allow ) {
134
+ mShownUid = uid ;
135
+ mShownAllow = allow ;
136
+ getLoaderManager ().restartLoader (DETAILS_LOADER , null , this );
137
+ getLoaderManager ().restartLoader (LOG_LOADER , null , this );
138
+ }
139
+
127
140
@ Override
128
141
public void onCreate (Bundle savedInstanceState ) {
129
142
super .onCreate (savedInstanceState );
@@ -163,11 +176,14 @@ public void onActivityCreated(Bundle savedInstanceState) {
163
176
164
177
if (savedInstanceState != null &&
165
178
savedInstanceState .containsKey ("mShownIndex" )) {
166
- mShownIndex = savedInstanceState .getLong ("mShownIndex" );
179
+ mShownUid = savedInstanceState .getInt ("mShownUid" );
180
+ mShownAllow = savedInstanceState .getInt ("mShownAllow" );
167
181
} else if (getArguments () != null ) {
168
- mShownIndex = getArguments ().getLong ("index" , 0 );
182
+ mShownUid = getArguments ().getInt ("uid" , 0 );
183
+ mShownAllow = getArguments ().getInt ("allow" , 0 );
169
184
} else {
170
- mShownIndex = 0 ;
185
+ mShownUid = -1 ;
186
+ mShownAllow = 0 ;
171
187
}
172
188
173
189
setupListView ();
@@ -261,8 +277,9 @@ public boolean onOptionsItemSelected(MenuItem item) {
261
277
262
278
@ Override
263
279
public void onSaveInstanceState (Bundle outState ) {
264
- if (mShownIndex != -1 ) {
265
- outState .putLong ("mShownIndex" , mShownIndex );
280
+ if (mShownUid != -1 ) {
281
+ outState .putInt ("mShownUid" , mShownUid );
282
+ outState .putInt ("mShownAllow" , mShownAllow );
266
283
}
267
284
268
285
super .onSaveInstanceState (outState );
@@ -292,7 +309,7 @@ private void setOptions(int option) {
292
309
values .put (Apps .LOGGING , mLoggingEnabled );
293
310
break ;
294
311
}
295
- cr .update (ContentUris .withAppendedId (Apps .CONTENT_URI , mShownIndex ),
312
+ cr .update (ContentUris .withAppendedId (Apps .CONTENT_URI_UID , mShownUid ),
296
313
values , null , null );
297
314
getSherlockActivity ().invalidateOptionsMenu ();
298
315
}
@@ -310,7 +327,6 @@ public void toggle(View view) {
310
327
} else {
311
328
doToggle ();
312
329
}
313
-
314
330
}
315
331
316
332
@ Override
@@ -322,20 +338,23 @@ public void onActivityResult(int requestCode, int resultCode, Intent data) {
322
338
323
339
private void doToggle () {
324
340
ContentResolver cr = getActivity ().getContentResolver ();
325
- Uri uri = Uri .withAppendedPath (Apps .CONTENT_URI , String .valueOf (mShownIndex ));
326
341
327
- ContentValues values = new ContentValues ();
328
- values .put (Apps .ALLOW , mAllow == 1 ?0 :1 );
329
- cr .update (uri , values , null , null );
330
-
331
- // Update the log
332
- values .clear ();
333
- values .put (Logs .DATE , System .currentTimeMillis ());
334
- values .put (Logs .TYPE , Logs .LogType .TOGGLE );
335
- cr .insert (Uri .withAppendedPath (Logs .CONTENT_URI , String .valueOf (mShownIndex )), values );
336
- Intent intent = new Intent (getActivity (), ResultService .class );
337
- intent .putExtra (ResultService .EXTRA_ACTION , ResultService .ACTION_RECYCLE );
338
- getActivity ().startService (intent );
342
+ for (Long id : mShownIndexes ) {
343
+ Uri uri = Uri .withAppendedPath (Apps .CONTENT_URI , String .valueOf (id ));
344
+ ContentValues values = new ContentValues ();
345
+ values .put (Apps .ALLOW , mAllow == 1 ?0 :1 );
346
+ cr .update (uri , values , null , null );
347
+
348
+ // Update the log
349
+ values .clear ();
350
+ values .put (Logs .DATE , System .currentTimeMillis ());
351
+ values .put (Logs .TYPE , Logs .LogType .TOGGLE );
352
+ cr .insert (Uri .withAppendedPath (Logs .CONTENT_URI , String .valueOf (id )), values );
353
+ Intent intent = new Intent (getActivity (), ResultService .class );
354
+ intent .putExtra (ResultService .EXTRA_ACTION , ResultService .ACTION_RECYCLE );
355
+ getActivity ().startService (intent );
356
+ }
357
+ setShownItem (mShownIndex , mShownUid , mShownAllow == 0 ?1 :0 );
339
358
}
340
359
341
360
public void forget (View view ) {
@@ -344,9 +363,10 @@ public void forget(View view) {
344
363
}
345
364
346
365
ContentResolver cr = getActivity ().getContentResolver ();
347
- Uri uri = Uri .withAppendedPath (Apps .CONTENT_URI , String .valueOf (mShownIndex ));
348
-
349
- cr .delete (uri , null , null );
366
+ for (Long id : mShownIndexes ) {
367
+ Uri uri = Uri .withAppendedPath (Apps .CONTENT_URI , String .valueOf (id ));
368
+ cr .delete (uri , null , null );
369
+ }
350
370
closeDetails ();
351
371
}
352
372
@@ -356,8 +376,11 @@ public void clearLog(View view) {
356
376
357
377
@ Override
358
378
public void clearLog () {
359
- if (mShownIndex != -1 ) {
360
- getActivity ().getContentResolver ().delete (ContentUris .withAppendedId (Logs .CONTENT_URI , mShownIndex ), null , null );
379
+ if (!mShownIndexes .isEmpty ()) {
380
+ for (Long id : mShownIndexes ) {
381
+ getActivity ().getContentResolver ()
382
+ .delete (ContentUris .withAppendedId (Logs .CONTENT_URI , id ), null , null );
383
+ }
361
384
}
362
385
}
363
386
@@ -380,12 +403,16 @@ public Loader<Cursor> onCreateLoader(int id, Bundle args) {
380
403
switch (id ) {
381
404
case DETAILS_LOADER :
382
405
return new CursorLoader (getActivity (),
383
- ContentUris .withAppendedId (Apps .CONTENT_URI , mShownIndex ),
384
- DETAILS_PROJECTION , null , null , null );
406
+ ContentUris .withAppendedId (Apps .CONTENT_URI_UID , mShownUid ),
407
+ DETAILS_PROJECTION ,
408
+ Apps .ALLOW + "=?" ,
409
+ new String [] { String .valueOf (mShownAllow ) },
410
+ null );
385
411
case LOG_LOADER :
386
412
return new CursorLoader (getActivity (),
387
- ContentUris .withAppendedId (Logs .CONTENT_URI , mShownIndex ),
388
- LogAdapter .PROJECTION , null , null , null );
413
+ ContentUris .withAppendedId (Apps .CONTENT_UID_LOGS , mShownUid ),
414
+ LogAdapter .PROJECTION , Apps .ALLOW + "=?" , new String [] { String .valueOf (mShownAllow ) },
415
+ null );
389
416
default :
390
417
throw new IllegalArgumentException ("Unknown Loader: " + id );
391
418
}
@@ -436,6 +463,15 @@ public void onLoadFinished(Loader<Cursor> loader, Cursor data) {
436
463
mNotificationsEnabled = notificationsStr .equals ("1" )?true :false ;
437
464
mLoggingEnabled = loggingStr .equals ("1" )?true :false ;
438
465
}
466
+ StringBuilder commandText = new StringBuilder (data .getString (DETAILS_COLUMN_EXEC_CMD ));
467
+ mShownIndexes .clear ();
468
+ mShownIndexes .add (data .getLong (0 ));
469
+ while (data .moveToNext ()) {
470
+ commandText .append (", " );
471
+ commandText .append (data .getString (DETAILS_COLUMN_EXEC_CMD ));
472
+ mShownIndexes .add (data .getLong (0 ));
473
+ }
474
+ mCommandText .setText (commandText .toString ());
439
475
}
440
476
mReady = true ;
441
477
getSherlockActivity ().invalidateOptionsMenu ();
0 commit comments