mirror of
				https://github.com/commons-app/apps-android-commons.git
				synced 2025-10-31 14:53:59 +01:00 
			
		
		
		
	Injected the ModifierSequenceDao where needed.
This commit is contained in:
		
							parent
							
								
									9927879680
								
							
						
					
					
						commit
						874627e3f5
					
				
					 9 changed files with 49 additions and 32 deletions
				
			
		|  | @ -23,15 +23,15 @@ public class ModificationsContentProvider extends ContentProvider { | |||
|     private static final int MODIFICATIONS = 1; | ||||
|     private static final int MODIFICATIONS_ID = 2; | ||||
| 
 | ||||
|     public static final String AUTHORITY = "fr.free.nrw.commons.modifications.contentprovider"; | ||||
|     public static final String MODIFICATIONS_AUTHORITY = "fr.free.nrw.commons.modifications.contentprovider"; | ||||
|     public static final String BASE_PATH = "modifications"; | ||||
| 
 | ||||
|     public static final Uri BASE_URI = Uri.parse("content://" + AUTHORITY + "/" + BASE_PATH); | ||||
|     public static final Uri BASE_URI = Uri.parse("content://" + MODIFICATIONS_AUTHORITY + "/" + BASE_PATH); | ||||
| 
 | ||||
|     private static final UriMatcher uriMatcher = new UriMatcher(UriMatcher.NO_MATCH); | ||||
|     static { | ||||
|         uriMatcher.addURI(AUTHORITY, BASE_PATH, MODIFICATIONS); | ||||
|         uriMatcher.addURI(AUTHORITY, BASE_PATH + "/#", MODIFICATIONS_ID); | ||||
|         uriMatcher.addURI(MODIFICATIONS_AUTHORITY, BASE_PATH, MODIFICATIONS); | ||||
|         uriMatcher.addURI(MODIFICATIONS_AUTHORITY, BASE_PATH + "/#", MODIFICATIONS_ID); | ||||
|     } | ||||
| 
 | ||||
|     public static Uri uriForId(int id) { | ||||
|  |  | |||
|  | @ -27,6 +27,7 @@ public class ModificationsSyncAdapter extends AbstractThreadedSyncAdapter { | |||
| 
 | ||||
|     @Inject MediaWikiApi mwApi; | ||||
|     @Inject ContributionDao contributionDao; | ||||
|     @Inject ModifierSequenceDao modifierSequenceDao; | ||||
| 
 | ||||
|     public ModificationsSyncAdapter(Context context, boolean autoInitialize) { | ||||
|         super(context, autoInitialize); | ||||
|  | @ -84,8 +85,7 @@ public class ModificationsSyncAdapter extends AbstractThreadedSyncAdapter { | |||
|             contributionsClient = getContext().getContentResolver().acquireContentProviderClient(ContributionsContentProvider.CONTRIBUTION_AUTHORITY); | ||||
| 
 | ||||
|             while (!allModifications.isAfterLast()) { | ||||
|                 ModifierSequence sequence = ModifierSequenceDao.fromCursor(allModifications); | ||||
|                 ModifierSequenceDao dao = new ModifierSequenceDao(contributionsClient); | ||||
|                 ModifierSequence sequence = modifierSequenceDao.fromCursor(allModifications); | ||||
|                 Contribution contrib; | ||||
| 
 | ||||
|                 Cursor contributionCursor; | ||||
|  | @ -123,7 +123,7 @@ public class ModificationsSyncAdapter extends AbstractThreadedSyncAdapter { | |||
|                         // FIXME: Log this somewhere else | ||||
|                         Timber.d("Non success result! %s", editResult); | ||||
|                     } else { | ||||
|                         dao.delete(sequence); | ||||
|                         modifierSequenceDao.delete(sequence); | ||||
|                     } | ||||
|                 } | ||||
|                 allModifications.moveToNext(); | ||||
|  |  | |||
|  | @ -11,15 +11,20 @@ import org.json.JSONArray; | |||
| import org.json.JSONException; | ||||
| import org.json.JSONObject; | ||||
| 
 | ||||
| import javax.inject.Inject; | ||||
| import javax.inject.Named; | ||||
| import javax.inject.Provider; | ||||
| 
 | ||||
| public class ModifierSequenceDao { | ||||
| 
 | ||||
|     private final ContentProviderClient client; | ||||
|     private final Provider<ContentProviderClient> clientProvider; | ||||
| 
 | ||||
|     public ModifierSequenceDao(ContentProviderClient client) { | ||||
|         this.client = client; | ||||
|     @Inject | ||||
|     public ModifierSequenceDao(@Named("modification") Provider<ContentProviderClient> clientProvider) { | ||||
|         this.clientProvider = clientProvider; | ||||
|     } | ||||
| 
 | ||||
|     public static ModifierSequence fromCursor(Cursor cursor) { | ||||
|     public ModifierSequence fromCursor(Cursor cursor) { | ||||
|         // Hardcoding column positions! | ||||
|         ModifierSequence ms = null; | ||||
|         try { | ||||
|  | @ -34,22 +39,28 @@ public class ModifierSequenceDao { | |||
|     } | ||||
| 
 | ||||
|     public void save(ModifierSequence sequence) { | ||||
|         ContentProviderClient db = clientProvider.get(); | ||||
|         try { | ||||
|             if (sequence.getContentUri() == null) { | ||||
|                 sequence.setContentUri(client.insert(ModificationsContentProvider.BASE_URI, toContentValues(sequence))); | ||||
|                 sequence.setContentUri(db.insert(ModificationsContentProvider.BASE_URI, toContentValues(sequence))); | ||||
|             } else { | ||||
|                 client.update(sequence.getContentUri(), toContentValues(sequence), null, null); | ||||
|                 db.update(sequence.getContentUri(), toContentValues(sequence), null, null); | ||||
|             } | ||||
|         } catch (RemoteException e) { | ||||
|             throw new RuntimeException(e); | ||||
|         } finally { | ||||
|             db.release(); | ||||
|         } | ||||
|     } | ||||
| 
 | ||||
|     public void delete(ModifierSequence sequence) { | ||||
|         ContentProviderClient db = clientProvider.get(); | ||||
|         try { | ||||
|             client.delete(sequence.getContentUri(), null, null); | ||||
|             db.delete(sequence.getContentUri(), null, null); | ||||
|         } catch (RemoteException e) { | ||||
|             throw new RuntimeException(e); | ||||
|         } finally { | ||||
|             db.release(); | ||||
|         } | ||||
|     } | ||||
| 
 | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Paul Hawke
						Paul Hawke