Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[TC-1426] Better way of handling property change. Especially this will work with T... #3309

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
package ti.modules.titanium.app.properties;

import org.appcelerator.kroll.KrollModule;
import org.appcelerator.kroll.KrollDict;
import org.appcelerator.kroll.annotations.Kroll;
import org.appcelerator.titanium.TiApplication;
import org.appcelerator.titanium.TiC;
Expand All @@ -15,16 +16,27 @@

import ti.modules.titanium.app.AppModule;

import android.content.SharedPreferences;

@Kroll.module(parentModule=AppModule.class)
public class PropertiesModule extends KrollModule {

private TiProperties appProperties;
private SharedPreferences.OnSharedPreferenceChangeListener listener;

public PropertiesModule()
{
super();

appProperties = TiApplication.getInstance().getAppProperties();
listener = new SharedPreferences.OnSharedPreferenceChangeListener() {
public void onSharedPreferenceChanged(SharedPreferences prefs,String key) {
KrollDict result = new KrollDict();
result.put("property", key);
fireEvent(TiC.EVENT_CHANGE, result);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Android and iOS did not have the "property" property associated with "change" event before. Why do you add this property here?

}
};
appProperties.getPreference().registerOnSharedPreferenceChangeListener(listener);
}

public PropertiesModule(TiContext tiContext)
Expand Down Expand Up @@ -73,7 +85,6 @@ public void removeProperty(String key)
{
if (hasProperty(key)) {
appProperties.removeProperty(key);
fireEvent(TiC.EVENT_CHANGE, null);
}
}

Expand All @@ -89,7 +100,6 @@ public void setBool(String key, boolean value)
Object boolValue = getPreferenceValue(key);
if (boolValue == null || !boolValue.equals(value)) {
appProperties.setBool(key, value);
fireEvent(TiC.EVENT_CHANGE, null);
}


Expand All @@ -103,7 +113,6 @@ public void setDouble(String key, double value)
//so we need to convert before comparing.
if (doubleValue == null || !doubleValue.equals(String.valueOf(value))) {
appProperties.setDouble(key, value);
fireEvent(TiC.EVENT_CHANGE, null);
}

}
Expand All @@ -114,7 +123,6 @@ public void setInt(String key, int value)
Object intValue = getPreferenceValue(key);
if (intValue == null || !intValue.equals(value)) {
appProperties.setInt(key, value);
fireEvent(TiC.EVENT_CHANGE, null);
}

}
Expand All @@ -125,7 +133,6 @@ public void setString(String key, String value)
Object stringValue = getPreferenceValue(key);
if (stringValue == null || !stringValue.equals(value)) {
appProperties.setString(key, value);
fireEvent(TiC.EVENT_CHANGE, null);
}
}

Expand Down