Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug transition iss ms #79

Merged
merged 7 commits into from
Jan 29, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -330,10 +330,7 @@ public boolean onOptionsItemSelected(MenuItem item) {
}
}
if (repository != null) {
Intent intent = RepositoryViewActivity.createIntent(repository);
intent.addFlags(FLAG_ACTIVITY_CLEAR_TOP
| FLAG_ACTIVITY_SINGLE_TOP);
startActivity(intent);
finish();
}
return true;
default:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,14 @@ public static Intent createIntent(final Milestone milestone,
return builder.toIntent();
}

private EditText titleText;

private EditText descriptionText;
// Param views
private EditText etTitle;
private EditText etDescription;
private TextView etDate;

private TextView dateText;
// Param
private Date mDate;

private MilestoneDialog milestoneDialog;

Expand All @@ -108,9 +111,9 @@ protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.milestone_edit);

titleText = finder.find(R.id.et_milestone_title);
descriptionText = finder.find(R.id.et_milestone_description);
dateText = finder.find(R.id.tv_milestone_date);
etTitle = finder.find(R.id.et_milestone_title);
etDescription = finder.find(R.id.et_milestone_description);
etDate = finder.find(R.id.tv_milestone_date);
Button twoWeeksButton = finder.find(R.id.b_two_weeks);
Button monthButton = finder.find(R.id.b_month);
Button chooseDateButton = finder.find(R.id.b_choose_date);
Expand All @@ -127,10 +130,7 @@ 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(getApplicationContext().getString(R.string.ms_date_format));
final Date startDate = dateAndTime.getTime();
String fdate = sd.format(startDate);
dateText.setText(fdate);

}
}, dateAndTime.get(Calendar.YEAR), dateAndTime.get(Calendar.MONTH), dateAndTime.get(Calendar.DAY_OF_MONTH)).show();

Expand All @@ -146,10 +146,7 @@ public void onClick(View v) {
Calendar calendar = Calendar.getInstance();
calendar.setTime(dateOfOrder);
dateAndTime.add(Calendar.DAY_OF_YEAR, noOfDays);
SimpleDateFormat sd = new SimpleDateFormat(getApplicationContext().getString(R.string.ms_date_format));
final Date startDate = dateAndTime.getTime();
String fdate = sd.format(startDate);
dateText.setText(fdate);
updateDate(dateAndTime.getTime());
}
});

Expand All @@ -158,17 +155,14 @@ public void onClick(View v) {
public void onClick(View v) {
final Calendar dateAndTime = Calendar.getInstance();
dateAndTime.add(Calendar.MONTH, 1);
SimpleDateFormat sd = new SimpleDateFormat(getApplicationContext().getString(R.string.ms_date_format));
final Date startDate = dateAndTime.getTime();
String fdate = sd.format(startDate);
dateText.setText(fdate);
updateDate(dateAndTime.getTime());
}
});

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

Expand Down Expand Up @@ -198,7 +192,7 @@ public void onClick(View v) {
actionBar.setTitle(R.string.ms_new_milestone);
actionBar.setSubtitle(repositoryId.generateId());

titleText.addTextChangedListener(new TextWatcherAdapter() {
etTitle.addTextChangedListener(new TextWatcherAdapter() {

@Override
public void afterTextChanged(Editable s) {
Expand All @@ -207,8 +201,8 @@ public void afterTextChanged(Editable s) {
});

updateSaveMenu();
titleText.setText(milestone.title);
descriptionText.setText(milestone.description);
etTitle.setText(milestone.title);
etDescription.setText(milestone.description);
}

@Override
Expand All @@ -231,19 +225,14 @@ private void showCollaboratorOptions() {

private void updateMilestone() {
if (milestone != null) {
titleText.setText(milestone.title);
descriptionText.setText(milestone.description);
etTitle.setText(milestone.title);
etDescription.setText(milestone.description);
Date dueOn = milestone.due_on;
if (dueOn != null) {
SimpleDateFormat sd = new SimpleDateFormat(getApplicationContext().getString(R.string.ms_date_format));
dateText.setText(sd.format(dueOn));
} else {
dateText.setText("");
}
updateDate(dueOn);
} else {
titleText.setText(R.string.none);
descriptionText.setText(R.string.none);
dateText.setText("");
etTitle.setText(R.string.none);
etDescription.setText(R.string.none);
etDate.setText("");
}
}

Expand All @@ -255,8 +244,8 @@ protected void onSaveInstanceState(Bundle outState) {
}

private void updateSaveMenu() {
if (titleText != null)
updateSaveMenu(titleText.getText());
if (etTitle != null)
updateSaveMenu(etTitle.getText());
}

private void updateSaveMenu(final CharSequence text) {
Expand All @@ -281,15 +270,9 @@ public boolean onOptionsItemSelected(MenuItem item) {
case R.id.m_apply:
ActionBar actionBar = getSupportActionBar();
actionBar.setTitle(milestone.title);
milestone.title = titleText.getText().toString();
milestone.description = descriptionText.getText().toString();
SimpleDateFormat sd = new SimpleDateFormat(getApplicationContext().getString(R.string.ms_date_format));
try {
Date date = sd.parse(dateText.getText().toString());
milestone.due_on = date;
} catch (ParseException e) {
milestone.due_on = null;
}
milestone.title = etTitle.getText().toString();
milestone.description = etDescription.getText().toString();
milestone.due_on = mDate;
if (milestone.created_at == null) {
new CreateMilestoneTask(this, repositoryId.getOwner(), repositoryId.getName(), milestone) {

Expand Down Expand Up @@ -349,4 +332,18 @@ protected void onException(Exception e) throws RuntimeException {
}
}.execute();
}

private void updateDate(Date date){
if (date == null){
etDate.setVisibility(View.GONE);
mDate = null;
milestone.due_on = null;
} else {
etDate.setVisibility(View.VISIBLE);
mDate = date;
SimpleDateFormat sd = new SimpleDateFormat(getApplicationContext().getString(R.string.ms_date_format));
String fdate = sd.format(date);
etDate.setText(fdate);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,12 @@
import android.view.ViewGroup;
import android.widget.ProgressBar;
import android.widget.TextView;

import com.github.mobile.R;
import com.github.mobile.ui.DialogFragment;

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

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Calendar;
Expand All @@ -48,7 +51,7 @@ public class MilestoneFragment extends DialogFragment {
private ProgressBar milestoneProgress;
private TextView milestoneProgressPercentage;
private TextView milestoneTime;

private final static int MS_TIME_PAST_DAYS = -100;
private final static int MS_TIME_OK_DAYS = 100;

Expand All @@ -57,7 +60,7 @@ public class MilestoneFragment extends DialogFragment {
public void onAttach(Context context) {
super.onAttach(context);

milestone = ((com.github.mobile.api.model.Milestone)getSerializableExtra(EXTRA_MILESTONE)).getOldModel();
milestone = ((com.github.mobile.api.model.Milestone) getSerializableExtra(EXTRA_MILESTONE)).getOldModel();
}

@Override
Expand All @@ -71,8 +74,8 @@ public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

Bundle bundle = getArguments();
if(bundle != null && bundle.getSerializable(EXTRA_MILESTONE) != null)
milestone = ((com.github.mobile.api.model.Milestone)bundle.getSerializable(EXTRA_MILESTONE)).getOldModel();
if (bundle != null && bundle.getSerializable(EXTRA_MILESTONE) != null)
milestone = ((com.github.mobile.api.model.Milestone) bundle.getSerializable(EXTRA_MILESTONE)).getOldModel();
}

@Override
Expand All @@ -90,7 +93,7 @@ public void onViewCreated(View view, Bundle savedInstanceState) {
@Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
if (milestone != null){
if (milestone != null) {
updateMilestone(milestone);
}
}
Expand All @@ -108,47 +111,60 @@ public void onCreateOptionsMenu(Menu optionsMenu, MenuInflater inflater) {
inflater.inflate(R.menu.milestone_view, optionsMenu);
}

private void updateMilestone(final Milestone milestone){
if (!isUsable()){
private void updateMilestone(final Milestone milestone) {
if (!isUsable()) {
return;
}

milestoneTitle.setText(milestone.getTitle());
DateFormat sdf = SimpleDateFormat.getDateInstance();
if(milestone.getDueOn() != null) {

if (milestone.getDueOn() != null) {
milestoneDueTo.setVisibility(View.VISIBLE);
milestoneDueTo.setText(sdf.format(milestone.getDueOn()));
} else {
milestoneDueTo.setVisibility(View.GONE);
}

if (milestone.getDescription() != null) {
milestoneDescription.setVisibility(View.VISIBLE);
milestoneDescription.setText(milestone.getDescription());
} else {
milestoneDescription.setVisibility(View.GONE);
}
milestoneDescription.setText(milestone.getDescription());

int totalIssues = milestone.getClosedIssues() + milestone.getOpenIssues();
int progress = totalIssues == 0 ? 0 : milestone.getClosedIssues() * 100 / totalIssues;
milestoneProgress.setProgress(progress);
milestoneProgressPercentage.setText(String.valueOf(progress));

Date dueOn = milestone.getDueOn();
Date current = Calendar.getInstance().getTime();
String state = milestone.getState();
boolean open = state.equals("open");
long days = MS_TIME_OK_DAYS;
if(dueOn != null) {
if (dueOn != null) {
Date current = Calendar.getInstance().getTime();
String state = milestone.getState();
boolean open = state.equals("open");
long days = MS_TIME_OK_DAYS;
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);
back.setColor(getResources().getColor(R.color.milestone_badge_default));
}
else if (MS_TIME_PAST_DAYS <= days && days < 0 && open){
milestoneTime.setText(getString(R.string.ms_time_past) + " " +(-days) + " " + getString(R.string.ms_days));
back.setColor(getResources().getColor(R.color.milestone_badge_red));
}
else if (0 <= days && days < MS_TIME_OK_DAYS && open){
milestoneTime.setText(days + " " + getString(R.string.ms_days));
back.setColor(getResources().getColor(R.color.milestone_badge_default));
}
else {
milestoneTime.setText("");
back.setColor(getResources().getColor(R.color.background));
GradientDrawable back = (GradientDrawable) milestoneTime.getBackground();
if (!open) {
milestoneTime.setVisibility(View.VISIBLE);
milestoneTime.setText(R.string.status_closed);
back.setColor(getResources().getColor(R.color.milestone_badge_default));
} else if (MS_TIME_PAST_DAYS <= days && days < 0 && open) {
milestoneTime.setVisibility(View.VISIBLE);
milestoneTime.setText(getString(R.string.ms_time_past) + " " + (-days) + " " + getString(R.string.ms_days));
back.setColor(getResources().getColor(R.color.milestone_badge_red));
} else if (0 <= days && days < MS_TIME_OK_DAYS && open) {
milestoneTime.setVisibility(View.VISIBLE);
milestoneTime.setText(days + " " + getString(R.string.ms_days));
back.setColor(getResources().getColor(R.color.milestone_badge_default));
} else {
milestoneTime.setText("");
back.setColor(getResources().getColor(R.color.background));
}
} else {
milestoneTime.setVisibility(View.GONE);
}
}
}