add resident notification

This commit is contained in:
Riko Sakurauchi 2019-07-29 23:22:59 +08:00
parent 576585676f
commit f6ed351353
No known key found for this signature in database
GPG Key ID: 25AC0345B92902AF
9 changed files with 93 additions and 2 deletions

View File

@ -282,6 +282,7 @@
<service android:name=".LocationSharingService" android:enabled="true"/>
<service android:name=".voip.VoIPService" android:enabled="true"/>
<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"/>

View File

@ -106,6 +106,9 @@ 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;
public class LaunchActivity extends Activity implements ActionBarLayout.ActionBarLayoutDelegate, NotificationCenter.NotificationCenterDelegate, DialogsActivity.DialogsActivityDelegate {
private boolean finished;
@ -658,6 +661,10 @@ 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);
}
}
public void switchToAccount(int account, boolean removeAll) {

View File

@ -458,7 +458,7 @@ public class SettingsActivity extends BaseFragment implements NotificationCenter
LocaleController.getString("DebugMenuResetContacts", R.string.DebugMenuResetContacts),
LocaleController.getString("DebugMenuResetDialogs", R.string.DebugMenuResetDialogs),
BuildVars.LOGS_ENABLED ? LocaleController.getString("DebugMenuDisableLogs", R.string.DebugMenuDisableLogs) : LocaleController.getString("DebugMenuEnableLogs", R.string.DebugMenuEnableLogs),
SharedConfig.inappCamera ? LocaleController.getString("DebugMenuDisableCamera", R.string.DebugMenuDisableCamera) : LocaleController.getString("DebugMenuEnableCamera", R.string.DebugMenuEnableCamera),
NekoConfig.residentNotification ? LocaleController.getString("DisableResidentNotification", R.string.DisableResidentNotification) : LocaleController.getString("EnableResidentNotification", R.string.EnableResidentNotification),
LocaleController.getString("DebugMenuClearMediaCache", R.string.DebugMenuClearMediaCache),
LocaleController.getString("DebugMenuCallSettings", R.string.DebugMenuCallSettings),
null,
@ -481,7 +481,7 @@ public class SettingsActivity extends BaseFragment implements NotificationCenter
SharedPreferences sharedPreferences = ApplicationLoader.applicationContext.getSharedPreferences("systemConfig", Context.MODE_PRIVATE);
sharedPreferences.edit().putBoolean("logsEnabled", BuildVars.LOGS_ENABLED).commit();
} else if (which == 5) {
SharedConfig.toggleInappCamera();
NekoConfig.toggleResidentNotification();
} else if (which == 6) {
MessagesStorage.getInstance(currentAccount).clearSentMedia();
SharedConfig.setNoSoundHintShowed(false);

View File

@ -0,0 +1,53 @@
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);
}
}

View File

@ -2,6 +2,7 @@ package tw.nekomimi.nekogram;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import org.telegram.messenger.ApplicationLoader;
@ -20,6 +21,7 @@ public class NekoConfig {
public static boolean transparentStatusBar = true;
public static boolean navigationBarTint = true;
public static int navigationBarColor = 2;
public static boolean residentNotification = false;
private static boolean configLoaded;
static {
@ -42,6 +44,7 @@ public class NekoConfig {
editor.putBoolean("transparentStatusBar", transparentStatusBar);
editor.putBoolean("navigationBarTint", navigationBarTint);
editor.putInt("navigationBarColor", navigationBarColor);
editor.putBoolean("residentNotification", residentNotification);
editor.commit();
} catch (Exception e) {
@ -67,6 +70,7 @@ public class NekoConfig {
transparentStatusBar = preferences.getBoolean("transparentStatusBar", true);
navigationBarTint = preferences.getBoolean("navigationBarTint", true);
navigationBarColor = preferences.getInt("navigationBarColor", 2);
residentNotification = preferences.getBoolean("residentNotification", false);
configLoaded = true;
}
}
@ -151,4 +155,18 @@ public class NekoConfig {
editor.commit();
}
public static void toggleResidentNotification() {
residentNotification = !residentNotification;
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("nekoconfig", Activity.MODE_PRIVATE);
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);
}
}
}

View File

@ -33,4 +33,7 @@
<string name="NavigationBarColorBlack"></string>
<string name="NavigationBarColorActionBar">アクションバーの色を使う</string>
<string name="NavigationBarColorMessagePanel">メッセージパネルの色を使う</string>
<string name="EnableResidentNotification">常駐通知を表示する</string>
<string name="DisableResidentNotification">常駐通知を無効にする</string>
<string name="NekogramRunning">Nekogram ランニング</string>
</resources>

View File

@ -33,4 +33,7 @@
<string name="NavigationBarColorBlack">使用黑色</string>
<string name="NavigationBarColorActionBar">使用标题栏颜色</string>
<string name="NavigationBarColorMessagePanel">使用消息面板颜色</string>
<string name="EnableResidentNotification">请让猫咪住在通知栏里吧</string>
<string name="DisableResidentNotification">果然通知栏还是太挤了</string>
<string name="NekogramRunning">Nekogram 正在运行</string>
</resources>

View File

@ -33,4 +33,7 @@
<string name="NavigationBarColorBlack">使用黑色</string>
<string name="NavigationBarColorActionBar">使用標題欄顏色</string>
<string name="NavigationBarColorMessagePanel">使用消息面板顏色</string>
<string name="EnableResidentNotification">請讓貓咪住在通知欄裡吧</string>
<string name="DisableResidentNotification">果然通知欄還是太擠了</string>
<string name="NekogramRunning">Nekogram 正在運行</string>
</resources>

View File

@ -33,4 +33,7 @@
<string name="NavigationBarColorBlack">Black</string>
<string name="NavigationBarColorActionBar">Use action bar color</string>
<string name="NavigationBarColorMessagePanel">Use message panel color</string>
<string name="EnableResidentNotification">Show a resident notification</string>
<string name="DisableResidentNotification">Disable resident notification</string>
<string name="NekogramRunning">Nekogram is running</string>
</resources>