From db36341251fc2259041068886fc20a12e93f1024 Mon Sep 17 00:00:00 2001 From: "B. Petersen" Date: Fri, 24 Mar 2017 15:43:28 +0100 Subject: [PATCH] Cleanup. --- MessengerProj/build.gradle | 4 +- .../com/b44t/messenger/AndroidUtilities.java | 2 +- .../com/b44t/messenger/ApplicationLoader.java | 57 +++++-- .../b44t/messenger/ConnectionsManager.java | 142 ----------------- .../com/b44t/messenger/FileLoadOperation.java | 91 +---------- .../java/com/b44t/messenger/ImageLoader.java | 2 +- .../com/b44t/messenger/MediaController.java | 50 +----- .../com/b44t/messenger/MessageObject.java | 4 +- .../b44t/messenger/MessagesController.java | 147 ------------------ .../java/com/b44t/messenger/MrMailbox.java | 52 ++++++- .../messenger/NotificationsController.java | 39 +---- .../b44t/messenger/SendMessagesHelper.java | 20 +-- .../java/com/b44t/messenger/UserConfig.java | 136 +--------------- .../com/b44t/ui/ActionBar/BaseFragment.java | 7 +- .../b44t/ui/Adapters/DrawerLayoutAdapter.java | 3 +- .../java/com/b44t/ui/AudioSelectActivity.java | 3 +- .../com/b44t/ui/BlockedUsersActivity.java | 10 +- .../com/b44t/ui/Cells/ChatActionCell.java | 3 +- .../com/b44t/ui/Cells/ChatMessageCell.java | 7 +- .../com/b44t/ui/Cells/ChatUnreadCell.java | 4 +- .../java/com/b44t/ui/Cells/DialogCell.java | 13 +- .../main/java/com/b44t/ui/Cells/UserCell.java | 54 +------ .../main/java/com/b44t/ui/ChatActivity.java | 24 ++- .../com/b44t/ui/Components/AvatarUpdater.java | 2 +- .../ui/Components/ChatActivityEnterView.java | 11 +- .../com/b44t/ui/Components/PasscodeView.java | 2 +- .../com/b44t/ui/Components/StickersAlert.java | 2 - .../java/com/b44t/ui/ContactAddActivity.java | 15 +- .../java/com/b44t/ui/ContactsActivity.java | 9 +- .../java/com/b44t/ui/DialogsActivity.java | 17 +- .../com/b44t/ui/GroupCreateFinalActivity.java | 13 +- .../main/java/com/b44t/ui/LaunchActivity.java | 28 +--- .../java/com/b44t/ui/ManageSpaceActivity.java | 16 -- .../ui/NotificationsSettingsActivity.java | 14 -- .../java/com/b44t/ui/PasscodeActivity.java | 8 +- .../main/java/com/b44t/ui/PhotoViewer.java | 13 +- .../java/com/b44t/ui/ProfileActivity.java | 21 ++- .../b44t/ui/ProfileNotificationsActivity.java | 6 +- .../java/com/b44t/ui/SettingsAdvActivity.java | 5 +- 39 files changed, 207 insertions(+), 849 deletions(-) delete mode 100644 MessengerProj/src/main/java/com/b44t/messenger/ConnectionsManager.java delete mode 100644 MessengerProj/src/main/java/com/b44t/messenger/MessagesController.java diff --git a/MessengerProj/build.gradle b/MessengerProj/build.gradle index 22936df99..579654c4d 100644 --- a/MessengerProj/build.gradle +++ b/MessengerProj/build.gradle @@ -115,8 +115,8 @@ android { } defaultConfig { - minSdkVersion 14 // 14: Android 4.0 Ice Cream Sandwich 2011 (Telegram default), 21: Android 5.0 Lollipop 2014 (recommended for InstantRun) - targetSdkVersion 25 + minSdkVersion 14 // 14: Android 4.0 Ice Cream Sandwich 2011 (Telegram default), 21: Android 5.0 Lollipop 2014 (recommended for InstantRun) + targetSdkVersion 25 // 25: Nougat. CAVE: Do NOT target "Andoid O" without checking the background tasks carefully, see https://developer.android.com/preview/behavior-changes.html#back-all . As long as we target "Nougat", everything works as expected even for "Andoid O" or later versionName "0.1.23" // do NOT forget to increase defaultConfig.versionCode! } } diff --git a/MessengerProj/src/main/java/com/b44t/messenger/AndroidUtilities.java b/MessengerProj/src/main/java/com/b44t/messenger/AndroidUtilities.java index ff5bf3b8c..c77d8a598 100644 --- a/MessengerProj/src/main/java/com/b44t/messenger/AndroidUtilities.java +++ b/MessengerProj/src/main/java/com/b44t/messenger/AndroidUtilities.java @@ -593,7 +593,7 @@ public class AndroidUtilities { ForegroundDetector.getInstance().resetBackgroundVar(); } return UserConfig.passcodeHash.length() > 0 && wasInBackground && - (UserConfig.appLocked || UserConfig.autoLockIn != 0 && UserConfig.lastPauseTime != 0 && !UserConfig.appLocked && (UserConfig.lastPauseTime + UserConfig.autoLockIn) <= ConnectionsManager.getInstance().getCurrentTime()); + (UserConfig.appLocked || UserConfig.autoLockIn != 0 && UserConfig.lastPauseTime != 0 && !UserConfig.appLocked && (UserConfig.lastPauseTime + UserConfig.autoLockIn) <= MrMailbox.getCurrentTime()); } public static void shakeView(final View view, final float x, final int num) { diff --git a/MessengerProj/src/main/java/com/b44t/messenger/ApplicationLoader.java b/MessengerProj/src/main/java/com/b44t/messenger/ApplicationLoader.java index a4c01e221..bfbba2580 100644 --- a/MessengerProj/src/main/java/com/b44t/messenger/ApplicationLoader.java +++ b/MessengerProj/src/main/java/com/b44t/messenger/ApplicationLoader.java @@ -36,11 +36,14 @@ import android.content.pm.ApplicationInfo; import android.content.res.Configuration; import android.graphics.drawable.ColorDrawable; import android.graphics.drawable.Drawable; +import android.net.ConnectivityManager; +import android.net.NetworkInfo; import android.os.Handler; import android.os.PowerManager; import android.util.Log; import com.b44t.ui.Components.ForegroundDetector; +import com.b44t.ui.SettingsAdvActivity; import java.io.File; @@ -67,6 +70,10 @@ public class ApplicationLoader extends Application { return selectedColor; } + private static PowerManager.WakeLock wakeLock = null; + + public static int fontSize; + public static void reloadWallpaper() { cachedWallpaper = null; loadWallpaper(); @@ -174,13 +181,24 @@ public class ApplicationLoader extends Application { } UserConfig.loadConfig(); + SharedPreferences notificationPreferences = ApplicationLoader.applicationContext.getSharedPreferences("Notifications", Activity.MODE_PRIVATE); - SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("Notifications", Activity.MODE_PRIVATE); - //boolean enablePushConnection = preferences.getBoolean("pushConnection", true); + // create and acquire wakeLock + try { + PowerManager pm = (PowerManager) ApplicationLoader.applicationContext.getSystemService(Context.POWER_SERVICE); + wakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "lock"); + wakeLock.setReferenceCounted(false); + if (notificationPreferences.getBoolean("pushService", true)) { + wakeLock.acquire(); + } - if( preferences.getInt("notify2_"+MrChat.MR_CHAT_ID_DEADDROP, 666)==666 ) { - // make sure, the notifications for the "deaddrop" dialog are muted by default - SharedPreferences.Editor editor = preferences.edit(); + } catch (Exception e) { + Log.e("DeltaChat", "Cannot acquire wakeLock"); + } + + // make sure, the notifications for the "deaddrop" dialog are muted by default + if( notificationPreferences.getInt("notify2_"+MrChat.MR_CHAT_ID_DEADDROP, 666)==666 ) { + SharedPreferences.Editor editor = notificationPreferences.edit(); editor.putInt("notify2_"+MrChat.MR_CHAT_ID_DEADDROP, 2); editor.apply(); } @@ -192,11 +210,10 @@ public class ApplicationLoader extends Application { MrMailbox.connect(); // create other default objects - MessagesController.getInstance(); - ConnectionsManager.getInstance().init(); - if (UserConfig.getCurrentUser() != null) { - SendMessagesHelper.getInstance().checkUnsentMessages(); - } + SharedPreferences mainPreferences = ApplicationLoader.applicationContext.getSharedPreferences("mainconfig", Activity.MODE_PRIVATE); + fontSize = mainPreferences.getInt("msg_font_size", SettingsAdvActivity.defMsgFontSize()); + + ImageLoader.getInstance(); MediaController.getInstance(); } @@ -206,7 +223,6 @@ public class ApplicationLoader extends Application { applicationContext = getApplicationContext(); NativeLoader.initNativeLibs(ApplicationLoader.applicationContext); - //ConnectionsManager.native_setJava(Build.VERSION.SDK_INT == 14 || Build.VERSION.SDK_INT == 15); new ForegroundDetector(this); // EDIT BY MR - create a MrMailbox object; as android stops the App by just killing it, we do never call MrMailboxUnref() @@ -256,4 +272,23 @@ public class ApplicationLoader extends Application { e.printStackTrace(); } } + + private static int lastClassGuid = 1; + public static int generateClassGuid() { + return lastClassGuid++; + } + + public static boolean isNetworkOnline() { + try { + ConnectivityManager cm = (ConnectivityManager) ApplicationLoader.applicationContext.getSystemService(Context.CONNECTIVITY_SERVICE); + NetworkInfo netInfo = cm.getActiveNetworkInfo(); + if (netInfo != null && netInfo.isConnected()) { + return true; + } + + } catch (Exception e) { + } + return false; + } + } diff --git a/MessengerProj/src/main/java/com/b44t/messenger/ConnectionsManager.java b/MessengerProj/src/main/java/com/b44t/messenger/ConnectionsManager.java deleted file mode 100644 index ba7039224..000000000 --- a/MessengerProj/src/main/java/com/b44t/messenger/ConnectionsManager.java +++ /dev/null @@ -1,142 +0,0 @@ -package com.b44t.messenger; - -import android.app.Activity; -import android.content.BroadcastReceiver; -import android.content.Context; -import android.content.Intent; -import android.content.IntentFilter; -import android.content.SharedPreferences; -import android.net.ConnectivityManager; -import android.net.NetworkInfo; -import android.os.PowerManager; -import android.util.Log; - -public class ConnectionsManager { - - public final static int RequestFlagFailOnServerErrors = 2; - - public final static int ConnectionStateConnecting = 1; - public final static int ConnectionStateWaitingForNetwork = 2; - public final static int ConnectionStateConnected = 3; - public final static int ConnectionStateUpdating = 4; - - private int lastClassGuid = 1; - private PowerManager.WakeLock wakeLock = null; - - private static volatile ConnectionsManager Instance = null; - - public static ConnectionsManager getInstance() { - ConnectionsManager localInstance = Instance; - if (localInstance == null) { - synchronized (ConnectionsManager.class) { - localInstance = Instance; - if (localInstance == null) { - Instance = localInstance = new ConnectionsManager(); - } - } - } - return localInstance; - } - - public ConnectionsManager() { - try { - PowerManager pm = (PowerManager) ApplicationLoader.applicationContext.getSystemService(Context.POWER_SERVICE); - wakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "lock"); - wakeLock.setReferenceCounted(false); - - SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("Notifications", Activity.MODE_PRIVATE); - if (preferences.getBoolean("pushService", true)) { - Log.i("DeltaChat", "*** Acquire wakeLock"); - wakeLock.acquire(); - } - - } catch (Exception e) { - FileLog.e("messenger", e); - } - } - - public int getCurrentTime() { - return MrMailbox.getCurrentTime(); - } - - public int getConnectionState() { - return ConnectionStateWaitingForNetwork; // EDIT BY MR - we're always disconnected from the view of the caller - /* EDIT BY MR - if (connectionState == ConnectionStateConnected && isUpdating) { - return ConnectionStateUpdating; - } - return connectionState; - */ - } - - public void init() { - //native_init(version, layer, apiId, deviceModel, systemVersion, appVersion, langCode, configPath, logPath, userId, enablePushConnection); - //checkConnection(); - BroadcastReceiver networkStateReceiver = new BroadcastReceiver() { - @Override - public void onReceive(Context context, Intent intent) { - //checkConnection(); - } - }; - IntentFilter filter = new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION); - ApplicationLoader.applicationContext.registerReceiver(networkStateReceiver, filter); - } - - public void resumeNetworkMaybe() { - //native_resumeNetwork(true); - } - - public int generateClassGuid() { - return lastClassGuid++; - } - - /* -- leave this for future use - public static boolean isRoaming() { - try { - ConnectivityManager cm = (ConnectivityManager) ApplicationLoader.applicationContext.getSystemService(Context.CONNECTIVITY_SERVICE); - NetworkInfo netInfo = cm.getActiveNetworkInfo(); - if (netInfo != null) { - return netInfo.isRoaming(); - } - } catch (Exception e) { - FileLog.e("messenger", e); - } - return false; - } */ - - /* -- leave this for future use - public static boolean isConnectedToWiFi() { - try { - ConnectivityManager cm = (ConnectivityManager) ApplicationLoader.applicationContext.getSystemService(Context.CONNECTIVITY_SERVICE); - NetworkInfo netInfo = cm.getNetworkInfo(ConnectivityManager.TYPE_WIFI); - if (netInfo != null && netInfo.getState() == NetworkInfo.State.CONNECTED) { - return true; - } - } catch (Exception e) { - FileLog.e("messenger", e); - } - return false; - } */ - - public static boolean isNetworkOnline() { - try { - ConnectivityManager cm = (ConnectivityManager) ApplicationLoader.applicationContext.getSystemService(Context.CONNECTIVITY_SERVICE); - NetworkInfo netInfo = cm.getActiveNetworkInfo(); - if (netInfo != null && netInfo.isConnected()) { - return true; - } - /* netInfo = cm.getNetworkInfo(ConnectivityManager.TYPE_MOBILE); - - if (netInfo != null && netInfo.isConnectedOrConnecting()) { - return true; - } else { - netInfo = cm.getNetworkInfo(ConnectivityManager.TYPE_WIFI); - if (netInfo != null && netInfo.isConnectedOrConnecting()) { - return true; - } - } */ - } catch (Exception e) { - } - return false; - } -} diff --git a/MessengerProj/src/main/java/com/b44t/messenger/FileLoadOperation.java b/MessengerProj/src/main/java/com/b44t/messenger/FileLoadOperation.java index 9d1d2b57a..b646c5441 100644 --- a/MessengerProj/src/main/java/com/b44t/messenger/FileLoadOperation.java +++ b/MessengerProj/src/main/java/com/b44t/messenger/FileLoadOperation.java @@ -30,8 +30,7 @@ import java.util.ArrayList; public class FileLoadOperation { private static class RequestInfo { - private int requestToken; - private int offset; + private int dummy; } private final static int stateIdle = 0; @@ -52,11 +51,8 @@ public class FileLoadOperation { private int totalBytesCount; private int bytesCountPadding; private FileLoadOperationDelegate delegate; - private byte[] key; - private byte[] iv; private int currentDownloadChunkSize; private int currentMaxDownloadRequests; - private int requestsCount; private int renameRetryCount; private int nextDownloadOffset; @@ -65,7 +61,6 @@ public class FileLoadOperation { private File cacheFileTemp; private File cacheFileFinal; - private File cacheIvTemp; private String ext; private RandomAccessFile fileOutputStream; @@ -81,17 +76,7 @@ public class FileLoadOperation { } public FileLoadOperation(TLRPC.FileLocation photoLocation, String extension, int size) { - /*if (photoLocation instanceof TLRPC.TL_fileEncryptedLocation) { - location = new TLRPC.TL_inputEncryptedFileLocation(); - location.id = photoLocation.volume_id; - location.volume_id = photoLocation.volume_id; - location.access_hash = photoLocation.secret; - location.local_id = photoLocation.local_id; - iv = new byte[32]; - System.arraycopy(photoLocation.iv, 0, iv, 0, iv.length); - key = photoLocation.key; - datacenter_id = photoLocation.dc_id; - } else*/ if (photoLocation instanceof TLRPC.TL_fileLocation) { + if (photoLocation instanceof TLRPC.TL_fileLocation) { location = new TLRPC.TL_inputFileLocation(); location.volume_id = photoLocation.volume_id; location.local_id = photoLocation.local_id; @@ -103,28 +88,13 @@ public class FileLoadOperation { public FileLoadOperation(TLRPC.Document documentLocation) { try { - /*if (documentLocation instanceof TLRPC.TL_documentEncrypted) { - location = new TLRPC.TL_inputEncryptedFileLocation(); - location.id = documentLocation.id; - location.access_hash = documentLocation.access_hash; - datacenter_id = documentLocation.dc_id; - iv = new byte[32]; - System.arraycopy(documentLocation.iv, 0, iv, 0, iv.length); - key = documentLocation.key; - } else*/ if (documentLocation instanceof TLRPC.TL_document) { + if (documentLocation instanceof TLRPC.TL_document) { location = new TLRPC.TL_inputDocumentFileLocation(); location.id = documentLocation.id; location.access_hash = documentLocation.access_hash; datacenter_id = documentLocation.dc_id; } totalBytesCount = documentLocation.size; - if (key != null) { - int toAdd = 0; - if (totalBytesCount % 16 != 0) { - bytesCountPadding = 16 - totalBytesCount % 16; - totalBytesCount += bytesCountPadding; - } - } ext = FileLoader.getDocumentFileName(documentLocation); int idx; if (ext == null || (idx = ext.lastIndexOf('.')) == -1) { @@ -196,13 +166,9 @@ public class FileLoadOperation { } String fileNameFinal; String fileNameTemp; - String fileNameIv = null; if (location.volume_id != 0 && location.local_id != 0) { fileNameTemp = location.volume_id + "_" + location.local_id + ".temp"; fileNameFinal = location.volume_id + "_" + location.local_id + "." + ext; - if (key != null) { - fileNameIv = location.volume_id + "_" + location.local_id + ".iv"; - } if (datacenter_id == Integer.MIN_VALUE || location.volume_id == Integer.MIN_VALUE || datacenter_id == 0) { cleanup(); Utilities.stageQueue.postRunnable(new Runnable() { @@ -216,9 +182,6 @@ public class FileLoadOperation { } else { fileNameTemp = datacenter_id + "_" + location.id + ".temp"; fileNameFinal = datacenter_id + "_" + location.id + ext; - if (key != null) { - fileNameIv = datacenter_id + "_" + location.id + ".iv"; - } if (datacenter_id == 0 || location.id == 0) { cleanup(); Utilities.stageQueue.postRunnable(new Runnable() { @@ -248,21 +211,6 @@ public class FileLoadOperation { FileLog.d("messenger", "start loading file to temp = " + cacheFileTemp + " final = " + cacheFileFinal); } - if (fileNameIv != null) { - cacheIvTemp = new File(tempPath, fileNameIv); - try { - fiv = new RandomAccessFile(cacheIvTemp, "rws"); - long len = cacheIvTemp.length(); - if (len > 0 && len % 32 == 0) { - fiv.read(iv, 0, 32); - } else { - downloadedBytes = 0; - } - } catch (Exception e) { - FileLog.e("messenger", e); - downloadedBytes = 0; - } - } try { fileOutputStream = new RandomAccessFile(cacheFileTemp, "rws"); if (downloadedBytes != 0) { @@ -313,14 +261,6 @@ public class FileLoadOperation { } state = stateFailed; cleanup(); - /*if (requestInfos != null) { - for (int a = 0; a < requestInfos.size(); a++) { - RequestInfo requestInfo = requestInfos.get(a); - if (requestInfo.requestToken != 0) { - ConnectionsManager.getInstance().cancelRequest(requestInfo.requestToken, true); - } - } - }*/ delegate.didFailedLoadingFile(FileLoadOperation.this, 1); } }); @@ -350,13 +290,6 @@ public class FileLoadOperation { FileLog.e("messenger", e); } if (delayedRequestInfos != null) { - for (int a = 0; a < delayedRequestInfos.size(); a++) { - RequestInfo requestInfo = delayedRequestInfos.get(a); - /*if (requestInfo.response != null) { - requestInfo.response.disableFree = false; - requestInfo.response.freeResources(); - }*/ - } delayedRequestInfos.clear(); } } @@ -367,10 +300,6 @@ public class FileLoadOperation { } state = stateFinished; cleanup(); - if (cacheIvTemp != null) { - cacheIvTemp.delete(); - cacheIvTemp = null; - } if (cacheFileTemp != null) { boolean renameResult = cacheFileTemp.renameTo(cacheFileFinal); if (!renameResult) { @@ -416,24 +345,10 @@ public class FileLoadOperation { if (totalBytesCount > 0 && nextDownloadOffset >= totalBytesCount) { break; } - boolean isLast = totalBytesCount <= 0 || a == count - 1 || totalBytesCount > 0 && nextDownloadOffset + currentDownloadChunkSize >= totalBytesCount; - //TLRPC.TL_upload_getFile req = new TLRPC.TL_upload_getFile(); - //req.location = location; - //req.offset = nextDownloadOffset; - //req.limit = currentDownloadChunkSize; nextDownloadOffset += currentDownloadChunkSize; final RequestInfo requestInfo = new RequestInfo(); requestInfos.add(requestInfo); - requestInfo.offset = nextDownloadOffset; - requestInfo.requestToken = 0;/*ConnectionsManager.getInstance().sendRequest(req, new RequestDelegate() { - @Override - public void run(TLObject response, TLRPC.TL_error error) { - requestInfo.response = (TLRPC.TL_upload_file) response; - processRequestResult(requestInfo, error); - } - }, null, (isForceRequest ? ConnectionsManager.RequestFlagForceDownload : 0) | ConnectionsManager.RequestFlagFailOnServerErrors, datacenter_id, requestsCount % 2 == 0 ? ConnectionsManager.ConnectionTypeDownload : ConnectionsManager.ConnectionTypeDownload2, isLast);*/ - requestsCount++; } } diff --git a/MessengerProj/src/main/java/com/b44t/messenger/ImageLoader.java b/MessengerProj/src/main/java/com/b44t/messenger/ImageLoader.java index ce7b595b7..366404107 100644 --- a/MessengerProj/src/main/java/com/b44t/messenger/ImageLoader.java +++ b/MessengerProj/src/main/java/com/b44t/messenger/ImageLoader.java @@ -151,7 +151,7 @@ public class ImageLoader { } } catch (Throwable e) { if (e instanceof SocketTimeoutException) { - if (ConnectionsManager.isNetworkOnline()) { + if (ApplicationLoader.isNetworkOnline()) { canRetry = false; } } else if (e instanceof UnknownHostException) { diff --git a/MessengerProj/src/main/java/com/b44t/messenger/MediaController.java b/MessengerProj/src/main/java/com/b44t/messenger/MediaController.java index 0c6df65bd..b59c1a810 100644 --- a/MessengerProj/src/main/java/com/b44t/messenger/MediaController.java +++ b/MessengerProj/src/main/java/com/b44t/messenger/MediaController.java @@ -27,10 +27,8 @@ import android.Manifest; import android.annotation.SuppressLint; import android.annotation.TargetApi; import android.app.Activity; -import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; -import android.content.IntentFilter; import android.content.SharedPreferences; import android.content.pm.PackageManager; import android.database.ContentObserver; @@ -50,7 +48,6 @@ import android.media.MediaExtractor; import android.media.MediaFormat; import android.media.MediaPlayer; import android.media.MediaRecorder; -import android.net.ConnectivityManager; import android.net.Uri; import android.os.Build; import android.os.Environment; @@ -84,6 +81,7 @@ import java.util.Timer; import java.util.TimerTask; import java.util.concurrent.Semaphore; + public class MediaController implements AudioManager.OnAudioFocusChangeListener, NotificationCenter.NotificationCenterDelegate, SensorEventListener { private native int startRecord(String path); @@ -546,17 +544,6 @@ public class MediaController implements AudioManager.OnAudioFocusChangeListener, } }); - BroadcastReceiver networkStateReceiver = new BroadcastReceiver() { - @Override - public void onReceive(Context context, Intent intent) { - checkAutodownloadSettings(); - } - }; - IntentFilter filter = new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION); - ApplicationLoader.applicationContext.registerReceiver(networkStateReceiver, filter); - - checkAutodownloadSettings(); - if (Build.VERSION.SDK_INT >= 16) { mediaProjections = new String[]{ MediaStore.Images.ImageColumns.DATA, @@ -739,31 +726,6 @@ public class MediaController implements AudioManager.OnAudioFocusChangeListener, cancelVideoConvert(null); } - - public void checkAutodownloadSettings() { - /* -- leave this for future use - int currentMask = getCurrentDownloadMask(); - if (currentMask == lastCheckMask) { - return; - } - lastCheckMask = currentMask; - - ... maybe tell the backend what can be downloaded ... - - */ - } - - /* -- leave this for future use - private int getCurrentDownloadMask() { - if (ConnectionsManager.isConnectedToWiFi()) { - return wifiDownloadMask; - } else if (ConnectionsManager.isRoaming()) { - return roamingDownloadMask; - } else { - return mobileDataDownloadMask; - } - } */ - public int generateObserverTag() { return lastTag++; } @@ -1552,7 +1514,7 @@ public class MediaController implements AudioManager.OnAudioFocusChangeListener, return true; } if (!messageObject.isOut() && messageObject.isContentUnread()) { - MessagesController.getInstance().markMessageContentAsRead(messageObject); + MrMailbox.markMessageContentAsRead(messageObject); } boolean notify = !playMusicAgain; if (playingMessageObject != null) { @@ -1843,12 +1805,12 @@ public class MediaController implements AudioManager.OnAudioFocusChangeListener, recordingAudio = new TLRPC.TL_document(); recordingAudio.dc_id = Integer.MIN_VALUE; recordingAudio.id = UserConfig.lastLocalId; - recordingAudio.user_id = UserConfig.getClientUserId(); + recordingAudio.user_id = MrContact.MR_CONTACT_ID_SELF; recordingAudio.mime_type = "audio/ogg"; recordingAudio.thumb = new TLRPC.TL_photoSizeEmpty(); recordingAudio.thumb.type = "s"; UserConfig.lastLocalId--; - UserConfig.saveConfig(false); + UserConfig.saveConfig(); recordingAudioFile = new File(FileLoader.getInstance().getDirectory(FileLoader.MEDIA_DIR_CACHE), FileLoader.getAttachFileName(recordingAudio)); @@ -1976,7 +1938,7 @@ public class MediaController implements AudioManager.OnAudioFocusChangeListener, AndroidUtilities.runOnUIThread(new Runnable() { @Override public void run() { - audioToSend.date = ConnectionsManager.getInstance().getCurrentTime(); + audioToSend.date = MrMailbox.getCurrentTime(); audioToSend.size = (int) recordingAudioFileToSend.length(); TLRPC.TL_documentAttributeAudio attributeAudio = new TLRPC.TL_documentAttributeAudio(); attributeAudio.voice = true; @@ -2139,7 +2101,7 @@ public class MediaController implements AudioManager.OnAudioFocusChangeListener, if (name == null) { int id = UserConfig.lastLocalId; UserConfig.lastLocalId--; - UserConfig.saveConfig(false); + UserConfig.saveConfig(); name = String.format(Locale.US, "%d.%s", id, ext); } inputStream = ApplicationLoader.applicationContext.getContentResolver().openInputStream(uri); diff --git a/MessengerProj/src/main/java/com/b44t/messenger/MessageObject.java b/MessengerProj/src/main/java/com/b44t/messenger/MessageObject.java index 05da04f8e..17487a62d 100644 --- a/MessengerProj/src/main/java/com/b44t/messenger/MessageObject.java +++ b/MessengerProj/src/main/java/com/b44t/messenger/MessageObject.java @@ -95,7 +95,7 @@ public class MessageObject { textPaint.linkColor = Theme.MSG_LINK_TEXT_COLOR; } - textPaint.setTextSize(AndroidUtilities.dp(MessagesController.getInstance().fontSize)); + textPaint.setTextSize(AndroidUtilities.dp(ApplicationLoader.fontSize)); messageOwner = message; @@ -120,7 +120,7 @@ public class MessageObject { textPaint = new TextPaint(Paint.ANTI_ALIAS_FLAG); textPaint.setColor(Theme.MSG_TEXT_COLOR); textPaint.linkColor = Theme.MSG_LINK_TEXT_COLOR; - textPaint.setTextSize(AndroidUtilities.dp(MessagesController.getInstance().fontSize)); + textPaint.setTextSize(AndroidUtilities.dp(ApplicationLoader.fontSize)); } return textPaint; } diff --git a/MessengerProj/src/main/java/com/b44t/messenger/MessagesController.java b/MessengerProj/src/main/java/com/b44t/messenger/MessagesController.java deleted file mode 100644 index 4de584b3a..000000000 --- a/MessengerProj/src/main/java/com/b44t/messenger/MessagesController.java +++ /dev/null @@ -1,147 +0,0 @@ -/******************************************************************************* - * - * Messenger Android Frontend - * (C) 2013-2016 Nikolai Kudashov - * (C) 2017 Björn Petersen - * Contact: r10s@b44t.com, http://b44t.com - * - * This program is free software: you can redistribute it and/or modify it under - * the terms of the GNU General Public License as published by the Free Software - * Foundation, either version 3 of the License, or (at your option) any later - * version. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS - * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more - * details. - * - * You should have received a copy of the GNU General Public License along with - * this program. If not, see http://www.gnu.org/licenses/ . - * - ******************************************************************************/ - - -package com.b44t.messenger; - -import android.app.Activity; -import android.content.SharedPreferences; - -import com.b44t.ui.SettingsAdvActivity; - -import java.util.ArrayList; - -public class MessagesController { - - public int fontSize; - - public static final int UPDATE_MASK_NAME = 1; - public static final int UPDATE_MASK_AVATAR = 2; - public static final int UPDATE_MASK_STATUS = 4; - public static final int UPDATE_MASK_CHAT_AVATAR = 8; - public static final int UPDATE_MASK_CHAT_NAME = 16; - public static final int UPDATE_MASK_CHAT_MEMBERS = 32; - public static final int UPDATE_MASK_SELECT_DIALOG = 512; - public static final int UPDATE_MASK_NEW_MESSAGE = 2048; - public static final int UPDATE_MASK_SEND_STATE = 4096; - - private static volatile MessagesController Instance = null; - - public static MessagesController getInstance() { - MessagesController localInstance = Instance; - if (localInstance == null) { - synchronized (MessagesController.class) { - localInstance = Instance; - if (localInstance == null) { - Instance = localInstance = new MessagesController(); - } - } - } - return localInstance; - } - - public MessagesController() { - ImageLoader.getInstance(); - - SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("mainconfig", Activity.MODE_PRIVATE); - fontSize = preferences.getInt("msg_font_size", SettingsAdvActivity.defMsgFontSize()); - } - - public TLRPC.User getUser(Integer id) { - // EDIT BY MR - additional information should be loaded as needed by the caller - TLRPC.User u = new TLRPC.User(); - u.id = id; - return u; - } - - public MediaController.SearchImage saveGif(TLRPC.Document document) { - MediaController.SearchImage searchImage = new MediaController.SearchImage(); - searchImage.type = 2; - searchImage.document = document; - searchImage.date = (int) (System.currentTimeMillis() / 1000); - searchImage.id = "" + searchImage.document.id; - - ArrayList arrayList = new ArrayList<>(); - arrayList.add(searchImage); - //MessagesStorage.getInstance().putWebRecent(arrayList); - /*TLRPC.TL_messages_saveGif req = new TLRPC.TL_messages_saveGif(); - req.id = new TLRPC.TL_inputDocument(); - req.id.id = searchImage.document.id; - req.id.access_hash = searchImage.document.access_hash; - req.unsave = false; - ConnectionsManager.getInstance().sendRequest(req, new RequestDelegate() { - @Override - public void run(TLObject response, TLRPC.TL_error error) { - - } - });*/ - return searchImage; - } - - public void cancelTyping(int action, long dialog_id) { - } - - public void sendTyping(final long dialog_id, final int action, int classGuid) { - } - - public void markMessageContentAsRead(final MessageObject messageObject) { - } - - public void changeChatAvatar(int chat_id, TLRPC.InputFile uploadedAvatar) { - /*TLObject request; - { - TLRPC.TL_messages_editChatPhoto req = new TLRPC.TL_messages_editChatPhoto(); - req.chat_id = chat_id; - if (uploadedAvatar != null) { - req.photo = new TLRPC.TL_inputChatUploadedPhoto(); - req.photo.file = uploadedAvatar; - req.photo.crop = new TLRPC.TL_inputPhotoCropAuto(); - } else { - req.photo = new TLRPC.TL_inputChatPhotoEmpty(); - } - request = req; - }*/ - /*ConnectionsManager.getInstance().sendRequest(request, new RequestDelegate() { - @Override - public void run(TLObject response, TLRPC.TL_error error) { - if (error != null) { - return; - } - processUpdates((TLRPC.Updates) response, false); - } - }, ConnectionsManager.RequestFlagInvokeAfter);*/ - } - - public boolean isDialogMuted(long dialog_id) { - SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("Notifications", Activity.MODE_PRIVATE); - int mute_type = preferences.getInt("notify2_" + dialog_id, 0); - if (mute_type == 2) { - return true; - } else if (mute_type == 3) { - int mute_until = preferences.getInt("notifyuntil_" + dialog_id, 0); - if (mute_until >= ConnectionsManager.getInstance().getCurrentTime()) { - return true; - } - } - return false; - } -} diff --git a/MessengerProj/src/main/java/com/b44t/messenger/MrMailbox.java b/MessengerProj/src/main/java/com/b44t/messenger/MrMailbox.java index 2c7a7d918..a0e857e68 100644 --- a/MessengerProj/src/main/java/com/b44t/messenger/MrMailbox.java +++ b/MessengerProj/src/main/java/com/b44t/messenger/MrMailbox.java @@ -28,6 +28,12 @@ package com.b44t.messenger; +import android.app.Activity; +import android.content.Context; +import android.content.SharedPreferences; +import android.net.ConnectivityManager; +import android.net.NetworkInfo; + import java.io.BufferedInputStream; import java.io.BufferedReader; import java.io.InputStream; @@ -253,8 +259,8 @@ public class MrMailbox { public void run() { reloadMainChatlist(); NotificationCenter.getInstance().postNotificationName(NotificationCenter.updateInterfaces, - MessagesController.UPDATE_MASK_NAME|MessagesController.UPDATE_MASK_CHAT_NAME| - MessagesController.UPDATE_MASK_CHAT_MEMBERS|MessagesController.UPDATE_MASK_AVATAR); + UPDATE_MASK_NAME|UPDATE_MASK_CHAT_NAME| + UPDATE_MASK_CHAT_MEMBERS|UPDATE_MASK_AVATAR); } }); return 0; @@ -313,7 +319,7 @@ public class MrMailbox { return String2CPtr(sp); case MR_EVENT_IS_ONLINE: - return ConnectionsManager.isNetworkOnline()? 1 : 0; + return ApplicationLoader.isNetworkOnline()? 1 : 0; case MR_EVENT_HTTP_GET: String httpContent = null; @@ -375,4 +381,44 @@ public class MrMailbox { String text = LocaleController.formatString("InviteText", R.string.InviteText, url, email); return text; } + + public static TLRPC.User getUser(Integer id) { + TLRPC.User u = new TLRPC.User(); // legacy function, information should be loaded as needed by the caller + u.id = id; + return u; + } + + public static void cancelTyping(int action, long dialog_id) { + } + + public static void sendTyping(final long dialog_id, final int action, int classGuid) { + } + + public static void markMessageContentAsRead(final MessageObject messageObject) { + } + + public static boolean isDialogMuted(long dialog_id) { + SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("Notifications", Activity.MODE_PRIVATE); + int mute_type = preferences.getInt("notify2_" + dialog_id, 0); + if (mute_type == 2) { + return true; + } else if (mute_type == 3) { + int mute_until = preferences.getInt("notifyuntil_" + dialog_id, 0); + if (mute_until >= MrMailbox.getCurrentTime()) { + return true; + } + } + return false; + } + + // legacy update masks + public static final int UPDATE_MASK_NAME = 1; + public static final int UPDATE_MASK_AVATAR = 2; + public static final int UPDATE_MASK_STATUS = 4; + public static final int UPDATE_MASK_CHAT_AVATAR = 8; + public static final int UPDATE_MASK_CHAT_NAME = 16; + public static final int UPDATE_MASK_CHAT_MEMBERS = 32; + public static final int UPDATE_MASK_SELECT_DIALOG = 512; + public static final int UPDATE_MASK_NEW_MESSAGE = 2048; + public static final int UPDATE_MASK_SEND_STATE = 4096; } diff --git a/MessengerProj/src/main/java/com/b44t/messenger/NotificationsController.java b/MessengerProj/src/main/java/com/b44t/messenger/NotificationsController.java index 76a8627a3..2276210a3 100644 --- a/MessengerProj/src/main/java/com/b44t/messenger/NotificationsController.java +++ b/MessengerProj/src/main/java/com/b44t/messenger/NotificationsController.java @@ -94,7 +94,7 @@ public class NotificationsController { public static NotificationsController getInstance() { NotificationsController localInstance = Instance; if (localInstance == null) { - synchronized (MessagesController.class) { + synchronized (NotificationsController.class) { localInstance = Instance; if (localInstance == null) { Instance = localInstance = new NotificationsController(); @@ -847,7 +847,7 @@ public class NotificationsController { int notifyOverride = preferences.getInt("notify2_" + dialog_id, 0); if (notifyOverride == 3) { int muteUntil = preferences.getInt("notifyuntil_" + dialog_id, 0); - if (muteUntil >= ConnectionsManager.getInstance().getCurrentTime()) { + if (muteUntil >= MrMailbox.getCurrentTime()) { notifyOverride = 2; } } @@ -968,8 +968,6 @@ public class NotificationsController { } try { - ConnectionsManager.getInstance().resumeNetworkMaybe(); - MessageObject lastMessageObject = pushMessages.get(0); SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("Notifications", Context.MODE_PRIVATE); int dismissDate = preferences.getInt("dismissDate", 0); @@ -1321,7 +1319,7 @@ public class NotificationsController { TLRPC.User user = null; String name; if (dialog_id > 0) { - user = MessagesController.getInstance().getUser((int)dialog_id); + user = MrMailbox.getUser((int)dialog_id); if (user == null) { continue; } @@ -1507,35 +1505,4 @@ public class NotificationsController { } }); } - - public static void updateServerNotificationsSettings(long dialog_id) { - // the following command is needed to reflect the changes in the GUI - NotificationCenter.getInstance().postNotificationName(NotificationCenter.notificationsSettingsUpdated); - - /* - if ((int) dialog_id == 0) { - return; - } - SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("Notifications", Activity.MODE_PRIVATE); - TLRPC.TL_account_updateNotifySettings req = new TLRPC.TL_account_updateNotifySettings(); - req.settings = new TLRPC.TL_inputPeerNotifySettings(); - req.settings.sound = "default"; - int mute_type = preferences.getInt("notify2_" + dialog_id, 0); - if (mute_type == 3) { - req.settings.mute_until = preferences.getInt("notifyuntil_" + dialog_id, 0); - } else { - req.settings.mute_until = mute_type != 2 ? 0 : Integer.MAX_VALUE; - } - req.settings.show_previews = preferences.getBoolean("preview_" + dialog_id, true); - req.settings.silent = preferences.getBoolean("silent_" + dialog_id, false); - req.peer = new TLRPC.TL_inputNotifyPeer(); - ((TLRPC.TL_inputNotifyPeer) req.peer).peer = MessagesController.getInputPeer((int) dialog_id); - ConnectionsManager.getInstance().sendRequest(req, new RequestDelegate() { - @Override - public void run(TLObject response, TLRPC.TL_error error) { - - } - }); - */ - } } diff --git a/MessengerProj/src/main/java/com/b44t/messenger/SendMessagesHelper.java b/MessengerProj/src/main/java/com/b44t/messenger/SendMessagesHelper.java index 4283b06d0..23f369c93 100644 --- a/MessengerProj/src/main/java/com/b44t/messenger/SendMessagesHelper.java +++ b/MessengerProj/src/main/java/com/b44t/messenger/SendMessagesHelper.java @@ -234,10 +234,6 @@ public class SendMessagesHelper implements NotificationCenter.NotificationCenter } } - public void checkUnsentMessages() { - //MessagesStorage.getInstance().getUnsentMessages(1000); - } - public TLRPC.TL_photo generatePhotoSizes(String path, Uri imageUri) { Bitmap bitmap = ImageLoader.loadBitmap(path, imageUri, AndroidUtilities.getPhotoSize(), AndroidUtilities.getPhotoSize(), true); if (bitmap == null && AndroidUtilities.getPhotoSize() != 800) { @@ -258,9 +254,9 @@ public class SendMessagesHelper implements NotificationCenter.NotificationCenter if (sizes.isEmpty()) { return null; } else { - UserConfig.saveConfig(false); + UserConfig.saveConfig(); TLRPC.TL_photo photo = new TLRPC.TL_photo(); - photo.date = ConnectionsManager.getInstance().getCurrentTime(); + photo.date = MrMailbox.getCurrentTime(); photo.sizes = sizes; return photo; } @@ -329,16 +325,10 @@ public class SendMessagesHelper implements NotificationCenter.NotificationCenter } TLRPC.TL_document document = null; - /*if (!isEncrypted)*/ { - document = null;//(TLRPC.TL_document) MessagesStorage.getInstance().getSentFile(originalPath, !isEncrypted ? 1 : 4); - if (document == null && !path.equals(originalPath) /*&& !isEncrypted*/) { - document = null;//(TLRPC.TL_document) MessagesStorage.getInstance().getSentFile(path + f.length(), !isEncrypted ? 1 : 4); - } - } - if (document == null) { + { document = new TLRPC.TL_document(); document.id = 0; - document.date = ConnectionsManager.getInstance().getCurrentTime(); + document.date = MrMailbox.getCurrentTime(); TLRPC.TL_documentAttributeFilename fileName = new TLRPC.TL_documentAttributeFilename(); fileName.file_name = name; document.attributes.add(fileName); @@ -654,7 +644,7 @@ public class SendMessagesHelper implements NotificationCenter.NotificationCenter { document = new TLRPC.TL_document(); document.mime_type = "video/mp4"; - UserConfig.saveConfig(false); + UserConfig.saveConfig(); TLRPC.TL_documentAttributeVideo attributeVideo = new TLRPC.TL_documentAttributeVideo(); document.attributes.add(attributeVideo); if (videoEditedInfo != null) { diff --git a/MessengerProj/src/main/java/com/b44t/messenger/UserConfig.java b/MessengerProj/src/main/java/com/b44t/messenger/UserConfig.java index 9300652c0..e4039bfce 100644 --- a/MessengerProj/src/main/java/com/b44t/messenger/UserConfig.java +++ b/MessengerProj/src/main/java/com/b44t/messenger/UserConfig.java @@ -31,7 +31,6 @@ import java.io.File; public class UserConfig { - private static TLRPC.User currentUser; public static int lastLocalId = -210000; private final static Object sync = new Object(); public static String passcodeHash = ""; @@ -43,11 +42,7 @@ public class UserConfig { public static boolean isWaitingForPasscodeEnter; public static boolean useFingerprint = true; - public static void saveConfig(boolean withFile) { - saveConfig(withFile, null); - } - - public static void saveConfig(boolean withFile, File oldFile) { + public static void saveConfig() { synchronized (sync) { try { SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("userconfing", Context.MODE_PRIVATE); @@ -61,128 +56,15 @@ public class UserConfig { editor.putInt("lastPauseTime", lastPauseTime); editor.putBoolean("useFingerprint", useFingerprint); - /* - if (currentUser != null) { - if (withFile) { - SerializedData data = new SerializedData(); - currentUser.serializeToStream(data); - String userString = Base64.encodeToString(data.toByteArray(), Base64.DEFAULT); - editor.putString("user", userString); - data.cleanup(); - } - } else { - editor.remove("user"); - } - */ - editor.apply(); - if (oldFile != null) { - oldFile.delete(); - } } catch (Exception e) { FileLog.e("messenger", e); } } } - public static boolean isClientActivated() { - return true; // EDIT BY MR -- for "real" checking, call MrMailbox.MrMailboxIsConfigured() - /* EDIT BY MR - synchronized (sync) { - return currentUser != null; - } - */ - } - - public static int getClientUserId() { - return 1; // we are user #1 by definition - /* EDIT BY MR - synchronized (sync) { - return currentUser != null ? currentUser.id : 0; - } - */ - } - - public static TLRPC.User getCurrentUser() { - synchronized (sync) { - if( currentUser==null ) { - currentUser = MrContact.contactId2user(1); - } - return currentUser; - } - } - - public static void setCurrentUser(TLRPC.User user) { - synchronized (sync) { - currentUser = MrContact.contactId2user(1); // EDIT BY MR - force the current user to be user #1, normally this function should not be called at all - } - } - public static void loadConfig() { synchronized (sync) { - /* - final File configFile = new File(ApplicationLoader.getFilesDirFixed(), "user.dat"); - if (configFile.exists()) { - try { - SerializedData data = new SerializedData(configFile); - int ver = data.readInt32(false); - if (ver == 1) { - int constructor = data.readInt32(false); - currentUser = TLRPC.User.TLdeserialize(data, constructor, false); - MessagesStorage.lastDateValue = data.readInt32(false); - MessagesStorage.lastPtsValue = data.readInt32(false); - MessagesStorage.lastSeqValue = data.readInt32(false); - registeredForPush = data.readBool(false); - pushString = data.readString(false); - lastSendMessageId = data.readInt32(false); - lastLocalId = data.readInt32(false); - contactsHash = data.readString(false); - data.readString(false); - saveIncomingPhotos = data.readBool(false); - //MessagesStorage.lastQtsValue = data.readInt32(false); - //MessagesStorage.lastSecretVersion = data.readInt32(false); - int val = data.readInt32(false); - //if (val == 1) { - // MessagesStorage.secretPBytes = data.readByteArray(false); - //} - //MessagesStorage.secretG = data.readInt32(false); - Utilities.stageQueue.postRunnable(new Runnable() { - @Override - public void run() { - saveConfig(true, configFile); - } - }); - } else if (ver == 2) { - int constructor = data.readInt32(false); - currentUser = TLRPC.User.TLdeserialize(data, constructor, false); - - SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("userconfing", Context.MODE_PRIVATE); - registeredForPush = preferences.getBoolean("registeredForPush", false); - pushString = preferences.getString("pushString2", ""); - lastSendMessageId = preferences.getInt("lastSendMessageId", -210000); - lastLocalId = preferences.getInt("lastLocalId", -210000); - contactsHash = preferences.getString("contactsHash", ""); - saveIncomingPhotos = preferences.getBoolean("saveIncomingPhotos", false); - } - if (lastLocalId > -210000) { - lastLocalId = -210000; - } - if (lastSendMessageId > -210000) { - lastSendMessageId = -210000; - } - data.cleanup(); - Utilities.stageQueue.postRunnable(new Runnable() { - @Override - public void run() { - saveConfig(true, configFile); - } - }); - } catch (Exception e) { - FileLog.e("messenger", e); - } - } else - */ - { SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("userconfing", Context.MODE_PRIVATE); lastLocalId = preferences.getInt("lastLocalId", -210000); passcodeHash = preferences.getString("passcodeHash1", ""); @@ -192,26 +74,12 @@ public class UserConfig { lastPauseTime = preferences.getInt("lastPauseTime", 0); useFingerprint = preferences.getBoolean("useFingerprint", true); - /* - String user = preferences.getString("user", null); - if (user != null) { - byte[] userBytes = Base64.decode(user, Base64.DEFAULT); - if (userBytes != null) { - SerializedData data = new SerializedData(userBytes); - currentUser = TLRPC.User.TLdeserialize(data, data.readInt32(false), false); - data.cleanup(); - } - } - */ - setCurrentUser(null); - String passcodeSaltString = preferences.getString("passcodeSalt", ""); if (passcodeSaltString.length() > 0) { passcodeSalt = Base64.decode(passcodeSaltString, Base64.DEFAULT); } else { passcodeSalt = new byte[0]; } - } } } @@ -228,7 +96,7 @@ public class UserConfig { System.arraycopy(passcodeBytes, 0, bytes, 16, passcodeBytes.length); System.arraycopy(passcodeSalt, 0, bytes, passcodeBytes.length + 16, 16); passcodeHash = Utilities.bytesToHex(Utilities.computeSHA256(bytes, 0, bytes.length)); - saveConfig(false); + saveConfig(); } catch (Exception e) { FileLog.e("messenger", e); } diff --git a/MessengerProj/src/main/java/com/b44t/ui/ActionBar/BaseFragment.java b/MessengerProj/src/main/java/com/b44t/ui/ActionBar/BaseFragment.java index b0e460f35..0151eaeda 100644 --- a/MessengerProj/src/main/java/com/b44t/ui/ActionBar/BaseFragment.java +++ b/MessengerProj/src/main/java/com/b44t/ui/ActionBar/BaseFragment.java @@ -33,8 +33,8 @@ import android.os.Bundle; import android.view.View; import android.view.ViewGroup; +import com.b44t.messenger.ApplicationLoader; import com.b44t.messenger.FileLog; -import com.b44t.messenger.ConnectionsManager; public class BaseFragment { @@ -63,12 +63,12 @@ public class BaseFragment { RC500_PHOTO_VIEW = 500; public BaseFragment() { - classGuid = ConnectionsManager.getInstance().generateClassGuid(); + classGuid = ApplicationLoader.generateClassGuid(); } public BaseFragment(Bundle args) { arguments = args; - classGuid = ConnectionsManager.getInstance().generateClassGuid(); + classGuid = ApplicationLoader.generateClassGuid(); } public ActionBar getActionBar() { @@ -179,7 +179,6 @@ public class BaseFragment { } public void onFragmentDestroy() { - //ConnectionsManager.getInstance().cancelRequestsForGuid(classGuid); isFinished = true; if (actionBar != null) { actionBar.setEnabled(false); diff --git a/MessengerProj/src/main/java/com/b44t/ui/Adapters/DrawerLayoutAdapter.java b/MessengerProj/src/main/java/com/b44t/ui/Adapters/DrawerLayoutAdapter.java index d2f7a4102..9ca253ccc 100644 --- a/MessengerProj/src/main/java/com/b44t/ui/Adapters/DrawerLayoutAdapter.java +++ b/MessengerProj/src/main/java/com/b44t/ui/Adapters/DrawerLayoutAdapter.java @@ -31,7 +31,6 @@ import android.widget.BaseAdapter; import com.b44t.messenger.AndroidUtilities; import com.b44t.messenger.LocaleController; import com.b44t.messenger.R; -import com.b44t.messenger.UserConfig; import com.b44t.ui.Cells.DrawerActionCell; import com.b44t.ui.Cells.DividerCell; import com.b44t.ui.Cells.EmptyCell; @@ -153,6 +152,6 @@ public class DrawerLayoutAdapter extends BaseAdapter { @Override public boolean isEmpty() { - return !UserConfig.isClientActivated(); + return false; } } diff --git a/MessengerProj/src/main/java/com/b44t/ui/AudioSelectActivity.java b/MessengerProj/src/main/java/com/b44t/ui/AudioSelectActivity.java index d7827dc50..e95645172 100644 --- a/MessengerProj/src/main/java/com/b44t/ui/AudioSelectActivity.java +++ b/MessengerProj/src/main/java/com/b44t/ui/AudioSelectActivity.java @@ -36,6 +36,7 @@ import com.b44t.messenger.AndroidUtilities; import com.b44t.messenger.LocaleController; import com.b44t.messenger.MediaController; import com.b44t.messenger.MessageObject; +import com.b44t.messenger.MrContact; import com.b44t.messenger.NotificationCenter; import com.b44t.messenger.ApplicationLoader; import com.b44t.messenger.FileLoader; @@ -229,7 +230,7 @@ public class AudioSelectActivity extends BaseFragment implements NotificationCen message.out = true; message.id = id; message.to_id = new TLRPC.TL_peerUser(); - message.to_id.user_id = message.from_id = UserConfig.getClientUserId(); + message.to_id.user_id = message.from_id = MrContact.MR_CONTACT_ID_SELF; message.date = (int) (System.currentTimeMillis() / 1000); message.message = "-1"; message.attachPath = audioEntry.path; diff --git a/MessengerProj/src/main/java/com/b44t/ui/BlockedUsersActivity.java b/MessengerProj/src/main/java/com/b44t/ui/BlockedUsersActivity.java index 4ec31b85b..ea91b61f9 100644 --- a/MessengerProj/src/main/java/com/b44t/ui/BlockedUsersActivity.java +++ b/MessengerProj/src/main/java/com/b44t/ui/BlockedUsersActivity.java @@ -40,8 +40,6 @@ import com.b44t.messenger.ApplicationLoader; import com.b44t.messenger.LocaleController; import com.b44t.messenger.MrContact; import com.b44t.messenger.MrMailbox; -import com.b44t.messenger.TLRPC; -import com.b44t.messenger.MessagesController; import com.b44t.messenger.NotificationCenter; import com.b44t.messenger.R; import com.b44t.ui.Adapters.BaseFragmentAdapter; @@ -167,8 +165,8 @@ public class BlockedUsersActivity extends BaseFragment implements NotificationCe public void didReceivedNotification(int id, Object... args) { if (id == NotificationCenter.updateInterfaces) { int mask = (Integer)args[0]; - if ((mask & MessagesController.UPDATE_MASK_AVATAR) != 0 || (mask & MessagesController.UPDATE_MASK_NAME) != 0) { - updateVisibleRows(mask); + if ((mask & MrMailbox.UPDATE_MASK_AVATAR) != 0 || (mask & MrMailbox.UPDATE_MASK_NAME) != 0) { + updateVisibleRows(); } } else if (id == NotificationCenter.blockedUsersDidLoaded) { blockedUserIds = MrMailbox.getBlockedContacts(); @@ -181,7 +179,7 @@ public class BlockedUsersActivity extends BaseFragment implements NotificationCe } } - private void updateVisibleRows(int mask) { + private void updateVisibleRows() { if (listView == null) { return; } @@ -189,7 +187,7 @@ public class BlockedUsersActivity extends BaseFragment implements NotificationCe for (int a = 0; a < count; a++) { View child = listView.getChildAt(a); if (child instanceof UserCell) { - ((UserCell) child).update(mask); + ((UserCell) child).update(); } } } diff --git a/MessengerProj/src/main/java/com/b44t/ui/Cells/ChatActionCell.java b/MessengerProj/src/main/java/com/b44t/ui/Cells/ChatActionCell.java index 781690c90..6f50758d0 100644 --- a/MessengerProj/src/main/java/com/b44t/ui/Cells/ChatActionCell.java +++ b/MessengerProj/src/main/java/com/b44t/ui/Cells/ChatActionCell.java @@ -35,7 +35,6 @@ import android.view.MotionEvent; import com.b44t.messenger.AndroidUtilities; import com.b44t.messenger.ApplicationLoader; import com.b44t.messenger.MessageObject; -import com.b44t.messenger.MessagesController; import com.b44t.messenger.FileLog; import com.b44t.ui.ActionBar.Theme; @@ -68,7 +67,7 @@ public class ChatActionCell extends BaseCell { } backPaint.setColor(ApplicationLoader.getServiceMessageColor()); - textPaint.setTextSize(AndroidUtilities.dp(MessagesController.getInstance().fontSize - 2)); + textPaint.setTextSize(AndroidUtilities.dp(ApplicationLoader.fontSize - 2)); } public void setMessageObject(MessageObject messageObject) { diff --git a/MessengerProj/src/main/java/com/b44t/ui/Cells/ChatMessageCell.java b/MessengerProj/src/main/java/com/b44t/ui/Cells/ChatMessageCell.java index 0676fd3d2..3101166c6 100644 --- a/MessengerProj/src/main/java/com/b44t/ui/Cells/ChatMessageCell.java +++ b/MessengerProj/src/main/java/com/b44t/ui/Cells/ChatMessageCell.java @@ -53,7 +53,6 @@ import com.b44t.messenger.MediaController; import com.b44t.messenger.FileLoader; import com.b44t.messenger.FileLog; import com.b44t.messenger.MessageObject; -import com.b44t.messenger.MessagesController; import com.b44t.messenger.MrChat; import com.b44t.messenger.MrContact; import com.b44t.messenger.MrMailbox; @@ -894,7 +893,7 @@ public class ChatMessageCell extends BaseCell implements SeekBar.SeekBarDelegate TLRPC.User newUser = null; final TLRPC.Chat newChat = null; if (currentMessageObject.isFromUser()) { - newUser = MessagesController.getInstance().getUser(currentMessageObject.messageOwner.from_id); + newUser = MrMailbox.getUser(currentMessageObject.messageOwner.from_id); } /*else if (currentMessageObject.messageOwner.post) { newChat = MessagesController.getInstance().getChat(currentMessageObject.messageOwner.to_id.channel_id); }*/ @@ -2120,7 +2119,7 @@ public class ChatMessageCell extends BaseCell implements SeekBar.SeekBarDelegate private void measureTime(MessageObject messageObject) { boolean hasSign = !messageObject.isOutOwner() && messageObject.messageOwner.from_id > 0 && messageObject.messageOwner.post; - TLRPC.User signUser = MessagesController.getInstance().getUser(messageObject.messageOwner.from_id); + TLRPC.User signUser = MrMailbox.getUser(messageObject.messageOwner.from_id); if (hasSign && signUser == null) { hasSign = false; } @@ -2163,7 +2162,7 @@ public class ChatMessageCell extends BaseCell implements SeekBar.SeekBarDelegate private void setMessageObjectInternal(MessageObject messageObject) { if (currentMessageObject.isFromUser()) { - currentUser = MessagesController.getInstance().getUser(currentMessageObject.messageOwner.from_id); + currentUser = MrMailbox.getUser(currentMessageObject.messageOwner.from_id); } /*else if (currentMessageObject.messageOwner.from_id < 0) { currentChat = MessagesController.getInstance().getChat(-currentMessageObject.messageOwner.from_id); } else if (currentMessageObject.messageOwner.post) { diff --git a/MessengerProj/src/main/java/com/b44t/ui/Cells/ChatUnreadCell.java b/MessengerProj/src/main/java/com/b44t/ui/Cells/ChatUnreadCell.java index 7f1e63afa..0d4697f93 100644 --- a/MessengerProj/src/main/java/com/b44t/ui/Cells/ChatUnreadCell.java +++ b/MessengerProj/src/main/java/com/b44t/ui/Cells/ChatUnreadCell.java @@ -32,7 +32,7 @@ import android.widget.ImageView; import android.widget.TextView; import com.b44t.messenger.AndroidUtilities; -import com.b44t.messenger.MessagesController; +import com.b44t.messenger.ApplicationLoader; import com.b44t.messenger.R; import com.b44t.ui.Components.LayoutHelper; import com.b44t.ui.ActionBar.Theme; @@ -50,7 +50,7 @@ public class ChatUnreadCell extends FrameLayout { textView = new TextView(context); textView.setPadding(0, 0, 0, AndroidUtilities.dp(1)); - textView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, MessagesController.getInstance().fontSize-2); + textView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, ApplicationLoader.fontSize-2); textView.setTextColor(Theme.MSG_IN_TIME_N_FWD_TEXT_COLOR); textView.setTypeface(Typeface.DEFAULT_BOLD); addView(textView, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, Gravity.CENTER)); diff --git a/MessengerProj/src/main/java/com/b44t/ui/Cells/DialogCell.java b/MessengerProj/src/main/java/com/b44t/ui/Cells/DialogCell.java index 1290e1842..da12c1d75 100644 --- a/MessengerProj/src/main/java/com/b44t/ui/Cells/DialogCell.java +++ b/MessengerProj/src/main/java/com/b44t/ui/Cells/DialogCell.java @@ -49,7 +49,6 @@ import com.b44t.messenger.MrMsg; import com.b44t.messenger.MrPoortext; import com.b44t.messenger.TLRPC; import com.b44t.messenger.Emoji; -import com.b44t.messenger.MessagesController; import com.b44t.messenger.R; import com.b44t.messenger.ImageReceiver; import com.b44t.ui.ActionBar.Theme; @@ -551,27 +550,27 @@ public class DialogCell extends BaseCell { if (mask != 0) { boolean continueUpdate = false; - if (!continueUpdate && (mask & MessagesController.UPDATE_MASK_AVATAR) != 0) { + if (!continueUpdate && (mask & MrMailbox.UPDATE_MASK_AVATAR) != 0) { if (chat == null) { continueUpdate = true; } } - if (!continueUpdate && (mask & MessagesController.UPDATE_MASK_NAME) != 0) { + if (!continueUpdate && (mask & MrMailbox.UPDATE_MASK_NAME) != 0) { if (chat == null) { continueUpdate = true; } } - if (!continueUpdate && (mask & MessagesController.UPDATE_MASK_CHAT_AVATAR) != 0) { + if (!continueUpdate && (mask & MrMailbox.UPDATE_MASK_CHAT_AVATAR) != 0) { if (user == null) { continueUpdate = true; } } - if (!continueUpdate && (mask & MessagesController.UPDATE_MASK_CHAT_NAME) != 0) { + if (!continueUpdate && (mask & MrMailbox.UPDATE_MASK_CHAT_NAME) != 0) { if (user == null) { continueUpdate = true; } } - if (!continueUpdate && (mask & MessagesController.UPDATE_MASK_SEND_STATE) != 0) { + if (!continueUpdate && (mask & MrMailbox.UPDATE_MASK_SEND_STATE) != 0) { if (message != null && lastSendState != message.messageOwner.send_state) { lastSendState = message.messageOwner.send_state; continueUpdate = true; @@ -583,7 +582,7 @@ public class DialogCell extends BaseCell { } } - dialogMuted = isDialogCell && MessagesController.getInstance().isDialogMuted(currentDialogId); + dialogMuted = isDialogCell && MrMailbox.isDialogMuted(currentDialogId); //user = null; //chat = null; diff --git a/MessengerProj/src/main/java/com/b44t/ui/Cells/UserCell.java b/MessengerProj/src/main/java/com/b44t/ui/Cells/UserCell.java index 1b87fa2de..a9ac3960e 100644 --- a/MessengerProj/src/main/java/com/b44t/ui/Cells/UserCell.java +++ b/MessengerProj/src/main/java/com/b44t/ui/Cells/UserCell.java @@ -96,7 +96,7 @@ public class UserCell extends FrameLayout { currentStatus = m_mrContact.getAddr(); } currentResId = resId; - update(0); + update(); } public void setChecked(boolean checked, boolean animated) { @@ -117,60 +117,10 @@ public class UserCell extends FrameLayout { statusColor = color; } - public void update(int mask) { + public void update() { if (m_mrContact==null) { return; } - TLRPC.FileLocation photo = null; - //String newName = null; - - /* - if (mask != 0) { - boolean continueUpdate = false; - if ((mask & MessagesController.UPDATE_MASK_AVATAR) != 0) { - if (lastAvatar != null && photo == null || lastAvatar == null && photo != null && lastAvatar != null && photo != null && (lastAvatar.volume_id != photo.volume_id || lastAvatar.local_id != photo.local_id)) { - continueUpdate = true; - } - } - - if (user_id != 0 && !continueUpdate && (mask & MessagesController.UPDATE_MASK_STATUS) != 0) { - int newStatus = 0; - if (currentUser.status != null) { - newStatus = currentUser.status.expires; - } - if (newStatus != lastStatus) { - continueUpdate = true; - } - } - - if (!continueUpdate && currentName == null && lastName != null && (mask & MessagesController.UPDATE_MASK_NAME) != 0) { - if (currentUser != null) { - newName = UserObject.getUserName(currentUser); - } else { - newName = currentChat.title; - } - if (!newName.equals(lastName)) { - continueUpdate = true; - } - } - if (!continueUpdate) { - return; - } - } - */ - - /* - if (currentUser != null) { - avatarDrawable.setInfoByUser(currentUser); - if (currentUser.status != null) { - lastStatus = currentUser.status.expires; - } else { - lastStatus = 0; - } - } else { - avatarDrawable.setInfoByChat(currentChat); - } - */ if (currentName != null) { nameTextView.setText(currentName); diff --git a/MessengerProj/src/main/java/com/b44t/ui/ChatActivity.java b/MessengerProj/src/main/java/com/b44t/ui/ChatActivity.java index 6a0430aad..7e3de7e41 100644 --- a/MessengerProj/src/main/java/com/b44t/ui/ChatActivity.java +++ b/MessengerProj/src/main/java/com/b44t/ui/ChatActivity.java @@ -73,11 +73,9 @@ import com.b44t.messenger.browser.Browser; import com.b44t.messenger.support.widget.LinearLayoutManager; import com.b44t.messenger.support.widget.RecyclerView; import com.b44t.messenger.ApplicationLoader; -import com.b44t.messenger.ConnectionsManager; import com.b44t.messenger.TLRPC; import com.b44t.messenger.FileLog; import com.b44t.messenger.MessageObject; -import com.b44t.messenger.MessagesController; import com.b44t.messenger.NotificationCenter; import com.b44t.messenger.R; import com.b44t.messenger.UserConfig; @@ -1056,7 +1054,7 @@ public class ChatActivity extends BaseFragment implements NotificationCenter.Not @Override public void needSendTyping() { - MessagesController.getInstance().sendTyping(dialog_id, 0, classGuid); + MrMailbox.sendTyping(dialog_id, 0, classGuid); } @Override @@ -1363,7 +1361,7 @@ public class ChatActivity extends BaseFragment implements NotificationCenter.Not } private void toggleMute() { - boolean muted = MessagesController.getInstance().isDialogMuted(dialog_id); + boolean muted = MrMailbox.isDialogMuted(dialog_id); if (!muted) { // EDIT BY MR AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity()); // was: BottomSheet.Builder @@ -1377,7 +1375,7 @@ public class ChatActivity extends BaseFragment implements NotificationCenter.Not builder.setItems(items, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialogInterface, int i) { - int untilTime = ConnectionsManager.getInstance().getCurrentTime(); + int untilTime = MrMailbox.getCurrentTime(); if (i == 0) { untilTime += 60 * 60; } else if (i == 1) { untilTime += 60 * 60 * 8; } else if (i == 2) { untilTime += 60 * 60 * 48; } @@ -1399,7 +1397,7 @@ public class ChatActivity extends BaseFragment implements NotificationCenter.Not dialog.notify_settings.mute_until = untilTime; } */ - NotificationsController.updateServerNotificationsSettings(dialog_id); + NotificationCenter.getInstance().postNotificationName(NotificationCenter.notificationsSettingsUpdated); } } ); @@ -1415,7 +1413,7 @@ public class ChatActivity extends BaseFragment implements NotificationCenter.Not dialog.notify_settings = new TLRPC.TL_peerNotifySettings(); } */ - NotificationsController.updateServerNotificationsSettings(dialog_id); + NotificationCenter.getInstance().postNotificationName(NotificationCenter.notificationsSettingsUpdated); } } @@ -1620,7 +1618,7 @@ public class ChatActivity extends BaseFragment implements NotificationCenter.Not } int rightIcon = 0; - if( m_canMute && MessagesController.getInstance().isDialogMuted(dialog_id) ) { + if( m_canMute && MrMailbox.isDialogMuted(dialog_id) ) { rightIcon = R.drawable.mute_fixed; } @@ -1879,16 +1877,16 @@ public class ChatActivity extends BaseFragment implements NotificationCenter.Not else if (id == NotificationCenter.updateInterfaces) { int updateMask = (Integer) args[0]; - if ((updateMask & MessagesController.UPDATE_MASK_NAME) != 0 || (updateMask & MessagesController.UPDATE_MASK_CHAT_NAME) != 0) { + if ((updateMask & MrMailbox.UPDATE_MASK_NAME) != 0 || (updateMask & MrMailbox.UPDATE_MASK_CHAT_NAME) != 0) { int back_id = m_mrChat.getId(); m_mrChat = MrMailbox.getChat(back_id); updateTitle(); } boolean updateSubtitle = false; - if ((updateMask & MessagesController.UPDATE_MASK_CHAT_MEMBERS) != 0 || (updateMask & MessagesController.UPDATE_MASK_STATUS) != 0) { + if ((updateMask & MrMailbox.UPDATE_MASK_CHAT_MEMBERS) != 0 || (updateMask & MrMailbox.UPDATE_MASK_STATUS) != 0) { updateSubtitle = true; } - if ((updateMask & MessagesController.UPDATE_MASK_AVATAR) != 0 || (updateMask & MessagesController.UPDATE_MASK_CHAT_AVATAR) != 0 || (updateMask & MessagesController.UPDATE_MASK_NAME) != 0) { + if ((updateMask & MrMailbox.UPDATE_MASK_AVATAR) != 0 || (updateMask & MrMailbox.UPDATE_MASK_CHAT_AVATAR) != 0 || (updateMask & MrMailbox.UPDATE_MASK_NAME) != 0) { checkAndUpdateAvatar(); updateVisibleRows(); } @@ -2252,7 +2250,7 @@ public class ChatActivity extends BaseFragment implements NotificationCenter.Not } m_mrChat.saveDraft(draftMessage, null); - MessagesController.getInstance().cancelTyping(0, dialog_id); + MrMailbox.cancelTyping(0, dialog_id); } private void applyDraftMaybe() { @@ -2603,7 +2601,7 @@ public class ChatActivity extends BaseFragment implements NotificationCenter.Not processRowSelect(cell); return; } - if (user != null && user.id != UserConfig.getClientUserId()) { + if (user != null && user.id != MrContact.MR_CONTACT_ID_SELF) { Bundle args = new Bundle(); args.putInt("user_id", user.id); ProfileActivity fragment = new ProfileActivity(args); diff --git a/MessengerProj/src/main/java/com/b44t/ui/Components/AvatarUpdater.java b/MessengerProj/src/main/java/com/b44t/ui/Components/AvatarUpdater.java index 98a065c49..be2f6045c 100644 --- a/MessengerProj/src/main/java/com/b44t/ui/Components/AvatarUpdater.java +++ b/MessengerProj/src/main/java/com/b44t/ui/Components/AvatarUpdater.java @@ -211,7 +211,7 @@ public class AvatarUpdater implements PhotoCropActivity.PhotoEditActivityDelegat delegate.didUploadedPhoto(null, smallPhoto, bigPhoto); } } else { - UserConfig.saveConfig(false); + UserConfig.saveConfig(); uploadingAvatar = FileLoader.getInstance().getDirectory(FileLoader.MEDIA_DIR_CACHE) + "/" + bigPhoto.location.volume_id + "_" + bigPhoto.location.local_id + ".jpg"; //FileLoader.getInstance().uploadFile(uploadingAvatar, false, true); } diff --git a/MessengerProj/src/main/java/com/b44t/ui/Components/ChatActivityEnterView.java b/MessengerProj/src/main/java/com/b44t/ui/Components/ChatActivityEnterView.java index ad38bfd31..db9b88ff6 100644 --- a/MessengerProj/src/main/java/com/b44t/ui/Components/ChatActivityEnterView.java +++ b/MessengerProj/src/main/java/com/b44t/ui/Components/ChatActivityEnterView.java @@ -65,7 +65,8 @@ import com.b44t.messenger.Emoji; import com.b44t.messenger.LocaleController; import com.b44t.messenger.MediaController; import com.b44t.messenger.MessageObject; -import com.b44t.messenger.MessagesController; +import com.b44t.messenger.MrContact; +import com.b44t.messenger.MrMailbox; import com.b44t.messenger.SendMessagesHelper; import com.b44t.messenger.FileLog; import com.b44t.messenger.NotificationCenter; @@ -1384,7 +1385,7 @@ public class ChatActivityEnterView extends FrameLayout implements NotificationCe public void onGifSelected(TLRPC.Document gif) { SendMessagesHelper.getInstance().sendSticker(gif, dialog_id); if ((int) dialog_id == 0) { - MessagesController.getInstance().saveGif(gif); + //MessagesController.getInstance().saveGif(gif); } if (delegate != null) { delegate.onMessageSend(null); @@ -1632,7 +1633,7 @@ public class ChatActivityEnterView extends FrameLayout implements NotificationCe String str = String.format("%02d:%02d.%02d", time / 60, time % 60, ms); if (lastTimeString == null || !lastTimeString.equals(str)) { if (time % 5 == 0) { - MessagesController.getInstance().sendTyping(dialog_id, 1, 0); + MrMailbox.sendTyping(dialog_id, 1, 0); } if (recordTimeText != null) { recordTimeText.setText(str); @@ -1647,7 +1648,7 @@ public class ChatActivityEnterView extends FrameLayout implements NotificationCe } } else if (id == NotificationCenter.recordStartError || id == NotificationCenter.recordStopped) { if (recordingAudio) { - MessagesController.getInstance().sendTyping(dialog_id, 2, 0); + MrMailbox.sendTyping(dialog_id, 2, 0); recordingAudio = false; updateAudioRecordInterface(); } @@ -1668,7 +1669,7 @@ public class ChatActivityEnterView extends FrameLayout implements NotificationCe message.out = true; message.id = 0; message.to_id = new TLRPC.TL_peerUser(); - message.to_id.user_id = message.from_id = UserConfig.getClientUserId(); + message.to_id.user_id = message.from_id = MrContact.MR_CONTACT_ID_SELF; message.date = (int) (System.currentTimeMillis() / 1000); message.message = "-1"; message.attachPath = audioToSendPath; diff --git a/MessengerProj/src/main/java/com/b44t/ui/Components/PasscodeView.java b/MessengerProj/src/main/java/com/b44t/ui/Components/PasscodeView.java index 99d5c0f92..e59fcd554 100644 --- a/MessengerProj/src/main/java/com/b44t/ui/Components/PasscodeView.java +++ b/MessengerProj/src/main/java/com/b44t/ui/Components/PasscodeView.java @@ -434,7 +434,7 @@ public class PasscodeView extends FrameLayout { AnimatorSet.start(); UserConfig.appLocked = false; - UserConfig.saveConfig(false); + UserConfig.saveConfig(); NotificationCenter.getInstance().postNotificationName(NotificationCenter.didSetPasscode); setOnTouchListener(null); if (delegate != null) { diff --git a/MessengerProj/src/main/java/com/b44t/ui/Components/StickersAlert.java b/MessengerProj/src/main/java/com/b44t/ui/Components/StickersAlert.java index 03b9f7aff..8b206fd60 100644 --- a/MessengerProj/src/main/java/com/b44t/ui/Components/StickersAlert.java +++ b/MessengerProj/src/main/java/com/b44t/ui/Components/StickersAlert.java @@ -46,13 +46,11 @@ import android.widget.TextView; import com.b44t.messenger.AndroidUtilities; import com.b44t.messenger.AnimatorListenerAdapterProxy; import com.b44t.messenger.ApplicationLoader; -import com.b44t.messenger.Emoji; import com.b44t.messenger.LocaleController; import com.b44t.messenger.NotificationCenter; import com.b44t.messenger.R; import com.b44t.messenger.support.widget.GridLayoutManager; import com.b44t.messenger.support.widget.RecyclerView; -import com.b44t.messenger.ConnectionsManager; import com.b44t.messenger.TLRPC; import com.b44t.ui.ActionBar.BottomSheet; import com.b44t.ui.ActionBar.Theme; diff --git a/MessengerProj/src/main/java/com/b44t/ui/ContactAddActivity.java b/MessengerProj/src/main/java/com/b44t/ui/ContactAddActivity.java index 166d301f5..a06171e9c 100644 --- a/MessengerProj/src/main/java/com/b44t/ui/ContactAddActivity.java +++ b/MessengerProj/src/main/java/com/b44t/ui/ContactAddActivity.java @@ -42,11 +42,9 @@ import android.widget.Toast; import com.b44t.messenger.AndroidUtilities; import com.b44t.messenger.ContactsController; import com.b44t.messenger.LocaleController; -import com.b44t.messenger.MrChat; import com.b44t.messenger.MrContact; import com.b44t.messenger.MrMailbox; import com.b44t.messenger.TLRPC; -import com.b44t.messenger.MessagesController; import com.b44t.messenger.NotificationCenter; import com.b44t.messenger.R; import com.b44t.ui.ActionBar.ActionBar; @@ -160,7 +158,7 @@ public class ContactAddActivity extends BaseFragment implements NotificationCent args.putInt("chat_id", belonging_chat_id); presentFragment(new ChatActivity(args), true); NotificationCenter.getInstance().postNotificationName(NotificationCenter.chatDidCreated, belonging_chat_id); /*this will remove the contact list from stack */ - NotificationCenter.getInstance().postNotificationName(NotificationCenter.updateInterfaces, MessagesController.UPDATE_MASK_NAME); + NotificationCenter.getInstance().postNotificationName(NotificationCenter.updateInterfaces, MrMailbox.UPDATE_MASK_NAME); return; } } @@ -171,7 +169,7 @@ public class ContactAddActivity extends BaseFragment implements NotificationCent } finishFragment(); - NotificationCenter.getInstance().postNotificationName(NotificationCenter.updateInterfaces, MessagesController.UPDATE_MASK_NAME); + NotificationCenter.getInstance().postNotificationName(NotificationCenter.updateInterfaces, MrMailbox.UPDATE_MASK_NAME); } } }); @@ -392,14 +390,5 @@ public class ContactAddActivity extends BaseFragment implements NotificationCent @Override public void didReceivedNotification(int id, final Object... args) { - if (id == NotificationCenter.updateInterfaces) { - int mask = (Integer)args[0]; - if ((mask & MessagesController.UPDATE_MASK_AVATAR) != 0 || (mask & MessagesController.UPDATE_MASK_NAME) != 0 || (mask & MessagesController.UPDATE_MASK_STATUS) != 0) { - updateVisibleRows(mask); - } - } - } - - private void updateVisibleRows(int mask) { } } diff --git a/MessengerProj/src/main/java/com/b44t/ui/ContactsActivity.java b/MessengerProj/src/main/java/com/b44t/ui/ContactsActivity.java index 531f82272..f9be7ba73 100644 --- a/MessengerProj/src/main/java/com/b44t/ui/ContactsActivity.java +++ b/MessengerProj/src/main/java/com/b44t/ui/ContactsActivity.java @@ -63,7 +63,6 @@ import com.b44t.messenger.MrMailbox; import com.b44t.messenger.Utilities; import com.b44t.messenger.TLRPC; import com.b44t.messenger.FileLog; -import com.b44t.messenger.MessagesController; import com.b44t.messenger.NotificationCenter; import com.b44t.messenger.R; import com.b44t.ui.Adapters.ContactsAdapter; @@ -576,8 +575,8 @@ public class ContactsActivity extends BaseFragment implements NotificationCenter } } else if (id == NotificationCenter.updateInterfaces) { int mask = (Integer)args[0]; - if ((mask & MessagesController.UPDATE_MASK_AVATAR) != 0 || (mask & MessagesController.UPDATE_MASK_NAME) != 0 || (mask & MessagesController.UPDATE_MASK_STATUS) != 0) { - updateVisibleRows(mask); + if ((mask & MrMailbox.UPDATE_MASK_AVATAR) != 0 || (mask & MrMailbox.UPDATE_MASK_NAME) != 0 || (mask & MrMailbox.UPDATE_MASK_STATUS) != 0) { + updateVisibleRows(); } } else if (id == NotificationCenter.closeChats) { removeSelfFromStack(); @@ -586,13 +585,13 @@ public class ContactsActivity extends BaseFragment implements NotificationCenter } } - private void updateVisibleRows(int mask) { + private void updateVisibleRows() { if (listView != null) { int count = listView.getChildCount(); for (int a = 0; a < count; a++) { View child = listView.getChildAt(a); if (child instanceof UserCell) { - ((UserCell) child).update(mask); + ((UserCell) child).update(); } } } diff --git a/MessengerProj/src/main/java/com/b44t/ui/DialogsActivity.java b/MessengerProj/src/main/java/com/b44t/ui/DialogsActivity.java index fd89d9984..f6a05dcea 100644 --- a/MessengerProj/src/main/java/com/b44t/ui/DialogsActivity.java +++ b/MessengerProj/src/main/java/com/b44t/ui/DialogsActivity.java @@ -62,7 +62,6 @@ import com.b44t.messenger.Utilities; import com.b44t.messenger.support.widget.LinearLayoutManager; import com.b44t.messenger.support.widget.RecyclerView; import com.b44t.messenger.FileLog; -import com.b44t.messenger.MessagesController; import com.b44t.messenger.NotificationCenter; import com.b44t.messenger.R; import com.b44t.messenger.UserConfig; @@ -278,7 +277,7 @@ public class DialogsActivity extends BaseFragment implements NotificationCenter. listView.setVisibility(View.INVISIBLE); UserConfig.appLocked = !UserConfig.appLocked; - UserConfig.saveConfig(false); + UserConfig.saveConfig(); if( UserConfig.appLocked ) { // hide list as it is visible in the "last app switcher" otherwise, save state @@ -372,7 +371,7 @@ public class DialogsActivity extends BaseFragment implements NotificationCenter. } if (dialogsAdapter != null) { dialogsAdapter.setOpenedDialogId(openedDialogId = dialog_id); - updateVisibleRows(MessagesController.UPDATE_MASK_SELECT_DIALOG); + updateVisibleRows(MrMailbox.UPDATE_MASK_SELECT_DIALOG); } } @@ -596,7 +595,7 @@ public class DialogsActivity extends BaseFragment implements NotificationCenter. if (dialogsAdapter.isDataSetChanged()) { dialogsAdapter.notifyDataSetChanged(); } else { - updateVisibleRows(MessagesController.UPDATE_MASK_NEW_MESSAGE); + updateVisibleRows(MrMailbox.UPDATE_MASK_NEW_MESSAGE); } */ } @@ -646,12 +645,12 @@ public class DialogsActivity extends BaseFragment implements NotificationCenter. if (dialogsAdapter != null) { dialogsAdapter.setOpenedDialogId(openedDialogId); } - updateVisibleRows(MessagesController.UPDATE_MASK_SELECT_DIALOG); + updateVisibleRows(MrMailbox.UPDATE_MASK_SELECT_DIALOG); } } else if (id == NotificationCenter.notificationsSettingsUpdated) { updateVisibleRows(0); } else if ( id == NotificationCenter.messageSendError) { - updateVisibleRows(MessagesController.UPDATE_MASK_SEND_STATE); + updateVisibleRows(MrMailbox.UPDATE_MASK_SEND_STATE); } else if (id == NotificationCenter.didSetPasscode) { updatePasscodeButton(); } @@ -694,12 +693,12 @@ public class DialogsActivity extends BaseFragment implements NotificationCenter. if (child instanceof DialogCell) { if (listView.getAdapter() != dialogsSearchAdapter) { DialogCell cell = (DialogCell) child; - if ((mask & MessagesController.UPDATE_MASK_NEW_MESSAGE) != 0) { + if ((mask & MrMailbox.UPDATE_MASK_NEW_MESSAGE) != 0) { cell.checkCurrentDialogIndex(); if ( AndroidUtilities.isTablet()) { cell.setDialogSelected(cell.getDialogId() == openedDialogId); } - } else if ((mask & MessagesController.UPDATE_MASK_SELECT_DIALOG) != 0) { + } else if ((mask & MrMailbox.UPDATE_MASK_SELECT_DIALOG) != 0) { if ( AndroidUtilities.isTablet()) { cell.setDialogSelected(cell.getDialogId() == openedDialogId); } @@ -708,7 +707,7 @@ public class DialogsActivity extends BaseFragment implements NotificationCenter. } } } else if (child instanceof UserCell) { - ((UserCell) child).update(mask); + ((UserCell) child).update(); } } } diff --git a/MessengerProj/src/main/java/com/b44t/ui/GroupCreateFinalActivity.java b/MessengerProj/src/main/java/com/b44t/ui/GroupCreateFinalActivity.java index 22dba6831..0e269a307 100644 --- a/MessengerProj/src/main/java/com/b44t/ui/GroupCreateFinalActivity.java +++ b/MessengerProj/src/main/java/com/b44t/ui/GroupCreateFinalActivity.java @@ -23,9 +23,7 @@ package com.b44t.ui; -import android.app.AlertDialog; import android.content.Context; -import android.content.DialogInterface; import android.content.Intent; import android.os.Bundle; import android.text.Editable; @@ -49,7 +47,6 @@ import com.b44t.messenger.LocaleController; import com.b44t.messenger.MrContact; import com.b44t.messenger.MrMailbox; import com.b44t.messenger.TLRPC; -import com.b44t.messenger.MessagesController; import com.b44t.messenger.NotificationCenter; import com.b44t.messenger.R; import com.b44t.ui.Adapters.BaseFragmentAdapter; @@ -151,7 +148,7 @@ public class GroupCreateFinalActivity extends BaseFragment implements Notificati args2.putInt("chat_id", chat_id); presentFragment(new ChatActivity(args2), true); if (uploadedAvatar != null) { - MessagesController.getInstance().changeChatAvatar(chat_id, uploadedAvatar); + //MessagesController.getInstance().changeChatAvatar(chat_id, uploadedAvatar); } } } @@ -360,13 +357,13 @@ public class GroupCreateFinalActivity extends BaseFragment implements Notificati public void didReceivedNotification(int id, final Object... args) { if (id == NotificationCenter.updateInterfaces) { int mask = (Integer)args[0]; - if ((mask & MessagesController.UPDATE_MASK_AVATAR) != 0 || (mask & MessagesController.UPDATE_MASK_NAME) != 0 || (mask & MessagesController.UPDATE_MASK_STATUS) != 0) { - updateVisibleRows(mask); + if ((mask & MrMailbox.UPDATE_MASK_AVATAR) != 0 || (mask & MrMailbox.UPDATE_MASK_NAME) != 0 || (mask & MrMailbox.UPDATE_MASK_STATUS) != 0) { + updateVisibleRows(); } } } - private void updateVisibleRows(int mask) { + private void updateVisibleRows() { if (listView == null) { return; } @@ -374,7 +371,7 @@ public class GroupCreateFinalActivity extends BaseFragment implements Notificati for (int a = 0; a < count; a++) { View child = listView.getChildAt(a); if (child instanceof UserCell) { - ((UserCell) child).update(mask); + ((UserCell) child).update(); } } } diff --git a/MessengerProj/src/main/java/com/b44t/ui/LaunchActivity.java b/MessengerProj/src/main/java/com/b44t/ui/LaunchActivity.java index d91e05fc6..cd29f1ddb 100644 --- a/MessengerProj/src/main/java/com/b44t/ui/LaunchActivity.java +++ b/MessengerProj/src/main/java/com/b44t/ui/LaunchActivity.java @@ -69,7 +69,6 @@ import com.b44t.messenger.LocaleController; import com.b44t.messenger.NotificationCenter; import com.b44t.messenger.R; import com.b44t.messenger.browser.Browser; -import com.b44t.messenger.ConnectionsManager; import com.b44t.messenger.UserConfig; import com.b44t.ui.Adapters.DrawerLayoutAdapter; import com.b44t.ui.ActionBar.ActionBarLayout; @@ -96,7 +95,6 @@ public class LaunchActivity extends Activity implements ActionBarLayout.ActionBa private String documentsMimeType; private ArrayList documentsOriginalPathsArray; private ArrayList contactsToSend; - private int currentConnectionState; private static ArrayList mainFragmentsStack = new ArrayList<>(); private static ArrayList layerFragmentsStack = new ArrayList<>(); private static ArrayList rightFragmentsStack = new ArrayList<>(); @@ -166,7 +164,7 @@ public class LaunchActivity extends Activity implements ActionBarLayout.ActionBa Theme.loadRecources(this); if (UserConfig.passcodeHash.length() != 0 && UserConfig.appLocked) { - UserConfig.lastPauseTime = ConnectionsManager.getInstance().getCurrentTime(); + UserConfig.lastPauseTime = MrMailbox.getCurrentTime(); } int resourceId = getResources().getIdentifier("status_bar_height", "dimen", "android"); @@ -364,7 +362,6 @@ public class LaunchActivity extends Activity implements ActionBarLayout.ActionBa passcodeView.setLayoutParams(layoutParams1); NotificationCenter.getInstance().postNotificationName(NotificationCenter.closeOtherAppActivities, this); - currentConnectionState = ConnectionsManager.getInstance().getConnectionState(); NotificationCenter.getInstance().addObserver(this, NotificationCenter.mainUserInfoChanged); NotificationCenter.getInstance().addObserver(this, NotificationCenter.closeOtherAppActivities); @@ -499,7 +496,7 @@ public class LaunchActivity extends Activity implements ActionBarLayout.ActionBa passcodeSaveIntent = intent; passcodeSaveIntentIsNew = isNew; passcodeSaveIntentIsRestore = restore; - UserConfig.saveConfig(false); + UserConfig.saveConfig(); } else { boolean pushOpened = false; @@ -1215,7 +1212,7 @@ public class LaunchActivity extends Activity implements ActionBarLayout.ActionBa protected void onActivityResult(int requestCode, int resultCode, Intent data) { if (UserConfig.passcodeHash.length() != 0 && UserConfig.lastPauseTime != 0) { UserConfig.lastPauseTime = 0; - UserConfig.saveConfig(false); + UserConfig.saveConfig(); } super.onActivityResult(requestCode, resultCode, data); if (actionBarLayout.fragmentsStack.size() != 0) { @@ -1382,7 +1379,6 @@ public class LaunchActivity extends Activity implements ActionBarLayout.ActionBa passcodeView.onResume(); } ContactsController.cleanupAvatarCache(); - updateCurrentConnectionState(); if (PhotoViewer.getInstance().isVisible()) { PhotoViewer.getInstance().onResume(); } @@ -1414,7 +1410,7 @@ public class LaunchActivity extends Activity implements ActionBarLayout.ActionBa lockRunnable = null; } if (UserConfig.passcodeHash.length() != 0) { - UserConfig.lastPauseTime = ConnectionsManager.getInstance().getCurrentTime(); + UserConfig.lastPauseTime = MrMailbox.getCurrentTime(); lockRunnable = new Runnable() { @Override public void run() { @@ -1437,7 +1433,7 @@ public class LaunchActivity extends Activity implements ActionBarLayout.ActionBa } else { UserConfig.lastPauseTime = 0; } - UserConfig.saveConfig(false); + UserConfig.saveConfig(); } private void onPasscodeResume() { @@ -1450,22 +1446,10 @@ public class LaunchActivity extends Activity implements ActionBarLayout.ActionBa } if (UserConfig.lastPauseTime != 0) { UserConfig.lastPauseTime = 0; - UserConfig.saveConfig(false); + UserConfig.saveConfig(); } } - private void updateCurrentConnectionState() { - String text = null; - if (currentConnectionState == ConnectionsManager.ConnectionStateWaitingForNetwork) { - text = LocaleController.getString("WaitingForNetwork", R.string.WaitingForNetwork); - } else if (currentConnectionState == ConnectionsManager.ConnectionStateConnecting) { - text = LocaleController.getString("Connecting", R.string.Connecting); - } else if (currentConnectionState == ConnectionsManager.ConnectionStateUpdating) { - text = LocaleController.getString("Updating", R.string.Updating); - } - actionBarLayout.setTitleOverlayText(text); - } - @Override protected void onSaveInstanceState(Bundle outState) { try { diff --git a/MessengerProj/src/main/java/com/b44t/ui/ManageSpaceActivity.java b/MessengerProj/src/main/java/com/b44t/ui/ManageSpaceActivity.java index 6f93b4495..676de7326 100644 --- a/MessengerProj/src/main/java/com/b44t/ui/ManageSpaceActivity.java +++ b/MessengerProj/src/main/java/com/b44t/ui/ManageSpaceActivity.java @@ -41,10 +41,8 @@ import android.widget.RelativeLayout; import com.b44t.messenger.AndroidUtilities; import com.b44t.messenger.ApplicationLoader; -import com.b44t.messenger.LocaleController; import com.b44t.messenger.NotificationCenter; import com.b44t.messenger.R; -import com.b44t.messenger.ConnectionsManager; import com.b44t.ui.ActionBar.ActionBarLayout; import com.b44t.ui.ActionBar.BaseFragment; import com.b44t.ui.ActionBar.DrawerLayoutContainer; @@ -56,7 +54,6 @@ import java.util.ArrayList; public class ManageSpaceActivity extends Activity implements ActionBarLayout.ActionBarLayoutDelegate { private boolean finished; - private int currentConnectionState; private static ArrayList mainFragmentsStack = new ArrayList<>(); private static ArrayList layerFragmentsStack = new ArrayList<>(); @@ -180,7 +177,6 @@ public class ManageSpaceActivity extends Activity implements ActionBarLayout.Act actionBarLayout.setDelegate(this); NotificationCenter.getInstance().postNotificationName(NotificationCenter.closeOtherAppActivities, this); - currentConnectionState = ConnectionsManager.getInstance().getConnectionState(); handleIntent(getIntent(), false, savedInstanceState != null, false); needLayout(); @@ -318,18 +314,6 @@ public class ManageSpaceActivity extends Activity implements ActionBarLayout.Act fixLayout(); } - private void updateCurrentConnectionState() { - String text = null; - if (currentConnectionState == ConnectionsManager.ConnectionStateWaitingForNetwork) { - text = LocaleController.getString("WaitingForNetwork", R.string.WaitingForNetwork); - } else if (currentConnectionState == ConnectionsManager.ConnectionStateConnecting) { - text = LocaleController.getString("Connecting", R.string.Connecting); - } else if (currentConnectionState == ConnectionsManager.ConnectionStateUpdating) { - text = LocaleController.getString("Updating", R.string.Updating); - } - actionBarLayout.setTitleOverlayText(text); - } - @Override public void onBackPressed() { if (PhotoViewer.getInstance().isVisible()) { diff --git a/MessengerProj/src/main/java/com/b44t/ui/NotificationsSettingsActivity.java b/MessengerProj/src/main/java/com/b44t/ui/NotificationsSettingsActivity.java index b99482aa7..f2f19a984 100644 --- a/MessengerProj/src/main/java/com/b44t/ui/NotificationsSettingsActivity.java +++ b/MessengerProj/src/main/java/com/b44t/ui/NotificationsSettingsActivity.java @@ -46,7 +46,6 @@ import com.b44t.messenger.LocaleController; import com.b44t.messenger.NotificationsController; import com.b44t.messenger.NotificationCenter; import com.b44t.messenger.ApplicationLoader; -import com.b44t.messenger.ConnectionsManager; import com.b44t.messenger.FileLog; import com.b44t.messenger.R; import com.b44t.ui.Adapters.BaseFragmentAdapter; @@ -295,19 +294,6 @@ public class NotificationsSettingsActivity extends BaseFragment implements Notif editor.apply(); NotificationsController.getInstance().setBadgeEnabled(!enabled); } - /*else if (i == notificationsServiceConnectionRow) { - // background connection option - SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("Notifications", Activity.MODE_PRIVATE); - enabled = preferences.getBoolean("pushConnection", true); - SharedPreferences.Editor editor = preferences.edit(); - editor.putBoolean("pushConnection", !enabled); - editor.apply(); - if (!enabled) { - ConnectionsManager.getInstance().setPushConnectionEnabled(true); - } else { - ConnectionsManager.getInstance().setPushConnectionEnabled(false); - } - }*/ else if (i == notificationsServiceRow) { // keep-alive service option final SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("Notifications", Activity.MODE_PRIVATE); diff --git a/MessengerProj/src/main/java/com/b44t/ui/PasscodeActivity.java b/MessengerProj/src/main/java/com/b44t/ui/PasscodeActivity.java index bf5a9ffd4..c33fe13f7 100644 --- a/MessengerProj/src/main/java/com/b44t/ui/PasscodeActivity.java +++ b/MessengerProj/src/main/java/com/b44t/ui/PasscodeActivity.java @@ -331,7 +331,7 @@ public class PasscodeActivity extends BaseFragment implements NotificationCenter if (UserConfig.passcodeHash.length() != 0) { UserConfig.passcodeHash = ""; UserConfig.appLocked = false; - UserConfig.saveConfig(false); + UserConfig.saveConfig(); int count = listView.getChildCount(); for (int a = 0; a < count; a++) { View child = listView.getChildAt(a); @@ -401,13 +401,13 @@ public class PasscodeActivity extends BaseFragment implements NotificationCenter UserConfig.autoLockIn = 60 * 60 * 5; } listView.invalidateViews(); - UserConfig.saveConfig(false); + UserConfig.saveConfig(); } }); showDialog(builder.create()); } else if (i == fingerprintRow) { UserConfig.useFingerprint = !UserConfig.useFingerprint; - UserConfig.saveConfig(false); + UserConfig.saveConfig(); ((TextCheckCell) view).setChecked(UserConfig.useFingerprint); } } @@ -567,7 +567,7 @@ public class PasscodeActivity extends BaseFragment implements NotificationCenter } UserConfig.passcodeType = currentPasswordType; - UserConfig.saveConfig(false); + UserConfig.saveConfig(); finishFragment(); NotificationCenter.getInstance().postNotificationName(NotificationCenter.didSetPasscode); passwordEditText.clearFocus(); diff --git a/MessengerProj/src/main/java/com/b44t/ui/PhotoViewer.java b/MessengerProj/src/main/java/com/b44t/ui/PhotoViewer.java index 6038090d4..97dc1ca02 100644 --- a/MessengerProj/src/main/java/com/b44t/ui/PhotoViewer.java +++ b/MessengerProj/src/main/java/com/b44t/ui/PhotoViewer.java @@ -78,7 +78,6 @@ import com.b44t.messenger.LocaleController; import com.b44t.messenger.MediaController; import com.b44t.messenger.NotificationCenter; import com.b44t.messenger.R; -import com.b44t.messenger.ConnectionsManager; import com.b44t.messenger.TLRPC; import com.b44t.messenger.MessageObject; import com.b44t.messenger.Utilities; @@ -2327,7 +2326,7 @@ public class PhotoViewer implements NotificationCenter.NotificationCenterDelegat } private void onPhotoShow(final MessageObject messageObject, final TLRPC.FileLocation fileLocation, final ArrayList messages, final ArrayList photos, int index, final PlaceProviderObject object) { - classGuid = ConnectionsManager.getInstance().generateClassGuid(); + classGuid = ApplicationLoader.generateClassGuid(); currentMessageObject = null; currentFileLocation = null; currentPathObject = null; @@ -2577,13 +2576,6 @@ public class PhotoViewer implements NotificationCenter.NotificationCenterDelegat } else if (!imagesArrLocations.isEmpty()) { nameTextView.setText(""); dateTextView.setText(""); - /* - if (avatarsDialogId == UserConfig.getClientUserId() && !avatarsArr.isEmpty()) { - menuItem.showSubItem(gallery_menu_delete); - } else { - menuItem.hideSubItem(gallery_menu_delete); - } - */ TLRPC.FileLocation old = currentFileLocation; if (index < 0 || index >= imagesArrLocations.size()) { closePhoto(false, false); @@ -2603,11 +2595,9 @@ public class PhotoViewer implements NotificationCenter.NotificationCenterDelegat return; } boolean fromCamera = false; - CharSequence caption = null; if (object instanceof MediaController.PhotoEntry) { currentPathObject = ((MediaController.PhotoEntry) object).path; fromCamera = ((MediaController.PhotoEntry) object).bucketId == 0 && ((MediaController.PhotoEntry) object).dateTaken == 0 && imagesArrLocals.size() == 1; - caption = ((MediaController.PhotoEntry) object).caption; } else if (object instanceof MediaController.SearchImage) { MediaController.SearchImage searchImage = (MediaController.SearchImage) object; if (searchImage.document != null) { @@ -2615,7 +2605,6 @@ public class PhotoViewer implements NotificationCenter.NotificationCenterDelegat } else { currentPathObject = searchImage.imageUrl; } - caption = searchImage.caption; } if (fromCamera) { actionBar.setTitle(LocaleController.getString("AttachPhoto", R.string.AttachPhoto)); diff --git a/MessengerProj/src/main/java/com/b44t/ui/ProfileActivity.java b/MessengerProj/src/main/java/com/b44t/ui/ProfileActivity.java index c90abb470..e3a119853 100644 --- a/MessengerProj/src/main/java/com/b44t/ui/ProfileActivity.java +++ b/MessengerProj/src/main/java/com/b44t/ui/ProfileActivity.java @@ -65,7 +65,6 @@ import com.b44t.messenger.support.widget.RecyclerView; import com.b44t.messenger.TLRPC; import com.b44t.messenger.FileLog; -import com.b44t.messenger.MessagesController; import com.b44t.messenger.NotificationCenter; import com.b44t.messenger.R; import com.b44t.messenger.MessageObject; @@ -190,7 +189,7 @@ public class ProfileActivity extends BaseFragment implements NotificationCenter. if (user_id != 0) { dialog_id = arguments.getLong("dialog_id", 0); - TLRPC.User user = MessagesController.getInstance().getUser(user_id); + TLRPC.User user = MrMailbox.getUser(user_id); if (user == null) { return false; } @@ -205,7 +204,7 @@ public class ProfileActivity extends BaseFragment implements NotificationCenter. @Override public void didUploadedPhoto(TLRPC.InputFile file, TLRPC.PhotoSize small, TLRPC.PhotoSize big) { if (chat_id != 0) { - MessagesController.getInstance().changeChatAvatar(chat_id, file); + //MessagesController.getInstance().changeChatAvatar(chat_id, file); } } }; @@ -454,7 +453,7 @@ public class ProfileActivity extends BaseFragment implements NotificationCenter. @Override public void onClick(DialogInterface dialogInterface, int i) { MrMailbox.addContactToChat(chat_id, added_user_id); - NotificationCenter.getInstance().postNotificationName(NotificationCenter.updateInterfaces, MessagesController.UPDATE_MASK_CHAT_MEMBERS); + NotificationCenter.getInstance().postNotificationName(NotificationCenter.updateInterfaces, MrMailbox.UPDATE_MASK_CHAT_MEMBERS); } }); builder.setNegativeButton(ApplicationLoader.applicationContext.getString(R.string.Cancel), null); @@ -501,7 +500,7 @@ public class ProfileActivity extends BaseFragment implements NotificationCenter. @Override public void onClick(DialogInterface dialogInterface, int i) { MrMailbox.removeContactFromChat(chat_id, curr_user_id); - NotificationCenter.getInstance().postNotificationName(NotificationCenter.updateInterfaces, MessagesController.UPDATE_MASK_CHAT_MEMBERS); + NotificationCenter.getInstance().postNotificationName(NotificationCenter.updateInterfaces, MrMailbox.UPDATE_MASK_CHAT_MEMBERS); } }); builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null); @@ -537,7 +536,7 @@ public class ProfileActivity extends BaseFragment implements NotificationCenter. @Override public void onClick(View v) { if (user_id != 0) { - TLRPC.User user = MessagesController.getInstance().getUser(user_id); + TLRPC.User user = MrMailbox.getUser(user_id); if (user.photo != null && user.photo.photo_big != null) { PhotoViewer.getInstance().setParentActivity(getParentActivity()); PhotoViewer.getInstance().openPhoto(user.photo.photo_big, ProfileActivity.this); @@ -821,7 +820,7 @@ public class ProfileActivity extends BaseFragment implements NotificationCenter. if (id == NotificationCenter.updateInterfaces) { int mask = (Integer) args[0]; if (user_id != 0) { - if ((mask & MessagesController.UPDATE_MASK_AVATAR) != 0 || (mask & MessagesController.UPDATE_MASK_NAME) != 0 || (mask & MessagesController.UPDATE_MASK_STATUS) != 0) { + if ((mask & MrMailbox.UPDATE_MASK_AVATAR) != 0 || (mask & MrMailbox.UPDATE_MASK_NAME) != 0 || (mask & MrMailbox.UPDATE_MASK_STATUS) != 0) { updateProfileData(); } } else if (chat_id != 0) { @@ -830,13 +829,13 @@ public class ProfileActivity extends BaseFragment implements NotificationCenter. updateProfileData(); listAdapter.notifyDataSetChanged(); - if ((mask & MessagesController.UPDATE_MASK_AVATAR) != 0 || (mask & MessagesController.UPDATE_MASK_NAME) != 0 || (mask & MessagesController.UPDATE_MASK_STATUS) != 0) { + if ((mask & MrMailbox.UPDATE_MASK_AVATAR) != 0 || (mask & MrMailbox.UPDATE_MASK_NAME) != 0 || (mask & MrMailbox.UPDATE_MASK_STATUS) != 0) { if (listView != null) { int count = listView.getChildCount(); for (int a = 0; a < count; a++) { View child = listView.getChildAt(a); if (child instanceof UserCell) { - ((UserCell) child).update(mask); + ((UserCell) child).update(); } } } @@ -1039,7 +1038,7 @@ public class ProfileActivity extends BaseFragment implements NotificationCenter. TLRPC.FileLocation photoBig = null; if (user_id != 0) { - TLRPC.User user = MessagesController.getInstance().getUser(user_id); + TLRPC.User user = MrMailbox.getUser(user_id); if (user != null && user.photo != null && user.photo.photo_big != null) { photoBig = user.photo.photo_big; } @@ -1184,7 +1183,7 @@ public class ProfileActivity extends BaseFragment implements NotificationCenter. int leftIcon = 0;//currentEncryptedChat != null ? R.drawable.ic_lock_header : 0; int rightIcon = 0; if (a == 0) { - rightIcon = MessagesController.getInstance().isDialogMuted(dialog_id != 0 ? dialog_id : (long) user_id) ? R.drawable.mute_fixed : 0; + rightIcon = MrMailbox.isDialogMuted(dialog_id != 0 ? dialog_id : (long) user_id) ? R.drawable.mute_fixed : 0; } nameTextView[a].setLeftDrawable(leftIcon); nameTextView[a].setRightDrawable(rightIcon); diff --git a/MessengerProj/src/main/java/com/b44t/ui/ProfileNotificationsActivity.java b/MessengerProj/src/main/java/com/b44t/ui/ProfileNotificationsActivity.java index ce811fc8e..c696bad42 100644 --- a/MessengerProj/src/main/java/com/b44t/ui/ProfileNotificationsActivity.java +++ b/MessengerProj/src/main/java/com/b44t/ui/ProfileNotificationsActivity.java @@ -48,13 +48,11 @@ import android.widget.TextView; import com.b44t.messenger.AndroidUtilities; import com.b44t.messenger.MrChat; import com.b44t.messenger.MrMailbox; -import com.b44t.messenger.NotificationsController; import com.b44t.messenger.ApplicationLoader; import com.b44t.messenger.FileLog; import com.b44t.messenger.LocaleController; import com.b44t.messenger.NotificationCenter; import com.b44t.messenger.R; -import com.b44t.messenger.ConnectionsManager; import com.b44t.ui.ActionBar.Theme; import com.b44t.ui.Adapters.BaseFragmentAdapter; import com.b44t.ui.Cells.HeaderCell; @@ -219,7 +217,7 @@ public class ProfileNotificationsActivity extends BaseFragment implements Notifi if (listView != null) { listView.invalidateViews(); } - NotificationsController.updateServerNotificationsSettings(dialog_id); + NotificationCenter.getInstance().postNotificationName(NotificationCenter.notificationsSettingsUpdated); } }); builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null); @@ -576,7 +574,7 @@ public class ProfileNotificationsActivity extends BaseFragment implements Notifi } else if (value == 2) { textCell.setTextAndValue(LocaleController.getString("Notifications", R.string.Notifications), LocaleController.getString("Disabled", R.string.Disabled), true); } else if (value == 3) { - int delta = preferences.getInt("notifyuntil_" + dialog_id, 0) - ConnectionsManager.getInstance().getCurrentTime(); + int delta = preferences.getInt("notifyuntil_" + dialog_id, 0) - MrMailbox.getCurrentTime(); String val; if (delta <= 0) { val = LocaleController.getString("Enabled", R.string.Enabled); diff --git a/MessengerProj/src/main/java/com/b44t/ui/SettingsAdvActivity.java b/MessengerProj/src/main/java/com/b44t/ui/SettingsAdvActivity.java index 694c30d86..9c62fc619 100644 --- a/MessengerProj/src/main/java/com/b44t/ui/SettingsAdvActivity.java +++ b/MessengerProj/src/main/java/com/b44t/ui/SettingsAdvActivity.java @@ -39,7 +39,6 @@ import com.b44t.messenger.AndroidUtilities; import com.b44t.messenger.MediaController; import com.b44t.messenger.ApplicationLoader; import com.b44t.messenger.LocaleController; -import com.b44t.messenger.MessagesController; import com.b44t.messenger.R; import com.b44t.ui.Adapters.BaseFragmentAdapter; import com.b44t.ui.Cells.ShadowSectionCell; @@ -148,7 +147,7 @@ public class SettingsAdvActivity extends BaseFragment { numberPicker.setMaxValue(MAX_VAL); numberPicker.setDisplayedValues(displayValues); numberPicker.setWrapSelectorWheel(false); - numberPicker.setValue(MessagesController.getInstance().fontSize); + numberPicker.setValue(ApplicationLoader.fontSize); builder.setView(numberPicker); builder.setNegativeButton(LocaleController.getString("Done", R.string.Done), new DialogInterface.OnClickListener() { @Override @@ -156,7 +155,7 @@ public class SettingsAdvActivity extends BaseFragment { SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("mainconfig", Activity.MODE_PRIVATE); SharedPreferences.Editor editor = preferences.edit(); editor.putInt("msg_font_size", numberPicker.getValue()); - MessagesController.getInstance().fontSize = numberPicker.getValue(); + ApplicationLoader.fontSize = numberPicker.getValue(); editor.apply(); if (listView != null) { listView.invalidateViews();