Search in sources :

Example 6 with BackupManager

use of android.app.backup.BackupManager in project android_frameworks_base by ParanoidAndroid.

the class HugeBackupActivity method onCreate.

/** Set up the activity and populate its UI from the persistent data. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    /** Establish the activity's UI */
    setContentView(R.layout.backup_restore);
    /** Once the UI has been inflated, cache the controls for later */
    mFillingGroup = (RadioGroup) findViewById(R.id.filling_group);
    mAddMayoCheckbox = (CheckBox) findViewById(R.id.mayo);
    mAddTomatoCheckbox = (CheckBox) findViewById(R.id.tomato);
    /** Set up our file bookkeeping */
    mDataFile = new File(getFilesDir(), HugeBackupActivity.DATA_FILE_NAME);
    /** It is handy to keep a BackupManager cached */
    mBackupManager = new BackupManager(this);
    /**
         * Finally, build the UI from the persistent store
         */
    populateUI();
}
Also used : RandomAccessFile(java.io.RandomAccessFile) File(java.io.File) BackupManager(android.app.backup.BackupManager)

Example 7 with BackupManager

use of android.app.backup.BackupManager in project platform_frameworks_base by android.

the class HugeBackupActivity method onCreate.

/** Set up the activity and populate its UI from the persistent data. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    /** Establish the activity's UI */
    setContentView(R.layout.backup_restore);
    /** Once the UI has been inflated, cache the controls for later */
    mFillingGroup = (RadioGroup) findViewById(R.id.filling_group);
    mAddMayoCheckbox = (CheckBox) findViewById(R.id.mayo);
    mAddTomatoCheckbox = (CheckBox) findViewById(R.id.tomato);
    /** Set up our file bookkeeping */
    mDataFile = new File(getFilesDir(), HugeBackupActivity.DATA_FILE_NAME);
    /** It is handy to keep a BackupManager cached */
    mBackupManager = new BackupManager(this);
    /**
         * Finally, build the UI from the persistent store
         */
    populateUI();
}
Also used : RandomAccessFile(java.io.RandomAccessFile) File(java.io.File) BackupManager(android.app.backup.BackupManager)

Example 8 with BackupManager

use of android.app.backup.BackupManager in project AntennaPod by AntennaPod.

the class DBWriter method addNewFeed.

static Future<?> addNewFeed(final Context context, final Feed... feeds) {
    return dbExec.submit(() -> {
        final PodDBAdapter adapter = PodDBAdapter.getInstance();
        adapter.open();
        adapter.setCompleteFeed(feeds);
        adapter.close();
        if (ClientConfig.gpodnetCallbacks.gpodnetEnabled()) {
            for (Feed feed : feeds) {
                GpodnetPreferences.addAddedFeed(feed.getDownload_url());
            }
        }
        BackupManager backupManager = new BackupManager(context);
        backupManager.dataChanged();
    });
}
Also used : BackupManager(android.app.backup.BackupManager) Feed(de.danoeh.antennapod.core.feed.Feed)

Example 9 with BackupManager

use of android.app.backup.BackupManager in project AntennaPod by AntennaPod.

the class DBWriter method deleteFeed.

/**
     * Deletes a Feed and all downloaded files of its components like images and downloaded episodes.
     *
     * @param context A context that is used for opening a database connection.
     * @param feedId  ID of the Feed that should be deleted.
     */
