Skip to content
This repository has been archived by the owner on May 9, 2022. It is now read-only.

Issue #6: String resource conversion #7

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle sa
View view = inflater.inflate(R.layout.about_fragment, container, false);

TextView tvAboutInfo = (TextView) view.findViewById(R.id.tvAboutInfo);
tvAboutInfo.setText("Support information\nDatabase build date:\n" + mDbInfo.get(DbLoader.INFO_BUILDDATE) + " (v " + mDbInfo.get(DbLoader.INFO_DBVER) + ")");
tvAboutInfo.setText(getString(R.string.support_info) + mDbInfo.get(DbLoader.INFO_BUILDDATE) + " (v " + mDbInfo.get(DbLoader.INFO_DBVER) + ")");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should use string formatting instead of compounding the string.


TextView tvDataAttribution = (TextView) view.findViewById(R.id.tvDataAttribution);
tvDataAttribution.setText(mDbInfo.get(DbLoader.INFO_PROVIDER_DETAILS));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ protected MergeAdapter getMergeAdapter() {
MergeAdapter adapter = new MergeAdapter();
View hotelRow = getMainActivity().getLayoutInflater().inflate(android.R.layout.simple_list_item_1, null);
TextView text1 = (TextView) hotelRow.findViewById(android.R.id.text1);
text1.setText("Hotel info");
text1.setText(R.string.hotel_info);
adapter.addView(hotelRow, true);

adapter.addAdapter(getStandardAdapterObject());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.menu_map:
// TODO: Make this better
startFragment(ImageViewFragment.createInstance("dealersroom", "Dealer's room"));
startFragment(ImageViewFragment.createInstance("dealersroom", getString(R.string.dealers_room)));
return true;
default:
return super.onOptionsItemSelected(item);
Expand Down Expand Up @@ -103,7 +103,7 @@ public void onListItemClick(ListView l, View v, int position, long id) {

String details = dli.getDescription();
if (details == null) {
sb.append("(No description given)");
sb.append(getString(R.string.no_description));
} else {
sb.append(details);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ else if (mDestination == GuideDestination.ATMs)

if (item == null) {
Log.w("GuideDetailFragment.onLoadFinished no data loaded from cursor");
Toast.makeText(getActivity(), "Error: No data was loaded.", Toast.LENGTH_SHORT).show();
Toast.makeText(getActivity(), R.string.error_no_data_loaded, Toast.LENGTH_SHORT).show();
return;
}

Expand Down Expand Up @@ -180,26 +180,26 @@ public View getView(int position, View convertView, ViewGroup parent) {
text2.setText(sb);
break;
case ROW_PHONE:
text1.setText("Call " + item.getPhone());
text1.setText(getString(R.string.call_number) + item.getPhone());
text1.setCompoundDrawablesWithIntrinsicBounds(0, 0, android.R.drawable.ic_menu_call, 0);
break;
case ROW_CATEGORY:
text1.setText("Category");
text1.setText(R.string.row_category);
text2.setText(item.getCategory());
break;
case ROW_RATING:
text1.setText("Rating");
text2.setText(rItem.getRating() + " stars");
text1.setText(R.string.row_rating);
text2.setText(rItem.getRating() + getString(R.string.rating_stars));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use string formatting.

break;
case ROW_COST:
text1.setText("Cost");
text1.setText(R.string.row_cost);
text2.setText(rItem.getDollarsAsSigns());
break;
case ROW_DELIVERY:
text1.setText("Has delivery");
text1.setText(R.string.row_has_delivery);
break;
case ROW_COMMENTS:
text1.setText("Review/comments");
text1.setText(R.string.row_comments);
text2.setText(item.getComments());
break;
case ROW_HOURS:
Expand All @@ -214,15 +214,15 @@ public View getView(int position, View convertView, ViewGroup parent) {
tvSunday.setText(GuideBaseItem.getTimeText(item.getSundayHours()));
break;
case ROW_URL:
text1.setText("Open website");
text1.setText(R.string.open_website);
text1.setCompoundDrawablesWithIntrinsicBounds(0, 0, android.R.drawable.ic_menu_directions, 0);
break;
case ROW_GOOGLE:
text1.setText("Open in Google Maps");
text1.setText(R.string.open_in_maps);
text1.setCompoundDrawablesWithIntrinsicBounds(0, 0, android.R.drawable.ic_menu_mapmode, 0);
break;
case ROW_YELP:
text1.setText("Open on Yelp");
text1.setText(R.string.open_in_yelp);
text1.setCompoundDrawablesWithIntrinsicBounds(0, 0, android.R.drawable.ic_menu_directions, 0);
break;
default:
Expand Down Expand Up @@ -276,7 +276,7 @@ private void showError(String message) {
AlertDialog.Builder alert = new AlertDialog.Builder(getActivity());
alert.setMessage(message)
.setCancelable(true)
.setNegativeButton("Close", new DialogInterface.OnClickListener() {
.setNegativeButton(R.string.close, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int id) {
dialog.dismiss();
Expand All @@ -286,23 +286,23 @@ public void onClick(DialogInterface dialog, int id) {

private void showLocation(final GuideBaseItem<?> item) {
if (item.getPlaceId().equals("")) {
String message = "This location could not be found in Google Maps.";
String message = getString(R.string.not_found_on_maps);

if ((mDestination == GuideDestination.Restaurants) || (mDestination == GuideDestination.RestaurantsOpenNow)) {
// Special 'closed' checks
RestaurantListItem restaurant = (RestaurantListItem) item;
RestaurantOpenStatus openStatus = restaurant.getOpenStatus();

if (openStatus == RestaurantOpenStatus.Closed) {
message = "This location could not be found in Google Maps, and may be closed.";
message = getString(R.string.not_found_on_maps_closed);
} else if (openStatus == RestaurantOpenStatus.VerifiedOpen) {
message = "This location could not be found in Google Maps, but it was verified to be open by MyConbook.";
message = getString(R.string.not_found_on_maps_verified_open);
}
}

AlertDialog.Builder dialog = new AlertDialog.Builder(getActivity());
dialog.setCancelable(true).setTitle("Location not found").setMessage(message)
.setNegativeButton("Cancel", new android.content.DialogInterface.OnClickListener() {
dialog.setCancelable(true).setTitle(R.string.location_not_found).setMessage(message)
.setNegativeButton(android.R.string.cancel, new android.content.DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.cancel();
Expand All @@ -316,15 +316,15 @@ public void onClick(DialogInterface dialog, int which) {

if (openStatus == RestaurantOpenStatus.Closed) {
AlertDialog.Builder dialog = new AlertDialog.Builder(getActivity());
dialog.setCancelable(true).setTitle("Location may be closed")
.setMessage("This location was marked as closed according to Google, but was still in the conbook. It may or may not still be open.")
.setPositiveButton("Continue", new android.content.DialogInterface.OnClickListener() {
dialog.setCancelable(true).setTitle(R.string.location_may_be_closed)
.setMessage(R.string.location_may_be_closed_message)
.setPositiveButton(R.string.continue, new android.content.DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
showPlaceInMaps(item);
}
})
.setNegativeButton("Cancel", new android.content.DialogInterface.OnClickListener() {
.setNegativeButton(android.R.string.cancel, new android.content.DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.cancel();
Expand All @@ -347,7 +347,7 @@ private void showPlaceInMaps(GuideBaseItem<?> item) {
startActivity(i);
} catch (ActivityNotFoundException e) {
Log.w("GuideDetailFragment.showPlaceInMaps error launching Places link", e);
showError("Unable to launch Google Maps.");
showError(getString(R.string.unable_to_launch_maps));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should make showError take ints and resolve string at display time.

}
}

Expand All @@ -359,7 +359,7 @@ private void launchBrowser(String url) {
startActivity(i);
} catch (ActivityNotFoundException e) {
Log.w("GuideDetailFragment.launchBrowser error launching browser for url " + url, e);
showError("Unable to launch browser for link " + url + ".");
showError(R.string.cant_open_link + url + ".");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use string formatting.

}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,8 @@ public boolean onOptionsItemSelected(MenuItem item) {
Intent i = new Intent(Intent.ACTION_SEND);
i.setType("plain/text");
i.putExtra(Intent.EXTRA_EMAIL, new String[]{getString(R.string.email)});
i.putExtra(Intent.EXTRA_SUBJECT, "Report a problem");
startSafeActivity(Intent.createChooser(i, "Send mail"));
i.putExtra(Intent.EXTRA_SUBJECT, getString(R.string.report_problem));
startSafeActivity(Intent.createChooser(i, getString(R.string.send_mail)));
return true;
default:
return super.onOptionsItemSelected(item);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ public void onLoadFinished(Loader<Cursor> loader, Cursor data) {
if (data == null) return;

ArrayList<String> categories = new ArrayList<String>();
categories.add(" --- All --- ");
categories.add(getString(R.string.all_categories));

while (data.moveToNext()) {
categories.add(data.getString(data.getColumnIndexOrThrow(RestaurantCategories.CATEGORY)));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public void onListItemClick(ListView l, View v, int position, long id) {
return;
}

String items[] = {"Call " + hli.getPhone(), "Open in Google Maps"};
String items[] = {getString(R.string.call_number) + hli.getPhone(), getString(R.string.open_in_maps)};
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use string formatting.


AlertDialog.Builder dialog = new AlertDialog.Builder(getActivity());
dialog.setCancelable(true).setTitle(hli.getName()).setItems(items, new OnClickListener() {
Expand All @@ -66,7 +66,7 @@ public void onClick(DialogInterface dialog, int which) {
try {
startActivity(i);
} catch (ActivityNotFoundException e) {
showError("Could not find an application to handle the request.");
showError(getString(R.string.activity_not_found));
}
} else if (which == 1) {
// Open place
Expand All @@ -75,7 +75,7 @@ public void onClick(DialogInterface dialog, int which) {
try {
startActivity(i);
} catch (ActivityNotFoundException e) {
showError("Could not find an application to handle the request.");
showError(getString(R.string.activity_not_found));
}
} else {
dialog.cancel();
Expand All @@ -90,7 +90,7 @@ private void showError(String message) {
AlertDialog.Builder alert = new AlertDialog.Builder(getActivity());
alert.setMessage(message)
.setCancelable(false)
.setNegativeButton("Close", new DialogInterface.OnClickListener() {
.setNegativeButton(R.string.close, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
dialog.dismiss();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ public void onClick(View v) {
i.setData(Uri.parse(mDbInfo.get(DbLoader.INFO_GUIDE_URL)));
startSafeActivity(i);
} else {
showError("This convention does not support the guide feature.", false);
showError(getString(R.string.con_no_guide_feature), false);
return;
}
} else {
Expand Down Expand Up @@ -281,7 +281,7 @@ public void startSafeActivity(Intent i) {
try {
startActivity(i);
} catch (ActivityNotFoundException e) {
showError("Could not find an application to handle the request.", false);
showError(getString(R.string.activity_not_found), false);
}
}

Expand Down Expand Up @@ -332,7 +332,7 @@ public void onCancel(DialogInterface dialog) {
alert.setMessage(message).setCancelable(false).setOnCancelListener(cancelListener);

if (!fatal) {
alert.setPositiveButton("Retry", new DialogInterface.OnClickListener() {
alert.setPositiveButton(R.string.retry, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
mAlertShown = false;
startListUpdate(true);
Expand All @@ -341,7 +341,7 @@ public void onClick(DialogInterface dialog, int id) {
});
}

alert.setNegativeButton(fatal ? "Exit" : "Cancel", new DialogInterface.OnClickListener() {
alert.setNegativeButton(fatal ? R.string.exit : android.R.string.cancel, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
mAlertShown = false;
dialog.cancel();
Expand All @@ -354,7 +354,7 @@ public void onClick(DialogInterface dialog, int id) {

private void populateConList(List<UpdaterInfo.ConventionInfo> cons) {
if (cons == null || cons.isEmpty()) {
showError("No conventions are currently listed.", true);
showError(getString(R.string.no_conventions_listed), true);
return;
}

Expand Down Expand Up @@ -446,7 +446,7 @@ private void refreshFromDb() {

if (mDbInfo == null) {
Log.w("MainActivity.refreshFromDb dbInfo is still null");
showError("The database could not be loaded.", true);
showError(getString(R.string.error_database_not_loaded), true);
return;
} else {
toggleButtons(true);
Expand Down Expand Up @@ -476,7 +476,7 @@ private void updateInfoDisplays() {
if (mDbInfo.containsKey(DbLoader.INFO_CONVENTION)) {
getSupportActionBar().setTitle(mDbInfo.get(DbLoader.INFO_CONVENTION));
} else {
getSupportActionBar().setTitle("Error: Reload DB!");
getSupportActionBar().setTitle(getString(R.string.error_reload_db));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ActionBar.setTitle takes resource string ints.

}
}

Expand All @@ -485,7 +485,7 @@ private void updateInfoDisplays() {
public void onNewerApp() {
AlertDialog.Builder alert = new AlertDialog.Builder(MainActivity.this);

alert.setMessage("A new version of MyConbook is available. Do you want to go to the Play Store to upgrade?")
alert.setMessage(R.string.new_version_available)
.setCancelable(true)
.setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ public boolean onContextItemSelected(MenuItem item) {
try {
startActivity(i);
} catch (ActivityNotFoundException e) {
showError("Could not find an application to handle the request.");
showError(getString(R.string.activity_not_found));
}

return true;
Expand Down Expand Up @@ -296,11 +296,11 @@ public void onListItemClick(ListView l, View v, int position, long id) {
}

if (details.trim().equals("")) {
details = "(No description given)";
details = getString(R.string.no_description);
}

if (cli.getCategory() != null && !"".equals(cli.getCategory())) {
details += "\n\nCategory: " + cli.getCategory();
details += "\n\n" + getString(R.string.details_category) + cli.getCategory();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use string formatting after the line breaks

}

// Show details dialog
Expand All @@ -314,7 +314,7 @@ private void showError(String message) {
AlertDialog.Builder alert = new AlertDialog.Builder(getActivity());
alert.setMessage(message)
.setCancelable(false)
.setNegativeButton("Close", new DialogInterface.OnClickListener() {
.setNegativeButton(R.string.close, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
dialog.dismiss();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ protected void onPostExecute(UpdaterReturn result) {
private class AsyncFetchList extends UpdaterTask<Boolean> {
@Override
protected void onPreExecute() {
publishProgress("Fetching convention list...");
publishProgress(getString(R.string.fetching_con_list));
}

@Override
Expand Down Expand Up @@ -177,7 +177,7 @@ protected void onOkAction() {
private class AsyncFetchCon extends UpdaterTask<String> {
@Override
protected void onPreExecute() {
publishProgress("Fetching convention data...");
publishProgress(getString(R.string.fetching_con_data));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,16 +38,16 @@ public GuideBaseItem(String name, String category, String address, String phone,

public static String getTimeText(String time) {
if ((time == null) || (time.equals(""))) {
return "Closed";
return getString(R.string.closed);
} else if (time.equals("?")) {
return "Unknown";
return getString(R.string.unknown);
} else {
return time;
}
}

protected static void setTimeText(TextView field, String time) {
field.setText("Today's hours: " + getTimeText(time));
field.setText(getString(R.string.todays_hours) + getTimeText(time));
}

public String getName() {
Expand Down Expand Up @@ -126,7 +126,7 @@ public String getTodayTime() {
case Calendar.SUNDAY:
return getSundayHours();
default:
return "Not available";
return getString(R.string.not_available);
}
}

Expand Down
Loading