Signed-off-by: Andrey Shovkoplyas <motor4ik@gmail.com>
This commit is contained in:
tbenr 2018-08-03 18:43:37 +02:00 committed by Andrey Shovkoplyas
parent e037b3345a
commit 672e8255c4
No known key found for this signature in database
GPG Key ID: EAAB7C8622D860A4
5 changed files with 44 additions and 10 deletions

View File

@ -23,6 +23,7 @@ import java.io.FileInputStream;
import java.io.OutputStream;
import java.io.FileOutputStream;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
@ -31,6 +32,8 @@ import org.json.JSONObject;
import org.json.JSONException;
import com.instabug.library.Instabug;
import javax.annotation.Nullable;
class StatusModule extends ReactContextBaseJavaModule implements LifecycleEventListener, ConnectorHandler {
private static final String TAG = "StatusModule";
@ -43,6 +46,7 @@ class StatusModule extends ReactContextBaseJavaModule implements LifecycleEventL
private boolean debug;
private boolean devCluster;
private String logLevel;
private ReactApplicationContext reactContext;
StatusModule(ReactApplicationContext reactContext, boolean debug, boolean devCluster, String logLevel) {
super(reactContext);
@ -52,6 +56,7 @@ class StatusModule extends ReactContextBaseJavaModule implements LifecycleEventL
this.debug = debug;
this.devCluster = devCluster;
this.logLevel = logLevel;
this.reactContext = reactContext;
reactContext.addLifecycleEventListener(this);
}
@ -722,4 +727,17 @@ class StatusModule extends ReactContextBaseJavaModule implements LifecycleEventL
}
callback.invoke(uniqueID);
}
private Boolean is24Hour() {
return android.text.format.DateFormat.is24HourFormat(this.reactContext.getApplicationContext());
}
@Override
public @Nullable
Map<String, Object> getConstants() {
HashMap<String, Object> constants = new HashMap<String, Object>();
constants.put("is24Hour", this.is24Hour());
return constants;
}
}

View File

@ -398,4 +398,17 @@ RCT_EXPORT_METHOD(getDeviceUUID:(RCTResponseSenderBlock)callback) {
return;
}
- (bool) is24Hour
{
NSString *format = [NSDateFormatter dateFormatFromTemplate:@"j" options:0 locale:[NSLocale currentLocale]];
return ([format rangeOfString:@"a"].location == NSNotFound);
}
- (NSDictionary *)constantsToExport
{
return @{
@"is24Hour": @(self.is24Hour),
};
}
@end

View File

@ -65,3 +65,6 @@
(defn get-device-UUID [callback]
(native-module/get-device-UUID callback))
(defn is24Hour []
(native-module/is24Hour))

View File

@ -154,3 +154,7 @@
status
(fn [UUID]
(callback (string/upper-case UUID))))))
(defn is24Hour []
(when status
(.-is24Hour status)))

View File

@ -5,6 +5,7 @@
formatter
unparse]]
[status-im.i18n :refer [label label-pluralize]]
[status-im.native-module.core :as status]
[goog.string :as gstring]
goog.string.format
goog.i18n.DateTimeFormat
@ -39,16 +40,11 @@
"a")))
;; returns is24Hour from device or from given locale symbols
;; when device-info module is not available (ie. desktop) returns from the given locale
;
; TODO integrate with native module. example:
; (defn- is24Hour [locsym]
; (if rn/device-info
; (.is24Hour rn/device-info)
; (is24Hour-locsym locsym)))
;; whenever we get non-nil value use it, else calculate it from the given locale symbol
(defn- is24Hour [locsym]
(is24Hour-locsym locsym))
(if-some [fromdev (status/is24Hour)]
fromdev
(is24Hour-locsym locsym)))
;; time formats
(defn- short-time-format [locsym] (if (is24Hour locsym) "HH:mm" "h:mm a"))