src/main/java/de/blau/android/presets/PresetMRUInfo.java
/**
     * Add a preset to the front of the MRU list (removing old duplicates and limiting the list if needed)
     * 
     * @param item the item to add
     * @param region country to filter on
     * 
     */
Add a preset to the front of the MRU list (removing old duplicates and limiting the list if needed)

@param item the item to add
@param region country to filter on
Add a preset to the front of the MRU list ( removing old duplicates and limiting the list if needed ) @param item the item to add @param region country to filter on
public void putRecentlyUsed(@NonNull PresetItem item, @Nullable String region) {
        final PresetGroup rootGroup = item.getPreset().getRootGroup();
        TimestampedPresetElementPath path = new TimestampedPresetElementPath(item.getPath(rootGroup));
        if (!recentPresets.remove(path) && item.getLinkedPresetItems() != null) {
            LinkedList<PresetItemLink> linkedPresets = new LinkedList<>(item.getLinkedPresetItems());
            Collections.reverse(linkedPresets);
            Preset preset = item.getPreset();
            for (PresetItemLink pl : linkedPresets) {
                PresetItem linkedItem = preset.getItemByName(pl.getPresetName(), region);
                if (linkedItem != null) { 
                    TimestampedPresetElementPath linkedPath = new TimestampedPresetElementPath(linkedItem.getPath(rootGroup));
                    if (!recentPresets.contains(linkedPath)) { 
                        recentPresets.addFirst(linkedPath);
                        if (recentPresets.size() > MAX_MRU_SIZE) {
                            recentPresets.removeLast();
                        }
                    }
                } else {
                    Log.e(DEBUG_TAG, "linked preset not found for " + pl.getPresetName() + " in preset " + item.getName());
                }
            }
        }
        recentPresets.addFirst(path);
        if (recentPresets.size() > MAX_MRU_SIZE) {
            recentPresets.removeLast();
        }
        setChanged();
    }
public void putRecentlyUsed ( @ NonNull PresetItem item , @ Nullable String region ) { final PresetGroup rootGroup = item . getPreset ( ) . getRootGroup ( ) ; TimestampedPresetElementPath path = new TimestampedPresetElementPath ( item . getPath ( rootGroup ) ) ; if ( ! recentPresets . remove ( path ) && item . getLinkedPresetItems ( ) != null ) { LinkedList < PresetItemLink > linkedPresets = new LinkedList < > ( item . getLinkedPresetItems ( ) ) ; Collections . reverse ( linkedPresets ) ; Preset preset = item . getPreset ( ) ; for ( PresetItemLink pl : linkedPresets ) { PresetItem linkedItem = preset . getItemByName ( pl . getPresetName ( ) , region ) ; if ( linkedItem != null ) { TimestampedPresetElementPath linkedPath = new TimestampedPresetElementPath ( linkedItem . getPath ( rootGroup ) ) ; if ( ! recentPresets . contains ( linkedPath ) ) { recentPresets . addFirst ( linkedPath ) ; if ( recentPresets . size ( ) > MAX_MRU_SIZE ) { recentPresets . removeLast ( ) ; } } } else { Log . e ( DEBUG_TAG , "linked preset not found for " + pl . getPresetName ( ) + " in preset " + item . getName ( ) ) ; } } } recentPresets . addFirst ( path ) ; if ( recentPresets . size ( ) > MAX_MRU_SIZE ) { recentPresets . removeLast ( ) ; } setChanged ( ) ; }
Add a preset to the front of the MRU list (removing old duplicates and limiting the list if needed)
Add a preset to the front of the MRU list ( removing old duplicates and limiting the list if needed )
// prevent duplicates and preset is not in the list, add linked presets first // null if the link wasn't found // only add if not already present