Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
A
AloqaIM-Android
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Administrator
AloqaIM-Android
Commits
88174b75
Commit
88174b75
authored
Dec 07, 2016
by
Yusuke Iwaki
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
FIX #68 add Google Login feature. refactor logic to show/hide OAuth Provider button.
parent
d9217310
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
130 additions
and
46 deletions
+130
-46
AbstractOAuthFragment.java
.../rocket/android/fragment/oauth/AbstractOAuthFragment.java
+1
-1
GitHubOAuthFragment.java
...at/rocket/android/fragment/oauth/GitHubOAuthFragment.java
+0
-12
GoogleOAuthFragment.java
...at/rocket/android/fragment/oauth/GoogleOAuthFragment.java
+42
-0
TwitterOAuthFragment.java
...t/rocket/android/fragment/oauth/TwitterOAuthFragment.java
+0
-12
LoginFragment.java
.../rocket/android/fragment/server_config/LoginFragment.java
+35
-21
OAuthProviderInfo.java
.../rocket/android/layouthelper/oauth/OAuthProviderInfo.java
+32
-0
fragment_login.xml
app/src/main/res/layout/fragment_login.xml
+18
-0
fa_strings.xml
app/src/main/res/values/fa_strings.xml
+2
-0
No files found.
app/src/main/java/chat/rocket/android/fragment/oauth/AbstractOAuthFragment.java
View file @
88174b75
...
...
@@ -15,7 +15,7 @@ import org.json.JSONException;
import
org.json.JSONObject
;
import
timber.log.Timber
;
abstract
class
AbstractOAuthFragment
extends
AbstractWebViewFragment
{
public
abstract
class
AbstractOAuthFragment
extends
AbstractWebViewFragment
{
protected
String
serverConfigId
;
protected
String
hostname
;
...
...
app/src/main/java/chat/rocket/android/fragment/oauth/GitHubOAuthFragment.java
View file @
88174b75
package
chat
.
rocket
.
android
.
fragment
.
oauth
;
import
android.os.Bundle
;
import
android.util.Base64
;
import
chat.rocket.android.model.ddp.MeteorLoginServiceConfiguration
;
import
java.nio.charset.Charset
;
...
...
@@ -10,17 +9,6 @@ import timber.log.Timber;
public
class
GitHubOAuthFragment
extends
AbstractOAuthFragment
{
/**
* create new Fragment with ServerConfig-ID.
*/
public
static
GitHubOAuthFragment
create
(
final
String
serverConfigId
)
{
Bundle
args
=
new
Bundle
();
args
.
putString
(
"serverConfigId"
,
serverConfigId
);
GitHubOAuthFragment
fragment
=
new
GitHubOAuthFragment
();
fragment
.
setArguments
(
args
);
return
fragment
;
}
@Override
protected
String
getOAuthServiceName
()
{
return
"github"
;
}
...
...
app/src/main/java/chat/rocket/android/fragment/oauth/GoogleOAuthFragment.java
0 → 100644
View file @
88174b75
package
chat
.
rocket
.
android
.
fragment
.
oauth
;
import
android.util.Base64
;
import
chat.rocket.android.model.ddp.MeteorLoginServiceConfiguration
;
import
java.nio.charset.Charset
;
import
okhttp3.HttpUrl
;
import
org.json.JSONObject
;
import
timber.log.Timber
;
public
class
GoogleOAuthFragment
extends
AbstractOAuthFragment
{
@Override
protected
String
getOAuthServiceName
()
{
return
"google"
;
}
@Override
protected
String
generateURL
(
MeteorLoginServiceConfiguration
oauthConfig
)
{
final
String
clientId
=
oauthConfig
.
getClientId
();
try
{
String
state
=
Base64
.
encodeToString
(
new
JSONObject
().
put
(
"loginStyle"
,
"popup"
)
.
put
(
"credentialToken"
,
"google"
+
System
.
currentTimeMillis
())
.
put
(
"isCordova"
,
true
)
.
toString
()
.
getBytes
(
Charset
.
forName
(
"UTF-8"
)),
Base64
.
NO_WRAP
);
return
new
HttpUrl
.
Builder
().
scheme
(
"https"
)
.
host
(
"accounts.google.com"
)
.
addPathSegment
(
"o"
)
.
addPathSegment
(
"oauth2"
)
.
addPathSegment
(
"auth"
)
.
addQueryParameter
(
"response_type"
,
"code"
)
.
addQueryParameter
(
"client_id"
,
clientId
)
.
addQueryParameter
(
"scope"
,
"profile email"
)
.
addQueryParameter
(
"redirect_uri"
,
"https://"
+
hostname
+
"/_oauth/google?close"
)
.
addQueryParameter
(
"state"
,
state
)
.
build
()
.
toString
();
}
catch
(
Exception
exception
)
{
Timber
.
e
(
exception
,
"failed to generate Google OAUth URL"
);
}
return
null
;
}
}
app/src/main/java/chat/rocket/android/fragment/oauth/TwitterOAuthFragment.java
View file @
88174b75
package
chat
.
rocket
.
android
.
fragment
.
oauth
;
import
android.os.Bundle
;
import
android.util.Base64
;
import
chat.rocket.android.model.ddp.MeteorLoginServiceConfiguration
;
import
java.nio.charset.Charset
;
...
...
@@ -9,17 +8,6 @@ import timber.log.Timber;
public
class
TwitterOAuthFragment
extends
AbstractOAuthFragment
{
/**
* create new Fragment with ServerConfig-ID.
*/
public
static
TwitterOAuthFragment
create
(
final
String
serverConfigId
)
{
Bundle
args
=
new
Bundle
();
args
.
putString
(
"serverConfigId"
,
serverConfigId
);
TwitterOAuthFragment
fragment
=
new
TwitterOAuthFragment
();
fragment
.
setArguments
(
args
);
return
fragment
;
}
@Override
protected
String
getOAuthServiceName
()
{
return
"twitter"
;
}
...
...
app/src/main/java/chat/rocket/android/fragment/server_config/LoginFragment.java
View file @
88174b75
...
...
@@ -3,17 +3,19 @@ package chat.rocket.android.fragment.server_config;
import
android.os.Bundle
;
import
android.support.annotation.Nullable
;
import
android.support.design.widget.Snackbar
;
import
android.support.v4.app.Fragment
;
import
android.view.View
;
import
android.widget.TextView
;
import
chat.rocket.android.R
;
import
chat.rocket.android.fragment.oauth.GitHubOAuthFragment
;
import
chat.rocket.android.api.MethodCallHelper
;
import
chat.rocket.android.fragment.oauth.TwitterOAuthFragment
;
import
chat.rocket.android.helper.TextUtils
;
import
chat.rocket.android.layouthelper.oauth.OAuthProviderInfo
;
import
chat.rocket.android.model.ddp.MeteorLoginServiceConfiguration
;
import
chat.rocket.android.realm_helper.RealmListObserver
;
import
chat.rocket.android.realm_helper.RealmStore
;
import
java.util.HashMap
;
import
java.util.List
;
import
timber.log.Timber
;
/**
* Login screen.
...
...
@@ -68,30 +70,42 @@ public class LoginFragment extends AbstractServerConfigFragment {
}
private
void
onRenderAuthProviders
(
List
<
MeteorLoginServiceConfiguration
>
authProviders
)
{
final
View
btnTwitter
=
rootView
.
findViewById
(
R
.
id
.
btn_login_with_twitter
);
final
View
btnGitHub
=
rootView
.
findViewById
(
R
.
id
.
btn_login_with_github
);
HashMap
<
String
,
View
>
viewMap
=
new
HashMap
<>();
HashMap
<
String
,
Boolean
>
supportedMap
=
new
HashMap
<>();
for
(
OAuthProviderInfo
info
:
OAuthProviderInfo
.
LIST
)
{
viewMap
.
put
(
info
.
serviceName
,
rootView
.
findViewById
(
info
.
buttonId
));
supportedMap
.
put
(
info
.
serviceName
,
false
);
}
boolean
hasTwitter
=
false
;
boolean
hasGitHub
=
false
;
for
(
MeteorLoginServiceConfiguration
authProvider
:
authProviders
)
{
if
(!
hasTwitter
&&
"twitter"
.
equals
(
authProvider
.
getService
()))
{
hasTwitter
=
true
;
btnTwitter
.
setOnClickListener
(
view
->
{
showFragmentWithBackStack
(
TwitterOAuthFragment
.
create
(
serverConfigId
));
});
}
if
(!
hasGitHub
&&
"github"
.
equals
(
authProvider
.
getService
()))
{
hasGitHub
=
true
;
btnGitHub
.
setOnClickListener
(
view
->
{
showFragmentWithBackStack
(
GitHubOAuthFragment
.
create
(
serverConfigId
));
});
for
(
OAuthProviderInfo
info
:
OAuthProviderInfo
.
LIST
)
{
if
(!
supportedMap
.
get
(
info
.
serviceName
)
&&
info
.
serviceName
.
equals
(
authProvider
.
getService
()))
{
supportedMap
.
put
(
info
.
serviceName
,
true
);
viewMap
.
get
(
info
.
serviceName
).
setOnClickListener
(
view
->
{
Fragment
fragment
=
null
;
try
{
fragment
=
info
.
fragmentClass
.
newInstance
();
}
catch
(
java
.
lang
.
InstantiationException
|
IllegalAccessException
exception
)
{
Timber
.
w
(
exception
,
"failed to create new Fragment"
);
}
if
(
fragment
!=
null
)
{
Bundle
args
=
new
Bundle
();
args
.
putString
(
"serverConfigId"
,
serverConfigId
);
fragment
.
setArguments
(
args
);
showFragmentWithBackStack
(
fragment
);
}
});
viewMap
.
get
(
info
.
serviceName
).
setVisibility
(
View
.
VISIBLE
);
}
}
}
btnTwitter
.
setVisibility
(
hasTwitter
?
View
.
VISIBLE
:
View
.
GONE
);
btnGitHub
.
setVisibility
(
hasGitHub
?
View
.
VISIBLE
:
View
.
GONE
);
for
(
OAuthProviderInfo
info
:
OAuthProviderInfo
.
LIST
)
{
if
(!
supportedMap
.
get
(
info
.
serviceName
))
{
viewMap
.
get
(
info
.
serviceName
).
setVisibility
(
View
.
GONE
);
}
}
}
@Override
public
void
onResume
()
{
...
...
app/src/main/java/chat/rocket/android/layouthelper/oauth/OAuthProviderInfo.java
0 → 100644
View file @
88174b75
package
chat
.
rocket
.
android
.
layouthelper
.
oauth
;
import
chat.rocket.android.R
;
import
chat.rocket.android.fragment.oauth.AbstractOAuthFragment
;
import
chat.rocket.android.fragment.oauth.GitHubOAuthFragment
;
import
chat.rocket.android.fragment.oauth.GoogleOAuthFragment
;
import
chat.rocket.android.fragment.oauth.TwitterOAuthFragment
;
import
java.util.ArrayList
;
public
class
OAuthProviderInfo
{
public
String
serviceName
;
public
int
buttonId
;
public
Class
<?
extends
AbstractOAuthFragment
>
fragmentClass
;
public
OAuthProviderInfo
(
String
serviceName
,
int
buttonId
,
Class
<?
extends
AbstractOAuthFragment
>
fragmentClass
)
{
this
.
serviceName
=
serviceName
;
this
.
buttonId
=
buttonId
;
this
.
fragmentClass
=
fragmentClass
;
}
public
static
ArrayList
<
OAuthProviderInfo
>
LIST
=
new
ArrayList
<
OAuthProviderInfo
>()
{
{
add
(
new
OAuthProviderInfo
(
"twitter"
,
R
.
id
.
btn_login_with_twitter
,
TwitterOAuthFragment
.
class
));
add
(
new
OAuthProviderInfo
(
"github"
,
R
.
id
.
btn_login_with_github
,
GitHubOAuthFragment
.
class
));
add
(
new
OAuthProviderInfo
(
"google"
,
R
.
id
.
btn_login_with_google
,
GoogleOAuthFragment
.
class
));
}
};
}
app/src/main/res/layout/fragment_login.xml
View file @
88174b75
...
...
@@ -27,6 +27,15 @@
android:text=
"@string/fa_twitter"
android:textSize=
"16dp"
/>
<chat.rocket.android.widget.FontAwesomeButton
android:id=
"@+id/btn_login_with_facebook"
android:layout_width=
"48dp"
android:layout_height=
"48dp"
android:enabled=
"false"
android:layout_marginEnd=
"@dimen/margin_8"
android:text=
"@string/fa_facebook_official"
android:textSize=
"16dp"
/>
<chat.rocket.android.widget.FontAwesomeButton
android:id=
"@+id/btn_login_with_github"
android:layout_width=
"48dp"
...
...
@@ -34,6 +43,15 @@
android:layout_marginEnd=
"@dimen/margin_8"
android:text=
"@string/fa_github"
android:textSize=
"16dp"
/>
<chat.rocket.android.widget.FontAwesomeButton
android:id=
"@+id/btn_login_with_google"
android:layout_width=
"48dp"
android:layout_height=
"48dp"
android:layout_marginEnd=
"@dimen/margin_8"
android:text=
"@string/fa_google"
android:textSize=
"16dp"
/>
</LinearLayout>
<android.support.design.widget.TextInputLayout
...
...
app/src/main/res/values/fa_strings.xml
View file @
88174b75
...
...
@@ -3,6 +3,8 @@
<string
name=
"fa_chevron_down"
translatable=
"false"
>

</string>
<string
name=
"fa_twitter"
translatable=
"false"
>

</string>
<string
name=
"fa_github"
translatable=
"false"
>

</string>
<string
name=
"fa_google"
translatable=
"false"
>

</string>
<string
name=
"fa_facebook_official"
translatable=
"false"
>

</string>
<string
name=
"fa_plus"
translatable=
"false"
>

</string>
<string
name=
"fa_sign_out"
translatable=
"false"
>

</string>
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment