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

Milestones list view #44

Merged
merged 5 commits into from
Dec 16, 2017
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
17 changes: 17 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,23 @@
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity android:name=".ui.milestone.EditMilestoneActivity"
android:configChanges="orientation|keyboardHidden|screenSize">
<intent-filter>
<action android:name="jp.forkhub.mobile.repo.milestones.edit.VIEW" />

<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name=".ui.repo.RepositoryMilestonesActivity"
android:configChanges="orientation|keyboardHidden|screenSize">
<intent-filter>
<action android:name="jp.forkhub.mobile.repo.milestones.VIEW" />

<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name=".ui.search.SearchActivity"
android:configChanges="orientation|keyboardHidden|screenSize"
Expand Down
16 changes: 16 additions & 0 deletions app/src/main/java/com/github/mobile/Intents.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import org.eclipse.egit.github.core.Gist;
import org.eclipse.egit.github.core.GistFile;
import org.eclipse.egit.github.core.Issue;
import org.eclipse.egit.github.core.Milestone;
import org.eclipse.egit.github.core.Repository;
import org.eclipse.egit.github.core.RepositoryId;
import org.eclipse.egit.github.core.User;
Expand Down Expand Up @@ -81,6 +82,11 @@ public class Intents {
*/
public static final String EXTRA_ISSUE = INTENT_EXTRA_PREFIX + "ISSUE";

/**
* Milestone handle
*/
public static final String EXTRA_MILESTONE = INTENT_EXTRA_PREFIX + "MILESTONE";

/**
* Issue number collection handle
*/
Expand Down Expand Up @@ -250,6 +256,16 @@ public Builder issue(Issue issue) {
issue).add(EXTRA_ISSUE_NUMBER, issue.getNumber());
}

/**
* Add milestone to intent being built up
*
* @param milestone
* @return this builder
*/
public Builder milestone(Milestone milestone) {
return add(EXTRA_MILESTONE, milestone);
}

/**
* Add project to intent being built up
*
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,228 @@
package com.github.mobile.ui.milestone;


import android.content.Intent;
import android.support.v7.app.ActionBar;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextUtils;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
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.Milestone;
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.LabelsDialog;
import com.github.mobile.ui.issue.MilestoneDialog;
import com.github.mobile.util.AvatarLoader;
import com.google.inject.Inject;

import org.eclipse.egit.github.core.Issue;
import org.eclipse.egit.github.core.RepositoryId;
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 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.RequestCodes.ISSUE_MILESTONE_UPDATE;

/*
* Activity to edit or create a milestone
*/
public class EditMilestoneActivity extends DialogFragmentActivity {

/**
* Create intent to create a milestone
*
* @param issue
* @return intent
*/
public static Intent createIntent(Issue issue) {
return createIntent(null, issue);
}


/**
* Create intent to edit a milestone
*
* @param milestone
* @param issue
* @return intent
*/
public static Intent createIntent(final Milestone milestone,
final Issue issue) {
Intents.Builder builder = new Intents.Builder("repo.milestones.edit.VIEW");
if (issue != null)
builder.add(EXTRA_ISSUE, issue);
if (milestone != null)
builder.milestone(milestone);
return builder.toIntent();
}

private EditText titleText;

private EditText descriptionText;

private TextView dateText;

private Button twoWeeksButton;

private Button monthButton;

private TextView clearText;

private ScrollView milestoneContent;

@Inject
private AvatarLoader avatars;

@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 LabelsDialog labelsDialog;

@Override
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);
twoWeeksButton = finder.find(R.id.b_two_weeks);
monthButton = finder.find(R.id.b_month);
clearText = finder.find(R.id.tv_clear);

//todo checkCollaboratorStatus();?

Intent intent = getIntent();

if (savedInstanceState != null)
milestone = (Milestone) savedInstanceState.getSerializable(EXTRA_MILESTONE);
if (milestone == null)
milestone = (Milestone) intent.getSerializableExtra(EXTRA_MILESTONE);
if (milestone == null)
milestone = new Milestone();

//todo RepositoryId.create?

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

//todo staff with actionbar

titleText.addTextChangedListener(new TextWatcherAdapter() {

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

updateSaveMenu();
titleText.setText(milestone.getTitle());
descriptionText.setText(milestone.getDescription());
}

@Override
public void onDialogResult(int requestCode, int resultCode, Bundle arguments) {
if (RESULT_OK != resultCode)
return;
switch (requestCode) {
case ISSUE_MILESTONE_UPDATE:
//todo
/*issue.setMilestone(MilestoneDialogFragment.getSelected(arguments));
updateMilestone();
break;*/
case ISSUE_ASSIGNEE_UPDATE:
//todo
case ISSUE_LABELS_UPDATE:
//todo
}
}

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

private void showCollaboratorOptions() {
//todo
}

private void updateMilestone() {
//todo
}

private void updateAssignee() {
//todo
}

private void updateLabels() {
//todo
}

@Override
protected void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
outState.putSerializable(EXTRA_MILESTONE, milestone);
}

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

private void updateSaveMenu(final CharSequence text) {
if (saveItem != null)
saveItem.setEnabled(!TextUtils.isEmpty(text));
}

@Override
public boolean onCreateOptionsMenu(Menu options) {
getMenuInflater().inflate(R.menu.milestone_edit, options);
saveItem = options.findItem(R.id.m_apply);
updateSaveMenu();
return true;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
//todo
default:
return super.onOptionsItemSelected(item);
}
}

private void checkCollaboratorStatus() {
//todo
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/*
* Copyright 2013 GitHub Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.github.mobile.ui.repo;

import android.content.Context;
import android.view.LayoutInflater;

import com.github.kevinsawicki.wishlist.SingleTypeAdapter;
import com.github.mobile.R;
import com.github.mobile.util.AvatarLoader;

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

import java.text.SimpleDateFormat;
/**
* List adapter for a list of milestones
*/
public class MilestoneListAdapter extends SingleTypeAdapter<Milestone> {

private final Context context;
/**
* Create milestone list adapter
*
* @param context
* @param elements
* @param avatars
*/
public MilestoneListAdapter(final Context context,
final Milestone[] elements, final AvatarLoader avatars) {
super(LayoutInflater.from(context), R.layout.milestone_item);
this.context = context.getApplicationContext();
setItems(elements);
}

@Override
protected int[] getChildViewIds() {
return new int[]{R.id.tv_milestone_title,
R.id.tv_milestone_due_to,
R.id.tv_milestone_opened_iss_number,
R.id.tv_milestone_closed_iss_number};
}

@Override
protected void update(int position, Milestone milestone) {
SimpleDateFormat sdf = new SimpleDateFormat("dd MMM yyyy");

setText(0, milestone.getTitle());
setText(1, context.getString(R.string.ms_due_by) + sdf.format(milestone.getDueOn()));
setText(2, context.getString(R.string.ms_opened_issues) + String.valueOf(milestone.getOpenIssues()));
setText(3, context.getString(R.string.ms_closed_issues) + String.valueOf(milestone.getClosedIssues()));
}
}
Loading