Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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
35 changes: 35 additions & 0 deletions core/src/main/java/in/testpress/fragments/WebViewFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -43,28 +43,63 @@ class WebViewFragment : Fragment(), EmptyViewListener {

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
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")
Comment on lines +48 to +53
Copy link
Copy Markdown

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()

}

override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
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")
Comment on lines +61 to +66
Copy link
Copy Markdown

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)

return layout.root
}

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)

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")
Comment on lines +73 to +104
Copy link
Copy Markdown

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()

}

override fun onDestroy() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import android.webkit.*
class CustomWebViewClient(val fragment: WebViewFragment) : WebViewClient() {

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

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.


override fun shouldOverrideUrlLoading(view: WebView?, request: WebResourceRequest?): Boolean {
val url = request?.url.toString()
Expand Down Expand Up @@ -36,10 +37,23 @@ class CustomWebViewClient(val fragment: WebViewFragment) : WebViewClient() {
}

override fun onPageStarted(view: WebView?, url: String?, favicon: Bitmap?) {
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")
Copy link
Copy Markdown

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.

if (fragment.showLoadingBetweenPages) fragment.showLoading()
}

override fun onPageFinished(view: WebView?, url: String?) {
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", "========================================")

Comment on lines +129 to +138
Copy link
Copy Markdown

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.

fragment.hideLoading()
fragment.hideEmptyViewShowWebView()
checkWebViewHasError()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,31 +25,52 @@ class AIChatPdfFragment : Fragment() {
container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
return inflater.inflate(R.layout.ai_pdf_fragment, container, false)
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
Comment on lines +28 to +34
Copy link
Copy Markdown

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)

}

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)

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")
Comment on lines +40 to +73
Copy link
Copy Markdown

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()

}

private fun getPdfUrl(courseId: Long, contentId: Long): String {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,22 +114,36 @@ class DocumentViewerFragment : BaseContentDetailFragment(), PdfDownloadListener,


private fun showAIView() {
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")
Comment on lines +117 to +146
Copy link
Copy Markdown

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()


isAIView = true
activity?.invalidateOptionsMenu()
Expand Down