From 7ddc9d3e11174399e73deab2973c3bba3a3be9c3 Mon Sep 17 00:00:00 2001 From: Mark-McCleane Date: Wed, 24 Aug 2022 23:46:10 +0100 Subject: [PATCH] final day translation for app and code cleanup --- .../aniketjain/weatherapp/HomeActivity.java | 7 +++++ .../weatherapp/adapter/DaysAdapter.java | 30 +------------------ .../weatherapp/update/UpdateUI.java | 24 +++++++++++++++ 3 files changed, 32 insertions(+), 29 deletions(-) diff --git a/app/src/main/java/com/aniketjain/weatherapp/HomeActivity.java b/app/src/main/java/com/aniketjain/weatherapp/HomeActivity.java index 9b740c8..bd9b437 100644 --- a/app/src/main/java/com/aniketjain/weatherapp/HomeActivity.java +++ b/app/src/main/java/com/aniketjain/weatherapp/HomeActivity.java @@ -249,6 +249,7 @@ private void getTodayWeatherInfo(String name) { @SuppressLint("SetTextI18n") private void updateUI() { binding.layout.nameTv.setText(name); + updated_at = translate(updated_at); binding.layout.updatedAtTv.setText(updated_at); binding.layout.conditionIv.setImageResource( getResources().getIdentifier( @@ -265,6 +266,12 @@ private void updateUI() { binding.layout.humidityTv.setText(humidity + "%"); } + private String translate(String dayToTranslate) { + String[] dayToTranslateSplit = dayToTranslate.split(" "); + dayToTranslateSplit[0] = UpdateUI.TranslateDay(dayToTranslateSplit[0].trim(), getApplicationContext()); + return dayToTranslateSplit[0].concat(" " + dayToTranslateSplit[1]); + } + private void hideProgressBar() { binding.progress.setVisibility(View.GONE); binding.layout.mainLayout.setVisibility(View.VISIBLE); diff --git a/app/src/main/java/com/aniketjain/weatherapp/adapter/DaysAdapter.java b/app/src/main/java/com/aniketjain/weatherapp/adapter/DaysAdapter.java index d3c2282..a39c154 100644 --- a/app/src/main/java/com/aniketjain/weatherapp/adapter/DaysAdapter.java +++ b/app/src/main/java/com/aniketjain/weatherapp/adapter/DaysAdapter.java @@ -87,7 +87,7 @@ private void getDailyWeatherInfo(int i, DayViewHolder holder) { @SuppressLint("SetTextI18n") private void updateUI(DayViewHolder holder) { - String day = translateDay(updated_at); + String day = UpdateUI.TranslateDay(updated_at, context); holder.dTime.setText(day); holder.temp_min.setText(min + "°C"); holder.temp_max.setText(max + "°C"); @@ -102,34 +102,6 @@ private void updateUI(DayViewHolder holder) { )); } - private String translateDay(String dayToBeTranslated) { - String localeLanguage = Locale.getDefault().getDisplayCountry(); - if(localeLanguage.equals(Locale.ENGLISH)){ - return dayToBeTranslated; - } - return TranslateDay(dayToBeTranslated); - } - - private String TranslateDay(String dayToBeTranslated) { - switch (dayToBeTranslated.trim()){ - case "Monday": - return context.getResources().getString(R.string.monday); - case "Tuesday": - return context.getResources().getString(R.string.tuesday); - case "Wednesday": - return context.getResources().getString(R.string.wednesday); - case "Thursday": - return context.getResources().getString(R.string.thursday); - case "Friday": - return context.getResources().getString(R.string.friday); - case "Saturday": - return context.getResources().getString(R.string.saturday); - case "Sunday": - return context.getResources().getString(R.string.sunday); - } - return dayToBeTranslated; - } - private void hideProgressBar(DayViewHolder holder) { holder.progress.setVisibility(View.GONE); holder.layout.setVisibility(View.VISIBLE); diff --git a/app/src/main/java/com/aniketjain/weatherapp/update/UpdateUI.java b/app/src/main/java/com/aniketjain/weatherapp/update/UpdateUI.java index 6429de9..78b88f1 100644 --- a/app/src/main/java/com/aniketjain/weatherapp/update/UpdateUI.java +++ b/app/src/main/java/com/aniketjain/weatherapp/update/UpdateUI.java @@ -1,5 +1,9 @@ package com.aniketjain.weatherapp.update; +import android.content.Context; + +import com.aniketjain.weatherapp.R; + public class UpdateUI { public static String getIconID(int condition, long update_time, long sunrise, long sunset) { @@ -29,4 +33,24 @@ else if (condition == 803 || condition == 804) return "broken_clouds"; return null; } + + public static String TranslateDay(String dayToBeTranslated, Context context) { + switch (dayToBeTranslated.trim()){ + case "Monday": + return context.getResources().getString(R.string.monday); + case "Tuesday": + return context.getResources().getString(R.string.tuesday); + case "Wednesday": + return context.getResources().getString(R.string.wednesday); + case "Thursday": + return context.getResources().getString(R.string.thursday); + case "Friday": + return context.getResources().getString(R.string.friday); + case "Saturday": + return context.getResources().getString(R.string.saturday); + case "Sunday": + return context.getResources().getString(R.string.sunday); + } + return dayToBeTranslated; + } }