Native rewrite #878

Merged
akinwale merged 65 commits from native-rewrite into master 2020-05-23 08:49:00 +02:00
14 changed files with 117 additions and 25 deletions
Showing only changes of commit c78f669fb1 - Show all commits

View file

@ -84,8 +84,8 @@ dependencies {
androidTestImplementation 'androidx.test.ext:junit:1.1.1' androidTestImplementation 'androidx.test.ext:junit:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0' androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
__32bitImplementation files('libs/lbrysdk-0.67.1-release__arm.aar') __32bitImplementation files('libs/lbrysdk-0.71.0-release__arm.aar')
__64bitImplementation files('libs/lbrysdk-0.67.1-release__arm64.aar') __64bitImplementation files('libs/lbrysdk-0.71.0-release__arm64.aar')
} }
apply plugin: 'com.google.gms.google-services' apply plugin: 'com.google.gms.google-services'

View file

@ -29,9 +29,15 @@
android:windowSoftInputMode="adjustResize"> android:windowSoftInputMode="adjustResize">
<intent-filter> <intent-filter>
<action android:name="android.intent.action.MAIN" /> <action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" /> <category android:name="android.intent.category.LAUNCHER" />
</intent-filter> </intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="lbry" />
</intent-filter>
</activity> </activity>
<activity <activity

View file

