Native rewrite #878

Merged
akinwale merged 65 commits from native-rewrite into master 2020-05-23 08:49:00 +02:00
3 changed files with 55 additions and 13 deletions
Showing only changes of commit 5839821f8f - Show all commits

View file

@ -245,7 +245,7 @@ public class MainActivity extends AppCompatActivity implements SdkStatusListener
// preference keys // preference keys
public static final String PREFERENCE_KEY_DARK_MODE = "io.lbry.browser.preference.userinterface.DarkMode"; 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_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_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_REWARDS = "io.lbry.browser.preference.notifications.Rewards";
public static final String PREFERENCE_KEY_NOTIFICATION_CONTENT_INTERESTS = "io.lbry.browser.preference.notifications.ContentInterests"; 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())); 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 // register receivers
registerRequestsReceiver(); registerRequestsReceiver();
@ -789,6 +782,12 @@ public class MainActivity extends AppCompatActivity implements SdkStatusListener
stopExoplayer(); stopExoplayer();
nowPlayingClaim = null; nowPlayingClaim = null;
nowPlayingClaimUrl = null; nowPlayingClaimUrl = null;
appStarted = false;
if (!keepSdkBackground()) {
sendBroadcast(new Intent(LbrynetService.ACTION_STOP_SERVICE));
}
super.onDestroy(); super.onDestroy();
} }
@ -915,6 +914,17 @@ public class MainActivity extends AppCompatActivity implements SdkStatusListener
return Helper.getScaledValue(value, scale); 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() { private void setupUriBar() {
findViewById(R.id.wunderbar_close).setOnClickListener(new View.OnClickListener() { findViewById(R.id.wunderbar_close).setOnClickListener(new View.OnClickListener() {
@Override @Override
@ -931,11 +941,14 @@ public class MainActivity extends AppCompatActivity implements SdkStatusListener
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.showSoftInput(view, 0); imm.showSoftInput(view, 0);
} }
if (canShowUrlSuggestions()) {
toggleUrlSuggestions(hasFocus); toggleUrlSuggestions(hasFocus);
if (hasFocus && Helper.isNullOrEmpty(Helper.getValue(((EditText) view).getText()))) { if (hasFocus && Helper.isNullOrEmpty(Helper.getValue(((EditText) view).getText()))) {
displayUrlSuggestionsForNoInput(); displayUrlSuggestionsForNoInput();
} }
} }
}
}); });
wunderbar.addTextChangedListener(new TextWatcher() { wunderbar.addTextChangedListener(new TextWatcher() {
@ -946,7 +959,7 @@ public class MainActivity extends AppCompatActivity implements SdkStatusListener
@Override @Override
public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) { public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
if (charSequence != null) { if (charSequence != null && canShowUrlSuggestions()) {
handleUriInputChanged(charSequence.toString().trim()); handleUriInputChanged(charSequence.toString().trim());
} }
} }

View file

@ -2,6 +2,7 @@ package io.lbry.browser.ui.other;
import android.content.Context; import android.content.Context;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.os.AsyncTask;
import android.os.Bundle; import android.os.Bundle;
import androidx.appcompat.app.ActionBar; import androidx.appcompat.app.ActionBar;
@ -9,9 +10,14 @@ import androidx.appcompat.app.AppCompatDelegate;
import androidx.preference.PreferenceFragmentCompat; import androidx.preference.PreferenceFragmentCompat;
import androidx.preference.PreferenceManager; import androidx.preference.PreferenceManager;
import java.io.FileOutputStream;
import java.io.PrintStream;
import io.lbry.browser.MainActivity; import io.lbry.browser.MainActivity;
import io.lbry.browser.R; import io.lbry.browser.R;
import io.lbry.browser.utils.Helper;
import io.lbry.browser.utils.LbryAnalytics; import io.lbry.browser.utils.LbryAnalytics;
import io.lbry.lbrysdk.Utils;
public class SettingsFragment extends PreferenceFragmentCompat implements SharedPreferences.OnSharedPreferenceChangeListener { public class SettingsFragment extends PreferenceFragmentCompat implements SharedPreferences.OnSharedPreferenceChangeListener {
@Override @Override
@ -69,6 +75,29 @@ public class SettingsFragment extends PreferenceFragmentCompat implements Shared
if (key.equalsIgnoreCase(MainActivity.PREFERENCE_KEY_DARK_MODE)) { if (key.equalsIgnoreCase(MainActivity.PREFERENCE_KEY_DARK_MODE)) {
boolean darkMode = sp.getBoolean(MainActivity.PREFERENCE_KEY_DARK_MODE, false); boolean darkMode = sp.getBoolean(MainActivity.PREFERENCE_KEY_DARK_MODE, false);
AppCompatDelegate.setDefaultNightMode(darkMode ? AppCompatDelegate.MODE_NIGHT_YES : AppCompatDelegate.MODE_NIGHT_NO); 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);
}
} }

View file

@ -215,7 +215,7 @@
<string name="content_interests">Content Interests</string> <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="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 --> <!-- URL suggestions -->
<string name="search_url_title">%1$s - Search</string> <string name="search_url_title">%1$s - Search</string>