-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement a reusable webview fragment with SSO login support #524
Conversation
PruthiviRaj27
commented
May 17, 2023
•
edited
Loading
edited
- In this commit Add a Webview fragment with SSO login support
- This can be reused in any activity/fragment
- This will reduce redundant code.
9ddeeea
to
f35c6a8
Compare
6355f15
to
6fc9549
Compare
d10615d
to
8e0ac31
Compare
private var mCM: String? = null | ||
private var mUM: ValueCallback<Uri?>? = null | ||
private var mUMA: ValueCallback<Array<Uri>?>? = null | ||
private val FCR = 1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
?
} | ||
} | ||
|
||
override fun onActivityResult(requestCode: Int, resultCode: Int, intent: Intent?) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't this depreceated?
if (Build.VERSION.SDK_INT >= 21) { | ||
var results: Array<Uri>? = null | ||
|
||
//Check if response is positive | ||
if (resultCode == RESULT_OK) { | ||
if (requestCode == FCR) { | ||
|
||
if (mUMA == null) { | ||
return | ||
} | ||
if (intent == null) { | ||
//Capture Photo if no image available | ||
if (mCM != null) { | ||
results = arrayOf(Uri.parse(mCM)) | ||
} | ||
} else { | ||
val dataString = intent.dataString | ||
if (dataString != null) { | ||
results = arrayOf(Uri.parse(dataString)) | ||
} | ||
} | ||
} | ||
} | ||
mUMA?.onReceiveValue(results) | ||
mUMA = null | ||
} else { | ||
|
||
if (requestCode == FCR) { | ||
if (mUM == null) return | ||
val result = if (intent == null || resultCode != RESULT_OK) null else intent.data | ||
mUM?.onReceiveValue(result) | ||
mUM = null | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
?
private inner class CustomWevChromeClient : WebChromeClient() { | ||
|
||
override fun onShowFileChooser( | ||
webView: WebView?, filePathCallback: ValueCallback<Array<Uri>?>?, | ||
fileChooserParams: FileChooserParams? | ||
): Boolean { | ||
if (mUMA != null) { | ||
mUMA?.onReceiveValue(null) | ||
} | ||
mUMA = filePathCallback | ||
var takePictureIntent: Intent? = Intent(MediaStore.ACTION_IMAGE_CAPTURE) | ||
if (takePictureIntent!!.resolveActivity(this@WebViewFragment.requireActivity().packageManager) != null) { | ||
var photoFile: File? = null | ||
try { | ||
photoFile = createImageFile() | ||
takePictureIntent.putExtra("PhotoPath", mCM) | ||
} catch (ex: IOException) { | ||
Log.e(TAG, "Image file creation failed", ex) | ||
} | ||
if (photoFile != null) { | ||
mCM = "file:" + photoFile.absolutePath | ||
takePictureIntent!!.putExtra( | ||
MediaStore.EXTRA_OUTPUT, | ||
Uri.fromFile(photoFile) | ||
) | ||
} else { | ||
takePictureIntent = null | ||
} | ||
} | ||
val contentSelectionIntent = Intent(Intent.ACTION_GET_CONTENT) | ||
contentSelectionIntent.addCategory(Intent.CATEGORY_OPENABLE) | ||
contentSelectionIntent.type = "*/*" | ||
val intentArray: Array<Intent?> = | ||
takePictureIntent?.let { arrayOf(it) } ?: arrayOfNulls(0) | ||
val chooserIntent = Intent(Intent.ACTION_CHOOSER) | ||
chooserIntent.putExtra(Intent.EXTRA_INTENT, contentSelectionIntent) | ||
chooserIntent.putExtra(Intent.EXTRA_TITLE, "Image Chooser") | ||
chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, intentArray) | ||
startActivityForResult(chooserIntent, FCR) | ||
return true |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Extract into meaningful methods?
import java.text.SimpleDateFormat | ||
import java.util.* | ||
|
||
class CustomWevChromeClient(val fragment: WebViewFragment) : WebChromeClient() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
.