mirror of
https://github.com/k0shk0sh/FastHub.git
synced 2025-12-08 19:05:54 +00:00
this commit fixes #288
it also improves notifications for good in notification panel & adds gist files deep links.
This commit is contained in:
parent
1c1301eb2a
commit
ade1fe84cc
@ -26,6 +26,7 @@ _(To download the app from here, please look at the [latest release](https://git
|
||||
- Offline-mode
|
||||
- Markdown and code highlighting support
|
||||
- Notifications overview and "Mark all as read"
|
||||
- Search users/orgs, repos, issues/prs & code.
|
||||
- Pinned Repos
|
||||
- **Repositories**
|
||||
- Search Repos
|
||||
@ -54,6 +55,11 @@ _(To download the app from here, please look at the [latest release](https://git
|
||||
- Comment on Commits/Gists
|
||||
- Manage Commit/Gist comments
|
||||
- Create/Delete Gists
|
||||
- **Orgs**
|
||||
- Overview
|
||||
- Feeds
|
||||
- Teams & Teams repos
|
||||
- Repos
|
||||
- **Users**
|
||||
- Follow/unfollow users
|
||||
- Search Users, Repos, Issues,Pull Requests and Code
|
||||
|
||||
@ -197,6 +197,10 @@
|
||||
android:host="raw.githubusercontent.com"
|
||||
android:scheme="https"/>
|
||||
|
||||
<data
|
||||
android:host="raw.githubusercontent.com"
|
||||
android:scheme="https"/>
|
||||
|
||||
<data android:pathPattern=".*"/>
|
||||
|
||||
<category android:name="android.intent.category.DEFAULT"/>
|
||||
@ -206,8 +210,7 @@
|
||||
|
||||
<service
|
||||
android:name=".provider.tasks.notification.NotificationSchedulerJobTask"
|
||||
android:permission="android.permission.BIND_JOB_SERVICE">
|
||||
</service>
|
||||
android:permission="android.permission.BIND_JOB_SERVICE"/>
|
||||
<service android:name=".provider.tasks.notification.ReadNotificationService"/>
|
||||
<service android:name=".provider.tasks.git.GithubActionService"/>
|
||||
<service android:name=".provider.tasks.git.ReactionService"/>
|
||||
|
||||
@ -67,4 +67,8 @@ public class InputHelper {
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
public static int getSafeIntId(long id) {
|
||||
return id > Integer.MAX_VALUE ? (int) (id - Integer.MAX_VALUE) : (int) id;
|
||||
}
|
||||
}
|
||||
|
||||
@ -0,0 +1,30 @@
|
||||
package com.fastaccess.provider.scheme;
|
||||
|
||||
import android.support.annotation.NonNull;
|
||||
|
||||
import com.annimon.stream.Collectors;
|
||||
import com.annimon.stream.Optional;
|
||||
import com.annimon.stream.Stream;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
/**
|
||||
* Created by Kosh on 11 Apr 2017, 10:02 PM
|
||||
*/
|
||||
|
||||
class LinkParserHelper {
|
||||
static final String HOST_DEFAULT = "github.com";
|
||||
static final String HOST_GISTS = "gist.github.com";
|
||||
static final String HOST_GISTS_RAW = "gist.githubusercontent.com";
|
||||
static final String RAW_AUTHORITY = "raw.githubusercontent.com";
|
||||
static final String API_AUTHORITY = "api.github.com";
|
||||
static final String PROTOCOL_HTTPS = "https";
|
||||
static final ArrayList<String> IGNORED_LIST = Stream.of("notifications", "settings", "blog", "explore",
|
||||
"dashboard", "repositories", "site", "security", "contact", "about", "")
|
||||
.collect(Collectors.toCollection(ArrayList::new));
|
||||
|
||||
|
||||
@SafeVarargs static <T> Optional<T> returnNonNull(@NonNull T... t) {
|
||||
return Stream.of(t).filter(value -> value != null).findFirst();
|
||||
}
|
||||
}
|
||||
@ -10,9 +10,7 @@ import android.support.annotation.Nullable;
|
||||
import android.text.TextUtils;
|
||||
import android.webkit.MimeTypeMap;
|
||||
|
||||
import com.annimon.stream.Collectors;
|
||||
import com.annimon.stream.Optional;
|
||||
import com.annimon.stream.Stream;
|
||||
import com.fastaccess.helper.ActivityHelper;
|
||||
import com.fastaccess.helper.InputHelper;
|
||||
import com.fastaccess.helper.Logger;
|
||||
@ -25,23 +23,22 @@ import com.fastaccess.ui.modules.repos.issues.issue.details.IssuePagerView;
|
||||
import com.fastaccess.ui.modules.repos.pull_requests.pull_request.details.PullRequestPagerView;
|
||||
import com.fastaccess.ui.modules.user.UserPagerView;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import static com.fastaccess.provider.scheme.LinkParserHelper.*;
|
||||
import static com.fastaccess.provider.scheme.LinkParserHelper.API_AUTHORITY;
|
||||
import static com.fastaccess.provider.scheme.LinkParserHelper.HOST_DEFAULT;
|
||||
import static com.fastaccess.provider.scheme.LinkParserHelper.HOST_GISTS;
|
||||
import static com.fastaccess.provider.scheme.LinkParserHelper.HOST_GISTS_RAW;
|
||||
import static com.fastaccess.provider.scheme.LinkParserHelper.PROTOCOL_HTTPS;
|
||||
import static com.fastaccess.provider.scheme.LinkParserHelper.RAW_AUTHORITY;
|
||||
import static com.fastaccess.provider.scheme.LinkParserHelper.returnNonNull;
|
||||
|
||||
/**
|
||||
* Created by Kosh on 09 Dec 2016, 4:44 PM
|
||||
*/
|
||||
|
||||
public class SchemeParser {
|
||||
private static final String HOST_DEFAULT = "github.com";
|
||||
private static final String HOST_GISTS = "gist.github.com";
|
||||
private static final String RAW_AUTHORITY = "raw.githubusercontent.com";
|
||||
private static final String API_AUTHORITY = "api.github.com";
|
||||
private static final String PROTOCOL_HTTPS = "https";
|
||||
|
||||
static final ArrayList<String> IGNORED_LIST = Stream.of("notifications", "settings", "blog", "explore",
|
||||
"dashboard", "repositories", "site", "security", "contact", "about", "")
|
||||
.collect(Collectors.toCollection(ArrayList::new));
|
||||
|
||||
public static void launchUri(@NonNull Context context, @NonNull Uri data) {
|
||||
launchUri(context, data, false);
|
||||
@ -79,8 +76,8 @@ public class SchemeParser {
|
||||
}
|
||||
}
|
||||
if (!data.getPathSegments().isEmpty()) {
|
||||
Logger.e(SchemeParser.IGNORED_LIST.contains(data.getPath()), data.getPathSegments().get(0));
|
||||
if (SchemeParser.IGNORED_LIST.contains(data.getPathSegments().get(0))) return null;
|
||||
Logger.e(IGNORED_LIST.contains(data.getPath()), data.getPathSegments().get(0));
|
||||
if (IGNORED_LIST.contains(data.getPathSegments().get(0))) return null;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
@ -93,6 +90,8 @@ public class SchemeParser {
|
||||
if (gist != null) {
|
||||
return GistView.createIntent(context, gist);
|
||||
}
|
||||
} else if (HOST_GISTS_RAW.equalsIgnoreCase(data.getHost())) {
|
||||
return getGistFile(context, data);
|
||||
} else {
|
||||
String authority = data.getAuthority();
|
||||
if (TextUtils.equals(authority, HOST_DEFAULT) || TextUtils.equals(authority, RAW_AUTHORITY) ||
|
||||
@ -205,7 +204,7 @@ public class SchemeParser {
|
||||
|
||||
@Nullable private static Intent getCommits(@NonNull Context context, @NonNull Uri uri, boolean showRepoBtn) {
|
||||
List<String> segments = uri.getPathSegments();
|
||||
if (segments == null || segments.isEmpty() || segments.size() < 4) return null;
|
||||
if (segments == null || segments.isEmpty() || segments.size() < 3) return null;
|
||||
if (segments.get(3).equals("commits")) {
|
||||
String login = segments.get(1);
|
||||
String repoId = segments.get(2);
|
||||
@ -217,7 +216,7 @@ public class SchemeParser {
|
||||
|
||||
@Nullable private static Intent getCommit(@NonNull Context context, @NonNull Uri uri, boolean showRepoBtn) {
|
||||
List<String> segments = uri.getPathSegments();
|
||||
if (segments == null || segments.size() < 4 || !"commit".equals(segments.get(2))) return null;
|
||||
if (segments == null || segments.size() < 3 || !"commit".equals(segments.get(2))) return null;
|
||||
String login = segments.get(0);
|
||||
String repoId = segments.get(1);
|
||||
String sha = segments.get(3);
|
||||
@ -283,7 +282,10 @@ public class SchemeParser {
|
||||
return null;
|
||||
}
|
||||
|
||||
@SafeVarargs private static <T> Optional<T> returnNonNull(@NonNull T... t) {
|
||||
return Stream.of(t).filter(value -> value != null).findFirst();
|
||||
@Nullable private static Intent getGistFile(@NonNull Context context, @NonNull Uri uri) {
|
||||
if (uri.getHost().equalsIgnoreCase(HOST_GISTS_RAW)) {
|
||||
return CodeViewerView.createIntent(context, uri.toString());
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@ -10,7 +10,6 @@ import android.text.TextUtils;
|
||||
import android.webkit.MimeTypeMap;
|
||||
|
||||
import com.annimon.stream.Optional;
|
||||
import com.annimon.stream.Stream;
|
||||
import com.fastaccess.helper.ActivityHelper;
|
||||
import com.fastaccess.helper.InputHelper;
|
||||
import com.fastaccess.helper.Logger;
|
||||
@ -28,16 +27,20 @@ import com.fastaccess.ui.modules.user.UserPagerView;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static com.fastaccess.provider.scheme.LinkParserHelper.API_AUTHORITY;
|
||||
import static com.fastaccess.provider.scheme.LinkParserHelper.HOST_DEFAULT;
|
||||
import static com.fastaccess.provider.scheme.LinkParserHelper.HOST_GISTS;
|
||||
import static com.fastaccess.provider.scheme.LinkParserHelper.HOST_GISTS_RAW;
|
||||
import static com.fastaccess.provider.scheme.LinkParserHelper.IGNORED_LIST;
|
||||
import static com.fastaccess.provider.scheme.LinkParserHelper.PROTOCOL_HTTPS;
|
||||
import static com.fastaccess.provider.scheme.LinkParserHelper.RAW_AUTHORITY;
|
||||
import static com.fastaccess.provider.scheme.LinkParserHelper.returnNonNull;
|
||||
|
||||
/**
|
||||
* Created by Kosh on 09 Dec 2016, 4:44 PM
|
||||
*/
|
||||
|
||||
public class StackBuilderSchemeParser {
|
||||
private static final String HOST_DEFAULT = "github.com";
|
||||
private static final String HOST_GISTS = "gist.github.com";
|
||||
private static final String RAW_AUTHORITY = "raw.githubusercontent.com";
|
||||
private static final String API_AUTHORITY = "api.github.com";
|
||||
private static final String PROTOCOL_HTTPS = "https";
|
||||
|
||||
public static void launchUri(@NonNull Context context, @NonNull Intent data) {
|
||||
if (data.getData() != null) {
|
||||
@ -74,8 +77,7 @@ public class StackBuilderSchemeParser {
|
||||
}
|
||||
}
|
||||
if (!data.getPathSegments().isEmpty()) {
|
||||
Logger.e(SchemeParser.IGNORED_LIST.contains(data.getPath()), data.getPathSegments().get(0));
|
||||
if (SchemeParser.IGNORED_LIST.contains(data.getPathSegments().get(0))) return null;
|
||||
if (IGNORED_LIST.contains(data.getPathSegments().get(0))) return null;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
@ -91,6 +93,8 @@ public class StackBuilderSchemeParser {
|
||||
.addNextIntentWithParentStack(new Intent(context, MainView.class))
|
||||
.addNextIntent(GistView.createIntent(context, gist));
|
||||
}
|
||||
} else if (HOST_GISTS_RAW.equalsIgnoreCase(data.getHost())) {
|
||||
return getGistFile(context, data);
|
||||
} else {
|
||||
String authority = data.getAuthority();
|
||||
if (TextUtils.equals(authority, HOST_DEFAULT) || TextUtils.equals(authority, RAW_AUTHORITY) ||
|
||||
@ -311,9 +315,6 @@ public class StackBuilderSchemeParser {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* https://github.com/owner/repo/issues/new
|
||||
*/
|
||||
@Nullable private static TaskStackBuilder getCreateIssueIntent(@NonNull Context context, @NonNull Uri uri) {
|
||||
List<String> segments = uri.getPathSegments();
|
||||
Logger.e(segments);
|
||||
@ -331,8 +332,15 @@ public class StackBuilderSchemeParser {
|
||||
return null;
|
||||
}
|
||||
|
||||
@SafeVarargs private static <T> Optional<T> returnNonNull(T... t) {
|
||||
return Stream.of(t).filter(value -> value != null).findFirst();
|
||||
@Nullable private static TaskStackBuilder getGistFile(@NonNull Context context, @NonNull Uri uri) {
|
||||
if (uri.getHost().equalsIgnoreCase(HOST_GISTS_RAW)) {
|
||||
return TaskStackBuilder.create(context)
|
||||
.addParentStack(MainView.class)
|
||||
.addNextIntentWithParentStack(new Intent(context, MainView.class))
|
||||
.addNextIntentWithParentStack(GistView.createIntent(context, uri.getPathSegments().get(1)))
|
||||
.addNextIntent(CodeViewerView.createIntent(context, uri.toString()));
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Nullable private static String getGistId(@NonNull Uri uri) {
|
||||
|
||||
@ -15,6 +15,7 @@ import android.os.Build;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.v4.app.NotificationCompat;
|
||||
import android.support.v4.content.ContextCompat;
|
||||
|
||||
import com.annimon.stream.Stream;
|
||||
import com.fastaccess.R;
|
||||
@ -22,15 +23,17 @@ import com.fastaccess.data.dao.model.Comment;
|
||||
import com.fastaccess.data.dao.model.Login;
|
||||
import com.fastaccess.data.dao.model.Notification;
|
||||
import com.fastaccess.helper.AppHelper;
|
||||
import com.fastaccess.helper.BundleConstant;
|
||||
import com.fastaccess.helper.InputHelper;
|
||||
import com.fastaccess.helper.Logger;
|
||||
import com.fastaccess.helper.PrefGetter;
|
||||
import com.fastaccess.helper.RxHelper;
|
||||
import com.fastaccess.helper.ViewHelper;
|
||||
import com.fastaccess.provider.rest.RestProvider;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import rx.Observable;
|
||||
import rx.schedulers.Schedulers;
|
||||
|
||||
/**
|
||||
@ -50,11 +53,14 @@ public class NotificationSchedulerJobTask extends JobService {
|
||||
.subscribe(item -> {
|
||||
AppHelper.cancelAllNotifications(getApplicationContext());
|
||||
if (item != null) {
|
||||
onSave(item.getItems());
|
||||
onSave(item.getItems(), job);
|
||||
} else {
|
||||
finishJob(job);
|
||||
}
|
||||
scheduleJob(getApplicationContext());
|
||||
jobFinished(job, false);
|
||||
}, Throwable::printStackTrace);
|
||||
}, throwable -> finishJob(job));
|
||||
} else {
|
||||
finishJob(job);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@ -69,41 +75,35 @@ public class NotificationSchedulerJobTask extends JobService {
|
||||
}
|
||||
|
||||
public static void scheduleJob(@NonNull Context context, long duration, boolean cancel) {
|
||||
JobScheduler mJobScheduler = (JobScheduler)
|
||||
context.getSystemService( Context.JOB_SCHEDULER_SERVICE );
|
||||
JobScheduler mJobScheduler = (JobScheduler) context.getSystemService(Context.JOB_SCHEDULER_SERVICE);
|
||||
if (cancel) mJobScheduler.cancel(JOB_ID_EVERY_30_MINS);
|
||||
if (duration == -1) {
|
||||
mJobScheduler.cancel(JOB_ID_EVERY_30_MINS);
|
||||
return;
|
||||
}
|
||||
duration = duration <= 0 ? THIRTY_MINUTES : duration;
|
||||
|
||||
JobInfo.Builder builder = new JobInfo.Builder(JOB_ID_EVERY_30_MINS, new ComponentName(context.getPackageName(),
|
||||
NotificationSchedulerJobTask.class.getName()))
|
||||
.setBackoffCriteria(JobInfo.DEFAULT_INITIAL_BACKOFF_MILLIS, JobInfo.BACKOFF_POLICY_LINEAR)
|
||||
.setPersisted(true)
|
||||
.setRequiredNetworkType(JobInfo.NETWORK_TYPE_ANY);
|
||||
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N &&
|
||||
duration < JobInfo.getMinPeriodMillis()) {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N && duration < JobInfo.getMinPeriodMillis()) {
|
||||
builder.setMinimumLatency(duration);
|
||||
} else {
|
||||
builder.setPeriodic(duration);
|
||||
}
|
||||
|
||||
if (mJobScheduler.schedule(builder.build()) <= 0) {
|
||||
// something gone wrong
|
||||
}
|
||||
mJobScheduler.schedule(builder.build());
|
||||
}
|
||||
|
||||
private void onSave(@Nullable List<Notification> notificationThreadModels) {
|
||||
private void onSave(@Nullable List<Notification> notificationThreadModels, JobParameters job) {
|
||||
if (notificationThreadModels != null) {
|
||||
RxHelper.safeObservable(Notification.save(notificationThreadModels)).subscribe();
|
||||
onNotifyUser(notificationThreadModels);
|
||||
onNotifyUser(notificationThreadModels, job);
|
||||
}
|
||||
}
|
||||
|
||||
private void onNotifyUser(@NonNull List<Notification> notificationThreadModels) {
|
||||
private void onNotifyUser(@NonNull List<Notification> notificationThreadModels, JobParameters job) {
|
||||
long count = Stream.of(notificationThreadModels)
|
||||
.filter(Notification::isUnread)
|
||||
.count();
|
||||
@ -112,82 +112,90 @@ public class NotificationSchedulerJobTask extends JobService {
|
||||
return;
|
||||
}
|
||||
Context context = getApplicationContext();
|
||||
int accentColor = ContextCompat.getColor(this, R.color.material_blue_700);
|
||||
Bitmap largeIcon = BitmapFactory.decodeResource(context.getResources(),
|
||||
R.mipmap.ic_launcher);
|
||||
int accentColor = ViewHelper.getAccentColor(context);
|
||||
Notification firstNotification = notificationThreadModels.get(0);
|
||||
android.app.Notification grouped = getSummaryGroupNotification(firstNotification, accentColor, largeIcon);
|
||||
showNotification((int) firstNotification.getId(), grouped);
|
||||
Stream.of(notificationThreadModels)
|
||||
.filter(notification -> notification.isUnread() && notification.getId() != firstNotification.getId())
|
||||
Observable.from(notificationThreadModels)
|
||||
.subscribeOn(Schedulers.io())
|
||||
.filter(Notification::isUnread)
|
||||
.limit(10)
|
||||
.forEach(thread -> {
|
||||
.flatMap(notification -> RestProvider.getNotificationService()
|
||||
.getComment(notification.getSubject().getLatestCommentUrl())
|
||||
.subscribeOn(Schedulers.io()), (thread, comment) -> {
|
||||
if (!InputHelper.isEmpty(thread.getSubject().getLatestCommentUrl())) {
|
||||
RestProvider.getNotificationService().getComment(thread.getSubject().getLatestCommentUrl())
|
||||
.subscribeOn(Schedulers.io())
|
||||
.subscribe(comment -> {
|
||||
android.app.Notification toAdd = getNotificationWithComment(context, largeIcon, accentColor, thread, comment);
|
||||
showNotification((int) thread.getId(), toAdd);
|
||||
}, Throwable::printStackTrace);
|
||||
} else {
|
||||
showNotificationWithoutCommnet(context, largeIcon, accentColor, thread);
|
||||
android.app.Notification toAdd = getNotificationWithComment(context, accentColor, largeIcon, thread, comment);
|
||||
showNotification((int) comment.getId(), toAdd);
|
||||
return null;
|
||||
}
|
||||
return thread;
|
||||
})
|
||||
.subscribeOn(Schedulers.io())
|
||||
.subscribe(thread -> {
|
||||
if (thread != null) {
|
||||
showNotificationWithoutComment(context, accentColor, thread, largeIcon);
|
||||
}
|
||||
}, throwable -> finishJob(job), () -> {
|
||||
Logger.e();
|
||||
android.app.Notification grouped = getSummaryGroupNotification(accentColor);
|
||||
showNotification(BundleConstant.REQUEST_CODE, grouped);
|
||||
finishJob(job);
|
||||
});
|
||||
}
|
||||
|
||||
private void showNotificationWithoutCommnet(Context context, Bitmap largeIcon, int accentColor, Notification thread) {
|
||||
android.app.Notification toAdd = getNotification(thread.getSubject().getTitle(),
|
||||
thread.getRepository().getFullName())
|
||||
private void finishJob(JobParameters job) {
|
||||
jobFinished(job, false);
|
||||
}
|
||||
|
||||
private void showNotificationWithoutComment(Context context, int accentColor, Notification thread, Bitmap largeIcon) {
|
||||
android.app.Notification toAdd = getNotification(thread.getSubject().getTitle(), thread.getRepository().getFullName())
|
||||
.setLargeIcon(largeIcon)
|
||||
.setContentIntent(getPendingIntent(thread.getId(), thread.getSubject().getUrl()))
|
||||
.setGroup(NOTIFICATION_GROUP_ID)
|
||||
.setColor(accentColor)
|
||||
.addAction(R.drawable.ic_github, context.getString(R.string.open), getPendingIntent(thread.getId(), thread
|
||||
.getSubject().getUrl()))
|
||||
.addAction(R.drawable.ic_eye_off, context.getString(R.string.mark_as_read), getReadOnlyPendingIntent(thread.getId(), thread
|
||||
.getSubject().getUrl()))
|
||||
.setWhen(thread.getUpdatedAt() != null ? thread.getUpdatedAt().getTime() : System.currentTimeMillis())
|
||||
.setShowWhen(true)
|
||||
.setColor(accentColor)
|
||||
.setGroup(NOTIFICATION_GROUP_ID)
|
||||
.build();
|
||||
showNotification((int) thread.getId(), toAdd);
|
||||
}
|
||||
|
||||
private android.app.Notification getNotificationWithComment(Context context, Bitmap largeIcon, int accentColor,
|
||||
private android.app.Notification getNotificationWithComment(Context context, int accentColor, Bitmap largeIcon,
|
||||
Notification thread, Comment comment) {
|
||||
return getNotification(thread.getSubject().getTitle(),
|
||||
thread.getRepository().getFullName())
|
||||
.setStyle(new NotificationCompat.BigTextStyle()
|
||||
.bigText(comment.getBody())
|
||||
.setBigContentTitle(comment.getUser() != null ? comment.getUser().getLogin() : ""))
|
||||
return getNotification(comment.getUser() != null ? comment.getUser().getLogin() : "", comment.getBody())
|
||||
.setSmallIcon(R.drawable.ic_notification)
|
||||
.setLargeIcon(largeIcon)
|
||||
.setContentIntent(getPendingIntent(thread.getId(), thread.getSubject().getUrl()))
|
||||
.setGroup(NOTIFICATION_GROUP_ID)
|
||||
.setColor(accentColor)
|
||||
.setStyle(new NotificationCompat.BigTextStyle()
|
||||
.setBigContentTitle(comment.getUser() != null ? comment.getUser().getLogin() : "")
|
||||
.bigText(comment.getBody()))
|
||||
.setWhen(comment.getCreatedAt().getTime())
|
||||
.setShowWhen(true)
|
||||
.addAction(R.drawable.ic_github, context.getString(R.string.open), getPendingIntent(thread.getId(),
|
||||
thread.getSubject().getUrl()))
|
||||
.addAction(R.drawable.ic_eye_off, context.getString(R.string.mark_as_read), getReadOnlyPendingIntent(thread.getId(),
|
||||
thread.getSubject().getUrl()))
|
||||
.setContentIntent(getPendingIntent(thread.getId(), thread.getSubject().getUrl()))
|
||||
.setColor(accentColor)
|
||||
.setGroup(NOTIFICATION_GROUP_ID)
|
||||
.build();
|
||||
}
|
||||
|
||||
private android.app.Notification getSummaryGroupNotification(@NonNull Notification notification, int accentColor, Bitmap largeIcon) {
|
||||
return getNotification(notification.getSubject().getTitle(), notification.getRepository().getFullName())
|
||||
.setLargeIcon(largeIcon)
|
||||
private android.app.Notification getSummaryGroupNotification(int accentColor) {
|
||||
return getNotification(getString(R.string.notifications), getString(R.string.unread_notification))
|
||||
.setSmallIcon(R.drawable.ic_notification)
|
||||
.setColor(accentColor)
|
||||
.setGroup(NOTIFICATION_GROUP_ID)
|
||||
.setGroupSummary(true)
|
||||
.setColor(accentColor)
|
||||
.setContentIntent(getPendingIntent(notification.getId(), notification.getSubject().getUrl()))
|
||||
.addAction(R.drawable.ic_github, getString(R.string.open),
|
||||
getPendingIntent(notification.getId(), notification.getSubject().getUrl()))
|
||||
.addAction(R.drawable.ic_eye_off, getString(R.string.mark_as_read), getReadOnlyPendingIntent(notification.getId(),
|
||||
notification.getSubject().getUrl()))
|
||||
.setAutoCancel(true)
|
||||
.build();
|
||||
}
|
||||
|
||||
private NotificationCompat.Builder getNotification(@NonNull String title, @NonNull String message) {
|
||||
return new NotificationCompat.Builder(this)
|
||||
.setSmallIcon(R.drawable.ic_notification)
|
||||
.setContentTitle(title)
|
||||
.setContentText(message);
|
||||
.setContentText(message)
|
||||
.setAutoCancel(true);
|
||||
}
|
||||
|
||||
private void showNotification(int id, android.app.Notification notification) {
|
||||
@ -197,13 +205,13 @@ public class NotificationSchedulerJobTask extends JobService {
|
||||
|
||||
private PendingIntent getReadOnlyPendingIntent(long id, @NonNull String url) {
|
||||
Intent intent = ReadNotificationService.start(this, id, url, true);
|
||||
return PendingIntent.getService(this, (int) (id / 2), intent,
|
||||
return PendingIntent.getService(this, InputHelper.getSafeIntId(id) / 2, intent,
|
||||
PendingIntent.FLAG_UPDATE_CURRENT);
|
||||
}
|
||||
|
||||
private PendingIntent getPendingIntent(long id, @NonNull String url) {
|
||||
Intent intent = ReadNotificationService.start(this, id, url);
|
||||
return PendingIntent.getService(this, (int) id, intent,
|
||||
return PendingIntent.getService(this, InputHelper.getSafeIntId(id), intent,
|
||||
PendingIntent.FLAG_UPDATE_CURRENT);
|
||||
}
|
||||
}
|
||||
|
||||
@ -15,6 +15,7 @@ import com.fastaccess.R;
|
||||
import com.fastaccess.helper.AppHelper;
|
||||
import com.fastaccess.helper.BundleConstant;
|
||||
import com.fastaccess.helper.Bundler;
|
||||
import com.fastaccess.helper.InputHelper;
|
||||
import com.fastaccess.helper.PrefGetter;
|
||||
import com.fastaccess.provider.rest.RestProvider;
|
||||
import com.fastaccess.provider.scheme.SchemeParser;
|
||||
@ -87,7 +88,7 @@ public class ReadNotificationService extends IntentService {
|
||||
|
||||
private void openNotification(long id, @Nullable String url, boolean readOnly) {
|
||||
if (id > 0 && url != null) {
|
||||
AppHelper.cancelNotification(this, (int) id);
|
||||
AppHelper.cancelNotification(this, InputHelper.getSafeIntId(id));
|
||||
if (!PrefGetter.isMarkAsReadEnabled() || readOnly) {
|
||||
markSingleAsRead(id);
|
||||
}
|
||||
@ -104,7 +105,7 @@ public class ReadNotificationService extends IntentService {
|
||||
private void markSingleAsRead(long id) {
|
||||
RestProvider.getNotificationService()
|
||||
.markAsRead(String.valueOf(id))
|
||||
.doOnSubscribe(() -> getNotificationManager().notify((int) id, getNotification().build()))
|
||||
.doOnSubscribe(() -> getNotificationManager().notify(InputHelper.getSafeIntId(id), getNotification().build()))
|
||||
.subscribeOn(Schedulers.io())
|
||||
.subscribe(booleanResponse -> {
|
||||
}, Throwable::printStackTrace, () -> getNotificationManager().cancel((int) id));
|
||||
|
||||
@ -19,6 +19,7 @@ import com.fastaccess.helper.InputHelper;
|
||||
import com.fastaccess.provider.rest.RestProvider;
|
||||
import com.fastaccess.ui.base.BaseActivity;
|
||||
import com.fastaccess.ui.base.mvp.presenter.BasePresenter;
|
||||
import com.fastaccess.ui.modules.gists.gist.GistView;
|
||||
import com.fastaccess.ui.modules.repos.code.files.activity.RepoFilesActivity;
|
||||
import com.fastaccess.ui.modules.repos.code.prettifier.ViewerView;
|
||||
|
||||
@ -103,7 +104,14 @@ public class CodeViewerView extends BaseActivity {
|
||||
ActivityHelper.shareUrl(this, url);
|
||||
return true;
|
||||
} else if (item.getItemId() == android.R.id.home) {
|
||||
RepoFilesActivity.startActivity(this, url);
|
||||
Uri uri = Uri.parse(url);
|
||||
if (uri.getHost().contains("gist.github")) {
|
||||
if (uri.getPathSegments() != null && !uri.getPathSegments().isEmpty() && uri.getPathSegments().size() >= 1) {
|
||||
GistView.createIntent(this, uri.getPathSegments().get(1));
|
||||
}
|
||||
} else {
|
||||
RepoFilesActivity.startActivity(this, url);
|
||||
}
|
||||
finish();
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -47,18 +47,11 @@ public class LoginView extends BaseActivity<LoginMvp.View, LoginPresenter> imple
|
||||
Toasty.info(this, getString(R.string.open_in_browser)).show();
|
||||
}
|
||||
|
||||
public void doLogin() {
|
||||
if(progress.getVisibility() == View.GONE) {
|
||||
getPresenter().login(InputHelper.toString(username),
|
||||
InputHelper.toString(password), InputHelper.toString(twoFactor));
|
||||
}
|
||||
}
|
||||
|
||||
@OnClick(R.id.login) public void onClick() {
|
||||
doLogin();
|
||||
}
|
||||
|
||||
@OnEditorAction(R.id.passwordEditText) public boolean onSendPassword(int actionId) {
|
||||
@OnEditorAction(R.id.passwordEditText) public boolean onSendPassword() {
|
||||
if (twoFactor.getVisibility() == View.VISIBLE) {
|
||||
twoFactorEditText.requestFocus();
|
||||
} else {
|
||||
@ -67,7 +60,7 @@ public class LoginView extends BaseActivity<LoginMvp.View, LoginPresenter> imple
|
||||
return true;
|
||||
}
|
||||
|
||||
@OnEditorAction(R.id.twoFactorEditText) public boolean onSend2FA(int actionId) {
|
||||
@OnEditorAction(R.id.twoFactorEditText) public boolean onSend2FA() {
|
||||
doLogin();
|
||||
return true;
|
||||
}
|
||||
@ -159,4 +152,11 @@ public class LoginView extends BaseActivity<LoginMvp.View, LoginPresenter> imple
|
||||
getPresenter().onHandleAuthIntent(getIntent());
|
||||
setIntent(null);
|
||||
}
|
||||
|
||||
private void doLogin() {
|
||||
if (progress.getVisibility() == View.GONE) {
|
||||
getPresenter().login(InputHelper.toString(username),
|
||||
InputHelper.toString(password), InputHelper.toString(twoFactor));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -205,7 +205,6 @@ public class CommitCommentsView extends BaseFragment<CommitCommentsMvp.View, Com
|
||||
|
||||
@Override public void onToggle(int position, boolean isCollapsed) {
|
||||
getSparseBooleanArray().put(position, isCollapsed);
|
||||
adapter.notifyItemChanged(position);
|
||||
}
|
||||
|
||||
@Override public boolean isCollapsed(int position) {
|
||||
|
||||
@ -34,8 +34,8 @@ public class SettingsFragment extends PreferenceFragmentCompat implements Prefer
|
||||
|
||||
@Override public boolean onPreferenceChange(Preference preference, Object newValue) {
|
||||
if (preference.getKey().equalsIgnoreCase("notificationTime")) {
|
||||
NotificationSchedulerJobTask.scheduleJob(getActivity().getApplicationContext(), PrefGetter.getNotificationTaskDuration(getActivity()
|
||||
.getApplicationContext()), true);
|
||||
NotificationSchedulerJobTask.scheduleJob(getActivity().getApplicationContext(),
|
||||
PrefGetter.getNotificationTaskDuration(getActivity().getApplicationContext()), true);
|
||||
return true;
|
||||
} else if (preference.getKey().equalsIgnoreCase("recylerViewAnimation")) {
|
||||
restartActivity();
|
||||
|
||||
@ -8,7 +8,8 @@
|
||||
android:background="@color/material_indigo_700"
|
||||
android:fitsSystemWindows="true"
|
||||
android:orientation="vertical"
|
||||
app:statusBarBackground="@color/material_indigo_900">
|
||||
app:statusBarBackground="@color/material_indigo_900"
|
||||
tools:context=".ui.modules.login.LoginView">
|
||||
|
||||
<android.support.v4.widget.NestedScrollView
|
||||
android:layout_width="match_parent"
|
||||
@ -22,7 +23,6 @@
|
||||
android:layout_margin="@dimen/spacing_s_large"
|
||||
android:minHeight="350dp"
|
||||
android:minWidth="250dp"
|
||||
app:cardBackgroundColor="?card_background"
|
||||
app:cardElevation="@dimen/spacing_normal">
|
||||
|
||||
<LinearLayout
|
||||
@ -85,9 +85,9 @@
|
||||
android:id="@+id/passwordEditText"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:imeOptions="actionSend"
|
||||
android:inputType="textPassword"
|
||||
android:maxLines="1"
|
||||
android:imeOptions="actionSend"/>
|
||||
android:maxLines="1"/>
|
||||
</android.support.design.widget.TextInputLayout>
|
||||
|
||||
<android.support.design.widget.TextInputLayout
|
||||
@ -103,9 +103,9 @@
|
||||
android:id="@+id/twoFactorEditText"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:imeOptions="actionSend"
|
||||
android:inputType="text"
|
||||
android:maxLines="1"
|
||||
android:imeOptions="actionSend"/>
|
||||
android:maxLines="1"/>
|
||||
</android.support.design.widget.TextInputLayout>
|
||||
|
||||
<FrameLayout
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user