Skip to content

Commit

Permalink
#4 Create View Home
Browse files Browse the repository at this point in the history
  • Loading branch information
victorr97 committed Apr 4, 2020
1 parent e23fd04 commit 4a6103a
Show file tree
Hide file tree
Showing 6 changed files with 230 additions and 95 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package salle.android.projects.registertest.controller.adapters;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import java.util.ArrayList;

import salle.android.projects.registertest.R;

public class GenresAdapter extends RecyclerView.Adapter<GenresAdapter.ViewHolder> {

public static final String TAG = GenresAdapter.class.getName();

private ArrayList<String> mGenres;

public GenresAdapter(ArrayList<String> genres) {
mGenres = genres;
}

@NonNull
@Override
public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_genre, parent, false);
return new GenresAdapter.ViewHolder(v);
}

@Override
public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
holder.tvName.setText(mGenres.get(position));
}

@Override
public int getItemCount() {
return (mGenres != null ? mGenres.size() : 0);
}

public class ViewHolder extends RecyclerView.ViewHolder {

Button tvName;

public ViewHolder(@NonNull View itemView) {
super(itemView);
tvName = (Button) itemView.findViewById(R.id.item_genre_btn);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,32 +1,48 @@
package salle.android.projects.registertest.controller.fragments;

import android.os.Bundle;
import android.os.Handler;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageButton;
import android.widget.SeekBar;
import android.widget.TextView;
import android.widget.Toast;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

import salle.android.projects.registertest.R;
import salle.android.projects.registertest.controller.adapters.GenresAdapter;
import salle.android.projects.registertest.controller.adapters.PlaylistListAdapter;
import salle.android.projects.registertest.controller.callbacks.PlaylistAdapterCallback;
import salle.android.projects.registertest.model.Genre;
import salle.android.projects.registertest.model.Playlist;
import salle.android.projects.registertest.model.Track;
import salle.android.projects.registertest.restapi.callback.GenreCallback;
import salle.android.projects.registertest.restapi.callback.PlaylistCallback;
import salle.android.projects.registertest.restapi.manager.GenreManager;
import salle.android.projects.registertest.restapi.manager.PlaylistManager;

public class HomeFragment extends Fragment implements PlaylistCallback, PlaylistAdapterCallback {

public class HomeFragment extends Fragment implements PlaylistCallback, PlaylistAdapterCallback, GenreCallback {

public static final String TAG = HomeFragment.class.getName();
private RecyclerView mRecyclerView;
private PlaylistListAdapter mAdapter;

private RecyclerView mPlaylistsView;
private PlaylistListAdapter mPlaylistAdapter;

private RecyclerView mGenresView;
private GenresAdapter mGenresAdapter;


public static HomeFragment getInstance() {
return new HomeFragment();
Expand All @@ -53,15 +69,23 @@ public void onResume() {
}

private void initViews(View v) {
GridLayoutManager mGridLayoutManager = new GridLayoutManager(getActivity(), 2);
mAdapter = new PlaylistListAdapter(null, getContext(), this, R.layout.playlist_item);
mRecyclerView = (RecyclerView) v.findViewById(R.id.home_recyclerview);
mRecyclerView.setLayoutManager(mGridLayoutManager);
mRecyclerView.setAdapter(mAdapter);
LinearLayoutManager managerPlaylists = new LinearLayoutManager(getActivity(), RecyclerView.HORIZONTAL, false);
mPlaylistAdapter = new PlaylistListAdapter(null, getContext(), null, R.layout.item_playlist_short);
mPlaylistsView = (RecyclerView) v.findViewById(R.id.home_playlists_recyclerview);
mPlaylistsView.setLayoutManager(managerPlaylists);
mPlaylistsView.setAdapter(mPlaylistAdapter);

GridLayoutManager gridLayoutManager = new GridLayoutManager(getActivity(), 3, RecyclerView.HORIZONTAL, false);
mGenresAdapter = new GenresAdapter(null);
mGenresView = (RecyclerView) v.findViewById(R.id.home_genres_recyclerview);
mGenresView.setLayoutManager(gridLayoutManager);
mGenresView.setAdapter(mGenresAdapter);
}

private void getData() {
PlaylistManager.getInstance(getContext()).getAllPlaylist(this);
GenreManager.getInstance(getContext())
.getAllGenres(this);
}

@Override
Expand All @@ -80,8 +104,8 @@ public void onPlaylistClick(Playlist playlist) {

@Override
public void onShowPlaylist(List<Playlist> playlists) {
mAdapter = new PlaylistListAdapter(playlists, getContext(), this, R.layout.playlist_item);
mRecyclerView.setAdapter(mAdapter);
mPlaylistAdapter = new PlaylistListAdapter(playlists, getContext(), this, R.layout.item_playlist_short);
mPlaylistsView.setAdapter(mPlaylistAdapter);
}

@Override
Expand All @@ -108,4 +132,20 @@ public void onUpdateSucces(Playlist playlist) {
public void onFailure(Throwable throwable) {
Toast.makeText(getContext(), "Something went wrong", Toast.LENGTH_LONG).show();
}

/**********************************************************************************************
* * * * * * * * GenreCallback * * * * * * * * *
**********************************************************************************************/

@Override
public void onGenresReceive(ArrayList<Genre> genres) {
ArrayList<String> genresString = (ArrayList<String>) genres.stream().map(Genre::getName).collect(Collectors.toList());
mGenresAdapter = new GenresAdapter(genresString);
mGenresView.setAdapter(mGenresAdapter);
}

@Override
public void onTracksByGenre(ArrayList<Track> tracks) {

}
}
66 changes: 0 additions & 66 deletions app/src/main/res/layout/activity_home.xml

This file was deleted.

72 changes: 54 additions & 18 deletions app/src/main/res/layout/fragment_home.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
android:background="@color/colorPrimary">

<com.scwang.wave.MultiWaveHeader
android:id="@+id/search_multiWaveHeader"
android:id="@+id/home_multiWaveHeader"
android:layout_width="match_parent"
android:layout_height="200dp"
android:rotation="-20"
Expand All @@ -19,25 +19,61 @@
app:mwhCloseColor="@color/colorSecondary"
app:mwhStartColor="@color/colorPrimary" />

<TextView
android:id="@+id/textView"
style="@style/fragmentTitle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="30dp"
android:text="@string/Home"
android:textAlignment="center"
app:layout_constraintTop_toTopOf="@+id/search_multiWaveHeader" />

<androidx.recyclerview.widget.RecyclerView
android:id="@+id/home_recyclerview"
<ScrollView
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_marginTop="30dp"
android:layout_marginBottom="30dp"
android:layout_marginStart="20dp"
android:layout_marginEnd="20dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textView" />
android:layout_marginBottom="10dp"
android:padding="10dp"
android:orientation="vertical"
app:layout_constraintTop_toTopOf="parent">

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="40dp"
android:orientation="vertical">

<TextView
style="@style/settings_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:text="@string/homeListaExitos" />

<androidx.recyclerview.widget.RecyclerView
android:id="@+id/home_playlists_recyclerview"
android:layout_width="match_parent"
android:layout_height="wrap_content" />

</LinearLayout>

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="40dp"
android:orientation="vertical">

<TextView
style="@style/settings_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:text="@string/homeListaGeneros" />

<androidx.recyclerview.widget.RecyclerView
android:id="@+id/home_genres_recyclerview"
android:layout_width="match_parent"
android:layout_height="wrap_content" />

</LinearLayout>

</LinearLayout>
</ScrollView>

</androidx.constraintlayout.widget.ConstraintLayout>
17 changes: 17 additions & 0 deletions app/src/main/res/layout/item_genre.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="wrap_content"
android:gravity="center"
android:layout_height="wrap_content">

<Button
android:id="@+id/item_genre_btn"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
style="@style/genre_item_text"
android:text="@string/create_song_genre"/>


</LinearLayout>
Loading

0 comments on commit 4a6103a

Please sign in to comment.