mirror of
				https://github.com/commons-app/apps-android-commons.git
				synced 2025-10-30 22:34:02 +01:00 
			
		
		
		
	@Injected shared preferences where needed
This commit is contained in:
		
							parent
							
								
									1b840502a9
								
							
						
					
					
						commit
						9aa021695b
					
				
					 20 changed files with 137 additions and 100 deletions
				
			
		|  | @ -9,7 +9,6 @@ import android.database.Cursor; | |||
| import android.database.DataSetObserver; | ||||
| import android.os.Bundle; | ||||
| import android.os.IBinder; | ||||
| import android.preference.PreferenceManager; | ||||
| import android.support.v4.app.FragmentManager; | ||||
| import android.support.v4.app.LoaderManager; | ||||
| import android.support.v4.content.CursorLoader; | ||||
|  | @ -24,6 +23,7 @@ import android.widget.AdapterView; | |||
| import java.util.ArrayList; | ||||
| 
 | ||||
| import javax.inject.Inject; | ||||
| import javax.inject.Named; | ||||
| 
 | ||||
| import butterknife.ButterKnife; | ||||
| import fr.free.nrw.commons.HandlerService; | ||||
|  | @ -45,7 +45,9 @@ import static fr.free.nrw.commons.contributions.Contribution.STATE_FAILED; | |||
| import static fr.free.nrw.commons.contributions.Contribution.Table.ALL_FIELDS; | ||||
| import static fr.free.nrw.commons.contributions.ContributionsContentProvider.AUTHORITY; | ||||
| import static fr.free.nrw.commons.contributions.ContributionsContentProvider.BASE_URI; | ||||
| import static fr.free.nrw.commons.settings.Prefs.UPLOADS_SHOWING;public  class       ContributionsActivity | ||||
| import static fr.free.nrw.commons.settings.Prefs.UPLOADS_SHOWING; | ||||
| 
 | ||||
| public  class       ContributionsActivity | ||||
|         extends     AuthenticatedActivity | ||||
|         implements  LoaderManager.LoaderCallbacks<Cursor>, | ||||
|                     AdapterView.OnItemClickListener, | ||||
|  | @ -55,6 +57,7 @@ import static fr.free.nrw.commons.settings.Prefs.UPLOADS_SHOWING;public  class | |||
| 
 | ||||
|     @Inject MediaWikiApi mediaWikiApi; | ||||
|     @Inject SessionManager sessionManager; | ||||
|     @Inject @Named("default_preferences") SharedPreferences prefs; | ||||
| 
 | ||||
|     private Cursor allContributions; | ||||
|     private ContributionsListFragment contributionsList; | ||||
|  | @ -108,12 +111,8 @@ import static fr.free.nrw.commons.settings.Prefs.UPLOADS_SHOWING;public  class | |||
|     @Override | ||||
|     protected void onResume() { | ||||
|         super.onResume(); | ||||
|         SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this); | ||||
|         boolean isSettingsChanged = | ||||
|                 sharedPreferences.getBoolean(Prefs.IS_CONTRIBUTION_COUNT_CHANGED, false); | ||||
|         SharedPreferences.Editor editor = sharedPreferences.edit(); | ||||
|         editor.putBoolean(Prefs.IS_CONTRIBUTION_COUNT_CHANGED, false); | ||||
|         editor.apply(); | ||||
|         boolean isSettingsChanged = prefs.getBoolean(Prefs.IS_CONTRIBUTION_COUNT_CHANGED, false); | ||||
|         prefs.edit().putBoolean(Prefs.IS_CONTRIBUTION_COUNT_CHANGED, false).apply(); | ||||
|         if (isSettingsChanged) { | ||||
|             refreshSource(); | ||||
|         } | ||||
|  | @ -235,8 +234,7 @@ import static fr.free.nrw.commons.settings.Prefs.UPLOADS_SHOWING;public  class | |||
| 
 | ||||
