Skip to content

Commit

Permalink
Added date picker
Browse files Browse the repository at this point in the history
  • Loading branch information
arepina committed Dec 17, 2017
1 parent f7ba846 commit e2a05c3
Show file tree
Hide file tree
Showing 3 changed files with 123 additions and 53 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@


import android.accounts.Account;
import android.app.DatePickerDialog;
import android.content.Intent;
import android.support.v7.app.ActionBar;
import android.os.Bundle;
Expand All @@ -11,36 +12,43 @@
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.DatePicker;
import android.widget.EditText;
import android.widget.ScrollView;
import android.widget.TextView;

import com.github.mobile.Intents;
import com.github.mobile.R;

import org.eclipse.egit.github.core.Issue;
import org.eclipse.egit.github.core.Milestone;

import com.github.mobile.accounts.AccountUtils;
import com.github.mobile.accounts.AuthenticatedUserTask;
import com.github.mobile.ui.DialogFragmentActivity;
import com.github.mobile.ui.TextWatcherAdapter;
import com.github.mobile.ui.issue.AssigneeDialog;
import com.github.mobile.ui.issue.EditIssueActivity;
import com.github.mobile.ui.issue.LabelsDialog;
import com.github.mobile.ui.issue.MilestoneDialog;
import com.github.mobile.ui.issue.MilestoneDialogFragment;
import com.github.mobile.ui.repo.RepositoryViewActivity;
import com.github.mobile.util.AvatarLoader;
import com.google.inject.Inject;

import org.eclipse.egit.github.core.Issue;
import org.eclipse.egit.github.core.Repository;
import org.eclipse.egit.github.core.RepositoryId;
import org.eclipse.egit.github.core.User;
import org.eclipse.egit.github.core.service.CollaboratorService;
import org.eclipse.egit.github.core.service.LabelService;
import org.eclipse.egit.github.core.service.MilestoneService;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

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_ISSUE;
import static com.github.mobile.Intents.EXTRA_MILESTONE;
import static com.github.mobile.RequestCodes.ISSUE_ASSIGNEE_UPDATE;
import static com.github.mobile.RequestCodes.ISSUE_LABELS_UPDATE;
import static com.github.mobile.Intents.EXTRA_REPOSITORY_NAME;
import static com.github.mobile.Intents.EXTRA_REPOSITORY_OWNER;
import static com.github.mobile.Intents.EXTRA_USER;
import static com.github.mobile.RequestCodes.ISSUE_MILESTONE_UPDATE;

/*
Expand All @@ -50,28 +58,35 @@ public class EditMilestoneActivity extends DialogFragmentActivity {


/**
* Create intent for this activity
* Create intent to create milestone
*
* @param repository
* @return intent
*/
public static Intent createIntent(Repository repository) {
return new Intents.Builder("repo.milestones.edit.VIEW").repo(repository).toIntent();
return createIntent(null, repository.getOwner().getLogin(),
repository.getName(), repository.getOwner(), null);
}


/**
* Create intent to edit a milestone
* Create intent to edit milestone
*
* @param milestone
* @param issue
* @param repositoryOwner
* @param repositoryName
* @param user
* @return intent
*/
public static Intent createIntent(final Milestone milestone,
final Issue issue) {
final String repositoryOwner, final String repositoryName,
final User user, final Issue issue) {
Intents.Builder builder = new Intents.Builder("repo.milestones.edit.VIEW");
if (issue != null)
if (user != null)
builder.add(EXTRA_USER, user);
if(issue != null)
builder.add(EXTRA_ISSUE, issue);
builder.add(EXTRA_REPOSITORY_NAME, repositoryName);
builder.add(EXTRA_REPOSITORY_OWNER, repositoryOwner);
if (milestone != null)
builder.milestone(milestone);
return builder.toIntent();
Expand All @@ -81,39 +96,36 @@ public static Intent createIntent(final Milestone milestone,

private EditText descriptionText;

private TextView dateText;
private EditText dateText;

private Button twoWeeksButton;

private Button monthButton;

private TextView clearText;
private Button chooseButton;

private Button clear;

private ScrollView milestoneContent;

@Inject
private AvatarLoader avatars;

private MilestoneDialog milestoneDialog;

@Inject
private MilestoneService milestoneService;

@Inject
private CollaboratorService collaboratorService;

@Inject
private LabelService labelService;

private Milestone milestone;

private RepositoryId repository;

private MenuItem saveItem;

private MilestoneDialog milestoneDialog;

private AssigneeDialog assigneeDialog;
private Issue issue;

private LabelsDialog labelsDialog;
private MenuItem saveItem;

@Override
protected void onCreate(Bundle savedInstanceState) {
Expand All @@ -122,10 +134,44 @@ protected void onCreate(Bundle savedInstanceState) {

titleText = finder.find(R.id.et_milestone_title);
descriptionText = finder.find(R.id.et_milestone_description);
dateText = finder.find(R.id.tv_milestone_date);
dateText = finder.find(R.id.et_milestone_date);
twoWeeksButton = finder.find(R.id.b_two_weeks);
monthButton = finder.find(R.id.b_month);
clearText = finder.find(R.id.tv_clear);
chooseButton = finder.find(R.id.b_choose_date);
clear = finder.find(R.id.b_clear);

final Calendar dateAndTime = Calendar.getInstance();

chooseButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
DatePickerDialog.OnDateSetListener picker =new DatePickerDialog.OnDateSetListener() {
public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
dateAndTime.set(Calendar.YEAR, year);
dateAndTime.set(Calendar.MONTH, monthOfYear);
dateAndTime.set(Calendar.DAY_OF_MONTH, dayOfMonth);
SimpleDateFormat sd = new SimpleDateFormat("dd-MM-yyyy");
final Date startDate = dateAndTime.getTime();
String fdate = sd.format(startDate);
dateText.setText(fdate);
}
};
new DatePickerDialog(EditMilestoneActivity.this, picker,
dateAndTime.get(Calendar.YEAR),
dateAndTime.get(Calendar.MONTH),
dateAndTime.get(Calendar.DAY_OF_MONTH))
.show();
}
});

