Skip to content

Commit 836d0be

Browse files
committed
bug fixes
1 parent 171d0ab commit 836d0be

6 files changed

Lines changed: 28 additions & 24 deletions

File tree

app/src/main/java/com/baato/osmnavigationapp/MainActivity.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ protected void onCreate(Bundle savedInstanceState) {
3131
setContentView(R.layout.activity_main);
3232
ToasterMessage.s(this, "Hello Good Morning");
3333
Geometry geometry = BaatoUtil.getGeoJsonFromEncodedPolyLine(encoded);
34-
BaatoTranslationMap trMap = new BaatoTranslationMap().doImport("locale/");
34+
BaatoTranslationMap trMap = new BaatoTranslationMap().doImport(getApplicationContext());
3535
performRouting();
3636
performReverseGeoCoding();
3737
performSearch();

baatolibrary/src/main/AndroidManifest.xml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,5 @@
66
<uses-permission android:name="android.permission.INTERNET" />
77

88
<application
9-
android:name="com.baato.baatolibrary.application.BaatoLib"
109
tools:targetApi="n" />
1110
</manifest>

baatolibrary/src/main/java/com/baato/baatolibrary/application/BaatoLib.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,16 @@
2121

2222
public class BaatoLib extends Application {
2323
private static TinyDB tinyDB;
24-
@SuppressLint("StaticFieldLeak")
25-
private static Context mContext;
24+
// @SuppressLint("StaticFieldLeak")
25+
// private static Context mContext;
2626

2727

2828
@Override
2929
public void onCreate() {
3030
super.onCreate();
3131
//tiny db config
3232
tinyDB = new TinyDB(getApplicationContext());
33-
mContext = this;
33+
// mContext = this;
3434
}
3535

3636
public static TinyDB db() {
@@ -65,7 +65,7 @@ public static boolean isConnectedToNetwork(Context context) {
6565
}
6666
return isConnected;
6767
}
68-
public static Context getContext(){
69-
return mContext;
70-
}
68+
// public static Context getContext(){
69+
// return mContext;
70+
// }
7171
}

baatolibrary/src/main/java/com/baato/baatolibrary/navigation/BaatoTranslationMap.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.baato.baatolibrary.navigation;
22

3+
import android.content.Context;
34
import android.content.res.AssetManager;
45
import android.content.res.Resources;
56
import android.util.Log;
@@ -32,18 +33,18 @@ public static int countOccurence(String phrase, String splitter) {
3233
return Helper.isEmpty(phrase) ? 0 : phrase.trim().split(splitter).length;
3334
}
3435

35-
public BaatoTranslationMap doImport(String folder) {
36-
// AssetManager gi = BaatoLib.getContext().getAssets();
37-
Resources resources = BaatoLib.getContext().getResources();
36+
public BaatoTranslationMap doImport(Context context) {
37+
AssetManager gi = context.getAssets();
38+
// Resources resources = context.getResources();
3839

3940
try {
4041
Iterator var2 = LOCALES.iterator();
4142
while(var2.hasNext()) {
4243
String locale = (String)var2.next();
4344
BaatoTranslationMap.TranslationHashMap trMap = new BaatoTranslationMap.TranslationHashMap(Helper.getLocale(locale));
44-
int identifier = resources.getIdentifier(locale.toLowerCase(),"raw", BaatoLib.getContext().getPackageName());
45-
// InputStream is = gi.open(folder+locale + ".txt");
46-
InputStream is = resources.openRawResource(identifier);
45+
// int identifier = resources.getIdentifier(locale.toLowerCase(),"raw", context.getPackageName());
46+
InputStream is = gi.open("locale/"+locale + ".txt");
47+
// InputStream is = resources.openRawResource(identifier);
4748
trMap.doImport(is);
4849
this.add(trMap);
4950
}

baatolibrary/src/main/java/com/baato/baatolibrary/navigation/NavigateResponseConverter.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121

2222
import androidx.annotation.Nullable;
2323

24+
import android.content.Context;
2425
import android.util.Log;
2526

2627
import com.baato.baatolibrary.models.NavResponse;
@@ -108,18 +109,18 @@ private enum Profile {
108109
/**
109110
* Converts a GHResponse into a json that follows the Mapbox API specification
110111
*/
111-
public static ObjectNode convertFromGHResponse(NavResponse ghResponsee, String type) {
112+
public static ObjectNode convertFromGHResponse(NavResponse ghResponsee, String type, Context context) {
112113
ghResponse = ghResponsee;
113114
mtrMap = new NavigateResponseConverterTranslationMap(locale.getLanguage()).doImport();
114-
trMap = new BaatoTranslationMap().doImport("locale/");
115+
trMap = new BaatoTranslationMap().doImport(context);
115116
return navConverter(type);
116117
}
117-
public static ObjectNode convertFromGHResponse(NavResponse ghResponsee, String type, Locale localevar) {
118+
public static ObjectNode convertFromGHResponse(NavResponse ghResponsee, String type, Locale localevar, Context context) {
118119
ObjectNode json = JsonNodeFactory.instance.objectNode();
119120
ghResponse = ghResponsee;
120121
locale = localevar;
121122
mtrMap = new NavigateResponseConverterTranslationMap(locale.getLanguage()).doImport();
122-
trMap = new BaatoTranslationMap().doImport("locale/");
123+
trMap = new BaatoTranslationMap().doImport(context);
123124
return navConverter(type);
124125
// if (ghResponse.hasErrors())
125126
// throw new IllegalStateException("If the response has errors, you should use the method NavigateResponseConverter#convertFromGHResponseError");

baatolibrary/src/main/java/com/baato/baatolibrary/services/BaatoRouting.java

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,10 @@ public BaatoRouting setLocale(Locale locale) {
6464
this.locale = locale;
6565
return this;
6666
}
67+
public BaatoRouting setContext(Context context) {
68+
this.context = context;
69+
return this;
70+
}
6771

6872
/**
6973
* Set the apiBaseURL.
@@ -148,11 +152,10 @@ public void cancelRequest() {
148152
directionsAPIResponseCall.cancel();
149153
}
150154

151-
public static String getParsedNavResponse(DirectionsAPIResponse response, String mode, Locale locale) {
152-
return NavigateResponseConverter.convertFromGHResponse(response.getData().get(0), mode, locale).toString();
153-
}
154-
155-
public static String getParsedNavResponse(DirectionsAPIResponse response, String mode) {
156-
return NavigateResponseConverter.convertFromGHResponse(response.getData().get(0), mode).toString();
155+
public static String getParsedNavResponse(DirectionsAPIResponse response, String mode, Context context) {
156+
return NavigateResponseConverter.convertFromGHResponse(response.getData().get(0), mode,context).toString();
157157
}
158+
// public static String getParsedNavResponse(DirectionsAPIResponse response, String mode) {
159+
// return NavigateResponseConverter.convertFromGHResponse(response.getData().get(0), mode).toString();
160+
// }
158161
}

0 commit comments

Comments
 (0)