Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: Show FollowingFragment in first run #371

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 44 additions & 9 deletions app/src/main/java/com/odysee/app/FirstRunActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.util.Log;
import android.view.View;
import android.view.WindowInsetsController;
import android.widget.ImageView;
Expand Down Expand Up @@ -58,6 +59,7 @@
import com.odysee.app.tasks.RewardVerifiedHandler;
import com.odysee.app.tasks.claim.ClaimListResultHandler;
import com.odysee.app.tasks.claim.ClaimListTask;
import com.odysee.app.ui.findcontent.FollowingFragment;
import com.odysee.app.ui.firstrun.CreateChannelFragment;
import com.odysee.app.ui.rewards.RewardVerificationFragment;
import com.odysee.app.ui.firstrun.SignInFragment;
Expand All @@ -78,17 +80,20 @@ public class FirstRunActivity extends AppCompatActivity implements FirstRunStepH

public static final int FIRST_RUN_STEP_ACCOUNT = 1;
public static final int FIRST_RUN_STEP_CHANNEL = 2;
public static final int FIRST_RUN_STEP_REWARDS = 3;
public static final int FIRST_RUN_STEP_FOLLOW = 3;
public static final int FIRST_RUN_STEP_REWARDS = 4;

private static final String PREFERENCE_KEY_INTERNAL_CURRENT_FIRST_RUN_STEP = "com.odysee.app.CurrentFirstRunStep";

private int currentStep;
private boolean ytSyncOptInChecked;
private boolean currentSignInMode;
private String currentChannelName;
private boolean ytSyncOptInChecked;
private ViewPager2 viewPager;
private ImageView pagerIndicator1;
private ImageView pagerIndicator2;
private ImageView pagerIndicator3;
private ImageView pagerIndicator4;

private MaterialButton buttonSkip;
private MaterialButton buttonContinue;
Expand Down Expand Up @@ -168,6 +173,7 @@ public void onError(Exception error) {
pagerIndicator1 = findViewById(R.id.pager_indicator_1);
pagerIndicator2 = findViewById(R.id.pager_indicator_2);
pagerIndicator3 = findViewById(R.id.pager_indicator_3);
pagerIndicator4 = findViewById(R.id.pager_indicator_4);

buttonContinue = findViewById(R.id.first_run_continue_button);
buttonSkip = findViewById(R.id.first_run_skip_button);
Expand All @@ -176,7 +182,7 @@ public void onError(Exception error) {
buttonSkip.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
finishFirstRun();
onCompleted(currentStep);
}
});

