/*package com.ved.musicmapapp.providers;
import java.util.List;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import com.ved.musicmapapp.Objects.Artist;
import com.ved.musicmapapp.Objects.Song;
import com.ved.musicmapapp.Objects.User;
import com.ved.musicmapapp.adapters.DBAdapter;
import android.content.Context;
import android.content.SharedPreferences;
import android.os.AsyncTask;
public class SaveDataUserTask extends AsyncTask<Void, Void, Void> {
private SharedPreferences mSharedPreference;
private User user;
private Context context;
public SaveDataUserTask(Context context, User user) {
mSharedPreference = context.getSharedPreferences("MUSIC_MAP",
Context.MODE_PRIVATE);
this.context = context;
this.user = user;
}
@Override
protected Void doInBackground(Void... params) {
saveData();
return null;
}
private void saveData() {
if (user != null) {
try {
JSONArray jsonArray = new JSONArray();
JSONObject userJSONObject = new JSONObject();
userJSONObject.put("id", String.valueOf(user.getID()));
userJSONObject.put("username", user.getUserName());
userJSONObject.put("fbid", user.getFbid());
userJSONObject.put("first_name", user.getFirstName());
userJSONObject.put("last_name", user.getLastName());
userJSONObject.put("full_name", user.getFullName());
userJSONObject.put("email", user.getEmail());
userJSONObject.put("birthday", user.getBirthday());
userJSONObject.put("city", user.getCity());
userJSONObject.put("country", user.getCountry());
userJSONObject.put("address", user.getAddress());
userJSONObject.put("lat", String.valueOf(user.getLat()));
userJSONObject.put("lon", String.valueOf(user.getLon()));
userJSONObject.put("about_me", user.getAboutMe());
userJSONObject.put("gender", user.getGender());
userJSONObject.put("religion", user.getReligion());
userJSONObject.put("device_id", user.getDeviceId());
userJSONObject.put("join_date", user.getJoinDate());
userJSONObject.put("gcm_regid", user.getGcmRegId());
userJSONObject.put("noLastAdd",
String.valueOf(user.getNoLastAdd()));
userJSONObject.put("followMe", user.isFollowMe());
userJSONObject.put("percentage", user.getPercentage());
userJSONObject.put("followed", user.isFollowed() ? "1" : "0");
userJSONObject.put("startFollow",
String.valueOf(user.getStartFollow()));
userJSONObject.put("endFollow",
String.valueOf(user.getEndFollow()));
userJSONObject.put("noSong", user.getNoSong());
DBAdapter adapter = new DBAdapter(context);
adapter.addUser(user);
if (user.getArtists() != null) {
JSONArray artistsJSONArray = new JSONArray();
for (Artist artist : user.getArtists()) {
JSONObject artistJSONObject = new JSONObject();
artistJSONObject.put("user_artist_id",
artist.getUserArtistId());
artistJSONObject.put("id", artist.getID());
artistJSONObject.put("name", artist.getName());
artistJSONObject.put("avatar", artist.getAvatar());
artistJSONObject.put("last_update",
artist.getLatUpdate());
artistJSONObject.put("globalPlaylist",
artist.getGlobalPlaylist());
artistJSONObject.put("hasArtist", artist.isHasArtist());
artistJSONObject.put("isLiked", artist.isLiked() ? "1"
: "0");
artistJSONObject
.put("startLike", artist.getStartLike());
artistJSONObject.put("endLike", artist.getEndLike());
//Remove All Data
adapter.removeAllArtistAndSongByUser(user);
adapter.addArtist(artist, user);
JSONArray songsJSONArray = new JSONArray();
for (Song song : artist.getSongs()) {
JSONObject songJSONObject = new JSONObject();
songJSONObject.put("id", song.getID());
songJSONObject.put("title", song.getTitle());
songJSONObject.put("album", song.getAlbum());
songJSONObject.put("buyLink", song.getBuyLink());
songJSONObject.put("_7digital_id",
song.get7DigigtalTrackId());
songJSONObject.put("hasSong", song.isHasSong());
songJSONObject.put("isLiked", song.isLiked() ? "1"
: "0");
songJSONObject
.put("startLike", song.getStartLike());
songJSONObject.put("endLike", song.getEndLike());
songsJSONArray.put(songJSONObject);
adapter.addSong(song, artist, user.getID());
}
artistJSONObject.put("songs", songsJSONArray);
artistsJSONArray.put(artistJSONObject);
}
userJSONObject.put("artists", artistsJSONArray);
}
jsonArray.put(userJSONObject);
// mSharedPreference.edit()
// .putString("LAST_DATA", jsonArray.toString()).commit();
} catch (JSONException e) {
e.printStackTrace();
}
}
}
}
*/