Search in sources :

Example 6 with ModelUpdateResult

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));
}
Also used : IEntryModelUpdateListener(com.newsrob.IEntryModelUpdateListener) ModelUpdateResult(com.newsrob.jobs.ModelUpdateResult) CountDownLatch(java.util.concurrent.CountDownLatch)

Example 7 with ModelUpdateResult

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);
}
Also used : IEntryModelUpdateListener(com.newsrob.IEntryModelUpdateListener) Entry(com.newsrob.Entry) ModelUpdateResult(com.newsrob.jobs.ModelUpdateResult)

Example 8 with ModelUpdateResult

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();
    }
}
Also used : ModelUpdateResult(com.newsrob.jobs.ModelUpdateResult) Date(java.util.Date) LinkedList(java.util.LinkedList) SdCardStorageAdapter(com.newsrob.storage.SdCardStorageAdapter) SwitchStorageProviderResult(com.newsrob.jobs.SwitchStorageProviderResult) PowerManager(android.os.PowerManager) SwitchStorageProviderFailed(com.newsrob.jobs.SwitchStorageProviderFailed) Timing(com.newsrob.util.Timing) Job(com.newsrob.jobs.Job) PhoneMemoryStorageAdapter(com.newsrob.storage.PhoneMemoryStorageAdapter)

Example 9 with ModelUpdateResult

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;
}
Also used : RemoteViews(android.widget.RemoteViews) ModelUpdateResult(com.newsrob.jobs.ModelUpdateResult) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) PendingIntent(android.app.PendingIntent) Notification(android.app.Notification) Date(java.util.Date)

Aggregations

ModelUpdateResult (com.newsrob.jobs.ModelUpdateResult)9 IEntryModelUpdateListener (com.newsrob.IEntryModelUpdateListener)5 Date (java.util.Date)4 CountDownLatch (java.util.concurrent.CountDownLatch)4 Job (com.newsrob.jobs.Job)3 Timing (com.newsrob.util.Timing)3 LinkedList (java.util.LinkedList)3 Context (android.content.Context)2 Cursor (android.database.Cursor)2 SyncJobStatus (com.newsrob.EntryManager.SyncJobStatus)2 DownloadCancelledException (com.newsrob.download.DownloadCancelledException)2 DownloadException (com.newsrob.download.DownloadException)2 DownloadTimedOutException (com.newsrob.download.DownloadTimedOutException)2 SynchronizeModelFailed (com.newsrob.jobs.SynchronizeModelFailed)2 SynchronizeModelSucceeded (com.newsrob.jobs.SynchronizeModelSucceeded)2 IStorageAdapter (com.newsrob.storage.IStorageAdapter)2 FileNotFoundException (java.io.FileNotFoundException)2 IOException (java.io.IOException)2 MalformedURLException (java.net.MalformedURLException)2 SocketException (java.net.SocketException)2