android - Universal-Image-Loader Custom FileNameGenerator based on local file name -
I am using a Universal Image Loader to display images downloaded from the URI or the first in the disk cache implementation Available from.
I want to display the music album cover, but there can be only one URI for the cover in more than one track (i.e. track from the same album). I want that even if the image is the same, each time it is stored for each track with the name of the track, because I want the users to be able to change the default armor with a custom one, even so That's for each single track.
For example- 01 - Track 01.M.E
- 02 - Track 02.mpi
The same album and cover is from the URI http: //something/img.jpg
, I have to be on the disk cache
- 01 - Track 01.jpg
- 02 - Track 02.jpg
Even if it is the same image.
So I have coded a filename generator
that stores set
for hash for each URI
, where The full path of the hash file is SHA-1.
Here's my implementation:
Public MyFileNameGenerator {string} {super}; This.ext = ext } Hashmap & lt; String, hashaseet & lt; String & gt; & Gt; Name = new hashmop & lt; String, hashaseet & lt; String & gt; & Gt; (); @ Override public string generated (string image ury) {if (imageUri == empty) return tap; If (imageUri.startsWith ("file: ///")) {back filename utility. Extension (URI.parse (imageUri) .getLastPathSegment ()) + "." + Ext. How To Identify The Right Hash? // Return filename utility. Revue Extension (Data.Current.get (names.get (imageUri)). GetName ()) + "." + Ext. } Public Zero Settrackdata (String Yuri, String Hash) {If (Kontsky (Yuri's Name) names! Input (Yuri, new hashset & lt; string & gt; ()); Names.get (URI) .add (hash); }
But I am at a dead end, because it is impossible to understand what image I am displaying, because only the image moves in the form of parameters and more ish Relationship can be the same urine
How can I stop this issue?
I think I have found a solution for this.
Whenever I call my ImageLoader
to show an image for example, I use
(if! = Tap & amp;! Uri.isEmpty ()) {Uuri = Uri.parse (URI) .buildUpon () .appendQueryParameter ("myhashkeyparameter", "myHashValue"). ToString (); } MImageLoader.displayImage (uri, mImageView);
This code will add a vaild uri query parameter, Yuri will be created:
http: //someuri/image.jpg? MyHashkeyPerameter = MyHashValue
Then in the generated
method of
string hash = URI. Parse (imageUri) .getQueryParameter ("myhashkeyparameter");
To recover the image as a key without the use of Yuri
Full code:
@ Override generated public string (string image Yuri) {if (imageUri == faucet} imageUri.isEmpty ()) Return ""; If (imageUri.startsWith ("file: ///")) {back filename utility. Extension (URI.parse (imageUri) .getLastPathSegment ()) + "." + Ext. } String hash = uri. PRSE (Image Yuri). Dataparmetra ("MyHoashquimeter"); If (null == hash} hash.ISPT ()) "" return; If (Data.currentFiles.containsKey (hash)) {return file name utility .removeExtension (Data.currentFiles.get (hash) .getName ()) + ".png"; } And return ""; }
All you have to be careful is that the string not already used in the query URL, hence avoid conventional names like name, hash, h, title etc.
Comments
Post a Comment