Search in sources :

Example 1 with CacheCleaner

use of org.moire.ultrasonic.util.CacheCleaner in project ultrasonic by ultrasonic.

the class SelectPlaylistActivity method load.

private void load() {
    BackgroundTask<List<Playlist>> task = new TabActivityBackgroundTask<List<Playlist>>(this, true) {

        @Override
        protected List<Playlist> doInBackground() throws Throwable {
            MusicService musicService = MusicServiceFactory.getMusicService(SelectPlaylistActivity.this);
            boolean refresh = getIntent().getBooleanExtra(Constants.INTENT_EXTRA_NAME_REFRESH, false);
            List<Playlist> playlists = musicService.getPlaylists(refresh, SelectPlaylistActivity.this, this);
            if (!Util.isOffline(SelectPlaylistActivity.this))
                new CacheCleaner(SelectPlaylistActivity.this, getDownloadService()).cleanPlaylists(playlists);
            return playlists;
        }

        @Override
        protected void done(List<Playlist> result) {
            playlistsListView.setAdapter(playlistAdapter = new PlaylistAdapter(SelectPlaylistActivity.this, result));
            emptyTextView.setVisibility(result.isEmpty() ? View.VISIBLE : View.GONE);
        }
    };
    task.execute();
}
Also used : Playlist(org.moire.ultrasonic.domain.Playlist) TabActivityBackgroundTask(org.moire.ultrasonic.util.TabActivityBackgroundTask) MusicService(org.moire.ultrasonic.service.MusicService) PlaylistAdapter(org.moire.ultrasonic.view.PlaylistAdapter) List(java.util.List) CacheCleaner(org.moire.ultrasonic.util.CacheCleaner)

Example 2 with CacheCleaner

use of org.moire.ultrasonic.util.CacheCleaner in project ultrasonic by ultrasonic.

the class DownloadServiceLifecycleSupport method onCreate.

public void onCreate() {
    Runnable downloadChecker = new Runnable() {

        @Override
        public void run() {
            try {
                downloadService.checkDownloads();
            } catch (Throwable x) {
                Log.e(TAG, "checkDownloads() failed.", x);
            }
        }
    };
    executorService = Executors.newSingleThreadScheduledExecutor();
    executorService.scheduleWithFixedDelay(downloadChecker, 5, 5, TimeUnit.SECONDS);
    registerHeadsetReceiver();
    // Stop when SD card is ejected.
    ejectEventReceiver = new BroadcastReceiver() {

        @Override
        public void onReceive(Context context, Intent intent) {
            externalStorageAvailable = Intent.ACTION_MEDIA_MOUNTED.equals(intent.getAction());
            if (!externalStorageAvailable) {
                Log.i(TAG, "External media is ejecting. Stopping playback.");
                downloadService.reset();
            } else {
                Log.i(TAG, "External media is available.");
            }
        }
    };
    IntentFilter ejectFilter = new IntentFilter(Intent.ACTION_MEDIA_EJECT);
    ejectFilter.addAction(Intent.ACTION_MEDIA_MOUNTED);
    ejectFilter.addDataScheme("file");
    downloadService.registerReceiver(ejectEventReceiver, ejectFilter);
    // React to media buttons.
    Util.registerMediaButtonEventReceiver(downloadService);
    // Pause temporarily on incoming phone calls.
    // phoneStateListener = new MyPhoneStateListener();
    // TelephonyManager telephonyManager = (TelephonyManager) downloadService.getSystemService(Context.TELEPHONY_SERVICE);
    // telephonyManager.listen(phoneStateListener, PhoneStateListener.LISTEN_CALL_STATE);
    // Register the handler for outside intents.
    IntentFilter commandFilter = new IntentFilter();
    commandFilter.addAction(DownloadServiceImpl.CMD_PLAY);
    commandFilter.addAction(DownloadServiceImpl.CMD_TOGGLEPAUSE);
    commandFilter.addAction(DownloadServiceImpl.CMD_PAUSE);
    commandFilter.addAction(DownloadServiceImpl.CMD_STOP);
    commandFilter.addAction(DownloadServiceImpl.CMD_PREVIOUS);
    commandFilter.addAction(DownloadServiceImpl.CMD_NEXT);
    downloadService.registerReceiver(intentReceiver, commandFilter);
    int instance = Util.getActiveServer(downloadService);
    downloadService.setJukeboxEnabled(Util.getJukeboxEnabled(downloadService, instance));
    deserializeDownloadQueue();
    new CacheCleaner(downloadService, downloadService).clean();
}
Also used : Context(android.content.Context) IntentFilter(android.content.IntentFilter) Intent(android.content.Intent) BroadcastReceiver(android.content.BroadcastReceiver) SuppressLint(android.annotation.SuppressLint) CacheCleaner(org.moire.ultrasonic.util.CacheCleaner)

Aggregations

CacheCleaner (org.moire.ultrasonic.util.CacheCleaner)2 SuppressLint (android.annotation.SuppressLint)1 BroadcastReceiver (android.content.BroadcastReceiver)1 Context (android.content.Context)1 Intent (android.content.Intent)1 IntentFilter (android.content.IntentFilter)1 List (java.util.List)1 Playlist (org.moire.ultrasonic.domain.Playlist)1 MusicService (org.moire.ultrasonic.service.MusicService)1 TabActivityBackgroundTask (org.moire.ultrasonic.util.TabActivityBackgroundTask)1 PlaylistAdapter (org.moire.ultrasonic.view.PlaylistAdapter)1