show banner when Over Data/WiFi Settings disable updating from internet

This commit is contained in:
Hans-Christoph Steiner 2021-04-13 16:25:10 +02:00
parent 8773d6205c
commit 908921e978
4 changed files with 82 additions and 16 deletions

View File

@ -253,6 +253,37 @@ public class UpdateService extends JobIntentService {
} }
} }
/**
* Return a {@link List} of all {@link Repo}s that have either a local
* canonical URL or a local mirror URL. These are repos that can be
* updated and used without using the Internet.
*/
public static List<Repo> getLocalRepos(Context context) {
return getLocalRepos(RepoProvider.Helper.all(context));
}
/**
* Return the repos in the {@code repos} {@link List} that have either a
* local canonical URL or a local mirror URL. These are repos that can be
* updated and used without using the Internet.
*/
public static List<Repo> getLocalRepos(List<Repo> repos) {
ArrayList<Repo> localRepos = new ArrayList<>();
for (Repo repo : repos) {
if (isLocalRepoAddress(repo.address)) {
localRepos.add(repo);
} else {
for (String mirrorAddress : repo.getMirrorList()) {
if (isLocalRepoAddress(mirrorAddress)) {
localRepos.add(repo);
break;
}
}
}
}
return localRepos;
}
@Override @Override
public void onCreate() { public void onCreate() {
super.onCreate(); super.onCreate();
@ -405,19 +436,7 @@ public class UpdateService extends JobIntentService {
Utils.debugLog(TAG, "skipping internet check, this is local: " + address); Utils.debugLog(TAG, "skipping internet check, this is local: " + address);
} else if (netState == ConnectivityMonitorService.FLAG_NET_UNAVAILABLE) { } else if (netState == ConnectivityMonitorService.FLAG_NET_UNAVAILABLE) {
// keep track of repos that have a local copy in case internet is not available // keep track of repos that have a local copy in case internet is not available
ArrayList<Repo> localRepos = new ArrayList<>(); List<Repo> localRepos = getLocalRepos(repos);
for (Repo repo : repos) {
if (isLocalRepoAddress(repo.address)) {
localRepos.add(repo);
} else {
for (String mirrorAddress : repo.getMirrorList()) {
if (isLocalRepoAddress(mirrorAddress)) {
localRepos.add(repo);
break;
}
}
}
}
if (localRepos.size() > 0) { if (localRepos.size() > 0) {
repos = localRepos; repos = localRepos;
} else { } else {

View File

@ -4,16 +4,22 @@ import android.content.BroadcastReceiver;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.content.IntentFilter; import android.content.IntentFilter;
import android.content.SharedPreferences;
import android.net.ConnectivityManager; import android.net.ConnectivityManager;
import android.util.AttributeSet; import android.util.AttributeSet;
import android.view.Gravity; import android.view.Gravity;
import android.view.View; import android.view.View;
import org.fdroid.fdroid.Preferences;
import org.fdroid.fdroid.R; import org.fdroid.fdroid.R;
import org.fdroid.fdroid.UpdateService; import org.fdroid.fdroid.UpdateService;
import org.fdroid.fdroid.data.Repo;
import org.fdroid.fdroid.net.ConnectivityMonitorService; import org.fdroid.fdroid.net.ConnectivityMonitorService;
import java.util.List;
import androidx.localbroadcastmanager.content.LocalBroadcastManager; import androidx.localbroadcastmanager.content.LocalBroadcastManager;
import androidx.preference.PreferenceManager;
/** /**
* Banner widget which reflects current status related to repository updates. * Banner widget which reflects current status related to repository updates.
@ -37,6 +43,11 @@ public class StatusBanner extends androidx.appcompat.widget.AppCompatTextView {
private int updateServiceStatus = UpdateService.STATUS_COMPLETE_WITH_CHANGES; private int updateServiceStatus = UpdateService.STATUS_COMPLETE_WITH_CHANGES;
private int networkState = ConnectivityMonitorService.FLAG_NET_NO_LIMIT; private int networkState = ConnectivityMonitorService.FLAG_NET_NO_LIMIT;
private int overDataState;
private int overWiFiState;
private List<Repo> localRepos;
private final SharedPreferences preferences;
public StatusBanner(Context context) { public StatusBanner(Context context) {
this(context, null); this(context, null);
@ -53,6 +64,8 @@ public class StatusBanner extends androidx.appcompat.widget.AppCompatTextView {
setBackgroundColor(0xFF4A4A4A); setBackgroundColor(0xFF4A4A4A);
setGravity(Gravity.CENTER_VERTICAL | Gravity.CENTER_HORIZONTAL); setGravity(Gravity.CENTER_VERTICAL | Gravity.CENTER_HORIZONTAL);
setTextColor(0xFFFFFFFF); setTextColor(0xFFFFFFFF);
preferences = PreferenceManager.getDefaultSharedPreferences(context);
} }
@Override @Override
@ -69,6 +82,11 @@ public class StatusBanner extends androidx.appcompat.widget.AppCompatTextView {
LocalBroadcastManager.getInstance(context).registerReceiver(onRepoFeedback, LocalBroadcastManager.getInstance(context).registerReceiver(onRepoFeedback,
new IntentFilter(UpdateService.LOCAL_ACTION_STATUS)); new IntentFilter(UpdateService.LOCAL_ACTION_STATUS));
overDataState = Preferences.get().getOverData();
overWiFiState = Preferences.get().getOverWifi();
localRepos = UpdateService.getLocalRepos(context);
preferences.registerOnSharedPreferenceChangeListener(dataWifiChangeListener);
setBannerTextAndVisibility(); setBannerTextAndVisibility();
} }
@ -78,6 +96,7 @@ public class StatusBanner extends androidx.appcompat.widget.AppCompatTextView {
Context context = getContext(); Context context = getContext();
LocalBroadcastManager.getInstance(context).unregisterReceiver(onRepoFeedback); LocalBroadcastManager.getInstance(context).unregisterReceiver(onRepoFeedback);
context.unregisterReceiver(onNetworkStateChanged); context.unregisterReceiver(onNetworkStateChanged);
preferences.unregisterOnSharedPreferenceChangeListener(dataWifiChangeListener);
} }
private void setBannerTextAndVisibility() { private void setBannerTextAndVisibility() {
@ -88,6 +107,15 @@ public class StatusBanner extends androidx.appcompat.widget.AppCompatTextView {
|| networkState == ConnectivityMonitorService.FLAG_NET_DEVICE_AP_WITHOUT_INTERNET) { || networkState == ConnectivityMonitorService.FLAG_NET_DEVICE_AP_WITHOUT_INTERNET) {
setText(R.string.banner_no_internet); setText(R.string.banner_no_internet);
setVisibility(View.VISIBLE); setVisibility(View.VISIBLE);
} else if (overDataState == Preferences.OVER_NETWORK_NEVER
&& overWiFiState == Preferences.OVER_NETWORK_NEVER) {
localRepos = UpdateService.getLocalRepos(getContext());
if (localRepos.size() == 0) {
setText(R.string.banner_no_data_or_wifi);
setVisibility(View.VISIBLE);
} else {
setVisibility(View.GONE);
}
} else { } else {
setVisibility(View.GONE); setVisibility(View.GONE);
} }
@ -113,4 +141,16 @@ public class StatusBanner extends androidx.appcompat.widget.AppCompatTextView {
setBannerTextAndVisibility(); setBannerTextAndVisibility();
} }
}; };
private final SharedPreferences.OnSharedPreferenceChangeListener dataWifiChangeListener =
new SharedPreferences.OnSharedPreferenceChangeListener() {
@Override
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
if (key == Preferences.PREF_OVER_DATA || key == Preferences.PREF_OVER_WIFI) {
overDataState = Preferences.get().getOverData();
overWiFiState = Preferences.get().getOverWifi();
setBannerTextAndVisibility();
}
}
};
} }

View File

@ -378,8 +378,12 @@ This often occurs with apps installed via Google Play or other sources, if they
--> -->
<string name="status_download_unknown_size">Downloading\n%2$s from\n%1$s</string> <string name="status_download_unknown_size">Downloading\n%2$s from\n%1$s</string>
<string name="download_404">The requested file was not found.</string> <string name="download_404">The requested file was not found.</string>
<!-- This is a banner title, it should be maximum 30 characters -->
<string name="banner_updating_repositories">Updating repositories</string> <string name="banner_updating_repositories">Updating repositories</string>
<!-- This is a banner title, it should be maximum 30 characters -->
<string name="banner_no_internet">No Internet</string> <string name="banner_no_internet">No Internet</string>
<!-- This is a banner title, it should be maximum 30 characters -->
<string name="banner_no_data_or_wifi">No Data or WiFi enabled</string>
<string name="status_processing_xml_percent">Processing %2$s / %3$s (%4$d%%) from %1$s</string> <string name="status_processing_xml_percent">Processing %2$s / %3$s (%4$d%%) from %1$s</string>
<string name="status_connecting_to_repo">Connecting to\n%1$s</string> <string name="status_connecting_to_repo">Connecting to\n%1$s</string>
<string name="status_inserting_apps">Saving app details</string> <string name="status_inserting_apps">Saving app details</string>

View File

@ -8,21 +8,24 @@ import sys
from xml.etree import ElementTree from xml.etree import ElementTree
maxlengths = { maxlengths = {
"banner_no_data_or_wifi": 30,
"banner_no_internet": 30,
"banner_updating_repositories": 30,
"installing": 50,
"menu_install": 15, "menu_install": 15,
"menu_uninstall": 15, "menu_uninstall": 15,
"installing": 50,
"uninstalling": 50,
"nearby_splash__find_people_button": 30, "nearby_splash__find_people_button": 30,
"nearby_splash__request_permission": 30, "nearby_splash__request_permission": 30,
"swap": 25, "swap": 25,
"swap_nfc_title": 25,
"swap_choose_apps": 25, "swap_choose_apps": 25,
"swap_confirm": 25, "swap_confirm": 25,
"swap_connecting": 25, "swap_connecting": 25,
"swap_nearby": 25, "swap_nearby": 25,
"swap_nfc_title": 25,
"swap_scan_qr": 18, "swap_scan_qr": 18,
"swap_send_fdroid": 18, "swap_send_fdroid": 18,
"swap_success": 25, "swap_success": 25,
"uninstalling": 50,
"update_all": 20, "update_all": 20,
"updates__hide_updateable_apps": 35, "updates__hide_updateable_apps": 35,
"updates__show_updateable_apps": 35, "updates__show_updateable_apps": 35,