Remove Util.formatDate

This commit is contained in:
Andrew Rabert 2017-03-05 13:25:47 -05:00
parent cff384d311
commit b13f71952c
3 changed files with 12 additions and 52 deletions

View File

@ -30,6 +30,7 @@ import net.nullsum.audinaut.util.Util;
import net.nullsum.audinaut.adapter.PlaylistAdapter;
import net.nullsum.audinaut.view.UpdateView;
import java.text.DateFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
@ -237,11 +238,15 @@ public class SelectPlaylistFragment extends SelectRecyclerFragment<Playlist> {
if(playlist.getCreated() != null) {
headers.add(R.string.details_created);
details.add(Util.formatDate(playlist.getCreated()));
DateFormat dateFormat = DateFormat.getDateInstance();
details.add(dateFormat.format(playlist.getCreated()));
}
if(playlist.getChanged() != null) {
headers.add(R.string.details_updated);
details.add(Util.formatDate(playlist.getChanged()));
DateFormat dateFormat = DateFormat.getDateInstance();
details.add(dateFormat.format(playlist.getChanged()));
}
Util.showDetailsDialog(context, R.string.details_title_playlist, headers, details);

View File

@ -89,7 +89,6 @@ import net.nullsum.audinaut.view.UpdateView;
import java.io.File;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
@ -1014,12 +1013,11 @@ public class SubsonicFragment extends Fragment implements SwipeRefreshLayout.OnR
Log.i(TAG, "Playlist id isn't a integer, probably MusicCabinet");
}
} else {
DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
DateFormat dateFormat = DateFormat.getDateInstance();
playlistNameView.setText(dateFormat.format(new Date()));
}
} else {
DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
playlistNameView.setText(dateFormat.format(new Date()));
DateFormat dateFormat = DateFormat.getDateInstance(); playlistNameView.setText(dateFormat.format(new Date()));
}
AlertDialog.Builder builder = new AlertDialog.Builder(context);
@ -1206,7 +1204,9 @@ public class SubsonicFragment extends Fragment implements SwipeRefreshLayout.OnR
Long[] dates = SongDBHandler.getHandler(context).getLastPlayed(song);
if(dates != null && dates[0] != null && dates[0] > 0) {
headers.add(R.string.details_last_played);
details.add(Util.formatDate((dates[1] != null && dates[1] > dates[0]) ? dates[1] : dates[0]));
Date date = new Date((dates[1] != null && dates[1] > dates[0]) ? dates[1] : dates[0]);
DateFormat dateFormat = DateFormat.getDateInstance();
details.add(dateFormat.format(date));
}
} catch(Exception e) {
Log.e(TAG, "Failed to get last played", e);

View File

@ -108,10 +108,6 @@ public final class Util {
private static DecimalFormat MEGA_BYTE_LOCALIZED_FORMAT = null;
private static DecimalFormat KILO_BYTE_LOCALIZED_FORMAT = null;
private static DecimalFormat BYTE_LOCALIZED_FORMAT = null;
private static SimpleDateFormat DATE_FORMAT_SHORT = new SimpleDateFormat("MMM d h:mm a");
private static SimpleDateFormat DATE_FORMAT_LONG = new SimpleDateFormat("MMM d, yyyy h:mm a");
private static SimpleDateFormat DATE_FORMAT_NO_TIME = new SimpleDateFormat("MMM d, yyyy");
private static int CURRENT_YEAR = new Date().getYear();
public static final String EVENT_META_CHANGED = "net.nullsum.audinaut.EVENT_META_CHANGED";
public static final String EVENT_PLAYSTATE_CHANGED = "net.nullsum.audinaut.EVENT_PLAYSTATE_CHANGED";
@ -783,47 +779,6 @@ public final class Util {
return builder.toString();
}
public static String formatDate(Context context, String dateString) {
return formatDate(context, dateString, true);
}
public static String formatDate(Context context, String dateString, boolean includeTime) {
if(dateString == null) {
return "";
}
try {
dateString = dateString.replace(' ', 'T');
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss", Locale.ENGLISH);
dateFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
return formatDate(dateFormat.parse(dateString), includeTime);
} catch(ParseException e) {
Log.e(TAG, "Failed to parse date string", e);
return dateString;
}
}
public static String formatDate(Date date) {
return formatDate(date, true);
}
public static String formatDate(Date date, boolean includeTime) {
if(date == null) {
return "Never";
} else {
if(includeTime) {
if (date.getYear() != CURRENT_YEAR) {
return DATE_FORMAT_LONG.format(date);
} else {
return DATE_FORMAT_SHORT.format(date);
}
} else {
return DATE_FORMAT_NO_TIME.format(date);
}
}
}
public static String formatDate(long millis) {
return formatDate(new Date(millis));
}
public static String formatBoolean(Context context, boolean value) {
return context.getResources().getString(value ? R.string.common_true : R.string.common_false);
}