feat: some extensions, dependencies, and layouts added
This commit is contained in:
parent
ec4f09c455
commit
df0836852d
@ -35,9 +35,14 @@ android {
|
|||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
|
implementation("org.testng:testng:6.9.6")
|
||||||
defaultLibrary()
|
defaultLibrary()
|
||||||
|
|
||||||
|
val version = "2.24.0"
|
||||||
|
testImplementation("org.mockito:mockito-core:${version}")
|
||||||
|
androidTestImplementation("org.mockito:mockito-android:${version}")
|
||||||
|
|
||||||
|
implementation("androidx.paging:paging-runtime:3.3.6")
|
||||||
implementation("androidx.swiperefreshlayout:swiperefreshlayout:1.2.0-alpha01")
|
implementation("androidx.swiperefreshlayout:swiperefreshlayout:1.2.0-alpha01")
|
||||||
|
|
||||||
val ktorClientCore = "3.0.3"
|
val ktorClientCore = "3.0.3"
|
||||||
@ -54,9 +59,6 @@ dependencies {
|
|||||||
implementation(Dependencies.AndroidX.Navigation.fragment)
|
implementation(Dependencies.AndroidX.Navigation.fragment)
|
||||||
implementation(Dependencies.AndroidX.Navigation.navigationUi)
|
implementation(Dependencies.AndroidX.Navigation.navigationUi)
|
||||||
|
|
||||||
implementation(Dependencies.Retrofit.library)
|
|
||||||
implementation(Dependencies.Retrofit.gsonConverter)
|
|
||||||
|
|
||||||
implementation("com.squareup.picasso:picasso:2.8")
|
implementation("com.squareup.picasso:picasso:2.8")
|
||||||
implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.7.3")
|
implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.7.3")
|
||||||
implementation("androidx.datastore:datastore-preferences:1.1.2")
|
implementation("androidx.datastore:datastore-preferences:1.1.2")
|
||||||
|
@ -0,0 +1,22 @@
|
|||||||
|
package ru.myitschool.work.utils
|
||||||
|
|
||||||
|
import android.content.Context
|
||||||
|
import android.net.ConnectivityManager
|
||||||
|
import android.net.NetworkCapabilities
|
||||||
|
|
||||||
|
fun isOnline(context: Context): Boolean {
|
||||||
|
val connectivityManager =
|
||||||
|
context.getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager
|
||||||
|
val capabilities =
|
||||||
|
connectivityManager.getNetworkCapabilities(connectivityManager.activeNetwork)
|
||||||
|
if (capabilities != null) {
|
||||||
|
if (capabilities.hasTransport(NetworkCapabilities.TRANSPORT_CELLULAR)) {
|
||||||
|
return true
|
||||||
|
} else if (capabilities.hasTransport(NetworkCapabilities.TRANSPORT_WIFI)) {
|
||||||
|
return true
|
||||||
|
} else if (capabilities.hasTransport(NetworkCapabilities.TRANSPORT_ETHERNET)) {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
@ -1,18 +1,19 @@
|
|||||||
package ru.myitschool.work.utils
|
package ru.myitschool.work.utils
|
||||||
|
|
||||||
import androidx.fragment.app.Fragment
|
import androidx.fragment.app.Fragment
|
||||||
import androidx.lifecycle.flowWithLifecycle
|
import androidx.lifecycle.Lifecycle
|
||||||
import androidx.lifecycle.lifecycleScope
|
import androidx.lifecycle.lifecycleScope
|
||||||
|
import androidx.lifecycle.repeatOnLifecycle
|
||||||
import kotlinx.coroutines.flow.Flow
|
import kotlinx.coroutines.flow.Flow
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
|
|
||||||
inline fun <T> Flow<T>.collectWithLifecycle(
|
fun <T> Flow<T>.collectWithLifecycle(
|
||||||
fragment: Fragment,
|
fragment: Fragment,
|
||||||
crossinline collector: (T) -> Unit
|
function: suspend (T) -> Unit
|
||||||
) {
|
) {
|
||||||
fragment.viewLifecycleOwner.lifecycleScope.launch {
|
fragment.viewLifecycleOwner.lifecycleScope.launch {
|
||||||
flowWithLifecycle(fragment.viewLifecycleOwner.lifecycle).collect { value ->
|
fragment.repeatOnLifecycle(Lifecycle.State.STARTED) {
|
||||||
collector(value)
|
collect { function.invoke(it) }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
BIN
app/src/main/res/drawable/no_wifi_pic.png
Normal file
BIN
app/src/main/res/drawable/no_wifi_pic.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 55 KiB |
@ -0,0 +1,54 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8" ?>
|
||||||
|
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
app:layout_behavior="com.google.android.material.bottomsheet.BottomSheetBehavior"
|
||||||
|
app:layout_constraintBottom_toBottomOf="parent">
|
||||||
|
|
||||||
|
<com.google.android.material.bottomsheet.BottomSheetDragHandleView
|
||||||
|
android:id="@+id/drag_handle"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
app:layout_constraintTop_toTopOf="parent" />
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginHorizontal="24dp"
|
||||||
|
android:layout_marginTop="20dp"
|
||||||
|
android:gravity="center_horizontal"
|
||||||
|
android:orientation="vertical"
|
||||||
|
app:layout_constraintTop_toBottomOf="@id/drag_handle">
|
||||||
|
|
||||||
|
<ImageView
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:src="@drawable/no_wifi_pic" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="@string/offline_error"
|
||||||
|
android:textFontWeight="700"
|
||||||
|
android:textSize="24sp" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:gravity="center"
|
||||||
|
android:text="@string/no_internet_instructions"
|
||||||
|
android:textFontWeight="400"
|
||||||
|
android:textSize="18sp" />
|
||||||
|
|
||||||
|
<Button
|
||||||
|
android:foreground="?attr/selectableItemBackground"
|
||||||
|
android:textColor="@color/white"
|
||||||
|
android:layout_marginTop="16dp"
|
||||||
|
android:id="@+id/close"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="@string/to_main_menu"
|
||||||
|
android:background="@drawable/main_button" />
|
||||||
|
</LinearLayout>
|
||||||
|
</androidx.constraintlayout.widget.ConstraintLayout>
|
Loading…
x
Reference in New Issue
Block a user