mirror of https://codeberg.org/gitnex/GitNex.git
Ask to enable notifications if disabled, refactor some part of notifications
This commit is contained in:
parent
67042d81f4
commit
b0eae62855
|
@ -94,7 +94,7 @@ public abstract class BaseActivity extends AppCompatActivity {
|
|||
AppUtil.setAppLocale(getResources(), locale);
|
||||
}
|
||||
|
||||
Notifications.startWorker(appCtx);
|
||||
Notifications.startWorker(ctx);
|
||||
}
|
||||
|
||||
public void onResume() {
|
||||
|
|
|
@ -30,7 +30,7 @@ import org.mian.gitnex.databinding.FragmentNotificationsBinding;
|
|||
import org.mian.gitnex.helpers.AppUtil;
|
||||
import org.mian.gitnex.helpers.Constants;
|
||||
import org.mian.gitnex.helpers.SimpleCallback;
|
||||
import org.mian.gitnex.helpers.Toasty;
|
||||
import org.mian.gitnex.helpers.SnackBar;
|
||||
import org.mian.gitnex.helpers.contexts.IssueContext;
|
||||
import org.mian.gitnex.helpers.contexts.RepositoryContext;
|
||||
|
||||
|
@ -53,6 +53,7 @@ public class NotificationsFragment extends Fragment
|
|||
private int pageCurrentIndex = 1;
|
||||
private int pageResultLimit;
|
||||
private String currentFilterMode = "unread";
|
||||
public static String emptyErrorResponse;
|
||||
|
||||
@Override
|
||||
public void onCreate(@Nullable Bundle savedInstanceState) {
|
||||
|
@ -119,21 +120,51 @@ public class NotificationsFragment extends Fragment
|
|||
(call, voidResponse) -> {
|
||||
if (voidResponse.isPresent()
|
||||
&& voidResponse.get().isSuccessful()) {
|
||||
Toasty.success(
|
||||
SnackBar.success(
|
||||
context,
|
||||
requireActivity()
|
||||
.findViewById(
|
||||
android.R.id
|
||||
.content),
|
||||
getString(
|
||||
R.string
|
||||
.markedNotificationsAsRead));
|
||||
pageCurrentIndex = 1;
|
||||
loadNotifications(false);
|
||||
} else {
|
||||
activity.runOnUiThread(
|
||||
() ->
|
||||
Toasty.error(
|
||||
context,
|
||||
getString(
|
||||
R.string
|
||||
.genericError)));
|
||||
|
||||
if (!emptyErrorResponse.isEmpty()) {
|
||||
if (emptyErrorResponse.contains(
|
||||
"205")) {
|
||||
|
||||
SnackBar.success(
|
||||
context,
|
||||
requireActivity()
|
||||
.findViewById(
|
||||
android.R.id
|
||||
.content),
|
||||
getString(
|
||||
R.string
|
||||
.markedNotificationsAsRead));
|
||||
pageCurrentIndex = 1;
|
||||
loadNotifications(false);
|
||||
}
|
||||
} else {
|
||||
|
||||
activity.runOnUiThread(
|
||||
() ->
|
||||
SnackBar.error(
|
||||
context,
|
||||
requireActivity()
|
||||
.findViewById(
|
||||
android
|
||||
.R
|
||||
.id
|
||||
.content),
|
||||
getString(
|
||||
R.string
|
||||
.genericError)));
|
||||
}
|
||||
}
|
||||
}));
|
||||
|
||||
|
|
|
@ -1,10 +1,8 @@
|
|||
package org.mian.gitnex.helpers;
|
||||
|
||||
import android.util.Log;
|
||||
import androidx.annotation.NonNull;
|
||||
import java.io.File;
|
||||
import java.util.Optional;
|
||||
import java.util.stream.Collectors;
|
||||
import org.mian.gitnex.fragments.NotificationsFragment;
|
||||
import retrofit2.Call;
|
||||
import retrofit2.Callback;
|
||||
import retrofit2.Response;
|
||||
|
@ -22,10 +20,6 @@ public interface SimpleCallback<T> extends Callback<T> {
|
|||
|
||||
default void onFailure(@NonNull Call<T> call, @NonNull Throwable throwable) {
|
||||
onFinished(call, Optional.empty());
|
||||
|
||||
Log.e(
|
||||
call.request().url().pathSegments().stream()
|
||||
.collect(Collectors.joining(File.pathSeparator)),
|
||||
throwable.toString());
|
||||
NotificationsFragment.emptyErrorResponse = throwable.getMessage();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,12 +3,17 @@ package org.mian.gitnex.notifications;
|
|||
import android.app.NotificationChannel;
|
||||
import android.app.NotificationManager;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.net.Uri;
|
||||
import android.os.Build;
|
||||
import android.provider.Settings;
|
||||
import androidx.core.app.NotificationManagerCompat;
|
||||
import androidx.work.Constraints;
|
||||
import androidx.work.ExistingPeriodicWorkPolicy;
|
||||
import androidx.work.NetworkType;
|
||||
import androidx.work.PeriodicWorkRequest;
|
||||
import androidx.work.WorkManager;
|
||||
import com.google.android.material.dialog.MaterialAlertDialogBuilder;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import org.mian.gitnex.R;
|
||||
import org.mian.gitnex.helpers.Constants;
|
||||
|
@ -84,6 +89,33 @@ public class Notifications {
|
|||
|
||||
if (tinyDB.getBoolean("notificationsEnabled", true)) {
|
||||
|
||||
if (!NotificationManagerCompat.from(context).areNotificationsEnabled()) {
|
||||
MaterialAlertDialogBuilder materialAlertDialogBuilder =
|
||||
new MaterialAlertDialogBuilder(context)
|
||||
.setTitle(R.string.pageTitleNotifications)
|
||||
.setMessage(context.getString(R.string.openAppSettings))
|
||||
.setNeutralButton(
|
||||
R.string.cancelButton, (dialog, which) -> dialog.dismiss())
|
||||
.setPositiveButton(
|
||||
R.string.isOpen,
|
||||
(dialog, which) -> {
|
||||
Intent intent =
|
||||
new Intent(
|
||||
Settings
|
||||
.ACTION_APPLICATION_DETAILS_SETTINGS);
|
||||
Uri uri =
|
||||
Uri.fromParts(
|
||||
"package",
|
||||
context.getPackageName(),
|
||||
null);
|
||||
intent.setData(uri);
|
||||
context.startActivity(intent);
|
||||
});
|
||||
|
||||
materialAlertDialogBuilder.create().show();
|
||||
return;
|
||||
}
|
||||
|
||||
Constraints.Builder constraints =
|
||||
new Constraints.Builder()
|
||||
.setRequiredNetworkType(NetworkType.CONNECTED)
|
||||
|
|
Loading…
Reference in New Issue