Skip to content

fix: Add log cat to check webview delay loading#960

Open
kaaviya98 wants to merge 3 commits intomasterfrom
testing
Open

fix: Add log cat to check webview delay loading#960
kaaviya98 wants to merge 3 commits intomasterfrom
testing

Conversation

@kaaviya98
Copy link
Contributor

Changes done

Reason for the changes

Fixes # .

@gemini-code-assist
Copy link

Summary of Changes

Hello @kaaviya98, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request introduces comprehensive logging across several Android fragments responsible for displaying WebView content, particularly for PDF viewing. The added Logcat statements, complete with timestamps and step indicators, are designed to precisely track the performance and timing of WebView initialization, fragment transactions, and content loading. This will help in identifying and debugging any delays in the WebView's rendering process.

Highlights

  • Performance Monitoring: Detailed Logcat timing statements have been added to key lifecycle methods of WebViewFragment, AIChatPdfFragment, and DocumentViewerFragment to measure the duration of various WebView initialization and loading steps.
  • WebView Client Logging: A pageLoadStartTime variable was introduced in CustomWebViewClient to accurately log the total page load time from onPageStarted to onPageFinished, providing a clear metric for WebView content display.
  • Debugging WebView Delays: The primary purpose of these changes is to diagnose and understand potential delays in WebView loading by providing granular timing information throughout the process, using a consistent 'AI_TIMING' tag.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request adds extensive logging for timing and debugging the WebView loading process. While this is very useful for development and performance analysis, this kind of debug code should not be merged into the main branch. It clutters the codebase, adds noise to production logs, and introduces a small performance overhead. I've added comments to remove this logging from all modified files.

Comment on lines +46 to +51
val startTime = System.currentTimeMillis()
android.util.Log.d("AI_TIMING", "🟦 STEP 8: WebViewFragment.onCreate() STARTED")

parseArguments()

android.util.Log.d("AI_TIMING", "✅ STEP 8 DONE: WebViewFragment.onCreate() completed in ${System.currentTimeMillis() - startTime}ms")

Choose a reason for hiding this comment

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

high

These timing logs appear to be for debugging purposes. They should be removed from the final code to keep the codebase clean and avoid unnecessary logging in production.

Suggested change
val startTime = System.currentTimeMillis()
android.util.Log.d("AI_TIMING", "🟦 STEP 8: WebViewFragment.onCreate() STARTED")
parseArguments()
android.util.Log.d("AI_TIMING", "✅ STEP 8 DONE: WebViewFragment.onCreate() completed in ${System.currentTimeMillis() - startTime}ms")
parseArguments()

Comment on lines +59 to +64
val startTime = System.currentTimeMillis()
android.util.Log.d("AI_TIMING", "🟦 STEP 9: WebViewFragment.onCreateView() STARTED")

_layout = WebviewFragmentBinding.inflate(inflater, container, false)

android.util.Log.d("AI_TIMING", "✅ STEP 9 DONE: WebViewFragment.onCreateView() completed in ${System.currentTimeMillis() - startTime}ms")

Choose a reason for hiding this comment

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

high

This debugging code should be removed before merging. It adds noise to the logs and is not necessary for production builds.

Suggested change
val startTime = System.currentTimeMillis()
android.util.Log.d("AI_TIMING", "🟦 STEP 9: WebViewFragment.onCreateView() STARTED")
_layout = WebviewFragmentBinding.inflate(inflater, container, false)
android.util.Log.d("AI_TIMING", "✅ STEP 9 DONE: WebViewFragment.onCreateView() completed in ${System.currentTimeMillis() - startTime}ms")
_layout = WebviewFragmentBinding.inflate(inflater, container, false)

Comment on lines +71 to +102
val startTime = System.currentTimeMillis()
android.util.Log.d("AI_TIMING", "🟦 STEP 10: WebViewFragment.onViewCreated() STARTED")

showLoading()
android.util.Log.d("AI_TIMING", " Showing loading spinner... (${System.currentTimeMillis() - startTime}ms)")

initializedSwipeRefresh()
android.util.Log.d("AI_TIMING", " Initialized swipe refresh (${System.currentTimeMillis() - startTime}ms)")

initializeEmptyViewFragment()
android.util.Log.d("AI_TIMING", " Initialized empty view fragment (${System.currentTimeMillis() - startTime}ms)")

