Skip to content

Commit

Permalink
cobaltians/Cobalt#175: android class declaration in cobalt.json contr…
Browse files Browse the repository at this point in the history
…oller becomes optional
  • Loading branch information
Sébastien Vitard committed Apr 24, 2019
1 parent 2462365 commit aa31894
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
4 changes: 4 additions & 0 deletions src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,8 @@

<uses-permission android:name="android.permission.INTERNET" />

<application>
<activity android:name=".activities.CobaltActivity" />
</application>

</manifest>
16 changes: 11 additions & 5 deletions src/main/java/org/cobaltians/cobalt/Cobalt.java
Original file line number Diff line number Diff line change
Expand Up @@ -393,23 +393,30 @@ public Bundle getConfigurationForController(String controller) {

if (controller != null
&& controllers.has(controller)) {
activity = controllers.getJSONObject(controller).getString(kAndroid);
activity = controllers.getJSONObject(controller).optString(kAndroid, null);
bars = controllers.getJSONObject(controller).optJSONObject(kBars);
enablePullToRefresh = controllers.getJSONObject(controller).optBoolean(kPullToRefresh);
enableInfiniteScroll = controllers.getJSONObject(controller).optBoolean(kInfiniteScroll);
infiniteScrollOffset = controllers.getJSONObject(controller).optInt(kInfiniteScrollOffset, INFINITE_SCROLL_OFFSET_DEFAULT_VALUE);
backgroundColor = controllers.getJSONObject(controller).optString(kBackgroundColor, BACKGROUND_COLOR_DEFAULT);
}
else {
activity = controllers.getJSONObject(kDefaultController).getString(kAndroid);
activity = controllers.getJSONObject(kDefaultController).optString(kAndroid, null);
bars = controllers.getJSONObject(kDefaultController).optJSONObject(kBars);
enablePullToRefresh = controllers.getJSONObject(kDefaultController).optBoolean(kPullToRefresh);
enableInfiniteScroll = controllers.getJSONObject(kDefaultController).optBoolean(kInfiniteScroll);
infiniteScrollOffset = controllers.getJSONObject(kDefaultController).optInt(kInfiniteScrollOffset, INFINITE_SCROLL_OFFSET_DEFAULT_VALUE);
backgroundColor = controllers.getJSONObject(kDefaultController).optString(kBackgroundColor, BACKGROUND_COLOR_DEFAULT);
}

if (activity.substring(0,1).equals(".")) activity = sContext.getPackageName() + activity;
if (activity == null)
{
activity = "org.cobaltians.cobalt.activities.CobaltActivity";
}
else if (activity.startsWith("."))
{
activity = sContext.getPackageName() + activity;
}

bundle.putString(kController, controller);
bundle.putString(kActivity, activity);
Expand All @@ -424,8 +431,7 @@ public Bundle getConfigurationForController(String controller) {
catch (JSONException exception) {
if (Cobalt.DEBUG) Log.e(Cobalt.TAG, TAG + " - getConfigurationForController: check cobalt.json. Known issues: \n "
+ "\t - controllers field not found or not a JSONObject \n "
+ "\t - " + controller + " controller not found and no " + kDefaultController + " controller defined \n "
+ "\t - " + controller + " or " + kDefaultController + "controller found but no " + kAndroid + "defined \n ");
+ "\t - " + controller + " controller not found and no " + kDefaultController + " controller defined \n ");
exception.printStackTrace();
}

Expand Down

0 comments on commit aa31894

Please sign in to comment.