This commit is contained in:
Javi Rueda 2021-04-12 20:24:33 +02:00
commit dea820763d
9 changed files with 232 additions and 15 deletions

View file

@ -2657,15 +2657,7 @@ public class MainActivity extends AppCompatActivity implements SdkStatusListener
}
private Fragment getCurrentFragment() {
int backCount = getSupportFragmentManager().getBackStackEntryCount();
if (backCount > 0) {
try {
return getSupportFragmentManager().getFragments().get(backCount - 1);
} catch (IndexOutOfBoundsException ex) {
return null;
}
}
return null;
return getSupportFragmentManager().findFragmentById(R.id.content_main);
}
public void hideActionBar() {
@ -3371,6 +3363,18 @@ public class MainActivity extends AppCompatActivity implements SdkStatusListener
return;
}
if (currentFragment != null && ((BaseFragment) currentFragment).getParams() != null
&& ((BaseFragment) currentFragment).getParams().containsKey("source")
&& ((BaseFragment) currentFragment).getParams().get("source").equals("notification")) {
Map<String, Object> currentParams = new HashMap<>(1);
if (((BaseFragment) currentFragment).getParams().containsKey("url"))
currentParams.put("url", ((BaseFragment) currentFragment).getParams().get("url"));
((BaseFragment) currentFragment).setParams(currentParams);
}
//fragment.setRetainInstance(true);
FragmentManager manager = getSupportFragmentManager();
FragmentTransaction transaction = manager.beginTransaction().replace(R.id.content_main, fragment);

View file

