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;
class AndroidSettingsModule extends ReactContextBaseJavaModule {
/**
* React Native module name.
*/
private static final String MODULE_NAME = "AndroidSettings";
public AndroidSettingsModule(ReactApplicationContext reactContext) {
super(reactContext);
}
/**
* {@inheritDoc}
*/
@Override
public String getName() {
return MODULE_NAME;
return "AndroidSettings";
}
@ReactMethod

View File

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

View File

@ -74,12 +74,13 @@ class AudioModeModule extends ReactContextBaseJavaModule {
: 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";
/**
* Tag used when logging messages.
* The <tt>Log</tt> tag <tt>AudioModeModule</tt> is to log messages with.
*/
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.
*/

View File

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

View File

@ -33,7 +33,8 @@ import com.facebook.react.bridge.UiThreadUtil;
*/
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";

View File

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