Skip to content

Commit

Permalink
Use default map folder only on faild load.
Browse files Browse the repository at this point in the history
Load all settings only once.
Should solve #139
  • Loading branch information
Starcommander committed Feb 1, 2020
1 parent 1938288 commit 4cbd04a
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
import com.junjunguo.pocketmaps.util.IO;
import com.junjunguo.pocketmaps.util.SetStatusBarColor;
import com.junjunguo.pocketmaps.util.Variable;
import com.junjunguo.pocketmaps.util.Variable.VarType;

import java.io.File;
import java.io.FilenameFilter;
Expand Down Expand Up @@ -108,20 +109,27 @@ boolean continueActivity()
new SetStatusBarColor().setStatusBarColor(findViewById(R.id.statusBarBackgroundMain),
getResources().getColor(R.color.my_primary_dark), this);

File defMapsDir = IO.getDefaultBaseDirectory(this);
if (defMapsDir==null) { return false; }
Variable.getVariable().setBaseFolder(defMapsDir.getPath());
boolean loadSuccess = true;
if (!Variable.getVariable().isLoaded(VarType.Base))
{
loadSuccess = Variable.getVariable().loadVariables(Variable.VarType.Base);
}
if (!loadSuccess)
{ // First time app started, or loading-error.
File defMapsDir = IO.getDefaultBaseDirectory(this);
if (defMapsDir==null) { return false; }
Variable.getVariable().setBaseFolder(defMapsDir.getPath());
}

if (!Variable.getVariable().getMapsFolder().exists())
{
Variable.getVariable().getMapsFolder().mkdirs();
}
boolean loadSuccess = true;
if (!Variable.getVariable().isBaseLoaded())
if (!Variable.getVariable().isLoaded(VarType.Geocode))
{
loadSuccess = Variable.getVariable().loadVariables(Variable.VarType.Base);
Variable.getVariable().loadVariables(Variable.VarType.Geocode);
}
Variable.getVariable().loadVariables(Variable.VarType.Geocode);

activateAddBtn();
activateRecyclerView(new ArrayList<MyMap>());
generateList();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

/**
Expand All @@ -30,9 +31,8 @@
public class Variable {
public enum TravelMode{Foot, Bike, Car};
public enum VarType{Base, Geocode};

private boolean baseLoaded = false;
private TravelMode travelMode;
private HashMap<VarType, Boolean> loadStatus = new HashMap<VarType, Boolean>();
/**
* fastest, shortest (route)
*/
Expand Down Expand Up @@ -178,7 +178,11 @@ public static Variable getVariable() {
return variable;
}

public boolean isBaseLoaded() { return baseLoaded; }
public boolean isLoaded(VarType type)
{
if (loadStatus.containsKey(type)) { return true; }
return false;
}

public String getMapUrlJSON() {
return mapUrlJSON;
Expand Down Expand Up @@ -478,11 +482,12 @@ public boolean loadVariables(VarType varType)
if (varType == VarType.Base)
{
content = readFile("pocketmapssavedfile.txt");
baseLoaded = true;
loadStatus.put(VarType.Base, Boolean.TRUE);
}
else
{
content = readFile("pocketmapssavedfile_" + varType + ".txt");
loadStatus.put(VarType.Geocode, Boolean.TRUE);
}
if (content == null)
{
Expand Down

0 comments on commit 4cbd04a

Please sign in to comment.