Improve resident notification
This commit is contained in:
parent
2750b495d2
commit
cae1b079da
@ -298,7 +298,6 @@
|
||||
<service android:name=".voip.VoIPService" android:enabled="true"/>
|
||||
<service android:name=".GoogleVoiceClientService"/>
|
||||
<service android:name=".MusicPlayerService" android:exported="true" android:enabled="true"/>
|
||||
<service android:name="tw.nekomimi.nekogram.DuangService" android:exported="true" android:enabled="true"/>
|
||||
<service android:name=".MusicBrowserService" android:exported="true">
|
||||
<intent-filter>
|
||||
<action android:name="android.media.browse.MediaBrowserService"/>
|
||||
|
@ -21,6 +21,7 @@ import android.content.pm.ApplicationInfo;
|
||||
import android.content.res.Configuration;
|
||||
import android.net.ConnectivityManager;
|
||||
import android.net.NetworkInfo;
|
||||
import android.os.Build;
|
||||
import android.os.Handler;
|
||||
import android.os.PowerManager;
|
||||
import android.telephony.TelephonyManager;
|
||||
@ -36,6 +37,8 @@ import org.telegram.ui.Components.ForegroundDetector;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import tw.nekomimi.nekogram.NekoConfig;
|
||||
|
||||
public class ApplicationLoader extends Application {
|
||||
|
||||
@SuppressLint("StaticFieldLeak")
|
||||
@ -198,7 +201,11 @@ public class ApplicationLoader extends Application {
|
||||
}
|
||||
if (enabled) {
|
||||
try {
|
||||
applicationContext.startService(new Intent(applicationContext, NotificationsService.class));
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O && NekoConfig.residentNotification) {
|
||||
applicationContext.startForegroundService(new Intent(applicationContext, NotificationsService.class));
|
||||
} else {
|
||||
applicationContext.startService(new Intent(applicationContext, NotificationsService.class));
|
||||
}
|
||||
} catch (Throwable ignore) {
|
||||
|
||||
}
|
||||
|
@ -8,17 +8,52 @@
|
||||
|
||||
package org.telegram.messenger;
|
||||
|
||||
import android.app.Notification;
|
||||
import android.app.NotificationChannel;
|
||||
import android.app.NotificationManager;
|
||||
import android.app.PendingIntent;
|
||||
import android.app.Service;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.os.Build;
|
||||
import android.os.IBinder;
|
||||
|
||||
import androidx.core.app.NotificationCompat;
|
||||
|
||||
import org.telegram.ui.LaunchActivity;
|
||||
|
||||
import tw.nekomimi.nekogram.NekoConfig;
|
||||
|
||||
public class NotificationsService extends Service {
|
||||
|
||||
@Override
|
||||
public void onCreate() {
|
||||
super.onCreate();
|
||||
ApplicationLoader.postInitApplication();
|
||||
if (NekoConfig.residentNotification) {
|
||||
Intent activityIntent = new Intent(this, LaunchActivity.class);
|
||||
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, activityIntent, 0);
|
||||
|
||||
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.O) {
|
||||
NotificationChannel channel = new NotificationChannel("nekogram", LocaleController.getString("NekogramRunning", R.string.NekogramRunning), NotificationManager.IMPORTANCE_DEFAULT);
|
||||
channel.enableLights(false);
|
||||
channel.enableVibration(false);
|
||||
channel.setSound(null, null);
|
||||
NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
|
||||
if (notificationManager != null) {
|
||||
notificationManager.createNotificationChannel(channel);
|
||||
}
|
||||
}
|
||||
Notification notification = new NotificationCompat.Builder(this, "nekogram")
|
||||
.setSmallIcon(R.drawable.notification)
|
||||
.setColor(0xff11acfa)
|
||||
.setContentTitle(LocaleController.getString("NekogramRunning", R.string.NekogramRunning))
|
||||
.setContentIntent(pendingIntent)
|
||||
.setCategory(NotificationCompat.CATEGORY_STATUS)
|
||||
.build();
|
||||
startForeground(38264, notification);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -21,8 +21,6 @@ import android.content.res.Configuration;
|
||||
import android.database.Cursor;
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.Color;
|
||||
import android.graphics.Point;
|
||||
import android.graphics.Shader;
|
||||
import android.graphics.drawable.BitmapDrawable;
|
||||
@ -116,13 +114,10 @@ import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import androidx.recyclerview.widget.DefaultItemAnimator;
|
||||
import androidx.recyclerview.widget.ItemTouchHelper;
|
||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import tw.nekomimi.nekogram.DuangService;
|
||||
import tw.nekomimi.nekogram.NekoConfig;
|
||||
import tw.nekomimi.nekogram.NekoSettingsActivity;
|
||||
|
||||
public class LaunchActivity extends Activity implements ActionBarLayout.ActionBarLayoutDelegate, NotificationCenter.NotificationCenterDelegate, DialogsActivity.DialogsActivityDelegate {
|
||||
@ -734,10 +729,6 @@ public class LaunchActivity extends Activity implements ActionBarLayout.ActionBa
|
||||
FileLog.e(e);
|
||||
}
|
||||
MediaController.getInstance().setBaseActivity(this, true);
|
||||
if (NekoConfig.residentNotification) {
|
||||
Intent duangIntent = new Intent(ApplicationLoader.applicationContext, DuangService.class);
|
||||
ApplicationLoader.applicationContext.startService(duangIntent);
|
||||
}
|
||||
}
|
||||
|
||||
private void checkSystemBarColors() {
|
||||
|
@ -1,53 +0,0 @@
|
||||
package tw.nekomimi.nekogram;
|
||||
|
||||
import android.app.Notification;
|
||||
import android.app.NotificationChannel;
|
||||
import android.app.NotificationManager;
|
||||
import android.app.PendingIntent;
|
||||
import android.app.Service;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.os.Build;
|
||||
import android.os.IBinder;
|
||||
|
||||
import org.telegram.messenger.ApplicationLoader;
|
||||
import org.telegram.messenger.LocaleController;
|
||||
import org.telegram.messenger.R;
|
||||
import org.telegram.ui.LaunchActivity;
|
||||
|
||||
public class DuangService extends Service {
|
||||
|
||||
NotificationManager systemNotificationManager = null;
|
||||
|
||||
@Override
|
||||
public IBinder onBind(Intent intent) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int onStartCommand(Intent intent, int flags, int startId) {
|
||||
Intent activityIntent = new Intent(this, LaunchActivity.class);
|
||||
PendingIntent pendingIntent = PendingIntent.getActivity(getApplication(), 0, activityIntent, 0);
|
||||
|
||||
Notification.Builder builder;
|
||||
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.O) {
|
||||
NotificationChannel notificationChannel = new NotificationChannel("duang", "Other", NotificationManager.IMPORTANCE_DEFAULT);
|
||||
notificationChannel.enableLights(false);
|
||||
notificationChannel.enableVibration(false);
|
||||
notificationChannel.setSound(null, null);
|
||||
systemNotificationManager = (NotificationManager) ApplicationLoader.applicationContext.getSystemService(Context.NOTIFICATION_SERVICE);
|
||||
systemNotificationManager.createNotificationChannel(notificationChannel);
|
||||
builder = new Notification.Builder(getApplication(), "duang");
|
||||
} else {
|
||||
builder = new Notification.Builder(getApplication());
|
||||
|
||||
}
|
||||
Notification notification = builder.setSmallIcon(R.drawable.notification).
|
||||
setContentTitle(LocaleController.getString("NekogramRunning", R.string.NekogramRunning)).
|
||||
setContentIntent(pendingIntent).
|
||||
setWhen(System.currentTimeMillis()).
|
||||
build();
|
||||
startForeground(38264, notification);
|
||||
return super.onStartCommand(intent, flags, startId);
|
||||
}
|
||||
}
|
@ -8,26 +8,24 @@ import android.os.Build;
|
||||
|
||||
import org.telegram.messenger.ApplicationLoader;
|
||||
import org.telegram.messenger.FileLog;
|
||||
import org.telegram.messenger.NotificationsService;
|
||||
|
||||
public class NekoConfig {
|
||||
|
||||
private static final Object sync = new Object();
|
||||
public static boolean useIPv6 = false;
|
||||
public static boolean hidePhone = true;
|
||||
public static boolean showTestBackend = false;
|
||||
|
||||
public static boolean openFilterByActionBar = true;
|
||||
public static boolean openFilterByFab = false;
|
||||
|
||||
public static boolean ignoreBlocked = false;
|
||||
public static boolean forceTablet = false;
|
||||
public static int typeface = 0;
|
||||
public static int nameOrder = 1;
|
||||
public static int mapPreviewProvider = 0;
|
||||
public static boolean transparentStatusBar = false;
|
||||
public static boolean residentNotification = false;
|
||||
public static boolean hideProxySponsorChannel = false;
|
||||
public static boolean saveCacheToPrivateDirectory = Build.VERSION.SDK_INT >= 24;
|
||||
public static float stickerSize = 14.0f;
|
||||
public static boolean unlimitedFavedStickers = false;
|
||||
public static boolean disablePhotoSideAction = true;
|
||||
public static boolean unlimitedPinnedDialogs = false;
|
||||
public static boolean openArchiveOnPull = false;
|
||||
public static int mapPreviewProvider = 0;
|
||||
public static float stickerSize = 14.0f;
|
||||
public static int translationProvider = 1;
|
||||
|
||||
public static boolean showAddToSavedMessages = true;
|
||||
public static boolean showReport = false;
|
||||
@ -40,16 +38,19 @@ public class NekoConfig {
|
||||
public static boolean showTranslate = true;
|
||||
public static boolean showRepeat = true;
|
||||
|
||||
public static boolean hidePhone = true;
|
||||
public static int typeface = 0;
|
||||
public static boolean transparentStatusBar = false;
|
||||
public static boolean forceTablet = false;
|
||||
public static boolean openArchiveOnPull = false;
|
||||
public static int nameOrder = 1;
|
||||
public static int eventType = 0;
|
||||
public static int actionBarDecoration = 0;
|
||||
public static boolean newYear = false;
|
||||
public static int actionBarDecoration = 0;
|
||||
public static boolean unlimitedFavedStickers = false;
|
||||
public static boolean unlimitedPinnedDialogs = false;
|
||||
|
||||
public static int translationProvider = 1;
|
||||
|
||||
public static boolean openFilterByActionBar = true;
|
||||
public static boolean openFilterByFab = false;
|
||||
|
||||
public static boolean showTestBackend = false;
|
||||
public static boolean residentNotification = false;
|
||||
|
||||
private static boolean configLoaded;
|
||||
|
||||
@ -67,9 +68,6 @@ public class NekoConfig {
|
||||
editor.putBoolean("hidePhone", hidePhone);
|
||||
editor.putBoolean("ignoreBlocked", ignoreBlocked);
|
||||
editor.putBoolean("forceTablet", forceTablet);
|
||||
editor.putInt("typeface", typeface);
|
||||
editor.putInt("nameOrder", nameOrder);
|
||||
editor.putInt("mapPreviewProvider", mapPreviewProvider);
|
||||
editor.putBoolean("transparentStatusBar", transparentStatusBar);
|
||||
editor.putBoolean("residentNotification", residentNotification);
|
||||
editor.putBoolean("hideProxySponsorChannel", hideProxySponsorChannel);
|
||||
@ -85,7 +83,6 @@ public class NekoConfig {
|
||||
editor.putBoolean("showTranslate", showTranslate);
|
||||
editor.putBoolean("showRepeat", showRepeat);
|
||||
editor.putBoolean("newYear", newYear);
|
||||
editor.putFloat("stickerSize", stickerSize);
|
||||
editor.putBoolean("unlimitedFavedStickers", unlimitedFavedStickers);
|
||||
editor.putBoolean("unlimitedPinnedDialogs", unlimitedPinnedDialogs);
|
||||
editor.putBoolean("disablePhotoSideAction", disablePhotoSideAction);
|
||||
@ -93,6 +90,10 @@ public class NekoConfig {
|
||||
editor.putBoolean("openFilterByActionBar", openFilterByActionBar);
|
||||
editor.putBoolean("openFilterByFab", openFilterByFab);
|
||||
editor.putBoolean("showTestBackend", showTestBackend);
|
||||
editor.putFloat("stickerSize", stickerSize);
|
||||
editor.putInt("typeface", typeface);
|
||||
editor.putInt("nameOrder", nameOrder);
|
||||
editor.putInt("mapPreviewProvider", mapPreviewProvider);
|
||||
editor.putInt("translationProvider", translationProvider);
|
||||
editor.putInt("eventType", eventType);
|
||||
editor.putInt("actionBarDecoration", actionBarDecoration);
|
||||
@ -290,12 +291,8 @@ public class NekoConfig {
|
||||
SharedPreferences.Editor editor = preferences.edit();
|
||||
editor.putBoolean("residentNotification", residentNotification);
|
||||
editor.commit();
|
||||
Intent duangIntent = new Intent(ApplicationLoader.applicationContext, DuangService.class);
|
||||
if (residentNotification) {
|
||||
ApplicationLoader.applicationContext.startService(duangIntent);
|
||||
} else {
|
||||
ApplicationLoader.applicationContext.stopService(duangIntent);
|
||||
}
|
||||
ApplicationLoader.applicationContext.stopService(new Intent(ApplicationLoader.applicationContext, NotificationsService.class));
|
||||
ApplicationLoader.startPushService();
|
||||
}
|
||||
|
||||
public static void toggleHideProxySponsorChannel() {
|
||||
|
Loading…
Reference in New Issue
Block a user