Skip to content

Commit

Permalink
Added creation of new milestone
Browse files Browse the repository at this point in the history
  • Loading branch information
arepina committed Jan 17, 2018
1 parent cc7da89 commit 6d3f519
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 16 deletions.
5 changes: 5 additions & 0 deletions app/src/main/java/com/github/mobile/RequestCodes.java
Original file line number Diff line number Diff line change
Expand Up @@ -119,4 +119,9 @@ public interface RequestCodes {
* Request to edit milestone
*/
int MILESTONE_EDIT = 17;

/**
* Request to create milestone
*/
int MILESTONE_CREATE = 18;
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import com.github.mobile.accounts.AccountUtils;
import com.github.mobile.accounts.AuthenticatedUserTask;
import com.github.mobile.api.model.Milestone;
import com.github.mobile.core.milestone.CreateMilestoneTask;
import com.github.mobile.core.milestone.EditMilestoneTask;
import com.github.mobile.ui.DialogFragmentActivity;
import com.github.mobile.ui.TextWatcherAdapter;
Expand Down Expand Up @@ -281,21 +282,35 @@ public boolean onOptionsItemSelected(MenuItem item) {
} catch (ParseException e) {
e.printStackTrace();
}

new EditMilestoneTask(this, repository.getOwner(), repository.getName(), milestone) {

@Override
protected void onSuccess(Milestone editedMilestone)
throws Exception {
super.onSuccess(editedMilestone);

Intent intent = new Intent();
intent.putExtra(EXTRA_MILESTONE, editedMilestone);
setResult(RESULT_OK, intent);
finish();
}
}.edit();

if(milestone.created_at == null) {
new CreateMilestoneTask(this, repository.getOwner(), repository.getName(), milestone) {

@Override
protected void onSuccess(Milestone created) throws Exception {
super.onSuccess(created);

Intent intent = new Intent();
intent.putExtra(EXTRA_MILESTONE, created);
setResult(RESULT_OK, intent);
finish();
}

}.create();
}else {
new EditMilestoneTask(this, repository.getOwner(), repository.getName(), milestone) {

@Override
protected void onSuccess(Milestone editedMilestone)
throws Exception {
super.onSuccess(editedMilestone);

Intent intent = new Intent();
intent.putExtra(EXTRA_MILESTONE, editedMilestone);
setResult(RESULT_OK, intent);
finish();
}
}.edit();
}
return true;
default:
return super.onOptionsItemSelected(item);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@

import static android.content.Intent.FLAG_ACTIVITY_CLEAR_TOP;
import static android.content.Intent.FLAG_ACTIVITY_SINGLE_TOP;
import static com.github.mobile.Intents.EXTRA_MILESTONE;
import static com.github.mobile.Intents.EXTRA_REPOSITORY;
import static com.github.mobile.RequestCodes.MILESTONE_CREATE;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.ActionBar;
Expand All @@ -26,6 +29,7 @@

import com.github.mobile.Intents;
import com.github.mobile.R;
import com.github.mobile.api.model.Milestone;
import com.github.mobile.ui.DialogFragmentActivity;
import com.github.mobile.ui.milestone.EditMilestoneActivity;

Expand Down Expand Up @@ -74,13 +78,21 @@ public boolean onOptionsItemSelected(MenuItem item) {
//creating new milestone
Intent i = EditMilestoneActivity.createIntent(repository);
i.addFlags(FLAG_ACTIVITY_CLEAR_TOP | FLAG_ACTIVITY_SINGLE_TOP);
startActivity(i);
startActivityForResult(i, MILESTONE_CREATE);
return true;
default:
return super.onOptionsItemSelected(item);
}
}

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == MILESTONE_CREATE && resultCode == RESULT_OK) {
//todo refresh list
}
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.milestone, menu);
Expand Down

0 comments on commit 6d3f519

Please sign in to comment.