Skip to content
This repository was archived by the owner on Feb 14, 2020. It is now read-only.

Improve styling #39

Merged
merged 2 commits into from
Jul 17, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions library/src/main/java/com/parse/twitter/AsyncCallback.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
package com.parse.twitter;

public interface AsyncCallback {
void onSuccess(Object result);
void onSuccess(Object result);

void onCancel();
void onCancel();

void onFailure(Throwable error);
void onFailure(Throwable error);
}
122 changes: 122 additions & 0 deletions library/src/main/java/com/parse/twitter/OAuth1FlowDialog.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
/*
* Copyright (c) 2015-present, Parse, LLC.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/
package com.parse.twitter;

import android.annotation.SuppressLint;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.graphics.Bitmap;
import android.net.Uri;
import android.os.Bundle;
import android.support.v7.app.AppCompatDialog;
import android.view.View;
import android.view.Window;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.ProgressBar;

/**
* For internal use.
*/
class OAuth1FlowDialog extends AppCompatDialog {

private final String callbackUrl;
private final String requestUrl;
private final String serviceUrlIdentifier;
private final FlowResultHandler handler;

private WebView webView;
private ProgressBar progress;

OAuth1FlowDialog(Context context, String requestUrl, String callbackUrl, String serviceUrlIdentifier, FlowResultHandler resultHandler) {
super(context);
this.requestUrl = requestUrl;
this.callbackUrl = callbackUrl;
this.serviceUrlIdentifier = serviceUrlIdentifier;
this.handler = resultHandler;
this.setOnCancelListener(new OnCancelListener() {
@Override
public void onCancel(DialogInterface dialog) {
handler.onCancel();
}
});
}

@SuppressLint("SetJavaScriptEnabled")
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.parse_twitter_dialog_login);
webView = findViewById(R.id.webView);
progress = findViewById(R.id.progress);

webView.setVerticalScrollBarEnabled(false);
webView.setHorizontalScrollBarEnabled(false);
webView.setWebViewClient(new OAuth1WebViewClient());
webView.getSettings().setJavaScriptEnabled(true);
webView.loadUrl(requestUrl);
}

public interface FlowResultHandler {
/**
* Called when the user cancels the dialog.
*/
void onCancel();

/**
* Called when the dialog's web view receives an error.
*/
void onError(int errorCode, String description, String failingUrl);

/**
* Called when the dialog portion of the flow is complete.
*
* @param callbackUrl The final URL called back (including any query string appended
* by the server).
*/
void onComplete(String callbackUrl);
}

private class OAuth1WebViewClient extends WebViewClient {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
if (url.startsWith(callbackUrl)) {
OAuth1FlowDialog.this.dismiss();
handler.onComplete(url);
return true;
} else if (url.contains(serviceUrlIdentifier)) {
return false;
}
// launch non-service URLs in a full browser
getContext().startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(url)));
return true;
}

@Override
public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
super.onReceivedError(view, errorCode, description, failingUrl);
OAuth1FlowDialog.this.dismiss();
handler.onError(errorCode, description, failingUrl);
}

@Override
public void onPageStarted(WebView view, String url, Bitmap favicon) {
super.onPageStarted(view, url, favicon);
progress.setVisibility(View.VISIBLE);
}

@Override
public void onPageFinished(WebView view, String url) {
super.onPageFinished(view, url);
progress.setVisibility(View.GONE);
}
}
}
39 changes: 39 additions & 0 deletions library/src/main/java/com/parse/twitter/OAuth1FlowException.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* Copyright (c) 2015-present, Parse, LLC.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/
package com.parse.twitter;

/**
* OAuth Flow exception
*/
public class OAuth1FlowException extends Exception {
private static final long serialVersionUID = 4272662026279290823L;
private final int errorCode;
private final String description;
private final String failingUrl;

public OAuth1FlowException(int errorCode, String description, String failingUrl) {
super(String.format("OAuth Flow Error %d: Url: %s Description: %s", errorCode, failingUrl,
description));
this.errorCode = errorCode;
this.description = description;
this.failingUrl = failingUrl;
}

public int getErrorCode() {
return errorCode;
}

public String getDescription() {
return description;
}

public String getFailingUrl() {
return failingUrl;
}
}
Loading