Skip to content

Commit

Permalink
Copy martykan#365 crash fix to ClassicTimeWidgetProvider
Browse files Browse the repository at this point in the history
  • Loading branch information
kmantel committed Dec 29, 2023
1 parent 917a183 commit 6267a10
Showing 1 changed file with 13 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,17 +49,22 @@ public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] a

DateFormat timeFormat = android.text.format.DateFormat.getTimeFormat(context);
String defaultDateFormat = context.getResources().getStringArray(R.array.dateFormatsValues)[0];
String dateFormat = sp.getString("dateFormat", defaultDateFormat);
dateFormat = dateFormat.substring(0, dateFormat.indexOf("-")-1);
if ("custom".equals(dateFormat)) {
dateFormat = sp.getString("dateFormatCustom", defaultDateFormat);
String simpleDateFormat = sp.getString("dateFormat", defaultDateFormat);
if ("custom".equals(simpleDateFormat)) {
simpleDateFormat = sp.getString("dateFormatCustom", defaultDateFormat);
}
String dateString;
try {
SimpleDateFormat resultFormat = new SimpleDateFormat(dateFormat);
dateString = resultFormat.format(new Date());
} catch (IllegalArgumentException e) {
dateString = context.getResources().getString(R.string.error_dateFormat);
simpleDateFormat = simpleDateFormat.substring(0, simpleDateFormat.indexOf("-") - 1);
try {
SimpleDateFormat resultFormat = new SimpleDateFormat(simpleDateFormat);
dateString = resultFormat.format(new Date());
} catch (IllegalArgumentException e) {
dateString = context.getResources().getString(R.string.error_dateFormat);
}
} catch (StringIndexOutOfBoundsException e) {
DateFormat dateFormat = DateFormat.getDateInstance(DateFormat.LONG);
dateString = dateFormat.format(new Date());
}

remoteViews.setTextViewText(R.id.time, timeFormat.format(new Date()));
Expand Down

0 comments on commit 6267a10

Please sign in to comment.