webView = layout.webView
listener?.onWebViewInitializationSuccess()
android.util.Log.d("AI_TIMING", " WebView reference obtained (${System.currentTimeMillis() - startTime}ms)")

android.util.Log.d("AI_TIMING", "🟦 STEP 11: Calling setupWebView()...")
val setupStart = System.currentTimeMillis()
setupWebView()
android.util.Log.d("AI_TIMING", "✅ STEP 11 DONE: setupWebView() completed in ${System.currentTimeMillis() - setupStart}ms")

android.util.Log.d("AI_TIMING", "🟦 STEP 12: Calling populateInstituteSettings()...")
val settingsStart = System.currentTimeMillis()
populateInstituteSettings()
android.util.Log.d("AI_TIMING", "✅ STEP 12 DONE: populateInstituteSettings() completed in ${System.currentTimeMillis() - settingsStart}ms")

android.util.Log.d("AI_TIMING", "🟦 STEP 13: Calling loadContent() - NETWORK REQUEST STARTS HERE...")
val loadStart = System.currentTimeMillis()
loadContent()
android.util.Log.d("AI_TIMING", "✅ STEP 13 DONE: loadContent() initiated in ${System.currentTimeMillis() - loadStart}ms (network request continues in background)")

android.util.Log.d("AI_TIMING", "✅ STEP 10 DONE: WebViewFragment.onViewCreated() completed in ${System.currentTimeMillis() - startTime}ms total")

Choose a reason for hiding this comment

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

high

The extensive timing logs in this method are useful for debugging but should not be part of the production code. Please remove them to improve readability and avoid log spam.

Suggested change
val startTime = System.currentTimeMillis()
android.util.Log.d("AI_TIMING", "🟦 STEP 10: WebViewFragment.onViewCreated() STARTED")
showLoading()
android.util.Log.d("AI_TIMING", " Showing loading spinner... (${System.currentTimeMillis() - startTime}ms)")
initializedSwipeRefresh()
android.util.Log.d("AI_TIMING", " Initialized swipe refresh (${System.currentTimeMillis() - startTime}ms)")
initializeEmptyViewFragment()
android.util.Log.d("AI_TIMING", " Initialized empty view fragment (${System.currentTimeMillis() - startTime}ms)")
webView = layout.webView
listener?.onWebViewInitializationSuccess()
android.util.Log.d("AI_TIMING", " WebView reference obtained (${System.currentTimeMillis() - startTime}ms)")
android.util.Log.d("AI_TIMING", "🟦 STEP 11: Calling setupWebView()...")
val setupStart = System.currentTimeMillis()
setupWebView()
android.util.Log.d("AI_TIMING", "✅ STEP 11 DONE: setupWebView() completed in ${System.currentTimeMillis() - setupStart}ms")
android.util.Log.d("AI_TIMING", "🟦 STEP 12: Calling populateInstituteSettings()...")
val settingsStart = System.currentTimeMillis()
populateInstituteSettings()
android.util.Log.d("AI_TIMING", "✅ STEP 12 DONE: populateInstituteSettings() completed in ${System.currentTimeMillis() - settingsStart}ms")
android.util.Log.d("AI_TIMING", "🟦 STEP 13: Calling loadContent() - NETWORK REQUEST STARTS HERE...")
val loadStart = System.currentTimeMillis()
loadContent()
android.util.Log.d("AI_TIMING", "✅ STEP 13 DONE: loadContent() initiated in ${System.currentTimeMillis() - loadStart}ms (network request continues in background)")
android.util.Log.d("AI_TIMING", "✅ STEP 10 DONE: WebViewFragment.onViewCreated() completed in ${System.currentTimeMillis() - startTime}ms total")
showLoading()
initializedSwipeRefresh()
initializeEmptyViewFragment()
webView = layout.webView
listener?.onWebViewInitializationSuccess()
setupWebView()
populateInstituteSettings()
loadContent()

