Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
weixin_43355755
engine
提交
30cc1574
E
engine
项目概览
weixin_43355755
/
engine
与 Fork 源项目一致
从无法访问的项目Fork
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
E
engine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
30cc1574
编写于
1月 21, 2016
作者:
C
Collin Jackson
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #2282 from collinjackson/android_setValue
Android support for Firebase setValue
上级
c03a5dda
cd05f5f4
变更
4
显示空白变更内容
内联
并排
Showing
4 changed file
with
88 addition
and
12 deletion
+88
-12
sky/services/firebase/firebase.mojom
sky/services/firebase/firebase.mojom
+2
-1
sky/services/firebase/ios/firebase_impl.h
sky/services/firebase/ios/firebase_impl.h
+3
-2
sky/services/firebase/ios/firebase_impl.mm
sky/services/firebase/ios/firebase_impl.mm
+5
-0
sky/services/firebase/src/org/domokit/firebase/FirebaseImpl.java
...vices/firebase/src/org/domokit/firebase/FirebaseImpl.java
+78
-9
未找到文件。
sky/services/firebase/firebase.mojom
浏览文件 @
30cc1574
...
...
@@ -15,7 +15,7 @@ enum EventType {
struct DataSnapshot {
string key;
string
value; // TODO(jackson): Support more value types
string
jsonValue;
};
struct Error {
...
...
@@ -51,4 +51,5 @@ interface Firebase {
AddChildEventListener(ChildEventListener listener);
ObserveSingleEventOfType(EventType eventType) => (DataSnapshot snapshot);
AuthWithOAuthToken(string provider, string credentials) => (Error? error, AuthData? authData);
SetValue(string jsonValue) => (Error? error);
};
sky/services/firebase/ios/firebase_impl.h
浏览文件 @
30cc1574
...
...
@@ -41,6 +41,7 @@ class FirebaseImpl : public ::firebase::Firebase {
const
mojo
::
String
&
provider
,
const
mojo
::
String
&
credentials
,
const
AuthWithOAuthTokenCallback
&
callback
)
override
;
void
SetValue
(
const
mojo
::
String
&
jsonValue
);
private:
mojo
::
StrongBinding
<::
firebase
::
Firebase
>
binding_
;
...
...
sky/services/firebase/ios/firebase_impl.mm
浏览文件 @
30cc1574
...
...
@@ -159,6 +159,11 @@ void FirebaseImpl::AuthWithOAuthToken(
}];
}
void
FirebaseImpl
::
SetValue
(
const
mojo
::
String
&
jsonValue
)
{
// TODO(jackson): JSON deserialization
[
client_
setValue
:
@
(
jsonValue
.
data
())];
}
void
FirebaseFactory
::
Create
(
mojo
::
ApplicationConnection
*
connection
,
mojo
::
InterfaceRequest
<::
firebase
::
Firebase
>
request
)
{
...
...
sky/services/firebase/src/org/domokit/firebase/FirebaseImpl.java
浏览文件 @
30cc1574
...
...
@@ -7,11 +7,17 @@ package org.domokit.firebase;
import
android.content.Context
;
import
android.util.Log
;
import
java.io.IOException
;
import
com.firebase.client.AuthData
;
import
com.firebase.client.FirebaseError
;
import
com.firebase.client.Firebase.AuthResultHandler
;
import
com.firebase.client.AuthData
;
import
com.firebase.client.Firebase.CompletionListener
;
import
java.io.IOException
;
import
java.util.ArrayList
;
import
java.util.List
;
import
java.util.Iterator
;
import
java.util.Map
;
import
java.util.HashMap
;
import
org.chromium.mojo.bindings.ConnectionErrorHandler
;
import
org.chromium.mojo.bindings.InterfaceRequest
;
...
...
@@ -21,6 +27,10 @@ import org.chromium.mojom.firebase.EventType;
import
org.chromium.mojom.firebase.Firebase
;
import
org.chromium.mojom.firebase.ValueEventListener
;
import
org.json.JSONArray
;
import
org.json.JSONException
;
import
org.json.JSONObject
;
public
class
FirebaseImpl
implements
org
.
chromium
.
mojom
.
firebase
.
Firebase
{
private
static
final
String
TAG
=
"FirebaseImpl"
;
static
private
Context
mContext
;
...
...
@@ -149,27 +159,86 @@ public class FirebaseImpl implements org.chromium.mojom.firebase.Firebase {
responseCopy
.
call
(
null
,
mojoAuthData
);
}
public
void
onAuthenticationError
(
FirebaseError
error
)
{
responseCopy
.
call
(
toMojoError
(
error
),
null
);
}
});
}
@Override
public
void
setValue
(
String
jsonValue
,
SetValueResponse
response
)
{
final
SetValueResponse
responseCopy
=
response
;
try
{
JSONObject
root
=
new
JSONObject
(
jsonValue
);
Object
value
=
toMap
(
root
).
get
(
"value"
);
mClient
.
setValue
(
value
,
null
,
new
CompletionListener
()
{
@Override
public
void
onComplete
(
FirebaseError
error
,
com
.
firebase
.
client
.
Firebase
ref
)
{
responseCopy
.
call
(
toMojoError
(
error
));
}
});
}
catch
(
JSONException
e
)
{
org
.
chromium
.
mojom
.
firebase
.
Error
mojoError
=
new
org
.
chromium
.
mojom
.
firebase
.
Error
();
mojoError
.
code
=
error
.
getCode
();
mojoError
.
message
=
error
.
getMessage
();
responseCopy
.
call
(
mojoError
,
null
);
mojoError
.
code
=
-
1
;
mojoError
.
message
=
"setValue JSONException"
;
Log
.
e
(
TAG
,
"setValue JSONException"
,
e
);
responseCopy
.
call
(
mojoError
);
}
});
}
DataSnapshot
toMojoSnapshot
(
com
.
firebase
.
client
.
DataSnapshot
snapshot
)
{
DataSnapshot
mojoSnapshot
=
new
DataSnapshot
();
mojoSnapshot
.
key
=
snapshot
.
getKey
();
mojoSnapshot
.
value
=
(
String
)
snapshot
.
getValue
();
try
{
JSONObject
jsonObject
=
new
JSONObject
();
jsonObject
.
put
(
"value"
,
snapshot
.
getValue
());
mojoSnapshot
.
jsonValue
=
jsonObject
.
toString
();
}
catch
(
JSONException
e
)
{
Log
.
e
(
TAG
,
"toMojoSnapshot JSONException"
,
e
);
}
return
mojoSnapshot
;
}
org
.
chromium
.
mojom
.
firebase
.
Error
toMojoError
(
FirebaseError
error
)
{
if
(
error
==
null
)
return
null
;
org
.
chromium
.
mojom
.
firebase
.
Error
mojoError
=
new
org
.
chromium
.
mojom
.
firebase
.
Error
();
mojoError
.
code
=
error
.
getCode
();
mojoError
.
message
=
error
.
getMessage
();
return
mojoError
;
}
// public domain code from https://gist.github.com/codebutler/2339666
@SuppressWarnings
({
"rawtypes"
,
"unchecked"
})
static
Map
<
String
,
Object
>
toMap
(
JSONObject
object
)
throws
JSONException
{
Map
<
String
,
Object
>
map
=
new
HashMap
();
Iterator
keys
=
object
.
keys
();
while
(
keys
.
hasNext
())
{
String
key
=
(
String
)
keys
.
next
();
map
.
put
(
key
,
fromJson
(
object
.
get
(
key
)));
}
return
map
;
}
@SuppressWarnings
({
"rawtypes"
,
"unchecked"
})
static
List
toList
(
JSONArray
array
)
throws
JSONException
{
List
list
=
new
ArrayList
();
for
(
int
i
=
0
;
i
<
array
.
length
();
i
++)
{
list
.
add
(
fromJson
(
array
.
get
(
i
)));
}
return
list
;
}
static
Object
fromJson
(
Object
json
)
throws
JSONException
{
if
(
json
==
JSONObject
.
NULL
)
{
return
null
;
}
else
if
(
json
instanceof
JSONObject
)
{
return
toMap
((
JSONObject
)
json
);
}
else
if
(
json
instanceof
JSONArray
)
{
return
toList
((
JSONArray
)
json
);
}
else
{
return
json
;
}
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录