mirror of
https://codeberg.org/OpenTracksApp/OpenTracks.git
synced 2026-10-08 04:13:06 +02:00
Multiple improvements to the data hub:
* Making registration finer-grained so we only listen to the data we really need. * Moving the system listener registration to an external class (for testability and readability) * Adding a unit test (not yet complete) * Adding documention and cleaning up comments Still many things TODO: * Allow pausing of registrations * Add pause/resume to onPause/onResume of activities * Move sampling logic out of the hub * Optimize data reloading when display preferences change * (maybe) move the data hub and related classes to the "content" package
This commit is contained in:
+38
@@ -0,0 +1,38 @@
|
||||
// Copyright 2010 Google Inc. All Rights Reserved.
|
||||
|
||||
package com.google.android.apps.mytracks.testing;
|
||||
|
||||
import com.google.android.apps.mytracks.content.MyTracksProviderUtils;
|
||||
import com.google.android.apps.mytracks.content.MyTracksProviderUtils.Factory;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
/**
|
||||
* A fake factory for {@link MyTracksProviderUtils} which always returns a
|
||||
* predefined instance.
|
||||
*
|
||||
* @author Rodrigo Damazio
|
||||
*/
|
||||
public class TestingProviderUtilsFactory extends Factory {
|
||||
private MyTracksProviderUtils instance;
|
||||
|
||||
public TestingProviderUtilsFactory(MyTracksProviderUtils instance) {
|
||||
this.instance = instance;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected MyTracksProviderUtils newForContext(Context context) {
|
||||
return instance;
|
||||
}
|
||||
|
||||
public static Factory installWithInstance(MyTracksProviderUtils instance) {
|
||||
Factory oldFactory = Factory.getInstance();
|
||||
Factory factory = new TestingProviderUtilsFactory(instance);
|
||||
MyTracksProviderUtils.Factory.overrideInstance(factory);
|
||||
return oldFactory;
|
||||
}
|
||||
|
||||
public static void restoreOldFactory(Factory factory) {
|
||||
MyTracksProviderUtils.Factory.overrideInstance(factory);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user