Merge remote-tracking branch 'upstream/master'

This commit is contained in:
Javi Rueda 2020-07-16 16:50:23 +02:00
commit ee212c5172
6 changed files with 122 additions and 58 deletions

Binary file not shown.

View file

@ -49,6 +49,7 @@ import io.lbry.browser.tasks.claim.ClaimListResultHandler;
import io.lbry.browser.tasks.claim.ResolveTask; import io.lbry.browser.tasks.claim.ResolveTask;
import io.lbry.browser.tasks.lbryinc.FetchStatCountTask; import io.lbry.browser.tasks.lbryinc.FetchStatCountTask;
import io.lbry.browser.ui.BaseFragment; import io.lbry.browser.ui.BaseFragment;
import io.lbry.browser.ui.controls.OutlineIconView;
import io.lbry.browser.ui.controls.SolidIconView; import io.lbry.browser.ui.controls.SolidIconView;
import io.lbry.browser.ui.findcontent.FollowingFragment; import io.lbry.browser.ui.findcontent.FollowingFragment;
import io.lbry.browser.utils.Helper; import io.lbry.browser.utils.Helper;
@ -80,7 +81,8 @@ public class ChannelFragment extends BaseFragment implements FetchChannelsListen
private View buttonTip; private View buttonTip;
private View buttonFollowUnfollow; private View buttonFollowUnfollow;
private int subCount; private int subCount;
private SolidIconView iconFollowUnfollow; private OutlineIconView iconFollow;
private SolidIconView iconUnfollow;
private View layoutNothingAtLocation; private View layoutNothingAtLocation;
private View layoutLoadingState; private View layoutLoadingState;
@ -105,7 +107,8 @@ public class ChannelFragment extends BaseFragment implements FetchChannelsListen
buttonShare = root.findViewById(R.id.channel_view_share); buttonShare = root.findViewById(R.id.channel_view_share);
buttonTip = root.findViewById(R.id.channel_view_tip); buttonTip = root.findViewById(R.id.channel_view_tip);
buttonFollowUnfollow = root.findViewById(R.id.channel_view_follow_unfollow); buttonFollowUnfollow = root.findViewById(R.id.channel_view_follow_unfollow);
iconFollowUnfollow = root.findViewById(R.id.channel_view_icon_follow_unfollow); iconFollow = root.findViewById(R.id.channel_view_icon_follow);
iconUnfollow = root.findViewById(R.id.channel_view_icon_unfollow);
tabPager = root.findViewById(R.id.channel_view_pager); tabPager = root.findViewById(R.id.channel_view_pager);
tabLayout = root.findViewById(R.id.channel_view_tabs); tabLayout = root.findViewById(R.id.channel_view_tabs);
@ -274,13 +277,8 @@ public class ChannelFragment extends BaseFragment implements FetchChannelsListen
private void checkIsFollowing() { private void checkIsFollowing() {
if (claim != null) { if (claim != null) {
boolean isFollowing = Lbryio.isFollowing(claim); boolean isFollowing = Lbryio.isFollowing(claim);
if (iconFollowUnfollow != null) { Helper.setViewVisibility(iconFollow, !isFollowing ? View.VISIBLE : View.GONE);
iconFollowUnfollow.setText(isFollowing ? R.string.fa_heart_broken : R.string.fa_heart); Helper.setViewVisibility(iconUnfollow, isFollowing ? View.VISIBLE : View.GONE);
Context context = getContext();
if (context != null) {
iconFollowUnfollow.setTextColor(ContextCompat.getColor(context, isFollowing ? R.color.foreground : R.color.red));
}
}
} }
} }

View file

@ -0,0 +1,29 @@
package io.lbry.browser.ui.controls;
import android.content.Context;
import android.graphics.Typeface;
import android.util.AttributeSet;
import android.view.Gravity;
import androidx.appcompat.widget.AppCompatTextView;
public class OutlineIconView extends AppCompatTextView {
private Context context;
public OutlineIconView(Context context) {
super(context);
this.context = context;
init();
}
public OutlineIconView(Context context, AttributeSet attrs) {
super(context, attrs);
this.context = context;
init();
}
private void init() {
setGravity(Gravity.CENTER);
setTypeface(Typeface.createFromAsset(context.getAssets(), "font_awesome_5_free_regular.otf"));
}
}

View file

