This question is answered. Helpful answers available: 2. Correct answers available: 1.


Permlink Replies: 21 - Pages: 2 [ 1 2 | Next ] - Last Post: 23 Mar 22, 00:04 Last Post By: RobM Threads: [ Previous | Next ]
RobM

Posts: 4,383
Registered: 4-Aug-2006
AlbumObjects and isIncluded()
Posted: 19 Mar 22, 00:46
 
  Click to reply to this thread Reply
In init.bsh I do a for AlbumObject loop, starting at the root, within a for AlbumObject loop.

Within the second loop I create an AlbumObject instance of an object in the first loop.
In the first loop it reports excluded items as excluded, but in the inner loop it reports them as included.

Am I pushing the bounds too far or is it a bug?

This is to synchronise the included status of base and additional objects, currently I just sync include/use original states.

Cut down code
//First loop
for(AlbumObject ao: folder.getChildren()) {
  if(ao.isFolder()) {
    File extrasFile = new File(folder.getFile(), extraDirName);
    AlbumObject extrasFolder = rootFolder.getFactory().createInstance(extrasFile);
    //Second loop
    for(AlbumObject extraObject: extrasFolder.getChildren()) {
      String basePath = ao.getFile().getParentFile() + File.separator + extraObject;
      File baseFile = new File(basePath);
      AlbumObject baseObject = rootFolder.getFactory().createInstance(baseFile);
      //baseObject.isIncluded() = true
    }
  }
  else { //first loop again
  //actual baseObject.isIncluded() = false
}


Full code
checkExtras(AlbumObject folder) {
	for(AlbumObject ao: folder.getChildren()) {
		if(ao.isFolder()) {
			if(ao.getName().equals(extraDirName)) {
				File extrasFile = new File(folder.getFile(), extraDirName);
				boolean extraExists = false;
				String thisObject;		
				if(extrasFile.exists() && ao.getName().equals(extraDirName)) {
					// Make the extras folder an AlbumObject
					AlbumObject extrasFolder = rootFolder.getFactory().createInstance(extrasFile);
					//Loop through the extras folder
					for(AlbumObject extraObject: extrasFolder.getChildren()) {
						//Do we have an object of the same name as the current object
						String basePath = ao.getFile().getParentFile() + File.separator + extraObject;
						File baseFile = new File(basePath);
						if(baseFile.exists()) {
							AlbumObject baseObject = rootFolder.getFactory().createInstance(baseFile);
							System.out.println("baseObject " + baseObject + " and " + extraObject.isIncluded());
						}
					}
				}
			}
			else {
				checkExtras(ao);
			}		
		}
		else {
			System.out.println("ao " + ao + " " + ao.isIncluded());
		}
	}
}
 
checkExtras(rootFolder);
RobM

Posts: 4,383
Registered: 4-Aug-2006
Re: AlbumObjects and isIncluded()
Posted: 19 Mar 22, 20:41   in response to: RobM in response to: RobM
 
  Click to reply to this thread Reply
I've come to the conclusion that AlbumObject ao = rootFolder.getFactory().createInstance(aoFile);
is creating a new instance, which has properties like title, comment etc. but not the included status of the original object.

I guess that means making a list/map of objects and then getting the included status from the list/map. A lot more work and processing though.
RobM

Posts: 4,383
Registered: 4-Aug-2006
Re: AlbumObjects and isIncluded()
Posted: 20 Mar 22, 00:42   in response to: RobM in response to: RobM
 
  Click to reply to this thread Reply
Changed code to map the extra objects and then synchronise the mapped objects to the primary object
davidekholm

Posts: 4,407
Registered: 18-Oct-2002
Re: AlbumObjects and isIncluded()
Posted: 21 Mar 22, 13:45   in response to: RobM in response to: RobM
 
  Click to reply to this thread Reply
I don't understand the objective of that code. Could you please explain it in pure English. Make no assumptions. Try to explain it to me like you would to someone without much jAlbum knowledge.
RobM

Posts: 4,383
Registered: 4-Aug-2006
Re: AlbumObjects and isIncluded()
Posted: 21 Mar 22, 14:43   in response to: davidekholm in response to: davidekholm
 
  Click to reply to this thread Reply
Missive skin supports alternative images by letting the user add a named folder. For any folder that has images needing an alternative the user adds a folder of that name, say extras. Within that folder the user adds images with the same filename as the primary image.

Now, in init.bsh I hide any folder that has the name ‘extras’, that stops the extra images appearing in the album via normal navigation. The next step is to make the extra images match the primary for the object’s isIncludeOriginal, isUseOriginal and isIncluded. This is so when switching images the image linking of the extra is the same as the primary, and if the image is needed or not.

To synchronise those properties I loop through the extras folder and for every object I create a new instance of the primary image. The new instance has the properties for isIncludeOriginal and isUseOriginal, but not for its isIncluded status. What would make it easier is if when creating a new AlbumObject instance of an object you could decide to include its isIncluded status or not.

I have got round the issue by mapping primary objects that have an extra image, then getting the isIncluded status from the mapped object.

Hope that makes it clearer.
davidekholm

Posts: 4,407
Registered: 18-Oct-2002
Re: AlbumObjects and isIncluded()
Posted: 21 Mar 22, 15:13   in response to: RobM in response to: RobM
 
  Click to reply to this thread Reply
But why do you create new instances of AlbumObjects at all?
Even if isIncluded() is implemented differently (using albumfiles.txt instead of .info files), the API is the same: Just call setIncluded(), setIncludeOriginal() etc.

To look up a corresponding "primary" object given an object under "extras", simply refer to the parent folder and call the getChild method, passing the name of the "extra" image as argument.
davidekholm

Posts: 4,407
Registered: 18-Oct-2002
Re: AlbumObjects and isIncluded()
Posted: 21 Mar 22, 15:19   in response to: davidekholm in response to: davidekholm
 
  Click to reply to this thread Reply
I also want to comment that the "rootFolder" variable you have access to during album builds refers to a temporary AlbumObject tree. If you make changes via it, I'm not 100% sure they propagate to the corresponding main AlbumObject tree the Explorer is using. To ensure that this happens, you might need to call invalidate() on the corresponding "extras" folder of the original AlbumObject tree. You can reach the original tree via context.getExplorer().getRootFolder().
JeffTucker

Posts: 8,467
Registered: 31-Jan-2006
Re: AlbumObjects and isIncluded()
Posted: 21 Mar 22, 15:31   in response to: RobM in response to: RobM
 
  Click to reply to this thread Reply
ctwist wrote:
In init.bsh, it would be better to hide the images in the extras folder instead of excluding them.

Doesn't that still leave him with a problem? Say the main sparky.jpg image is tagged as Use original, but none of the other images is. What does that mean for extras/sparky.jpg? Maybe it's incumbent upon the user to choose those options for each extra image, and not expect the skin to do that for him. What if the user wants the original of sparky.jpg, but wants to use the jAlbum-generated slide image for extras/sparky.jpg? That would mitigate against cloning the settings for the AO's to the extras.

Just thinking out loud....
JeffTucker

Posts: 8,467
Registered: 31-Jan-2006
Re: AlbumObjects and isIncluded()
Posted: 21 Mar 22, 15:47   in response to: RobM in response to: RobM
 
  Click to reply to this thread Reply
Attachment fixedglitch.jpg (166.1 KB)
You're safe as long as you don't run into these guys (attached).

It's like using the Google Docs Viewer to display PDF's in a skin. Sure, it works, but it's undocumented, and Google could pull the plug on it this afternoon.
RobM

Posts: 4,383
Registered: 4-Aug-2006
Re: AlbumObjects and isIncluded()
Posted: 21 Mar 22, 16:17   in response to: davidekholm in response to: davidekholm
 
  Click to reply to this thread Reply
davidekholm wrote:
But why do you create new instances of AlbumObjects at all?
Even if isIncluded() is implemented differently (using albumfiles.txt instead of .info files), the API is the same: Just call setIncluded(), setIncludeOriginal() etc.

To look up a corresponding "primary" object given an object under "extras", simply refer to the parent folder and call the getChild method, passing the name of the "extra" image as argument.

Lightbulb moment! I hadn’t thought of that, too busy trying to find devious ways to complicate things.

I will recode it tonight, thanks.
RobM

Posts: 4,383
Registered: 4-Aug-2006
Re: AlbumObjects and isIncluded()
Posted: 21 Mar 22, 16:19   in response to: RobM in response to: RobM
 
  Click to reply to this thread Reply
ctwist wrote:
If I understand you correctly:

In init.bsh, it would be better to hide the images in the extras folder instead of excluding them.

albumObject.setHidden(true);
jAlbum will create an AlbumObject for each image, but it will not include them in the album. You do not need to create an AlbumObject.

I actually use this technique, and it works.

I already hide the folder containing the extra images. If a user excludes a primary I just want to exclude the extra image too.
RobM

Posts: 4,383
Registered: 4-Aug-2006
Re: AlbumObjects and isIncluded()
Posted: 21 Mar 22, 16:23   in response to: davidekholm in response to: davidekholm
 
  Click to reply to this thread Reply
davidekholm wrote:
I also want to comment that the "rootFolder" variable you have access to during album builds refers to a temporary AlbumObject tree. If you make changes via it, I'm not 100% sure they propagate to the corresponding main AlbumObject tree the Explorer is using. To ensure that this happens, you might need to call invalidate() on the corresponding "extras" folder of the original AlbumObject tree. You can reach the original tree via context.getExplorer().getRootFolder().
I have never had a issue yet, and in this case the objects do update correctly in the Explorer, but I will look at all my uses of rootFolder - not many I think.
JeffTucker

Posts: 8,467
Registered: 31-Jan-2006
Re: AlbumObjects and isIncluded()
Posted: 21 Mar 22, 16:29   in response to: RobM in response to: RobM
 
  Click to reply to this thread Reply
RobM wrote:
I already hide the folder containing the extra images. If a user excludes a primary I just want to exclude the extra image too.

I think I'd just let the chips fall where they may, in that case. The only downside is that there will be a slide image for the "extra" that isn't really needed. Most users would never even notice it.
RobM

Posts: 4,383
Registered: 4-Aug-2006
Re: AlbumObjects and isIncluded()
Posted: 21 Mar 22, 16:33   in response to: JeffTucker in response to: JeffTucker
 
  Click to reply to this thread Reply
JeffTucker wrote:
RobM wrote:
I already hide the folder containing the extra images. If a user excludes a primary I just want to exclude the extra image too.

I think I'd just let the chips fall where they may, in that case. The only downside is that there will be a slide image for the "extra" that isn't really needed. Most users would never even notice it.

Yes, the first skin version does ignore the included state of the primary. I could leave it to the user, but that seems unfriendly.
JeffTucker

Posts: 8,467
Registered: 31-Jan-2006
Re: AlbumObjects and isIncluded()
Posted: 21 Mar 22, 16:49   in response to: RobM in response to: RobM
 
  Click to reply to this thread Reply
But if he wants to exclude sparky.jpg, is there really any harm in not excluding extras/sparky.jpg? The core will generate an unused slide image, but beyond that....
Legend
Forum admins
Helpful Answer
Correct Answer

Point your RSS reader here for a feed of the latest messages in all forums