/*
 * Copyright (C) 2017 team-cachebox.de
 *
 * Licensed under the : GNU General Public License (GPL);
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.gnu.org/licenses/gpl.html
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package de.longri.cachebox3.gui.map.baseMap;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.files.FileHandle;
import de.longri.cachebox3.CB;
import de.longri.cachebox3.Utils;
import de.longri.cachebox3.settings.Config;
import de.longri.cachebox3.utils.lists.CB_List;

import java.io.File;
import java.io.FileFilter;

/**
 * Created by Longri on 22.02.2017.
 */
public final class BaseMapManager extends CB_List<AbstractManagedMapLayer> {

    public final static BaseMapManager INSTANCE = new BaseMapManager();

    public BaseMapManager() {
    }

    public void refreshMaps() {
        this.clear();
        FileHandle workPath = Gdx.files.absolute(CB.WorkPath);
        // add map files from repository
        String repositoryMaps = addMapFiles(workPath.child("repository").child("maps"));

        // add map files from act selected repository
        String actRepositoryName = Config.DatabaseName.getValue().replace(".db3", "");
        addMapFiles(workPath.child("repositories").child(actRepositoryName).child("maps"));

        // add map files from user map folder
        FileHandle userMapFolder = Gdx.files.absolute(Config.MapPackFolder.getValue());
        if (!userMapFolder.path().equals(repositoryMaps))
            addMapFiles(userMapFolder);

        this.addStaticMaps();
        this.sort();
    }

    private String addMapFiles(FileHandle workPath) {
        FileFilter mapFileFilter = new FileFilter() {
            @Override
            public boolean accept(File pathname) {
                return Utils.getFileExtension(pathname.getAbsolutePath()).toLowerCase().equals("map");
            }
        };
        FileHandle[] mapFiles = workPath.list(mapFileFilter);

        for (FileHandle mapFile : mapFiles) {
            this.add(new MapsforgeSingleMap(mapFile));
        }
        return workPath.path();
    }

    private void addStaticMaps() {
        this.add(new HikeBike());
        this.add(new StamenWaterColor());
        this.add(new StamenToner());
        this.add(new OSciMap());
        this.add(new OpenStreetMapTransport());
        this.add(new OpenStreetMap());
        this.add(new ImagicoLandCover());
        this.add(new HikeBikeHillShade());
    }
}

@@ -862,29 +862,8 @@
 t;%0A%0A
-import java.io.File;%0A
 impo
@@ -1086,21 +1086,22 @@
 ;%0A%0A    p
-ublic
+rivate
  BaseMap
@@ -1163,82 +1163,132 @@
     
-this.clear(
+refreshMaps(Gdx.files.absolute(CB.WorkPath)
 );%0A    
+%7D%0A%0A
     
-FileHandle workPath = Gdx.files.absolute(CB.WorkPath
+private void refreshMaps(FileHandle workPath) %7B%0A        this.clear(
 );%0A 
@@ -2035,122 +2035,19 @@
 r = 
-new FileFilter() %7B%0A            @Override%0A            public boolean accept(File pathname) %7B%0A                return
+pathname -%3E
  Uti
@@ -2127,33 +2127,8 @@
 %22);%0A
-            %7D%0A        %7D;%0A
     

fix JUnit test are broken with commit fbf5bbb617b51e7cd8777e2d4d9cc64b1cc9666b