@ -9,6 +9,7 @@ import android.content.Intent;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.content.pm.ActivityInfo; import android.content.pm.ActivityInfo;
import android.graphics.Color; import android.graphics.Color;
import android.graphics.Outline;
import android.net.Uri; import android.net.Uri;
import android.os.AsyncTask; import android.os.AsyncTask;
import android.os.Bundle; import android.os.Bundle;
@ -141,6 +142,7 @@ import io.lbry.browser.tasks.lbryinc.ClaimRewardTask;
import io.lbry.browser.tasks.lbryinc.FetchStatCountTask; import io.lbry.browser.tasks.lbryinc.FetchStatCountTask;
import io.lbry.browser.tasks.lbryinc.LogFileViewTask; import io.lbry.browser.tasks.lbryinc.LogFileViewTask;
import io.lbry.browser.ui.BaseFragment; import io.lbry.browser.ui.BaseFragment;
import io.lbry.browser.ui.controls.OutlineIconView;
import io.lbry.browser.ui.controls.SolidIconView; import io.lbry.browser.ui.controls.SolidIconView;
import io.lbry.browser.ui.publish.PublishFragment; import io.lbry.browser.ui.publish.PublishFragment;
import io.lbry.browser.utils.Helper; import io.lbry.browser.utils.Helper;
@ -724,6 +726,44 @@ public class FileViewFragment extends BaseFragment implements
} }
} }
private View.OnClickListener followUnfollowListener = new View.OnClickListener() {
@Override
public void onClick(View view) {
if (claim != null && claim.getSigningChannel() != null) {
Claim publisher = claim.getSigningChannel();
boolean isFollowing = Lbryio.isFollowing(publisher);
Subscription subscription = Subscription.fromClaim(publisher);
view.setEnabled(false);
Context context = getContext();
new ChannelSubscribeTask(context, publisher.getClaimId(), subscription, isFollowing, new ChannelSubscribeTask.ChannelSubscribeHandler() {
@Override
public void onSuccess() {
if (isFollowing) {
Lbryio.removeSubscription(subscription);
Lbryio.removeCachedResolvedSubscription(publisher);
} else {
Lbryio.addSubscription(subscription);
Lbryio.addCachedResolvedSubscription(publisher);
}
view.setEnabled(true);
checkIsFollowing();
FollowingFragment.resetClaimSearchContent = true;
// Save shared user state
if (context != null) {
context.sendBroadcast(new Intent(MainActivity.ACTION_SAVE_SHARED_USER_STATE));
}
}
@Override
public void onError(Exception exception) {
view.setEnabled(true);
}
}).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
}
};
private void resolveUrl(String url) { private void resolveUrl(String url) {
resolving = true; resolving = true;
Helper.setViewVisibility(layoutDisplayArea, View.INVISIBLE); Helper.setViewVisibility(layoutDisplayArea, View.INVISIBLE);
@ -1060,44 +1100,10 @@ public class FileViewFragment extends BaseFragment implements
} }
}); });
View buttonFollowUnfollow = root.findViewById(R.id.file_view_icon_follow_unfollow); View buttonFollow = root.findViewById(R.id.file_view_icon_follow);
buttonFollowUnfollow.setOnClickListener(new View.OnClickListener() { View buttonUnfollow = root.findViewById(R.id.file_view_icon_unfollow);
@Override buttonFollow.setOnClickListener(followUnfollowListener);
public void onClick(View view) { buttonUnfollow.setOnClickListener(followUnfollowListener);
if (claim != null && claim.getSigningChannel() != null) {
Claim publisher = claim.getSigningChannel();
boolean isFollowing = Lbryio.isFollowing(publisher);
Subscription subscription = Subscription.fromClaim(publisher);
buttonFollowUnfollow.setEnabled(false);
Context context = getContext();
new ChannelSubscribeTask(context, publisher.getClaimId(), subscription, isFollowing, new ChannelSubscribeTask.ChannelSubscribeHandler() {
@Override
public void onSuccess() {
if (isFollowing) {
Lbryio.removeSubscription(subscription);
Lbryio.removeCachedResolvedSubscription(publisher);
} else {
Lbryio.addSubscription(subscription);
Lbryio.addCachedResolvedSubscription(publisher);
}
buttonFollowUnfollow.setEnabled(true);
checkIsFollowing();
FollowingFragment.resetClaimSearchContent = true;
// Save shared user state
if (context != null) {
context.sendBroadcast(new Intent(MainActivity.ACTION_SAVE_SHARED_USER_STATE));
}
}
@Override
public void onError(Exception exception) {
buttonFollowUnfollow.setEnabled(true);
}
}).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
}
});
commentChannelSpinnerAdapter = new InlineChannelSpinnerAdapter(getContext(), R.layout.spinner_item_channel, new ArrayList<>()); commentChannelSpinnerAdapter = new InlineChannelSpinnerAdapter(getContext(), R.layout.spinner_item_channel, new ArrayList<>());
commentChannelSpinnerAdapter.addPlaceholder(false); commentChannelSpinnerAdapter.addPlaceholder(false);
@ -1418,7 +1424,17 @@ public class FileViewFragment extends BaseFragment implements
} }
} }
root.findViewById(R.id.file_view_icon_follow_unfollow).setVisibility(claim.getSigningChannel() != null ? View.VISIBLE : View.GONE); boolean isAnonymous = claim.getSigningChannel() == null;
View iconFollow = root.findViewById(R.id.file_view_icon_follow);
View iconUnfollow = root.findViewById(R.id.file_view_icon_unfollow);
if (isAnonymous) {
if (iconFollow.getVisibility() == View.VISIBLE) {
iconFollow.setVisibility(View.INVISIBLE);
}
if (iconUnfollow.getVisibility() == View.VISIBLE) {
iconUnfollow.setVisibility(View.INVISIBLE);
}
}
MaterialButton mainActionButton = root.findViewById(R.id.file_view_main_action_button); MaterialButton mainActionButton = root.findViewById(R.id.file_view_main_action_button);
if (claim.isPlayable()) { if (claim.isPlayable()) {
@ -2408,11 +2424,10 @@ public class FileViewFragment extends BaseFragment implements
Context context = getContext(); Context context = getContext();
View root = getView(); View root = getView();
if (context != null && root != null) { if (context != null && root != null) {
SolidIconView iconFollowUnfollow = root.findViewById(R.id.file_view_icon_follow_unfollow); OutlineIconView iconFollow = root.findViewById(R.id.file_view_icon_follow);
if (iconFollowUnfollow != null) { SolidIconView iconUnfollow = root.findViewById(R.id.file_view_icon_unfollow);
iconFollowUnfollow.setText(isFollowing ? R.string.fa_heart_broken : R.string.fa_heart); Helper.setViewVisibility(iconFollow, !isFollowing ? View.VISIBLE: View.INVISIBLE);
iconFollowUnfollow.setTextColor(ContextCompat.getColor(context, isFollowing ? R.color.foreground : R.color.red)); Helper.setViewVisibility(iconUnfollow, isFollowing ? View.VISIBLE : View.INVISIBLE);
}
} }
} }
} }

