mirror of
https://github.com/DrKLO/Telegram.git
synced 2024-12-22 22:45:18 +01:00
Added option for "only wifi automatic download" in audio and photo settings (issue #146)
This commit is contained in:
parent
f9d23e3137
commit
d96ce3c140
4 changed files with 66 additions and 3 deletions
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -256,6 +256,7 @@
|
|||
<string name="AutomaticAudioDownload">AUTOMATIC AUDIO DOWNLOAD</string>
|
||||
<string name="AutomaticPhotoDownloadGroups">Groups</string>
|
||||
<string name="AutomaticPhotoDownloadPrivateChats">Private Chats</string>
|
||||
<string name="AutomaticDownloadOnlyWifi">Only with WIFI</string>
|
||||
<string name="Events">EVENTS</string>
|
||||
<string name="ContactJoined">Contact joined Telegram</string>
|
||||
<string name="Pebble">PEBBLE</string>
|
||||
|
|
Loading…
Reference in a new issue