From 6825b9e4824ac2febd0d77cb4952707a18fbc154 Mon Sep 17 00:00:00 2001 From: vng Date: Sun, 10 Jun 2012 15:28:45 -0700 Subject: [PATCH] [android] Check files to download in sdcard and in apk. Minor changes. --- .../maps/DownloadResourcesActivity.cpp | 37 +++++++++---------- .../jni/com/mapswithme/maps/MWMActivity.cpp | 4 +- .../src/com/mapswithme/maps/MWMActivity.java | 16 ++++---- 3 files changed, 27 insertions(+), 30 deletions(-) diff --git a/android/jni/com/mapswithme/maps/DownloadResourcesActivity.cpp b/android/jni/com/mapswithme/maps/DownloadResourcesActivity.cpp index 057b802773..322a494e37 100644 --- a/android/jni/com/mapswithme/maps/DownloadResourcesActivity.cpp +++ b/android/jni/com/mapswithme/maps/DownloadResourcesActivity.cpp @@ -44,8 +44,8 @@ struct FileToDownload uint64_t m_fileSize; }; -static string g_apkPath; -static string g_sdcardPath; +//static string g_apkPath; +//static string g_sdcardPath; static vector g_filesToDownload; static int g_totalDownloadedBytes; static int g_totalBytesToDownload; @@ -53,11 +53,11 @@ static shared_ptr g_currentRequest; extern "C" { - int HasSpaceForFiles(size_t fileSize) + int HasSpaceForFiles(string const & sdcardPath, size_t fileSize) { struct statfs st; - if (statfs(g_sdcardPath.c_str(), &st) != 0) + if (statfs(sdcardPath.c_str(), &st) != 0) return ERR_STORAGE_DISCONNECTED; if (st.f_bsize * st.f_bavail <= fileSize) @@ -70,12 +70,13 @@ extern "C" Java_com_mapswithme_maps_DownloadResourcesActivity_getBytesToDownload(JNIEnv * env, jobject thiz, jstring apkPath, jstring sdcardPath) { - g_apkPath = jni::ToNativeString(apkPath); - g_sdcardPath = jni::ToNativeString(sdcardPath); + //g_apkPath = jni::ToNativeString(apkPath); + string const path = jni::ToNativeString(sdcardPath); - jint totalBytesToDownload = 0; + int totalBytesToDownload = 0; - ReaderStreamBuf buffer(GetPlatform().GetReader("external_resources.txt")); + Platform & pl = GetPlatform(); + ReaderStreamBuf buffer(pl.GetReader("external_resources.txt")); istream in(&buffer); @@ -94,18 +95,16 @@ extern "C" if (!in.good()) break; - FileToDownload f; - - f.m_pathOnSdcard = g_sdcardPath + name; - f.m_fileName = name; - - uint64_t sizeOnSdcard = 0; - Platform::GetFileSizeByFullPath(f.m_pathOnSdcard, sizeOnSdcard); - - if (size != sizeOnSdcard) + uint64_t originSize = 0; + if (!pl.GetFileSizeByName(name, originSize) || size != originSize) { - LOG(LDEBUG, ("should download : ", name, "sized", size, "bytes")); + LOG(LDEBUG, ("Should download", name, "sized", size, "bytes")); + + FileToDownload f; + f.m_pathOnSdcard = path + name; + f.m_fileName = name; f.m_fileSize = size; + g_filesToDownload.push_back(f); totalBytesToDownload += size; } @@ -113,7 +112,7 @@ extern "C" g_totalDownloadedBytes = 0; - int res = HasSpaceForFiles(totalBytesToDownload); + int res = HasSpaceForFiles(path, totalBytesToDownload); switch (res) { diff --git a/android/jni/com/mapswithme/maps/MWMActivity.cpp b/android/jni/com/mapswithme/maps/MWMActivity.cpp index 1449134fe9..d3e92bcc45 100644 --- a/android/jni/com/mapswithme/maps/MWMActivity.cpp +++ b/android/jni/com/mapswithme/maps/MWMActivity.cpp @@ -135,7 +135,7 @@ extern "C" void OnProVersionServerReply(downloader::HttpRequest & r, shared_ptr obj) { - uint64_t curTime = time(0); + uint64_t const curTime = time(0); if (r.Status() == downloader::HttpRequest::ECompleted) { @@ -155,8 +155,6 @@ extern "C" jmethodID methodID = jni::GetJavaMethodID(env, *obj.get(), "onProVersionAvailable", "()V"); env->CallVoidMethod(*obj.get(), methodID); - - return; } else LOG(LDEBUG, ("ProVersion is not available, checkTime=", curTime)); diff --git a/android/src/com/mapswithme/maps/MWMActivity.java b/android/src/com/mapswithme/maps/MWMActivity.java index d0ca2c3a02..d30fad3202 100644 --- a/android/src/com/mapswithme/maps/MWMActivity.java +++ b/android/src/com/mapswithme/maps/MWMActivity.java @@ -201,17 +201,19 @@ public class MWMActivity extends NvEventQueueActivity implements LocationService void checkProVersionAvailable() { - if (nativeIsProVersion() || (nativeGetProVersionURL().length() != 0)) + final boolean isPro = nativeIsProVersion(); + // get pro-version url only for lite-version + final String url = isPro ? "" : nativeGetProVersionURL(); + + if (isPro || (url.length() != 0)) findViewById(R.id.map_button_search).setVisibility(View.VISIBLE); - if (!nativeIsProVersion() && (nativeGetProVersionURL().length() == 0)) + if (!isPro && (url.length() == 0)) { - String commonServerURL = "http://redbutton.mapswithme.com/enable_search_banner_google_play"; - String kindleServerURL = "http://redbutton.mapswithme.com/enable_search_banner_amazon_appstore"; if (android.os.Build.MODEL.equals("Kindle Fire")) - nativeCheckForProVersion(kindleServerURL); + nativeCheckForProVersion("http://redbutton.mapswithme.com/enable_search_banner_amazon_appstore"); else - nativeCheckForProVersion(commonServerURL); + nativeCheckForProVersion("http://redbutton.mapswithme.com/enable_search_banner_google_play"); } } @@ -225,8 +227,6 @@ public class MWMActivity extends NvEventQueueActivity implements LocationService { AlertDialog alert = new AlertDialog.Builder(getCurrentContext()).create(); - final Activity a = this; - alert.setMessage(message); alert.setCancelable(false);