View file

@ -210,14 +210,22 @@
android:clickable="true" android:clickable="true"
android:layout_width="36dp" android:layout_width="36dp"
android:layout_height="36dp"> android:layout_height="36dp">
<io.lbry.browser.ui.controls.SolidIconView <io.lbry.browser.ui.controls.OutlineIconView
android:id="@+id/channel_view_icon_follow_unfollow" android:id="@+id/channel_view_icon_follow"
android:layout_centerInParent="true" android:layout_centerInParent="true"
android:layout_width="24dp" android:layout_width="24dp"
android:layout_height="24dp" android:layout_height="24dp"
android:text="@string/fa_heart" android:text="@string/fa_heart"
android:textColor="@color/red" android:textColor="@color/red"
android:textSize="20dp" /> android:textSize="20dp" />
<io.lbry.browser.ui.controls.SolidIconView
android:id="@+id/channel_view_icon_unfollow"
android:layout_centerInParent="true"
android:layout_width="24dp"
android:layout_height="24dp"
android:text="@string/fa_heart_broken"
android:textSize="20dp"
android:visibility="invisible"/>
</RelativeLayout> </RelativeLayout>
</LinearLayout> </LinearLayout>
</RelativeLayout> </RelativeLayout>

View file

@ -484,7 +484,7 @@
android:paddingTop="12dp" android:paddingTop="12dp"
android:paddingLeft="16dp" android:paddingLeft="16dp"
android:paddingBottom="12dp" android:paddingBottom="12dp"
android:layout_toLeftOf="@id/file_view_icon_follow_unfollow"> android:layout_toLeftOf="@id/file_view_icon_follow">
<RelativeLayout <RelativeLayout
android:id="@+id/file_view_publisher_avatar" android:id="@+id/file_view_publisher_avatar"
android:layout_width="50dp" android:layout_width="50dp"
@ -541,8 +541,8 @@
</LinearLayout> </LinearLayout>
</LinearLayout> </LinearLayout>
<io.lbry.browser.ui.controls.SolidIconView <io.lbry.browser.ui.controls.OutlineIconView
android:id="@+id/file_view_icon_follow_unfollow" android:id="@+id/file_view_icon_follow"
android:clickable="true" android:clickable="true"
android:background="?attr/selectableItemBackground" android:background="?attr/selectableItemBackground"
android:layout_alignParentRight="true" android:layout_alignParentRight="true"
@ -554,6 +554,20 @@
android:text="@string/fa_heart" android:text="@string/fa_heart"
android:textColor="@color/red" android:textColor="@color/red"
android:textSize="20dp" /> android:textSize="20dp" />
<io.lbry.browser.ui.controls.SolidIconView
android:id="@+id/file_view_icon_unfollow"
android:clickable="true"
android:background="?attr/selectableItemBackground"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_width="24dp"
android:layout_height="24dp"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
android:text="@string/fa_heart_broken"
android:textSize="20dp"
android:visibility="invisible" />
</RelativeLayout> </RelativeLayout>
<View <View