clear.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
titleText.setText("");
descriptionText.setText("");
dateText.setText("");
}
});

checkCollaboratorStatus();

Expand All @@ -138,12 +184,20 @@ protected void onCreate(Bundle savedInstanceState) {
if (milestone == null)
milestone = new Milestone();

//todo RepositoryId.create?
repository = RepositoryId.create(
intent.getStringExtra(EXTRA_REPOSITORY_OWNER),
intent.getStringExtra(EXTRA_REPOSITORY_NAME));

issue = (Issue)intent.getSerializableExtra(EXTRA_ISSUE);

ActionBar actionBar = getSupportActionBar();
actionBar.setDisplayHomeAsUpEnabled(true);

//todo staff with actionbar
if (milestone.getNumber() > 0)
actionBar.setTitle(getString(R.string.milestone)
+ milestone.getNumber());
else
actionBar.setTitle(R.string.new_milestone);
actionBar.setSubtitle(repository.generateId());

titleText.addTextChangedListener(new TextWatcherAdapter() {

Expand All @@ -164,14 +218,10 @@ public void onDialogResult(int requestCode, int resultCode, Bundle arguments) {
return;
switch (requestCode) {
case ISSUE_MILESTONE_UPDATE:
//todo
/*issue.setMilestone(MilestoneDialogFragment.getSelected(arguments));
issue.setMilestone(MilestoneDialogFragment.getSelected(arguments));
updateMilestone();
break;*/
case ISSUE_ASSIGNEE_UPDATE:
//todo
case ISSUE_LABELS_UPDATE:
//todo
break;
//todo think about labels and assignee cases
}
}

Expand All @@ -181,24 +231,25 @@ private void showMainContent() {
}

private void showCollaboratorOptions() {
//todo
updateMilestone();
//todo think about labels and assignee update
}

private void updateMilestone() {
//todo
}

private void updateAssignee() {
//todo
}

private void updateLabels() {
//todo
Milestone milestone = issue.getMilestone();
if (milestone != null) {
titleText.setText(milestone.getTitle());
//todo add more fields
} else {
titleText.setText(R.string.none);
//todo add more fields
}
}

@Override
protected void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);

outState.putSerializable(EXTRA_MILESTONE, milestone);
}

Expand All @@ -223,7 +274,20 @@ public boolean onCreateOptionsMenu(Menu options) {
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
//todo
case android.R.id.home:
Repository repo = new Repository();
repo.setName(repository.getName());
repo.setOwner(new User().setLogin(repository.getOwner()));
Intent intent = RepositoryViewActivity.createIntent(repo);
intent.addFlags(FLAG_ACTIVITY_CLEAR_TOP
| FLAG_ACTIVITY_SINGLE_TOP);
startActivity(intent);
return true;
case R.id.m_apply:
milestone.setTitle(titleText.getText().toString());
milestone.setDescription(descriptionText.getText().toString());
//todo add more information to milestone and run EditMilestoneTask
return true;
default:
return super.onOptionsItemSelected(item);
}
Expand Down
13 changes: 9 additions & 4 deletions app/src/main/res/layout/milestone_edit.xml
Original file line number Diff line number Diff line change
Expand Up @@ -99,15 +99,20 @@
android:id="@+id/tv_milestone_date"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Date:" />

<TextView
android:id="@+id/tv_clear"
<EditText
android:id="@+id/et_milestone_date"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@color/text"
android:layout_weight="1"/>

<Button
android:id="@+id/b_clear"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:text="@string/clear" />

</LinearLayout>
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -349,5 +349,6 @@
<string name="ms_due_by">Due by</string>
<string name="ms_opened_issues">Opened:</string>
<string name="ms_closed_issues">Closed:</string>
<string name="new_milestone">New milestone</string>

</resources>

0 comments on commit e2a05c3

Please sign in to comment.