Skip to content

Commit

Permalink
Added option for "only wifi automatic download" in audio and photo se…
Browse files Browse the repository at this point in the history
…ttings (issue #146)
  • Loading branch information
rubenlagus committed Apr 28, 2014
1 parent f9d23e3 commit d96ce3c
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,12 @@
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;
Expand Down Expand Up @@ -893,6 +896,20 @@ public static boolean isNetworkOnline() {
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;
}
Expand Down
5 changes: 5 additions & 0 deletions TMessagesProj/src/main/java/org/telegram/ui/ChatActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -451,6 +451,11 @@ public void run() {
} 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;
}
Expand Down
46 changes: 43 additions & 3 deletions TMessagesProj/src/main/java/org/telegram/ui/SettingsActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -189,9 +191,11 @@ public void run() {
photoDownloadSection = rowCount++;
photoDownloadChatRow = rowCount++;
photoDownloadPrivateRow = rowCount++;
photoDownloadOnlyWifiRow = rowCount++;
audioDownloadSection = rowCount++;
audioDownloadChatRow = rowCount++;
audioDownloadPrivateRow = rowCount++;
audioDownloadOnlyWifiRow = rowCount++;
messagesSectionRow = rowCount++;
textSizeRow = rowCount++;
sendByEnterRow = rowCount++;
Expand Down Expand Up @@ -364,6 +368,24 @@ public void run(TLObject response, TLRPC.TL_error error) {
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);
Expand Down Expand Up @@ -633,8 +655,8 @@ public boolean areAllItemsEnabled() {
@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;
}

Expand Down Expand Up @@ -916,6 +938,24 @@ public void run() {
} 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);
Expand Down Expand Up @@ -1003,7 +1043,7 @@ public int getItemViewType(int i) {
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;
Expand Down
1 change: 1 addition & 0 deletions TMessagesProj/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down

0 comments on commit d96ce3c

Please sign in to comment.