Android Open Source - GalDroid Entity






From Project

Back to project page GalDroid.

License

The source code is released under:

GNU General Public License

If you think the Android project GalDroid listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

/*
 * GalDroid - a webgallery frontend for android
 * Copyright (C) 2011  Raptor 2101 [raptor2101@gmx.de]
 *    // www .  ja v  a 2  s.c  o m
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.

 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.

 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.  
 */

package de.raptor2101.GalDroid.WebGallery.Gallery3.JSON;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import de.raptor2101.GalDroid.WebGallery.Gallery3.DownloadObject;
import de.raptor2101.GalDroid.WebGallery.Gallery3.Gallery3Imp;
import de.raptor2101.GalDroid.WebGallery.Interfaces.GalleryObject;
import de.raptor2101.GalDroid.WebGallery.Interfaces.GalleryDownloadObject;

public abstract class Entity implements GalleryObject {
  private static final long serialVersionUID = 632836774464520503L;
  
  private final Pattern mPatternExtractTagId = Pattern.compile("tag_item/(\\d+),\\d+");
  private final String mRootLink;
  private final String mTitle;
  private final String mLink;
  private final int mId;

  private final Date mUploadDate;
  private final ArrayList<String> mTags;
  protected String mLink_Full;
  protected String mLink_Thumb;

  protected int mFileSize_Full;
  protected int mFileSize_Thumb;

  public Entity(JSONObject jsonObject, Gallery3Imp gallery3) throws JSONException {
    JSONObject entity = jsonObject.getJSONObject("entity");

    mId = entity.getInt("id");

    long msElapsed = entity.getLong("created") * 1000;
    mUploadDate = new Date(msElapsed);

    mTitle = entity.getString("title");
    mLink = gallery3.getItemLink(mId);
    mRootLink = gallery3.getRootLink();

    JSONObject relationShips = jsonObject.getJSONObject("relationships");
    JSONObject tagsSection = relationShips.getJSONObject("tags");
    JSONArray tags = tagsSection.getJSONArray("members");

    mTags = new ArrayList<String>(tags.length());
    for (int i = 0; i < tags.length(); i++) {
      Matcher matcher = mPatternExtractTagId.matcher(tags.getString(i));
      while (matcher.find()) {
        String tagId = matcher.group(1);
        mTags.add(String.format(gallery3.LinkRest_LoadTag, tagId));
      }
    }
  }

  public String getTitle() {
    return mTitle;
  }

  public int getId() {
    return mId;
  }

  public String getObjectId() {
    return String.format("%s/%d", mRootLink, mId);
  }

  public String getObjectLink() {
    return mLink;
  }

  public Date getDateUploaded() {
    return mUploadDate;
  }

  public GalleryDownloadObject getImage() {
    return createDownloadObject(mLink_Full, mFileSize_Full);
  }

  public GalleryDownloadObject getThumbnail() {
    return createDownloadObject(mLink_Thumb, mFileSize_Thumb);
  }

  private GalleryDownloadObject createDownloadObject(String link, int fileSize) {
    return !link.equals("") ? new DownloadObject(mRootLink, link, fileSize) : null;
  }

  public List<String> getTagLinks() {
    return mTags;
  }

  @Override
  public String toString() {
    return mLink;
  }

  @Override
  public boolean equals(Object o) {
    if (o instanceof Entity) {
      Entity entity = (Entity) o;
      return entity.mId == mId;
    } else {
      return false;
    }
  }
}




Java Source Code List

de.raptor2101.GalDroid.Activities.EditGalleryActivity.java
de.raptor2101.GalDroid.Activities.GalDroidApp.java
de.raptor2101.GalDroid.Activities.GalleryActivity.java
de.raptor2101.GalDroid.Activities.GalleryListingActivitiy.java
de.raptor2101.GalDroid.Activities.GridViewActivity.java
de.raptor2101.GalDroid.Activities.ImageViewActivity.java
de.raptor2101.GalDroid.Activities.Helpers.ActionBarHider.java
de.raptor2101.GalDroid.Activities.Helpers.ImageAdapter.java
de.raptor2101.GalDroid.Activities.Listeners.ImageViewOnTouchListener.java
de.raptor2101.GalDroid.Activities.Views.GalleryImageViewListener.java
de.raptor2101.GalDroid.Activities.Views.GalleryImageView.java
de.raptor2101.GalDroid.Activities.Views.ImageInformationView.java
de.raptor2101.GalDroid.Config.GalDroidPreference.java
de.raptor2101.GalDroid.Config.GalleryConfig.java
de.raptor2101.GalDroid.WebGallery.DegMinSec.java
de.raptor2101.GalDroid.WebGallery.GalleryFactory.java
de.raptor2101.GalDroid.WebGallery.ImageCache.java
de.raptor2101.GalDroid.WebGallery.ImageInformation.java
de.raptor2101.GalDroid.WebGallery.Stream.java
de.raptor2101.GalDroid.WebGallery.TitleConfig.java
de.raptor2101.GalDroid.WebGallery.Gallery3.DownloadObject.java
de.raptor2101.GalDroid.WebGallery.Gallery3.Gallery3Imp.java
de.raptor2101.GalDroid.WebGallery.Gallery3.ProgressListener.java
de.raptor2101.GalDroid.WebGallery.Gallery3.RestCall.java
de.raptor2101.GalDroid.WebGallery.Gallery3.JSON.AlbumEntity.java
de.raptor2101.GalDroid.WebGallery.Gallery3.JSON.CommentEntity.java
de.raptor2101.GalDroid.WebGallery.Gallery3.JSON.EntityFactory.java
de.raptor2101.GalDroid.WebGallery.Gallery3.JSON.Entity.java
de.raptor2101.GalDroid.WebGallery.Gallery3.JSON.PictureEntity.java
de.raptor2101.GalDroid.WebGallery.Gallery3.Tasks.JSONArrayLoaderTask.java
de.raptor2101.GalDroid.WebGallery.Interfaces.GalleryDownloadObject.java
de.raptor2101.GalDroid.WebGallery.Interfaces.GalleryObjectComment.java
de.raptor2101.GalDroid.WebGallery.Interfaces.GalleryObject.java
de.raptor2101.GalDroid.WebGallery.Interfaces.GalleryProgressListener.java
de.raptor2101.GalDroid.WebGallery.Interfaces.WebGallery.java
de.raptor2101.GalDroid.WebGallery.Tasks.CacheTaskListener.java
de.raptor2101.GalDroid.WebGallery.Tasks.CleanUpCacheTask.java
de.raptor2101.GalDroid.WebGallery.Tasks.GalleryLoaderTaskListener.java
de.raptor2101.GalDroid.WebGallery.Tasks.GalleryLoaderTask.java
de.raptor2101.GalDroid.WebGallery.Tasks.GalleryVerifyTask.java
de.raptor2101.GalDroid.WebGallery.Tasks.ImageInformationLoaderTaskListener.java
de.raptor2101.GalDroid.WebGallery.Tasks.ImageInformationLoaderTask.java
de.raptor2101.GalDroid.WebGallery.Tasks.ImageLoaderTaskListener.java
de.raptor2101.GalDroid.WebGallery.Tasks.ImageLoaderTask.java
de.raptor2101.GalDroid.WebGallery.Tasks.Progress.java
de.raptor2101.GalDroid.WebGallery.Tasks.RepeatingTask.java
de.raptor2101.GalDroid.WebGallery.Tasks.SyncronizeCacheTask.java
de.raptor2101.GalDroid.WebGallery.Tasks.TaskInterface.java