Skip to content
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

Merged
merged 23 commits into from
Jun 12, 2023

Conversation

PruthiviRaj27
Copy link
Contributor

@PruthiviRaj27 PruthiviRaj27 commented May 17, 2023

  • In this commit Add a Webview fragment with SSO login support
  • This can be reused in any activity/fragment
  • This will reduce redundant code.

Comment on lines 50 to 53
private var mCM: String? = null
private var mUM: ValueCallback<Uri?>? = null
private var mUMA: ValueCallback<Array<Uri>?>? = null
private val FCR = 1
Copy link
Contributor

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?) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't this depreceated?

@PruthiviRaj27 PruthiviRaj27 changed the title refactor: activity to fragment Implement a reusable webview fragment with SSO login support Jun 8, 2023
Comment on lines 221 to 253
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
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

?

Comment on lines 310 to 349
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
Copy link
Contributor

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() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

.

@Karthik-0 Karthik-0 merged commit 94b1889 into master Jun 12, 2023
@delete-merged-branch delete-merged-branch bot deleted the webview_fragment branch June 12, 2023 05:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants