show URL suggestions and data network (DHT) settings
This commit is contained in:
parent
1d8f0dabe6
commit
5839821f8f
3 changed files with 55 additions and 13 deletions
|
@ -245,7 +245,7 @@ public class MainActivity extends AppCompatActivity implements SdkStatusListener
|
|||
// preference keys
|
||||
public static final String PREFERENCE_KEY_DARK_MODE = "io.lbry.browser.preference.userinterface.DarkMode";
|
||||
public static final String PREFERENCE_KEY_SHOW_MATURE_CONTENT = "io.lbry.browser.preference.userinterface.ShowMatureContent";
|
||||
public static final String PREFERENCE_KEY_NOTIFICATION_URL_SUGGESTIONS = "io.lbry.browser.preference.userinterface.UrlSuggestions";
|
||||
public static final String PREFERENCE_KEY_SHOW_URL_SUGGESTIONS = "io.lbry.browser.preference.userinterface.UrlSuggestions";
|
||||
public static final String PREFERENCE_KEY_NOTIFICATION_SUBSCRIPTIONS = "io.lbry.browser.preference.notifications.Subscriptions";
|
||||
public static final String PREFERENCE_KEY_NOTIFICATION_REWARDS = "io.lbry.browser.preference.notifications.Rewards";
|
||||
public static final String PREFERENCE_KEY_NOTIFICATION_CONTENT_INTERESTS = "io.lbry.browser.preference.notifications.ContentInterests";
|
||||
|
@ -366,13 +366,6 @@ public class MainActivity extends AppCompatActivity implements SdkStatusListener
|
|||
0, insets.getSystemWindowInsetBottom()));
|
||||
}
|
||||
});
|
||||
/*ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.url_suggestions_container), new OnApplyWindowInsetsListener() {
|
||||
@Override
|
||||
public WindowInsetsCompat onApplyWindowInsets(View v, WindowInsetsCompat insets) {
|
||||
return ViewCompat.onApplyWindowInsets(v,
|
||||
insets.replaceSystemWindowInsets(0, 0,0, insets.getSystemWindowInsetBottom()));
|
||||
}
|
||||
});*/
|
||||
|
||||
// register receivers
|
||||
registerRequestsReceiver();
|
||||
|
@ -789,6 +782,12 @@ public class MainActivity extends AppCompatActivity implements SdkStatusListener
|
|||
stopExoplayer();
|
||||
nowPlayingClaim = null;
|
||||
nowPlayingClaimUrl = null;
|
||||
appStarted = false;
|
||||
|
||||
if (!keepSdkBackground()) {
|
||||
sendBroadcast(new Intent(LbrynetService.ACTION_STOP_SERVICE));
|
||||
}
|
||||
|
||||
super.onDestroy();
|
||||
}
|
||||
|
||||
|
@ -915,6 +914,17 @@ public class MainActivity extends AppCompatActivity implements SdkStatusListener
|
|||
return Helper.getScaledValue(value, scale);
|
||||
}
|
||||
|
||||
|
||||
public boolean canShowUrlSuggestions() {
|
||||
SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(this);
|
||||
return sp.getBoolean(MainActivity.PREFERENCE_KEY_SHOW_URL_SUGGESTIONS, false);
|
||||
}
|
||||
|
||||
public boolean keepSdkBackground() {
|
||||
SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(this);
|
||||
return sp.getBoolean(MainActivity.PREFERENCE_KEY_KEEP_SDK_BACKGROUND, true);
|
||||
}
|
||||
|
||||
private void setupUriBar() {
|
||||
findViewById(R.id.wunderbar_close).setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
|
@ -931,11 +941,14 @@ public class MainActivity extends AppCompatActivity implements SdkStatusListener
|
|||
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
|
||||
imm.showSoftInput(view, 0);
|
||||
}
|
||||
|
||||
if (canShowUrlSuggestions()) {
|
||||
toggleUrlSuggestions(hasFocus);
|
||||
if (hasFocus && Helper.isNullOrEmpty(Helper.getValue(((EditText) view).getText()))) {
|
||||
displayUrlSuggestionsForNoInput();
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
wunderbar.addTextChangedListener(new TextWatcher() {
|
||||
|
@ -946,7 +959,7 @@ public class MainActivity extends AppCompatActivity implements SdkStatusListener
|
|||
|
||||
@Override
|
||||
public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
|
||||
if (charSequence != null) {
|
||||
if (charSequence != null && canShowUrlSuggestions()) {
|
||||
handleUriInputChanged(charSequence.toString().trim());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,6 +2,7 @@ package io.lbry.browser.ui.other;
|
|||
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import android.os.AsyncTask;
|
||||
import android.os.Bundle;
|
||||
|
||||
import androidx.appcompat.app.ActionBar;
|
||||
|
@ -9,9 +10,14 @@ import androidx.appcompat.app.AppCompatDelegate;
|
|||
import androidx.preference.PreferenceFragmentCompat;
|
||||
import androidx.preference.PreferenceManager;
|
||||
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.PrintStream;
|
||||
|
||||
import io.lbry.browser.MainActivity;
|
||||
import io.lbry.browser.R;
|
||||
import io.lbry.browser.utils.Helper;
|
||||
import io.lbry.browser.utils.LbryAnalytics;
|
||||
import io.lbry.lbrysdk.Utils;
|
||||
|
||||
public class SettingsFragment extends PreferenceFragmentCompat implements SharedPreferences.OnSharedPreferenceChangeListener {
|
||||
@Override
|
||||
|
@ -69,6 +75,29 @@ public class SettingsFragment extends PreferenceFragmentCompat implements Shared
|
|||
if (key.equalsIgnoreCase(MainActivity.PREFERENCE_KEY_DARK_MODE)) {
|
||||
boolean darkMode = sp.getBoolean(MainActivity.PREFERENCE_KEY_DARK_MODE, false);
|
||||
AppCompatDelegate.setDefaultNightMode(darkMode ? AppCompatDelegate.MODE_NIGHT_YES : AppCompatDelegate.MODE_NIGHT_NO);
|
||||
} else if (key.equalsIgnoreCase(MainActivity.PREFERENCE_KEY_PARTICIPATE_DATA_NETWORK)) {
|
||||
boolean dhtEnabled = sp.getBoolean(MainActivity.PREFERENCE_KEY_PARTICIPATE_DATA_NETWORK, false);
|
||||
updateDHTFileSetting(dhtEnabled);
|
||||
}
|
||||
}
|
||||
|
||||
private void updateDHTFileSetting(final boolean enabled) {
|
||||
Context context = getContext();
|
||||
(new AsyncTask<Void, Void, Void>() {
|
||||
protected Void doInBackground(Void... params) {
|
||||
PrintStream out = null;
|
||||
try {
|
||||
String fileContent = enabled ? "on" : "off";
|
||||
String path = String.format("%s/%s", Utils.getAppInternalStorageDir(context), "dht");
|
||||
out = new PrintStream(new FileOutputStream(path));
|
||||
out.print(fileContent);
|
||||
} catch (Exception ex) {
|
||||
// pass
|
||||
} finally {
|
||||
Helper.closeCloseable(out);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -215,7 +215,7 @@
|
|||
<string name="content_interests">Content Interests</string>
|
||||
|
||||
<string name="keep_sdk_in_background">Keep the LBRY service running in the background for improved wallet and network performance</string>
|
||||
<string name="participate_in_data_network">Participate in the data network</string>
|
||||
<string name="participate_in_data_network">Participate in the data network (requires app and background service restart)</string>
|
||||
|
||||
<!-- URL suggestions -->
|
||||
<string name="search_url_title">%1$s - Search</string>
|
||||
|
|
Loading…
Reference in a new issue