Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
SidarthK committed Apr 21, 2024
2 parents 0ba228a + 43faf7c commit 40b05b2
Show file tree
Hide file tree
Showing 10 changed files with 498 additions and 12 deletions.
6 changes: 6 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,13 @@
android:name=".ArtistsActivity"
android:exported="true"></activity>
<activity

android:name=".ForYouActivity"

android:name=".SavedTrackWrappedActivity"
android:exported="true"></activity>
<activity
android:name=".SavedArtistWrappedActivity"
android:exported="true"></activity>

<meta-data
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,31 @@
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.Spinner;
import android.widget.TextView;
import android.widget.Toast;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;
import androidx.constraintlayout.widget.ConstraintLayout;

import com.bumptech.glide.Glide;
import com.example.spotifywrapped2340.ObjectStructures.Artist;
import com.example.spotifywrapped2340.ObjectStructures.Track;
import com.example.spotifywrapped2340.SpotifyDataManagers.SpotifyManager;
import com.google.android.gms.tasks.OnSuccessListener;
import com.google.firebase.firestore.FirebaseFirestore;

import java.util.HashMap;

import org.json.JSONException;

import java.util.ArrayList;

Expand All @@ -40,8 +51,18 @@ public class ArtistWrapped extends AppCompatActivity implements StoriesProgressV

private ImageView imageView;


private ArrayList<Artist> topArtists = SpotifyManager.topArtistsShort; //change if necessary

public ArtistWrapped(String json) throws JSONException {
SpotifyManager.getInstance(ArtistWrapped.this).fetchTopArtists(json);
}

public ArtistWrapped(){}

private Button saveButton;



@Override
protected void onStart() {
Expand Down Expand Up @@ -116,7 +137,39 @@ public void onClick(View v) {
}
});


saveButton = (Button) findViewById(R.id.save_button);

FirebaseFirestore db = FirebaseFirestore.getInstance();
AlertDialog.Builder builder = new AlertDialog.Builder(ArtistWrapped.this);
final EditText edittext = new EditText(ArtistWrapped.this);
builder.setView(edittext);
builder.setTitle("Name your Wrapped");
HashMap<String, Object> nestedData = new HashMap<>();
builder
.setPositiveButton("Save", (dialog, which) -> {
nestedData.put("json", SpotifyManager.getInstance(getApplicationContext()).artistString);
nestedData.put("image_url", SpotifyManager.topTracks.get(0).getAlbumCoverURL());
nestedData.put("wrapped_name", edittext.getText().toString());
db.collection("Users").document(SpotifyManager.getInstance(getApplicationContext()).user.getUserId()).collection("artistpaths").document().set(nestedData).addOnSuccessListener(new OnSuccessListener<Void>() {
@Override
public void onSuccess(Void unused) {
Log.d("SUCCESS", "RAHHHH");
}
});
Log.d("Dialog", SpotifyManager.getInstance(getApplicationContext()).user.getUserId());

})
.setNegativeButton("Cancel", (dialog, which) -> {

});

AlertDialog dialog = builder.create();
saveButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
dialog.show();
}
});



Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ protected void onCreate(@Nullable Bundle savedInstanceState) {
ProfileGridItem[] gridItems = new ProfileGridItem[]{
new ProfileGridItem("Tracks", R.drawable.tracks_placeholder_card_image, new TracksActivity()),
new ProfileGridItem("Artists", R.drawable.artists_placeholder_card, new ArtistWrapped()),
new ProfileGridItem("Playlists", R.drawable.playlists_placeholder_card, new TracksActivity()),
new ProfileGridItem("Lyrics", R.drawable.lyrics_placeholder_card, new TracksActivity()),
new ProfileGridItem("Past Track Wraps", R.drawable.playlists_placeholder_card, new SavedTrackWrappedActivity()),
new ProfileGridItem("Past Artist Wraps", R.drawable.lyrics_placeholder_card, new SavedArtistWrappedActivity()),
new ProfileGridItem("For You", R.drawable.foryou_placeholder_card, new ForYouActivity()),
new ProfileGridItem("Browse", R.drawable.browse_placeholder_card, new TracksActivity())
};
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
package com.example.spotifywrapped2340;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.GridLayout;
import android.widget.ImageButton;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.content.ContextCompat;

import com.example.spotifywrapped2340.SpotifyDataManagers.SpotifyManager;
import com.example.spotifywrapped2340.UIHelpers.ProfileGridItem;
import com.example.spotifywrapped2340.util.CompletionListener;
import com.google.android.gms.tasks.OnCompleteListener;
import com.google.android.gms.tasks.Task;
import com.google.common.util.concurrent.Futures;

import java.io.IOException;

import com.google.ai.client.generativeai.GenerativeModel;
import com.google.ai.client.generativeai.java.GenerativeModelFutures;
import com.google.ai.client.generativeai.type.Content;
import com.google.ai.client.generativeai.type.GenerateContentResponse;
import com.google.common.util.concurrent.FutureCallback;
import com.google.common.util.concurrent.ListenableFuture;
import com.google.firebase.firestore.FirebaseFirestore;
import com.google.firebase.firestore.QueryDocumentSnapshot;
import com.google.firebase.firestore.QuerySnapshot;
import com.spotify.sdk.android.auth.AuthorizationClient;
import com.spotify.sdk.android.auth.AuthorizationRequest;
import com.spotify.sdk.android.auth.AuthorizationResponse;

import org.json.JSONException;

import java.util.ArrayList;
import java.util.concurrent.Executor;

public class SavedArtistWrappedActivity extends AppCompatActivity {

private GridLayout gridLayout;

@Override
protected void onStart() {
super.onStart();
//SpotifyManager manager = SpotifyManager.getInstance(getApplicationContext());
//manager.fetchTopArtists(SpotifyManager.TopItemType.artists, "medium_range", 10);

}

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

gridLayout = findViewById(R.id.gridLayout2);
ArrayList<ProfileGridItem> gridItemArrayList = new ArrayList<>();
FirebaseFirestore db = FirebaseFirestore.getInstance();

db.collection("Users").document(SpotifyManager.getInstance(getApplicationContext()).user.getUserId()).collection("artistpaths").get().addOnCompleteListener(new OnCompleteListener<QuerySnapshot>() {
@Override
public void onComplete(@NonNull Task<QuerySnapshot> task) {
if (task.isSuccessful()) {
for (QueryDocumentSnapshot snapshot : task.getResult()) {
try {
gridItemArrayList.add(new ProfileGridItem(snapshot.get("wrapped_name").toString(), R.drawable.spotify_wrapped_login_logo, new ArtistWrapped(snapshot.get("json").toString())));
} catch (JSONException e) {
throw new RuntimeException(e);
}
}
updateGridLayout(gridItemArrayList);
}
}
});




}


private void updateGridLayout(ArrayList<ProfileGridItem> itemsList) {
// Clear existing views in GridLayout
gridLayout.removeAllViews();

// Add new views based on the data list
for (ProfileGridItem item : itemsList) {
// Inflate a new instance of your grid item layout
LayoutInflater inflater = LayoutInflater.from(getApplicationContext());
View itemView = inflater.inflate(R.layout.item_layout, gridLayout, false);

// Bind data to the layout
ImageButton imageButton = (ImageButton) itemView.findViewById(R.id.card_image);
TextView textView = itemView.findViewById(R.id.card_text);

imageButton.setImageDrawable(ContextCompat.getDrawable(this, item.getImageResource()));
textView.setText(item.getText());

imageButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(getApplicationContext(), item.getActivity().getClass());
startActivity(intent);
finish();
}
});

