use of com.newsrob.jobs.ModelUpdateResult in project newsrob by marianokamp.
the class MarkReadUntilHereUITests method executeMarkReadUntilHereOnCurrentSelection.
private void executeMarkReadUntilHereOnCurrentSelection() throws InterruptedException {
final CountDownLatch latch = new CountDownLatch(1);
entryManager.addListener(new IEntryModelUpdateListener() {
@Override
public void statusUpdated() {
}
@Override
public void modelUpdated(String atomId) {
}
@Override
public void modelUpdated() {
latch.countDown();
}
@Override
public void modelUpdateStarted(boolean fastSyncOnly) {
}
@Override
public void modelUpdateFinished(ModelUpdateResult result) {
}
});
getInstrumentation().invokeContextMenuAction(getActivity(), 112, 0);
getInstrumentation().waitForIdleSync();
// Scream if timeout
assertTrue(latch.await(3, TimeUnit.SECONDS));
}
use of com.newsrob.jobs.ModelUpdateResult in project newsrob by marianokamp.
the class LikeStateTests method testUpdateNotification.
public void testUpdateNotification() {
entryManager.addListener(new IEntryModelUpdateListener() {
@Override
public void statusUpdated() {
}
@Override
public void modelUpdated(String atomId) {
modelUpdatedStringCalled = true;
}
@Override
public void modelUpdated() {
modelUpdatedCalled = true;
}
@Override
public void modelUpdateStarted(boolean fastSyncOnly) {
}
@Override
public void modelUpdateFinished(ModelUpdateResult result) {
}
});
Entry e = findEntryNotLikedNotLikePending();
assertTrue(modelUpdatedCalled);
}
use of com.newsrob.jobs.ModelUpdateResult in project newsrob by marianokamp.
the class EntryManager method switchStorageProvider.
private void switchStorageProvider() {
Log.d(TAG, "Switch Storage Provider");
if (isModelCurrentlyUpdated())
return;
final String newPrefValue = getSharedPreferences().getString(SETTINGS_STORAGE_PROVIDER_KEY, null);
final String oldStorageProviderClass = fileContextAdapter.getClass().getName();
final String newStorageProviderClass = STORAGE_PROVIDER_SD_CARD.equals(newPrefValue) ? SdCardStorageAdapter.class.getName() : PhoneMemoryStorageAdapter.class.getName();
if (!oldStorageProviderClass.equals(newStorageProviderClass)) {
runningThread = new Thread(new Runnable() {
public void run() {
final PowerManager pm = (PowerManager) ctx.getSystemService(Context.POWER_SERVICE);
final PowerManager.WakeLock wl = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, TAG);
Log.i(TAG, "Wake lock acquired at " + new Date().toString() + ".");
wl.acquire();
Process.setThreadPriority(Process.THREAD_PRIORITY_BACKGROUND);
final Timing t = new Timing("Storage Provider Switch", ctx);
ModelUpdateResult result = null;
if (isModelCurrentlyUpdated())
return;
try {
lockModel("EM.switchStorageProvider.run");
} catch (final IllegalStateException ise) {
return;
}
try {
Log.i(TAG, "Switching storage providers started at " + new Date().toString() + ".");
fireModelUpdateStarted("Switching storage providers", false, true);
Log.d(TAG, "Change of storage provider detected.");
final List<Job> jobList = new LinkedList<Job>();
final Job clearOldStorageProvider = new Job("Clearing Old Storage Provider", EntryManager.this) {
@Override
public void run() {
Log.d(TAG, "Clearing the old storage provider.");
doClearCache();
if (fileContextAdapter.canWrite())
WebPageDownloadDirector.removeAllAssets(fileContextAdapter, ctx);
}
};
jobList.add(clearOldStorageProvider);
final Job switchStorageProviders = new Job("Switching Storage Providers", EntryManager.this) {
@Override
public void run() throws Exception {
Log.d(TAG, "Establishing new storage provider: " + newStorageProviderClass);
fileContextAdapter = newStorageProviderClass.equals(SdCardStorageAdapter.class.getName()) ? new SdCardStorageAdapter(ctx) : new PhoneMemoryStorageAdapter(ctx);
Log.d(TAG, "New storage provider established.");
}
};
jobList.add(switchStorageProviders);
final Job clearNewStorageProvider = new Job("Clearing New Storage Provider", EntryManager.this) {
@Override
public void run() {
Log.d(TAG, "Clearing the new storage provider.");
doClearCache();
if (fileContextAdapter.canWrite())
WebPageDownloadDirector.removeAllAssets(fileContextAdapter, ctx);
}
};
jobList.add(clearNewStorageProvider);
runJobs(jobList);
result = new SwitchStorageProviderResult();
} catch (final Throwable throwable) {
result = new SwitchStorageProviderFailed(throwable);
Log.d(TAG, "Problem during switching storage providers.", throwable);
t.stop();
} finally {
unlockModel("EM.switchStorageProvider.run");
clearCancelState();
fireModelUpdateFinished(result);
fireStatusUpdated();
Log.i(TAG, "Switching storage providers finished at " + new Date().toString() + ".");
wl.release();
t.stop();
}
}
}, "Storage Provider Switch Worker");
runningThread.start();
}
}
use of com.newsrob.jobs.ModelUpdateResult in project newsrob by marianokamp.
the class NewsRobNotificationManager method createSynchronizationRunningNotificationOld.
Notification createSynchronizationRunningNotificationOld(boolean fastSyncOnly) {
final EntryManager entryManager = EntryManager.getInstance(context);
final Notification n = new Notification(R.drawable.gen_auto_notification_icon, context.getResources().getString(fastSyncOnly ? R.string.fast_synchronization_running_notification_title : R.string.synchronization_running_notification_title), new Date().getTime());
n.flags = Notification.FLAG_ONGOING_EVENT;
final RemoteViews contentView = new RemoteViews(context.getPackageName(), R.layout.in_progress_notification);
n.contentView = contentView;
Intent cancelSyncIntent = new Intent("com.newsrob.CANCEL_SYNC");
// Intent cancelSyncIntent = new Intent();
cancelSyncIntent.setClass(context, FireReceiver.class);
PendingIntent pendingCancelSyncIntent = PendingIntent.getBroadcast(context, 0, cancelSyncIntent, 0);
contentView.setOnClickPendingIntent(R.id.cancel_sync, pendingCancelSyncIntent);
Intent showDashboardIntent = new Intent(context, DashboardListActivity.class);
PendingIntent showDashboardPendingIntent = PendingIntent.getActivity(context, 0, showDashboardIntent, 0);
// showDashboardPendingIntent;
n.contentIntent = pendingCancelSyncIntent;
updateContentView(entryManager, contentView);
entryManager.addListener(new IEntryModelUpdateListener() {
@Override
public void statusUpdated() {
updateContentView(entryManager, contentView);
nm.notify(NOTIFICATION_SYNCHRONIZATION_RUNNING, n);
}
@Override
public void modelUpdated(String atomId) {
}
@Override
public void modelUpdated() {
}
@Override
public void modelUpdateStarted(boolean fastSyncOnly) {
}
@Override
public void modelUpdateFinished(ModelUpdateResult result) {
entryManager.removeListener(this);
}
});
return n;
}
Aggregations