diff --git a/TMessagesProj/src/main/java/org/telegram/messenger/ConnectionsManager.java b/TMessagesProj/src/main/java/org/telegram/messenger/ConnectionsManager.java index 2ea99793e..37501da93 100644 --- a/TMessagesProj/src/main/java/org/telegram/messenger/ConnectionsManager.java +++ b/TMessagesProj/src/main/java/org/telegram/messenger/ConnectionsManager.java @@ -16,9 +16,12 @@ import android.net.NetworkInfo; import android.os.Build; import android.util.Base64; +import net.hockeyapp.android.utils.ConnectionManager; + import org.telegram.ui.ApplicationLoader; import java.io.File; +import java.sql.Connection; import java.util.ArrayList; import java.util.Arrays; import java.util.HashMap; @@ -893,6 +896,20 @@ public class ConnectionsManager implements Action.ActionDelegate, TcpConnection. return status; } + public static boolean isConnectionTypeWifi() { + boolean connectionType = false; + try { + ConnectivityManager cm = (ConnectivityManager)ApplicationLoader.applicationContext.getSystemService(Context.CONNECTIVITY_SERVICE); + NetworkInfo mWifi = cm.getNetworkInfo(ConnectivityManager.TYPE_WIFI); + if (mWifi != null && mWifi.isAvailable()) + connectionType = true; + } catch(Exception e) { + FileLog.e("tmessages", e); + return true; + } + return connectionType; + } + public int getCurrentTime() { return (int)(System.currentTimeMillis() / 1000) + timeDifference; } diff --git a/TMessagesProj/src/main/java/org/telegram/ui/ChatActivity.java b/TMessagesProj/src/main/java/org/telegram/ui/ChatActivity.java index 5c9744a2e..805b56bb7 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/ChatActivity.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/ChatActivity.java @@ -451,6 +451,11 @@ public class ChatActivity extends BaseFragment implements SizeNotifierRelativeLa } else { downloadAudios = preferences.getBoolean("audio_download_user", true); } + if (!ConnectionsManager.isConnectionTypeWifi()) { + downloadPhotos = !preferences.getBoolean("photo_only_wifi", false); + downloadAudios = !preferences.getBoolean("audio_only_wifi", false); + } + return true; } diff --git a/TMessagesProj/src/main/java/org/telegram/ui/SettingsActivity.java b/TMessagesProj/src/main/java/org/telegram/ui/SettingsActivity.java index 366b5704a..e0e28e106 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/SettingsActivity.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/SettingsActivity.java @@ -92,9 +92,11 @@ public class SettingsActivity extends BaseFragment implements NotificationCenter private int photoDownloadSection; private int photoDownloadChatRow; private int photoDownloadPrivateRow; + private int photoDownloadOnlyWifiRow; private int audioDownloadSection; private int audioDownloadChatRow; private int audioDownloadPrivateRow; + private int audioDownloadOnlyWifiRow; private int telegramFaqRow; private int languageRow; private int versionSectionRow; @@ -189,9 +191,11 @@ public class SettingsActivity extends BaseFragment implements NotificationCenter photoDownloadSection = rowCount++; photoDownloadChatRow = rowCount++; photoDownloadPrivateRow = rowCount++; + photoDownloadOnlyWifiRow = rowCount++; audioDownloadSection = rowCount++; audioDownloadChatRow = rowCount++; audioDownloadPrivateRow = rowCount++; + audioDownloadOnlyWifiRow = rowCount++; messagesSectionRow = rowCount++; textSizeRow = rowCount++; sendByEnterRow = rowCount++; @@ -364,6 +368,24 @@ public class SettingsActivity extends BaseFragment implements NotificationCenter if (listView != null) { listView.invalidateViews(); } + } else if (i == photoDownloadOnlyWifiRow) { + SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("mainconfig", Activity.MODE_PRIVATE); + boolean value = preferences.getBoolean("photo_only_wifi", false); + SharedPreferences.Editor editor = preferences.edit(); + editor.putBoolean("photo_only_wifi", !value); + editor.commit(); + if (listView != null) { + listView.invalidateViews(); + } + } else if (i == audioDownloadOnlyWifiRow) { + SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("mainconfig", Activity.MODE_PRIVATE); + boolean value = preferences.getBoolean("audio_only_wifi", false); + SharedPreferences.Editor editor = preferences.edit(); + editor.putBoolean("audio_only_wifi", !value); + editor.commit(); + if (listView != null) { + listView.invalidateViews(); + } } else if (i == audioDownloadChatRow) { SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("mainconfig", Activity.MODE_PRIVATE); boolean value = preferences.getBoolean("audio_download_chat", true); @@ -633,8 +655,8 @@ public class SettingsActivity extends BaseFragment implements NotificationCenter @Override public boolean isEnabled(int i) { return i == textSizeRow || i == enableAnimationsRow || i == connectionStateShowRow || i == blockedRow || i == notificationRow || i == backgroundRow || - i == askQuestionRow || i == sendLogsRow || i == sendByEnterRow || i == terminateSessionsRow || i == photoDownloadPrivateRow || - i == photoDownloadChatRow || i == clearLogsRow || i == audioDownloadChatRow || i == audioDownloadPrivateRow || i == languageRow || + i == askQuestionRow || i == sendLogsRow || i == sendByEnterRow || i == terminateSessionsRow || i == photoDownloadPrivateRow || i == audioDownloadOnlyWifiRow || + i == photoDownloadOnlyWifiRow || i == photoDownloadChatRow || i == clearLogsRow || i == audioDownloadChatRow || i == audioDownloadPrivateRow || i == languageRow || i == switchBackendButtonRow || i == telegramFaqRow || i == telegramVersionRow; } @@ -916,6 +938,24 @@ public class SettingsActivity extends BaseFragment implements NotificationCenter } else { checkButton.setImageResource(R.drawable.btn_check_off); } + } else if (i == photoDownloadOnlyWifiRow) { + textView.setText(LocaleController.getString("AutomaticDownloadOnlyWifi", R.string.AutomaticDownloadOnlyWifi)); + divider.setVisibility(View.INVISIBLE); + boolean enabled = preferences.getBoolean("photo_only_wifi", false); + if (enabled) { + checkButton.setImageResource(R.drawable.btn_check_on); + } else { + checkButton.setImageResource(R.drawable.btn_check_off); + } + } else if (i == audioDownloadOnlyWifiRow) { + textView.setText(LocaleController.getString("AutomaticDownloadOnlyWifi", R.string.AutomaticDownloadOnlyWifi)); + divider.setVisibility(View.INVISIBLE); + boolean enabled = preferences.getBoolean("audio_only_wifi", false); + if (enabled) { + checkButton.setImageResource(R.drawable.btn_check_on); + } else { + checkButton.setImageResource(R.drawable.btn_check_off); + } } else if (i == audioDownloadChatRow) { textView.setText(LocaleController.getString("AutomaticPhotoDownloadGroups", R.string.AutomaticPhotoDownloadGroups)); divider.setVisibility(View.VISIBLE); @@ -1003,7 +1043,7 @@ public class SettingsActivity extends BaseFragment implements NotificationCenter return 1; } else if (i == textSizeRow || i == languageRow) { return 5; - } else if (i == enableAnimationsRow || i == connectionStateShowRow|| i == sendByEnterRow || i == photoDownloadChatRow || i == photoDownloadPrivateRow || i == audioDownloadChatRow || i == audioDownloadPrivateRow) { + } else if (i == enableAnimationsRow || i == connectionStateShowRow|| i == sendByEnterRow || i == photoDownloadChatRow || i == photoDownloadPrivateRow || i == audioDownloadChatRow || i == audioDownloadPrivateRow || i == audioDownloadOnlyWifiRow || i == photoDownloadOnlyWifiRow) { return 3; } else if (i == numberRow || i == notificationRow || i == blockedRow || i == backgroundRow || i == askQuestionRow || i == sendLogsRow || i == terminateSessionsRow || i == clearLogsRow || i == switchBackendButtonRow || i == telegramFaqRow || i == telegramVersionRow) { return 2; diff --git a/TMessagesProj/src/main/res/values/strings.xml b/TMessagesProj/src/main/res/values/strings.xml index 0dc936228..ca37bc1a3 100644 --- a/TMessagesProj/src/main/res/values/strings.xml +++ b/TMessagesProj/src/main/res/values/strings.xml @@ -256,6 +256,7 @@ AUTOMATIC AUDIO DOWNLOAD Groups Private Chats + Only with WIFI EVENTS Contact joined Telegram PEBBLE