Bug fixes

This commit is contained in:
DrKLO 2015-03-27 13:32:33 +03:00
parent 08ac6a14e7
commit 1b913b2a2f
18 changed files with 125 additions and 20 deletions

View file

@ -17,10 +17,10 @@ import android.content.Intent;
import android.content.SharedPreferences;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.content.res.AssetFileDescriptor;
import android.graphics.drawable.BitmapDrawable;
import android.media.AudioManager;
import android.media.MediaPlayer;
import android.media.SoundPool;
import android.net.Uri;
import android.os.Build;
import android.os.SystemClock;
@ -68,11 +68,10 @@ public class NotificationsController {
private int lastOnlineFromOtherDevice = 0;
private boolean inChatSoundEnabled = true;
private SoundPool soundPool;
private int inChatOutgoingSound;
private long lastSoundPlay;
private MediaPlayer mediaPlayer;
private String lastMediaPlayerUri;
private MediaPlayer mediaPlayerIn;
private MediaPlayer mediaPlayerOut;
private AudioManager audioManager;
private static volatile NotificationsController Instance = null;
public static NotificationsController getInstance() {
@ -94,9 +93,8 @@ public class NotificationsController {
inChatSoundEnabled = preferences.getBoolean("EnableInChatSound", true);
try {
soundPool = new SoundPool(1, AudioManager.STREAM_NOTIFICATION, 0);
inChatOutgoingSound = soundPool.load(ApplicationLoader.applicationContext, R.raw.sound_out, 1);
mediaPlayer = new MediaPlayer();
audioManager = (AudioManager) ApplicationLoader.applicationContext.getSystemService(Context.AUDIO_SERVICE);
//mediaPlayer = new MediaPlayer();
} catch (Exception e) {
FileLog.e("tmessages", e);
}
@ -389,6 +387,7 @@ public class NotificationsController {
inAppPriority = preferences.getBoolean("EnableInAppPriority", false);
vibrate_override = preferences.getInt("vibrate_" + dialog_id, 0);
priority_override = preferences.getInt("priority_" + dialog_id, 3);
boolean vibrateOnlyIfSilent = false;
choosenSoundPath = preferences.getString("sound_path_" + dialog_id, null);
if (chat_id != 0) {
@ -418,6 +417,10 @@ public class NotificationsController {
priority = priority_override;
}
if (needVibrate == 4) {
vibrateOnlyIfSilent = true;
needVibrate = 0;
}
if (needVibrate == 2 && (vibrate_override == 1 || vibrate_override == 3 || vibrate_override == 5) || needVibrate != 2 && vibrate_override == 2 || vibrate_override != 0) {
needVibrate = vibrate_override;
}
@ -434,6 +437,16 @@ public class NotificationsController {
priority = 1;
}
}
if (vibrateOnlyIfSilent && needVibrate != 2) {
try {
int mode = audioManager.getRingerMode();
if (mode != AudioManager.RINGER_MODE_SILENT && mode != AudioManager.RINGER_MODE_VIBRATE) {
needVibrate = 2;
}
} catch (Exception e) {
FileLog.e("tmessages", e);
}
}
}
Intent intent = new Intent(ApplicationLoader.applicationContext, LaunchActivity.class);
@ -824,13 +837,53 @@ public class NotificationsController {
if (!inChatSoundEnabled) {
return;
}
if (lastSoundPlay > System.currentTimeMillis() - 1800) {
return;
}
try {
String choosenSoundPath = null;
String defaultPath = Settings.System.DEFAULT_NOTIFICATION_URI.getPath();
if (audioManager.getRingerMode() == AudioManager.RINGER_MODE_SILENT) {
return;
}
} catch (Exception e) {
FileLog.e("tmessages", e);
}
try {
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("Notifications", Context.MODE_PRIVATE);
int notify_override = preferences.getInt("notify2_" + openned_dialog_id, 0);
if (notify_override == 3) {
int mute_until = preferences.getInt("notifyuntil_" + openned_dialog_id, 0);
if (mute_until >= ConnectionsManager.getInstance().getCurrentTime()) {
notify_override = 2;
}
}
if (notify_override == 2) {
return;
}
notificationsQueue.postRunnable(new Runnable() {
@Override
public void run() {
if (lastSoundPlay > System.currentTimeMillis() - 500) {
return;
}
try {
if (mediaPlayerIn == null) {
AssetFileDescriptor assetFileDescriptor = ApplicationLoader.applicationContext.getResources().openRawResourceFd(R.raw.sound_in);
if (assetFileDescriptor != null) {
mediaPlayerIn = new MediaPlayer();
mediaPlayerIn.setAudioStreamType(AudioManager.STREAM_NOTIFICATION);
mediaPlayerIn.setDataSource(assetFileDescriptor.getFileDescriptor(), assetFileDescriptor.getStartOffset(), assetFileDescriptor.getLength());
mediaPlayerIn.setLooping(false);
assetFileDescriptor.close();
mediaPlayerIn.prepare();
}
}
mediaPlayerIn.start();
} catch (Exception e) {
FileLog.e("tmessages", e);
}
}
});
/*String choosenSoundPath = null;
String defaultPath = Settings.System.DEFAULT_NOTIFICATION_URI.getPath();
choosenSoundPath = preferences.getString("sound_path_" + openned_dialog_id, null);
boolean isChat = (int)(openned_dialog_id) < 0;
if (isChat) {
@ -860,7 +913,7 @@ public class NotificationsController {
mediaPlayer.prepare();
}
mediaPlayer.start();
}
}*/
} catch (Exception e) {
FileLog.e("tmessages", e);
}
@ -871,10 +924,33 @@ public class NotificationsController {
return;
}
try {
soundPool.play(inChatOutgoingSound, 1, 1, 1, 0, 1);
if (audioManager.getRingerMode() == AudioManager.RINGER_MODE_SILENT) {
return;
}
} catch (Exception e) {
FileLog.e("tmessages", e);
}
notificationsQueue.postRunnable(new Runnable() {
@Override
public void run() {
try {
if (mediaPlayerOut == null) {
AssetFileDescriptor assetFileDescriptor = ApplicationLoader.applicationContext.getResources().openRawResourceFd(R.raw.sound_out);
if (assetFileDescriptor != null) {
mediaPlayerOut = new MediaPlayer();
mediaPlayerOut.setAudioStreamType(AudioManager.STREAM_NOTIFICATION);
mediaPlayerOut.setDataSource(assetFileDescriptor.getFileDescriptor(), assetFileDescriptor.getStartOffset(), assetFileDescriptor.getLength());
mediaPlayerOut.setLooping(false);
assetFileDescriptor.close();
mediaPlayerOut.prepare();
}
}
mediaPlayerOut.start();
} catch (Exception e) {
FileLog.e("tmessages", e);
}
}
});
}
public void processNewMessages(ArrayList<MessageObject> messageObjects, boolean isLast) {