diff --git a/android/jni/Android.mk b/android/jni/Android.mk index ab8ad51523..4b0206d002 100644 --- a/android/jni/Android.mk +++ b/android/jni/Android.mk @@ -27,12 +27,12 @@ LOCAL_SRC_FILES := \ com/mapswithme/core/jni_helper.cpp \ com/mapswithme/core/logging.cpp \ com/mapswithme/core/render_context.cpp \ - com/mapswithme/maps/DownloadUI.cpp \ com/mapswithme/maps/Framework.cpp \ com/mapswithme/maps/VideoTimer.cpp \ com/mapswithme/maps/MWMActivity.cpp \ com/mapswithme/maps/MWMApplication.cpp \ com/mapswithme/maps/Lifecycle.cpp \ + com/mapswithme/maps/MapStorage.cpp \ com/mapswithme/maps/DownloadResourcesActivity.cpp \ com/mapswithme/platform/Platform.cpp \ com/mapswithme/platform/HttpThread.cpp \ diff --git a/android/jni/com/mapswithme/maps/DownloadUI.cpp b/android/jni/com/mapswithme/maps/DownloadUI.cpp deleted file mode 100644 index bee70f2e11..0000000000 --- a/android/jni/com/mapswithme/maps/DownloadUI.cpp +++ /dev/null @@ -1,125 +0,0 @@ -#include "../core/jni_helper.hpp" - -#include "Framework.hpp" -#include "DownloadUI.hpp" - -#include "../../../../../std/bind.hpp" - -android::DownloadUI * g_downloadUI = 0; - -namespace android -{ - DownloadUI::DownloadUI(jobject self) - { - JNIEnv * env = jni::GetEnv(); - m_self = env->NewGlobalRef(self); - - jclass k = env->GetObjectClass(m_self); - ASSERT(k, ("Can't get java class")); - m_onChangeCountry = env->GetMethodID(k, "onChangeCountry", "(III)V"); - ASSERT(m_onChangeCountry, ("Can't get onChangeCountry methodID")); - m_onProgress = env->GetMethodID(k, "onProgress", "(IIIJJ)V"); - ASSERT(m_onProgress, ("Can't get onProgress methodID")); - - ASSERT(!g_downloadUI, ("DownloadUI is initialized twice")); - g_downloadUI = this; - } - - DownloadUI::~DownloadUI() - { - g_downloadUI = 0; - jni::GetEnv()->DeleteGlobalRef(m_self); - } - - void DownloadUI::OnChangeCountry(storage::TIndex const & idx) - { - jni::GetEnv()->CallVoidMethod(m_self, m_onChangeCountry, idx.m_group, idx.m_country, idx.m_region); - } - - void DownloadUI::OnProgress(storage::TIndex const & idx, pair const & p) - { - jni::GetEnv()->CallVoidMethod(m_self, m_onProgress, idx.m_group, idx.m_country, idx.m_region, p.first, p.second); - } -} - -/////////////////////////////////////////////////////////////////////////////////// -// DownloadUI -/////////////////////////////////////////////////////////////////////////////////// - -extern "C" -{ - JNIEXPORT void JNICALL - Java_com_mapswithme_maps_DownloadUI_nativeCreate(JNIEnv * env, jobject thiz) - { - if (g_downloadUI) - { - /// activity has been killed without onDestroy, destroying manually - g_framework->Storage().Unsubscribe(); - delete g_downloadUI; - g_downloadUI = 0; - } - - g_downloadUI = new android::DownloadUI(thiz); - g_framework->Storage().Subscribe(bind(&android::DownloadUI::OnChangeCountry, g_downloadUI, _1), - bind(&android::DownloadUI::OnProgress, g_downloadUI, _1, _2)); - } - - JNIEXPORT void JNICALL - Java_com_mapswithme_maps_DownloadUI_nativeDestroy(JNIEnv * env, jobject thiz) - { - g_framework->Storage().Unsubscribe(); - delete g_downloadUI; - g_downloadUI = 0; - } - - JNIEXPORT jint JNICALL - Java_com_mapswithme_maps_DownloadUI_countriesCount(JNIEnv * env, jobject thiz, - jint group, jint country, jint region) - { - return static_cast(g_framework->Storage().CountriesCount(storage::TIndex(group, country, region))); - } - - JNIEXPORT jstring JNICALL - Java_com_mapswithme_maps_DownloadUI_countryName(JNIEnv * env, jobject thiz, - jint group, jint country, jint region) - { - string const name = g_framework->Storage().CountryName(storage::TIndex(group, country, region)); - return env->NewStringUTF(name.c_str()); - } - - JNIEXPORT jlong JNICALL - Java_com_mapswithme_maps_DownloadUI_countryLocalSizeInBytes(JNIEnv * env, jobject thiz, - jint group, jint country, jint region) - { - return g_framework->Storage().CountrySizeInBytes(storage::TIndex(group, country, region)).first; - } - - JNIEXPORT jlong JNICALL - Java_com_mapswithme_maps_DownloadUI_countryRemoteSizeInBytes(JNIEnv * env, jobject thiz, - jint group, jint country, jint region) - { - return g_framework->Storage().CountrySizeInBytes(storage::TIndex(group, country, region)).second; - } - - JNIEXPORT jint JNICALL - Java_com_mapswithme_maps_DownloadUI_countryStatus(JNIEnv * env, jobject thiz, - jint group, jint country, jint region) - { - return static_cast(g_framework->Storage().CountryStatus(storage::TIndex(group, country, region))); - } - - JNIEXPORT void JNICALL - Java_com_mapswithme_maps_DownloadUI_downloadCountry(JNIEnv * env, jobject thiz, - jint group, jint country, jint region) - { - g_framework->Storage().DownloadCountry(storage::TIndex(group, country, region)); - } - - JNIEXPORT void JNICALL - Java_com_mapswithme_maps_DownloadUI_deleteCountry(JNIEnv * env, jobject thiz, - jint group, jint country, jint region) - { - g_framework->Storage().DeleteCountry(storage::TIndex(group, country, region)); - } -} - diff --git a/android/jni/com/mapswithme/maps/DownloadUI.hpp b/android/jni/com/mapswithme/maps/DownloadUI.hpp deleted file mode 100644 index e94ed43533..0000000000 --- a/android/jni/com/mapswithme/maps/DownloadUI.hpp +++ /dev/null @@ -1,25 +0,0 @@ -#pragma once - -#include - -#include "../../../../../storage/storage.hpp" - -namespace android -{ - class DownloadUI - { - private: - jobject m_self; - - jmethodID m_onChangeCountry; - jmethodID m_onProgress; - - public: - - DownloadUI(jobject self); - ~DownloadUI(); - - void OnChangeCountry(storage::TIndex const & idx); - void OnProgress(storage::TIndex const & idx, pair const & p); - }; -} diff --git a/android/jni/com/mapswithme/maps/MapStorage.cpp b/android/jni/com/mapswithme/maps/MapStorage.cpp new file mode 100644 index 0000000000..ac811cd7fa --- /dev/null +++ b/android/jni/com/mapswithme/maps/MapStorage.cpp @@ -0,0 +1,158 @@ +/////////////////////////////////////////////////////////////////////////////////// +// DownloadUI +/////////////////////////////////////////////////////////////////////////////////// + +#include "Framework.hpp" +#include "../core/jni_helper.hpp" + +extern "C" +{ + class IndexBinding + { + private: + + shared_ptr m_self; + + jfieldID m_groupID; + jfieldID m_countryID; + jfieldID m_regionID; + + public: + + IndexBinding(jobject self) : m_self(jni::make_global_ref(self)) + { + jclass cls = jni::GetEnv()->GetObjectClass(*m_self.get()); + + m_groupID = jni::GetEnv()->GetFieldID(cls, "mGroup", "I"); + m_countryID = jni::GetEnv()->GetFieldID(cls, "mCountry", "I"); + m_regionID = jni::GetEnv()->GetFieldID(cls, "mRegion", "I"); + } + + int group() const + { + return jni::GetEnv()->GetIntField(*m_self.get(), m_groupID); + } + + int country() const + { + return jni::GetEnv()->GetIntField(*m_self.get(), m_groupID); + } + + int region() const + { + return jni::GetEnv()->GetIntField(*m_self.get(), m_groupID); + } + + storage::TIndex const toNative() const + { + return storage::TIndex(group(), country(), region()); + } + + static jobject toJava(storage::TIndex const & idx) + { + LOG(LINFO, ("constructing Java Index object from ", idx.m_group, idx.m_country, idx.m_region)); + + JNIEnv * env = jni::GetEnv(); + + jclass klass = env->FindClass("com/mapswithme/maps/MapStorage$Index"); + CHECK(klass, ("Can't find java class com/mapswithme/maps/MapStorage$Index")); + + jmethodID methodId = env->GetMethodID(klass, "", "(III)V"); + CHECK(methodId, ("Can't find java constructor in com/mapswithme/maps/MapStorage$Index")); + + return env->NewObject(klass, methodId, idx.m_group, idx.m_country, idx.m_region); + } + }; + + JNIEXPORT jint JNICALL + Java_com_mapswithme_maps_MapStorage_countriesCount(JNIEnv * env, jobject thiz, jobject idx) + { + return static_cast(g_framework->Storage().CountriesCount(IndexBinding(idx).toNative())); + } + + JNIEXPORT jstring JNICALL + Java_com_mapswithme_maps_MapStorage_countryName(JNIEnv * env, jobject thiz, jobject idx) + { + string const name = g_framework->Storage().CountryName(IndexBinding(idx).toNative()); + return env->NewStringUTF(name.c_str()); + } + + JNIEXPORT jlong JNICALL + Java_com_mapswithme_maps_MapStorage_countryLocalSizeInBytes(JNIEnv * env, jobject thiz, jobject idx) + { + return g_framework->Storage().CountrySizeInBytes(IndexBinding(idx).toNative()).first; + } + + JNIEXPORT jlong JNICALL + Java_com_mapswithme_maps_MapStorage_countryRemoteSizeInBytes(JNIEnv * env, jobject thiz, jobject idx) + { + return g_framework->Storage().CountrySizeInBytes(IndexBinding(idx).toNative()).second; + } + + JNIEXPORT jint JNICALL + Java_com_mapswithme_maps_MapStorage_countryStatus(JNIEnv * env, jobject thiz, jobject idx) + { + return static_cast(g_framework->Storage().CountryStatus(IndexBinding(idx).toNative())); + } + + JNIEXPORT void JNICALL + Java_com_mapswithme_maps_MapStorage_downloadCountry(JNIEnv * env, jobject thiz, jobject idx) + { + g_framework->Storage().DownloadCountry(IndexBinding(idx).toNative()); + } + + JNIEXPORT void JNICALL + Java_com_mapswithme_maps_MapStorage_deleteCountry(JNIEnv * env, jobject thiz, jobject idx) + { + g_framework->Storage().DeleteCountry(IndexBinding(idx).toNative()); + } + + JNIEXPORT jobject JNICALL + Java_com_mapswithme_maps_MapStorage_findIndexByName(JNIEnv * env, jobject thiz, jstring name) + { + char const * strCountry = env->GetStringUTFChars(name, 0); + + if (!strCountry) + return IndexBinding::toJava(storage::TIndex()); + + return IndexBinding::toJava(g_framework->Storage().FindIndexByName(strCountry)); + } + + void ReportChangeCountryStatus(shared_ptr const & obj, storage::TIndex const & idx) + { + JNIEnv * env = jni::GetEnv(); + + jclass klass = env->GetObjectClass(*obj.get()); + + jmethodID methodID = env->GetMethodID(klass, "onCountryStatusChanged", "(Lcom/mapswithme/maps/MapStorage$Index;)V"); + + env->CallVoidMethod(*obj.get(), methodID, IndexBinding::toJava(idx)); + } + + void ReportCountryProgress(shared_ptr const & obj, storage::TIndex const & idx, pair const & p) + { + JNIEnv * env = jni::GetEnv(); + jclass klass = env->GetObjectClass(*obj.get()); + + jmethodID methodID = env->GetMethodID(klass, "onCountryProgress", "(Lcom/mapswithme/maps/MapStorage$Index;JJ)V"); + + jlong current = p.first; + jlong total = p.second; + + env->CallVoidMethod(*obj.get(), methodID, IndexBinding::toJava(idx), current, total); + } + + JNIEXPORT jint JNICALL + Java_com_mapswithme_maps_MapStorage_subscribe(JNIEnv * env, jobject thiz, jobject obs) + { + jint res = g_framework->Storage().Subscribe(bind(&ReportChangeCountryStatus, jni::make_global_ref(obs), _1), + bind(&ReportCountryProgress, jni::make_global_ref(obs), _1, _2)); + return res; + } + + JNIEXPORT void JNICALL + Java_com_mapswithme_maps_MapStorage_unsubscribe(JNIEnv * env, jobject thiz, jint slotID) + { + g_framework->Storage().Unsubscribe(slotID); + } +} diff --git a/android/src/com/mapswithme/maps/DownloadUI.java b/android/src/com/mapswithme/maps/DownloadUI.java index f3d8298e4e..ed803a2e8a 100644 --- a/android/src/com/mapswithme/maps/DownloadUI.java +++ b/android/src/com/mapswithme/maps/DownloadUI.java @@ -15,21 +15,12 @@ import android.preference.PreferenceScreen; import android.provider.Settings; import android.util.Log; -public class DownloadUI extends PreferenceActivity +public class DownloadUI extends PreferenceActivity implements MapStorage.Listener { private static String TAG = "DownloadUI"; - private native int countriesCount(int group, int country, int region); - private native int countryStatus(int group, int country, int region); - private native long countryLocalSizeInBytes(int group, int country, int region); - private native long countryRemoteSizeInBytes(int group, int country, int region); - private native String countryName(int group, int country, int region); - private native void nativeCreate(); - private native void nativeDestroy(); - - private native void downloadCountry(int group, int country, int region); - private native void deleteCountry(int group, int country, int region); - + private int mSlotId = 0; + private AlertDialog.Builder m_alert; private DialogInterface.OnClickListener m_alertCancelHandler = new DialogInterface.OnClickListener() { public void onClick(DialogInterface dlg, int which) { dlg.dismiss(); } }; @@ -38,38 +29,45 @@ public class DownloadUI extends PreferenceActivity private String m_kb; private String m_mb; - static - { - // Used to avoid crash when ndk library is not loaded. - // We just "touch" MWMActivity which should load it automatically - MWMActivity.getCurrentContext(); - } - + private MapStorage mMapStorage; + @Override protected void onCreate(Bundle savedInstanceState) { + mMapStorage = MapStorage.getInstance(); + super.onCreate(savedInstanceState); m_kb = getString(R.string.kb); m_mb = getString(R.string.mb); PreferenceScreen root = getPreferenceManager().createPreferenceScreen(this); - setPreferenceScreen(createCountriesHierarchy(root, -1, -1, -1)); + setPreferenceScreen(createCountriesHierarchy(root, new MapStorage.Index())); m_alert = new AlertDialog.Builder(this); m_alert.setCancelable(true); - - nativeCreate(); } - + @Override - public void onDestroy() + protected void onResume() { - super.onDestroy(); - - nativeDestroy(); + super.onResume(); + + if (mSlotId == 0) + mSlotId = mMapStorage.subscribe(this); } - + + protected void onPause() + { + super.onPause(); + + if (mSlotId != 0) + { + mMapStorage.unsubscribe(mSlotId); + mSlotId = 0; + } + } + private String formatSizeString(long sizeInBytes) { if (sizeInBytes > 1024 * 1024) @@ -80,73 +78,73 @@ public class DownloadUI extends PreferenceActivity return (sizeInBytes + 1023) / 1024 + " " + m_kb; } - private void updateCountryCell(final Preference cell, int group, int country, int region) + private void updateCountryCell(final Preference cell, MapStorage.Index idx) { - final int status = countryStatus(group, country, region); + final int status = mMapStorage.countryStatus(idx); switch (status) { - case 0: // EOnDisk + case MapStorage.ON_DISK: cell.setSummary(getString(R.string.downloaded_touch_to_delete, - formatSizeString(countryLocalSizeInBytes(group, country, region)))); + formatSizeString(mMapStorage.countryLocalSizeInBytes(idx)))); cell.setLayoutResource(R.layout.country_on_disk); break; - case 1: // ENotDownloaded + case MapStorage.NOT_DOWNLOADED: cell.setSummary(getString(R.string.touch_to_download)); cell.setLayoutResource(R.layout.country_not_downloaded); break; - case 2: // EDownloadFailed + case MapStorage.DOWNLOAD_FAILED: cell.setSummary(getString(R.string.download_has_failed)); cell.setLayoutResource(R.layout.country_download_failed); break; - case 3: // EDownloading + case MapStorage.DOWNLOADING: cell.setSummary(getString(R.string.downloading)); cell.setLayoutResource(R.layout.country_downloading); break; - case 4: // EInQueue + case MapStorage.IN_QUEUE: cell.setSummary(getString(R.string.marked_for_downloading)); cell.setLayoutResource(R.layout.country_in_the_queue); break; - case 5: // EUnknown + case MapStorage.UNKNOWN: cell.setSummary("Unknown state :("); break; - case 6: // EGeneratingIndex + case MapStorage.GENERATING_INDEX: cell.setSummary("Indexing for search..."); cell.setLayoutResource(R.layout.country_generating_search_index); } } - public void onChangeCountry(int group, int country, int region) + public void onCountryStatusChanged(MapStorage.Index idx) { - final Preference cell = findPreference(group + " " + country + " " + region); + final Preference cell = findPreference(idx.mGroup + " " + idx.mCountry + " " + idx.mRegion); if (cell == null) { - Log.d(TAG, String.format("no preference found for %d %d %d", group, country, region)); + Log.d(TAG, String.format("no preference found for %d %d %d", idx.mGroup, idx.mCountry, idx.mRegion)); return; } - updateCountryCell(cell, group, country, region); + updateCountryCell(cell, idx); } - public void onProgress(int group, int country, int region, long current, long total) + public void onCountryProgress(MapStorage.Index idx, long current, long total) { - final Preference c = findPreference(group + " " + country + " " + region); + final Preference c = findPreference(idx.mGroup + " " + idx.mCountry + " " + idx.mRegion); if (c == null) - Log.d(TAG, String.format("no preference found for %d %d %d", group, country, region)); + Log.d(TAG, String.format("no preference found for %d %d %d", idx.mGroup, idx.mCountry, idx.mRegion)); else c.setSummary(getString(R.string.downloading_touch_to_cancel, current * 100 / total)); } - private Preference createElement(int group, int country, int region) + private Preference createElement(MapStorage.Index idx) { - final String name = countryName(group, country, region); - if (countriesCount(group, country, region) == 0) + final String name = mMapStorage.countryName(idx); + if (mMapStorage.countriesCount(idx) == 0) { // it's downloadable country element final Preference cell = new Preference(this); - cell.setKey(group + " " + country + " " + region); + cell.setKey(idx.mGroup + " " + idx.mCountry + " " + idx.mRegion); cell.setTitle(name); - updateCountryCell(cell, group, country, region); + updateCountryCell(cell, idx); return cell; } @@ -154,11 +152,11 @@ public class DownloadUI extends PreferenceActivity { // it's parent element for downloadable countries PreferenceScreen parent = getPreferenceManager().createPreferenceScreen(this); parent.setTitle(name); - return createCountriesHierarchy(parent, group, country, region); + return createCountriesHierarchy(parent, idx); } } - private PreferenceScreen createCountriesHierarchy(PreferenceScreen root, int group, int country, int region) + private PreferenceScreen createCountriesHierarchy(PreferenceScreen root, MapStorage.Index idx) { // Add "header" with "Map" and "Connection Settings" buttons final Preference cell = new Preference(this); @@ -168,15 +166,15 @@ public class DownloadUI extends PreferenceActivity cell.setLayoutResource(R.layout.downloader_header_map); root.addPreference(cell); - final int count = countriesCount(group, country, region); + final int count = mMapStorage.countriesCount(idx); for (int i = 0; i < count; ++i) { - if (group == -1) - root.addPreference(createElement(i, country, region)); - else if (country == -1) - root.addPreference(createElement(group, i, region)); - else if (region == -1) - root.addPreference(createElement(group, country, i)); + if (idx.mGroup == -1) + root.addPreference(createElement(new MapStorage.Index(i, idx.mCountry, idx.mRegion))); + else if (idx.mCountry == -1) + root.addPreference(createElement(new MapStorage.Index(idx.mGroup, i, idx.mRegion))); + else if (idx.mRegion == -1) + root.addPreference(createElement(new MapStorage.Index(idx.mGroup, idx.mCountry, i))); } return root; } @@ -208,13 +206,13 @@ public class DownloadUI extends PreferenceActivity final int country = Integer.parseInt(keys[1]); final int region = Integer.parseInt(keys[2]); - switch (countryStatus(group, country, region)) + switch (mMapStorage.countryStatus(new MapStorage.Index(group, country, region))) { - case 0: // EOnDisk - m_alert.setTitle(countryName(group, country, region)); + case MapStorage.ON_DISK: + m_alert.setTitle(mMapStorage.countryName(new MapStorage.Index(group, country, region))); m_alert.setPositiveButton(R.string.delete, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dlg, int which) { - deleteCountry(group, country, region); + mMapStorage.deleteCountry(new MapStorage.Index(group, country, region)); dlg.dismiss(); } }); @@ -222,10 +220,10 @@ public class DownloadUI extends PreferenceActivity m_alert.create().show(); break; - case 1: // ENotDownloaded + case MapStorage.NOT_DOWNLOADED: // Check for available free space - final long size = countryRemoteSizeInBytes(group, country, region); - final String name = countryName(group, country, region); + final long size = mMapStorage.countryRemoteSizeInBytes(new MapStorage.Index(group, country, region)); + final String name = mMapStorage.countryName(new MapStorage.Index(group, country, region)); if (size > getFreeSpace()) { showNotEnoughFreeSpaceDialog(formatSizeString(size), name); @@ -237,7 +235,7 @@ public class DownloadUI extends PreferenceActivity m_alert.setPositiveButton(getString(R.string.download_mb_or_kb, formatSizeString(size)), new DialogInterface.OnClickListener() { public void onClick(DialogInterface dlg, int which) { - downloadCountry(group, country, region); + mMapStorage.downloadCountry(new MapStorage.Index(group, country, region)); dlg.dismiss(); } }); @@ -246,17 +244,17 @@ public class DownloadUI extends PreferenceActivity } break; - case 2: // EDownloadFailed + case MapStorage.DOWNLOAD_FAILED: // Do not confirm download if status is failed, just start it - downloadCountry(group, country, region); + mMapStorage.downloadCountry(new MapStorage.Index(group, country, region)); break; - case 3: // EDownloading + case MapStorage.DOWNLOADING: /// Confirm canceling - m_alert.setTitle(countryName(group, country, region)); + m_alert.setTitle(mMapStorage.countryName(new MapStorage.Index(group, country, region))); m_alert.setPositiveButton(R.string.cancel_download, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dlg, int which) { - deleteCountry(group, country, region); + mMapStorage.deleteCountry(new MapStorage.Index(group, country, region)); dlg.dismiss(); } }); @@ -264,12 +262,12 @@ public class DownloadUI extends PreferenceActivity m_alert.create().show(); break; - case 4: // EInQueue + case MapStorage.IN_QUEUE: // Silently discard country from the queue - deleteCountry(group, country, region); + mMapStorage.deleteCountry(new MapStorage.Index(group, country, region)); break; - case 5: // EUnknown + case MapStorage.UNKNOWN: Log.d(TAG, "Unknown country state"); break; } diff --git a/android/src/com/mapswithme/maps/MapStorage.java b/android/src/com/mapswithme/maps/MapStorage.java new file mode 100644 index 0000000000..b5d8b4e3f4 --- /dev/null +++ b/android/src/com/mapswithme/maps/MapStorage.java @@ -0,0 +1,70 @@ +package com.mapswithme.maps; + +public class MapStorage +{ + public static final int ON_DISK = 0; + public static final int NOT_DOWNLOADED = 1; + public static final int DOWNLOAD_FAILED = 2; + public static final int DOWNLOADING = 3; + public static final int IN_QUEUE = 4; + public static final int UNKNOWN = 5; + public static final int GENERATING_INDEX = 6; + + public interface Listener + { + public void onCountryStatusChanged(Index idx); + public void onCountryProgress(Index idx, long current, long total); + }; + + public static class Index + { + int mGroup; + int mCountry; + int mRegion; + + public Index() + { + mGroup = -1; + mCountry = -1; + mRegion = -1; + } + + public Index(int group, int country, int region) + { + mGroup = group; + mCountry = country; + mRegion = region; + } + + public boolean isValid() + { + return !((mGroup == -1) && (mCountry == -1) && (mRegion == -1)); + } + } + + public native int countriesCount(Index idx); + public native int countryStatus(Index idx); + public native long countryLocalSizeInBytes(Index idx); + public native long countryRemoteSizeInBytes(Index idx); + public native String countryName(Index idx); + + public native void downloadCountry(Index idx); + public native void deleteCountry(Index idx); + public native Index findIndexByName(String name); + + private MapStorage() + {} + + private static MapStorage mInstance = null; + + public static MapStorage getInstance() + { + if (mInstance == null) + mInstance = new MapStorage(); + + return mInstance; + } + + public native int subscribe(Listener l); + public native void unsubscribe(int slotId); +} diff --git a/storage/storage.cpp b/storage/storage.cpp index 1ff85d3cdb..2a08f057cb 100644 --- a/storage/storage.cpp +++ b/storage/storage.cpp @@ -327,7 +327,7 @@ namespace storage obs.m_changeCountryFn = change; obs.m_progressFn = progress; - obs.m_slotId = m_currentSlotId++; + obs.m_slotId = ++m_currentSlotId; m_observers.push_back(obs); @@ -492,10 +492,22 @@ namespace storage TIndex const Storage::FindIndexByName(string const & name) const { for (unsigned i = 0; i < m_countries.SiblingsCount(); ++i) + { + if (m_countries[i].Value().Name() == name) + return TIndex(i); + for (unsigned j = 0; j < m_countries[i].SiblingsCount(); ++j) + { + if (m_countries[i][j].Value().Name() == name) + return TIndex(i, j); + for (unsigned k = 0; k < m_countries[i][j].SiblingsCount(); ++k) + { if (m_countries[i][j][k].Value().Name() == name) return TIndex(i, j, k); + } + } + } return TIndex(); }