Threadly’s Stories feature allows users to share photos and videos that disappear after 24 hours. Stories appear in a horizontal scrollable feed at the top of the home screen.
The StoriesManager handles all story-related operations:
network_managers/StoriesManager.java
public class StoriesManager { SharedPreferences loginInfo; public StoriesManager(){ this.loginInfo = Core.getPreference(); } // Add a new story public void AddStory(File media, String Type, NetworkCallbackInterfaceWithProgressTracking callback) // Get stories from followed users public void getStories(NetworkCallbackInterfaceWithJsonObjectDelivery callback) // Get stories of a specific user public void getStoriesOf(String Userid, NetworkCallbackInterfaceWithJsonObjectDelivery callback) // Get my own stories public void getMyStories(NetworkCallbackInterfaceWithJsonObjectDelivery callback) // Delete a story public void RemoveStory(int storyId, NetworkCallbackInterface callback)}
// Load my storiesstoriesViewModel.getMyStories().observe(getViewLifecycleOwner(), storyMediaModels -> { if(!storyMediaModels.isEmpty()){ // User has active stories - show colored ring mainXml.StoryOuterBorderColor.setBackground( AppCompatResources.getDrawable(requireActivity(), R.drawable.red_circle) ); mainXml.addStorySymbol.setVisibility(View.GONE); mainXml.MyStoryUsername.setText(R.string.your_story); mainXml.myStoryLayoutMain.setVisibility(View.VISIBLE); } else { // No stories - show add button mainXml.myStoryLayoutMain.setVisibility(View.VISIBLE); mainXml.addStorySymbol.setVisibility(View.VISIBLE); }});
// Story viewer with swipe navigationStoriesViewpagerAdapter adapter = new StoriesViewpagerAdapter( this, storyList, currentPosition);viewPager.setAdapter(adapter);viewPager.setCurrentItem(currentPosition);
// Play story videoExoplayerUtil.playNoLoop(Uri.parse(storyUrl), playerView);// Auto-advance to next story when video endsexoplayer.addListener(new Player.Listener() { @Override public void onPlaybackStateChanged(int state) { if (state == Player.STATE_ENDED) { // Move to next story viewPager.setCurrentItem(viewPager.getCurrentItem() + 1); } }});
Multiple stories from one user show progress bars:
// Show progress bars for each story segmentLinearLayout progressBarsContainer = findViewById(R.id.progress_bars);for (int i = 0; i < storyCount; i++) { ProgressBar progressBar = new ProgressBar(this, null, android.R.attr.progressBarStyleHorizontal); progressBar.setMax(100); progressBarsContainer.addView(progressBar);}// Animate current story progressValueAnimator animator = ValueAnimator.ofInt(0, 100);animator.setDuration(5000); // 5 seconds per storyanimator.addUpdateListener(animation -> { int progress = (int) animation.getAnimatedValue(); currentProgressBar.setProgress(progress);});animator.start();