Skip to content
This repository has been archived by the owner on Mar 9, 2023. It is now read-only.

Commit

Permalink
Changed the way landing page and searching works.
Browse files Browse the repository at this point in the history
  • Loading branch information
BuildTools committed Jul 12, 2019
1 parent a45ca22 commit 86aa5b8
Show file tree
Hide file tree
Showing 60 changed files with 953 additions and 212 deletions.
1 change: 1 addition & 0 deletions ApplicationClient/.idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion ApplicationClient/.idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -1,55 +1,51 @@
package com.twitchflix.applicationclient.landingpage;

import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.AsyncTask;
import android.os.Bundle;
import android.widget.SearchView;
import androidx.lifecycle.ViewModelProvider;
import androidx.lifecycle.ViewModelProviders;
import com.google.android.material.navigation.NavigationView;
import androidx.core.view.GravityCompat;
import androidx.drawerlayout.widget.DrawerLayout;
import androidx.appcompat.app.ActionBarDrawerToggle;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.ScrollView;
import android.widget.SearchView;
import android.widget.TextView;
import androidx.appcompat.app.ActionBarDrawerToggle;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar;
import androidx.core.view.GravityCompat;
import androidx.drawerlayout.widget.DrawerLayout;
import androidx.lifecycle.ViewModelProviders;
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;
import com.google.android.material.navigation.NavigationView;
import com.twitchflix.applicationclient.ClientApp;
import com.twitchflix.applicationclient.MainActivity;
import com.twitchflix.applicationclient.R;
import com.twitchflix.applicationclient.activities.AccountSettings;
import com.twitchflix.applicationclient.activities.Stream;
import com.twitchflix.applicationclient.channelview.ChannelView;
import com.twitchflix.applicationclient.landingpage.drawers.Drawer;
import com.twitchflix.applicationclient.landingpage.drawers.LandingPageDrawer;
import com.twitchflix.applicationclient.landingpage.drawers.SearchPageDrawer;
import com.twitchflix.applicationclient.rest.models.UserData;
import com.twitchflix.applicationclient.searchvideos.SearchActivity;
import com.twitchflix.applicationclient.utils.NetworkUser;
import com.twitchflix.applicationclient.viewmodels.LandingPageViewModel;

import java.io.ByteArrayOutputStream;
import java.util.List;
import java.util.Map;
import java.util.UUID;

public class LandingPage extends AppCompatActivity
implements NavigationView.OnNavigationItemSelectedListener {

private LandingPageViewModel pageViewModel;

private Drawer searchPageDrawer, landingPageDrawer;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_landing_page);

this.pageViewModel = ViewModelProviders.of(this).get(LandingPageViewModel.class);

this.pageViewModel.getLandingPageVideos().observe(this, (videos) -> {

});

setTitle("TwitchFlix");

Toolbar toolbar = findViewById(R.id.toolbar);
Expand Down Expand Up @@ -98,24 +94,35 @@ public boolean onCreateOptionsMenu(Menu menu) {
@Override
public boolean onQueryTextSubmit(String s) {

SearchActivity.start(LandingPage.this, s);
pageViewModel.setQueryString(s);

return true;
}

@Override
public boolean onQueryTextChange(String s) {
return false;

pageViewModel.setQueryString(s);

return true;
}
});

pageViewModel.getSearchQueryVideos().observe(this, (videos) -> {

searchPageDrawer.draw(videos);

});

return true;
}

@Override
public void onOptionsMenuClosed(Menu menu) {
super.onOptionsMenuClosed(menu);

pageViewModel.getSearchQueryVideos().removeObservers(this);

}

@Override
Expand Down Expand Up @@ -182,6 +189,22 @@ private void initAndDraw() {
String userFullName = userData.getFirstName() + " " + userData.getLastName();

userName.setText(userFullName);

SwipeRefreshLayout refreshLayout = findViewById(R.id.search_refresh);

ScrollView scrollView = refreshLayout.findViewById(R.id.scroll_search);

LinearLayout videoLayout = scrollView.findViewById(R.id.display_results);

this.searchPageDrawer = new SearchPageDrawer(this, videoLayout);

this.landingPageDrawer = new LandingPageDrawer(this, videoLayout);

this.pageViewModel.getLandingPageVideos().observe(this, (videos) -> {

landingPageDrawer.draw(videos);

});
}