|     @Override | ||||
|     public Loader<Cursor> onCreateLoader(int i, Bundle bundle) { | ||||
|         SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(this); | ||||
|         int uploads = sharedPref.getInt(UPLOADS_SHOWING, 100); | ||||
|         int uploads = prefs.getInt(UPLOADS_SHOWING, 100); | ||||
|         return new CursorLoader(this, BASE_URI, | ||||
|                 ALL_FIELDS, CONTRIBUTION_SELECTION, null, | ||||
|                 CONTRIBUTION_SORT + "LIMIT " + uploads); | ||||
|  |  | |||
|  | @ -19,6 +19,9 @@ import android.widget.GridView; | |||
| import android.widget.ListAdapter; | ||||
| import android.widget.TextView; | ||||
| 
 | ||||
| import javax.inject.Inject; | ||||
| import javax.inject.Named; | ||||
| 
 | ||||
| import butterknife.BindView; | ||||
| import butterknife.ButterKnife; | ||||
| import dagger.android.support.DaggerFragment; | ||||
|  | @ -28,7 +31,6 @@ import timber.log.Timber; | |||
| 
 | ||||
| import static android.Manifest.permission.READ_EXTERNAL_STORAGE; | ||||
| import static android.app.Activity.RESULT_OK; | ||||
| import static android.content.Context.MODE_PRIVATE; | ||||
| import static android.content.pm.PackageManager.PERMISSION_GRANTED; | ||||
| import static android.view.View.GONE; | ||||
| 
 | ||||
|  | @ -37,6 +39,7 @@ public class ContributionsListFragment extends DaggerFragment { | |||
|     @BindView(R.id.contributionsList) GridView contributionsList; | ||||
|     @BindView(R.id.waitingMessage) TextView waitingMessage; | ||||
|     @BindView(R.id.emptyMessage) TextView emptyMessage; | ||||
|     @Inject @Named("prefs") SharedPreferences prefs; | ||||
|     private ContributionController controller; | ||||
| 
 | ||||
|     @Override | ||||
|  | @ -51,7 +54,6 @@ public class ContributionsListFragment extends DaggerFragment { | |||
|         } | ||||
| 
 | ||||
|         //TODO: Should this be in onResume? | ||||
|         SharedPreferences prefs = getActivity().getSharedPreferences("prefs", MODE_PRIVATE); | ||||
|         String lastModified = prefs.getString("lastSyncTimestamp", ""); | ||||
|         Timber.d("Last Sync Timestamp: %s", lastModified); | ||||
| 
 | ||||
|  |  | |||
|  | @ -21,6 +21,7 @@ import java.util.Locale; | |||
| import java.util.TimeZone; | ||||
| 
 | ||||
| import javax.inject.Inject; | ||||
| import javax.inject.Named; | ||||
| 
 | ||||
| import fr.free.nrw.commons.CommonsApplication; | ||||
| import fr.free.nrw.commons.Utils; | ||||
|  | @ -28,11 +29,11 @@ import fr.free.nrw.commons.mwapi.LogEventResult; | |||
| import fr.free.nrw.commons.mwapi.MediaWikiApi; | ||||
| import timber.log.Timber; | ||||
| 
 | ||||
| import static android.content.Context.MODE_PRIVATE; | ||||
| import static fr.free.nrw.commons.contributions.Contribution.STATE_COMPLETED; | ||||
| import static fr.free.nrw.commons.contributions.Contribution.Table.COLUMN_FILENAME; | ||||
| import static fr.free.nrw.commons.contributions.ContributionsContentProvider.BASE_URI; | ||||
| 
 | ||||
| @SuppressWarnings("WeakerAccess") | ||||
| public class ContributionsSyncAdapter extends AbstractThreadedSyncAdapter { | ||||
| 
 | ||||
|     private static final String[] existsQuery = {COLUMN_FILENAME}; | ||||
|  | @ -42,6 +43,7 @@ public class ContributionsSyncAdapter extends AbstractThreadedSyncAdapter { | |||
| 
 | ||||
|     @SuppressWarnings("WeakerAccess") | ||||
|     @Inject MediaWikiApi mwApi; | ||||
|     @Inject @Named("prefs") SharedPreferences prefs; | ||||
| 
 | ||||
|     public ContributionsSyncAdapter(Context context, boolean autoInitialize) { | ||||
|         super(context, autoInitialize); | ||||
|  | @ -79,7 +81,6 @@ public class ContributionsSyncAdapter extends AbstractThreadedSyncAdapter { | |||
|         ((CommonsApplication) getContext().getApplicationContext()).injector().inject(this); | ||||
|         // This code is fraught with possibilities of race conditions, but lalalalala I can't hear you! | ||||
|         String user = account.name; | ||||
|         SharedPreferences prefs = getContext().getSharedPreferences("prefs", MODE_PRIVATE); | ||||
|         String lastModified = prefs.getString("lastSyncTimestamp", ""); | ||||
|         Date curTime = new Date(); | ||||
|         LogEventResult result; | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Paul Hawke
						Paul Hawke