mirror of
https://github.com/k0shk0sh/FastHub.git
synced 2025-12-08 19:05:54 +00:00
fix posting reaction
This commit is contained in:
parent
429f984bf4
commit
9709baa13e
@ -306,7 +306,6 @@
|
||||
</service>
|
||||
<service android:name=".provider.tasks.notification.ReadNotificationService" />
|
||||
<service android:name=".provider.tasks.git.GithubActionService" />
|
||||
<service android:name=".provider.tasks.git.ReactionService" />
|
||||
<service android:name=".provider.tasks.slack.SlackInvitationService" />
|
||||
<service android:name=".provider.tasks.version.CheckVersionService" />
|
||||
<service
|
||||
|
||||
@ -35,6 +35,16 @@ public enum ReactionTypes {
|
||||
return content;
|
||||
}
|
||||
|
||||
public String getPostContent() {
|
||||
if (this == PLUS_ONE) {
|
||||
return "+1";
|
||||
} else if (this == MINUS_ONE) {
|
||||
return "-1";
|
||||
} else {
|
||||
return getContent();
|
||||
}
|
||||
}
|
||||
|
||||
@IdRes public int getvId() {
|
||||
return vId;
|
||||
}
|
||||
|
||||
@ -1,109 +0,0 @@
|
||||
package com.fastaccess.provider.tasks.git;
|
||||
|
||||
import android.app.IntentService;
|
||||
import android.app.NotificationManager;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.core.app.NotificationCompat;
|
||||
|
||||
import com.fastaccess.R;
|
||||
import com.fastaccess.data.dao.PostReactionModel;
|
||||
import com.fastaccess.data.dao.types.ReactionTypes;
|
||||
import com.fastaccess.helper.BundleConstant;
|
||||
import com.fastaccess.helper.Bundler;
|
||||
import com.fastaccess.helper.InputHelper;
|
||||
import com.fastaccess.helper.RxHelper;
|
||||
import com.fastaccess.provider.rest.RestProvider;
|
||||
|
||||
/**
|
||||
* Created by Kosh on 29 Mar 2017, 9:59 PM
|
||||
*/
|
||||
|
||||
public class ReactionService extends IntentService {
|
||||
|
||||
private NotificationCompat.Builder notification;
|
||||
private NotificationManager notificationManager;
|
||||
|
||||
public static void start(@NonNull Context context, @NonNull String login, @NonNull String repo,
|
||||
long commentId, ReactionTypes reactionType, boolean isCommit, boolean isDelete,
|
||||
boolean isEnterprise) {
|
||||
Intent intent = new Intent(context, ReactionService.class);
|
||||
intent.putExtras(Bundler.start()
|
||||
.put(BundleConstant.EXTRA, isCommit)
|
||||
.put(BundleConstant.EXTRA_TWO, login)
|
||||
.put(BundleConstant.EXTRA_THREE, repo)
|
||||
.put(BundleConstant.EXTRA_FOUR, isDelete)
|
||||
.put(BundleConstant.ID, commentId)
|
||||
.put(BundleConstant.EXTRA_TYPE, reactionType)
|
||||
.put(BundleConstant.IS_ENTERPRISE, isEnterprise)
|
||||
.end());
|
||||
context.startService(intent);
|
||||
}
|
||||
|
||||
public ReactionService() {
|
||||
super(ReactionService.class.getSimpleName());
|
||||
}
|
||||
|
||||
@Override protected void onHandleIntent(@Nullable Intent intent) {
|
||||
if (intent != null && intent.getExtras() != null) {
|
||||
Bundle bundle = intent.getExtras();
|
||||
ReactionTypes reactionType = (ReactionTypes) bundle.getSerializable(BundleConstant.EXTRA_TYPE);
|
||||
boolean isCommit = bundle.getBoolean(BundleConstant.EXTRA);
|
||||
String login = bundle.getString(BundleConstant.EXTRA_TWO);
|
||||
String repo = bundle.getString(BundleConstant.EXTRA_THREE);
|
||||
long commentId = bundle.getLong(BundleConstant.ID);
|
||||
boolean isEnterprise = bundle.getBoolean(BundleConstant.IS_ENTERPRISE);
|
||||
if (InputHelper.isEmpty(login) || InputHelper.isEmpty(repo) || reactionType == null) {
|
||||
stopSelf();
|
||||
return;
|
||||
}
|
||||
if (isCommit) {
|
||||
postCommit(reactionType, login, repo, commentId, isEnterprise);
|
||||
} else {
|
||||
post(reactionType, login, repo, commentId, isEnterprise);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void post(@NonNull ReactionTypes reactionType, @NonNull String login, @NonNull String repo, long commentId, boolean isEnterprise) {
|
||||
RxHelper.safeObservable(RestProvider.getReactionsService(isEnterprise)
|
||||
.postIssueCommentReaction(new PostReactionModel(reactionType.getContent()), login, repo, commentId))
|
||||
.doOnSubscribe(disposable -> showNotification(getNotification(reactionType), (int) commentId))
|
||||
.subscribe(response -> hideNotification((int) commentId), throwable -> hideNotification((int) commentId));
|
||||
}
|
||||
|
||||
private void postCommit(@NonNull ReactionTypes reactionType, @NonNull String login, @NonNull String repo, long commentId, boolean isEnterprise) {
|
||||
RxHelper.safeObservable(RestProvider.getReactionsService(isEnterprise)
|
||||
.postCommitReaction(new PostReactionModel(reactionType.getContent()), login, repo, commentId))
|
||||
.doOnSubscribe(disposable -> showNotification(getNotification(reactionType), (int) commentId))
|
||||
.subscribe(response -> hideNotification((int) commentId), throwable -> hideNotification((int) commentId));
|
||||
}
|
||||
|
||||
public NotificationCompat.Builder getNotification(@NonNull ReactionTypes reactionTypes) {
|
||||
if (notification == null) {
|
||||
notification = new NotificationCompat.Builder(this, "reaction")
|
||||
.setSmallIcon(R.drawable.ic_sync)
|
||||
.setProgress(0, 100, true);
|
||||
}
|
||||
notification.setContentTitle(getString(R.string.posting_reaction, reactionTypes.getContent()));
|
||||
return notification;
|
||||
}
|
||||
|
||||
public NotificationManager getNotificationManager() {
|
||||
if (notificationManager == null) {
|
||||
notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
|
||||
}
|
||||
return notificationManager;
|
||||
}
|
||||
|
||||
private void showNotification(@NonNull NotificationCompat.Builder builder, int id) {
|
||||
getNotificationManager().notify(id, builder.build());
|
||||
}
|
||||
|
||||
private void hideNotification(int id) {
|
||||
getNotificationManager().cancel(id);
|
||||
}
|
||||
}
|
||||
@ -1,28 +1,21 @@
|
||||
package com.fastaccess.provider.timeline;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import androidx.annotation.IdRes;
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import android.view.View;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.annimon.stream.Collectors;
|
||||
import com.annimon.stream.Stream;
|
||||
import com.fastaccess.R;
|
||||
import com.fastaccess.data.dao.ReactionsModel;
|
||||
import com.fastaccess.data.dao.TimelineModel;
|
||||
import com.fastaccess.data.dao.model.Comment;
|
||||
import com.fastaccess.data.dao.types.ReactionTypes;
|
||||
import com.fastaccess.provider.tasks.git.ReactionService;
|
||||
import com.fastaccess.ui.widgets.SpannableBuilder;
|
||||
|
||||
import org.w3c.dom.Text;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
/**
|
||||
* Created by Kosh on 30 Mar 2017, 6:44 PM
|
||||
*/
|
||||
|
||||
@ -50,19 +50,19 @@ public class ReactionsProvider {
|
||||
switch (reactionType) {
|
||||
case COMMENT:
|
||||
observable = RestProvider.getReactionsService(isEnterprise)
|
||||
.postIssueCommentReaction(new PostReactionModel(reactionTypes.getContent()), login, repoId, idOrNumber);
|
||||
.postIssueCommentReaction(new PostReactionModel(reactionTypes.getPostContent()), login, repoId, idOrNumber);
|
||||
break;
|
||||
case HEADER:
|
||||
observable = RestProvider.getReactionsService(isEnterprise)
|
||||
.postIssueReaction(new PostReactionModel(reactionTypes.getContent()), login, repoId, idOrNumber);
|
||||
.postIssueReaction(new PostReactionModel(reactionTypes.getPostContent()), login, repoId, idOrNumber);
|
||||
break;
|
||||
case REVIEW_COMMENT:
|
||||
observable = RestProvider.getReactionsService(isEnterprise)
|
||||
.postCommentReviewReaction(new PostReactionModel(reactionTypes.getContent()), login, repoId, idOrNumber);
|
||||
.postCommentReviewReaction(new PostReactionModel(reactionTypes.getPostContent()), login, repoId, idOrNumber);
|
||||
break;
|
||||
case COMMIT:
|
||||
observable = RestProvider.getReactionsService(isEnterprise)
|
||||
.postCommitReaction(new PostReactionModel(reactionTypes.getContent()), login, repoId, idOrNumber);
|
||||
.postCommitReaction(new PostReactionModel(reactionTypes.getPostContent()), login, repoId, idOrNumber);
|
||||
break;
|
||||
}
|
||||
if (observable == null) return null;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user