Esri / mapbook-android

App to replace paper maps for field work
Apache License 2.0
12 stars 13 forks source link

Determine strategy for using string resources in presenters #14

Open zinfin opened 7 years ago

zinfin commented 7 years ago
  @Override final public void checkForMapbook() {

    mPath = mFileManager.fileExists();
    if (mPath != null){

      loadMapbook(new DataManagerCallbacks.MapbookCallback() {
        /**
         * If successfully loaded, populate view
         * @param mobileMapPackage - MobileMapPackage
         */
        @Override final public void onMapbookLoaded(final MobileMapPackage mobileMapPackage) {
          final List<ArcGISMap> maps = mobileMapPackage.getMaps();
          mView.setMaps(maps);
          final Item item = mobileMapPackage.getItem();
          mView.populateMapbookLayout(item);

          // Get the file size and date
          final long mapbookSize = mFileManager.getSize();
          final long mapbookModified = mFileManager.getModifiedDate();

          mView.setMapbookMetatdata(mapbookSize, mapbookModified, maps.size());

          final byte[] thumbnailData = item.getThumbnailData();
          if (thumbnailData != null && thumbnailData.length > 0) {
            mView.setThumbnailBitmap(thumbnailData);
          }else{
            final ListenableFuture<byte[]> futureThumbnail = item.fetchThumbnailAsync();
            futureThumbnail.addDoneListener(new Runnable() {
              @Override public void run() {
                try {
                  final byte[] itemThumbnailData = futureThumbnail.get();
                  mView.setThumbnailBitmap(itemThumbnailData);
                } catch (final Exception e) {
                  Log.e(TAG,e.getMessage());
                  mView.showMessage("There were problems obtaining thumbnail images for maps in mapbook.");
                }
              }
            });
          }
        }

        /**
         * If the mapbook fails to load, show a message
         * @param error - Throwable
         */
        @Override final public void onMapbookNotLoaded(final Throwable error) {
          Log.e(TAG, "Problem loading map book " + error.getMessage());
          mView.showMapbookNotFound();
          mView.showMessage("There was a problem loading the mapbook");
        }
      });

Was thinking the presenter can determine which string resource to provide and the view handles loading the resource. Have to think about this a bit more so we can handle this through a separate issue if we want to dig deeper.

zinfin commented 6 years ago

See these links for inspiration on Context and MVP: https://stackoverflow.com/questions/34303510/does-the-presenter-having-knowledge-of-the-activity-context-a-bad-idea-in-the?noredirect=1&lq=1 https://stackoverflow.com/questions/39100105/need-context-in-model-in-mvp