diff --git a/app/src/main/java/com/frodo/github/MainActivity.java b/app/src/main/java/com/frodo/github/MainActivity.java index 29072ba..6b24c2a 100644 --- a/app/src/main/java/com/frodo/github/MainActivity.java +++ b/app/src/main/java/com/frodo/github/MainActivity.java @@ -28,6 +28,7 @@ import com.frodo.github.business.activity.NotificationsFragment; import com.frodo.github.business.explore.ExploreFragment; import com.frodo.github.business.repository.RepositoryIssuesFragment; +import com.frodo.github.business.repository.RepositoryListFragment; import com.frodo.github.business.user.ProfileFragment; import com.frodo.github.business.user.UserModel; import com.frodo.github.common.ApiFragment; @@ -121,6 +122,9 @@ public boolean onNavigationItemSelected(MenuItem menuItem) { toolbar.setTitle(menuItem.getTitle()); Bundle bundle; switch (menuItem.getItemId()) { + case R.id.action_notifications: + FragmentScheduler.replaceFragment(MainActivity.this, NotificationsFragment.class); + break; case R.id.action_sign_in: FragmentScheduler.nextFragment(MainActivity.this, LoginFragment.class); break; @@ -130,18 +134,25 @@ public boolean onNavigationItemSelected(MenuItem menuItem) { case R.id.action_explore: FragmentScheduler.replaceFragment(MainActivity.this, ExploreFragment.class); break; + case R.id.action_news: + bundle = new Bundle(); + bundle.putString("events_args", String.format("events_user_%s", accountModel.getSignInUser())); + FragmentScheduler.replaceFragmentWithUniqueTag(MainActivity.this, EventsFragment.class, bundle); + break; case R.id.action_issues: bundle = new Bundle(); bundle.putString("issues_args", "issues_account"); - FragmentScheduler.replaceFragment(MainActivity.this, RepositoryIssuesFragment.class, bundle); + FragmentScheduler.replaceFragmentWithUniqueTag(MainActivity.this, RepositoryIssuesFragment.class, bundle); break; case R.id.action_events: bundle = new Bundle(); - bundle.putString("username", accountModel.getSignInUser()); - FragmentScheduler.replaceFragment(MainActivity.this, EventsFragment.class, bundle); + bundle.putString("events_args", String.format("events_account_%s", accountModel.getSignInUser())); + FragmentScheduler.replaceFragmentWithUniqueTag(MainActivity.this, EventsFragment.class, bundle); break; - case R.id.action_notifications: - FragmentScheduler.replaceFragment(MainActivity.this, NotificationsFragment.class); + case R.id.action_repositories: + bundle = new Bundle(); + bundle.putString("repos_args", String.format("repos_user_%s", accountModel.getSignInUser())); + FragmentScheduler.replaceFragmentWithUniqueTag(MainActivity.this, RepositoryListFragment.class, bundle); break; case R.id.action_author: bundle = new Bundle(); @@ -151,17 +162,17 @@ public boolean onNavigationItemSelected(MenuItem menuItem) { case R.id.action_iconics_test: bundle = new Bundle(); bundle.putString("api", "IconicsTest"); - FragmentScheduler.replaceFragmentWithUniqueTag(MainActivity.this, ApiFragment.class, bundle); + FragmentScheduler.replaceFragment(MainActivity.this, ApiFragment.class, bundle); break; case R.id.action_icon_api: bundle = new Bundle(); bundle.putString("api", "StaticOcticons"); - FragmentScheduler.replaceFragmentWithUniqueTag(MainActivity.this, ApiFragment.class, bundle); + FragmentScheduler.replaceFragment(MainActivity.this, ApiFragment.class, bundle); break; case R.id.action_jsoup_api: bundle = new Bundle(); bundle.putString("api", "JsoupApi"); - FragmentScheduler.replaceFragmentWithUniqueTag(MainActivity.this, ApiFragment.class, bundle); + FragmentScheduler.replaceFragment(MainActivity.this, ApiFragment.class, bundle); break; default: ViewProvider.wrapNotImplementFeature(MainActivity.this, null); @@ -275,8 +286,10 @@ private void updateMenu(Menu menu) { updateMenuItem(menu.findItem(R.id.action_explore), Octicons.Icon.oct_telescope); updateMenuItem(menu.findItem(R.id.action_sign_in), Octicons.Icon.oct_sign_in); updateMenuItem(menu.findItem(R.id.action_sign_out), Octicons.Icon.oct_sign_out); + updateMenuItem(menu.findItem(R.id.action_news), Octicons.Icon.oct_radio_tower); updateMenuItem(menu.findItem(R.id.action_issues), Octicons.Icon.oct_issue_opened); - updateMenuItem(menu.findItem(R.id.action_events), Octicons.Icon.oct_radio_tower); + updateMenuItem(menu.findItem(R.id.action_events), Octicons.Icon.oct_rss); + updateMenuItem(menu.findItem(R.id.action_repositories), Octicons.Icon.oct_repo); updateMenuItem(menu.findItem(R.id.action_setting), Octicons.Icon.oct_gear); updateMenuItem(menu.findItem(R.id.action_author), Octicons.Icon.oct_gist_secret); @@ -287,7 +300,7 @@ private void updateMenu(Menu menu) { private void updateMenuItem(MenuItem menuItem, Octicons.Icon icon) { if (menuItem != null) - menuItem.setIcon(new IconicsDrawable(this).icon(icon).colorRes(android.R.color.black)); + menuItem.setIcon(new IconicsDrawable(this).icon(icon).sizeDp(16).colorRes(android.R.color.black)); } @Override diff --git a/app/src/main/java/com/frodo/github/business/activity/EventsFragment.java b/app/src/main/java/com/frodo/github/business/activity/EventsFragment.java index 656fbc3..d4886ea 100644 --- a/app/src/main/java/com/frodo/github/business/activity/EventsFragment.java +++ b/app/src/main/java/com/frodo/github/business/activity/EventsFragment.java @@ -9,12 +9,14 @@ import com.frodo.app.android.ui.fragment.StatedFragment; import com.frodo.github.bean.dto.response.GithubEvent; +import com.frodo.github.bean.dto.response.Issue; import com.frodo.github.view.CircleProgressDialog; import com.frodo.github.view.ViewProvider; import java.util.ArrayList; import java.util.List; +import rx.Observable; import rx.android.schedulers.AndroidSchedulers; import rx.functions.Action0; import rx.functions.Action1; @@ -26,6 +28,8 @@ public class EventsFragment extends StatedFragment { private List stateContents; + private String repoOwner; + private String repo; @Override public EventsView createUIView(Context context, LayoutInflater inflater, ViewGroup container) { @@ -53,34 +57,52 @@ public void onResume() { @Override public void onFirstTimeLaunched() { Bundle bundle = getArguments(); - if (bundle.containsKey("username")) { - String username = bundle.getString("username"); - getModel().loadReceivedEvents(username).subscribeOn(Schedulers.io()) - .doOnSubscribe(new Action0() { - @Override - public void call() { - getUIView().showEmptyView(); - CircleProgressDialog.showLoadingDialog(getAndroidContext()); - } - }) - .subscribeOn(AndroidSchedulers.mainThread()) - .observeOn(AndroidSchedulers.mainThread()) - .subscribe(new Action1>() { - @Override - public void call(List events) { - stateContents = events; - CircleProgressDialog.hideLoadingDialog(); - getUIView().hideEmptyView(); - getUIView().showDetail(events); - } - }, - new Action1() { + //TODO events_account_{username} + // events_user_{username} + // events_repo_{owner}_{repo} + if (bundle != null && bundle.containsKey("events_args")) { + String[] argsArray = bundle.getString("events_args").split("_"); + + if (argsArray[0].equalsIgnoreCase("events")) { + Observable> observable = null; + if (argsArray[1].equalsIgnoreCase("account")) { + observable = getModel().loadAccountEvents(argsArray[2]); + } else if (argsArray[1].equalsIgnoreCase("user")) { + observable = getModel().loadReceivedEvents(argsArray[2]); + } else if (argsArray[1].equalsIgnoreCase("repo")) { + repoOwner = argsArray[2]; + repo = argsArray[3]; + } + + if (observable != null) { + observable.subscribeOn(Schedulers.io()) + .doOnSubscribe(new Action0() { @Override - public void call(Throwable throwable) { - CircleProgressDialog.hideLoadingDialog(); - getUIView().showErrorView(ViewProvider.handleError(getMainController().getConfig().isDebug(), throwable)); + public void call() { + getUIView().showEmptyView(); + CircleProgressDialog.showLoadingDialog(getAndroidContext()); } - }); + }) + .subscribeOn(AndroidSchedulers.mainThread()) + .observeOn(AndroidSchedulers.mainThread()) + .subscribe(new Action1>() { + @Override + public void call(List events) { + stateContents = events; + CircleProgressDialog.hideLoadingDialog(); + getUIView().hideEmptyView(); + getUIView().showDetail(events); + } + }, + new Action1() { + @Override + public void call(Throwable throwable) { + CircleProgressDialog.hideLoadingDialog(); + getUIView().showErrorView(ViewProvider.handleError(getMainController().getConfig().isDebug(), throwable)); + } + }); + } + } } } } diff --git a/app/src/main/java/com/frodo/github/business/activity/EventsModel.java b/app/src/main/java/com/frodo/github/business/activity/EventsModel.java index 0c1b2c8..69df4d1 100644 --- a/app/src/main/java/com/frodo/github/business/activity/EventsModel.java +++ b/app/src/main/java/com/frodo/github/business/activity/EventsModel.java @@ -41,13 +41,21 @@ public String name() { return TAG; } + public Observable> loadAccountEvents(String accountUser) { + return loadEventsWithReactor(Path.replace(Path.Activity.USER_EVENTS, new Pair<>("username", accountUser))); + } + public Observable> loadReceivedEvents(final String username) { + return loadEventsWithReactor(Path.replace(Path.Activity.RECEIVED_EVENTS, new Pair<>("username", username))); + } + + private Observable> loadEventsWithReactor(final String path) { return Observable.create(new Observable.OnSubscribe() { @Override public void call(Subscriber subscriber) { Request request = new Request.Builder() .method("GET") - .relativeUrl(Path.replace(Path.Activity.RECEIVED_EVENTS, new Pair<>("username", username))) + .relativeUrl(path) .build(); final NetworkTransport networkTransport = getMainController().getNetworkTransport(); networkTransport.setAPIUrl(Path.HOST_GITHUB); diff --git a/app/src/main/java/com/frodo/github/business/activity/EventsView.java b/app/src/main/java/com/frodo/github/business/activity/EventsView.java index 26d6af7..4b88622 100644 --- a/app/src/main/java/com/frodo/github/business/activity/EventsView.java +++ b/app/src/main/java/com/frodo/github/business/activity/EventsView.java @@ -69,7 +69,7 @@ public void onBindViewHolder(ViewHolder vh, int position) { vh.titleOV.setText(String.format("%s commented on issue %s#%s", event.actor.login, event.repo.name, event.payload.issue.number)); vh.actorOV.setVisibility(View.VISIBLE); - vh.actorOV.getFrescoAndIconicsImageView().setImageURI(Uri.parse(event.payload.comment.user.avatar_url)); + vh.actorOV.getFrescoAndIconicsImageView().setImageURI(Uri.parse(event.actor.avatar_url)); vh.actorOV.setText(event.payload.comment.body); } else if (event.type.equals(EventType.WatchEvent)) { vh.titleOV.getFrescoAndIconicsImageView().setIcon(Octicons.Icon.oct_star); @@ -83,6 +83,20 @@ public void onBindViewHolder(ViewHolder vh, int position) { vh.titleOV.getFrescoAndIconicsImageView().setIcon(Octicons.Icon.oct_git_branch); vh.titleOV.setText(String.format("%s forked %s", event.actor.login, event.repo.name)); vh.actorOV.setVisibility(View.GONE); + } else if (event.type.equals(EventType.ReleaseEvent)) { + vh.titleOV.getFrescoAndIconicsImageView().setIcon(Octicons.Icon.oct_tag); + vh.titleOV.setText(String.format("%s released to %s at %s", event.actor.login, event.payload.release.name,event.repo.name)); + + vh.actorOV.setVisibility(View.VISIBLE); + vh.actorOV.getFrescoAndIconicsImageView().setImageURI(Uri.parse(event.actor.avatar_url)); + vh.actorOV.setText(event.payload.release.assets.get(0).name); + } else if (event.type.equals(EventType.PushEvent)) { + vh.titleOV.getFrescoAndIconicsImageView().setIcon(Octicons.Icon.oct_git_commit); + vh.titleOV.setText(String.format("%s pushed to %s at %s", event.actor.login, event.payload.ref, event.repo.name)); + + vh.actorOV.setVisibility(View.VISIBLE); + vh.actorOV.getFrescoAndIconicsImageView().setImageURI(Uri.parse(event.actor.avatar_url)); + vh.actorOV.setText(event.payload.commits.get(0).message); } else { vh.titleOV.getFrescoAndIconicsImageView().setIcon(Octicons.Icon.oct_unmute); vh.titleOV.setText("unknown"); diff --git a/app/src/main/java/com/frodo/github/common/Path.java b/app/src/main/java/com/frodo/github/common/Path.java index 48d9390..2586324 100644 --- a/app/src/main/java/com/frodo/github/common/Path.java +++ b/app/src/main/java/com/frodo/github/common/Path.java @@ -30,7 +30,9 @@ public final static class Authentication { public final static class Activity { public static final String RECEIVED_EVENTS = "/users/{username}/received_events"; + public static final String USER_EVENTS = "/users/{username}/events"; public static final String NOTIFICATIONS = "/notifications"; + public static final String EVENTS = "/events"; } public final static class Gists { diff --git a/app/src/main/res/layout/drawer_head.xml b/app/src/main/res/layout/drawer_head.xml index 6065287..46422b4 100644 --- a/app/src/main/res/layout/drawer_head.xml +++ b/app/src/main/res/layout/drawer_head.xml @@ -16,6 +16,7 @@ android:contentDescription="@null" android:background="@android:color/white" app:fadeDuration="300" + android:layout_marginTop="@dimen/margin_xlarge" app:roundAsCircle="true" app:roundWithOverlayColor="?attr/colorPrimaryDark" app:roundingBorderWidth="1dp" diff --git a/app/src/main/res/menu/menu_drawer_already_signed.xml b/app/src/main/res/menu/menu_drawer_already_signed.xml index 1f97b49..02d647e 100644 --- a/app/src/main/res/menu/menu_drawer_already_signed.xml +++ b/app/src/main/res/menu/menu_drawer_already_signed.xml @@ -4,6 +4,7 @@ + + + 16dp - 85dp + 100dp 45dp 35dp 25dp diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index d273f70..665623d 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -8,6 +8,7 @@ Sign in Sign out Code + News Issues Events Organizations