Skip to content

Commit

Permalink
Fix bug #64
Browse files Browse the repository at this point in the history
+ fix crash with null date in milestoneView
  • Loading branch information
tsnik committed Jan 27, 2018
1 parent 5f549cc commit 9a3f483
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
5 changes: 5 additions & 0 deletions app/src/main/java/com/github/mobile/GitHubModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import com.github.mobile.accounts.GitHubAccount;
import com.github.mobile.api.DateAdapter;
import com.github.mobile.api.RequestConfiguration;
import com.github.mobile.api.model.Milestone;
import com.github.mobile.core.commit.CommitStore;
import com.github.mobile.core.gist.GistStore;
import com.github.mobile.core.issue.IssueStore;
Expand All @@ -33,6 +34,7 @@
import com.google.inject.Singleton;
import com.google.inject.assistedinject.FactoryModuleBuilder;
import com.google.inject.name.Named;
import com.squareup.moshi.JsonAdapter;
import com.squareup.moshi.Moshi;

import java.io.File;
Expand Down Expand Up @@ -80,8 +82,11 @@ Retrofit retrofit(Provider<GitHubAccount> accountProvider) {
.addInterceptor(new RequestConfiguration(accountProvider))
.build();

JsonAdapter<Milestone> adapter =
new Moshi.Builder().add(new DateAdapter()).build().adapter(Milestone.class).serializeNulls();
Moshi converter = new Moshi.Builder()
.add(new DateAdapter())
.add(Milestone.class, adapter)
.build();

return new Retrofit.Builder()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ public boolean onOptionsItemSelected(MenuItem item) {
Date date = sd.parse(dateText.getText().toString());
milestone.due_on = date;
} catch (ParseException e) {
e.printStackTrace();
milestone.due_on = null;
}
if (milestone.created_at == null) {
new CreateMilestoneTask(this, repositoryId.getOwner(), repositoryId.getName(), milestone) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,9 @@ private void updateMilestone(final Milestone milestone){

milestoneTitle.setText(milestone.getTitle());
DateFormat sdf = SimpleDateFormat.getDateInstance();
milestoneDueTo.setText(sdf.format(milestone.getDueOn()));
if(milestone.getDueOn() != null) {
milestoneDueTo.setText(sdf.format(milestone.getDueOn()));
}
milestoneDescription.setText(milestone.getDescription());
int totalIssues = milestone.getClosedIssues() + milestone.getOpenIssues();
int progress = totalIssues == 0 ? 0 : milestone.getClosedIssues() * 100 / totalIssues;
Expand All @@ -122,8 +124,11 @@ private void updateMilestone(final Milestone milestone){
Date current = Calendar.getInstance().getTime();
String state = milestone.getState();
boolean open = state.equals("open");
long diff = dueOn.getTime() - current.getTime();
long days = TimeUnit.DAYS.convert(diff, TimeUnit.MILLISECONDS);
long days = 200;
if(dueOn != null) {
long diff = dueOn.getTime() - current.getTime();
days = TimeUnit.DAYS.convert(diff, TimeUnit.MILLISECONDS);
}
GradientDrawable back = (GradientDrawable) milestoneTime.getBackground();
if (!open){
milestoneTime.setText(R.string.status_closed);
Expand Down

0 comments on commit 9a3f483

Please sign in to comment.