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

Implemented Auto Refresh for WebView #77

Merged
merged 12 commits into from
May 27, 2020
Merged

Implemented Auto Refresh for WebView #77

merged 12 commits into from
May 27, 2020

Commits on May 25, 2020

  1. Updated Libs using refreshVersions

    Updated Libs and changed strings in implementations to variables in Libs object
    nizarmah committed May 25, 2020
    Configuration menu
    Copy the full SHA
    fdb7e5a View commit details
    Browse the repository at this point in the history
  2. Configuration menu
    Copy the full SHA
    fabe47e View commit details
    Browse the repository at this point in the history
  3. Added Kotlin Coroutines Dependency

    Updated Kotlin Version to v1.3.71 since Kotlin Coroutines v1.3.7 are only supported with Kotlin v1.3.7+
    nizarmah committed May 25, 2020
    Configuration menu
    Copy the full SHA
    a60775e View commit details
    Browse the repository at this point in the history
  4. Enabled MutliDex for DEV Android App

    Added multidex following android docs, https://developer.android.com/studio/build/multidex
    nizarmah committed May 25, 2020
    Configuration menu
    Copy the full SHA
    a517dea View commit details
    Browse the repository at this point in the history
  5. Added NetworkStatusEvent and NetworkStatus for EventBus

    NetworkStatusEvent will be used with EventBus, it will carry the NetworkStatus to Listeners or Subscribers to that Event
    
    Once the NetworkStatusEvent is received, certain actions will be taken, depending on if the device is online or offline.
    nizarmah committed May 25, 2020
    Configuration menu
    Copy the full SHA
    17c592c View commit details
    Browse the repository at this point in the history
  6. Added NetworkUtils to Check if Device is Online/Offline

    Checking if user is online is done through opening a socket with 8.8.8.8 (google dns). This online check is according to the stackoverflow answer linked below. It is faster than other options.
    
    https://stackoverflow.com/a/27312494/5512292
    nizarmah committed May 25, 2020
    Configuration menu
    Copy the full SHA
    e54fc7f View commit details
    Browse the repository at this point in the history
  7. Added NetworkWatcher BroadcastReceiver to Know When Device is Back On…

    …line
    
    This is used in order to check if the device is back online. Once the device's connectivity changes, ie is connected to internet after being offline, it posts an Event indicating the device is back online.
    nizarmah committed May 25, 2020
    Configuration menu
    Copy the full SHA
    57d8a38 View commit details
    Browse the repository at this point in the history
  8. Implemented WebView Auto Refresh using Network Observer

    A coroutine scope is started in the main activity, in oder to prevent work leaks. onDestroy, all coroutines are cancelled.
    
    The webview client takes the coroutine scope, again to avoid work leaks, and utilizes it to check if the user is offline when the webview client receives an error
    
    Once the webview client receives an error, an Event indicating the user is offline is posted.
    
    The webview client is subscribed to the NetworkStatusEvent in order to know the network status. Once the device is offline, the network watcher is started (a broadcast receiver waits until the device is back online). Once the device is back online, the network watcher is stopped and the webview is refreshed
    
    It is important to note that the webview client is not automatically registered to the Event. This is because we want to avoid leaks. Therefore, whenever it is manually registered, it should be manually unregistered.
    nizarmah committed May 25, 2020
    Configuration menu
    Copy the full SHA
    edbf645 View commit details
    Browse the repository at this point in the history
  9. Changed Online Check Hostname to dev.to

    Uses hostname instead of url, so created BuildConfig.baseHostname instead of trimming the 'https://' and '/' segments of the BuildConfig.baseUrl. This gives for easier changes later on in the future.
    
    Also, @fdoxyz requested that change in order to reconnect to the website once it is up again, if it was down. Mentioned in pull request #77.
    nizarmah committed May 25, 2020
    Configuration menu
    Copy the full SHA
    442002a View commit details
    Browse the repository at this point in the history
  10. Cleared Network Watcher Variable to Null on Unregistration in WebView…

    …Client
    
    Previously, an exception was being thrown due to unregistering a network watcher and then trying to unregister it again later on. Now, since it is being cleared back to null, it is no longer being unregistered again if it was previously unregistered
    nizarmah committed May 25, 2020
    Configuration menu
    Copy the full SHA
    036f977 View commit details
    Browse the repository at this point in the history

Commits on May 26, 2020

  1. Fixed Multiple Re-Registrations for Network Watcher

    onReceiveError was being called multiple times, this was resulting in multiple events being posted indicating that the device is offline. Accordingly, it was important to stop re-registering the networkWatcher again and again whenever the events were captured. However, it was previously done in case the coroutineScope did change. However, if the coroutineScope changes, the activity has probably died and been recreated. Therefore, the webview would have already been destroyed and recreated with the new scope. Thus, there is no need to re-register a network watcher if it has already been registered
    nizarmah committed May 26, 2020
    Configuration menu
    Copy the full SHA
    1cc26c7 View commit details
    Browse the repository at this point in the history

Commits on May 27, 2020

  1. Merge branch 'master' of github.com:thepracticaldev/DEV-Android into …

    …bug/auto-refresh
    
    # Conflicts:
    #	app/build.gradle.kts
    fdocr committed May 27, 2020
    Configuration menu
    Copy the full SHA
    b4f1a59 View commit details
    Browse the repository at this point in the history