-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
157 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
app/src/main/java/com/android/mediproject/NetworkStateDialogFragment.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package com.android.mediproject | ||
|
||
import android.os.Bundle | ||
import android.view.LayoutInflater | ||
import android.view.View | ||
import android.view.ViewGroup | ||
import com.google.android.material.bottomsheet.BottomSheetDialogFragment | ||
import dagger.hilt.android.AndroidEntryPoint | ||
|
||
@AndroidEntryPoint | ||
class NetworkStateDialogFragment : BottomSheetDialogFragment() { | ||
|
||
private var _binding: BindingView | ||
|
||
override fun onCreateView( | ||
inflater: LayoutInflater, | ||
container: ViewGroup?, | ||
savedInstanceState: Bundle? | ||
): View? = inflater.inflate(R.layout.modal_bottom_sheet_content, container, false) | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||
xmlns:app="http://schemas.android.com/apk/res-auto" | ||
style="@style/ModalBottomSheetDialog" | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
android:backgroundTint="@color/white" | ||
android:gravity="center" | ||
android:orientation="vertical" | ||
android:paddingHorizontal="24dp" | ||
android:paddingVertical="24dp" | ||
app:layout_behavior="com.google.android.material.bottomsheet.BottomSheetBehavior"> | ||
|
||
<TextView | ||
android:id="@+id/messageTextView" | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
android:layout_marginBottom="16dp" | ||
android:gravity="center" | ||
android:text="@string/noInternetConnection" | ||
android:textSize="22sp" /> | ||
|
||
<Button | ||
android:id="@+id/okButton" | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
android:backgroundTint="@color/main" | ||
android:text="@string/confirm" /> | ||
|
||
</LinearLayout> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,15 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<resources> | ||
|
||
<style name="ModalBottomSheet" parent="Widget.Material3.BottomSheet.Modal"> | ||
<item name="android:backgroundTint">@color/white</item> | ||
<item name="behavior_hideable">false</item> | ||
<item name="behavior_draggable">false</item> | ||
</style> | ||
|
||
<style name="ModalBottomSheetDialog" parent="ThemeOverlay.Material3.BottomSheetDialog"> | ||
<item name="bottomSheetStyle">@style/ModalBottomSheet</item> | ||
</style> | ||
|
||
|
||
</resources> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"> | ||
|
||
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> | ||
</manifest> |
73 changes: 73 additions & 0 deletions
73
core/network/src/main/java/com/android/mediproject/core/network/InternetNetworkListener.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
package com.android.mediproject.core.network | ||
|
||
import android.content.Context | ||
import android.net.ConnectivityManager | ||
import android.net.LinkProperties | ||
import android.net.Network | ||
import android.net.NetworkCapabilities | ||
import android.os.Handler | ||
import androidx.lifecycle.Lifecycle | ||
import androidx.lifecycle.LifecycleEventObserver | ||
import androidx.lifecycle.LifecycleOwner | ||
import dagger.hilt.android.qualifiers.ApplicationContext | ||
import javax.inject.Inject | ||
import javax.inject.Singleton | ||
|
||
@Singleton | ||
class InternetNetworkListener @Inject constructor(@ApplicationContext private val context: Context) : LifecycleEventObserver { | ||
|
||
private val connectivityManager by lazy { | ||
context.getSystemService(ConnectivityManager::class.java) | ||
} | ||
|
||
private val networkCallback: ConnectivityManager.NetworkCallback = object : ConnectivityManager.NetworkCallback() { | ||
override fun onAvailable(network: Network) { | ||
super.onAvailable(network) | ||
networkStateCallback?.onChangedState(true) | ||
} | ||
|
||
override fun onLost(network: Network) { | ||
super.onLost(network) | ||
networkStateCallback?.onChangedState(false) | ||
} | ||
|
||
override fun onCapabilitiesChanged(network: Network, networkCapabilities: NetworkCapabilities) { | ||
super.onCapabilitiesChanged(network, networkCapabilities) | ||
} | ||
|
||
override fun onLinkPropertiesChanged(network: Network, linkProperties: LinkProperties) { | ||
super.onLinkPropertiesChanged(network, linkProperties) | ||
} | ||
} | ||
|
||
fun interface NetworkStateCallback { | ||
fun onChangedState(isConnected: Boolean) | ||
} | ||
|
||
var networkStateCallback: NetworkStateCallback? = null | ||
set(value) { | ||
field = value | ||
connectivityManager.registerDefaultNetworkCallback(networkCallback, | ||
Handler.createAsync(context.mainLooper)) | ||
} | ||
|
||
var activityLifeCycle: Lifecycle? = null | ||
set(value) { | ||
field = value | ||
field?.addObserver(this) | ||
} | ||
|
||
override fun onStateChanged(source: LifecycleOwner, event: Lifecycle.Event) { | ||
when (event) { | ||
Lifecycle.Event.ON_START -> { | ||
connectivityManager.unregisterNetworkCallback(networkCallback) | ||
} | ||
|
||
Lifecycle.Event.ON_PAUSE -> { | ||
networkStateCallback?.onChangedState(false) | ||
} | ||
|
||
else -> {} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters