Skip to content

Commit

Permalink
Move some methods to keep consistency through the class, clean imports
Browse files Browse the repository at this point in the history
  • Loading branch information
atermenji committed Nov 2, 2013
1 parent 941a391 commit f5db7f2
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 81 deletions.
4 changes: 0 additions & 4 deletions app/res/layout/issue_edit.xml
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,6 @@
style="@style/FormalSingleLineEditText"
android:layout_width="match_parent" />

<!-- We initially hide many of these because we don't know if the
the user is a collaborator, so we show them later as necessary
-->

<TextView
android:id="@+id/tv_labels_label"
style="@style/HeaderTitleText"
Expand Down
140 changes: 63 additions & 77 deletions app/src/main/java/com/github/mobile/ui/issue/EditIssueActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
import android.os.Bundle;
import android.text.Editable;
import android.text.TextUtils;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.EditText;
Expand All @@ -49,7 +48,6 @@
import com.github.mobile.accounts.AuthenticatedUserTask;
import com.github.mobile.core.issue.IssueUtils;
import com.github.mobile.ui.DialogFragmentActivity;
import com.github.mobile.ui.ProgressDialogTask;
import com.github.mobile.ui.StyledText;
import com.github.mobile.ui.TextWatcherAdapter;
import com.github.mobile.util.AvatarLoader;
Expand Down Expand Up @@ -105,8 +103,6 @@ public static Intent createIntent(final Issue issue,
return builder.toIntent();
}

private static final String TAG = "EditIssueActivity";

private EditText titleText;

private EditText bodyText;
Expand Down Expand Up @@ -199,45 +195,38 @@ public void afterTextChanged(Editable s) {
});

updateSaveMenu();
updateView();
titleText.setText(issue.getTitle());
bodyText.setText(issue.getBody());
}

private void checkCollaboratorStatus() {
new AuthenticatedUserTask<Boolean>(this) {

@Override
public Boolean run(Account account) throws Exception {
return collaboratorService.isCollaborator(repository, AccountUtils.getLogin(EditIssueActivity.this));
}

@Override
protected void onSuccess(Boolean isCollaborator) throws Exception {
super.onSuccess(isCollaborator);

showMainContent();

if(isCollaborator)
showCollaboratorOptions();
}

@Override
protected void onException(Exception e) throws RuntimeException {
super.onException(e);

Log.d(TAG, "Error loading collaborators for issue editing", e);
showMainContent();
}
@Override
public void onDialogResult(int requestCode, int resultCode, Bundle arguments) {
if (RESULT_OK != resultCode)
return;

@Override
public void execute() {
super.execute();
}
switch (requestCode) {
case ISSUE_MILESTONE_UPDATE:
issue.setMilestone(MilestoneDialogFragment.getSelected(arguments));
updateMilestone();
break;
case ISSUE_ASSIGNEE_UPDATE:
User assignee = AssigneeDialogFragment.getSelected(arguments);
if (assignee != null)
issue.setAssignee(assignee);
else
issue.setAssignee(new User().setLogin(""));
updateAssignee();
break;
case ISSUE_LABELS_UPDATE:
issue.setLabels(LabelsDialogFragment.getSelected(arguments));
updateLabels();
break;
}
}

private void showMainContent() {
finder.find(id.sv_issue_content).setVisibility(View.VISIBLE);
finder.find(id.pb_loading).setVisibility(View.GONE);
}
}.execute();
private void showMainContent() {
finder.find(id.sv_issue_content).setVisibility(View.VISIBLE);
finder.find(id.pb_loading).setVisibility(View.GONE);
}

private void showCollaboratorOptions() {
Expand All @@ -254,8 +243,8 @@ private void showCollaboratorOptions() {
public void onClick(View v) {
if (milestoneDialog == null)
milestoneDialog = new MilestoneDialog(
EditIssueActivity.this, ISSUE_MILESTONE_UPDATE,
repository, milestoneService);
EditIssueActivity.this, ISSUE_MILESTONE_UPDATE,
repository, milestoneService);
milestoneDialog.show(issue.getMilestone());
}
});
Expand All @@ -266,8 +255,8 @@ public void onClick(View v) {
public void onClick(View v) {
if (assigneeDialog == null)
assigneeDialog = new AssigneeDialog(EditIssueActivity.this,
ISSUE_ASSIGNEE_UPDATE, repository,
collaboratorService);
ISSUE_ASSIGNEE_UPDATE, repository,
collaboratorService);
assigneeDialog.show(issue.getAssignee());
}
});
Expand All @@ -278,35 +267,14 @@ public void onClick(View v) {
public void onClick(View v) {
if (labelsDialog == null)
labelsDialog = new LabelsDialog(EditIssueActivity.this,
ISSUE_LABELS_UPDATE, repository, labelService);
ISSUE_LABELS_UPDATE, repository, labelService);
labelsDialog.show(issue.getLabels());
}
});
}

@Override
public void onDialogResult(int requestCode, int resultCode, Bundle arguments) {
if (RESULT_OK != resultCode)
return;

switch (requestCode) {
case ISSUE_MILESTONE_UPDATE:
issue.setMilestone(MilestoneDialogFragment.getSelected(arguments));
updateMilestone();
break;
case ISSUE_ASSIGNEE_UPDATE:
User assignee = AssigneeDialogFragment.getSelected(arguments);
if (assignee != null)
issue.setAssignee(assignee);
else
issue.setAssignee(new User().setLogin(""));
updateAssignee();
break;
case ISSUE_LABELS_UPDATE:
issue.setLabels(LabelsDialogFragment.getSelected(arguments));
updateLabels();
break;
}
updateAssignee();
updateLabels();
updateMilestone();
}

private void updateMilestone() {
Expand Down Expand Up @@ -349,15 +317,6 @@ private void updateLabels() {
labelsText.setText(string.none);
}

private void updateView() {
titleText.setText(issue.getTitle());
bodyText.setText(issue.getBody());

updateAssignee();
updateLabels();
updateMilestone();
}

@Override
protected void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
Expand Down Expand Up @@ -422,4 +381,31 @@ protected void onSuccess(Issue created) throws Exception {
return super.onOptionsItemSelected(item);
}
}

private void checkCollaboratorStatus() {
new AuthenticatedUserTask<Boolean>(this) {

@Override
public Boolean run(Account account) throws Exception {
return collaboratorService.isCollaborator(
repository, AccountUtils.getLogin(EditIssueActivity.this));
}

@Override
protected void onSuccess(Boolean isCollaborator) throws Exception {
super.onSuccess(isCollaborator);

showMainContent();
if(isCollaborator)
showCollaboratorOptions();
}

@Override
protected void onException(Exception e) throws RuntimeException {
super.onException(e);

showMainContent();
}
}.execute();
}
}

0 comments on commit f5db7f2

Please sign in to comment.