Skip to content
This repository has been archived by the owner on Jan 13, 2022. It is now read-only.

Commit

Permalink
Step 6: Make the default build be an exopackage
Browse files Browse the repository at this point in the history
  • Loading branch information
dreiss authored and k21 committed Jun 25, 2015
1 parent 1f1b375 commit 4250292
Show file tree
Hide file tree
Showing 15 changed files with 85 additions and 34 deletions.
3 changes: 2 additions & 1 deletion AndroidManifest.xml
@@ -1,4 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- The files and modifications provided by Facebook are for testing and evaluation purposes only. Facebook reserves all rights not expressly granted. -->
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="de.danoeh.antennapod"
android:versionCode="37"
Expand Down Expand Up @@ -32,7 +33,7 @@
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>

<application
android:name="de.danoeh.antennapod.PodcastApp"
android:name="de.danoeh.antennapod.AppShell"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:backupAgent=".backup.OpmlBackupAgent"
Expand Down
21 changes: 20 additions & 1 deletion BUCK
Expand Up @@ -37,9 +37,11 @@ android_build_config(
package = 'de.danoeh.antennapod',
)

APP_CLASS_SOURCE = 'src/de/danoeh/antennapod/AppShell.java'

android_library(
name = 'main-lib',
srcs = glob(['src/de/danoeh/antennapod/**/*.java']),
srcs = glob(['src/de/danoeh/antennapod/**/*.java'], excludes = [APP_CLASS_SOURCE]),
deps = [
':all-jars',
':dslv-lib',
Expand All @@ -50,6 +52,15 @@ android_library(
],
)

android_library(
name = 'application-lib',
srcs = [APP_CLASS_SOURCE],
deps = [
':build-config',
':jars__buck-android-support',
],
)

android_resource(
name = 'res',
package = 'de.danoeh.antennapod',
Expand Down Expand Up @@ -105,8 +116,16 @@ android_binary(
name = 'antennapod',
manifest = ':manifest',
keystore = ':debug_keystore',
use_split_dex = True,
exopackage = True,
primary_dex_patterns = [
'^de/danoeh/antennapod/AppShell^',
'^de/danoeh/antennapod/BuildConfig^',
'^com/facebook/buck/android/support/exopackage/'
],
deps = [
':main-lib',
':application-lib',
],
)

Expand Down
10 changes: 10 additions & 0 deletions src/de/danoeh/antennapod/AppShell.java
@@ -0,0 +1,10 @@
// The files and modifications provided by Facebook are for testing and evaluation purposes only. Facebook reserves all rights not expressly granted.
package de.danoeh.antennapod;

import com.facebook.buck.android.support.exopackage.ExopackageApplication;

public class AppShell extends ExopackageApplication {
public AppShell() {
super("de.danoeh.antennapod.PodcastApp", BuildConfig.IS_EXOPACKAGE);
}
}
32 changes: 21 additions & 11 deletions src/de/danoeh/antennapod/PodcastApp.java
@@ -1,16 +1,18 @@
// The files and modifications provided by Facebook are for testing and evaluation purposes only. Facebook reserves all rights not expressly granted.
package de.danoeh.antennapod;

import android.app.Application;
import android.content.res.Configuration;
import android.util.Log;
import com.facebook.buck.android.support.exopackage.DefaultApplicationLike;
import de.danoeh.antennapod.asynctask.ImageLoader;
import de.danoeh.antennapod.feed.EventDistributor;
import de.danoeh.antennapod.preferences.PlaybackPreferences;
import de.danoeh.antennapod.preferences.UserPreferences;
import de.danoeh.antennapod.spa.SPAUtil;

/** Main application class. */
public class PodcastApp extends Application {
public class PodcastApp extends DefaultApplicationLike {

private static final String TAG = "PodcastApp";
public static final String EXPORT_DIR = "export/";
Expand All @@ -19,37 +21,45 @@ public class PodcastApp extends Application {

private static PodcastApp singleton;

public static PodcastApp getInstance() {
public static PodcastApp getInstance() {
return singleton;
}

private final Application appContext;

public static Application getAppContext() {
return getInstance().appContext;
}

public PodcastApp(Application appContext) {
this.appContext = appContext;
}

@Override
public void onCreate() {
super.onCreate();
singleton = this;
LOGICAL_DENSITY = getResources().getDisplayMetrics().density;
LOGICAL_DENSITY = appContext.getResources().getDisplayMetrics().density;

UserPreferences.createInstance(this);
PlaybackPreferences.createInstance(this);
UserPreferences.createInstance(appContext);
PlaybackPreferences.createInstance(appContext);
EventDistributor.getInstance();

SPAUtil.sendSPAppsQueryFeedsIntent(this);
SPAUtil.sendSPAppsQueryFeedsIntent(appContext);
}

@Override
public void onLowMemory() {
super.onLowMemory();
Log.w(TAG, "Received onLowOnMemory warning. Cleaning image cache...");
ImageLoader.getInstance().wipeImageCache();
}

public static float getLogicalDensity() {
public static float getLogicalDensity() {
return LOGICAL_DENSITY;
}

public boolean isLargeScreen() {
return (getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) == Configuration.SCREENLAYOUT_SIZE_LARGE
|| (getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) == Configuration.SCREENLAYOUT_SIZE_XLARGE;
return (appContext.getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) == Configuration.SCREENLAYOUT_SIZE_LARGE
|| (appContext.getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) == Configuration.SCREENLAYOUT_SIZE_XLARGE;

}
}
@@ -1,3 +1,4 @@
// The files and modifications provided by Facebook are for testing and evaluation purposes only. Facebook reserves all rights not expressly granted.
package de.danoeh.antennapod.asynctask;

import android.graphics.BitmapFactory;
Expand Down Expand Up @@ -57,8 +58,8 @@ protected void onPostExecute() {
// check if imageview is still supposed to display this image
if (tagsMatching(target) && cBitmap.getBitmap() != null) {
Drawable[] drawables = new Drawable[]{
PodcastApp.getInstance().getResources().getDrawable(android.R.color.transparent),
new BitmapDrawable(PodcastApp.getInstance().getResources(), cBitmap.getBitmap())
PodcastApp.getAppContext().getResources().getDrawable(android.R.color.transparent),
new BitmapDrawable(PodcastApp.getAppContext().getResources(), cBitmap.getBitmap())
};
TransitionDrawable transitionDrawable = new TransitionDrawable(drawables);
target.setImageDrawable(transitionDrawable);
Expand Down
3 changes: 2 additions & 1 deletion src/de/danoeh/antennapod/asynctask/ImageDiskCache.java
@@ -1,3 +1,4 @@
// The files and modifications provided by Facebook are for testing and evaluation purposes only. Facebook reserves all rights not expressly granted.
package de.danoeh.antennapod.asynctask;

import android.os.Handler;
Expand Down Expand Up @@ -37,7 +38,7 @@ public static synchronized ImageDiskCache getDefaultInstance() {
final String DEFAULT_PATH = "imagecache";
final long DEFAULT_MAX_CACHE_SIZE = 10 * 1024 * 1024;

File cacheDir = PodcastApp.getInstance().getExternalCacheDir();
File cacheDir = PodcastApp.getAppContext().getExternalCacheDir();
if (cacheDir == null) {
return null;
}
Expand Down
3 changes: 2 additions & 1 deletion src/de/danoeh/antennapod/asynctask/ImageLoader.java
@@ -1,3 +1,4 @@
// The files and modifications provided by Facebook are for testing and evaluation purposes only. Facebook reserves all rights not expressly granted.
package de.danoeh.antennapod.asynctask;

import android.annotation.SuppressLint;
Expand Down Expand Up @@ -40,7 +41,7 @@ public class ImageLoader {
* the FeedImage the bitmap belongs to.
*/

final int memClass = ((ActivityManager) PodcastApp.getInstance()
final int memClass = ((ActivityManager) PodcastApp.getAppContext()
.getSystemService(Context.ACTIVITY_SERVICE)).getMemoryClass();

// Use 1/8th of the available memory for this memory cache.
Expand Down
3 changes: 2 additions & 1 deletion src/de/danoeh/antennapod/feed/FeedItem.java
@@ -1,3 +1,4 @@
// The files and modifications provided by Facebook are for testing and evaluation purposes only. Facebook reserves all rights not expressly granted.
package de.danoeh.antennapod.feed;

import de.danoeh.antennapod.PodcastApp;
Expand Down Expand Up @@ -253,7 +254,7 @@ public Callable<String> loadShownotes() {
public String call() throws Exception {

if (contentEncoded == null || description == null) {
DBReader.loadExtraInformationOfFeedItem(PodcastApp.getInstance(), FeedItem.this);
DBReader.loadExtraInformationOfFeedItem(PodcastApp.getAppContext(), FeedItem.this);

}
return (contentEncoded != null) ? contentEncoded : description;
Expand Down
11 changes: 6 additions & 5 deletions src/de/danoeh/antennapod/feed/FeedMedia.java
@@ -1,3 +1,4 @@
// The files and modifications provided by Facebook are for testing and evaluation purposes only. Facebook reserves all rights not expressly granted.
package de.danoeh.antennapod.feed;

import android.content.SharedPreferences;
Expand Down Expand Up @@ -239,7 +240,7 @@ public void writeToPreferences(Editor prefEditor) {
@Override
public void loadMetadata() throws PlayableException {
if (item == null && itemID != 0) {
item = DBReader.getFeedItem(PodcastApp.getInstance(), itemID);
item = DBReader.getFeedItem(PodcastApp.getAppContext(), itemID);
}
}

Expand All @@ -248,7 +249,7 @@ public void loadChapterMarks() {
if (getChapters() == null && !localFileAvailable()) {
ChapterUtils.loadChaptersFromStreamUrl(this);
if (getChapters() != null && item != null) {
DBWriter.setFeedItem(PodcastApp.getInstance(),
DBWriter.setFeedItem(PodcastApp.getAppContext(),
item);
}
}
Expand Down Expand Up @@ -327,7 +328,7 @@ public boolean streamAvailable() {
@Override
public void saveCurrentPosition(SharedPreferences pref, int newPosition) {
setPosition(newPosition);
DBWriter.setFeedMediaPlaybackInformation(PodcastApp.getInstance(), this);
DBWriter.setFeedMediaPlaybackInformation(PodcastApp.getAppContext(), this);
}

@Override
Expand Down Expand Up @@ -355,10 +356,10 @@ public Callable<String> loadShownotes() {
@Override
public String call() throws Exception {
if (item == null) {
item = DBReader.getFeedItem(PodcastApp.getInstance(), itemID);
item = DBReader.getFeedItem(PodcastApp.getAppContext(), itemID);
}
if (item.getContentEncoded() == null || item.getDescription() == null) {
DBReader.loadExtraInformationOfFeedItem(PodcastApp.getInstance(), item);
DBReader.loadExtraInformationOfFeedItem(PodcastApp.getAppContext(), item);

}
return (item.getContentEncoded() != null) ? item.getContentEncoded() : item.getDescription();
Expand Down
7 changes: 4 additions & 3 deletions src/de/danoeh/antennapod/preferences/GpodnetPreferences.java
@@ -1,3 +1,4 @@
// The files and modifications provided by Facebook are for testing and evaluation purposes only. Facebook reserves all rights not expressly granted.
package de.danoeh.antennapod.preferences;

import android.content.Context;
Expand Down Expand Up @@ -48,7 +49,7 @@ public class GpodnetPreferences {
private static boolean preferencesLoaded = false;

private static SharedPreferences getPreferences() {
return PodcastApp.getInstance().getSharedPreferences(PREF_NAME, Context.MODE_PRIVATE);
return PodcastApp.getAppContext().getSharedPreferences(PREF_NAME, Context.MODE_PRIVATE);
}

private static synchronized void ensurePreferencesLoaded() {
Expand Down Expand Up @@ -148,7 +149,7 @@ public static void addAddedFeed(String feed) {
writePreference(PREF_SYNC_REMOVED, removedFeeds);
}
feedListLock.unlock();
GpodnetSyncService.sendSyncIntent(PodcastApp.getInstance());
GpodnetSyncService.sendSyncIntent(PodcastApp.getAppContext());
}

public static void addRemovedFeed(String feed) {
Expand All @@ -161,7 +162,7 @@ public static void addRemovedFeed(String feed) {
writePreference(PREF_SYNC_ADDED, addedFeeds);
}
feedListLock.unlock();
GpodnetSyncService.sendSyncIntent(PodcastApp.getInstance());
GpodnetSyncService.sendSyncIntent(PodcastApp.getAppContext());
}

public static Set<String> getAddedFeedsCopy() {
Expand Down
5 changes: 3 additions & 2 deletions src/de/danoeh/antennapod/service/download/Downloader.java
@@ -1,3 +1,4 @@
// The files and modifications provided by Facebook are for testing and evaluation purposes only. Facebook reserves all rights not expressly granted.
package de.danoeh.antennapod.service.download;

import android.content.Context;
Expand Down Expand Up @@ -29,7 +30,7 @@ public Downloader(DownloadRequest request) {
protected abstract void download();

public final Downloader call() {
WifiManager wifiManager = (WifiManager) PodcastApp.getInstance().getSystemService(Context.WIFI_SERVICE);
WifiManager wifiManager = (WifiManager) PodcastApp.getAppContext().getSystemService(Context.WIFI_SERVICE);
WifiManager.WifiLock wifiLock = null;
if (wifiManager != null) {
wifiLock = wifiManager.createWifiLock(TAG);
Expand Down Expand Up @@ -66,4 +67,4 @@ public void cancel() {
cancelled = true;
}

}
}
@@ -1,3 +1,4 @@
// The files and modifications provided by Facebook are for testing and evaluation purposes only. Facebook reserves all rights not expressly granted.
package de.danoeh.antennapod.service.download;

import android.net.http.AndroidHttpClient;
Expand Down Expand Up @@ -104,7 +105,7 @@ protected void download() {
return;
}

if (!StorageUtils.storageAvailable(PodcastApp.getInstance())) {
if (!StorageUtils.storageAvailable(PodcastApp.getAppContext())) {
onFail(DownloadError.ERROR_DEVICE_NOT_FOUND, null);
return;
}
Expand Down
@@ -1,3 +1,4 @@
// The files and modifications provided by Facebook are for testing and evaluation purposes only. Facebook reserves all rights not expressly granted.
package de.danoeh.antennapod.service.playback;

import android.annotation.SuppressLint;
Expand Down Expand Up @@ -758,7 +759,7 @@ private synchronized void saveCurrentPosition(boolean updatePlayedDuration, int
Log.d(TAG, "saveCurrentPosition: performing auto flattr since played duration " + Integer.toString(m.getPlayedDuration())
+ " is " + UserPreferences.getPlayedDurationAutoflattrThreshold() * 100 + "% of file duration " + Integer.toString(duration));
item.getFlattrStatus().setFlattrQueue();
DBWriter.setFeedItemFlattrStatus(PodcastApp.getInstance(), item, false);
DBWriter.setFeedItemFlattrStatus(PodcastApp.getAppContext(), item, false);
}
}
playable.saveCurrentPosition(PreferenceManager
Expand Down
3 changes: 2 additions & 1 deletion src/de/danoeh/antennapod/util/StorageUtils.java
@@ -1,3 +1,4 @@
// The files and modifications provided by Facebook are for testing and evaluation purposes only. Facebook reserves all rights not expressly granted.
package de.danoeh.antennapod.util;

import android.app.Activity;
Expand Down Expand Up @@ -51,7 +52,7 @@ public static boolean checkStorageAvailability(Activity activity) {
/** Get the number of free bytes that are available on the external storage. */
public static long getFreeSpaceAvailable() {
StatFs stat = new StatFs(UserPreferences.getDataFolder(
PodcastApp.getInstance(), null).getAbsolutePath());
PodcastApp.getAppContext(), null).getAbsolutePath());
long availableBlocks;
long blockSize;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
Expand Down
7 changes: 4 additions & 3 deletions src/de/danoeh/antennapod/util/flattr/FlattrUtils.java
@@ -1,3 +1,4 @@
// The files and modifications provided by Facebook are for testing and evaluation purposes only. Facebook reserves all rights not expressly granted.
package de.danoeh.antennapod.util.flattr;

import android.app.AlertDialog;
Expand Down Expand Up @@ -59,7 +60,7 @@ private static AccessToken retrieveToken() {
if (BuildConfig.DEBUG)
Log.d(TAG, "Retrieving access token");
String token = PreferenceManager.getDefaultSharedPreferences(
PodcastApp.getInstance())
PodcastApp.getAppContext())
.getString(PREF_ACCESS_TOKEN, null);
if (token != null) {
if (BuildConfig.DEBUG)
Expand All @@ -83,7 +84,7 @@ public static void storeToken(AccessToken token) {
if (BuildConfig.DEBUG)
Log.d(TAG, "Storing token");
SharedPreferences.Editor editor = PreferenceManager
.getDefaultSharedPreferences(PodcastApp.getInstance()).edit();
.getDefaultSharedPreferences(PodcastApp.getAppContext()).edit();
if (token != null) {
editor.putString(PREF_ACCESS_TOKEN, token.getToken());
} else {
Expand Down Expand Up @@ -271,4 +272,4 @@ public void onClick(DialogInterface dialog, int which) {
builder.create().show();
}

}
}

0 comments on commit 4250292

Please sign in to comment.