Skip to content

Commit

Permalink
Add old<->new Milestone mappers
Browse files Browse the repository at this point in the history
  • Loading branch information
phansier committed Jan 1, 2018
1 parent 59a4f43 commit 233d72c
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 8 deletions.
44 changes: 42 additions & 2 deletions app/src/main/java/com/github/mobile/api/model/Milestone.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,10 @@
*/
package com.github.mobile.api.model;

import java.io.Serializable;
import java.util.Date;

public class Milestone {
public class Milestone implements Serializable {
public long id;

public int number;
Expand All @@ -38,7 +39,46 @@ public class Milestone {

public Date updated_at;

public Date closed_at;
public Date closed_at; //it is in API but no in MilestoneService

public Date due_on;

public Milestone() {
}

public Milestone(org.eclipse.egit.github.core.Milestone milestone) {
//todo this.id=?
//there are two variants of id usage
//1)id is like an id in Issues, but it is in old Issues class too - the remove field
//2)id is like an serialVersionUID - then generate it using "serialver -classpath . Milestone" in terminal
this.number = milestone.getNumber();
this.state = milestone.getState();
this.title = milestone.getTitle();
this.description = milestone.getDescription();
this.creator = new User(milestone.getCreator());
this.open_issues = milestone.getOpenIssues();
this.closed_issues = milestone.getClosedIssues();
this.created_at = milestone.getCreatedAt();
//todo this.updated_at=???
//it is in API but no in MilestoneService
this.due_on = milestone.getDueOn();
}

public org.eclipse.egit.github.core.Milestone getOldModel() {
org.eclipse.egit.github.core.Milestone milestone = new org.eclipse.egit.github.core.Milestone();
milestone.setCreatedAt(created_at);
milestone.setDueOn(due_on);
milestone.setClosedIssues(closed_issues);
milestone.setNumber(number);
milestone.setOpenIssues(open_issues);
milestone.setDescription(description);
milestone.setState(state);
milestone.setTitle(title);
//todo milestone.setUrl();
//no url in this class
//it is in API but no in MilestoneService
milestone.setCreator(creator.getOldModel());

return milestone;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ public void onClick(View v) {
milestoneDialog = new MilestoneDialog(
EditIssuesFilterActivity.this, REQUEST_MILESTONE,
repository, milestones);
milestoneDialog.show(filter.getMilestone());
milestoneDialog.show(filter.getMilestone().getOldModel());
}
};

Expand Down Expand Up @@ -236,7 +236,7 @@ private void updateLabels() {
}

private void updateMilestone() {
Milestone selected = filter.getMilestone();
Milestone selected = filter.getMilestone().getOldModel();
if (selected != null)
milestoneText.setText(selected.getTitle());
else
Expand Down Expand Up @@ -265,7 +265,7 @@ public void onDialogResult(int requestCode, int resultCode, Bundle arguments) {
updateLabels();
break;
case REQUEST_MILESTONE:
filter.setMilestone(MilestoneDialogFragment.getSelected(arguments));
filter.setMilestone(new com.github.mobile.api.model.Milestone(MilestoneDialogFragment.getSelected(arguments)));
updateMilestone();
break;
case REQUEST_ASSIGNEE:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ protected void update(int position, IssueFilter filter) {
} else
setGone(3, true);

Milestone milestone = filter.getMilestone();
Milestone milestone = filter.getMilestone().getOldModel();
if (milestone != null)
ViewUtils.setGone(setText(4, milestone.getTitle()), false);
else
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ private void updateFilterSummary() {
} else
labels.setVisibility(GONE);

Milestone filterMilestone = filter.getMilestone();
Milestone filterMilestone = filter.getMilestone().getOldModel();
if (filterMilestone != null) {
milestone.setText(filterMilestone.getTitle());
milestone.setVisibility(VISIBLE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import com.github.mobile.ui.milestone.MilestoneViewActivity;
import com.google.inject.Inject;

import java.util.ArrayList;
import java.util.List;

import org.eclipse.egit.github.core.Repository;
Expand Down Expand Up @@ -71,11 +72,20 @@ public Loader<List<Milestone>> onCreateLoader(int id, Bundle args) {

@Override
public List<Milestone> loadData() throws Exception {
return service.getMilestones(repo, MILESTONES_STATE_ALL);
return convertMilestonesList(service.getMilestones(repo, MILESTONES_STATE_ALL));
}
};
}

private List<Milestone> convertMilestonesList(List<org.eclipse.egit.github.core.Milestone> milestoneList) {
List<Milestone> newList = new ArrayList<Milestone>();
for (org.eclipse.egit.github.core.Milestone m : milestoneList) {
newList.add(new Milestone(m));
}
return newList;

}

@Override
protected SingleTypeAdapter<Milestone> createAdapter(List<Milestone> items) {
return new MilestoneListAdapter(getActivity(),
Expand Down

0 comments on commit 233d72c

Please sign in to comment.