Skip to content

Commit

Permalink
develop issue comment page
Browse files Browse the repository at this point in the history
  • Loading branch information
ThirtyDegreesRay committed Sep 29, 2017
1 parent d6f3c26 commit 7c4b08c
Show file tree
Hide file tree
Showing 24 changed files with 526 additions and 21 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ dependencies {

// compile "com.tencent.bugly:crashreport:${BUGGLY_VERSION}"
compile "com.tencent.bugly:crashreport_upgrade:${BUGGLY_VERSION}"
// compile "com.zzhoujay.richtext:richtext:${RICKTEXT_VERSION}"
// compile 'com.zzhoujay.glideimagegetter:glideimagegetter:1.0.5'
compile "com.zzhoujay.richtext:richtext:${RICKTEXT_VERSION}"
compile 'com.zzhoujay.glideimagegetter:glideimagegetter:1.0.5'

}
12 changes: 10 additions & 2 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
~ limitations under the License.
-->
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.thirtydegreesray.openhub">
package="com.thirtydegreesray.openhub"
xmlns:tools="http://schemas.android.com/tools">

<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
Expand All @@ -32,7 +33,8 @@
android:icon="@mipmap/logo_white_round"
android:label="@string/app_name"
android:roundIcon="@mipmap/logo_white_round"
android:supportsRtl="true"
android:supportsRtl="false"
tools:replace="android:supportsRtl"
android:theme="@style/SplashTheme">

<receiver android:name=".service.NetBroadcastReceiver">
Expand Down Expand Up @@ -173,6 +175,12 @@
android:theme="@style/ThemeLight.Green">
</activity>

<activity
android:name=".ui.activity.MarkdownEditorActivity"
android:screenOrientation="portrait"
android:theme="@style/ThemeLight.Green">
</activity>

</application>

</manifest>
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,16 @@

import com.thirtydegreesray.openhub.mvp.model.Issue;
import com.thirtydegreesray.openhub.mvp.model.IssueEvent;
import com.thirtydegreesray.openhub.mvp.model.request.CommentRequestModel;

import java.util.ArrayList;

import retrofit2.Response;
import retrofit2.http.Body;
import retrofit2.http.GET;
import retrofit2.http.Header;
import retrofit2.http.Headers;
import retrofit2.http.POST;
import retrofit2.http.Path;
import retrofit2.http.Query;
import rx.Observable;
Expand Down Expand Up @@ -82,4 +85,13 @@ Observable<Response<ArrayList<IssueEvent>>> getIssueEvents(
@Query("page") int page
);

@NonNull @POST("repos/{owner}/{repo}/issues/{issueNumber}/comments")
@Headers("Accept: application/vnd.github.html")
Observable<Response<IssueEvent>> addComment(
@Path("owner") String owner,
@Path("repo") String repo,
@Path("issueNumber") int issueNumber,
@Body CommentRequestModel body
);

}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import com.thirtydegreesray.openhub.inject.ActivityScope;
import com.thirtydegreesray.openhub.inject.module.ActivityModule;
import com.thirtydegreesray.openhub.ui.activity.MarkdownEditorActivity;
import com.thirtydegreesray.openhub.ui.activity.IssueDetailActivity;
import com.thirtydegreesray.openhub.ui.activity.IssuesActivity;
import com.thirtydegreesray.openhub.ui.activity.LoginActivity;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
package com.thirtydegreesray.openhub.mvp.contract;

import android.support.annotation.NonNull;

import com.thirtydegreesray.openhub.mvp.contract.base.IBaseContract;
import com.thirtydegreesray.openhub.mvp.model.Issue;
import com.thirtydegreesray.openhub.mvp.model.IssueEvent;

/**
* Created by ThirtyDegreesRay on 2017/9/26 16:18:18
Expand All @@ -10,11 +13,12 @@
public interface IIssueDetailContract {

interface View extends IBaseContract.View{
void showIssue(Issue issue);
void showIssue(@NonNull Issue issue);
void showAddedComment(@NonNull IssueEvent event);
}

interface Presenter extends IBaseContract.Presenter<IIssueDetailContract.View> {

void addComment(@NonNull String text);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package com.thirtydegreesray.openhub.mvp.model.request;

import android.os.Parcel;
import android.os.Parcelable;

/**
* Created by ThirtyDegreesRay on 2017/9/29 16:39:59
*/

