FIX IssueComments moddel (#425)

Reformat Code

FIX IssueComments moddel

reformate Code

TimeHelper.formatTime dont crash on null date object

Co-authored-by: 6543 <6543@obermui.de>
Reviewed-on: https://gitea.com/gitnex/GitNex/pulls/425
Reviewed-by: M M Arif <mmarif@swatian.com>
This commit is contained in:
6543 2020-04-18 04:50:36 +00:00 committed by M M Arif
parent 0c6c596208
commit aa85b99e84
3 changed files with 139 additions and 122 deletions

View File

@ -262,7 +262,7 @@ public class IssueCommentsAdapter extends RecyclerView.Adapter<IssueCommentsAdap
} }
holder.issueCommentDate.setText(TimeHelper.formatTime(currentItem.getCreated_date(), new Locale(locale), timeFormat, mCtx)); holder.issueCommentDate.setText(TimeHelper.formatTime(currentItem.getCreated_at(), new Locale(locale), timeFormat, mCtx));
if(timeFormat.equals("pretty")) { if(timeFormat.equals("pretty")) {
holder.issueCommentDate.setOnClickListener(new ClickListener(TimeHelper.customDateFormatForToastDateFormat(currentItem.getCreated_at()), mCtx)); holder.issueCommentDate.setOnClickListener(new ClickListener(TimeHelper.customDateFormatForToastDateFormat(currentItem.getCreated_at()), mCtx));

View File

@ -16,77 +16,82 @@ import java.util.Locale;
public class TimeHelper { public class TimeHelper {
public static String customDateFormatForToast(String customDate) { public static String customDateFormatForToast(String customDate) {
String[] parts = customDate.split("\\+"); String[] parts = customDate.split("\\+");
String part1 = parts[0] + "Z"; String part1 = parts[0] + "Z";
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'", Locale.ENGLISH); SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'", Locale.ENGLISH);
Date createdTime = null; Date createdTime = null;
try { try {
createdTime = formatter.parse(part1); createdTime = formatter.parse(part1);
} catch (ParseException e) { }
e.printStackTrace(); catch(ParseException e) {
} e.printStackTrace();
}
DateFormat format = DateFormat.getDateTimeInstance(); DateFormat format = DateFormat.getDateTimeInstance();
return format.format(createdTime); return format.format(createdTime);
} }
public static String formatTime(Date date, Locale locale, String timeFormat, Context context) { public static String formatTime(Date date, Locale locale, String timeFormat, Context context) {
switch (timeFormat) { if(date == null) {
return "";
}
case "pretty": { switch(timeFormat) {
PrettyTime prettyTime = new PrettyTime(Locale.getDefault());
return prettyTime.format(date);
}
case "normal": { case "pretty": {
DateFormat formatter = new SimpleDateFormat("yyyy-MM-dd '" + context.getResources().getString(R.string.timeAtText) + "' HH:mm", locale); PrettyTime prettyTime = new PrettyTime(Locale.getDefault());
return formatter.format(date); return prettyTime.format(date);
} }
case "normal1": { case "normal": {
DateFormat formatter = new SimpleDateFormat("dd-MM-yyyy '" + context.getResources().getString(R.string.timeAtText) + "' HH:mm", locale); DateFormat formatter = new SimpleDateFormat("yyyy-MM-dd '" + context.getResources().getString(R.string.timeAtText) + "' HH:mm", locale);
return formatter.format(date); return formatter.format(date);
} }
} case "normal1": {
DateFormat formatter = new SimpleDateFormat("dd-MM-yyyy '" + context.getResources().getString(R.string.timeAtText) + "' HH:mm", locale);
return formatter.format(date);
}
return ""; }
}
public static String customDateFormatForToastDateFormat(Date customDate) { return "";
}
DateFormat format = DateFormat.getDateTimeInstance(); public static String customDateFormatForToastDateFormat(Date customDate) {
return format.format(customDate);
} DateFormat format = DateFormat.getDateTimeInstance();
return format.format(customDate);
public static boolean timeBetweenHours(int fromHour, int toHour) { }
Calendar cal = Calendar.getInstance(); public static boolean timeBetweenHours(int fromHour, int toHour) {
Calendar from = Calendar.getInstance(); Calendar cal = Calendar.getInstance();
from.set(Calendar.HOUR_OF_DAY, fromHour);
from.set(Calendar.MINUTE, 0);
Calendar to = Calendar.getInstance(); Calendar from = Calendar.getInstance();
to.set(Calendar.HOUR_OF_DAY, toHour); from.set(Calendar.HOUR_OF_DAY, fromHour);
to.set(Calendar.MINUTE, 0); from.set(Calendar.MINUTE, 0);
if(to.before(from)) { Calendar to = Calendar.getInstance();
if (cal.after(to)) { to.set(Calendar.HOUR_OF_DAY, toHour);
to.add(Calendar.DATE, 1); to.set(Calendar.MINUTE, 0);
}
else {
from.add(Calendar.DATE, -1);
}
}
return cal.after(from) && cal.before(to); if(to.before(from)) {
if(cal.after(to)) {
to.add(Calendar.DATE, 1);
}
else {
from.add(Calendar.DATE, -1);
}
}
} return cal.after(from) && cal.before(to);
}
} }

View File

@ -8,94 +8,106 @@ import java.util.Date;
public class IssueComments { public class IssueComments {
private int id; private int id;
private String html_url; private String html_url;
private String pull_request_url; private String pull_request_url;
private String issue_url; private String issue_url;
private String body; private String body;
private Date created_at; private Date created_at;
private Date created_date; private Date updated_at;
private Date updated_at;
private userObject user; private userObject user;
public IssueComments(String body) { public IssueComments(String body) {
this.body = body;
}
public class userObject { this.body = body;
}
private int id; public class userObject {
private String login;
private String full_name;
private String email;
private String avatar_url;
private String language;
private String username;
public int getId() { private int id;
return id; private String login;
} private String full_name;
private String email;
private String avatar_url;
private String language;
private String username;
public String getLogin() { public int getId() {
return login;
}
public String getFull_name() { return id;
return full_name; }
}
public String getEmail() { public String getLogin() {
return email;
}
public String getAvatar_url() { return login;
return avatar_url; }
}
public String getLanguage() { public String getFull_name() {
return language;
}
public String getUsername() { return full_name;
return username; }
}
} public String getEmail() {
public int getId() { return email;
return id; }
}
public String getHtml_url() { public String getAvatar_url() {
return html_url;
}
public String getPull_request_url() { return avatar_url;
return pull_request_url; }
}
public String getIssue_url() { public String getLanguage() {
return issue_url;
}
public String getBody() { return language;
return body; }
}
public Date getCreated_at() { public String getUsername() {
return created_at;
}
public Date getCreated_date() { return username;
return created_date; }
}
public userObject getUser() { }
return user;
} public int getId() {
return id;
}
public String getHtml_url() {
return html_url;
}
public String getPull_request_url() {
return pull_request_url;
}
public String getIssue_url() {
return issue_url;
}
public String getBody() {
return body;
}
public Date getCreated_at() {
return created_at;
}
public userObject getUser() {
return user;
}
public Date getUpdated_at() {
return updated_at;
}
public Date getUpdated_at() {
return updated_at;
}
} }