Commit e52ed63a authored by jade.woodward's avatar jade.woodward

this might eventually save stuff

i'm sorry for the terrible code
i'm tired
parent 447cb805
......@@ -7,6 +7,7 @@ import android.os.Bundle;
import android.util.Log;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.Toast;
import java.util.ArrayList;
......@@ -19,10 +20,6 @@ public class SavedPlaylists extends AppCompatActivity {
setContentView(R.layout.activity_saved_playlists);
playlists = getPreferences(Context.MODE_PRIVATE);
SharedPreferences.Editor editor = playlists.edit();
editor.putString("playlist 1", "1");
editor.commit();
ArrayList<String> saved = new ArrayList<>();
saved.add("Playlist " + playlists.getString("playlist 1", "0"));
......@@ -40,4 +37,27 @@ public class SavedPlaylists extends AppCompatActivity {
ArrayAdapter<String> adapter = new ArrayAdapter<>(this, android.R.layout.simple_list_item_1, saved);
listView.setAdapter(adapter);
}
/*
saves a playlist as a shared reference if there's space
produces a toast if not
needs the id stored in the databse as input
*/
public void savePlaylist(String databaseId) {
SharedPreferences.Editor editor = playlists.edit();
if (playlists.getString("playlist 1", "0").equals("0")) {
editor.putString("playlist 1", "id");
editor.commit();
} else if (playlists.getString("playlist 2", "0").equals("0")) {
editor.putString("playlist 2", "id");
editor.commit();
} else if (playlists.getString("playlist 3", "0").equals("0")) {
editor.putString("playlist 3", "id");
editor.commit();
} else {
Toast.makeText(getApplicationContext(),"Saved playlists full!", Toast.LENGTH_LONG).show();
}
}
}
package com.example.soulfood_assignment2;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
public class SavedPlaylists2 extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_saved_playlists2);
}
}
......@@ -107,7 +107,7 @@ public class databaseInterface {
* returns true if the playlist was made correctly
* returns false if something went wrong
*/
public Boolean savePlaylist(String title, ArrayList<String> spotifyIDs){
public String savePlaylist(String title, ArrayList<String> spotifyIDs){
HashMap<String, String> params = new HashMap<>();
params.put("title", title);
......@@ -128,10 +128,10 @@ public class databaseInterface {
param3.put("playlist", playlistid);
if(!getFromDatabase(url3, param3).equals("added a song to playlist")){
return false;
return "Failed to save to database";
}
}
return true;
return playlistid;
}
/*
......
......@@ -2,8 +2,11 @@ package com.example.soulfood_assignment2;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.Button;
import android.widget.ListView;
import java.util.ArrayList;
import static com.example.soulfood_assignment2.databaseInterface.Cuisine.american;
import static com.example.soulfood_assignment2.databaseInterface.Cuisine.any;
import static com.example.soulfood_assignment2.databaseInterface.Cuisine.chinese;
......@@ -91,5 +94,25 @@ public class playlistView extends AppCompatActivity {
thaiAsyncTask.listView = findViewById(R.id.playlistView);
thaiAsyncTask.execute();
playlistView = thaiAsyncTask.listView;
Button save = (Button)findViewById(R.id.saveButton);
save.setOnClickListener(save()); //when the button is pressed save should be implemeted
// but unfortunately i cant find the array list to put in
}
/*
needs an array list of songs
saves them in the databasee as a new playlist
saves the playlist as a shared preference
hopefully
*/
private void save(ArrayList<String> songs) {
databaseInterface dbi = new databaseInterface(); // so we can use database methods
String id = dbi.savePlaylist(songs); // save in the database, hopefully
// that method returns the saved id so we can put it in the shared preference
SavedPlaylists savedPlaylists = new SavedPlaylists(); //so we can save in the shared preference
savedPlaylists.savePlaylist(id); // saves as a shared preference
}
}
......@@ -17,7 +17,6 @@
android:layout_marginRight="8dp"
android:layout_marginBottom="8dp"
android:text="Saved Playlists"
app:layout_constraintBottom_toTopOf="@+id/_dynamic"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.498"
app:layout_constraintStart_toStartOf="parent"
......
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.soulfood_assignment2.SongScreenView">
<TextView
android:id="@+id/songName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="165dp"
android:layout_marginBottom="40dp"
android:text="TextView"
android:textColor="#000000"
android:textSize="36sp"
app:layout_constraintBottom_toTopOf="@+id/textView7"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.498"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="@+id/textView7"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="40dp"
android:layout_marginBottom="45dp"
android:text="Associated Tags"
android:textColor="#000000"
android:textSize="30sp"
app:layout_constraintBottom_toTopOf="@+id/vibeTagView"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.497"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/songName" />
<TextView
android:id="@+id/vibeTagView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="45dp"
android:text="TextView"
android:textColor="#000000"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textView7" />
<TextView
android:id="@+id/timeOfDayTagView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="45dp"
android:layout_marginBottom="45dp"
android:text="TextView"
android:textColor="#000000"
app:layout_constraintBottom_toTopOf="@+id/cuisineTagView"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/vibeTagView" />
<TextView
android:id="@+id/cuisineTagView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="45dp"
android:text="TextView"
android:textColor="#000000"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/timeOfDayTagView" />
<Button
android:id="@+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Play/Pause"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.498"
app:layout_constraintStart_toStartOf="parent"
tools:layout_editor_absoluteY="611dp" />
</android.support.constraint.ConstraintLayout>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment