Skip to content

Commit

Permalink
Merge branch 'main' into droidcon-theme-changer
Browse files Browse the repository at this point in the history
  • Loading branch information
alisen authored Jul 5, 2024
2 parents 84b044e + 019ddea commit aecbc18
Show file tree
Hide file tree
Showing 8 changed files with 147 additions and 63 deletions.
1 change: 1 addition & 0 deletions zeapp/android/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ android {
"pl",
"et",
"ru",
"hu",
),
)

Expand Down
12 changes: 12 additions & 0 deletions zeapp/android/src/main/java/de/berlindroid/zeapp/zedi/ApiModule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import de.berlindroid.zeapp.zeservices.ZePassApi
import de.berlindroid.zeapp.zeservices.ZePassService
import de.berlindroid.zeapp.zeservices.ZeUserApi
import de.berlindroid.zeapp.zeservices.ZeUserService
import de.berlindroid.zeapp.zeservices.ZeWeatherApi
import kotlinx.serialization.json.Json
import okhttp3.MediaType.Companion.toMediaType
import okhttp3.OkHttpClient
Expand All @@ -19,6 +20,7 @@ data class ZeServerBaseUrl(
)

private val BASE_URL = ZeServerBaseUrl("https://zebadge.app/api/")
private val METEO_URL = ZeServerBaseUrl("https://api.open-meteo.com")