public class CommentRequestModel implements Parcelable {

private String body;

public CommentRequestModel(String body) {
this.body = body;
}

public String getBody() {
return body;
}

public void setBody(String body) {
this.body = body;
}

@Override
public int describeContents() {
return 0;
}

@Override
public void writeToParcel(Parcel dest, int flags) {
dest.writeString(this.body);
}

protected CommentRequestModel(Parcel in) {
this.body = in.readString();
}

public static final Parcelable.Creator<CommentRequestModel> CREATOR = new Parcelable.Creator<CommentRequestModel>() {
@Override
public CommentRequestModel createFromParcel(Parcel source) {
return new CommentRequestModel(source);
}

@Override
public CommentRequestModel[] newArray(int size) {
return new CommentRequestModel[size];
}
};

}
Original file line number Diff line number Diff line change
@@ -1,13 +1,23 @@
package com.thirtydegreesray.openhub.mvp.presenter;

import android.support.annotation.NonNull;

import com.thirtydegreesray.dataautoaccess.annotation.AutoAccess;
import com.thirtydegreesray.openhub.R;
import com.thirtydegreesray.openhub.dao.DaoSession;
import com.thirtydegreesray.openhub.http.core.HttpObserver;
import com.thirtydegreesray.openhub.http.core.HttpResponse;
import com.thirtydegreesray.openhub.mvp.contract.IIssueDetailContract;
import com.thirtydegreesray.openhub.mvp.model.Issue;
import com.thirtydegreesray.openhub.mvp.model.IssueEvent;
import com.thirtydegreesray.openhub.mvp.model.request.CommentRequestModel;
import com.thirtydegreesray.openhub.mvp.presenter.base.BasePresenter;

import javax.inject.Inject;

import retrofit2.Response;
import rx.Observable;

