Handle lbry:// url scheme. Properly set URL bar values. SDK 0.71.0.

This commit is contained in:
Akinwale Ariwodola 2020-05-03 22:39:04 +01:00
parent 78dd587901
commit c78f669fb1
14 changed files with 117 additions and 25 deletions

View file

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

View file

@ -29,9 +29,15 @@
android:windowSoftInputMode="adjustResize">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</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

View file

@ -567,9 +567,11 @@ public class FileViewActivity extends AppCompatActivity {
private void renderPictureInPictureMode() {
findViewById(R.id.file_view_scroll_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() {
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);
controlView.setPlayer(null);

View file

@ -14,6 +14,7 @@ import android.content.res.Configuration;
import android.content.res.TypedArray;
import android.database.sqlite.SQLiteDatabase;
import android.graphics.drawable.Drawable;
import android.net.Uri;
import android.os.AsyncTask;
import android.os.Build;
import android.os.Bundle;
@ -184,13 +185,10 @@ public class MainActivity extends AppCompatActivity implements SdkStatusListener
private BroadcastReceiver requestsReceiver;
private BroadcastReceiver userActionsReceiver;
private boolean userAuthenticated = false;
private boolean appStarted;
private boolean serviceRunning;
private CheckSdkReadyTask checkSdkReadyTask;
private boolean receivedStopService;
private AppBarConfiguration mAppBarConfiguration;
private ActionBarDrawerToggle toggle;
@Getter
private DatabaseHelper dbHelper;
@ -200,6 +198,7 @@ public class MainActivity extends AppCompatActivity implements SdkStatusListener
@Getter
private ScheduledExecutorService scheduler = Executors.newSingleThreadScheduledExecutor();
private boolean walletBalanceUpdateScheduled;
private boolean shouldOpenUserSelectedMenuItem;
private boolean walletSyncScheduled;
private String pendingAllContentTag;
private String pendingChannelUrl;
@ -303,7 +302,8 @@ public class MainActivity extends AppCompatActivity implements SdkStatusListener
navMenuAdapter.setListener(new NavigationMenuAdapter.NavigationMenuItemClickListener() {
@Override
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
navMenuAdapter.setCurrentItem(menuItem);
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) {
if (!sdkStatusListeners.contains(listener)) {
@ -376,10 +379,9 @@ public class MainActivity extends AppCompatActivity implements SdkStatusListener
public void openChannelClaim(Claim claim) {
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()));
openFragment(ChannelFragment.class, true, NavMenuItem.ID_ITEM_FOLLOWING, params);
setWunderbarValue(claim.getShortUrl());
}
public void openChannelUrl(String url) {
@ -387,7 +389,6 @@ public class MainActivity extends AppCompatActivity implements SdkStatusListener
params.put("url", url);
params.put("claim", getCachedClaimForUrl(url));
openFragment(ChannelFragment.class, true, NavMenuItem.ID_ITEM_FOLLOWING, params);
setWunderbarValue(url); // TODO: Move this to fragment onResume
}
private Claim getCachedClaimForUrl(String url) {
@ -447,6 +448,7 @@ public class MainActivity extends AppCompatActivity implements SdkStatusListener
private void renderPictureInPictureMode() {
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);
getSupportActionBar().hide();
@ -457,6 +459,7 @@ public class MainActivity extends AppCompatActivity implements SdkStatusListener
private void renderFullMode() {
getSupportActionBar().show();
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);
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() {
@Override
public void onFocusChange(View view, boolean hasFocus) {
if (hasFocus) {
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.showSoftInput(view, 0);
}
toggleUrlSuggestions(hasFocus);
if (hasFocus && Helper.isNullOrEmpty(Helper.getValue(((EditText) view).getText()))) {
displayUrlSuggestionsForNoInput();
@ -707,6 +714,9 @@ public class MainActivity extends AppCompatActivity implements SdkStatusListener
List<UrlSuggestion> defaultSuggestions = buildDefaultSuggestions(text);
urlSuggestionListAdapter.addUrlSuggestions(defaultSuggestions);
if (LbryUri.PROTO_DEFAULT.equalsIgnoreCase(text)) {
return;
}
LighthouseAutoCompleteTask task = new LighthouseAutoCompleteTask(text, null, new LighthouseAutoCompleteTask.AutoCompleteResultHandler() {
@Override
@ -753,6 +763,10 @@ public class MainActivity extends AppCompatActivity implements SdkStatusListener
private List<UrlSuggestion> buildDefaultSuggestions(String text) {
List<UrlSuggestion> suggestions = new ArrayList<UrlSuggestion>();
if (LbryUri.PROTO_DEFAULT.equalsIgnoreCase(text)) {
return buildDefaultSuggestionsForBlankUrl();
}
// First item is always search
if (!text.startsWith(LbryUri.PROTO_DEFAULT)) {
UrlSuggestion searchSuggestion = new UrlSuggestion(UrlSuggestion.TYPE_SEARCH, text);
@ -760,29 +774,46 @@ public class MainActivity extends AppCompatActivity implements SdkStatusListener
}
if (!text.matches(LbryUri.REGEX_INVALID_URI)) {
boolean isUrlWithScheme = text.startsWith(LbryUri.PROTO_DEFAULT);
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) {
LbryUri uri = new LbryUri();
if (uri == null) {
uri = new LbryUri();
uri.setStreamName(text);
}
UrlSuggestion fileSuggestion = new UrlSuggestion(UrlSuggestion.TYPE_FILE, text);
fileSuggestion.setUri(uri);
suggestions.add(fileSuggestion);
}
if (text.indexOf(' ') == -1) {
// channels and tags should not contain spaces
// channels should not contain spaces
if (isChannel) {
LbryUri uri = new LbryUri();
if (uri == null) {
uri = new LbryUri();
uri.setChannelName(text);
}
UrlSuggestion suggestion = new UrlSuggestion(UrlSuggestion.TYPE_CHANNEL, text);
suggestion.setUri(uri);
suggestions.add(suggestion);
} else {
}
}
if (!isUrlWithScheme) {
UrlSuggestion suggestion = new UrlSuggestion(UrlSuggestion.TYPE_TAG, text);
suggestions.add(suggestion);
}
}
}
return suggestions;
}
@ -843,7 +874,7 @@ public class MainActivity extends AppCompatActivity implements SdkStatusListener
Base64.decode(encryptedAuthToken, Base64.NO_WRAP), this, Lbry.KEYSTORE), "UTF8");
} catch (Exception ex) {
// 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();
showSignedInUser();
checkUrlIntent(getIntent());
appStarted = true;
}
}).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() {
Fragment fragment = getCurrentFragment();

View file

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

View file

@ -203,6 +203,9 @@ public class ChannelFragment extends BaseFragment {
public void 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();
}

View file

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

View file

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

View file

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

View file

@ -219,6 +219,15 @@ public class WalletFragment extends BaseFragment implements SdkStatusListener, W
recentTransactionsList.setLayoutManager(llm);
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() {
@Override
public void onClick(View view) {
@ -392,6 +401,7 @@ public class WalletFragment extends BaseFragment implements SdkStatusListener, W
public void onResume() {
super.onResume();
Helper.setWunderbarValue(null, getContext());
if (!Lbry.SDK_READY) {
Context context = getContext();
if (context instanceof MainActivity) {
@ -415,6 +425,7 @@ public class WalletFragment extends BaseFragment implements SdkStatusListener, W
Context context = getContext();
if (context instanceof MainActivity) {
MainActivity activity = (MainActivity) context;
activity.setWunderbarValue(null);
activity.hideFloatingWalletBalance();
}
}

View file

@ -29,6 +29,7 @@ import java.util.List;
import java.util.Map;
import java.util.Random;
import io.lbry.browser.MainActivity;
import io.lbry.browser.dialog.ContentFromDialogFragment;
import io.lbry.browser.dialog.ContentSortDialogFragment;
import io.lbry.browser.model.Claim;
@ -324,4 +325,10 @@ public final class Helper {
}
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
android:id="@+id/wunderbar"
android:background="@android:color/transparent"
android:drawableLeft="@drawable/ic_search"
android:drawablePadding="8dp"
android:drawableTint="@color/actionBarForeground"
android:fontFamily="@font/inter"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/uri_placeholder"
android:selectAllOnFocus="true"
android:singleLine="true"
android:textFontWeight="300"
android:textSize="14sp"
android:drawableLeft="@drawable/ic_search"
android:drawablePadding="8dp"
android:drawableTint="@color/actionBarForeground" />
android:textSize="14sp" />
<LinearLayout
android:id="@+id/wunderbar_close"
android:clickable="true"