class CustomWebViewClient(val fragment: WebViewFragment) : WebViewClient() {

private var errorList = linkedMapOf<WebResourceRequest?,WebResourceResponse?>()
private var pageLoadStartTime: Long = 0

Choose a reason for hiding this comment

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

high

This property is only used for debug logging. It should be removed along with the associated logging code.

Comment on lines +40 to +42
pageLoadStartTime = System.currentTimeMillis()
android.util.Log.d("AI_TIMING", "🟦 STEP 14: WebView.onPageStarted() - URL loading started")
android.util.Log.d("AI_TIMING", " Loading URL: $url")

Choose a reason for hiding this comment

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

high

This debug logging and timing logic should be removed from the production codebase.

Comment on lines +47 to +56
val totalLoadTime = System.currentTimeMillis() - pageLoadStartTime
android.util.Log.d("AI_TIMING", "✅ STEP 14 DONE: WebView.onPageFinished() - Page loaded!")
android.util.Log.d("AI_TIMING", " Loaded URL: $url")
android.util.Log.d("AI_TIMING", " ⏱️ TOTAL PAGE LOAD TIME: ${totalLoadTime}ms")
android.util.Log.d("AI_TIMING", "")
android.util.Log.d("AI_TIMING", "========================================")
android.util.Log.d("AI_TIMING", "🎉 AI WEBVIEW FULLY LOADED AND VISIBLE!")
android.util.Log.d("AI_TIMING", "⏱️ Total time from button click: ${totalLoadTime}ms")
android.util.Log.d("AI_TIMING", "========================================")

Choose a reason for hiding this comment

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

high

This extensive block of debug logging should be removed before merging. It's not suitable for production code.

Comment on lines +28 to +34
val startTime = System.currentTimeMillis()
android.util.Log.d("AI_TIMING", "🟦 STEP 4: AIChatPdfFragment.onCreateView() STARTED")

val view = inflater.inflate(R.layout.ai_pdf_fragment, container, false)

android.util.Log.d("AI_TIMING", "✅ STEP 4 DONE: AIChatPdfFragment.onCreateView() completed in ${System.currentTimeMillis() - startTime}ms")
return view

Choose a reason for hiding this comment

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

high

Please remove the debug timing logs and revert to the original concise implementation.

Suggested change
val startTime = System.currentTimeMillis()
android.util.Log.d("AI_TIMING", "🟦 STEP 4: AIChatPdfFragment.onCreateView() STARTED")
val view = inflater.inflate(R.layout.ai_pdf_fragment, container, false)
android.util.Log.d("AI_TIMING", "✅ STEP 4 DONE: AIChatPdfFragment.onCreateView() completed in ${System.currentTimeMillis() - startTime}ms")
return view
return inflater.inflate(R.layout.ai_pdf_fragment, container, false)

Comment on lines +40 to +73
val startTime = System.currentTimeMillis()
android.util.Log.d("AI_TIMING", "🟦 STEP 5: AIChatPdfFragment.onViewCreated() STARTED")

val contentId = requireArguments().getLong(ARG_CONTENT_ID, -1L)
val courseId = requireArguments().getLong(ARG_COURSE_ID, -1L)

if (contentId == -1L || courseId == -1L) {
throw IllegalArgumentException("Required arguments (contentId, courseId) are missing or invalid.")
}

android.util.Log.d("AI_TIMING", "🟦 STEP 6: Creating WebViewFragment...")
val webViewCreateStart = System.currentTimeMillis()

val webViewFragment = WebViewFragment()

val pdfUrl = getPdfUrl(courseId, contentId)
android.util.Log.d("AI_TIMING", " URL to load: $pdfUrl")

webViewFragment.arguments = Bundle().apply {
putString(URL_TO_OPEN, pdfUrl)
putBoolean(IS_AUTHENTICATION_REQUIRED, true)
}

android.util.Log.d("AI_TIMING", "✅ STEP 6 DONE: WebViewFragment created in ${System.currentTimeMillis() - webViewCreateStart}ms")

android.util.Log.d("AI_TIMING", "🟦 STEP 7: Committing WebViewFragment transaction...")
val transactionStart = System.currentTimeMillis()

childFragmentManager.beginTransaction()
.replace(R.id.aiPdf_view_fragment, webViewFragment)
.commit()

android.util.Log.d("AI_TIMING", "✅ STEP 7 DONE: WebView transaction committed in ${System.currentTimeMillis() - transactionStart}ms")
android.util.Log.d("AI_TIMING", "✅ STEP 5 DONE: AIChatPdfFragment.onViewCreated() completed in ${System.currentTimeMillis() - startTime}ms total")

Choose a reason for hiding this comment

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

high

This extensive debug logging should be removed from the production code. Please revert the body of this method to its original state.

        val contentId = requireArguments().getLong(ARG_CONTENT_ID, -1L)
        val courseId = requireArguments().getLong(ARG_COURSE_ID, -1L)
        
