first excuse me for my poor English i'm looking for some sample code or Tutorial on how to use UIManager in Android GITKIT to produce customized UI for user Authentication, but i didn't find anything. please guide me thanx
1 Answers
First of all its not your fault and gitkit is poorly documented. As for the implementation itself, first you need to copy paste the code here (from the docs):
public class MyLoginActivity extends Activity {
private GitkitClient client;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// If there is no signed in user, create a GitkitClient to start sign in flow.
SignInCallbacks callbacks = new SignInCallbacks() {
// Implement the onSignIn method of GitkitClient.SignInCallbacks interface.
@Override
public void onSignIn(IdToken idToken, GitkitUser gitkitUser) {
// Send the idToken to the server. The server should issue a session cookie/token
// for the app if the idToken is verified.
authenticate(idToken.getTokenString());
...
}
// Implement the onSignInFailed method of GitkitClient.SignInCallbacks interface.
@Override
public void onSignInFailed() {
// Handle the sign in failure.
...
}
}
// The example suppose all necessary configurations are set in the AndroidManifest.xml.
// You can also set or overwrite them by calling the corresponding setters on the
// GitkitClientBuilder.
client = GitkitClient.newBuilder(this, callbacks).setUiManager(new MyUiManger()).build();
// Start sign in flow.
client.startSignIn();
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (client.handleActivityResult(requestCode, resultCode, data)) {
// result is handled by GitkitClient.
return;
}
// Otherwise, the result is not returned to GitkitClient and should be handled by the
// activity.
...
}
@Override
protected void onNewIntent(Intent intent) {
if (client.handleIntent(intent)) {
// intent is handled by the GitkitClient.
return;
}
// Otherwise, the intent is not for GitkitClient and should be handled by the activity.
...
}
}
Then you should implement a MyUIManger and paying attention to the method:
@Override
public void setRequestHandler(RequestHandler requestHandler) {
//store requestHandler somewhere accessible.
}
Since this is the object that you should send all your UI inputs to.
Regarding the rest of MyUIManager, Complying to the interface described here you should change your screens when these functions are called, and send the user input to the requestHandler with the appropriate request.
for instance, When the client.startSignIn() is called GitKitClient will call MyUIManager.ShowStartSignIn method, so inside that method you should display the relevant screen and send the inputs to the RequestHandler from earlier. something in the lines of:
//in MyUIManager:
@Override
public void showStartSignIn(GitkitUser.UserProfile userProfile) {
//Show start login fragment
}
//some where in the login fragment:
@Override
public void onClick(View view) {
StartSignInRequest request = new StartSignInRequest();
request.setEmail(email);
request.setIdProvider(idProvider);
mRequestHandler.handle(request);
}

- 671
- 6
- 10