@ -16,8 +16,10 @@ import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import io.lbry.browser.MainActivity;
import io.lbry.browser.data.DatabaseHelper;
@ -47,7 +49,9 @@ public class NotificationListTask extends AsyncTask<Void, Void, List<LbryNotific
List<LbryNotification> notifications = new ArrayList<>();
SQLiteDatabase db = null;
try {
JSONArray array = (JSONArray) Lbryio.parseResponse(Lbryio.call("notification", "list", context));
Map<String, String> parameters = new HashMap<>(1);
parameters.put("is_app_readable", "true");
JSONArray array = (JSONArray) Lbryio.parseResponse(Lbryio.call("notification", "list", parameters, context));
if (array != null) {
for (int i = 0; i < array.length(); i++) {
JSONObject item = array.getJSONObject(i);

View file

@ -64,7 +64,7 @@ public class BaseFragment extends Fragment {
}
}
if (params != null && params.containsKey("source") && "notification".equalsIgnoreCase(params.get("source").toString())) {
if (params != null && params.containsKey("source") && params.get("source") != null && "notification".equalsIgnoreCase(params.get("source").toString())) {
Context context = getContext();
if (context instanceof MainActivity) {
((MainActivity) context).navigateBackToNotifications();

View file

@ -73,6 +73,7 @@ public class ChannelFragment extends BaseFragment implements FetchChannelsListen
private TextView textFollowerCount;
private TabLayout tabLayout;
private ViewPager2 tabPager;
ViewPager2.OnPageChangeCallback opcc;
private View buttonEdit;
private View buttonDelete;
@ -91,6 +92,8 @@ public class ChannelFragment extends BaseFragment implements FetchChannelsListen
// if this is set, scroll to the specific comment on load
private String commentHash;
private float floatingWalletPositionY;
public View onCreateView(@NonNull LayoutInflater inflater,
ViewGroup container, Bundle savedInstanceState) {
View root = inflater.inflate(R.layout.fragment_channel, container, false);
@ -122,6 +125,25 @@ public class ChannelFragment extends BaseFragment implements FetchChannelsListen
tabLayout = root.findViewById(R.id.channel_view_tabs);
tabPager.setSaveEnabled(false);
View floatingBalance = getActivity().findViewById(R.id.floating_balance_main_container);
floatingWalletPositionY = floatingBalance.getY();
opcc = new ViewPager2.OnPageChangeCallback() {
@Override
public void onPageSelected(int position) {
super.onPageSelected(position);
if (position > 0) {
// Hide floating wallet for the About and the Comment tabs as they are mostly text
((MainActivity) getContext()).translateFloatingWallet(floatingWalletPositionY);
} else {
((MainActivity) getContext()).restoreWalletContainerPosition();
}
}
};
tabPager.registerOnPageChangeCallback(opcc);
buttonEdit.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
@ -380,6 +402,15 @@ public class ChannelFragment extends BaseFragment implements FetchChannelsListen
super.onPause();
}
public void onStop() {
Context context = getContext();
if (context instanceof MainActivity) {
((MainActivity) context ).restoreWalletContainerPosition();
}
tabPager.unregisterOnPageChangeCallback(opcc);
super.onStop();
}
private void checkParams() {
boolean updateRequired = false;
Map<String, Object> params = getParams();

View file

@ -12,6 +12,7 @@ import android.graphics.Color;
import android.net.Uri;
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.Environment;
import android.text.Editable;
import android.text.TextWatcher;
import android.text.format.DateUtils;
@ -87,8 +88,12 @@ import org.json.JSONException;
import org.json.JSONObject;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.text.DecimalFormat;
import java.text.NumberFormat;
import java.util.ArrayList;
@ -162,6 +167,10 @@ import io.lbry.lbrysdk.DownloadManager;
import io.lbry.lbrysdk.LbrynetService;
import io.lbry.lbrysdk.Utils;
import static android.os.Environment.DIRECTORY_DOWNLOADS;
import static android.os.Environment.DIRECTORY_MOVIES;
import static android.os.Environment.DIRECTORY_PICTURES;
public class FileViewFragment extends BaseFragment implements
MainActivity.BackPressInterceptor,
DownloadActionListener,
@ -2813,6 +2822,41 @@ public class FileViewFragment extends BaseFragment implements
downloadInProgress = false;
downloadProgressView.setProgress(100);
Helper.setViewVisibility(downloadProgressView, View.GONE);
// Copy file to shared Downloads folder
// TODO Assign this folder when downloading instead of copying the file
File fileFolder;
if (claimFile.getMimeType().contains("video"))
fileFolder = Environment.getExternalStoragePublicDirectory(DIRECTORY_MOVIES);
else if (claimFile.getMimeType().contains("image") || claimFile.getMimeType().contains("picture"))
fileFolder = Environment.getExternalStoragePublicDirectory(DIRECTORY_PICTURES);
else
fileFolder = Environment.getExternalStoragePublicDirectory(DIRECTORY_DOWNLOADS);
InputStream in = null;
OutputStream out;
try {
in = new FileInputStream(claimFile.getDownloadPath());
out = new FileOutputStream(new File(fileFolder, claimFile.getFileName()));
byte[] buf = new byte[1024];
int len;
while ((len = in.read(buf)) > 0) {
out.write(buf, 0, len);
}
in.close();
out.close();
} catch (IOException e) {
e.printStackTrace();
}
playOrViewMedia();
}
checkIsFileComplete();

View file

@ -33,6 +33,14 @@ import com.google.android.material.snackbar.Snackbar;
import com.google.android.material.switchmaterial.SwitchMaterial;
import com.google.android.material.textfield.TextInputEditText;
import org.json.JSONObject;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;
import okhttp3.ResponseBody;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.math.BigDecimal;
import java.net.URLEncoder;
@ -44,6 +52,10 @@ import java.text.DecimalFormatSymbols;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import javax.crypto.Mac;
import javax.crypto.spec.SecretKeySpec;
@ -291,6 +303,44 @@ public class WalletFragment extends BaseFragment implements SdkStatusListener, W
}
});
ExecutorService executor = Executors.newSingleThreadExecutor();
// This will return /true/ if user IP is **not** on the US or the request fails
Future<Boolean> localeFuture = executor.submit(() -> {
Request request = new Request.Builder().url("https://api.lbry.com/locale/get").build();
OkHttpClient okHttpClient = new OkHttpClient();
try (Response response = okHttpClient.newCall(request).execute()){
ResponseBody responseBody = response.body();
JSONObject responseJson;
if (responseBody != null)
responseJson = new JSONObject(responseBody.string());
else
return false;
if (responseJson.has("data") && responseJson.getBoolean("success")) {
JSONObject dataJson = (JSONObject) responseJson.get("data");
return !dataJson.getString("country").equals("US");
} else {
return false;
}
} catch (IOException e) {
e.printStackTrace();
}
return false;
});
try {
Boolean isNotUS = localeFuture.get();
if (isNotUS)
textConvertCreditsBittrex.setVisibility(View.VISIBLE);
else
textConvertCreditsBittrex.setVisibility(View.GONE);
} catch (ExecutionException | InterruptedException e) {
e.printStackTrace();
}
buttonSignUp.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {

View file

@ -1,5 +1,8 @@
package io.lbry.browser.utils;
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.List;
import java.util.regex.Matcher;
@ -8,6 +11,8 @@ import java.util.regex.Pattern;
import io.lbry.browser.exceptions.LbryUriException;
import lombok.Data;
import static org.apache.commons.codec.CharEncoding.UTF_8;
@Data
public class LbryUri {
public static final String LBRY_TV_BASE_URL = "https://lbry.tv/";
@ -117,10 +122,17 @@ public class LbryUri {
}
}
String streamOrChannelName = components.get(2);
String streamOrChannelName = null;
String possibleStreamName = null;
try {
// Using java.net.URLDecoder to be able to quickly unit test
streamOrChannelName = URLDecoder.decode(components.get(2), UTF_8);
possibleStreamName = URLDecoder.decode(components.get(6), UTF_8);
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
String primaryModSeparator = components.get(3);
String primaryModValue = components.get(4);
String possibleStreamName = components.get(6);
String secondaryModSeparator = components.get(7);
String secondaryModValue = components.get(8);
@ -188,7 +200,18 @@ public class LbryUri {
if (channelName != null) {
formattedChannelName = channelName.startsWith("@") ? channelName : String.format("@%s", channelName);
}
String primaryClaimName = claimName;
String primaryClaimName = null;
if (protocol.equals(LBRY_TV_BASE_URL) && Helper.isNullOrEmpty(formattedChannelName)) {
try {
primaryClaimName = URLEncoder.encode(claimName, UTF_8);
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
} else {
primaryClaimName = claimName;
}
if (Helper.isNullOrEmpty(primaryClaimName)) {
primaryClaimName = contentName;
}
@ -218,7 +241,15 @@ public class LbryUri {
secondaryClaimName = contentName;
}
if (Helper.isNullOrEmpty(secondaryClaimName)) {
secondaryClaimName = !Helper.isNullOrEmpty(formattedChannelName) ? streamName : null;
if (protocol.equals(LBRY_TV_BASE_URL)) {
try {
secondaryClaimName = !Helper.isNullOrEmpty(formattedChannelName) ? URLEncoder.encode(streamName, UTF_8) : null;
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
} else {
secondaryClaimName = !Helper.isNullOrEmpty(formattedChannelName) ? streamName : null;
}
}
String secondaryClaimId = !Helper.isNullOrEmpty(secondaryClaimName) ? streamClaimId : null;

View file

@ -155,6 +155,7 @@
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:layout_marginStart="16dp"
android:visibility="gone"
android:fontFamily="@font/inter"
android:text="@string/convert_credits_bittrex"
android:textColorLink="@color/lbryGreen"

View file

@ -113,6 +113,32 @@ public class LbryUriTest {
assertEquals(expectedForChannel, obtained);
}
@Test
public void parseLbryTvWithEncodedChars() {
LbryUri obtained = new LbryUri();
try {
obtained = LbryUri.parse("https://lbry.tv/@Content_I_Like:1/DR.-ASTRID-ST%C3%9CCKELBERGER:2",false);
} catch (LbryUriException e) {
e.printStackTrace();
}
expected = new LbryUri();
expected.setChannelName("@Content_I_Like");
expected.setStreamName("DR.-ASTRID-STÜCKELBERGER");
try {
LbryUri.UriModifier primaryMod = LbryUri.UriModifier.parse("#", "1");
LbryUri.UriModifier secondaryMod = LbryUri.UriModifier.parse("#", "2");
expected.setChannelClaimId(primaryMod.getClaimId());
expected.setStreamClaimId(secondaryMod.getClaimId());
} catch (LbryUriException e) {
e.printStackTrace();
}
assertEquals(expected, obtained);
}
@Test
public void lbryToTvString() {
LbryUri obtained = new LbryUri();
@ -126,6 +152,32 @@ public class LbryUriTest {
assertEquals("https://lbry.tv/@lbry:3f/lbryturns4:6", obtained.toTvString());
}
@Test
public void lbryToTvStringWithEncodedChars() {
LbryUri obtained = new LbryUri();
try {
obtained = LbryUri.parse("lbry://La-Peur,-Nos-Attentats,-c'est-VOTRE-Sécurité!-Les-Guignols#6",false);
} catch (LbryUriException e) {
e.printStackTrace();
}
assertEquals("https://lbry.tv/La-Peur%2C-Nos-Attentats%2C-c%27est-VOTRE-Se%CC%81curite%CC%81%21-Les-Guignols:6", obtained.toTvString());
}
@Test
public void lbryToTvStringWithChannelAndEncodedChars() {
LbryUri obtained = new LbryUri();
try {
obtained = LbryUri.parse("lbry://@test#1/La-Peur,-Nos-Attentats,-c'est-VOTRE-Sécurité!-Les-Guignols#6",false);
} catch (LbryUriException e) {
e.printStackTrace();
}
assertEquals("https://lbry.tv/@test:1/La-Peur%2C-Nos-Attentats%2C-c%27est-VOTRE-Se%CC%81curite%CC%81%21-Les-Guignols:6", obtained.toTvString());
}
@NotNull
private LbryUri sinthesizeExpected() {
LbryUri expectedForChannel = new LbryUri();