Skip to content

Commit

Permalink
added correct datetime to new episode fragment. Refactored a few Date…
Browse files Browse the repository at this point in the history
…Utils methods for easy use when displaying text in Locale Date an Time.
  • Loading branch information
espenaf committed Nov 19, 2012
1 parent 14d00a9 commit d6cc503
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 16 deletions.
2 changes: 1 addition & 1 deletion src/org/mythtv/client/ui/dvr/EpisodeFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ public void loadEpisode( Long channelId, DateTime startTime ) {

// airdate
tView = (TextView) activity.findViewById( R.id.textView_episode_airdate );
tView.setText( DateUtils.dateTimeFormatterPretty.print( program.getStartTime() ) );
tView.setText(DateUtils.getDateTimeUsingLocaleFormattingPretty(program.getStartTime(), getMainApplication().getDateFormat(), getMainApplication().getClockType()));

}

Expand Down
4 changes: 3 additions & 1 deletion src/org/mythtv/client/ui/dvr/ProgramGroupFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

import org.joda.time.DateTime;
import org.mythtv.R;
import org.mythtv.client.MainApplication;
import org.mythtv.client.ui.util.MythtvListFragment;
import org.mythtv.client.ui.util.ProgramHelper;
import org.mythtv.db.dvr.ProgramConstants;
Expand Down Expand Up @@ -196,6 +197,7 @@ public ProgramCursorAdapter( Context context, int layout, Cursor c, String[] fro
public View getView( int position, View convertView, ViewGroup parent ) {
Log.v( TAG, "getView : enter" );

MainApplication mainApplication = (MainApplication) mContext.getApplicationContext();
View v = convertView;
ViewHolder mHolder;

Expand All @@ -221,7 +223,7 @@ public View getView( int position, View convertView, ViewGroup parent ) {
Long startTime = getCursor().getLong( getCursor().getColumnIndexOrThrow( ProgramConstants.FIELD_START_TIME ) );
Log.v( TAG, "getView : id=" + id + ", title=" + title + ", subTitle=" + subTitle );

mHolder.subTitle.setText( !"".equals( subTitle ) ? subTitle : DateUtils.dateTimeFormatterPretty.print( new DateTime( startTime ) ) );
mHolder.subTitle.setText(!"".equals(subTitle) ? subTitle : DateUtils.getDateTimeUsingLocaleFormattingPretty(new DateTime(startTime), mainApplication.getDateFormat(), mainApplication.getClockType()));
mHolder.category.setBackgroundColor( mProgramHelper.getCategoryColor( category ) );

return v;
Expand Down
6 changes: 2 additions & 4 deletions src/org/mythtv/client/ui/dvr/RecordingRulesFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,12 @@
import java.util.ArrayList;
import java.util.List;

import org.joda.time.format.DateTimeFormat;
import org.joda.time.format.DateTimeFormatter;
import org.mythtv.R;
import org.mythtv.client.MainApplication;
import org.mythtv.client.ui.util.MythtvListFragment;
import org.mythtv.client.ui.util.ProgramHelper;
import org.mythtv.db.channel.ChannelDaoHelper;
import org.mythtv.service.util.DateUtils;
import org.mythtv.service.util.NotificationHelper;
import org.mythtv.service.util.NotificationHelper.NotificationType;
import org.mythtv.services.api.ETagInfo;
Expand Down Expand Up @@ -189,7 +188,6 @@ protected Void doInBackground(Integer... params) {

private class RecordingRuleAdapter extends BaseAdapter {

private final DateTimeFormatter formatter = DateTimeFormat.forPattern(mainApplication.getDateFormat());
private Context mContext;
private LayoutInflater mInflater;

Expand Down Expand Up @@ -278,7 +276,7 @@ public View getView( int position, View convertView, ViewGroup parent ) {
mHolder.title.setText( rule.getTitle() );
mHolder.channel.setText( channel );
mHolder.type.setText( rule.getType() );
mHolder.last.setText( formatter.print( rule.getLastRecorded() ) );
mHolder.last.setText(DateUtils.getDateWithLocaleFormatting(rule.getLastRecorded(), mainApplication.getDateFormat()));
mHolder.active.setChecked(!rule.isInactive());
mHolder.active.setTag(rule);
mHolder.active.setOnCheckedChangeListener(sRuleCheckChangeListener);
Expand Down
4 changes: 1 addition & 3 deletions src/org/mythtv/client/ui/dvr/UpcomingActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -267,9 +267,7 @@ public CharSequence getPageTitle( int position ) {
case 1:
return mResources.getString( R.string.upcoming_tomorrow );
default:
DateTimeFormatter defaultDateFormatter = DateTimeFormat.forPattern("yyyy-MM-dd");
DateTime currentDate = defaultDateFormatter.parseDateTime(fragmentHeadings.get( position ));
return DateTimeFormat.forPattern( getMainApplication().getDateFormat()).print(currentDate);
return DateUtils.getDateWithLocaleFormatting(fragmentHeadings.get(position), getMainApplication().getDateFormat());
}

}
Expand Down
7 changes: 1 addition & 6 deletions src/org/mythtv/client/ui/dvr/UpcomingFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -204,12 +204,7 @@ public void bindView( View view, Context context, Cursor cursor ) {
mHolder.subTitle.setText( program.getSubTitle() );
mHolder.channel.setText( null != program.getChannelInfo() ? program.getChannelInfo().getChannelNumber() : "" );
mHolder.duration.setText( program.getDurationInMinutes() + " minutes" );

if( mainApplication.getClockType() != null && mainApplication.getClockType().equals( "24" ) ) {
mHolder.startTime.setText( DateUtils.timeFormatter24.print( program.getStartTime() ) );
} else {
mHolder.startTime.setText( DateUtils.timeFormatter.print( program.getStartTime() ) );
}
mHolder.startTime.setText(DateUtils.getTimeWithLocaleFormatting(program.getStartTime(), mainApplication.getClockType()));

//Log.v( TAG, "UpcomingCursorAdapter.bindView : exit" );
}
Expand Down
27 changes: 26 additions & 1 deletion src/org/mythtv/service/util/DateUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@

/**
* @author Daniel Frey
*
* @author Espen Fossen
*
*/
public class DateUtils {

Expand Down Expand Up @@ -91,4 +92,28 @@ public static DateTime convertUtc( DateTime day ) {
return day.withZone( DateTimeZone.UTC );
}

public static String getDateTimeUsingLocaleFormattingPretty(String dateTime, String dateFormat, String clockType){
DateTime currentDateTime = dateTimeFormatterPretty.parseDateTime(dateTime);
return getDateTimeUsingLocaleFormattingPretty(currentDateTime, dateFormat, clockType);
}

public static String getDateTimeUsingLocaleFormattingPretty(DateTime dateTime, String dateFormat, String clockType){
if(clockType != null && clockType.equals("24")) return DateTimeFormat.forPattern( dateFormat+" "+"HH:mm" ).print(dateTime);
else return dateTimeFormatterPretty.print(dateTime);
}

public static String getDateWithLocaleFormatting(String date, String dateFormat){
DateTime currentDate = dateFormatter.parseDateTime(date);
return getDateWithLocaleFormatting(currentDate, dateFormat);
}

public static String getDateWithLocaleFormatting(DateTime date, String dateFormat){
return DateTimeFormat.forPattern(dateFormat).print(date);
}

public static String getTimeWithLocaleFormatting(DateTime date, String clockType){
if(clockType != null && clockType.equals("24")) return timeFormatter24.print(date);
else return timeFormatter.print(date);
}

}

0 comments on commit d6cc503

Please sign in to comment.