Skip to content

Commit

Permalink
Added all network and adapter related operations
Browse files Browse the repository at this point in the history
  • Loading branch information
sohamtriveous committed Oct 15, 2015
1 parent 8b93f80 commit 82ef454
Show file tree
Hide file tree
Showing 12 changed files with 940 additions and 32 deletions.
2 changes: 1 addition & 1 deletion .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions app/app.iml
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,9 @@
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/dex-cache" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.android.support/appcompat-v7/23.0.1/jars" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.android.support/design/23.0.1/jars" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.android.support/recyclerview-v7/23.0.0/jars" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.android.support/support-v4/23.0.1/jars" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/io.reactivex/rxandroid/1.0.1/jars" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/incremental" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/jacoco" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/javaResources" />
Expand All @@ -91,9 +93,16 @@
</content>
<orderEntry type="jdk" jdkName="Android API 23 Platform" jdkType="Android SDK" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" exported="" name="gson-2.3.1" level="project" />
<orderEntry type="library" exported="" name="rxandroid-1.0.1" level="project" />
<orderEntry type="library" exported="" name="rxjava-1.0.13" level="project" />
<orderEntry type="library" exported="" name="design-23.0.1" level="project" />
<orderEntry type="library" exported="" name="appcompat-v7-23.0.1" level="project" />
<orderEntry type="library" exported="" name="butterknife-7.0.1" level="project" />
<orderEntry type="library" exported="" name="picasso-2.5.2" level="project" />
<orderEntry type="library" exported="" name="retrofit-1.9.0" level="project" />
<orderEntry type="library" exported="" name="support-v4-23.0.1" level="project" />
<orderEntry type="library" exported="" name="support-annotations-23.0.1" level="project" />
<orderEntry type="library" exported="" name="recyclerview-v7-23.0.0" level="project" />
</component>
</module>
17 changes: 17 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,21 @@ dependencies {
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.0.1'
compile 'com.android.support:design:23.0.1'


// recycler view
compile "com.android.support:recyclerview-v7:23.0.0"

// retrofit
compile 'com.squareup.retrofit:retrofit:1.9.0'
compile 'com.google.code.gson:gson:2.3.1'

// rx
compile 'io.reactivex:rxandroid:1.0.1'

// picasso
compile 'com.squareup.picasso:picasso:2.5.2'

// butterknife
compile 'com.jakewharton:butterknife:7.0.1'
}
9 changes: 5 additions & 4 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="cc.soham.rxblrdroid" >
package="cc.soham.rxblrdroid">

<uses-permission android:name="android.permission.INTERNET" />

<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme" >
android:theme="@style/AppTheme">
<activity
android:name=".MainActivity"
android:label="@string/app_name"
android:theme="@style/AppTheme.NoActionBar" >
android:theme="@style/AppTheme.NoActionBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
Expand Down
27 changes: 18 additions & 9 deletions app/src/main/java/cc/soham/rxblrdroid/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,37 @@
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.view.Menu;
import android.view.MenuItem;

import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class MainActivity extends AppCompatActivity {
@Bind(R.id.recyclerview)
RecyclerView recyclerView;
@Bind(R.id.toolbar)
Toolbar toolbar;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);

ButterKnife.bind(this);

setSupportActionBar(toolbar);
recyclerView.setLayoutManager(new LinearLayoutManager(this));
}

FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
fab.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
.setAction("Action", null).show();
}
});
@OnClick(R.id.fab)
public void fabOnClick(View view) {
Snackbar.make(view, "Loading", Snackbar.LENGTH_LONG).show();
}

@Override
Expand Down
55 changes: 55 additions & 0 deletions app/src/main/java/cc/soham/rxblrdroid/network/MusicAdapter.java
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 app/src/main/java/cc/soham/rxblrdroid/network/MusicApi.java
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 app/src/main/java/cc/soham/rxblrdroid/objects/NetworkResponse.java
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;
}

}
Loading

0 comments on commit 82ef454

Please sign in to comment.