From b39d06d152ea3b5215201dae6d7bcc989fea07dd Mon Sep 17 00:00:00 2001 From: wesniem Date: Fri, 18 Nov 2016 15:47:07 -0500 Subject: [PATCH 1/2] First Feature --- .idea/misc.xml | 29 ++++++++- .idea/modules.xml | 9 +++ .idea/runConfigurations.xml | 12 ++++ .idea/vcs.xml | 6 ++ app/build.gradle | 12 ++-- .../googlenowandroidapp/MainActivity.java | 2 + .../googlenowandroidapp/MyAdapter.java | 20 ++++-- .../SwipeRefreshActivity.java | 64 +++++++++++++++++++ .../googlenowandroidapp/VineCardData.java | 6 +- .../googlenowandroidapp/VineViewHolder.java | 29 +++++++-- .../googlenowandroidapp/model/Record.java | 16 ++--- app/src/main/res/layout/activity_main.xml | 10 ++- app/src/main/res/layout/content_main.xml | 19 ------ app/src/main/res/layout/vine_item_view.xml | 3 +- 14 files changed, 187 insertions(+), 50 deletions(-) create mode 100644 .idea/modules.xml create mode 100644 .idea/runConfigurations.xml create mode 100644 .idea/vcs.xml create mode 100644 app/src/main/java/nyc/c4q/wesniemarcelin/googlenowandroidapp/SwipeRefreshActivity.java delete mode 100644 app/src/main/res/layout/content_main.xml diff --git a/.idea/misc.xml b/.idea/misc.xml index e6817d7..7158618 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -1,5 +1,32 @@ + + + + + + + @@ -10,7 +37,7 @@ - + diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..510055d --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/.idea/runConfigurations.xml b/.idea/runConfigurations.xml new file mode 100644 index 0000000..7f68460 --- /dev/null +++ b/.idea/runConfigurations.xml @@ -0,0 +1,12 @@ + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..94a25f7 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/app/build.gradle b/app/build.gradle index 3e43530..7b77f66 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -1,12 +1,12 @@ apply plugin: 'com.android.application' android { - compileSdkVersion 25 + compileSdkVersion 24 buildToolsVersion "24.0.3" defaultConfig { applicationId "nyc.c4q.wesniemarcelin.googlenowandroidapp" minSdkVersion 16 - targetSdkVersion 25 + targetSdkVersion 24 versionCode 1 versionName "1.0" testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" @@ -24,10 +24,11 @@ dependencies { androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', { exclude group: 'com.android.support', module: 'support-annotations' }) - compile 'com.android.support:appcompat-v7:25.0.0' + compile 'com.android.support:appcompat-v7:24.2.1' + compile 'com.android.support:support-v4:24.2.1' testCompile 'junit:junit:4.12' - compile 'com.android.support:cardview-v7:25.+' - compile 'com.android.support:recyclerview-v7:25.+' + compile 'com.android.support:cardview-v7:24.2.1' + compile 'com.android.support:recyclerview-v7:24.2.1' compile files('libs/YouTubeAndroidPlayerApi.jar') compile 'com.github.bumptech.glide:glide:3.7.0' compile 'com.squareup.retrofit2:retrofit:2.1.0' @@ -35,4 +36,5 @@ dependencies { compile 'com.squareup.okhttp3:okhttp:3.4.2' compile 'com.google.code.gson:gson:2.6.2' compile 'com.squareup.picasso:picasso:2.5.2' + compile 'com.marshalchen.ultimaterecyclerview:library:0.7.0' } diff --git a/app/src/main/java/nyc/c4q/wesniemarcelin/googlenowandroidapp/MainActivity.java b/app/src/main/java/nyc/c4q/wesniemarcelin/googlenowandroidapp/MainActivity.java index 6b42c17..e79c392 100644 --- a/app/src/main/java/nyc/c4q/wesniemarcelin/googlenowandroidapp/MainActivity.java +++ b/app/src/main/java/nyc/c4q/wesniemarcelin/googlenowandroidapp/MainActivity.java @@ -111,9 +111,11 @@ public void onResponse(Call call, Response response) VineCardData obj = (VineCardData) data.get(0); VineCardData vineAvatar = (VineCardData) data.get(0); VineCardData vineUsername = (VineCardData) data.get(0); + VineCardData vineUserId = (VineCardData) data.get(0); obj.setUrl(response.body().getData().getRecords().get(0).videoUrl); vineAvatar.setAvatarUrl(response.body().getData().getRecords().get(0).avatarUrl); vineUsername.setUsername(response.body().getData().getRecords().get(0).username); + vineUserId.setUserID(response.body().getData().getRecords().get(0).userId); adapter.notifyDataSetChanged(); } else { diff --git a/app/src/main/java/nyc/c4q/wesniemarcelin/googlenowandroidapp/MyAdapter.java b/app/src/main/java/nyc/c4q/wesniemarcelin/googlenowandroidapp/MyAdapter.java index 5851fa2..e6b7794 100644 --- a/app/src/main/java/nyc/c4q/wesniemarcelin/googlenowandroidapp/MyAdapter.java +++ b/app/src/main/java/nyc/c4q/wesniemarcelin/googlenowandroidapp/MyAdapter.java @@ -6,6 +6,7 @@ import android.view.ViewGroup; import java.util.ArrayList; +import java.util.List; import nyc.c4q.wesniemarcelin.googlenowandroidapp.TodoList.TodoListCarddata; import nyc.c4q.wesniemarcelin.googlenowandroidapp.TodoList.TodoListViewHolder; @@ -22,7 +23,7 @@ public class MyAdapter extends RecyclerView.Adapter { public final int YOUTUBECARD_POSITION = 3; - //List of "objects" + //List of "cards" public MyAdapter(ArrayList cards) { this.cards = cards; } @@ -52,13 +53,13 @@ public void onBindViewHolder(CardViewHolder holder, int position) { //holder.bind(cards.get(position)); if (viewType == TO_DO_LIST_POSITION){ - ((TodoListViewHolder) holder).bind((TodoListCarddata) cards.get(position)); + ((TodoListViewHolder) holder).bind((TodoListCarddata) cards.get((position)%(cards.size()))); } if(viewType == YOUTUBECARD_POSITION) { - ((VineViewHolder) holder).bind((VineCardData) cards.get(position)); + ((VineViewHolder) holder).bind((VineCardData) cards.get((position)%(cards.size()))); } if(viewType == INSPIRE_CARD_POSITION) { - ((QuoteViewHolder) holder).bind((QuoteCardData) cards.get(position)); + ((QuoteViewHolder) holder).bind((QuoteCardData) cards.get((position)%(cards.size()))); } } @@ -84,7 +85,16 @@ public int getItemCount() { return cards.size(); } - //Describes how viewholder should look + // Clean all elements of the recycler + public void clear() { + cards.clear(); + notifyDataSetChanged(); + } + // Add a list of items + public void addAll(List list) { + cards.addAll(list); + notifyDataSetChanged(); + } } diff --git a/app/src/main/java/nyc/c4q/wesniemarcelin/googlenowandroidapp/SwipeRefreshActivity.java b/app/src/main/java/nyc/c4q/wesniemarcelin/googlenowandroidapp/SwipeRefreshActivity.java new file mode 100644 index 0000000..7716750 --- /dev/null +++ b/app/src/main/java/nyc/c4q/wesniemarcelin/googlenowandroidapp/SwipeRefreshActivity.java @@ -0,0 +1,64 @@ +package nyc.c4q.wesniemarcelin.googlenowandroidapp; + +import android.app.Activity; +import android.os.Bundle; +import android.support.v4.widget.SwipeRefreshLayout; + +import nyc.c4q.wesniemarcelin.googlenowandroidapp.network.VineService; + +/** + * Created by wesniemarcelin on 11/16/16. + */ + +public class SwipeRefreshActivity extends Activity { + private SwipeRefreshLayout swipeContainer; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + // Only ever call `setContentView` once right at the top + setContentView(R.layout.activity_main); + // Lookup the swipe container view + swipeContainer = (SwipeRefreshLayout) findViewById(R.id.swipeRefreshLayout); + // Setup refresh listener which triggers new data loading + swipeContainer.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() { + @Override + public void onRefresh() { + //quoteRetrofitcall + //vineRetroFitCall + //Service call goes here + // Your code to refresh the list here. + // Make sure you call swipeContainer.setRefreshing(false) + // once the network request has completed successfully. + fetchTimelineAsync(0); + } + }); + // Configure the refreshing colors + swipeContainer.setColorSchemeResources(android.R.color.holo_blue_bright, + android.R.color.holo_green_light, + android.R.color.holo_orange_light, + android.R.color.holo_red_light); + } + + public void fetchTimelineAsync(int page) { + // Send the network request to fetch the updated data + // `client` here is an instance of Android Async HTTP + // getHomeTimeline is an example endpoint. + +// client.getHomeTimeline(0, new JsonHttpResponseHandler() { +// public void onSuccess(JSONArray json) { +// // Remember to CLEAR OUT old items before appending in the new ones +// adapter.clear(); +// // ...the data has come back, add new items to your adapter... +// adapter.addAll(...); +// // Now we call setRefreshing(false) to signal refresh has finished +// swipeContainer.setRefreshing(false); +// } +// +// public void onFailure(Throwable e) { +// Log.d("DEBUG", "Fetch timeline error: " + e.toString()); +// } +// }); + } +} + diff --git a/app/src/main/java/nyc/c4q/wesniemarcelin/googlenowandroidapp/VineCardData.java b/app/src/main/java/nyc/c4q/wesniemarcelin/googlenowandroidapp/VineCardData.java index 27b2788..da16148 100644 --- a/app/src/main/java/nyc/c4q/wesniemarcelin/googlenowandroidapp/VineCardData.java +++ b/app/src/main/java/nyc/c4q/wesniemarcelin/googlenowandroidapp/VineCardData.java @@ -12,13 +12,13 @@ public class VineCardData implements CardData { private String url; private String avatarUrl; private String username; - private int userID; + private String userID; - public int getUserID() { + public String getUserID() { return userID; } - public void setUserID(int userID) { + public void setUserID(String userID) { this.userID = userID; } diff --git a/app/src/main/java/nyc/c4q/wesniemarcelin/googlenowandroidapp/VineViewHolder.java b/app/src/main/java/nyc/c4q/wesniemarcelin/googlenowandroidapp/VineViewHolder.java index bfa295e..54dc6b7 100644 --- a/app/src/main/java/nyc/c4q/wesniemarcelin/googlenowandroidapp/VineViewHolder.java +++ b/app/src/main/java/nyc/c4q/wesniemarcelin/googlenowandroidapp/VineViewHolder.java @@ -1,6 +1,7 @@ package nyc.c4q.wesniemarcelin.googlenowandroidapp; import android.content.Context; +import android.content.Intent; import android.media.MediaPlayer; import android.net.Uri; import android.view.LayoutInflater; @@ -27,14 +28,16 @@ public class VineViewHolder extends CardViewHolder { Context context; TextView username; String user_name1; + String userId; + public VineViewHolder(ViewGroup parent) { super(inflateView(parent)); context = parent.getContext(); image = (ImageView) itemView.findViewById(R.id.image_view_vid_of_the_day); video = (VideoView) itemView.findViewById(R.id.video_view); - avatarView = (ImageView)itemView.findViewById(R.id.vine_avatar); - username = (TextView)itemView.findViewById(R.id.username_imageview); + avatarView = (ImageView) itemView.findViewById(R.id.vine_avatar); + username = (TextView) itemView.findViewById(R.id.username_imageview); } public static View inflateView(ViewGroup parent) { @@ -43,17 +46,18 @@ public static View inflateView(ViewGroup parent) { //Binds the specific Youtube card data with the view public void bind(VineCardData vineCardData) { + //gets and sets the user's profile picture avatarUrl = vineCardData.getAvatarUrl(); Picasso.with(context).load(avatarUrl).into(avatarView); + + //gets and sets username to the viewholder user_name1 = vineCardData.getUsername(); -// Picasso.with(context).load(user_name1).into(username); username.setText(user_name1); - - - + goToUserPage(); url = vineCardData.getUrl(); image.setImageResource(R.drawable.video_of_the_day_image); + userId = vineCardData.getUserID(); if (url != null) { video.setVideoURI(Uri.parse(url)); video.setMediaController(new MediaController(context)); @@ -66,6 +70,19 @@ public void onPrepared(MediaPlayer mediaPlayer) { }); } } + + public void goToUserPage() { + avatarView.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + + Uri uri = Uri.parse("http://vine.co/u/"+userId); + + Intent intent = new Intent(Intent.ACTION_VIEW, uri); + context.startActivity(intent); + } + }); + } } diff --git a/app/src/main/java/nyc/c4q/wesniemarcelin/googlenowandroidapp/model/Record.java b/app/src/main/java/nyc/c4q/wesniemarcelin/googlenowandroidapp/model/Record.java index fd58089..72092d5 100644 --- a/app/src/main/java/nyc/c4q/wesniemarcelin/googlenowandroidapp/model/Record.java +++ b/app/src/main/java/nyc/c4q/wesniemarcelin/googlenowandroidapp/model/Record.java @@ -16,7 +16,7 @@ public class Record { // public String description; // public String created; public String avatarUrl; -// public int userId; + public String userId; // public Comments comments; // public String thumbnailUrl; // public Object foursquareVenueId; @@ -93,14 +93,14 @@ public void setAvatarUrl(String avatarUrl) { this.avatarUrl = avatarUrl; } -// public int getUserId() { -// return userId; -// } + public String getUserId() { + return userId; + } + + public void setUserId(String userId) { + this.userId = userId; + } // -// public void setUserId(int userId) { -// this.userId = userId; -// } -//// // public Comments getComments() { // return comments; // } diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index 666b53c..26142a6 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -4,7 +4,8 @@ android:layout_width="match_parent" android:layout_height="match_parent" android:layout_gravity="bottom" - android:orientation="vertical"> + android:orientation="vertical" + android:id="@+id/layout_container"> + + - + diff --git a/app/src/main/res/layout/content_main.xml b/app/src/main/res/layout/content_main.xml deleted file mode 100644 index ffe1795..0000000 --- a/app/src/main/res/layout/content_main.xml +++ /dev/null @@ -1,19 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/app/src/main/res/layout/vine_item_view.xml b/app/src/main/res/layout/vine_item_view.xml index d9e7e8a..b4375af 100644 --- a/app/src/main/res/layout/vine_item_view.xml +++ b/app/src/main/res/layout/vine_item_view.xml @@ -39,7 +39,8 @@ android:layout_height="0dp" android:layout_gravity="center" android:layout_margin="5dp" - android:layout_weight="1" /> + android:layout_weight="1" + android:onClick="goToUserPage"/> Date: Fri, 18 Nov 2016 16:39:53 -0500 Subject: [PATCH 2/2] Second Feature --- .../googlenowandroidapp/MainActivity.java | 61 ++++++++++++++++-- .../googlenowandroidapp/MyAdapter.java | 14 ++-- .../SwipeRefreshActivity.java | 64 ------------------- 3 files changed, 62 insertions(+), 77 deletions(-) delete mode 100644 app/src/main/java/nyc/c4q/wesniemarcelin/googlenowandroidapp/SwipeRefreshActivity.java diff --git a/app/src/main/java/nyc/c4q/wesniemarcelin/googlenowandroidapp/MainActivity.java b/app/src/main/java/nyc/c4q/wesniemarcelin/googlenowandroidapp/MainActivity.java index e79c392..3fddbec 100644 --- a/app/src/main/java/nyc/c4q/wesniemarcelin/googlenowandroidapp/MainActivity.java +++ b/app/src/main/java/nyc/c4q/wesniemarcelin/googlenowandroidapp/MainActivity.java @@ -4,6 +4,7 @@ import android.content.DialogInterface; import android.content.SharedPreferences; import android.os.Bundle; +import android.support.v4.widget.SwipeRefreshLayout; import android.support.v7.app.AppCompatActivity; import android.support.v7.widget.LinearLayoutManager; import android.support.v7.widget.RecyclerView; @@ -33,9 +34,10 @@ public class MainActivity extends AppCompatActivity { public static final String BASE_URL = "https://api.vineapp.com/"; public static final String QUOTE_URL = "http://quotes.stormconsultancy.co.uk/"; private static final String TAG = "YOOOOO"; + private SwipeRefreshLayout swipeContainer; private AlertDialog confirmDialogObject; private static final String MODIFIED_NOTE = "Modified Note"; - public static final String MyPREFERENCES = "MyPrefs" ; + public static final String MyPREFERENCES = "MyPrefs"; public static final String NOTE = "noteKey"; private EditText notepad; @@ -54,6 +56,7 @@ protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); data = new ArrayList(); + swipeContainer = (SwipeRefreshLayout) findViewById(R.id.swipeRefreshLayout); data.add(new VineCardData(R.drawable.video_of_the_day_image)); data.add(new TodoListCarddata()); @@ -65,10 +68,32 @@ protected void onCreate(Bundle savedInstanceState) { recyclerView.setLayoutManager(new LinearLayoutManager(getApplicationContext())); adapter = new MyAdapter(data); recyclerView.setAdapter(adapter); - notepad = (EditText)findViewById(R.id.edit_text_notepad); + notepad = (EditText) findViewById(R.id.edit_text_notepad); buildConfirmDialog(); + + //Setting for refresh + swipeContainer.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() { + @Override + public void onRefresh() { + //quoteRetrofitcall + //vineRetroFitCall + //Service call goes here + // Your code to refresh the list here. + // Make sure you call swipeContainer.setRefreshing(false) + // once the network request has completed successfully. + + vineRetrofitCall(); + onRefreshQuoteRetrofitCall(); + swipeContainer.setRefreshing(false); + } + }); + swipeContainer.setColorSchemeResources(android.R.color.holo_blue_bright, + android.R.color.holo_green_light, + android.R.color.holo_orange_light, + android.R.color.holo_red_light); } + public void quoteretrofitCall() { Retrofit quoteRetrofit = new Retrofit.Builder() .baseUrl(QUOTE_URL) @@ -81,8 +106,8 @@ public void quoteretrofitCall() { call.enqueue(new Callback() { @Override public void onResponse(Call call, Response response) { - Log.d(TAG, "Success!" + response.body().toString()); - Quotes quote = response.body(); + Log.d(TAG, "Success!" + response.body().toString()); + Quotes quote = response.body(); data.add(new QuoteCardData(quote)); adapter.notifyDataSetChanged(); } @@ -94,6 +119,31 @@ public void onFailure(Call call, Throwable t) { }); } + public void onRefreshQuoteRetrofitCall() { + Retrofit quoteRetrofit = new Retrofit.Builder() + .baseUrl(QUOTE_URL) + .addConverterFactory(GsonConverterFactory.create()) + .build(); + QuoteService service = quoteRetrofit.create(QuoteService.class); + + Call call = service.listQuotes(); + Log.d(TAG, "Succ"); + call.enqueue(new Callback() { + @Override + public void onResponse(Call call, Response response) { + Log.d(TAG, "Success!" + response.body().toString()); + Quotes quote = response.body(); +// data.add(new QuoteCardData(quote)); + adapter.notifyDataSetChanged(); + } + + @Override + public void onFailure(Call call, Throwable t) { + Log.d(TAG, "Error!" + t.getMessage()); + } + }); + } + public void vineRetrofitCall() { Retrofit retrofit = new Retrofit.Builder() .baseUrl(BASE_URL) @@ -132,7 +182,6 @@ public void onFailure(Call call, Throwable t) { } - public void buildConfirmDialog() { AlertDialog.Builder confirmBuilder = new AlertDialog.Builder(this); confirmBuilder.setTitle("Are you sure?"); @@ -147,7 +196,7 @@ public void onClick(DialogInterface dialog, int which) { SharedPreferences.Editor editor = sharedpreferences.edit(); editor.putString(NOTE, notepad.getText().toString()).apply(); - Toast.makeText(MainActivity.this, sharedpreferences.getString(NOTE,"default"), Toast.LENGTH_SHORT).show(); + Toast.makeText(MainActivity.this, sharedpreferences.getString(NOTE, "default"), Toast.LENGTH_SHORT).show(); } }); diff --git a/app/src/main/java/nyc/c4q/wesniemarcelin/googlenowandroidapp/MyAdapter.java b/app/src/main/java/nyc/c4q/wesniemarcelin/googlenowandroidapp/MyAdapter.java index e6b7794..ea80d8d 100644 --- a/app/src/main/java/nyc/c4q/wesniemarcelin/googlenowandroidapp/MyAdapter.java +++ b/app/src/main/java/nyc/c4q/wesniemarcelin/googlenowandroidapp/MyAdapter.java @@ -20,7 +20,7 @@ public class MyAdapter extends RecyclerView.Adapter { public final int TO_DO_LIST_POSITION = 1; public final int INSPIRE_CARD_POSITION = 2; - public final int YOUTUBECARD_POSITION = 3; + public final int VINECARD_POSITION = 3; //List of "cards" @@ -39,7 +39,7 @@ public CardViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { if (viewType == INSPIRE_CARD_POSITION) { return new QuoteViewHolder(parent); } - if (viewType == YOUTUBECARD_POSITION) { + if (viewType == VINECARD_POSITION) { return new VineViewHolder(parent); } return null; @@ -53,20 +53,20 @@ public void onBindViewHolder(CardViewHolder holder, int position) { //holder.bind(cards.get(position)); if (viewType == TO_DO_LIST_POSITION){ - ((TodoListViewHolder) holder).bind((TodoListCarddata) cards.get((position)%(cards.size()))); + ((TodoListViewHolder) holder).bind((TodoListCarddata) cards.get((position))); } - if(viewType == YOUTUBECARD_POSITION) { - ((VineViewHolder) holder).bind((VineCardData) cards.get((position)%(cards.size()))); + if(viewType == VINECARD_POSITION) { + ((VineViewHolder) holder).bind((VineCardData) cards.get((position))); } if(viewType == INSPIRE_CARD_POSITION) { - ((QuoteViewHolder) holder).bind((QuoteCardData) cards.get((position)%(cards.size()))); + ((QuoteViewHolder) holder).bind((QuoteCardData) cards.get((position))); } } @Override public int getItemViewType(int position) { if (cards.get(position) instanceof VineCardData) { - return YOUTUBECARD_POSITION; + return VINECARD_POSITION; } else if (cards.get(position) instanceof TodoListCarddata) { return TO_DO_LIST_POSITION; diff --git a/app/src/main/java/nyc/c4q/wesniemarcelin/googlenowandroidapp/SwipeRefreshActivity.java b/app/src/main/java/nyc/c4q/wesniemarcelin/googlenowandroidapp/SwipeRefreshActivity.java deleted file mode 100644 index 7716750..0000000 --- a/app/src/main/java/nyc/c4q/wesniemarcelin/googlenowandroidapp/SwipeRefreshActivity.java +++ /dev/null @@ -1,64 +0,0 @@ -package nyc.c4q.wesniemarcelin.googlenowandroidapp; - -import android.app.Activity; -import android.os.Bundle; -import android.support.v4.widget.SwipeRefreshLayout; - -import nyc.c4q.wesniemarcelin.googlenowandroidapp.network.VineService; - -/** - * Created by wesniemarcelin on 11/16/16. - */ - -public class SwipeRefreshActivity extends Activity { - private SwipeRefreshLayout swipeContainer; - - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - // Only ever call `setContentView` once right at the top - setContentView(R.layout.activity_main); - // Lookup the swipe container view - swipeContainer = (SwipeRefreshLayout) findViewById(R.id.swipeRefreshLayout); - // Setup refresh listener which triggers new data loading - swipeContainer.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() { - @Override - public void onRefresh() { - //quoteRetrofitcall - //vineRetroFitCall - //Service call goes here - // Your code to refresh the list here. - // Make sure you call swipeContainer.setRefreshing(false) - // once the network request has completed successfully. - fetchTimelineAsync(0); - } - }); - // Configure the refreshing colors - swipeContainer.setColorSchemeResources(android.R.color.holo_blue_bright, - android.R.color.holo_green_light, - android.R.color.holo_orange_light, - android.R.color.holo_red_light); - } - - public void fetchTimelineAsync(int page) { - // Send the network request to fetch the updated data - // `client` here is an instance of Android Async HTTP - // getHomeTimeline is an example endpoint. - -// client.getHomeTimeline(0, new JsonHttpResponseHandler() { -// public void onSuccess(JSONArray json) { -// // Remember to CLEAR OUT old items before appending in the new ones -// adapter.clear(); -// // ...the data has come back, add new items to your adapter... -// adapter.addAll(...); -// // Now we call setRefreshing(false) to signal refresh has finished -// swipeContainer.setRefreshing(false); -// } -// -// public void onFailure(Throwable e) { -// Log.d("DEBUG", "Fetch timeline error: " + e.toString()); -// } -// }); - } -} -