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

feat(home): add connection status banner #327

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
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
3 changes: 3 additions & 0 deletions app/src/main/java/com/my/kizzy/Kizzy.kt
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,9 @@ internal fun ComponentActivity.Kizzy() {
viewModel.getLatestUpdate()
}
},
checkConnection = {
viewModel.checkConnection()
},
showBadge = showBadge,
features = homeFeaturesProvider(
navigateTo = { navController.navigate(it) },
Expand Down
2 changes: 1 addition & 1 deletion common/resources/src/main/res/values-de/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@
<string name="activity_streaming_title">Streaming at %1$s</string>
<string name="delete_config_successfully_toast">%1$s was deleted successfully</string>
<string name="service_enabled">Service enabled</string>
<string name="no_internet_connection">No internet connection</string>
<string name="no_internet_connection">No Internet connection</string>
<string name="unknown_error">An unexpected error occurred</string>
<string name="rpc_buttons">RPC buttons</string>
<string name="samsungRPC_settings">Enable Samsung RPC</string>
Expand Down
2 changes: 1 addition & 1 deletion common/resources/src/main/res/values-es/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@
<string name="activity_streaming_title">Streaming at %1$s</string>
<string name="delete_config_successfully_toast">%1$s was deleted successfully</string>
<string name="service_enabled">Service enabled</string>
<string name="no_internet_connection">No internet connection</string>
<string name="no_internet_connection">No Internet connection</string>
<string name="unknown_error">An unexpected error occurred</string>
<string name="rpc_buttons">RPC buttons</string>
<string name="samsungRPC_settings">Enable Samsung RPC</string>
Expand Down
2 changes: 1 addition & 1 deletion common/resources/src/main/res/values-fa/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@
<string name="activity_streaming_title">Streaming at %1$s</string>
<string name="delete_config_successfully_toast">%1$s was deleted successfully</string>
<string name="service_enabled">Service enabled</string>
<string name="no_internet_connection">No internet connection</string>
<string name="no_internet_connection">No Internet connection</string>
<string name="unknown_error">An unexpected error occurred</string>
<string name="rpc_buttons">RPC buttons</string>
<string name="samsungRPC_settings">Enable Samsung RPC</string>
Expand Down
2 changes: 1 addition & 1 deletion common/resources/src/main/res/values-fil/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@
<string name="activity_streaming_title">Streaming at %1$s</string>
<string name="delete_config_successfully_toast">%1$s was deleted successfully</string>
<string name="service_enabled">Service enabled</string>
<string name="no_internet_connection">No internet connection</string>
<string name="no_internet_connection">No Internet connection</string>
<string name="unknown_error">An unexpected error occurred</string>
<string name="rpc_buttons">RPC buttons</string>
<string name="samsungRPC_settings">Enable Samsung RPC</string>
Expand Down
2 changes: 1 addition & 1 deletion common/resources/src/main/res/values-fr/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@
<string name="activity_streaming_title">Streaming at %1$s</string>
<string name="delete_config_successfully_toast">%1$s was deleted successfully</string>
<string name="service_enabled">Service enabled</string>
<string name="no_internet_connection">No internet connection</string>
<string name="no_internet_connection">No Internet connection</string>
<string name="unknown_error">An unexpected error occurred</string>
<string name="rpc_buttons">RPC buttons</string>
<string name="samsungRPC_settings">Enable Samsung RPC</string>
Expand Down
2 changes: 1 addition & 1 deletion common/resources/src/main/res/values-hr/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@
<string name="activity_streaming_title">Streaming at %1$s</string>
<string name="delete_config_successfully_toast">%1$s was deleted successfully</string>
<string name="service_enabled">Service enabled</string>
<string name="no_internet_connection">No internet connection</string>
<string name="no_internet_connection">No Internet connection</string>
<string name="unknown_error">An unexpected error occurred</string>
<string name="rpc_buttons">RPC buttons</string>
<string name="samsungRPC_settings">Enable Samsung RPC</string>
Expand Down
2 changes: 1 addition & 1 deletion common/resources/src/main/res/values-in/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@
<string name="activity_streaming_title">Streaming at %1$s</string>
<string name="delete_config_successfully_toast">%1$s was deleted successfully</string>
<string name="service_enabled">Service enabled</string>
<string name="no_internet_connection">No internet connection</string>
<string name="no_internet_connection">No Internet connection</string>
<string name="unknown_error">An unexpected error occurred</string>
<string name="rpc_buttons">RPC buttons</string>
<string name="samsungRPC_settings">Enable Samsung RPC</string>
Expand Down
2 changes: 1 addition & 1 deletion common/resources/src/main/res/values-it/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@
<string name="activity_streaming_title">Streaming at %1$s</string>
<string name="delete_config_successfully_toast">%1$s was deleted successfully</string>
<string name="service_enabled">Service enabled</string>
<string name="no_internet_connection">No internet connection</string>
<string name="no_internet_connection">No Internet connection</string>
<string name="unknown_error">An unexpected error occurred</string>
<string name="rpc_buttons">RPC buttons</string>
<string name="samsungRPC_settings">Enable Samsung RPC</string>
Expand Down
2 changes: 1 addition & 1 deletion common/resources/src/main/res/values-ja/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@
<string name="activity_streaming_title">Streaming at %1$s</string>
<string name="delete_config_successfully_toast">%1$s was deleted successfully</string>
<string name="service_enabled">Service enabled</string>
<string name="no_internet_connection">No internet connection</string>
<string name="no_internet_connection">No Internet connection</string>
<string name="unknown_error">An unexpected error occurred</string>
<string name="rpc_buttons">RPC buttons</string>
<string name="samsungRPC_settings">Enable Samsung RPC</string>
Expand Down
2 changes: 1 addition & 1 deletion common/resources/src/main/res/values-mm/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@
<string name="activity_streaming_title">Streaming at %1$s</string>
<string name="delete_config_successfully_toast">%1$s was deleted successfully</string>
<string name="service_enabled">Service enabled</string>
<string name="no_internet_connection">No internet connection</string>
<string name="no_internet_connection">No Internet connection</string>
<string name="unknown_error">An unexpected error occurred</string>
<string name="rpc_buttons">RPC buttons</string>
<string name="samsungRPC_settings">Enable Samsung RPC</string>
Expand Down
2 changes: 1 addition & 1 deletion common/resources/src/main/res/values-nl/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@
<string name="activity_streaming_title">Streaming at %1$s</string>
<string name="delete_config_successfully_toast">%1$s was deleted successfully</string>
<string name="service_enabled">Service enabled</string>
<string name="no_internet_connection">No internet connection</string>
<string name="no_internet_connection">No Internet connection</string>
<string name="unknown_error">An unexpected error occurred</string>
<string name="rpc_buttons">RPC buttons</string>
<string name="samsungRPC_settings">Enable Samsung RPC</string>
Expand Down
2 changes: 1 addition & 1 deletion common/resources/src/main/res/values-pt/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@
<string name="activity_streaming_title">Streaming at %1$s</string>
<string name="delete_config_successfully_toast">%1$s was deleted successfully</string>
<string name="service_enabled">Service enabled</string>
<string name="no_internet_connection">No internet connection</string>
<string name="no_internet_connection">No Internet connection</string>
<string name="unknown_error">An unexpected error occurred</string>
<string name="rpc_buttons">RPC buttons</string>
<string name="samsungRPC_settings">Enable Samsung RPC</string>
Expand Down
2 changes: 1 addition & 1 deletion common/resources/src/main/res/values-th/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@
<string name="activity_streaming_title">Streaming at %1$s</string>
<string name="delete_config_successfully_toast">%1$s was deleted successfully</string>
<string name="service_enabled">Service enabled</string>
<string name="no_internet_connection">No internet connection</string>
<string name="no_internet_connection">No Internet connection</string>
<string name="unknown_error">An unexpected error occurred</string>
<string name="rpc_buttons">RPC buttons</string>
<string name="samsungRPC_settings">Enable Samsung RPC</string>
Expand Down
2 changes: 1 addition & 1 deletion common/resources/src/main/res/values-tr/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@
<string name="activity_streaming_title">Streaming at %1$s</string>
<string name="delete_config_successfully_toast">%1$s was deleted successfully</string>
<string name="service_enabled">Service enabled</string>
<string name="no_internet_connection">No internet connection</string>
<string name="no_internet_connection">No Internet connection</string>
<string name="unknown_error">An unexpected error occurred</string>
<string name="rpc_buttons">RPC buttons</string>
<string name="samsungRPC_settings">Enable Samsung RPC</string>
Expand Down
2 changes: 1 addition & 1 deletion common/resources/src/main/res/values-vi/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@
<string name="activity_streaming_title">Đang phát trực tiếp tại %1$s</string>
<string name="delete_config_successfully_toast">%1$s đã được xóa thành công</string>
<string name="service_enabled">Dịch vụ đã khởi chạy</string>
<string name="no_internet_connection">Không kết nối Internet</string>
<string name="no_internet_connection">Không kết nối tới máy chủ</string>
<string name="unknown_error">Mội lỗi bất ngờ đã xảy ra</string>
<string name="rpc_buttons">Nút hoạt động</string>
<string name="samsungRPC_settings">Bật Samsung RPC</string>
Expand Down
2 changes: 1 addition & 1 deletion common/resources/src/main/res/values-zh/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@
<string name="activity_streaming_title">Streaming at %1$s</string>
<string name="delete_config_successfully_toast">%1$s was deleted successfully</string>
<string name="service_enabled">Service enabled</string>
<string name="no_internet_connection">No internet connection</string>
<string name="no_internet_connection">No Internet connection</string>
<string name="unknown_error">An unexpected error occurred</string>
<string name="rpc_buttons">RPC buttons</string>
<string name="samsungRPC_settings">Enable Samsung RPC</string>
Expand Down
2 changes: 1 addition & 1 deletion common/resources/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@
<string name="activity_streaming_title">Streaming at %1$s</string>
<string name="delete_config_successfully_toast">%1$s was deleted successfully</string>
<string name="service_enabled">Service enabled</string>
<string name="no_internet_connection">No internet connection</string>
<string name="no_internet_connection">No Internet connection</string>
<string name="unknown_error">An unexpected error occurred</string>
<string name="rpc_buttons">RPC buttons</string>
<string name="samsungRPC_settings">Enable Samsung RPC</string>
Expand Down
15 changes: 13 additions & 2 deletions data/src/main/java/com/my/kizzy/data/remote/ApiService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,15 @@ package com.my.kizzy.data.remote

import com.my.kizzy.domain.model.samsung_rpc.GalaxyPresence
import io.ktor.client.HttpClient
import io.ktor.client.call.body
import io.ktor.client.request.forms.MultiPartFormDataContent
import io.ktor.client.request.forms.formData
import io.ktor.client.request.get
import io.ktor.client.request.head
import io.ktor.client.request.headers
import io.ktor.client.request.parameter
import io.ktor.client.request.post
import io.ktor.client.request.setBody
import io.ktor.client.request.url
import io.ktor.client.statement.HttpResponse
import io.ktor.http.ContentType
import io.ktor.http.Headers
import io.ktor.http.HttpHeaders
Expand All @@ -37,6 +36,18 @@ class ApiService @Inject constructor(
@Discord private val discordBaseUrl: String,
@Github private val githubBaseUrl: String,
) {
suspend fun checkConnection() = runCatching {
val apiConnection = client.head {
url(baseUrl)
}.status in listOf(HttpStatusCode.OK, HttpStatusCode.Found)

val discordConnection = client.head {
url(discordBaseUrl.replace(Regex("/api.+"), ""))
}.status in listOf(HttpStatusCode.OK, HttpStatusCode.Found)

apiConnection && discordConnection
}

suspend fun getImage(url: String) = runCatching {
client.get {
url("$baseUrl/image")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,15 +59,22 @@ class KizzyRepositoryImpl @Inject constructor(
override suspend fun getUser(userid: String): User {
return api.getUser(userid).getOrNull()?.body() ?: User()
}

override suspend fun getContributors(): List<Contributor> {
return api.getContributors().getOrNull()?.body() ?: emptyList()
}

override suspend fun setSamsungGalaxyPresence(galaxyPresence: GalaxyPresence,token: String) {
api.setSamsungGalaxyPresence(galaxyPresence,token)
}

override suspend fun checkForUpdate(): Release {
return api.checkForUpdate().getOrNull()?.releaseBody() ?: Release()
}

override suspend fun checkConnection(): Boolean {
return api.checkConnection().getOrNull() == true
}
}

suspend fun HttpResponse.releaseBody(): Release {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,5 @@ interface KizzyRepository {
suspend fun getContributors(): List<Contributor>
suspend fun setSamsungGalaxyPresence(galaxyPresence: GalaxyPresence, token: String)
suspend fun checkForUpdate(): Release
suspend fun checkConnection(): Boolean
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
*
* ******************************************************************
* * * Copyright (C) 2022
* * * CheckConnectionUseCase.kt is part of Kizzy
* * * and can not be copied and/or distributed without the express
* * * permission of yzziK(Vaibhav)
* * *****************************************************************
*
*
*/

package com.my.kizzy.domain.use_case.check_connection

import com.my.kizzy.domain.model.Resource
import com.my.kizzy.domain.repository.KizzyRepository
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.flow
import javax.inject.Inject

class CheckConnectionUseCase @Inject constructor(
private val repository: KizzyRepository
) {
operator fun invoke(): Flow<Resource<Boolean>> = flow {
try {
emit(Resource.Loading())
val isConnected = repository.checkConnection()
emit(Resource.Success(isConnected))
} catch (e: Exception) {
emit(Resource.Error(e.localizedMessage ?: "An unexpected error occurred"))
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ fun CreditsPreview() {
@Composable
fun CreditsPreview2() {
Credits(
state = CreditScreenState.Error(error = "No internet connection"),
state = CreditScreenState.Error(error = "No Internet connection"),
onBackPressed = {}
)
}
Expand Down
Loading
Loading