preference for the "name" of the local repo
This name is used in the RepoList, the local repo website title, the Bonjour broadcast, etc. By default, a name is generated using the make and model of the phone plus a random number.
This commit is contained in:
parent
248cefe1f3
commit
b5f7c0a481
@ -37,6 +37,8 @@
|
||||
<string name="local_repo_bonjour">Broadcast Local Repo</string>
|
||||
<string name="local_repo_bonjour_on">Advertise your local repo using Bonjour (mDNS)</string>
|
||||
<string name="local_repo_bonjour_off">Do not advertise your local repo.</string>
|
||||
<string name="local_repo_name">Name of your Local Repo</string>
|
||||
<string name="local_repo_name_summary">The advertised title of your local repo: %s</string>
|
||||
|
||||
<string name="search_results">Search Results</string>
|
||||
<string name="app_details">App Details</string>
|
||||
|
@ -48,6 +48,9 @@
|
||||
android:defaultValue="true"
|
||||
android:key="localRepoBonjour"
|
||||
android:title="@string/local_repo_bonjour" />
|
||||
<EditTextPreference
|
||||
android:key="localRepoName"
|
||||
android:title="@string/local_repo_name" />
|
||||
</PreferenceCategory>
|
||||
<PreferenceCategory android:title="@string/other">
|
||||
<CheckBoxPreference android:title="@string/cache_downloaded"
|
||||
|
@ -4,6 +4,7 @@ import java.util.*;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import android.os.Build;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.util.Log;
|
||||
|
||||
@ -21,6 +22,11 @@ public class Preferences implements SharedPreferences.OnSharedPreferenceChangeLi
|
||||
private Preferences(Context context) {
|
||||
preferences = PreferenceManager.getDefaultSharedPreferences(context);
|
||||
preferences.registerOnSharedPreferenceChangeListener(this);
|
||||
if (preferences.getString(PREF_LOCAL_REPO_NAME, null) == null) {
|
||||
preferences.edit()
|
||||
.putString(PREF_LOCAL_REPO_NAME, getDefaultLocalRepoName())
|
||||
.commit();
|
||||
}
|
||||
}
|
||||
|
||||
public static final String PREF_UPD_INTERVAL = "updateInterval";
|
||||
@ -39,6 +45,7 @@ public class Preferences implements SharedPreferences.OnSharedPreferenceChangeLi
|
||||
public static final String PREF_ROOT_INSTALLER = "rootInstaller";
|
||||
public static final String PREF_SYSTEM_INSTALLER = "systemInstaller";
|
||||
public static final String PREF_LOCAL_REPO_BONJOUR = "localRepoBonjour";
|
||||
public static final String PREF_LOCAL_REPO_NAME = "localRepoName";
|
||||
|
||||
private static final boolean DEFAULT_COMPACT_LAYOUT = false;
|
||||
private static final boolean DEFAULT_ROOTED = true;
|
||||
@ -56,6 +63,7 @@ public class Preferences implements SharedPreferences.OnSharedPreferenceChangeLi
|
||||
private List<ChangeListener> filterAppsRequiringRootListeners = new ArrayList<ChangeListener>();
|
||||
private List<ChangeListener> updateHistoryListeners = new ArrayList<ChangeListener>();
|
||||
private List<ChangeListener> localRepoBonjourListeners = new ArrayList<ChangeListener>();
|
||||
private List<ChangeListener> localRepoNameListeners = new ArrayList<ChangeListener>();
|
||||
|
||||
private boolean isInitialized(String key) {
|
||||
return initialized.containsKey(key) && initialized.get(key);
|
||||
@ -81,6 +89,15 @@ public class Preferences implements SharedPreferences.OnSharedPreferenceChangeLi
|
||||
return preferences.getBoolean(PREF_LOCAL_REPO_BONJOUR, DEFAULT_LOCAL_REPO_BONJOUR);
|
||||
}
|
||||
|
||||
private String getDefaultLocalRepoName() {
|
||||
return (Build.BRAND + " " + Build.MODEL + String.valueOf(new Random().nextInt(9999)))
|
||||
.replaceAll(" ", "-");
|
||||
}
|
||||
|
||||
public String getLocalRepoName() {
|
||||
return preferences.getString(PREF_LOCAL_REPO_NAME, getDefaultLocalRepoName());
|
||||
}
|
||||
|
||||
public boolean hasCompactLayout() {
|
||||
if (!isInitialized(PREF_COMPACT_LAYOUT)) {
|
||||
initialize(PREF_COMPACT_LAYOUT);
|
||||
@ -157,6 +174,10 @@ public class Preferences implements SharedPreferences.OnSharedPreferenceChangeLi
|
||||
for ( ChangeListener listener : localRepoBonjourListeners ) {
|
||||
listener.onPreferenceChange();
|
||||
}
|
||||
} else if (key.equals(PREF_LOCAL_REPO_NAME)) {
|
||||
for ( ChangeListener listener : localRepoNameListeners ) {
|
||||
listener.onPreferenceChange();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -176,6 +197,14 @@ public class Preferences implements SharedPreferences.OnSharedPreferenceChangeLi
|
||||
localRepoBonjourListeners.remove(listener);
|
||||
}
|
||||
|
||||
public void registerLocalRepoNameListeners(ChangeListener listener) {
|
||||
localRepoNameListeners.add(listener);
|
||||
}
|
||||
|
||||
public void unregisterLocalRepoNameListeners(ChangeListener listener) {
|
||||
localRepoNameListeners.remove(listener);
|
||||
}
|
||||
|
||||
public static interface ChangeListener {
|
||||
public void onPreferenceChange();
|
||||
}
|
||||
|
@ -55,6 +55,7 @@ public class PreferencesActivity extends PreferenceActivity implements
|
||||
Preferences.PREF_COMPACT_LAYOUT,
|
||||
Preferences.PREF_IGN_TOUCH,
|
||||
Preferences.PREF_LOCAL_REPO_BONJOUR,
|
||||
Preferences.PREF_LOCAL_REPO_NAME,
|
||||
Preferences.PREF_CACHE_APK,
|
||||
Preferences.PREF_EXPERT,
|
||||
Preferences.PREF_ROOT_INSTALLER,
|
||||
@ -88,10 +89,9 @@ public class PreferencesActivity extends PreferenceActivity implements
|
||||
pref.setSummary(pref.getEntry());
|
||||
}
|
||||
|
||||
protected void textSummary(String key) {
|
||||
protected void textSummary(String key, int resId) {
|
||||
EditTextPreference pref = (EditTextPreference)findPreference(key);
|
||||
pref.setSummary(getString(R.string.update_history_summ,
|
||||
pref.getText()));
|
||||
pref.setSummary(getString(resId, pref.getText()));
|
||||
}
|
||||
|
||||
protected void updateSummary(String key, boolean changing) {
|
||||
@ -118,7 +118,7 @@ public class PreferencesActivity extends PreferenceActivity implements
|
||||
R.string.notify_off);
|
||||
|
||||
} else if (key.equals(Preferences.PREF_UPD_HISTORY)) {
|
||||
textSummary(key);
|
||||
textSummary(key, R.string.update_history_summ);
|
||||
|
||||
} else if (key.equals(Preferences.PREF_PERMISSIONS)) {
|
||||
onoffSummary(key, R.string.showPermissions_on,
|
||||
@ -151,6 +151,9 @@ public class PreferencesActivity extends PreferenceActivity implements
|
||||
onoffSummary(key, R.string.local_repo_bonjour_on,
|
||||
R.string.local_repo_bonjour_off);
|
||||
|
||||
} else if (key.equals(Preferences.PREF_LOCAL_REPO_NAME)) {
|
||||
textSummary(key, R.string.local_repo_name_summary);
|
||||
|
||||
} else if (key.equals(Preferences.PREF_CACHE_APK)) {
|
||||
onoffSummary(key, R.string.cache_downloaded_on,
|
||||
R.string.cache_downloaded_off);
|
||||
|
@ -23,7 +23,6 @@ import android.content.pm.PackageManager.NameNotFoundException;
|
||||
import android.content.res.AssetManager;
|
||||
import android.content.res.XmlResourceParser;
|
||||
import android.net.Uri;
|
||||
import android.os.Build;
|
||||
import android.text.TextUtils;
|
||||
import android.util.DisplayMetrics;
|
||||
import android.util.Log;
|
||||
@ -453,8 +452,4 @@ public final class Utils {
|
||||
return String.format("%0" + (bytes.length << 1) + "X", bi);
|
||||
}
|
||||
|
||||
public static String getDefaultRepoName() {
|
||||
return (Build.BRAND + " " + Build.MODEL).replaceAll(" ", "-");
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -16,6 +16,7 @@ import android.preference.PreferenceManager;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
|
||||
import org.fdroid.fdroid.Preferences;
|
||||
import org.fdroid.fdroid.Utils;
|
||||
import org.fdroid.fdroid.data.Apk;
|
||||
import org.fdroid.fdroid.data.App;
|
||||
@ -271,7 +272,7 @@ public class LocalRepoManager {
|
||||
int repoMaxAge = Float.valueOf(prefs.getString("max_repo_age_days",
|
||||
DEFAULT_REPO_MAX_AGE_DAYS)).intValue();
|
||||
|
||||
String repoName = prefs.getString("repo_name", Utils.getDefaultRepoName());
|
||||
String repoName = Preferences.get().getLocalRepoName();
|
||||
|
||||
Element repo = doc.createElement("repo");
|
||||
repo.setAttribute("icon", "blah.png");
|
||||
|
@ -196,14 +196,15 @@ public class LocalRepoService extends Service {
|
||||
}
|
||||
|
||||
private void registerMDNSService() {
|
||||
String repoName = Preferences.get().getLocalRepoName();
|
||||
final HashMap<String, String> values = new HashMap<String, String>();
|
||||
values.put("path", "/fdroid/repo");
|
||||
values.put("name", FDroidApp.repo.name);
|
||||
values.put("name", repoName);
|
||||
// TODO set type based on "use HTTPS" pref
|
||||
// values.put("fingerprint", FDroidApp.repo.fingerprint);
|
||||
values.put("type", "fdroidrepo");
|
||||
pairService = ServiceInfo.create("_http._tcp.local.",
|
||||
FDroidApp.repo.name, FDroidApp.port, 0, 0, values);
|
||||
repoName, FDroidApp.port, 0, 0, values);
|
||||
new Thread(new Runnable() {
|
||||
|
||||
@Override
|
||||
|
@ -14,6 +14,7 @@ import android.support.v4.content.LocalBroadcastManager;
|
||||
import android.util.Log;
|
||||
|
||||
import org.fdroid.fdroid.FDroidApp;
|
||||
import org.fdroid.fdroid.Preferences;
|
||||
import org.fdroid.fdroid.Utils;
|
||||
|
||||
import java.util.Locale;
|
||||
@ -57,11 +58,13 @@ public class WifiStateChangeService extends Service {
|
||||
FDroidApp.bssid = wifiInfo.getBSSID();
|
||||
|
||||
String scheme;
|
||||
// TODO move this to Preferences.get().isHttpsEnabled();
|
||||
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(WifiStateChangeService.this);
|
||||
if (prefs.getBoolean("use_https", false))
|
||||
scheme = "https";
|
||||
else
|
||||
scheme = "http";
|
||||
FDroidApp.repo.name = Preferences.get().getLocalRepoName();
|
||||
FDroidApp.repo.address = String.format(Locale.ENGLISH, "%s://%s:%d/fdroid/repo",
|
||||
scheme, FDroidApp.ipAddressString, FDroidApp.port);
|
||||
FDroidApp.localRepo.setUriString(FDroidApp.repo.address);
|
||||
|
Loading…
x
Reference in New Issue
Block a user