Skip to content

Commit

Permalink
cobaltians/Cobalt#92 : remove setTexts and clean code
Browse files Browse the repository at this point in the history
  • Loading branch information
Myrdhinn committed Aug 16, 2016
1 parent 3f38d24 commit 14ba49e
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 135 deletions.
Original file line number Diff line number Diff line change
@@ -1,13 +1,7 @@
package org.cobaltians.catalog.fragments;

import org.cobaltians.cobalt.Cobalt;
import org.cobaltians.cobalt.activities.CobaltActivity;
import org.cobaltians.cobalt.fragments.CobaltFragment;

import android.support.v7.app.ActionBar;
import android.util.Log;

import org.json.JSONException;
import org.json.JSONObject;

/**
Expand All @@ -17,31 +11,12 @@ public abstract class AbstractFragment extends CobaltFragment {

protected final static String TAG = "AbstractFragment";

private final static String EVENT_SET_TEXTS = "setTexts";
private final static String TITLE_KEY = "title";
@Override
protected boolean onUnhandledCallback(String callback, JSONObject data) { return false;}

@Override
protected boolean onUnhandledEvent(String event, JSONObject data, String callback) {return false;}

@Override
protected boolean onUnhandledEvent(String event, JSONObject data, String callback) {
if (event.equals(EVENT_SET_TEXTS)) {
try {
final String title = data.getString(TITLE_KEY);
final ActionBar actionBar = ((CobaltActivity) mContext).getSupportActionBar();
if (actionBar != null) {
((CobaltActivity) mContext).runOnUiThread(new Runnable() {
@Override
public void run() {
actionBar.setTitle(title);
}
});
}
else if (Cobalt.DEBUG) Log.e(TAG, "onUnhandledEvent: setTexts event received but no action bar displayed");
}
catch (JSONException e) {
if (Cobalt.DEBUG) Log.e(TAG, "onUnhandledEvent: missing title field for event setTexts");
e.printStackTrace();
}
return true;
}
else return false;
}
protected void onUnhandledMessage(JSONObject message) { }
}
Original file line number Diff line number Diff line change
Expand Up @@ -75,15 +75,9 @@ public void onClick(View arg0) {
});
}

// unhandled JS messages
@Override
protected void onUnhandledMessage(JSONObject message) {

}
@Override
protected boolean onUnhandledEvent(String name, JSONObject data, String callback) {
if (super.onUnhandledEvent(name, data, callback)) return true;
else if (name.equals(JSAddValues)) {
if (name.equals(JSAddValues)) {
try {
JSONArray values = data.getJSONArray(kValues);
int val1 = values.getInt(0);
Expand All @@ -102,6 +96,7 @@ else if (name.equals(JSEcho)) {
}
return false;
}

@Override
protected boolean onUnhandledCallback(String name, JSONObject data) {
if (name.equals(JSValuesCallback)) {
Expand Down Expand Up @@ -149,12 +144,10 @@ else if (index==mArrayTest.size()-1) {
}

@Override
protected void onPullToRefreshRefreshed() {
}
protected void onPullToRefreshRefreshed() { }

@Override
protected void onInfiniteScrollRefreshed() {
}
protected void onInfiniteScrollRefreshed() { }

private void launchTest(int index){
JSONObject data = new JSONObject();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,35 +96,22 @@ private void setZoomLevelInWebView(int nZoomLevel)
}
}

// unhandled JS messages
@Override
protected void onUnhandledMessage(JSONObject message) { }
@Override
protected boolean onUnhandledEvent(String name, JSONObject data, String callback) {
if (super.onUnhandledEvent(name, data, callback)) return true;
else if(name.equals(JSNameHello)) {
if(name.equals(JSNameHello)) {
AlertDialog.Builder alert = new AlertDialog.Builder(getActivity());
alert.setMessage("hello world");
AlertDialog mAlert = alert.create();
mAlert.setCanceledOnTouchOutside(true);
mAlert.show();

return true;
}
return false;
}
@Override
protected boolean onUnhandledCallback(String name, JSONObject data) {
return false;
}


@Override
protected void onPullToRefreshRefreshed() {
}

protected void onPullToRefreshRefreshed() { }

@Override
protected void onInfiniteScrollRefreshed() {
}
protected void onInfiniteScrollRefreshed() { }
}
Original file line number Diff line number Diff line change
@@ -1,21 +1,4 @@
package org.cobaltians.catalog.fragments;

import org.json.JSONObject;

public class ModalFragment extends AbstractFragment {

@Override
protected boolean onUnhandledCallback(String callback, JSONObject data) {
return false;
}

@Override
protected boolean onUnhandledEvent(String event, JSONObject data, String callback) {
if (super.onUnhandledEvent(event, data, callback)) return true;
else return false;
}

@Override
protected void onUnhandledMessage(JSONObject message) { }
}
public class ModalFragment extends AbstractFragment { }

Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package org.cobaltians.catalog.fragments;

import org.json.JSONObject;

public class PullToRefreshCustomFragment extends AbstractFragment {

@Override
Expand All @@ -13,20 +11,4 @@ public void onStart() {
android.R.color.holo_blue_dark,
android.R.color.holo_orange_light);
}

@Override
protected boolean onUnhandledEvent(String name, JSONObject data, String callback) {
if (super.onUnhandledEvent(name, data, callback)) return true;
else return false;
}

@Override
protected boolean onUnhandledCallback(String name, JSONObject data) {
return false;
}

@Override
protected void onUnhandledMessage(JSONObject message) {

}
}
Original file line number Diff line number Diff line change
@@ -1,20 +1,3 @@
package org.cobaltians.catalog.fragments;

import org.json.JSONObject;

public class PullToRefreshFragment extends AbstractFragment {

@Override
protected boolean onUnhandledEvent(String name, JSONObject data, String callback) {
if (super.onUnhandledEvent(name, data, callback)) return true;
else return false;
}

@Override
protected boolean onUnhandledCallback(String name, JSONObject data) {
return false;
}

@Override
protected void onUnhandledMessage(JSONObject message) { }
}
public class PullToRefreshFragment extends AbstractFragment { }
Original file line number Diff line number Diff line change
Expand Up @@ -32,32 +32,11 @@ private JSONArray generateBigData(int size)
return a;
}

// unhandled JS messages
@Override
protected void onUnhandledMessage(JSONObject message) {

}

@Override
protected boolean onUnhandledEvent(String name, JSONObject data, String callback) {
if (super.onUnhandledEvent(name, data, callback)) return true;
else return false;
}

@Override
protected boolean onUnhandledCallback(String name, JSONObject data) {
return false;
}
protected void onPullToRefreshRefreshed() { }

@Override
protected void onPullToRefreshRefreshed() {

}

@Override
protected void onInfiniteScrollRefreshed() {

}
protected void onInfiniteScrollRefreshed() { }

@Override
public JSONObject treatData(JSONObject data, JSONObject process) {
Expand Down

0 comments on commit 14ba49e

Please sign in to comment.