-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added all network and adapter related operations
- Loading branch information
1 parent
8b93f80
commit 82ef454
Showing
12 changed files
with
940 additions
and
32 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 55 additions & 0 deletions
55
app/src/main/java/cc/soham/rxblrdroid/network/MusicAdapter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package cc.soham.rxblrdroid.network; | ||
|
||
import android.support.v7.widget.RecyclerView; | ||
import android.view.LayoutInflater; | ||
import android.view.View; | ||
import android.view.ViewGroup; | ||
import android.widget.TextView; | ||
|
||
import java.util.List; | ||
|
||
import butterknife.Bind; | ||
import butterknife.ButterKnife; | ||
import cc.soham.rxblrdroid.R; | ||
import cc.soham.rxblrdroid.objects.Result; | ||
|
||
/** | ||
* Created by sohammondal on 13/10/15. | ||
* Adapts the music {@Code Result} class to our {@code RecyclerView} | ||
*/ | ||
public class MusicAdapter extends RecyclerView.Adapter<MusicAdapter.ViewHolder> { | ||
private List<Result> results; | ||
|
||
public MusicAdapter(List<Result> results) { | ||
this.results = results; | ||
} | ||
|
||
@Override | ||
public MusicAdapter.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { | ||
View itemLayoutView = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_music, null); | ||
return new ViewHolder(itemLayoutView); | ||
} | ||
|
||
@Override | ||
public void onBindViewHolder(ViewHolder viewHolder, int position) { | ||
viewHolder.track.setText(results.get(position).getArtistName() + ", " + results.get(position).getTrackName()); | ||
viewHolder.time.setText(String.valueOf(results.get(position).getTrackTimeMillis())); | ||
} | ||
|
||
public static class ViewHolder extends RecyclerView.ViewHolder { | ||
@Bind(R.id.item_music_track) | ||
public TextView track; | ||
@Bind(R.id.item_music_time) | ||
public TextView time; | ||
|
||
public ViewHolder(View itemLayoutView) { | ||
super(itemLayoutView); | ||
ButterKnife.bind(this, itemLayoutView); | ||
} | ||
} | ||
|
||
@Override | ||
public int getItemCount() { | ||
return results.size(); | ||
} | ||
} |
40 changes: 40 additions & 0 deletions
40
app/src/main/java/cc/soham/rxblrdroid/network/MusicApi.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package cc.soham.rxblrdroid.network; | ||
|
||
import cc.soham.rxblrdroid.objects.NetworkResponse; | ||
import retrofit.Callback; | ||
import retrofit.RestAdapter; | ||
import retrofit.http.GET; | ||
import retrofit.http.Query; | ||
import rx.Observable; | ||
|
||
/** | ||
* Created by sohammondal on 12/10/15. | ||
* Handles all network operations | ||
*/ | ||
public class MusicApi { | ||
private static final String API_URL = "https://itunes.apple.com"; | ||
private static MusicApiInterface sMusicApiInterface; | ||
|
||
public static MusicApiInterface getApi() { | ||
if (sMusicApiInterface == null) { | ||
sMusicApiInterface = null; | ||
RestAdapter restAdapter = new RestAdapter.Builder() | ||
.setEndpoint(API_URL) | ||
.build(); | ||
|
||
sMusicApiInterface = restAdapter.create(MusicApiInterface.class); | ||
} | ||
return sMusicApiInterface; | ||
} | ||
|
||
public interface MusicApiInterface { | ||
@GET("/search?entity=musicVideo") | ||
NetworkResponse getMusic(@Query("term") String term); | ||
|
||
@GET("/search?entity=musicVideo") | ||
void getMusic(@Query("term") String term, Callback<NetworkResponse> networkResponseCallback); | ||
|
||
@GET("/search?entity=musicVideo") | ||
Observable<NetworkResponse> getMusicObservable(@Query("term") String term); | ||
} | ||
} |
58 changes: 58 additions & 0 deletions
58
app/src/main/java/cc/soham/rxblrdroid/objects/NetworkResponse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package cc.soham.rxblrdroid.objects; | ||
|
||
import com.google.gson.annotations.Expose; | ||
import com.google.gson.annotations.SerializedName; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
/** | ||
* Created by sohammondal on 12/10/15. | ||
* Represents the network response in {@code MusicApi} | ||
*/ | ||
public class NetworkResponse { | ||
|
||
@SerializedName("resultCount") | ||
@Expose | ||
private Integer resultCount; | ||
@SerializedName("results") | ||
@Expose | ||
private List<Result> results = new ArrayList<Result>(); | ||
|
||
/** | ||
* | ||
* @return | ||
* The resultCount | ||
*/ | ||
public Integer getResultCount() { | ||
return resultCount; | ||
} | ||
|
||
/** | ||
* | ||
* @param resultCount | ||
* The resultCount | ||
*/ | ||
public void setResultCount(Integer resultCount) { | ||
this.resultCount = resultCount; | ||
} | ||
|
||
/** | ||
* | ||
* @return | ||
* The results | ||
*/ | ||
public List<Result> getResults() { | ||
return results; | ||
} | ||
|
||
/** | ||
* | ||
* @param results | ||
* The results | ||
*/ | ||
public void setResults(List<Result> results) { | ||
this.results = results; | ||
} | ||
|
||
} |
Oops, something went wrong.