fix for follow / unfollow confusion
This commit is contained in:
parent
3738f3af21
commit
e4edebfed7
6 changed files with 122 additions and 58 deletions
BIN
app/src/main/assets/font_awesome_5_free_regular.otf
Normal file
BIN
app/src/main/assets/font_awesome_5_free_regular.otf
Normal file
Binary file not shown.
|
@ -49,6 +49,7 @@ import io.lbry.browser.tasks.claim.ClaimListResultHandler;
|
|||
import io.lbry.browser.tasks.claim.ResolveTask;
|
||||
import io.lbry.browser.tasks.lbryinc.FetchStatCountTask;
|
||||
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.findcontent.FollowingFragment;
|
||||
import io.lbry.browser.utils.Helper;
|
||||
|
@ -80,7 +81,8 @@ public class ChannelFragment extends BaseFragment implements FetchChannelsListen
|
|||
private View buttonTip;
|
||||
private View buttonFollowUnfollow;
|
||||
private int subCount;
|
||||
private SolidIconView iconFollowUnfollow;
|
||||
private OutlineIconView iconFollow;
|
||||
private SolidIconView iconUnfollow;
|
||||
private View layoutNothingAtLocation;
|
||||
private View layoutLoadingState;
|
||||
|
||||
|
@ -105,7 +107,8 @@ public class ChannelFragment extends BaseFragment implements FetchChannelsListen
|
|||
buttonShare = root.findViewById(R.id.channel_view_share);
|
||||
buttonTip = root.findViewById(R.id.channel_view_tip);
|
||||
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);
|
||||
tabLayout = root.findViewById(R.id.channel_view_tabs);
|
||||
|
@ -274,13 +277,8 @@ public class ChannelFragment extends BaseFragment implements FetchChannelsListen
|
|||
private void checkIsFollowing() {
|
||||
if (claim != null) {
|
||||
boolean isFollowing = Lbryio.isFollowing(claim);
|
||||
if (iconFollowUnfollow != null) {
|
||||
iconFollowUnfollow.setText(isFollowing ? R.string.fa_heart_broken : R.string.fa_heart);
|
||||
Context context = getContext();
|
||||
if (context != null) {
|
||||
iconFollowUnfollow.setTextColor(ContextCompat.getColor(context, isFollowing ? R.color.foreground : R.color.red));
|
||||
}
|
||||
}
|
||||
Helper.setViewVisibility(iconFollow, !isFollowing ? View.VISIBLE : View.GONE);
|
||||
Helper.setViewVisibility(iconUnfollow, isFollowing ? View.VISIBLE : View.GONE);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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"));
|
||||
}
|
||||
}
|
|
@ -9,6 +9,7 @@ import android.content.Intent;
|
|||
import android.content.SharedPreferences;
|
||||
import android.content.pm.ActivityInfo;
|
||||
import android.graphics.Color;
|
||||
import android.graphics.Outline;
|
||||
import android.net.Uri;
|
||||
import android.os.AsyncTask;
|
||||
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.LogFileViewTask;
|
||||
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.publish.PublishFragment;
|
||||
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) {
|
||||
resolving = true;
|
||||
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);
|
||||
buttonFollowUnfollow.setOnClickListener(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);
|
||||
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);
|
||||
}
|
||||
}
|
||||
});
|
||||
View buttonFollow = root.findViewById(R.id.file_view_icon_follow);
|
||||
View buttonUnfollow = root.findViewById(R.id.file_view_icon_unfollow);
|
||||
buttonFollow.setOnClickListener(followUnfollowListener);
|
||||
buttonUnfollow.setOnClickListener(followUnfollowListener);
|
||||
|
||||
commentChannelSpinnerAdapter = new InlineChannelSpinnerAdapter(getContext(), R.layout.spinner_item_channel, new ArrayList<>());
|
||||
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);
|
||||
if (claim.isPlayable()) {
|
||||
|
@ -2408,11 +2424,10 @@ public class FileViewFragment extends BaseFragment implements
|
|||
Context context = getContext();
|
||||
View root = getView();
|
||||
if (context != null && root != null) {
|
||||
SolidIconView iconFollowUnfollow = root.findViewById(R.id.file_view_icon_follow_unfollow);
|
||||
if (iconFollowUnfollow != null) {
|
||||
iconFollowUnfollow.setText(isFollowing ? R.string.fa_heart_broken : R.string.fa_heart);
|
||||
iconFollowUnfollow.setTextColor(ContextCompat.getColor(context, isFollowing ? R.color.foreground : R.color.red));
|
||||
}
|
||||
OutlineIconView iconFollow = root.findViewById(R.id.file_view_icon_follow);
|
||||
SolidIconView iconUnfollow = root.findViewById(R.id.file_view_icon_unfollow);
|
||||
Helper.setViewVisibility(iconFollow, !isFollowing ? View.VISIBLE: View.INVISIBLE);
|
||||
Helper.setViewVisibility(iconUnfollow, isFollowing ? View.VISIBLE : View.INVISIBLE);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -210,14 +210,22 @@
|
|||
android:clickable="true"
|
||||
android:layout_width="36dp"
|
||||
android:layout_height="36dp">
|
||||
<io.lbry.browser.ui.controls.SolidIconView
|
||||
android:id="@+id/channel_view_icon_follow_unfollow"
|
||||
<io.lbry.browser.ui.controls.OutlineIconView
|
||||
android:id="@+id/channel_view_icon_follow"
|
||||
android:layout_centerInParent="true"
|
||||
android:layout_width="24dp"
|
||||
android:layout_height="24dp"
|
||||
android:text="@string/fa_heart"
|
||||
android:textColor="@color/red"
|
||||
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>
|
||||
</LinearLayout>
|
||||
</RelativeLayout>
|
||||
|
|
|
@ -484,7 +484,7 @@
|
|||
android:paddingTop="12dp"
|
||||
android:paddingLeft="16dp"
|
||||
android:paddingBottom="12dp"
|
||||
android:layout_toLeftOf="@id/file_view_icon_follow_unfollow">
|
||||
android:layout_toLeftOf="@id/file_view_icon_follow">
|
||||
<RelativeLayout
|
||||
android:id="@+id/file_view_publisher_avatar"
|
||||
android:layout_width="50dp"
|
||||
|
@ -541,8 +541,8 @@
|
|||
</LinearLayout>
|
||||
</LinearLayout>
|
||||
|
||||
<io.lbry.browser.ui.controls.SolidIconView
|
||||
android:id="@+id/file_view_icon_follow_unfollow"
|
||||
<io.lbry.browser.ui.controls.OutlineIconView
|
||||
android:id="@+id/file_view_icon_follow"
|
||||
android:clickable="true"
|
||||
android:background="?attr/selectableItemBackground"
|
||||
android:layout_alignParentRight="true"
|
||||
|
@ -554,6 +554,20 @@
|
|||
android:text="@string/fa_heart"
|
||||
android:textColor="@color/red"
|
||||
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>
|
||||
|
||||
<View
|
||||
|
|
Loading…
Reference in a new issue