Skip to content

Commit

Permalink
final day translation for app and code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
Mark-McCleane committed Aug 24, 2022
1 parent 22c0e5d commit 7ddc9d3
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 29 deletions.
7 changes: 7 additions & 0 deletions app/src/main/java/com/aniketjain/weatherapp/HomeActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand All @@ -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);
Expand Down
24 changes: 24 additions & 0 deletions app/src/main/java/com/aniketjain/weatherapp/update/UpdateUI.java
Original file line number Diff line number Diff line change
@@ -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) {
Expand Down Expand Up @@ -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;
}
}

0 comments on commit 7ddc9d3

Please sign in to comment.