private static class LogOut extends NetworkUser<Void, Void, Boolean> {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,32 @@
package com.twitchflix.applicationclient.landingpage.drawers;

public class Drawer {
import android.app.Activity;
import android.view.ViewGroup;
import com.twitchflix.applicationclient.viewmodels.LandingPageViewModel;

import java.util.List;

public abstract class Drawer {

private ViewGroup parentViewGroup;

private Activity parentActivity;

public Drawer(Activity parent, ViewGroup parentView) {

this.parentActivity = parent;
this.parentViewGroup = parentView;

}

protected Activity getParentActivity() {
return parentActivity;
}

protected ViewGroup getParentView() {
return parentViewGroup;
}

public abstract void draw(List<LandingPageViewModel.VideoDAO> videos);

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
package com.twitchflix.applicationclient.landingpage.drawers;

import android.app.Activity;
import android.view.ViewGroup;
import android.widget.HorizontalScrollView;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import com.twitchflix.applicationclient.landingpage.OnClickVideoListener;
import com.twitchflix.applicationclient.viewmodels.LandingPageViewModel;

import java.util.*;

public class LandingPageDrawer extends Drawer {

public LandingPageDrawer(Activity parent, ViewGroup parentView) {
super(parent, parentView);
}

@Override
public void draw(List<LandingPageViewModel.VideoDAO> videos) {

getParentView().removeAllViews();

Map<UUID, List<LandingPageViewModel.VideoDAO>> groupedVideos = new HashMap<>();

for (LandingPageViewModel.VideoDAO video : videos) {
List<LandingPageViewModel.VideoDAO> videoDAOS = groupedVideos.get(video.getUploader());

if (videoDAOS == null) {
videoDAOS = new ArrayList<>();
}

videoDAOS.add(video);

groupedVideos.put(video.getUploader(), videoDAOS);
}

for (Map.Entry<UUID, List<LandingPageViewModel.VideoDAO>> channels : groupedVideos.entrySet()) {

String channel_name_text = channels.getValue().get(0).getUploaderName();

TextView channel_name = new TextView(getParentActivity());

channel_name.setText(channel_name_text);

channel_name.setClickable(true);

channel_name.setTextSize(25);

ViewGroup.MarginLayoutParams viewParams = new ViewGroup.MarginLayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
ViewGroup.LayoutParams.WRAP_CONTENT);

viewParams.setMargins(10, 40, 0, 15);

channel_name.setLayoutParams(viewParams);

getParentView().addView(channel_name);

drawIntoView(getParentView(), channels.getValue());

}

}

private void drawIntoView(ViewGroup parent, List<LandingPageViewModel.VideoDAO> toDraw) {

HorizontalScrollView scrollingVideo = new HorizontalScrollView(getParentActivity());

scrollingVideo.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));

LinearLayout videos = new LinearLayout(getParentActivity());

videos.setOrientation(LinearLayout.HORIZONTAL);

videos.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT));

scrollingVideo.addView(videos);

parent.addView(scrollingVideo);

for (LandingPageViewModel.VideoDAO videoDAO : toDraw) {
drawIntoView(videos, videoDAO);
}
}

private void drawIntoView(ViewGroup parent, LandingPageViewModel.VideoDAO toDraw) {

LinearLayout linearVideoLayout = new LinearLayout(getParentActivity());

ViewGroup.MarginLayoutParams params = new ViewGroup.MarginLayoutParams(320, 300);

params.setMargins(15, 0, 0, 0);

linearVideoLayout.setLayoutParams(params);

linearVideoLayout.setOrientation(LinearLayout.VERTICAL);

linearVideoLayout.setClickable(true);

ImageView thumbnail = new ImageView(getParentActivity());

thumbnail.setLayoutParams(new ViewGroup.LayoutParams(320, 240));

thumbnail.setAdjustViewBounds(true);

thumbnail.setScaleType(ImageView.ScaleType.FIT_CENTER);

thumbnail.setImageBitmap(toDraw.getThumbnail());

TextView videoTitle = new TextView(getParentActivity());

videoTitle.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));

videoTitle.setText(toDraw.getTitle());

linearVideoLayout.addView(thumbnail);
linearVideoLayout.addView(videoTitle);

linearVideoLayout.setOnClickListener(new OnClickVideoListener(getParentActivity(), toDraw.getVideoID()));

parent.addView(linearVideoLayout);
}
}
Loading

0 comments on commit 86aa5b8

Please sign in to comment.