Skip to content

Commit

Permalink
Non-collaborator restrictions in EditIssueActivity
Browse files Browse the repository at this point in the history
Made it so that issue administration options only show up
if the user is a collaborator on this repository
Closes pockethub#419
  • Loading branch information
maltzj authored and atermenji committed Nov 2, 2013
1 parent 43922d4 commit 941a391
Show file tree
Hide file tree
Showing 2 changed files with 96 additions and 18 deletions.
36 changes: 29 additions & 7 deletions app/res/layout/issue_edit.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,19 @@
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true" />

<ProgressBar
android:id="@+id/pb_loading"
style="@style/Spinner"
android:layout_centerInParent="true"
android:layout_width="64dp"
android:layout_height="64dp" />

<ScrollView
android:id="@+id/sv_issue_content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@id/v_header_separator" >
android:layout_below="@id/v_header_separator"
android:visibility="gone" >

<LinearLayout
android:layout_width="match_parent"
Expand All @@ -44,10 +53,16 @@
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"
android:paddingTop="5dp"
android:text="@string/labels" />
android:text="@string/labels"
android:visibility="gone" />

<LinearLayout
android:id="@+id/ll_labels"
Expand All @@ -56,7 +71,8 @@
android:background="@drawable/inset_background"
android:gravity="center_vertical"
android:orientation="horizontal"
android:padding="10dp" >
android:padding="10dp"
android:visibility="gone" >

<TextView
android:id="@+id/tv_labels"
Expand All @@ -66,9 +82,11 @@
</LinearLayout>

<TextView
android:id="@+id/tv_assignee_label"
style="@style/HeaderTitleText"
android:paddingTop="5dp"
android:text="@string/assignee" />
android:text="@string/assignee"
android:visibility="gone" />

<LinearLayout
android:id="@+id/ll_assignee"
Expand All @@ -77,7 +95,8 @@
android:background="@drawable/inset_background"
android:gravity="center_vertical"
android:orientation="horizontal"
android:padding="10dp" >
android:padding="10dp"
android:visibility="gone" >

<ImageView
android:id="@+id/iv_assignee_avatar"
Expand All @@ -93,9 +112,11 @@
</LinearLayout>

<TextView
android:id="@+id/tv_milestone_label"
style="@style/HeaderTitleText"
android:paddingTop="5dp"
android:text="@string/milestone" />
android:text="@string/milestone"
android:visibility="gone" />

<LinearLayout
android:id="@+id/ll_milestone"
Expand All @@ -104,7 +125,8 @@
android:background="@drawable/inset_background"
android:gravity="center_vertical"
android:orientation="vertical"
android:padding="10dp" >
android:padding="10dp"
android:visibility="gone" >

<TextView
android:id="@+id/tv_milestone"
Expand Down
78 changes: 67 additions & 11 deletions app/src/main/java/com/github/mobile/ui/issue/EditIssueActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,12 @@
import static com.github.mobile.RequestCodes.ISSUE_ASSIGNEE_UPDATE;
import static com.github.mobile.RequestCodes.ISSUE_LABELS_UPDATE;
import static com.github.mobile.RequestCodes.ISSUE_MILESTONE_UPDATE;
import android.accounts.Account;
import android.content.Intent;
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 @@ -43,8 +45,11 @@
import com.github.mobile.R.layout;
import com.github.mobile.R.menu;
import com.github.mobile.R.string;
import com.github.mobile.accounts.AccountUtils;
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 @@ -100,6 +105,8 @@ 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 @@ -155,6 +162,8 @@ protected void onCreate(Bundle savedInstanceState) {
assigneeText = finder.find(id.tv_assignee_name);
labelsText = finder.find(id.tv_labels);

checkCollaboratorStatus();

Intent intent = getIntent();

if (savedInstanceState != null)
Expand All @@ -181,6 +190,64 @@ protected void onCreate(Bundle savedInstanceState) {
actionBar.setSubtitle(repository.generateId());
avatars.bind(actionBar, (User) intent.getSerializableExtra(EXTRA_USER));

titleText.addTextChangedListener(new TextWatcherAdapter() {

@Override
public void afterTextChanged(Editable s) {
updateSaveMenu(s);
}
});

updateSaveMenu();
updateView();
}

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 execute() {
super.execute();
}

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

private void showCollaboratorOptions() {
finder.find(id.tv_milestone_label).setVisibility(View.VISIBLE);
finder.find(id.ll_milestone).setVisibility(View.VISIBLE);
finder.find(id.tv_labels_label).setVisibility(View.VISIBLE);
finder.find(id.ll_labels).setVisibility(View.VISIBLE);
finder.find(id.tv_assignee_label).setVisibility(View.VISIBLE);
finder.find(id.ll_assignee).setVisibility(View.VISIBLE);

findViewById(id.ll_milestone).setOnClickListener(new OnClickListener() {

@Override
Expand Down Expand Up @@ -215,17 +282,6 @@ public void onClick(View v) {
labelsDialog.show(issue.getLabels());
}
});

titleText.addTextChangedListener(new TextWatcherAdapter() {

@Override
public void afterTextChanged(Editable s) {
updateSaveMenu(s);
}
});

updateSaveMenu();
updateView();
}

@Override
Expand Down

0 comments on commit 941a391

Please sign in to comment.