From 7563fd212fd1c0802baaecbd8ad600f7ce3a674d Mon Sep 17 00:00:00 2001 From: kt programs Date: Tue, 18 Oct 2022 16:35:48 +0800 Subject: [PATCH] WIP: Show FollowingFragment in first run Auto-select @Odysee and @OdyseeHelp. --- .../java/com/odysee/app/FirstRunActivity.java | 53 +++++++++++++++---- .../app/ui/findcontent/FollowingFragment.java | 47 +++++++++++----- .../app/ui/firstrun/SignInFragment.java | 4 ++ .../odysee/app/utils/FirstRunStepHandler.java | 1 + .../main/res/layout/activity_first_run.xml | 7 +++ app/src/main/res/values/strings.xml | 2 +- 6 files changed, 92 insertions(+), 22 deletions(-) diff --git a/app/src/main/java/com/odysee/app/FirstRunActivity.java b/app/src/main/java/com/odysee/app/FirstRunActivity.java index 471f8a05..aeaa35d8 100644 --- a/app/src/main/java/com/odysee/app/FirstRunActivity.java +++ b/app/src/main/java/com/odysee/app/FirstRunActivity.java @@ -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; @@ -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; @@ -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; @@ -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); @@ -176,7 +182,7 @@ public void onError(Exception error) { buttonSkip.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { - finishFirstRun(); + onCompleted(currentStep); } }); @@ -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) @@ -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(); } @@ -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); } }); @@ -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); @@ -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)); } @@ -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(); @@ -447,7 +457,7 @@ public void onSuccess(List claims, boolean hasReachedEnd) { checkEmailVerifiedRewardForChannelStep(); } else { // this user already has a channel, move to the final step: rewards verification - proceedToRewardsStep(); + proceedToFollowStep(); } } @@ -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); @@ -505,6 +529,11 @@ public void run() { }); } + @Override + public void onSignInModeChanged(boolean signInMode) { + currentSignInMode = signInMode; + } + @Override public void onChannelNameUpdated(String channelName) { currentChannelName = channelName; @@ -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); @@ -636,7 +671,7 @@ public Fragment createFragment(int position) { @Override public int getItemCount() { - return 3; + return 4; } } diff --git a/app/src/main/java/com/odysee/app/ui/findcontent/FollowingFragment.java b/app/src/main/java/com/odysee/app/ui/findcontent/FollowingFragment.java index d2fb7918..0a4b771f 100644 --- a/app/src/main/java/com/odysee/app/ui/findcontent/FollowingFragment.java +++ b/app/src/main/java/com/odysee/app/ui/findcontent/FollowingFragment.java @@ -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; @@ -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; @@ -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; @@ -64,6 +67,7 @@ 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; @@ -71,6 +75,8 @@ import com.odysee.app.utils.Lbryio; import com.odysee.app.utils.Predefined; +import lombok.Setter; + public class FollowingFragment extends BaseFragment implements FetchSubscriptionsTask.FetchSubscriptionsHandler, ChannelItemSelectionListener, @@ -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) { @@ -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(); + } } } }); @@ -473,10 +487,14 @@ private Map buildSuggestedOptions() { canShowMatureContent = sp.getBoolean(MainActivity.PREFERENCE_KEY_SHOW_MATURE_CONTENT, false); } - ContentSources.Category primaryCategory = null; + ArrayList 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; } } @@ -485,10 +503,10 @@ private Map 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); @@ -1067,6 +1085,14 @@ public void onSuccess(List claims, boolean hasReachedEnd) { } if (suggestedChannelAdapter == null) { + // Put @Odysee and @OdyseeHelp channels at top of suggested + List 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) { @@ -1120,7 +1146,7 @@ public void onSuccess(List subscriptions) { } public void onError(Exception exception) { - + showError(exception.getLocalizedMessage()); } public void onChannelItemSelected(Claim claim) { @@ -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) { diff --git a/app/src/main/java/com/odysee/app/ui/firstrun/SignInFragment.java b/app/src/main/java/com/odysee/app/ui/firstrun/SignInFragment.java index 32967aa5..8c9def7f 100644 --- a/app/src/main/java/com/odysee/app/ui/firstrun/SignInFragment.java +++ b/app/src/main/java/com/odysee/app/ui/firstrun/SignInFragment.java @@ -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); + } } }); diff --git a/app/src/main/java/com/odysee/app/utils/FirstRunStepHandler.java b/app/src/main/java/com/odysee/app/utils/FirstRunStepHandler.java index e4e73168..2f2229f7 100644 --- a/app/src/main/java/com/odysee/app/utils/FirstRunStepHandler.java +++ b/app/src/main/java/com/odysee/app/utils/FirstRunStepHandler.java @@ -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(); diff --git a/app/src/main/res/layout/activity_first_run.xml b/app/src/main/res/layout/activity_first_run.xml index 7094e54c..ff00beaf 100644 --- a/app/src/main/res/layout/activity_first_run.xml +++ b/app/src/main/res/layout/activity_first_run.xml @@ -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" /> + + diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 596e8584..7d3cfb56 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -66,7 +66,7 @@ Find Channels to follow Discover - 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. + Odysee works better if you follow at least 5 creators you like. Please select up to 5 creators to continue. %1$d remaining… Done