Coding style

This commit is contained in:
Lyubo Marinov 2017-09-27 11:01:27 -05:00
parent 3fdffa7497
commit b55faab33e
6 changed files with 48 additions and 39 deletions

View File

@ -15,18 +15,16 @@ import com.facebook.react.bridge.ReactContextBaseJavaModule;
import com.facebook.react.bridge.ReactMethod; import com.facebook.react.bridge.ReactMethod;
class AndroidSettingsModule extends ReactContextBaseJavaModule { class AndroidSettingsModule extends ReactContextBaseJavaModule {
/**
* React Native module name.
*/
private static final String MODULE_NAME = "AndroidSettings";
public AndroidSettingsModule(ReactApplicationContext reactContext) { public AndroidSettingsModule(ReactApplicationContext reactContext) {
super(reactContext); super(reactContext);
} }
/**
* {@inheritDoc}
*/
@Override @Override
public String getName() { public String getName() {
return MODULE_NAME; return "AndroidSettings";
} }
@ReactMethod @ReactMethod

View File

@ -12,45 +12,53 @@ import java.util.HashMap;
import java.util.Map; import java.util.Map;
class AppInfoModule extends ReactContextBaseJavaModule { class AppInfoModule extends ReactContextBaseJavaModule {
/**
* React Native module name.
*/
private static final String MODULE_NAME = "AppInfo";
public AppInfoModule(ReactApplicationContext reactContext) { public AppInfoModule(ReactApplicationContext reactContext) {
super(reactContext); super(reactContext);
} }
/** /**
* Gets a mapping with the constants this module is exporting. * Gets a <tt>Map</tt> of constants this module exports to JS. Supports JSON
* types.
* *
* @return a {@link Map} mapping the constants to be exported with their * @return a {@link Map} of constants this module exports to JS
* values.
*/ */
@Override @Override
public Map<String, Object> getConstants() { public Map<String, Object> getConstants() {
Map<String, Object> constants = new HashMap<>();
Context context = getReactApplicationContext(); Context context = getReactApplicationContext();
PackageManager pm = context.getPackageManager(); PackageManager packageManager = context.getPackageManager();
ApplicationInfo appInfo; ApplicationInfo applicationInfo;
PackageInfo packageInfo; PackageInfo packageInfo;
try { try {
appInfo = pm.getApplicationInfo(context.getPackageName(), 0); String packageName = context.getPackageName();
packageInfo = pm.getPackageInfo(context.getPackageName(), 0);
applicationInfo
= packageManager.getApplicationInfo(packageName, 0);
packageInfo = packageManager.getPackageInfo(packageName, 0);
} catch (PackageManager.NameNotFoundException e) { } catch (PackageManager.NameNotFoundException e) {
constants.put("name", ""); applicationInfo = null;
constants.put("version", ""); packageInfo = null;
return constants;
} }
constants.put("name", pm.getApplicationLabel(appInfo)); Map<String, Object> constants = new HashMap<>();
constants.put("version", packageInfo.versionName);
constants.put(
"name",
applicationInfo == null
? ""
: packageManager.getApplicationLabel(applicationInfo));
constants.put(
"version",
packageInfo == null ? "" : packageInfo.versionName);
return constants; return constants;
} }
/**
* {@inheritDoc}
*/
@Override @Override
public String getName() { public String getName() {
return MODULE_NAME; return "AppInfo";
} }
} }

View File

@ -74,12 +74,13 @@ class AudioModeModule extends ReactContextBaseJavaModule {
: Intent.ACTION_HEADSET_PLUG; : Intent.ACTION_HEADSET_PLUG;
/** /**
* React Native module name. * The name of <tt>AudioModeModule</tt> to be used in the React Native
* bridge.
*/ */
private static final String MODULE_NAME = "AudioMode"; private static final String MODULE_NAME = "AudioMode";
/** /**
* Tag used when logging messages. * The <tt>Log</tt> tag <tt>AudioModeModule</tt> is to log messages with.
*/ */
static final String TAG = MODULE_NAME; static final String TAG = MODULE_NAME;
@ -155,7 +156,7 @@ class AudioModeModule extends ReactContextBaseJavaModule {
} }
/** /**
* Gets the name for this module, to be used in the React Native bridge. * Gets the name for this module to be used in the React Native bridge.
* *
* @return a string with the module name. * @return a string with the module name.
*/ */

View File

@ -47,11 +47,6 @@ class ExternalAPIModule extends ReactContextBaseJavaModule {
private static final Map<String, Method> JITSI_MEET_VIEW_LISTENER_METHODS private static final Map<String, Method> JITSI_MEET_VIEW_LISTENER_METHODS
= new HashMap<>(); = new HashMap<>();
/**
* The name of this module to be used in the React Native bridge.
*/
private static final String MODULE_NAME = "ExternalAPI";
static { static {
// Figure out the mapping between the JitsiMeetViewListener methods // Figure out the mapping between the JitsiMeetViewListener methods
// and the events i.e. redux action types. // and the events i.e. redux action types.
@ -113,7 +108,7 @@ class ExternalAPIModule extends ReactContextBaseJavaModule {
*/ */
@Override @Override
public String getName() { public String getName() {
return MODULE_NAME; return "ExternalAPI";
} }
/** /**

View File

@ -33,7 +33,8 @@ import com.facebook.react.bridge.UiThreadUtil;
*/ */
class ProximityModule extends ReactContextBaseJavaModule { class ProximityModule extends ReactContextBaseJavaModule {
/** /**
* React Native module name. * The name of <tt>ProximityModule</tt> to be used in the React Native
* bridge.
*/ */
private static final String MODULE_NAME = "Proximity"; private static final String MODULE_NAME = "Proximity";

View File

@ -27,16 +27,22 @@
RCT_EXPORT_MODULE(); RCT_EXPORT_MODULE();
- (NSDictionary *)constantsToExport { - (NSDictionary *)constantsToExport {
NSString *name = [[[NSBundle mainBundle]infoDictionary]objectForKey :@"CFBundleDisplayName"]; NSDictionary<NSString *, id> *infoDictionary
NSString *version = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"]; = [[NSBundle mainBundle] infoDictionary];
NSString *name = infoDictionary[@"CFBundleDisplayName"];
NSString *version = infoDictionary[@"CFBundleShortVersionString"];
if (version == nil) { if (version == nil) {
version = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleVersion"]; version = infoDictionary[@"CFBundleVersion"];
if (version == nil) { if (version == nil) {
version = @""; version = @"";
} }
} }
return @{ @"name" : name, @"version" : version }; return @{
@"name": name,
@"version": version
};
}; };
@end @end