/**
* Created by ThirtyDegreesRay on 2017/9/26 16:53:52
*/
Expand All @@ -31,4 +41,28 @@ public void onViewInitialized() {
public Issue getIssue() {
return issue;
}

@Override
public void addComment(@NonNull final String text) {
HttpObserver<IssueEvent> httpObserver
= new HttpObserver<IssueEvent>() {
@Override
public void onError(Throwable error) {
mView.showErrorToast(getErrorTip(error));
}

@Override
public void onSuccess(HttpResponse<IssueEvent> response) {
mView.showSuccessToast(getString(R.string.comment_success));
mView.showAddedComment(response.body());
}
};
generalRxHttpExecute(new IObservableCreator<IssueEvent>() {
@Override
public Observable<Response<IssueEvent>> createObservable(boolean forceNetWork) {
return getIssueService().addComment(issue.getUser().getLogin(),
issue.getRepoName(), issue.getNumber(), new CommentRequestModel(text));
}
}, httpObserver);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -135,4 +135,7 @@ private void handleError(Throwable error){
}
}

public ArrayList<IssueEvent> getTimeline() {
return timeline;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import android.os.Handler;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.design.widget.FloatingActionButton;
import android.support.v4.app.ActivityOptionsCompat;
import android.support.v4.util.Pair;
import android.view.Menu;
Expand All @@ -21,13 +22,15 @@
import com.thirtydegreesray.openhub.inject.module.ActivityModule;
import com.thirtydegreesray.openhub.mvp.contract.IIssueDetailContract;
import com.thirtydegreesray.openhub.mvp.model.Issue;
import com.thirtydegreesray.openhub.mvp.model.IssueEvent;
import com.thirtydegreesray.openhub.mvp.presenter.IssueDetailPresenter;
import com.thirtydegreesray.openhub.ui.activity.base.BaseActivity;
import com.thirtydegreesray.openhub.ui.fragment.IssueTimelineFragment;
import com.thirtydegreesray.openhub.util.AppHelper;
import com.thirtydegreesray.openhub.util.BundleBuilder;

import butterknife.BindView;
import butterknife.OnClick;

/**
* Created by ThirtyDegreesRay on 2017/9/26 19:27:11
Expand Down Expand Up @@ -57,9 +60,12 @@ public static void show(@NonNull Activity activity, @NonNull Issue issue){
@BindView(R.id.issue_title) TextView issueTitle;
@BindView(R.id.issue_state_img) ImageView issueStateImg;
@BindView(R.id.issue_state_text) TextView issueStateText;
@BindView(R.id.comment_bn) FloatingActionButton commentBn;

private IssueTimelineFragment issueTimelineFragment;

private final int ADD_COMMENT_REQUEST_CODE = 100;

@Override
protected void setupActivityComponent(AppComponent appComponent) {
DaggerActivityComponent.builder()
Expand Down Expand Up @@ -116,6 +122,7 @@ public void showIssue(final Issue issue) {
.placeholder(R.mipmap.logo)
.into(userImageView);
issueTitle.setText(issue.getTitle());
commentBn.setVisibility(issue.isLocked() ? View.GONE : View.VISIBLE);

String commentStr = String.valueOf(issue.getCommentNum()).concat(" ")
.concat(getString(R.string.comments).toLowerCase());
Expand All @@ -137,7 +144,26 @@ public void run() {
.commit();
}
}, 500);
}

@Override
public void showAddedComment(@NonNull IssueEvent event) {
issueTimelineFragment.addComment(event);
}

@OnClick(R.id.comment_bn)
public void onCommentBnClicked(){
MarkdownEditorActivity.show(getActivity(), R.string.comment, ADD_COMMENT_REQUEST_CODE);
}

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if(resultCode != RESULT_OK) return;
if(requestCode == ADD_COMMENT_REQUEST_CODE){
String text = data.getExtras().getString("text");
mPresenter.addComment(text);
return ;
}
super.onActivityResult(requestCode, resultCode, data);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,11 @@ public static void showForUser(@NonNull Activity activity){

private ArrayList<IssuesFilterListener> listeners ;

@Override
protected void initActivity() {
super.initActivity();
}

@Override
protected void setupActivityComponent(AppComponent appComponent) {
DaggerActivityComponent.builder()
Expand Down Expand Up @@ -129,8 +134,8 @@ private IssuesFilter getIssuesFilter(boolean open){
MenuItem selectedUserFilterMenu = ViewHelper.getSelectedMenu(
navView.getMenu().findItem(R.id.nav_type_chooser));
if(selectedUserFilterMenu != null) {
IssuesFilter.UserIssuesFilterType userFilterType = Enum.valueOf(
IssuesFilter.UserIssuesFilterType.class, selectedUserFilterMenu.getTitle().toString());
IssuesFilter.UserIssuesFilterType userFilterType =
getUserIssuesFilterType(selectedUserFilterMenu.getItemId());
issuesFilter.setUserIssuesFilterType(userFilterType);
}
}
Expand Down Expand Up @@ -170,6 +175,23 @@ private IssuesFilter getIssuesFilter(boolean open){
return issuesFilter;
}

private IssuesFilter.UserIssuesFilterType getUserIssuesFilterType(int itemId){
switch (itemId){
case R.id.nav_all:
return IssuesFilter.UserIssuesFilterType.All;
case R.id.nav_created:
return IssuesFilter.UserIssuesFilterType.Created;
case R.id.nav_assigned:
return IssuesFilter.UserIssuesFilterType.Assigned;
case R.id.nav_mentioned:
return IssuesFilter.UserIssuesFilterType.Mentioned;
case R.id.nav_subscribed:
return IssuesFilter.UserIssuesFilterType.Subscribed;
default:
return IssuesFilter.UserIssuesFilterType.All;
}
}

public interface IssuesFilterListener{
void onIssuesFilterChanged(@NonNull IssuesFilter issuesFilter);
}
Expand Down
Loading

0 comments on commit 7c4b08c

Please sign in to comment.