Merge pull request #12 from deathbaba/obb-first-file-in-dir
[and] Use first found .obb.
This commit is contained in:
commit
23ed9fea3e
4 changed files with 23 additions and 29 deletions
|
@ -1,6 +1,5 @@
|
|||
package com.example.travelguide;
|
||||
|
||||
import static com.example.travelguide.util.Expansion.DATA_FILE;
|
||||
import android.app.Activity;
|
||||
import android.app.PendingIntent;
|
||||
import android.content.Intent;
|
||||
|
@ -14,6 +13,7 @@ import android.widget.ProgressBar;
|
|||
import android.widget.TextView;
|
||||
|
||||
import com.example.travelguide.expansion.ExpansionService;
|
||||
import com.example.travelguide.util.Expansion;
|
||||
import com.example.travelguide.util.Utils;
|
||||
import com.google.android.vending.expansion.downloader.DownloadProgressInfo;
|
||||
import com.google.android.vending.expansion.downloader.DownloaderClientMarshaller;
|
||||
|
@ -109,10 +109,7 @@ public class ExpansionActivity extends Activity
|
|||
|
||||
private boolean expansionFilesDelivered()
|
||||
{
|
||||
final String fileName = Helpers.getExpansionAPKFileName(this, DATA_FILE.isMain, DATA_FILE.versionCode);
|
||||
if (!Helpers.doesFileExist(this, fileName, DATA_FILE.fileSize, false))
|
||||
return false;
|
||||
return true;
|
||||
return Expansion.findFirstObbFile(getPackageName()) != null;
|
||||
}
|
||||
|
||||
private PendingIntent createNotificationIntent()
|
||||
|
|
|
@ -19,7 +19,7 @@ public class ObbPathFinder extends OnObbStateChangeListener
|
|||
{
|
||||
mContext = context;
|
||||
mSm = (StorageManager) mContext.getSystemService(Context.STORAGE_SERVICE);
|
||||
mSm.mountObb(Expansion.getPath(), null, this);
|
||||
mSm.mountObb(Expansion.getPath(mContext.getPackageName()), null, this);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -30,7 +30,7 @@ public class ObbPathFinder extends OnObbStateChangeListener
|
|||
|
||||
public String getRootDir()
|
||||
{
|
||||
return "file://" + mSm.getMountedObbPath(Expansion.getPath()) + "/data/";
|
||||
return "file://" + mSm.getMountedObbPath(Expansion.getPath(mContext.getPackageName())) + "/data/";
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -35,7 +35,7 @@ public class ObbThumbnailProvider extends OnObbStateChangeListener implements Th
|
|||
{
|
||||
mContext = context;
|
||||
mSm = (StorageManager) mContext.getSystemService(Context.STORAGE_SERVICE);
|
||||
mSm.mountObb(Expansion.getPath(), null, this);
|
||||
mSm.mountObb(Expansion.getPath(mContext.getPackageName()), null, this);
|
||||
}
|
||||
|
||||
public ObbThumbnailProvider(Context context, MountStateChangedListener listener)
|
||||
|
@ -57,7 +57,7 @@ public class ObbThumbnailProvider extends OnObbStateChangeListener implements Th
|
|||
@Override
|
||||
public Drawable getThumbnailByUrl(String url)
|
||||
{
|
||||
final String pathInObb = mSm.getMountedObbPath(Expansion.getPath()) + "/data/thumb/" + url;
|
||||
final String pathInObb = mSm.getMountedObbPath(Expansion.getPath(mContext.getPackageName())) + "/data/thumb/" + url;
|
||||
return BitmapDrawable.createFromPath(pathInObb);
|
||||
}
|
||||
|
||||
|
|
|
@ -6,27 +6,9 @@ import android.os.Environment;
|
|||
|
||||
public class Expansion
|
||||
{
|
||||
public static final String PACKAGE = "com.susanin.travelguide";
|
||||
|
||||
public static final XAPKFile DATA_FILE = new XAPKFile(true, 1, 251904055);
|
||||
|
||||
public static class XAPKFile
|
||||
public static String getPath(String packageName)
|
||||
{
|
||||
public final boolean isMain;
|
||||
public final int versionCode;
|
||||
public final long fileSize;
|
||||
|
||||
public XAPKFile(boolean isMain, int versionCode, long fileSizeInBytes)
|
||||
{
|
||||
this.isMain = isMain;
|
||||
this.versionCode = versionCode;
|
||||
this.fileSize = fileSizeInBytes;
|
||||
}
|
||||
}
|
||||
|
||||
public static String getPath()
|
||||
{
|
||||
return Expansion.getMainObbPath(String.valueOf(DATA_FILE.versionCode), PACKAGE);
|
||||
return findFirstObbFile(packageName);
|
||||
}
|
||||
|
||||
public static String getMainObbFileName(String version, String packageName)
|
||||
|
@ -51,5 +33,20 @@ public class Expansion
|
|||
return mainObbPath;
|
||||
}
|
||||
|
||||
public static String findFirstObbFile(String packageName)
|
||||
{
|
||||
final File obbDir = new File(getObbLocation(packageName));
|
||||
if (obbDir.list() == null)
|
||||
return null;
|
||||
|
||||
for (final String filePath : obbDir.list())
|
||||
{
|
||||
if (filePath.endsWith(".obb"))
|
||||
return obbDir.getAbsolutePath() + File.separator + filePath;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private Expansion() {}
|
||||
}
|
||||
|
|
Reference in a new issue