From 081cf030803049adf483acf746a813d8a2a30f50 Mon Sep 17 00:00:00 2001 From: Anastasia Repina Date: Tue, 21 Nov 2017 22:50:27 +0300 Subject: [PATCH 1/5] Started implementation of create and edit function Added layouts Added menu items Added classes, activities, fragments --- app/src/main/AndroidManifest.xml | 17 ++ .../main/java/com/github/mobile/Intents.java | 16 ++ .../ui/milestone/EditMilestoneActivity.java | 228 ++++++++++++++++++ .../mobile/ui/repo/MilestoneListAdapter.java | 69 ++++++ .../ui/repo/RepositoryMilestonesActivity.java | 75 ++++++ .../ui/repo/RepositoryMilestonesFragment.java | 112 +++++++++ .../ui/repo/RepositoryViewActivity.java | 3 + app/src/main/res/layout/milestone_edit.xml | 148 ++++++++++++ app/src/main/res/layout/repo_milestones.xml | 32 +++ app/src/main/res/menu/milestone_edit.xml | 27 +++ app/src/main/res/menu/repository.xml | 6 + 11 files changed, 733 insertions(+) create mode 100644 app/src/main/java/com/github/mobile/ui/milestone/EditMilestoneActivity.java create mode 100644 app/src/main/java/com/github/mobile/ui/repo/MilestoneListAdapter.java create mode 100644 app/src/main/java/com/github/mobile/ui/repo/RepositoryMilestonesActivity.java create mode 100644 app/src/main/java/com/github/mobile/ui/repo/RepositoryMilestonesFragment.java create mode 100644 app/src/main/res/layout/milestone_edit.xml create mode 100644 app/src/main/res/layout/repo_milestones.xml create mode 100644 app/src/main/res/menu/milestone_edit.xml diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 03cbbae9..04a0a6ca 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -95,6 +95,23 @@ + + + + + + + + + + + + + + { + + /** + * 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.contributor_item); + + /*this.context = context.getApplicationContext(); + this.avatars = avatars; + setItems(elements);*/ + } + + @Override + public long getItemId(final int position) { + //todo + //return getItem(position).getId(); + return 0; + } + + @Override + protected int[] getChildViewIds() { + //todo + //return new int[] { R.id.iv_avatar, R.id.tv_login, R.id.tv_contributions }; + return new int[]{}; + } + + @Override + protected void update(int position, Milestone milestone) { + //todo + /*avatars.bind(imageView(0), contributor); + setText(1, contributor.getLogin()); + setText(2, context.getString(R.string.contributions, contributor.getContributions()));*/ + } +} \ No newline at end of file diff --git a/app/src/main/java/com/github/mobile/ui/repo/RepositoryMilestonesActivity.java b/app/src/main/java/com/github/mobile/ui/repo/RepositoryMilestonesActivity.java new file mode 100644 index 00000000..bb754eae --- /dev/null +++ b/app/src/main/java/com/github/mobile/ui/repo/RepositoryMilestonesActivity.java @@ -0,0 +1,75 @@ +/* + * 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 static android.content.Intent.FLAG_ACTIVITY_CLEAR_TOP; +import static android.content.Intent.FLAG_ACTIVITY_SINGLE_TOP; +import static com.github.mobile.Intents.EXTRA_REPOSITORY; +import android.content.Intent; +import android.os.Bundle; +import android.support.v7.app.ActionBar; +import android.view.MenuItem; + +import com.github.mobile.Intents; +import com.github.mobile.R; +import com.github.mobile.ui.DialogFragmentActivity; + +import org.eclipse.egit.github.core.Repository; + +/** + * Activity to view repository milestones + */ +public class RepositoryMilestonesActivity extends DialogFragmentActivity { + + /** + * Create intent for this activity + * + * @param repository + * @return intent + */ + public static Intent createIntent(Repository repository) { + return new Intents.Builder("repo.milestones.VIEW").repo(repository).toIntent(); + } + + private Repository repository; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + + setContentView(R.layout.repo_milestones); + + repository = getSerializableExtra(EXTRA_REPOSITORY); + + ActionBar actionBar = getSupportActionBar(); + actionBar.setTitle(repository.getName()); + actionBar.setSubtitle(R.string.milestone); + actionBar.setDisplayHomeAsUpEnabled(true); + } + + @Override + public boolean onOptionsItemSelected(MenuItem item) { + switch (item.getItemId()) { + case android.R.id.home: + Intent intent = RepositoryViewActivity.createIntent(repository); + intent.addFlags(FLAG_ACTIVITY_CLEAR_TOP | FLAG_ACTIVITY_SINGLE_TOP); + startActivity(intent); + return true; + default: + return super.onOptionsItemSelected(item); + } + } +} \ No newline at end of file diff --git a/app/src/main/java/com/github/mobile/ui/repo/RepositoryMilestonesFragment.java b/app/src/main/java/com/github/mobile/ui/repo/RepositoryMilestonesFragment.java new file mode 100644 index 00000000..842c91e2 --- /dev/null +++ b/app/src/main/java/com/github/mobile/ui/repo/RepositoryMilestonesFragment.java @@ -0,0 +1,112 @@ +/* + * 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 static com.github.mobile.Intents.EXTRA_REPOSITORY; +import static org.eclipse.egit.github.core.service.IssueService.STATE_OPEN; + +import android.content.Context; +import android.os.Bundle; +import android.support.v4.content.Loader; +import android.view.View; +import android.widget.ListView; + +import com.github.kevinsawicki.wishlist.SingleTypeAdapter; +import com.github.mobile.R; +import com.github.mobile.ThrowableLoader; +import com.github.mobile.ui.ItemListFragment; +import com.github.mobile.util.AvatarLoader; +import com.google.inject.Inject; + +import java.util.List; + +import org.eclipse.egit.github.core.Milestone; +import org.eclipse.egit.github.core.Repository; +import org.eclipse.egit.github.core.service.MilestoneService; + +/** + * Fragment to display a list of milestones for a specific repository + */ +public class RepositoryMilestonesFragment extends ItemListFragment { + + /** + * Avatar loader + */ + @Inject + protected AvatarLoader avatars; + + /** + * Milestone service + */ + @Inject + protected MilestoneService service; + + private Repository repo; + + @Override + public void onAttach(Context context) { + super.onAttach(context); + + repo = getSerializableExtra(EXTRA_REPOSITORY); + } + + @Override + public void onActivityCreated(Bundle savedInstanceState) { + super.onActivityCreated(savedInstanceState); + + setEmptyText(R.string.no_milestone); + } + + @Override + public Loader> onCreateLoader(int id, Bundle args) { + return new ThrowableLoader>(getActivity(), items) { + + @Override + public List loadData() throws Exception { + //todo which state? STATE_OPEN? + return service.getMilestones(repo, STATE_OPEN); + } + }; + } + + @Override + protected SingleTypeAdapter createAdapter(List items) { + //todo what to send to MilestoneListAdapter + return new MilestoneListAdapter(getActivity(), + items.toArray(new Milestone[items.size()]), avatars); + } + + @Override + public void onListItemClick(ListView l, View v, int position, long id) { + final Milestone milestone = (Milestone) l.getItemAtPosition(position); + //todo + /*new RefreshUserTask(getActivity(), contributor.getLogin()) { + + @Override + protected void onSuccess(User user) throws Exception { + super.onSuccess(user); + + if (!AccountUtils.isUser(getActivity(), user)) + startActivity(UserViewActivity.createIntent(user)); + } + }.execute();*/ + } + + @Override + protected int getErrorMessage(Exception exception) { + return R.string.error_milestones_load; + } +} \ No newline at end of file diff --git a/app/src/main/java/com/github/mobile/ui/repo/RepositoryViewActivity.java b/app/src/main/java/com/github/mobile/ui/repo/RepositoryViewActivity.java index bd61df70..8cc8a41c 100644 --- a/app/src/main/java/com/github/mobile/ui/repo/RepositoryViewActivity.java +++ b/app/src/main/java/com/github/mobile/ui/repo/RepositoryViewActivity.java @@ -198,6 +198,9 @@ public boolean onOptionsItemSelected(MenuItem item) { case R.id.m_contributors: startActivity(RepositoryContributorsActivity.createIntent(repository)); return true; + case R.id.m_milestone: + startActivity(RepositoryMilestonesActivity.createIntent(repository)); + return true; case R.id.m_parent_repo: if (repository.getParent() == null) { // TODO: save parent in OrganizationRepositories so we don't need to do this diff --git a/app/src/main/res/layout/milestone_edit.xml b/app/src/main/res/layout/milestone_edit.xml new file mode 100644 index 00000000..31c146e0 --- /dev/null +++ b/app/src/main/res/layout/milestone_edit.xml @@ -0,0 +1,148 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +