Finish basic DB update code. Start putting in skeleton of ui that will use the DB for albums.
This commit is contained in:
@@ -22,11 +22,13 @@ android {
|
||||
dependencies {
|
||||
compile fileTree(dir: 'libs', include: ['*.jar'])
|
||||
testCompile 'junit:junit:4.12'
|
||||
compile 'com.android.support:design:23.0.+'
|
||||
compile 'com.android.support:design:23.1.+'
|
||||
compile 'com.android.support:cardview-v7:23.0.+'
|
||||
compile 'com.heinrichreimersoftware:material-drawer:2.2.0' //Apache 2.0
|
||||
compile 'io.realm:realm-android:0.84.1' //Apache 2.0 + RCBL
|
||||
compile 'io.realm:realm-android:0.85.0' //Apache 2.0 + RCBL
|
||||
compile 'com.squareup.picasso:picasso:2.5.2' //Apache 2.0
|
||||
compile 'com.squareup.retrofit:retrofit:2.0.0-beta2'
|
||||
compile 'com.github.thorbenprimke:realm-recyclerview:0.9.5' //Apache 2.0
|
||||
compile 'com.squareup.retrofit:retrofit:2.0.0-beta2' //Apache 2.0
|
||||
compile ('com.squareup.retrofit:converter-simplexml:2.0.0-beta2') {
|
||||
exclude group: 'xpp3', module: 'xpp3'
|
||||
exclude group: 'stax', module: 'stax-api'
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
package com.magnatune.eyecreate.companionformagnatune.adapters;
|
||||
|
||||
import android.content.Context;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
import com.magnatune.eyecreate.companionformagnatune.model.Album;
|
||||
import com.magnatune.eyecreate.companionformagnatune.viewholders.AlbumViewHolder;
|
||||
|
||||
import io.realm.RealmBasedRecyclerViewAdapter;
|
||||
import io.realm.RealmResults;
|
||||
|
||||
public class AlbumsAdapter extends RealmBasedRecyclerViewAdapter<Album,AlbumViewHolder> {
|
||||
|
||||
public AlbumsAdapter(Context context, RealmResults<Album> realmResults, boolean automaticUpdate, boolean animateResults, String animateExtraColumnName) {
|
||||
super(context, realmResults, automaticUpdate, animateResults, animateExtraColumnName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public AlbumViewHolder onCreateRealmViewHolder(ViewGroup viewGroup, int i) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBindRealmViewHolder(AlbumViewHolder albumViewHolder, int i) {
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
package com.magnatune.eyecreate.companionformagnatune.fragments;
|
||||
|
||||
import android.support.v4.app.Fragment;
|
||||
|
||||
public class AlbumsFragment extends Fragment {
|
||||
|
||||
}
|
||||
@@ -1,7 +1,138 @@
|
||||
package com.magnatune.eyecreate.companionformagnatune.model;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
import io.realm.RealmList;
|
||||
import io.realm.RealmObject;
|
||||
import io.realm.annotations.PrimaryKey;
|
||||
|
||||
public class Album extends RealmObject {
|
||||
//TODO:fill
|
||||
|
||||
@PrimaryKey
|
||||
private String albumsku;
|
||||
private String albumname;
|
||||
private String artist;
|
||||
private String artistdesc;
|
||||
private String cover_small;
|
||||
private String cover_large;
|
||||
private String artistphoto;
|
||||
private int year;
|
||||
private String album_notes;
|
||||
private String homepage;
|
||||
private String mp3genre;
|
||||
private Date launchdate;
|
||||
private RealmList<MGenre> genres;
|
||||
private RealmList<Track> tracks;
|
||||
|
||||
public String getAlbumsku() {
|
||||
return albumsku;
|
||||
}
|
||||
|
||||
public void setAlbumsku(String albumsku) {
|
||||
this.albumsku = albumsku;
|
||||
}
|
||||
|
||||
public String getAlbumname() {
|
||||
return albumname;
|
||||
}
|
||||
|
||||
public void setAlbumname(String albumname) {
|
||||
this.albumname = albumname;
|
||||
}
|
||||
|
||||
public String getArtist() {
|
||||
return artist;
|
||||
}
|
||||
|
||||
public void setArtist(String artist) {
|
||||
this.artist = artist;
|
||||
}
|
||||
|
||||
public String getArtistdesc() {
|
||||
return artistdesc;
|
||||
}
|
||||
|
||||
public void setArtistdesc(String artistdesc) {
|
||||
this.artistdesc = artistdesc;
|
||||
}
|
||||
|
||||
public String getCover_small() {
|
||||
return cover_small;
|
||||
}
|
||||
|
||||
public void setCover_small(String cover_small) {
|
||||
this.cover_small = cover_small;
|
||||
}
|
||||
|
||||
public String getCover_large() {
|
||||
return cover_large;
|
||||
}
|
||||
|
||||
public void setCover_large(String cover_large) {
|
||||
this.cover_large = cover_large;
|
||||
}
|
||||
|
||||
public String getArtistphoto() {
|
||||
return artistphoto;
|
||||
}
|
||||
|
||||
public void setArtistphoto(String artistphoto) {
|
||||
this.artistphoto = artistphoto;
|
||||
}
|
||||
|
||||
public int getYear() {
|
||||
return year;
|
||||
}
|
||||
|
||||
public void setYear(int year) {
|
||||
this.year = year;
|
||||
}
|
||||
|
||||
public String getAlbum_notes() {
|
||||
return album_notes;
|
||||
}
|
||||
|
||||
public void setAlbum_notes(String album_notes) {
|
||||
this.album_notes = album_notes;
|
||||
}
|
||||
|
||||
public String getHomepage() {
|
||||
return homepage;
|
||||
}
|
||||
|
||||
public void setHomepage(String homepage) {
|
||||
this.homepage = homepage;
|
||||
}
|
||||
|
||||
public String getMp3genre() {
|
||||
return mp3genre;
|
||||
}
|
||||
|
||||
public void setMp3genre(String mp3genre) {
|
||||
this.mp3genre = mp3genre;
|
||||
}
|
||||
|
||||
public Date getLaunchdate() {
|
||||
return launchdate;
|
||||
}
|
||||
|
||||
public void setLaunchdate(Date launchdate) {
|
||||
this.launchdate = launchdate;
|
||||
}
|
||||
|
||||
public RealmList<MGenre> getGenres() {
|
||||
return genres;
|
||||
}
|
||||
|
||||
public void setGenres(RealmList<MGenre> genres) {
|
||||
this.genres = genres;
|
||||
}
|
||||
|
||||
public RealmList<Track> getTracks() {
|
||||
return tracks;
|
||||
}
|
||||
|
||||
public void setTracks(RealmList<Track> tracks) {
|
||||
this.tracks = tracks;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,6 +9,6 @@ import java.util.List;
|
||||
public class AlbumResponse {
|
||||
|
||||
@ElementList(inline=true)
|
||||
public List<Album> albums;
|
||||
public List<com.magnatune.eyecreate.companionformagnatune.model.xml.Album> albums;
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
package com.magnatune.eyecreate.companionformagnatune.model;
|
||||
|
||||
import io.realm.RealmObject;
|
||||
import io.realm.annotations.PrimaryKey;
|
||||
|
||||
public class MGenre extends RealmObject {
|
||||
@PrimaryKey
|
||||
private String genre_name;
|
||||
|
||||
public String getGenre_name() {
|
||||
return genre_name;
|
||||
}
|
||||
|
||||
public void setGenre_name(String genre_name) {
|
||||
this.genre_name = genre_name;
|
||||
}
|
||||
}
|
||||
@@ -1,18 +1,124 @@
|
||||
package com.magnatune.eyecreate.companionformagnatune.model;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.support.v4.content.LocalBroadcastManager;
|
||||
|
||||
import com.magnatune.eyecreate.companionformagnatune.MagnatuneCompainionApplication;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import io.realm.Realm;
|
||||
import io.realm.RealmList;
|
||||
import retrofit.Response;
|
||||
|
||||
public class MagnatuneDBManager {
|
||||
|
||||
public static final String ACTION_DB_UPDATE_DONE = "dbupdatedone";
|
||||
private static final String DB_CHECK_PREFS = "dbcheckprefs";
|
||||
private static final String SP_KEY_DB_HASH = "dbhash";
|
||||
|
||||
public static void updateDB() {
|
||||
//TODO:check if should update
|
||||
//TODO:update realm DB
|
||||
//This method should be called on another thread
|
||||
//Check if DB should update
|
||||
SharedPreferences prefs = MagnatuneCompainionApplication.getApplication().getSharedPreferences(DB_CHECK_PREFS, Context.MODE_PRIVATE);
|
||||
boolean shouldUpdate = false;
|
||||
if(prefs.contains(SP_KEY_DB_HASH)) {
|
||||
String hash = "";
|
||||
try {
|
||||
hash = MagnatuneCompainionApplication.getDataApi().getUpdateChecksum().execute().body();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
if(!hash.equals(prefs.getString(SP_KEY_DB_HASH,""))) {
|
||||
shouldUpdate = true;
|
||||
prefs.edit().putString(SP_KEY_DB_HASH,hash).apply();
|
||||
}
|
||||
} else {
|
||||
try {
|
||||
shouldUpdate = true;
|
||||
prefs.edit().putString(SP_KEY_DB_HASH,MagnatuneCompainionApplication.getDataApi().getUpdateChecksum().execute().body()).apply();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
if(shouldUpdate) {
|
||||
//Update DB
|
||||
try {
|
||||
Response<AlbumResponse> response = MagnatuneCompainionApplication.getDataApi().getAlbumList().execute();
|
||||
Realm db = getAlbumDB();
|
||||
db.beginTransaction();
|
||||
for(com.magnatune.eyecreate.companionformagnatune.model.xml.Album album:response.body().albums) {
|
||||
db.copyToRealmOrUpdate(xmlAlbumToDBAlbum(album));
|
||||
}
|
||||
db.commitTransaction();
|
||||
db.close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
//Broadcast Refresh done.
|
||||
LocalBroadcastManager.getInstance(MagnatuneCompainionApplication.getApplication()).sendBroadcast(new Intent(ACTION_DB_UPDATE_DONE));
|
||||
}
|
||||
|
||||
public static Realm getAlbumDB() {
|
||||
//Remember to close each instance when done.
|
||||
return Realm.getInstance(MagnatuneCompainionApplication.getAlbumDBConfig());
|
||||
}
|
||||
|
||||
public static RealmList<MGenre> genreCSVStringToMGenreList(String xmlgenres) {
|
||||
List<String> genres = Arrays.asList(xmlgenres.split(","));
|
||||
RealmList<MGenre> DBgenres = new RealmList<>();
|
||||
for(String genre:genres) {
|
||||
MGenre mGenre = new MGenre();
|
||||
mGenre.setGenre_name(genre);
|
||||
DBgenres.add(mGenre);
|
||||
}
|
||||
return DBgenres;
|
||||
}
|
||||
|
||||
public static Album xmlAlbumToDBAlbum(com.magnatune.eyecreate.companionformagnatune.model.xml.Album album) {
|
||||
Album entry = new Album();
|
||||
entry.setAlbumsku(album.albumsku);
|
||||
entry.setAlbumname(album.albumname);
|
||||
entry.setArtist(album.artist);
|
||||
entry.setArtistdesc(album.artistdesc);
|
||||
entry.setAlbum_notes(album.album_notes);
|
||||
entry.setCover_small(album.cover_small);
|
||||
entry.setCover_large(album.cover_small.replace("200", "800"));
|
||||
entry.setArtistphoto(album.artistphoto);
|
||||
entry.setYear(album.year);
|
||||
entry.setHomepage(album.home);
|
||||
entry.setMp3genre(album.mp3genre);
|
||||
entry.setLaunchdate(album.launchdate);
|
||||
entry.setGenres(genreCSVStringToMGenreList(album.magnatunegenres));
|
||||
RealmList<Track> tracks = new RealmList<>();
|
||||
for(com.magnatune.eyecreate.companionformagnatune.model.xml.Track track:album.tracks) {
|
||||
tracks.add(xmlTrackToDBTrack(track));
|
||||
}
|
||||
entry.setTracks(tracks);
|
||||
return entry;
|
||||
}
|
||||
|
||||
public static Track xmlTrackToDBTrack(com.magnatune.eyecreate.companionformagnatune.model.xml.Track track) {
|
||||
Track entry = new Track();
|
||||
entry.setIsrc(track.isrc);
|
||||
entry.setTrackname(track.trackname);
|
||||
entry.setArtist(track.artist);
|
||||
entry.setAlbumname(track.albumname);
|
||||
entry.setTracknumber(track.tracknum);
|
||||
entry.setYear(track.year);
|
||||
entry.setMp3genre(track.mp3genre);
|
||||
entry.setGenres(genreCSVStringToMGenreList(track.magnatunegenres));
|
||||
entry.setLicense(track.license);
|
||||
entry.setSeconds(track.seconds);
|
||||
entry.setUrl(track.url);
|
||||
entry.setMp3_low_quality(track.mp3lofi);
|
||||
entry.setOgg_url(track.oggurl);
|
||||
return entry;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,127 @@
|
||||
package com.magnatune.eyecreate.companionformagnatune.model;
|
||||
|
||||
import io.realm.RealmList;
|
||||
import io.realm.RealmObject;
|
||||
import io.realm.annotations.PrimaryKey;
|
||||
|
||||
public class Track extends RealmObject {
|
||||
//TODO:fill
|
||||
|
||||
@PrimaryKey
|
||||
private String isrc;
|
||||
private String trackname;
|
||||
private String artist;
|
||||
private String albumname;
|
||||
private int tracknumber;
|
||||
private int year;
|
||||
private String mp3genre;
|
||||
private RealmList<MGenre> genres;
|
||||
private String license;
|
||||
private long seconds;
|
||||
private String url;
|
||||
private String mp3_low_quality;
|
||||
private String ogg_url;
|
||||
|
||||
public String getIsrc() {
|
||||
return isrc;
|
||||
}
|
||||
|
||||
public void setIsrc(String isrc) {
|
||||
this.isrc = isrc;
|
||||
}
|
||||
|
||||
public String getTrackname() {
|
||||
return trackname;
|
||||
}
|
||||
|
||||
public void setTrackname(String trackname) {
|
||||
this.trackname = trackname;
|
||||
}
|
||||
|
||||
public String getArtist() {
|
||||
return artist;
|
||||
}
|
||||
|
||||
public void setArtist(String artist) {
|
||||
this.artist = artist;
|
||||
}
|
||||
|
||||
public String getAlbumname() {
|
||||
return albumname;
|
||||
}
|
||||
|
||||
public void setAlbumname(String albumname) {
|
||||
this.albumname = albumname;
|
||||
}
|
||||
|
||||
public int getTracknumber() {
|
||||
return tracknumber;
|
||||
}
|
||||
|
||||
public void setTracknumber(int tracknumber) {
|
||||
this.tracknumber = tracknumber;
|
||||
}
|
||||
|
||||
public int getYear() {
|
||||
return year;
|
||||
}
|
||||
|
||||
public void setYear(int year) {
|
||||
this.year = year;
|
||||
}
|
||||
|
||||
public String getMp3genre() {
|
||||
return mp3genre;
|
||||
}
|
||||
|
||||
public void setMp3genre(String mp3genre) {
|
||||
this.mp3genre = mp3genre;
|
||||
}
|
||||
|
||||
public RealmList<MGenre> getGenres() {
|
||||
return genres;
|
||||
}
|
||||
|
||||
public void setGenres(RealmList<MGenre> genres) {
|
||||
this.genres = genres;
|
||||
}
|
||||
|
||||
public String getLicense() {
|
||||
return license;
|
||||
}
|
||||
|
||||
public void setLicense(String license) {
|
||||
this.license = license;
|
||||
}
|
||||
|
||||
public long getSeconds() {
|
||||
return seconds;
|
||||
}
|
||||
|
||||
public void setSeconds(long seconds) {
|
||||
this.seconds = seconds;
|
||||
}
|
||||
|
||||
public String getUrl() {
|
||||
return url;
|
||||
}
|
||||
|
||||
public void setUrl(String url) {
|
||||
this.url = url;
|
||||
}
|
||||
|
||||
public String getMp3_low_quality() {
|
||||
return mp3_low_quality;
|
||||
}
|
||||
|
||||
public void setMp3_low_quality(String mp3_low_quality) {
|
||||
this.mp3_low_quality = mp3_low_quality;
|
||||
}
|
||||
|
||||
public String getOgg_url() {
|
||||
return ogg_url;
|
||||
}
|
||||
|
||||
public void setOgg_url(String ogg_url) {
|
||||
this.ogg_url = ogg_url;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -43,6 +43,9 @@ public class Album {
|
||||
@Element
|
||||
public Date launchdate;
|
||||
|
||||
@Element
|
||||
public String albumsku;
|
||||
|
||||
@ElementList(inline=true)
|
||||
public List<Track> tracks;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
package com.magnatune.eyecreate.companionformagnatune.viewholders;
|
||||
|
||||
import android.view.View;
|
||||
|
||||
import io.realm.RealmViewHolder;
|
||||
|
||||
public class AlbumViewHolder extends RealmViewHolder {
|
||||
public AlbumViewHolder(View itemView) {
|
||||
super(itemView);
|
||||
}
|
||||
}
|
||||
@@ -1,11 +1,9 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
|
||||
android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin"
|
||||
android:paddingRight="@dimen/activity_horizontal_margin"
|
||||
android:paddingTop="@dimen/activity_vertical_margin"
|
||||
android:paddingBottom="@dimen/activity_vertical_margin" tools:context=".BrowseActivity">
|
||||
android:layout_height="match_parent" tools:context=".BrowseActivity">
|
||||
|
||||
<TextView android:text="Hello World!" android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content" />
|
||||
<View android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:id="@+id/fragment_holder"/>
|
||||
</RelativeLayout>
|
||||
|
||||
11
app/src/main/res/layout/fragment_albums.xml
Normal file
11
app/src/main/res/layout/fragment_albums.xml
Normal file
@@ -0,0 +1,11 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<SwipeRefreshLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:id="@+id/swipe_layout">
|
||||
<co.moonmonkeylabs.realmrecyclerview.RealmRecyclerView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent" android:id="@+id/album_grid"
|
||||
app:rrvLayoutType="Grid" app:rrvIsRefreshable="true" app:rrvGridLayoutSpanCount="2"/>
|
||||
</SwipeRefreshLayout>
|
||||
17
app/src/main/res/layout/listitem_album_card.xml
Normal file
17
app/src/main/res/layout/listitem_album_card.xml
Normal file
@@ -0,0 +1,17 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<CardView xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
<ImageView
|
||||
android:layout_width="40dp"
|
||||
android:layout_height="40dp"
|
||||
android:id="@+id/album_art"/>
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content">
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:id="@+id/album_name"/>
|
||||
</LinearLayout>
|
||||
</CardView>
|
||||
Reference in New Issue
Block a user