public static Future<?> deleteFeed(final Context context, final long feedId) {
    return dbExec.submit(() -> {
        DownloadRequester requester = DownloadRequester.getInstance();
        SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context.getApplicationContext());
        final Feed feed = DBReader.getFeed(feedId);
        if (feed != null) {
            if (PlaybackPreferences.getCurrentlyPlayingMedia() == FeedMedia.PLAYABLE_TYPE_FEEDMEDIA && PlaybackPreferences.getLastPlayedFeedId() == feed.getId()) {
                context.sendBroadcast(new Intent(PlaybackService.ACTION_SHUTDOWN_PLAYBACK_SERVICE));
                SharedPreferences.Editor editor = prefs.edit();
                editor.putLong(PlaybackPreferences.PREF_CURRENTLY_PLAYING_FEED_ID, -1);
                editor.commit();
            }
            // delete image file
            if (feed.getImage() != null) {
                if (feed.getImage().isDownloaded() && feed.getImage().getFile_url() != null) {
                    File imageFile = new File(feed.getImage().getFile_url());
                    imageFile.delete();
                } else if (requester.isDownloadingFile(feed.getImage())) {
                    requester.cancelDownload(context, feed.getImage());
                }
            }
            // delete stored media files and mark them as read
            List<FeedItem> queue = DBReader.getQueue();
            List<FeedItem> removed = new ArrayList<>();
            if (feed.getItems() == null) {
                DBReader.getFeedItemList(feed);
            }
            for (FeedItem item : feed.getItems()) {
                if (queue.remove(item)) {
                    removed.add(item);
                }
                if (item.getMedia() != null && item.getMedia().isDownloaded()) {
                    File mediaFile = new File(item.getMedia().getFile_url());
                    mediaFile.delete();
                } else if (item.getMedia() != null && requester.isDownloadingFile(item.getMedia())) {
                    requester.cancelDownload(context, item.getMedia());
                }
                if (item.hasItemImage()) {
                    FeedImage image = item.getImage();
                    if (image.isDownloaded() && image.getFile_url() != null) {
                        File imgFile = new File(image.getFile_url());
                        imgFile.delete();
                    } else if (requester.isDownloadingFile(image)) {
                        requester.cancelDownload(context, item.getImage());
                    }
                }
            }
            PodDBAdapter adapter = PodDBAdapter.getInstance();
            adapter.open();
            if (removed.size() > 0) {
                adapter.setQueue(queue);
                for (FeedItem item : removed) {
                    EventBus.getDefault().post(QueueEvent.irreversibleRemoved(item));
                }
            }
            adapter.removeFeed(feed);
            adapter.close();
            if (ClientConfig.gpodnetCallbacks.gpodnetEnabled()) {
                GpodnetPreferences.addRemovedFeed(feed.getDownload_url());
            }
            EventDistributor.getInstance().sendFeedUpdateBroadcast();
            // we assume we also removed download log entries for the feed or its media files.
            // especially important if download or refresh failed, as the user should not be able
            // to retry these
            EventDistributor.getInstance().sendDownloadLogUpdateBroadcast();
            BackupManager backupManager = new BackupManager(context);
            backupManager.dataChanged();
        }
    });
}
Also used : FeedImage(de.danoeh.antennapod.core.feed.FeedImage) FeedItem(de.danoeh.antennapod.core.feed.FeedItem) SharedPreferences(android.content.SharedPreferences) ArrayList(java.util.ArrayList) Intent(android.content.Intent) File(java.io.File) BackupManager(android.app.backup.BackupManager) Feed(de.danoeh.antennapod.core.feed.Feed)

Example 10 with BackupManager

use of android.app.backup.BackupManager in project android_frameworks_base by crdroidandroid.

the class HugeBackupActivity method onCreate.

/** Set up the activity and populate its UI from the persistent data. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    /** Establish the activity's UI */
    setContentView(R.layout.backup_restore);
    /** Once the UI has been inflated, cache the controls for later */
    mFillingGroup = (RadioGroup) findViewById(R.id.filling_group);
    mAddMayoCheckbox = (CheckBox) findViewById(R.id.mayo);
    mAddTomatoCheckbox = (CheckBox) findViewById(R.id.tomato);
    /** Set up our file bookkeeping */
    mDataFile = new File(getFilesDir(), HugeBackupActivity.DATA_FILE_NAME);
    /** It is handy to keep a BackupManager cached */
    mBackupManager = new BackupManager(this);
    /**
         * Finally, build the UI from the persistent store
         */
    populateUI();
}
Also used : RandomAccessFile(java.io.RandomAccessFile) File(java.io.File) BackupManager(android.app.backup.BackupManager)

Aggregations

BackupManager (android.app.backup.BackupManager)10 File (java.io.File)6 RandomAccessFile (java.io.RandomAccessFile)5 Context (android.content.Context)3 SharedPreferences (android.content.SharedPreferences)3 Intent (android.content.Intent)2 Feed (de.danoeh.antennapod.core.feed.Feed)2 BroadcastReceiver (android.content.BroadcastReceiver)1 IntentFilter (android.content.IntentFilter)1 Editor (android.content.SharedPreferences.Editor)1 OnSharedPreferenceChangeListener (android.content.SharedPreferences.OnSharedPreferenceChangeListener)1 FeedImage (de.danoeh.antennapod.core.feed.FeedImage)1 FeedItem (de.danoeh.antennapod.core.feed.FeedItem)1 ArrayList (java.util.ArrayList)1