// Add the inflated view to the GridLayout
gridLayout.addView(itemView);
}
}


}
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
package com.example.spotifywrapped2340;

import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.GridLayout;
import android.widget.ImageButton;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.content.ContextCompat;

import com.example.spotifywrapped2340.SpotifyDataManagers.SpotifyManager;
import com.example.spotifywrapped2340.UIHelpers.ProfileGridItem;
import com.example.spotifywrapped2340.util.CompletionListener;
import com.google.android.gms.tasks.OnCompleteListener;
import com.google.android.gms.tasks.Task;
import com.google.common.util.concurrent.Futures;

import java.io.IOException;

import com.google.ai.client.generativeai.GenerativeModel;
import com.google.ai.client.generativeai.java.GenerativeModelFutures;
import com.google.ai.client.generativeai.type.Content;
import com.google.ai.client.generativeai.type.GenerateContentResponse;
import com.google.common.util.concurrent.FutureCallback;
import com.google.common.util.concurrent.ListenableFuture;
import com.google.firebase.firestore.FirebaseFirestore;
import com.google.firebase.firestore.QueryDocumentSnapshot;
import com.google.firebase.firestore.QuerySnapshot;
import com.spotify.sdk.android.auth.AuthorizationClient;
import com.spotify.sdk.android.auth.AuthorizationRequest;
import com.spotify.sdk.android.auth.AuthorizationResponse;

import org.json.JSONException;

import java.util.ArrayList;
import java.util.concurrent.Executor;

public class SavedTrackWrappedActivity extends AppCompatActivity {

private GridLayout gridLayout;

@Override
protected void onStart() {
super.onStart();
//SpotifyManager manager = SpotifyManager.getInstance(getApplicationContext());
//manager.fetchTopArtists(SpotifyManager.TopItemType.artists, "medium_range", 10);

}

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

gridLayout = findViewById(R.id.gridLayout2);
ArrayList<ProfileGridItem> gridItemArrayList = new ArrayList<>();
FirebaseFirestore db = FirebaseFirestore.getInstance();

db.collection("Users").document(SpotifyManager.getInstance(getApplicationContext()).user.getUserId()).collection("trackpaths").get().addOnCompleteListener(new OnCompleteListener<QuerySnapshot>() {
@Override
public void onComplete(@NonNull Task<QuerySnapshot> task) {
if (task.isSuccessful()) {
for (QueryDocumentSnapshot snapshot : task.getResult()) {
try {
gridItemArrayList.add(new ProfileGridItem(snapshot.get("wrapped_name").toString(), R.drawable.spotify_wrapped_login_logo, new TracksActivity(snapshot.get("json").toString())));
} catch (JSONException e) {
throw new RuntimeException(e);
}
}
updateGridLayout(gridItemArrayList);
}
}
});




}


private void updateGridLayout(ArrayList<ProfileGridItem> itemsList) {
// Clear existing views in GridLayout
gridLayout.removeAllViews();

// Add new views based on the data list
for (ProfileGridItem item : itemsList) {
// Inflate a new instance of your grid item layout
LayoutInflater inflater = LayoutInflater.from(getApplicationContext());
View itemView = inflater.inflate(R.layout.item_layout, gridLayout, false);

// Bind data to the layout
ImageButton imageButton = (ImageButton) itemView.findViewById(R.id.card_image);
TextView textView = itemView.findViewById(R.id.card_text);

imageButton.setImageDrawable(ContextCompat.getDrawable(this, item.getImageResource()));
textView.setText(item.getText());

imageButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(getApplicationContext(), item.getActivity().getClass());
startActivity(intent);
finish();
}
});

// Add the inflated view to the GridLayout
gridLayout.addView(itemView);
}
}


}
Loading

0 comments on commit 40b05b2

Please sign in to comment.