diff --git a/app/src/main/java/appteam/nith/hillffair/activities/NewsfeedActivity.java b/app/src/main/java/appteam/nith/hillffair/activities/NewsfeedActivity.java index 292eb47..bcf8206 100644 --- a/app/src/main/java/appteam/nith/hillffair/activities/NewsfeedActivity.java +++ b/app/src/main/java/appteam/nith/hillffair/activities/NewsfeedActivity.java @@ -10,6 +10,7 @@ import android.support.v7.widget.LinearLayoutManager; import android.support.v7.widget.RecyclerView; import android.support.v7.widget.Toolbar; +import android.util.Log; import android.view.View; import android.widget.ProgressBar; import android.widget.Toast; @@ -30,12 +31,13 @@ public class NewsfeedActivity extends AppCompatActivity implements SwipeRefreshLayout.OnRefreshListener{ + private static final String FEED_LIST ="list" ; private RecyclerView recyclerView; private CardAdapter adapter; private ProgressBar progressBar; private SwipeRefreshLayout swipeRefreshLayout; private boolean loading = true; - private int pastVisiblesItems, visibleItemCount, totalItemCount, previousTotal = 0, visibleThreshold = 0,feedNo=0; + private int pastVisiblesItems, visibleItemCount, totalItemCount, previousTotal = 0, visibleThreshold = 0,feedNo=1; private ArrayList list=new ArrayList<>(); private SharedPref pref; @@ -78,10 +80,8 @@ public void onScrolled(RecyclerView recyclerView, int dx, int dy) { } if (!loading && (totalItemCount - visibleItemCount) <= (pastVisiblesItems + visibleThreshold)) { - - list.add(null); adapter.notifyItemInserted(list.size() + 1); - feedNo+=11; + feedNo+=10; showData(feedNo); loading = true; } @@ -89,7 +89,22 @@ public void onScrolled(RecyclerView recyclerView, int dx, int dy) { } }); + + if(savedInstanceState==null) showData(1); + else { + + list=savedInstanceState.getParcelableArrayList(FEED_LIST); + if(list!=null){ + recyclerView.setVisibility(View.VISIBLE); + progressBar.setVisibility(View.GONE); + adapter.refresh(list); + } + else { + showData(1); + } + } + // Button to upload the NewsFeed FloatingActionButton upload= (FloatingActionButton) findViewById(R.id.upload_btn); @@ -102,17 +117,9 @@ public void onClick(View view) { } - - - /** - * Adding few albums for testing - */ - private void showData(int from){ - if(from>1){ - adapter.removeItem(null); - } - else if(from==1) { + + if(from==1) { list.clear(); adapter.refresh(list); recyclerView.setVisibility(View.GONE); @@ -125,27 +132,45 @@ public void onResponse(Call call, Response respons if(swipeRefreshLayout.isRefreshing()){ swipeRefreshLayout.setRefreshing(false); } - - recyclerView.setVisibility(View.VISIBLE); progressBar.setVisibility(View.GONE); if(response!=null&&response.isSuccess()){ if(response.body().getFeed()!=null){ if(response.body().getFeed().size()>0){ + + if(list.size()!=0){ + list.remove(list.size()-1); + adapter.refresh(list); + } + list.addAll(response.body().getFeed()); + list.add(null); - adapter.refresh(list);} - else { - adapter.removeItem(null); + adapter.refresh(list); } + + Log.d("rr","check"); + } else { - adapter.removeItem(null); + Log.d("sa","check"); + + if(list.size()!=0){ + list.remove(list.size()-1); + adapter.refresh(list); + } + } } else { - adapter.removeItem(null); + + if(list.size()!=0){ + list.remove(list.size()-1); + adapter.refresh(list); + } + + Toast.makeText(NewsfeedActivity.this,"Unable to fetch Data",Toast.LENGTH_SHORT).show(); } } @@ -155,7 +180,12 @@ public void onFailure(Call call, Throwable t) { if(swipeRefreshLayout.isRefreshing()){ swipeRefreshLayout.setRefreshing(false); } - adapter.removeItem(null); + + if(list.size()!=0){ + list.remove(list.size()-1); + adapter.refresh(list); + } + t.printStackTrace(); progressBar.setVisibility(View.GONE); Toast.makeText(NewsfeedActivity.this, "Please check your network connection and internet permission", Toast.LENGTH_LONG).show(); @@ -168,4 +198,11 @@ public void onRefresh() { showData(1); } + + @Override + protected void onSaveInstanceState(Bundle outState) { + super.onSaveInstanceState(outState); + if(list!=null) + outState.putParcelableArrayList(FEED_LIST,list); + } } diff --git a/app/src/main/java/appteam/nith/hillffair/adapters/CardAdapter.java b/app/src/main/java/appteam/nith/hillffair/adapters/CardAdapter.java index bf466a0..fed5288 100644 --- a/app/src/main/java/appteam/nith/hillffair/adapters/CardAdapter.java +++ b/app/src/main/java/appteam/nith/hillffair/adapters/CardAdapter.java @@ -196,12 +196,7 @@ public void onFailure(Call call, Throwable t) { @Override public int getItemCount() { - if(list_card.size()==0) - return 0; - else if(list_card.size()<=9) - return list_card.size(); - else - return list_card.size()+1; + return list_card.size(); } @@ -227,19 +222,13 @@ public MyViewHolder(View view) { } - // @Override - // public void onClick(View v) { - // NewsfeedModel2 card = list_card.get(position); - // APIINTERFACE mApiService = Utils.getRetrofitService(); - // Call mService = mApiService.likecount(); - //} } @Override public int getItemViewType(int position) { - return position>=list_card.size()?FOOTER_VIEW:NORMAL_VIEW; + return list_card.get(position)==null?FOOTER_VIEW:NORMAL_VIEW; } public static class footerView extends RecyclerView.ViewHolder { @@ -248,11 +237,4 @@ public footerView(View itemView) { } } - public void removeItem(NewsfeedModel2 item) { - int indexOfItem = list_card.indexOf(item); - if (indexOfItem != -1) { - list_card.remove(indexOfItem); - notifyItemRemoved(indexOfItem); - } - } } \ No newline at end of file diff --git a/app/src/main/java/appteam/nith/hillffair/application/MyApplication.java b/app/src/main/java/appteam/nith/hillffair/application/MyApplication.java index b3b1451..dadd2ae 100644 --- a/app/src/main/java/appteam/nith/hillffair/application/MyApplication.java +++ b/app/src/main/java/appteam/nith/hillffair/application/MyApplication.java @@ -51,6 +51,10 @@ public void notificationReceived(OSNotification notification) { DbHelper dbHelper = new DbHelper(getApplicationContext()); if(dbHelper.insert_2_homeposts(id,small_icon,title,description,image,large_icon,launch_url)){ Log.v("","inserted Successfully"); + Intent intent = new Intent(getApplicationContext(), NotificationActivity.class); + intent.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT | Intent.FLAG_ACTIVITY_NEW_TASK); + startActivity(intent); + } if (data != null) { diff --git a/app/src/main/java/appteam/nith/hillffair/utilities/APIINTERFACE.java b/app/src/main/java/appteam/nith/hillffair/utilities/APIINTERFACE.java index 71adbfe..ad0395d 100644 --- a/app/src/main/java/appteam/nith/hillffair/utilities/APIINTERFACE.java +++ b/app/src/main/java/appteam/nith/hillffair/utilities/APIINTERFACE.java @@ -68,7 +68,7 @@ public interface APIINTERFACE { Call getUserScore(@Field("id") String id); @FormUrlEncoded - @POST("quiz/questions") + @POST("quiz/questions_new") Call getQuiz(@Field("id") String id); @FormUrlEncoded