Fix empty binding

This commit is contained in:
Mieszko Wrzeszczyński 2018-12-17 00:56:07 +01:00
parent c1e20934e4
commit 2d9c8aa6cc
5 changed files with 102 additions and 87 deletions

View File

@ -67,8 +67,9 @@
android:theme="@style/AppTheme" />
<activity
android:name=".activity.BlackList"
android:label="@string/title_activity_black_list"
android:theme="@style/AppTheme"></activity>
android:configChanges="keyboardHidden|orientation|screenSize"
android:screenOrientation="portrait"
android:theme="@style/AppTheme" />
</application>
</manifest>

View File

@ -1,6 +1,7 @@
package com.uam.wmi.findmytutor.activity;
import android.os.Bundle;
import android.support.design.widget.CoordinatorLayout;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.support.v7.app.ActionBar;
@ -9,6 +10,8 @@ import android.support.v7.widget.DefaultItemAnimator;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.Toolbar;
import android.text.TextUtils;
import android.util.Log;
import android.view.View;
import android.widget.TextView;
import android.widget.Toast;
@ -28,76 +31,70 @@ import java.util.ArrayList;
import java.util.List;
import butterknife.BindView;
import butterknife.ButterKnife;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.disposables.CompositeDisposable;
import io.reactivex.observers.DisposableSingleObserver;
import io.reactivex.schedulers.Schedulers;
import okhttp3.ResponseBody;
import static com.mapbox.mapboxsdk.Mapbox.getApplicationContext;
public class BlackList extends AppCompatActivity {
private CompositeDisposable disposable = new CompositeDisposable();
private UserService userService;
@BindView(R.id.recycler_view)
RecyclerView recyclerView;
@BindView(R.id.black_list_empty_text_view)
TextView noNotesView;
@BindView(R.id.black_list_recycler_view)
RecyclerView mRecyclerView;
private BlackListAdapter mAdapter;
private List<User> blackList = new ArrayList<>();
private BlackListAdapter mAdapter;
private List<User> blacklistedUsers = new ArrayList<>();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
setContentView(R.layout.activity_black_list);
ButterKnife.bind(this);
// Custom Toolbar
Toolbar toolbar = findViewById(R.id.toolbar);
toolbar.setTitle(getString(R.string.activity_title_home));
setSupportActionBar(toolbar);
ActionBar actionBar = getSupportActionBar();
actionBar.setDisplayShowTitleEnabled(true);
actionBar.setDisplayHomeAsUpEnabled(true);
actionBar.setHomeButtonEnabled(true);
FloatingActionButton fab = findViewById(R.id.fab);
fab.setOnClickListener(view -> Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
.setAction("Action", null).show());
userService = ApiClient.getClient(getApplicationContext())
.create(UserService.class);
// Adapter
mAdapter = new BlackListAdapter(this, blackList);
RecyclerView.LayoutManager mLayoutManager = new LinearLayoutManager(this);
mRecyclerView.setLayoutManager(mLayoutManager);
mRecyclerView.setItemAnimator(new DefaultItemAnimator());
mRecyclerView.addItemDecoration(new MyDividerItemDecoration(this, LinearLayoutManager.VERTICAL, 16));
mRecyclerView.setAdapter(mAdapter);
mAdapter = new BlackListAdapter(this, blacklistedUsers);
RecyclerView.LayoutManager mLayoutManager = new LinearLayoutManager(getApplicationContext());
recyclerView.setLayoutManager(mLayoutManager);
recyclerView.setItemAnimator(new DefaultItemAnimator());
recyclerView.addItemDecoration(new MyDividerItemDecoration(this, LinearLayoutManager.VERTICAL, 16));
recyclerView.setAdapter(mAdapter);
//TODO API CALL HERE
fetchBlackListedUsers(PrefUtils.getUserId(this));
// mAdapter = new BlackListAdapter();
mRecyclerView.addOnItemTouchListener(new RecyclerTouchListener(this, mRecyclerView, new RecyclerTouchListener.ClickListener() {
/**
* On long press on RecyclerView item, open alert dialog
* with options to choose
* Edit and Delete
* */
recyclerView.addOnItemTouchListener(new RecyclerTouchListener(this,
recyclerView, new RecyclerTouchListener.ClickListener() {
@Override
public void onClick(View view, int position) {
Toast.makeText(getApplicationContext(), "OnClick", Toast.LENGTH_LONG);
public void onClick(View view, final int position) {
}
@Override
public void onLongClick(View view, int position) {
Toast.makeText(getApplicationContext(), "OnLongClick", Toast.LENGTH_LONG);
}
}));
fetchBlackListedUsers(PrefUtils.getUserId(getApplicationContext()));
}
private void fetchBlackListedUsers(String userId) {
disposable.add(
userService.getTutorBlacklistedByID(userId)
@ -107,7 +104,8 @@ public class BlackList extends AppCompatActivity {
@Override
public void onSuccess(List<User> users) {
// mAdapter.notifyDataSetChanged();
mAdapter.notifyDataSetChanged();
Log.e("BLACKLIST","fetch success");
toggleEmptyNotes();
}
@ -133,7 +131,7 @@ public class BlackList extends AppCompatActivity {
}
private void toggleEmptyNotes() {
if (blackList.size() > 0) {
if (blacklistedUsers.size() >= 0) {
noNotesView.setVisibility(View.GONE);
} else {
noNotesView.setVisibility(View.VISIBLE);

View File

@ -1,6 +1,8 @@
package com.uam.wmi.findmytutor.adapters;
import android.content.Context;
import android.graphics.drawable.Drawable;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
@ -12,45 +14,71 @@ import com.uam.wmi.findmytutor.model.User;
import java.util.List;
import butterknife.BindView;
import butterknife.ButterKnife;
public class BlackListAdapter extends RecyclerView.Adapter<BlackListAdapter.BlackListHolder> {
public class BlackListAdapter extends RecyclerView.Adapter<BlackListAdapter.MyViewHolder> {
private Context context;
private List<User> blackListed;
private List<User> tutorsList;
public BlackListAdapter(Context context,List<User> list) {
public BlackListAdapter(Context context, List<User> tutors) {
this.context = context;
this.blackListed = list;
this.tutorsList = tutors;
}
@NonNull
@Override
public BlackListAdapter.BlackListHolder onCreateViewHolder(ViewGroup parent,
int viewType) {
View v = LayoutInflater.from(parent.getContext())
public MyViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
View itemView = LayoutInflater.from(parent.getContext())
.inflate(R.layout.black_list_row, parent, false);
BlackListHolder vh = new BlackListHolder(v);
return vh;
return new MyViewHolder(itemView);
}
@Override
public void onBindViewHolder(BlackListHolder holder, int position) {
public void onBindViewHolder(@NonNull MyViewHolder holder, int position) {
Drawable image = null;
User tutor = tutorsList.get(position);
holder.firstName.setText(tutor.getFirstName());
holder.lastName.setText(tutor.getLastName());
if (tutor.isIsOnline()) {
image = context.getResources().getDrawable(R.drawable.user_list_online);
} else {
image = context.getResources().getDrawable(R.drawable.user_list_offline);
}
if (!tutor.isIsActive()) {
image = context.getResources().getDrawable(R.drawable.user_list_off);
}
image.setBounds(0, 0, image.getIntrinsicWidth(), image.getIntrinsicHeight());
holder.isOnline.setCompoundDrawables(image, null, null, null);
}
@Override
public int getItemCount(){
return blackListed.size();
public int getItemCount() {
return tutorsList.size();
}
class MyViewHolder extends RecyclerView.ViewHolder {
public static class BlackListHolder extends RecyclerView.ViewHolder {
@BindView(R.id.firstName)
TextView firstName;
public BlackListHolder(View view){
@BindView(R.id.lastName)
TextView lastName;
@BindView(R.id.isOnline)
TextView isOnline;
MyViewHolder(View view) {
super(view);
ButterKnife.bind(this, view);
}
}
}
}

View File

@ -76,11 +76,6 @@
app:srcCompat="@drawable/abc_ic_clear_material" />
<!-- A RecyclerView with some commonly used attributes -->
<android.support.v7.widget.RecyclerView
android:id="@+id/black_list_recycler_view"
android:scrollbars="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
<TextView

View File

@ -1,40 +1,33 @@
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.NestedScrollView xmlns:android="http://schemas.android.com/apk/res/android"
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:context=".activity.BlackList"
tools:showIn="@layout/activity_black_list">
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="35dp"
android:orientation="horizontal" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginTop="9dp"
android:text="412201 - Name Surnmae"
android:textColor="#404040"
android:textSize="20sp" />
<Button
android:layout_width="wrap_content"
android:layout_height="45dp"
android:layout_alignParentRight="true"
android:layout_marginLeft="10dp"
android:layout_marginRight="15dp"
android:text="Do smthing" />
</RelativeLayout>
tools:context=".activity.UsersListFragment"
android:fontFamily="@font/lato_regular"
tools:showIn="@layout/users_list_main">
<android.support.v7.widget.RecyclerView
android:id="@+id/recycler_view"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<TextView
android:id="@+id/txt_empty_notes_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginTop="@dimen/margin_top_no_notes"
android:fontFamily="sans-serif-light"
android:text="@string/loading"
android:textColor="@color/msg_no_notes"
android:textSize="@dimen/msg_no_notes" />
</RelativeLayout>
</android.support.v4.widget.NestedScrollView>