Expand All @@ -187,7 +193,7 @@ public void onClick(View view) {
if (!ytSyncOptInChecked) {
handleCreateChannel();
} else {
proceedToRewardsStep();
proceedToFollowStep();
}
} else if (currentStep == FIRST_RUN_STEP_REWARDS) {
// final step (Use Odysee)
Expand Down Expand Up @@ -287,7 +293,8 @@ public void run() {
// proceed to rewards step
viewPager.setVisibility(View.VISIBLE);
progressIndicator.setVisibility(View.GONE);
proceedToRewardsStep();
// TODO: Figure this out
proceedToFollowStep();
} else {
emailRewardChecked();
}
Expand Down Expand Up @@ -325,7 +332,7 @@ public void run() {
new Handler(Looper.getMainLooper()).post(new Runnable() {
@Override
public void run() {
proceedToRewardsStep();
proceedToFollowStep();
onRequestCompleted(FIRST_RUN_STEP_REWARDS);
}
});
Expand Down Expand Up @@ -373,6 +380,7 @@ public void run() {
private void displayControlsForStep(int step) {
switch (step) {
case FIRST_RUN_STEP_ACCOUNT:
case FIRST_RUN_STEP_FOLLOW:
default:
buttonSkip.setVisibility(View.VISIBLE);
buttonContinue.setVisibility(View.INVISIBLE);
Expand All @@ -394,7 +402,7 @@ private void displayControlsForStep(int step) {

private void setActiveStep(int step) {
currentStep = step;
ImageView[] indicators = { pagerIndicator1, pagerIndicator2, pagerIndicator3 };
ImageView[] indicators = { pagerIndicator1, pagerIndicator2, pagerIndicator3, pagerIndicator4 };
for (int i = 0; i < indicators.length; i++) {
indicators[i].setImageDrawable(AppCompatResources.getDrawable(this, (step == i + 1) ? R.drawable.selected_page_dot : R.drawable.page_dot));
}
Expand Down Expand Up @@ -430,6 +438,8 @@ public void onCompleted(int completedStep) {
onRequestInProgress(true);
checkChannelStep();
} else if (completedStep == FIRST_RUN_STEP_CHANNEL) {
proceedToFollowStep();
} else if (completedStep == FIRST_RUN_STEP_FOLLOW) {
proceedToRewardsStep();
} else if (completedStep == FIRST_RUN_STEP_REWARDS) {
finishFirstRun();
Expand All @@ -447,7 +457,7 @@ public void onSuccess(List<Claim> claims, boolean hasReachedEnd) {
checkEmailVerifiedRewardForChannelStep();
} else {
// this user already has a channel, move to the final step: rewards verification
proceedToRewardsStep();
proceedToFollowStep();
}
}

Expand All @@ -469,6 +479,20 @@ private void proceedToChannelStep() {
sp.edit().putInt(PREFERENCE_KEY_INTERNAL_CURRENT_FIRST_RUN_STEP, FIRST_RUN_STEP_CHANNEL).apply();
}

private void proceedToFollowStep() {
if (currentSignInMode /* Sign In */) {
proceedToRewardsStep();
return;
}

setActiveStep(FIRST_RUN_STEP_FOLLOW);
viewPager.setCurrentItem(FIRST_RUN_STEP_FOLLOW - 1);
displayControlsForStep(FIRST_RUN_STEP_FOLLOW);

SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(this);
sp.edit().putInt(PREFERENCE_KEY_INTERNAL_CURRENT_FIRST_RUN_STEP, FIRST_RUN_STEP_FOLLOW).apply();
}

private void proceedToRewardsStep() {
setActiveStep(FIRST_RUN_STEP_REWARDS);
viewPager.setCurrentItem(FIRST_RUN_STEP_REWARDS - 1);
Expand Down Expand Up @@ -505,6 +529,11 @@ public void run() {
});
}

@Override
public void onSignInModeChanged(boolean signInMode) {
currentSignInMode = signInMode;
}

@Override
public void onChannelNameUpdated(String channelName) {
currentChannelName = channelName;
Expand Down Expand Up @@ -626,6 +655,12 @@ public Fragment createFragment(int position) {
}
return ccFragment;
case 2:
FollowingFragment fFragment = FollowingFragment.class.newInstance();
if (activity instanceof FirstRunStepHandler) {
fFragment.setFirstRunStepHandler((FirstRunStepHandler) activity);
}
return fFragment;
case 3:
RewardVerificationFragment rvFragment = RewardVerificationFragment.class.newInstance();
if (activity instanceof FirstRunStepHandler) {
rvFragment.setFirstRunStepHandler((FirstRunStepHandler) activity);
Expand All @@ -636,7 +671,7 @@ public Fragment createFragment(int position) {

@Override
public int getItemCount() {
return 3;
return 4;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
Expand All @@ -21,6 +22,7 @@

import com.google.android.material.button.MaterialButton;

import com.odysee.app.FirstRunActivity;
import com.odysee.app.OdyseeApp;
import org.json.JSONArray;
import org.json.JSONException;
Expand All @@ -39,6 +41,7 @@
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;
import java.util.stream.Collectors;

import com.odysee.app.MainActivity;
import com.odysee.app.R;
Expand All @@ -64,13 +67,16 @@
import com.odysee.app.tasks.lbryinc.FetchSubscriptionsTask;
import com.odysee.app.ui.BaseFragment;
import com.odysee.app.utils.ContentSources;
import com.odysee.app.utils.FirstRunStepHandler;
import com.odysee.app.utils.Helper;
import com.odysee.app.utils.Lbry;
import com.odysee.app.utils.LbryAnalytics;
import com.odysee.app.utils.LbryUri;
import com.odysee.app.utils.Lbryio;
import com.odysee.app.utils.Predefined;

import lombok.Setter;

public class FollowingFragment extends BaseFragment implements
FetchSubscriptionsTask.FetchSubscriptionsHandler,
ChannelItemSelectionListener,
Expand Down Expand Up @@ -142,6 +148,10 @@ public class FollowingFragment extends BaseFragment implements

private boolean fetchingScheduledClaims = false;
private boolean scheduledClaimsFetched = false;

@Setter
private FirstRunStepHandler firstRunStepHandler;

@Override
public View onCreateView(@NonNull LayoutInflater inflater,
ViewGroup container, Bundle savedInstanceState) {
Expand Down Expand Up @@ -247,9 +257,13 @@ public void onClick(View view) {
if (remaining == MIN_SUGGESTED_SUBSCRIBE_COUNT) {
showMessage(R.string.select_five_subscriptions);
} else {
fetchSubscriptions();
showSubscribedContent();
fetchAndResolveChannelList();
if (firstRunStepHandler != null) {
firstRunStepHandler.onCompleted(FirstRunActivity.FIRST_RUN_STEP_FOLLOW);
} else {
fetchSubscriptions();
showSubscribedContent();
fetchAndResolveChannelList();
}
}
}
});
Expand Down Expand Up @@ -473,10 +487,14 @@ private Map<String, Object> buildSuggestedOptions() {
canShowMatureContent = sp.getBoolean(MainActivity.PREFERENCE_KEY_SHOW_MATURE_CONTENT, false);
}

ContentSources.Category primaryCategory = null;
ArrayList<String> channelIds = null;
for (ContentSources.Category category : ContentSources.DYNAMIC_CONTENT_CATEGORIES) {
if ("PRIMARY_CONTENT".equalsIgnoreCase(category.getKey())) {
primaryCategory = category;
channelIds = new ArrayList<>(Arrays.asList(category.getChannelIds()));
channelIds.addAll(0, Arrays.asList(
"80d2590ad04e36fb1d077a9b9e3a8bba76defdf8" /* @Odysee */,
"b58dfaeab6c70754d792cdd9b56ff59b90aea334" /* @OdyseeHelp */
));
break;
}
}
Expand All @@ -485,10 +503,10 @@ private Map<String, Object> buildSuggestedOptions() {
Claim.TYPE_CHANNEL,
null,
canShowMatureContent ? null : new ArrayList<>(Predefined.MATURE_TAGS),
primaryCategory != null ? Arrays.asList(primaryCategory.getChannelIds()) : null,
channelIds,
null,
excludeChannelIdsForDiscover,
Arrays.asList(Claim.ORDER_BY_TRENDING_MIXED),
Arrays.asList(Claim.ORDER_BY_TRENDING_GROUP, Claim.ORDER_BY_TRENDING_MIXED),
null,
currentSuggestedPage == 0 ? 1 : currentSuggestedPage,
SUGGESTED_PAGE_SIZE);
Expand Down Expand Up @@ -1067,6 +1085,14 @@ public void onSuccess(List<Claim> claims, boolean hasReachedEnd) {
}

if (suggestedChannelAdapter == null) {
// Put @Odysee and @OdyseeHelp channels at top of suggested
List<Claim> featuredClaims = claims.stream().filter(claim ->
claim.getClaimId().equals("80d2590ad04e36fb1d077a9b9e3a8bba76defdf8" /* @Odysee */) ||
claim.getClaimId().equals("b58dfaeab6c70754d792cdd9b56ff59b90aea334" /* @OdyseeHelp */))
.collect(Collectors.toList());
claims.removeAll(featuredClaims);
claims.addAll(0, featuredClaims);

suggestedChannelAdapter = new SuggestedChannelGridAdapter(claims, getContext());
suggestedChannelAdapter.setListener(FollowingFragment.this);
if (suggestedChannelGrid != null) {
Expand Down Expand Up @@ -1120,7 +1146,7 @@ public void onSuccess(List<Subscription> subscriptions) {
}

public void onError(Exception exception) {

showError(exception.getLocalizedMessage());
}

public void onChannelItemSelected(Claim claim) {
Expand Down Expand Up @@ -1179,10 +1205,7 @@ private void checkNoContent(boolean suggested) {
}

private void saveSharedUserState() {
Context context = getContext();
if (context instanceof MainActivity) {
((MainActivity) context).saveSharedUserState();
}
MainActivity.instance.saveSharedUserState();
}

public void onSharedPreferenceChanged(SharedPreferences sp, String key) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,10 @@ public void onClick(View v) {
buttonSecondary.setText(signInMode ? R.string.sign_up : R.string.sign_in);
layoutPassword.setVisibility(signInMode ? View.GONE : View.VISIBLE);
inputPassword.setText("");

if (firstRunStepHandler != null) {
firstRunStepHandler.onSignInModeChanged(signInMode);
}
}
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ public interface FirstRunStepHandler {
void onCompleted(int completedStep);
void onRequestInProgress(boolean showProgress);
void onRequestCompleted(int step);
void onSignInModeChanged(boolean signInMode);
void onChannelNameUpdated(String channelName);
void onYouTubeSyncOptInCheckChanged(boolean checked);
void onStarted();
Expand Down
7 changes: 7 additions & 0 deletions app/src/main/res/layout/activity_first_run.xml
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,13 @@
android:id="@+id/pager_indicator_3"
android:layout_width="12dp"
android:layout_height="12dp"
android:layout_marginEnd="8dp"
android:src="@drawable/page_dot" />

<ImageView
android:id="@+id/pager_indicator_4"
android:layout_width="12dp"
android:layout_height="12dp"
android:src="@drawable/page_dot" />
</androidx.appcompat.widget.LinearLayoutCompat>
</androidx.appcompat.widget.LinearLayoutCompat>
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
<!-- Following page -->
<string name="find_channels_to_follow">Find Channels to follow</string>
<string name="discover">Discover</string>
<string name="lbry_works_better">LBRY works better if you follow at least 5 creators you like. Sign in to show creators you follow if you already have an account.</string>
<string name="lbry_works_better">Odysee works better if you follow at least 5 creators you like.</string>
<string name="select_five_subscriptions">Please select up to 5 creators to continue.</string>
<string name="n_remaining">%1$d remaining…</string>
<string name="done">Done</string>
Expand Down