@ -567,9 +567,11 @@ public class FileViewActivity extends AppCompatActivity {
private void renderPictureInPictureMode() { private void renderPictureInPictureMode() {
findViewById(R.id.file_view_scroll_view).setVisibility(View.GONE); findViewById(R.id.file_view_scroll_view).setVisibility(View.GONE);
findViewById(R.id.file_view_exoplayer_control_view).setVisibility(View.GONE); findViewById(R.id.file_view_exoplayer_control_view).setVisibility(View.GONE);
findViewById(R.id.floating_balance_main_container).setVisibility(View.GONE);
} }
private void renderFullMode() { private void renderFullMode() {
findViewById(R.id.file_view_scroll_view).setVisibility(View.VISIBLE); findViewById(R.id.file_view_scroll_view).setVisibility(View.VISIBLE);
findViewById(R.id.floating_balance_main_container).setVisibility(View.VISIBLE);
PlayerControlView controlView = findViewById(R.id.file_view_exoplayer_control_view); PlayerControlView controlView = findViewById(R.id.file_view_exoplayer_control_view);
controlView.setPlayer(null); controlView.setPlayer(null);

View file

@ -14,6 +14,7 @@ import android.content.res.Configuration;
import android.content.res.TypedArray; import android.content.res.TypedArray;
import android.database.sqlite.SQLiteDatabase; import android.database.sqlite.SQLiteDatabase;
import android.graphics.drawable.Drawable; import android.graphics.drawable.Drawable;
import android.net.Uri;
import android.os.AsyncTask; import android.os.AsyncTask;
import android.os.Build; import android.os.Build;
import android.os.Bundle; import android.os.Bundle;
@ -184,13 +185,10 @@ public class MainActivity extends AppCompatActivity implements SdkStatusListener
private BroadcastReceiver requestsReceiver; private BroadcastReceiver requestsReceiver;
private BroadcastReceiver userActionsReceiver; private BroadcastReceiver userActionsReceiver;
private boolean userAuthenticated = false;
private boolean appStarted; private boolean appStarted;
private boolean serviceRunning; private boolean serviceRunning;
private CheckSdkReadyTask checkSdkReadyTask; private CheckSdkReadyTask checkSdkReadyTask;
private boolean receivedStopService; private boolean receivedStopService;
private AppBarConfiguration mAppBarConfiguration;
private ActionBarDrawerToggle toggle; private ActionBarDrawerToggle toggle;
@Getter @Getter
private DatabaseHelper dbHelper; private DatabaseHelper dbHelper;
@ -200,6 +198,7 @@ public class MainActivity extends AppCompatActivity implements SdkStatusListener
@Getter @Getter
private ScheduledExecutorService scheduler = Executors.newSingleThreadScheduledExecutor(); private ScheduledExecutorService scheduler = Executors.newSingleThreadScheduledExecutor();
private boolean walletBalanceUpdateScheduled; private boolean walletBalanceUpdateScheduled;
private boolean shouldOpenUserSelectedMenuItem;
private boolean walletSyncScheduled; private boolean walletSyncScheduled;
private String pendingAllContentTag; private String pendingAllContentTag;
private String pendingChannelUrl; private String pendingChannelUrl;
@ -303,7 +302,8 @@ public class MainActivity extends AppCompatActivity implements SdkStatusListener
navMenuAdapter.setListener(new NavigationMenuAdapter.NavigationMenuItemClickListener() { navMenuAdapter.setListener(new NavigationMenuAdapter.NavigationMenuItemClickListener() {
@Override @Override
public void onNavigationMenuItemClicked(NavMenuItem menuItem) { public void onNavigationMenuItemClicked(NavMenuItem menuItem) {
if (navMenuAdapter.getCurrentItemId() == menuItem.getId() && menuItem.getId() != NavMenuItem.ID_ITEM_ALL_CONTENT) { if (navMenuAdapter.getCurrentItemId() == menuItem.getId() && !Arrays.asList(
NavMenuItem.ID_ITEM_FOLLOWING, NavMenuItem.ID_ITEM_ALL_CONTENT, NavMenuItem.ID_ITEM_WALLET).contains(menuItem.getId())) {
// already open // already open
navMenuAdapter.setCurrentItem(menuItem); navMenuAdapter.setCurrentItem(menuItem);
closeDrawer(); closeDrawer();
@ -330,7 +330,10 @@ public class MainActivity extends AppCompatActivity implements SdkStatusListener
}); });
} }
private boolean shouldOpenUserSelectedMenuItem; protected void onNewIntent(Intent intent) {
super.onNewIntent(intent);
checkUrlIntent(intent);
}
public void addSdkStatusListener(SdkStatusListener listener) { public void addSdkStatusListener(SdkStatusListener listener) {
if (!sdkStatusListeners.contains(listener)) { if (!sdkStatusListeners.contains(listener)) {
@ -376,10 +379,9 @@ public class MainActivity extends AppCompatActivity implements SdkStatusListener
public void openChannelClaim(Claim claim) { public void openChannelClaim(Claim claim) {
Map<String, Object> params = new HashMap<>(); Map<String, Object> params = new HashMap<>();
params.put("url", claim.getPermanentUrl()); params.put("url", !Helper.isNullOrEmpty(claim.getShortUrl()) ? claim.getShortUrl() : claim.getPermanentUrl());
params.put("claim", getCachedClaimForUrl(claim.getPermanentUrl())); params.put("claim", getCachedClaimForUrl(claim.getPermanentUrl()));
openFragment(ChannelFragment.class, true, NavMenuItem.ID_ITEM_FOLLOWING, params); openFragment(ChannelFragment.class, true, NavMenuItem.ID_ITEM_FOLLOWING, params);
setWunderbarValue(claim.getShortUrl());
} }
public void openChannelUrl(String url) { public void openChannelUrl(String url) {
@ -387,7 +389,6 @@ public class MainActivity extends AppCompatActivity implements SdkStatusListener
params.put("url", url); params.put("url", url);
params.put("claim", getCachedClaimForUrl(url)); params.put("claim", getCachedClaimForUrl(url));
openFragment(ChannelFragment.class, true, NavMenuItem.ID_ITEM_FOLLOWING, params); openFragment(ChannelFragment.class, true, NavMenuItem.ID_ITEM_FOLLOWING, params);
setWunderbarValue(url); // TODO: Move this to fragment onResume
} }
private Claim getCachedClaimForUrl(String url) { private Claim getCachedClaimForUrl(String url) {
@ -447,6 +448,7 @@ public class MainActivity extends AppCompatActivity implements SdkStatusListener
private void renderPictureInPictureMode() { private void renderPictureInPictureMode() {
findViewById(R.id.content_main).setVisibility(View.GONE); findViewById(R.id.content_main).setVisibility(View.GONE);
findViewById(R.id.floating_balance_main_container).setVisibility(View.GONE);
findViewById(R.id.global_now_playing_card).setVisibility(View.GONE); findViewById(R.id.global_now_playing_card).setVisibility(View.GONE);
getSupportActionBar().hide(); getSupportActionBar().hide();
@ -457,6 +459,7 @@ public class MainActivity extends AppCompatActivity implements SdkStatusListener
private void renderFullMode() { private void renderFullMode() {
getSupportActionBar().show(); getSupportActionBar().show();
findViewById(R.id.content_main).setVisibility(View.VISIBLE); findViewById(R.id.content_main).setVisibility(View.VISIBLE);
findViewById(R.id.floating_balance_main_container).setVisibility(View.VISIBLE);
findViewById(R.id.global_now_playing_card).setVisibility(View.VISIBLE); findViewById(R.id.global_now_playing_card).setVisibility(View.VISIBLE);
PlayerView pipPlayer = findViewById(R.id.pip_player); PlayerView pipPlayer = findViewById(R.id.pip_player);
@ -573,6 +576,10 @@ public class MainActivity extends AppCompatActivity implements SdkStatusListener
findViewById(R.id.wunderbar).setOnFocusChangeListener(new View.OnFocusChangeListener() { findViewById(R.id.wunderbar).setOnFocusChangeListener(new View.OnFocusChangeListener() {
@Override @Override
public void onFocusChange(View view, boolean hasFocus) { public void onFocusChange(View view, boolean hasFocus) {
if (hasFocus) {
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.showSoftInput(view, 0);
}
toggleUrlSuggestions(hasFocus); toggleUrlSuggestions(hasFocus);
if (hasFocus && Helper.isNullOrEmpty(Helper.getValue(((EditText) view).getText()))) { if (hasFocus && Helper.isNullOrEmpty(Helper.getValue(((EditText) view).getText()))) {
displayUrlSuggestionsForNoInput(); displayUrlSuggestionsForNoInput();
@ -707,6 +714,9 @@ public class MainActivity extends AppCompatActivity implements SdkStatusListener
List<UrlSuggestion> defaultSuggestions = buildDefaultSuggestions(text); List<UrlSuggestion> defaultSuggestions = buildDefaultSuggestions(text);
urlSuggestionListAdapter.addUrlSuggestions(defaultSuggestions); urlSuggestionListAdapter.addUrlSuggestions(defaultSuggestions);
if (LbryUri.PROTO_DEFAULT.equalsIgnoreCase(text)) {
return;
}
LighthouseAutoCompleteTask task = new LighthouseAutoCompleteTask(text, null, new LighthouseAutoCompleteTask.AutoCompleteResultHandler() { LighthouseAutoCompleteTask task = new LighthouseAutoCompleteTask(text, null, new LighthouseAutoCompleteTask.AutoCompleteResultHandler() {
@Override @Override
@ -753,6 +763,10 @@ public class MainActivity extends AppCompatActivity implements SdkStatusListener
private List<UrlSuggestion> buildDefaultSuggestions(String text) { private List<UrlSuggestion> buildDefaultSuggestions(String text) {
List<UrlSuggestion> suggestions = new ArrayList<UrlSuggestion>(); List<UrlSuggestion> suggestions = new ArrayList<UrlSuggestion>();
if (LbryUri.PROTO_DEFAULT.equalsIgnoreCase(text)) {
return buildDefaultSuggestionsForBlankUrl();
}
// First item is always search // First item is always search
if (!text.startsWith(LbryUri.PROTO_DEFAULT)) { if (!text.startsWith(LbryUri.PROTO_DEFAULT)) {
UrlSuggestion searchSuggestion = new UrlSuggestion(UrlSuggestion.TYPE_SEARCH, text); UrlSuggestion searchSuggestion = new UrlSuggestion(UrlSuggestion.TYPE_SEARCH, text);
@ -760,28 +774,45 @@ public class MainActivity extends AppCompatActivity implements SdkStatusListener
} }
if (!text.matches(LbryUri.REGEX_INVALID_URI)) { if (!text.matches(LbryUri.REGEX_INVALID_URI)) {
boolean isUrlWithScheme = text.startsWith(LbryUri.PROTO_DEFAULT);
boolean isChannel = text.startsWith("@"); boolean isChannel = text.startsWith("@");
LbryUri uri = null;
if (isUrlWithScheme && text.length() > 7) {
try {
uri = LbryUri.parse(text);
isChannel = uri.isChannel();
} catch (LbryUriException ex) {
// pass
}
}
if (!isChannel) { if (!isChannel) {
LbryUri uri = new LbryUri(); if (uri == null) {
uri.setStreamName(text); uri = new LbryUri();
uri.setStreamName(text);
}
UrlSuggestion fileSuggestion = new UrlSuggestion(UrlSuggestion.TYPE_FILE, text); UrlSuggestion fileSuggestion = new UrlSuggestion(UrlSuggestion.TYPE_FILE, text);
fileSuggestion.setUri(uri); fileSuggestion.setUri(uri);
suggestions.add(fileSuggestion); suggestions.add(fileSuggestion);
} }
if (text.indexOf(' ') == -1) { if (text.indexOf(' ') == -1) {
// channels and tags should not contain spaces // channels should not contain spaces
if (isChannel) { if (isChannel) {
LbryUri uri = new LbryUri(); if (uri == null) {
uri.setChannelName(text); uri = new LbryUri();
uri.setChannelName(text);
}
UrlSuggestion suggestion = new UrlSuggestion(UrlSuggestion.TYPE_CHANNEL, text); UrlSuggestion suggestion = new UrlSuggestion(UrlSuggestion.TYPE_CHANNEL, text);
suggestion.setUri(uri); suggestion.setUri(uri);
suggestions.add(suggestion); suggestions.add(suggestion);
} else {
UrlSuggestion suggestion = new UrlSuggestion(UrlSuggestion.TYPE_TAG, text);
suggestions.add(suggestion);
} }
} }
if (!isUrlWithScheme) {
UrlSuggestion suggestion = new UrlSuggestion(UrlSuggestion.TYPE_TAG, text);
suggestions.add(suggestion);
}
} }
return suggestions; return suggestions;
@ -843,7 +874,7 @@ public class MainActivity extends AppCompatActivity implements SdkStatusListener
Base64.decode(encryptedAuthToken, Base64.NO_WRAP), this, Lbry.KEYSTORE), "UTF8"); Base64.decode(encryptedAuthToken, Base64.NO_WRAP), this, Lbry.KEYSTORE), "UTF8");
} catch (Exception ex) { } catch (Exception ex) {
// pass. A new auth token would have to be generated if the old one cannot be decrypted // pass. A new auth token would have to be generated if the old one cannot be decrypted
android.util.Log.e(TAG, "Could not decrypt existing auth token.", ex); Log.e(TAG, "Could not decrypt existing auth token.", ex);
} }
} }
} }
@ -1328,11 +1359,38 @@ public class MainActivity extends AppCompatActivity implements SdkStatusListener
loadLastFragment(); loadLastFragment();
showSignedInUser(); showSignedInUser();
checkUrlIntent(getIntent());
appStarted = true; appStarted = true;
} }
}).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); }).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
} }
private void checkUrlIntent(Intent intent) {
if (intent != null) {
Uri data = intent.getData();
if (data != null) {
String url = data.toString();
// check special urls
if (url.startsWith("lbry://?")) {
String pagePath = url.substring(8);
// TODO: Handle special page paths
} else {
try {
LbryUri uri = LbryUri.parse(url);
if (uri.isChannel()) {
openChannelUrl(uri.toString());
} else {
openFileUrl(uri.toString(), this);
}
} catch (LbryUriException ex) {
// pass
}
}
}
}
}
private void loadLastFragment() { private void loadLastFragment() {
Fragment fragment = getCurrentFragment(); Fragment fragment = getCurrentFragment();
@ -1663,7 +1721,7 @@ public class MainActivity extends AppCompatActivity implements SdkStatusListener
Fragment fragment = openNavFragments.containsKey(key) ? openNavFragments.get(key) : (Fragment) fragmentClass.newInstance(); Fragment fragment = openNavFragments.containsKey(key) ? openNavFragments.get(key) : (Fragment) fragmentClass.newInstance();
if (fragment instanceof BaseFragment) { if (fragment instanceof BaseFragment) {
((BaseFragment) fragment).setParams(params); ((BaseFragment) fragment).setParams(params);
} }
Fragment currentFragment = getCurrentFragment(); Fragment currentFragment = getCurrentFragment();
if (currentFragment != null && currentFragment.equals(fragment)) { if (currentFragment != null && currentFragment.equals(fragment)) {
return; return;

View file

@ -359,6 +359,7 @@ public class AllContentFragment extends BaseFragment implements SharedPreference
public void onResume() { public void onResume() {
super.onResume(); super.onResume();
Helper.setWunderbarValue(null, getContext());
PreferenceManager.getDefaultSharedPreferences(getContext()).registerOnSharedPreferenceChangeListener(this); PreferenceManager.getDefaultSharedPreferences(getContext()).registerOnSharedPreferenceChangeListener(this);
updateContentFromLinkText(); updateContentFromLinkText();
updateContentScopeLinkText(); updateContentScopeLinkText();

View file

@ -203,6 +203,9 @@ public class ChannelFragment extends BaseFragment {
public void onResume() { public void onResume() {
super.onResume(); super.onResume();
Map<String, Object> params = getParams();
String url = params != null && params.containsKey("url") ? (String) params.get("url") : null;
Helper.setWunderbarValue(url, getContext());
checkParams(); checkParams();
} }

View file

@ -81,6 +81,7 @@ public class EditorsChoiceFragment extends BaseFragment {
public void onResume() { public void onResume() {
super.onResume(); super.onResume();
Helper.setWunderbarValue(null, getContext());
if (contentListAdapter == null || contentListAdapter.getItemCount() == 0) { if (contentListAdapter == null || contentListAdapter.getItemCount() == 0) {
fetchClaimSearchContent(); fetchClaimSearchContent();
} else { } else {

View file

@ -326,6 +326,7 @@ public class FollowingFragment extends BaseFragment implements
public void onResume() { public void onResume() {
super.onResume(); super.onResume();
Helper.setWunderbarValue(null, getContext());
PreferenceManager.getDefaultSharedPreferences(getContext()).registerOnSharedPreferenceChangeListener(this); PreferenceManager.getDefaultSharedPreferences(getContext()).registerOnSharedPreferenceChangeListener(this);
// check if subscriptions exist // check if subscriptions exist

View file

@ -86,6 +86,7 @@ public class SearchFragment extends BaseFragment implements
public void onResume() { public void onResume() {
super.onResume(); super.onResume();
Helper.setWunderbarValue(currentQuery, getContext());
PreferenceManager.getDefaultSharedPreferences(getContext()).registerOnSharedPreferenceChangeListener(this); PreferenceManager.getDefaultSharedPreferences(getContext()).registerOnSharedPreferenceChangeListener(this);
if (!Helper.isNullOrEmpty(currentQuery)) { if (!Helper.isNullOrEmpty(currentQuery)) {
search(currentQuery, currentFrom); search(currentQuery, currentFrom);

View file

@ -219,6 +219,15 @@ public class WalletFragment extends BaseFragment implements SdkStatusListener, W
recentTransactionsList.setLayoutManager(llm); recentTransactionsList.setLayoutManager(llm);
recentTransactionsList.addItemDecoration(new DividerItemDecoration(context, DividerItemDecoration.VERTICAL)); recentTransactionsList.addItemDecoration(new DividerItemDecoration(context, DividerItemDecoration.VERTICAL));
buttonSignUp.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Context context = getContext();
if (context instanceof MainActivity) {
((MainActivity) context).walletSyncSignIn();
}
}
});
buttonGetNewAddress.setOnClickListener(new View.OnClickListener() { buttonGetNewAddress.setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View view) { public void onClick(View view) {
@ -392,6 +401,7 @@ public class WalletFragment extends BaseFragment implements SdkStatusListener, W
public void onResume() { public void onResume() {
super.onResume(); super.onResume();
Helper.setWunderbarValue(null, getContext());
if (!Lbry.SDK_READY) { if (!Lbry.SDK_READY) {
Context context = getContext(); Context context = getContext();
if (context instanceof MainActivity) { if (context instanceof MainActivity) {
@ -415,6 +425,7 @@ public class WalletFragment extends BaseFragment implements SdkStatusListener, W
Context context = getContext(); Context context = getContext();
if (context instanceof MainActivity) { if (context instanceof MainActivity) {
MainActivity activity = (MainActivity) context; MainActivity activity = (MainActivity) context;
activity.setWunderbarValue(null);
activity.hideFloatingWalletBalance(); activity.hideFloatingWalletBalance();
} }
} }

View file

@ -29,6 +29,7 @@ import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Random; import java.util.Random;
import io.lbry.browser.MainActivity;
import io.lbry.browser.dialog.ContentFromDialogFragment; import io.lbry.browser.dialog.ContentFromDialogFragment;
import io.lbry.browser.dialog.ContentSortDialogFragment; import io.lbry.browser.dialog.ContentSortDialogFragment;
import io.lbry.browser.model.Claim; import io.lbry.browser.model.Claim;
@ -324,4 +325,10 @@ public final class Helper {
} }
return followedTags; return followedTags;
} }
public static void setWunderbarValue(String value, Context context) {
if (context instanceof MainActivity) {
((MainActivity) context).setWunderbarValue(value);
}
}
} }

View file

@ -29,16 +29,17 @@
<EditText <EditText
android:id="@+id/wunderbar" android:id="@+id/wunderbar"
android:background="@android:color/transparent" android:background="@android:color/transparent"
android:drawableLeft="@drawable/ic_search"
android:drawablePadding="8dp"
android:drawableTint="@color/actionBarForeground"
android:fontFamily="@font/inter" android:fontFamily="@font/inter"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:hint="@string/uri_placeholder" android:hint="@string/uri_placeholder"
android:selectAllOnFocus="true"
android:singleLine="true" android:singleLine="true"
android:textFontWeight="300" android:textFontWeight="300"
android:textSize="14sp" android:textSize="14sp" />
android:drawableLeft="@drawable/ic_search"
android:drawablePadding="8dp"
android:drawableTint="@color/actionBarForeground" />
<LinearLayout <LinearLayout
android:id="@+id/wunderbar_close" android:id="@+id/wunderbar_close"
android:clickable="true" android:clickable="true"