@InstallIn(ViewModelComponent::class)
@Module
Expand Down Expand Up @@ -75,4 +77,14 @@ object ApiModule {
.create(
ZeUserService::class.java,
)

@Provides
fun provideZeWeatherApi(
json: Json,
): ZeWeatherApi =
Retrofit.Builder()
.baseUrl(METEO_URL.value)
.addConverterFactory(json.asConverterFactory("application/json".toMediaType()))
.build()
.create(ZeWeatherApi::class.java)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package de.berlindroid.zeapp.zeservices

import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable
import retrofit2.http.GET

interface ZeWeatherApi {

@Serializable
data class Weather(
@SerialName(value = "hourly")
val hourly: Hourly,
)

@Serializable
data class Hourly(
@SerialName(value = "time")
val time: List<String>,

@SerialName(value = "temperature_2m")
val temperature: List<Double>,
)

@GET("v1/forecast?latitude=52.5244&longitude=13.4105&hourly=temperature_2m&forecast_days=16")
suspend fun getWeather(): Weather
}
Original file line number Diff line number Diff line change
@@ -1,69 +1,38 @@
package de.berlindroid.zeapp.zeservices

import de.berlindroid.zeapp.zemodels.WeatherData
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable
import kotlinx.serialization.json.Json
import okhttp3.MediaType.Companion.toMediaType
import retrofit2.Retrofit
import retrofit2.converter.kotlinx.serialization.asConverterFactory
import retrofit2.http.GET

internal suspend fun fetchWeather(date: String): WeatherData {
try {
val weather = weatherApiService.getWeather()

val tempIndex = weather.hourly.time.indexOfFirst {
it.contains("${date}T12:00")
}
if (tempIndex == -1) {
import javax.inject.Inject


/**
* Service to fetch the weather data from the API by the provided date
*/
class ZeWeatherService @Inject constructor(private val zeWeatherApi: ZeWeatherApi) {

internal suspend fun fetchWeather(date: String): WeatherData {
try {
val weather = zeWeatherApi.getWeather()

val tempIndex = weather.hourly.time.indexOfFirst {
it.contains("${date}T12:00")
}
if (tempIndex == -1) {
return WeatherData(
day = null,
temperature = -1.0,
)
}
val temperature = weather.hourly.temperature[tempIndex]
val day = weather.hourly.time[tempIndex]
return WeatherData(
day = day,
temperature = temperature,
)
} catch (e: Exception) {
return WeatherData(
day = null,
temperature = -1.0,
temperature = -42.0,
)
}
val temperature = weather.hourly.temperature[tempIndex]
val day = weather.hourly.time[tempIndex]
return WeatherData(
day = day,
temperature = temperature,
)
} catch (e: Exception) {
return WeatherData(
day = null,
temperature = -42.0,
)
}
}

private val json = Json {
ignoreUnknownKeys = true
}

private val retrofit = Retrofit.Builder()
.baseUrl("https://api.open-meteo.com")
.addConverterFactory(json.asConverterFactory("application/json".toMediaType()))
.build()

private val weatherApiService = retrofit.create(WeatherApi::class.java)

private interface WeatherApi {

@Serializable
data class Weather(
@SerialName(value = "hourly")
val hourly: Hourly,
)

@Serializable
data class Hourly(
@SerialName(value = "time")
val time: List<String>,

@SerialName(value = "temperature_2m")
val temperature: List<Double>,
)

@GET("v1/forecast?latitude=52.5244&longitude=13.4105&hourly=temperature_2m&forecast_days=16")
suspend fun getWeather(): Weather
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ import de.berlindroid.zeapp.zebits.composableToBitmap
import de.berlindroid.zeapp.zebits.isBinary
import de.berlindroid.zeapp.zemodels.WeatherData
import de.berlindroid.zeapp.zemodels.ZeConfiguration
import de.berlindroid.zeapp.zeservices.fetchWeather
import de.berlindroid.zeapp.zeui.zepages.WeatherPage
import de.berlindroid.zeapp.zeui.zetheme.ZeBlack
import de.berlindroid.zeapp.zeui.zetheme.ZeWhite
Expand All @@ -59,6 +58,7 @@ fun WeatherEditorDialog(
dismissed: () -> Unit = {},
accepted: (config: ZeConfiguration.Weather) -> Unit,
updateMessage: (String) -> Unit,
onFetchWeatherClick: suspend (String) -> WeatherData,
) {
val activity = LocalContext.current as Activity

Expand Down Expand Up @@ -200,9 +200,8 @@ fun WeatherEditorDialog(
item {
Button(
onClick = {
// Fix this please :)
scope.launch {
weatherData = fetchWeather(date)
weatherData = onFetchWeatherClick(date)
redrawComposableImage()
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ internal fun SelectedEditor(
dismissed = { vm.slotConfigured(null, null) },
accepted = { newConfig -> vm.slotConfigured(editor.slot, newConfig) },
updateMessage = vm::showMessage,
onFetchWeatherClick = vm::fetchWeather,
)

is ZeConfiguration.Quote -> RandomQuotesEditorDialog(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import de.berlindroid.zeapp.zeservices.ZeBadgeManager
import de.berlindroid.zeapp.zeservices.ZeClipboardService
import de.berlindroid.zeapp.zeservices.ZeImageProviderService
import de.berlindroid.zeapp.zeservices.ZePreferencesService
import de.berlindroid.zeapp.zeservices.ZeWeatherService
import de.berlindroid.zeapp.zeui.pixelManipulation
import de.berlindroid.zeapp.zeui.simulator.ZeSimulatorButtonAction
import de.berlindroid.zekompanion.ditherFloydSteinberg
Expand Down Expand Up @@ -47,6 +48,7 @@ class ZeBadgeViewModel @Inject constructor(
private val badgeManager: ZeBadgeManager,
private val preferencesService: ZePreferencesService,
private val clipboardService: ZeClipboardService,
private val weatherService: ZeWeatherService,
private val getTemplateConfigurations: GetTemplateConfigurations,
) : ViewModel() {

Expand Down Expand Up @@ -545,6 +547,8 @@ class ZeBadgeViewModel @Inject constructor(
}
}

suspend fun fetchWeather(date: String) = weatherService.fetchWeather(date)

private fun getInitialUIState(): ZeBadgeUiState =
ZeBadgeUiState(
message = "",
Expand Down
72 changes: 72 additions & 0 deletions zeapp/android/src/main/res/values-hu/strings.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
<resources xmlns:tools="http://schemas.android.com/tools">
<string name="app_name" translatable="false">ZeApp</string>
<string name="repo_url" translatable="false">https://github.com/gdg-berlin-android</string>

<string name="black_and_white">B/W</string>
<string name="reset">Alaphelyzet</string>
<string name="ze_edit">Szerkesztés</string>
<string name="floyd_steninberg_initials">FS</string>
<string name="positional">Helyzeti</string>
<string name="rotate">Forgatás</string>
<string name="invert">Invertálás</string>
<string name="static_tool">Statikus</string>
<string name="ze_very_important" tools:ignore="MissingTranslation">Nagyon fontos</string>
<string name="remind_binary_image" tools:ignore="MissingTranslation">(Ez nem egy fekete-fehér kép fájl. Válassz egy szín szűrőt az alábbiakból!)</string>

<string name="generate">Generálás</string>
<string name="not_binary_image">Nem fekete-fehér kép fájl. Minden pixelnek feketének vagy fehérnek kell lennie.</string>
<string name="generate_image_page">Kép generálása</string>
<string name="draw_image_page">Kép rajzolása</string>
<string name="enter_prompt">Itt írd be a promptodat</string>
<string name="could_not_generate_image">Nem sikerült legenerálni a képet</string>

<string name="image_needed">Itt fekete-fehér képre van szükség. Nyomd meg az egyik gombot a kép alatt!</string>
<string name="add_qr_url">Add meg a QR URL-t</string>
<string name="qr_code_title">QR kód címe</string>
<string name="qr_code_text">További szöveg</string>
<string name="url">URL</string>
<string name="add_barcode_url">Add meg a vonalkód URL-jét</string>
<string name="bar_code_title">Vonalkód címe</string>
<string name="qr_vcard">vCard</string>
<string name="qr_code_email">Email</string>
<string name="qr_code_phone">Telefon</string>
<string name="your_name_here" tools:ignore="MissingTranslation">Neved</string>
<string name="contact_me_here" tools:ignore="MissingTranslation">Elérhetőséged</string>
<string name="binary_image_needed" tools:ignore="MissingTranslation">Bináris képre van szükség.</string>
<string name="add_your_phrase_here" tools:ignore="MissingTranslation">Adj meg egy kifejezést</string>
<string name="random_phrase" tools:ignore="MissingTranslation">Véletlenszerű kifejezés</string>
<string name="unicorn_at_an_android_conference_in_isometric_view" tools:ignore="MissingTranslation">Unicorn at an android conference in isometric view.</string>
<string name="name" tools:ignore="MissingTranslation">Név</string>
<string name="contact" tools:ignore="MissingTranslation">Elérhetőség</string>
<string name="clear" tools:ignore="MissingTranslation">Törlés</string>
<string name="add_your_contact_details" tools:ignore="MissingTranslation">Add meg az elérhetőségedet</string>
<string name="set_picture" tools:ignore="MissingTranslation">Kép beállítása</string>
<string name="click_get_to_show_quote_of_the_day" tools:ignore="MissingTranslation">Kattints a Nap idézetére</string>
<string name="get" tools:ignore="MissingTranslation">Beszerzés</string>
<string name="decline" tools:ignore="MissingTranslation">Elutasítás</string>
<string name="send" tools:ignore="MissingTranslation">Küldés</string>
<string name="n_a" tools:ignore="MissingTranslation">N/A</string>
<string name="load_weather" tools:ignore="MissingTranslation">Időjárás betöltése</string>
<string name="hello_my_github_profile_is" tools:ignore="MissingTranslation">Hello, my github profile is</string>
<string name="your_phrase_here" tools:ignore="MissingTranslation">A kifejezésed</string>
<string name="hello_my_name_is" tools:ignore="MissingTranslation">Hello, my name is</string>
<string name="upcoming_weather" tools:ignore="MissingTranslation">☀️Upcoming weather</string>
<string name="quote_of_the_day" tools:ignore="MissingTranslation">Quote of The Day</string>
<string name="send_icon_text" tools:ignore="MissingTranslation">Küldés</string>
<string name="badge_config_editor_title">Badge összeállítás szerkesztése</string>

<string name="ze_navdrawer_save_all_pages">Minden összeállítás mentése a badge-re</string>
<string name="ze_navdrawer_update_config">Beállítások frissítése a badge-en</string>
<string name="ze_navdrawer_send_random_page">Véletlenszerű összeállítás letöltése a badge-re</string>
<string name="ze_navdrawer_new_release">✨ Új verzió elérhető: %d</string>
<string name="ze_navdrawer_open_release_page">Kiadott verziók megtekintése</string>
<string name="ze_navdrawer_contributors">Hozzájárulók</string>
<string name="ze_navdrawer_open_source">Open Source</string>
<string name="ze_select_content" tools:ignore="MissingTranslation">Tartalom kiválasztása</string>
<string name="ze_not_added_yet_message" tools:ignore="MissingTranslation">Nem járultál még hozzá ezzel! Bármit hozzáadhatsz ehhez a szerkesztőhöz!</string>

<string name="ze_sample_configuration_key" tools:ignore="MissingTranslation">minta összeállítás</string>
<string name="ze_sample_configuration_value" tools:ignore="MissingTranslation">minta érték</string>
<string name="ze_sample_int_key" tools:ignore="MissingTranslation">minta szám</string>
<string name="ze_sample_another_configuration_key" tools:ignore="MissingTranslation">másik összeállítás</string>
</resources>

0 comments on commit aecbc18

Please sign in to comment.