Skip to content

Commit

Permalink
add news and events
Browse files Browse the repository at this point in the history
  • Loading branch information
frodoking committed Jun 13, 2016
1 parent af9e728 commit a6dac6f
Show file tree
Hide file tree
Showing 9 changed files with 109 additions and 39 deletions.
33 changes: 23 additions & 10 deletions app/src/main/java/com/frodo/github/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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();
Expand All @@ -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);
Expand Down Expand Up @@ -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);

Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -26,6 +28,8 @@
public class EventsFragment extends StatedFragment<EventsView, EventsModel> {

private List<GithubEvent> stateContents;
private String repoOwner;
private String repo;

@Override
public EventsView createUIView(Context context, LayoutInflater inflater, ViewGroup container) {
Expand Down Expand Up @@ -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<List<GithubEvent>>() {
@Override
public void call(List<GithubEvent> events) {
stateContents = events;
CircleProgressDialog.hideLoadingDialog();
getUIView().hideEmptyView();
getUIView().showDetail(events);
}
},
new Action1<Throwable>() {
//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<List<GithubEvent>> 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<List<GithubEvent>>() {
@Override
public void call(List<GithubEvent> events) {
stateContents = events;
CircleProgressDialog.hideLoadingDialog();
getUIView().hideEmptyView();
getUIView().showDetail(events);
}
},
new Action1<Throwable>() {
@Override
public void call(Throwable throwable) {
CircleProgressDialog.hideLoadingDialog();
getUIView().showErrorView(ViewProvider.handleError(getMainController().getConfig().isDebug(), throwable));
}
});
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,21 @@ public String name() {
return TAG;
}

public Observable<List<GithubEvent>> loadAccountEvents(String accountUser) {
return loadEventsWithReactor(Path.replace(Path.Activity.USER_EVENTS, new Pair<>("username", accountUser)));
}

public Observable<List<GithubEvent>> loadReceivedEvents(final String username) {
return loadEventsWithReactor(Path.replace(Path.Activity.RECEIVED_EVENTS, new Pair<>("username", username)));
}

private Observable<List<GithubEvent>> loadEventsWithReactor(final String path) {
return Observable.create(new Observable.OnSubscribe<Response>() {
@Override
public void call(Subscriber<? super Response> 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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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");
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/java/com/frodo/github/common/Path.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/layout/drawer_head.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
9 changes: 9 additions & 0 deletions app/src/main/res/menu/menu_drawer_already_signed.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
<group
android:id="@+id/group_base"
android:checkableBehavior="single">

<item
android:id="@+id/action_notifications"
android:title="@string/menu_notifications"
Expand All @@ -21,6 +22,10 @@
<group
android:id="@+id/group_info"
android:checkableBehavior="single">
<item
android:id="@+id/action_news"
android:title="@string/menu_news"
android:checkable="true"/>
<item
android:id="@+id/action_issues"
android:title="@string/menu_issues"
Expand All @@ -29,6 +34,10 @@
android:id="@+id/action_events"
android:title="@string/menu_events"
android:checkable="true"/>
<item
android:id="@+id/action_repositories"
android:title="@string/menu_repositories"
android:checkable="true"/>
</group>
<group
android:id="@+id/group_other"
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/values/dimens.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@

<dimen name="icon_size">16dp</dimen>

<dimen name="image_size_xxlarge">85dp</dimen>
<dimen name="image_size_xxlarge">100dp</dimen>
<dimen name="image_size_xlarge">45dp</dimen>
<dimen name="image_size_large">35dp</dimen>
<dimen name="image_size_default">25dp</dimen>
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
<string name="menu_sign_in">Sign in</string>
<string name="menu_sign_out">Sign out</string>
<string name="menu_code">Code</string>
<string name="menu_news">News</string>
<string name="menu_issues">Issues</string>
<string name="menu_events">Events</string>
<string name="menu_organizations">Organizations</string>
Expand Down

0 comments on commit a6dac6f

Please sign in to comment.