        if (contentId == -1L || courseId == -1L) {
            throw IllegalArgumentException("Required arguments (contentId, courseId) are missing or invalid.")
        }
        
        val webViewFragment = WebViewFragment()
        
        val pdfUrl = getPdfUrl(courseId, contentId)
    
        webViewFragment.arguments = Bundle().apply {
            putString(URL_TO_OPEN, pdfUrl)
            putBoolean(IS_AUTHENTICATION_REQUIRED, true)
        }
    
        childFragmentManager.beginTransaction()
            .replace(R.id.aiPdf_view_fragment, webViewFragment)
            .commit()

Comment on lines +117 to +146
val startTime = System.currentTimeMillis()
android.util.Log.d("AI_TIMING", "🟦 STEP 1: showAIView() STARTED at ${startTime}")

if (aiChatFragment == null) {
android.util.Log.d("AI_TIMING", "🟦 STEP 2: Creating AIChatPdfFragment...")
val fragmentCreateStart = System.currentTimeMillis()

aiChatFragment = AIChatPdfFragment()
val args = Bundle()
args.putLong("contentId", contentId)
args.putLong("courseId", content.courseId ?: -1L)
aiChatFragment?.arguments = args

android.util.Log.d("AI_TIMING", "✅ STEP 2 DONE: Fragment created in ${System.currentTimeMillis() - fragmentCreateStart}ms")
}

binding.pdfView.visibility = View.GONE
binding.bottomNavigationFragment.visibility = View.GONE
binding.askAiFab.visibility = View.GONE
binding.aiPdfViewFragment.visibility = View.VISIBLE

android.util.Log.d("AI_TIMING", "🟦 STEP 3: Committing fragment transaction...")
val transactionStart = System.currentTimeMillis()

childFragmentManager.beginTransaction()
.replace(R.id.aiPdf_view_fragment, aiChatFragment!!)
.commit()

android.util.Log.d("AI_TIMING", "✅ STEP 3 DONE: Transaction committed in ${System.currentTimeMillis() - transactionStart}ms")
android.util.Log.d("AI_TIMING", "✅ showAIView() COMPLETED in ${System.currentTimeMillis() - startTime}ms total")

Choose a reason for hiding this comment

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

high

Please remove the debug logging from this method and restore its original implementation.

Suggested change
val startTime = System.currentTimeMillis()
android.util.Log.d("AI_TIMING", "🟦 STEP 1: showAIView() STARTED at ${startTime}")
if (aiChatFragment == null) {
android.util.Log.d("AI_TIMING", "🟦 STEP 2: Creating AIChatPdfFragment...")
val fragmentCreateStart = System.currentTimeMillis()
aiChatFragment = AIChatPdfFragment()
val args = Bundle()
args.putLong("contentId", contentId)
args.putLong("courseId", content.courseId ?: -1L)
aiChatFragment?.arguments = args
android.util.Log.d("AI_TIMING", "✅ STEP 2 DONE: Fragment created in ${System.currentTimeMillis() - fragmentCreateStart}ms")
}
binding.pdfView.visibility = View.GONE
binding.bottomNavigationFragment.visibility = View.GONE
binding.askAiFab.visibility = View.GONE
binding.aiPdfViewFragment.visibility = View.VISIBLE
android.util.Log.d("AI_TIMING", "🟦 STEP 3: Committing fragment transaction...")
val transactionStart = System.currentTimeMillis()
childFragmentManager.beginTransaction()
.replace(R.id.aiPdf_view_fragment, aiChatFragment!!)
.commit()
android.util.Log.d("AI_TIMING", "✅ STEP 3 DONE: Transaction committed in ${System.currentTimeMillis() - transactionStart}ms")
android.util.Log.d("AI_TIMING", "✅ showAIView() COMPLETED in ${System.currentTimeMillis() - startTime}ms total")
if (aiChatFragment == null) {
aiChatFragment = AIChatPdfFragment()
val args = Bundle()
args.putLong("contentId", contentId)
args.putLong("courseId", content.courseId ?: -1L)
aiChatFragment?.arguments = args
}
binding.pdfView.visibility = View.GONE
binding.bottomNavigationFragment.visibility = View.GONE
binding.askAiFab.visibility = View.GONE
binding.aiPdfViewFragment.visibility = View.VISIBLE
childFragmentManager.beginTransaction()
.replace(R.id.aiPdf_view_fragment, aiChatFragment!!)
.commit()

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.

1 participant