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" /> android:theme="@style/AppTheme" />
<activity <activity
android:name=".activity.BlackList" android:name=".activity.BlackList"
android:label="@string/title_activity_black_list" android:configChanges="keyboardHidden|orientation|screenSize"
android:theme="@style/AppTheme"></activity> android:screenOrientation="portrait"
android:theme="@style/AppTheme" />
</application> </application>
</manifest> </manifest>

View File

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

View File

@ -1,6 +1,8 @@
package com.uam.wmi.findmytutor.adapters; package com.uam.wmi.findmytutor.adapters;
import android.content.Context; import android.content.Context;
import android.graphics.drawable.Drawable;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView; import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
@ -12,45 +14,71 @@ import com.uam.wmi.findmytutor.model.User;
import java.util.List; import java.util.List;
import butterknife.BindView;
import butterknife.ButterKnife; import butterknife.ButterKnife;
public class BlackListAdapter extends RecyclerView.Adapter<BlackListAdapter.BlackListHolder> {
public class BlackListAdapter extends RecyclerView.Adapter<BlackListAdapter.MyViewHolder> {
private Context context; 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.context = context;
this.blackListed = list; this.tutorsList = tutors;
} }
@NonNull
@Override @Override
public BlackListAdapter.BlackListHolder onCreateViewHolder(ViewGroup parent, public MyViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
int viewType) { View itemView = LayoutInflater.from(parent.getContext())
View v = LayoutInflater.from(parent.getContext())
.inflate(R.layout.black_list_row, parent, false); .inflate(R.layout.black_list_row, parent, false);
BlackListHolder vh = new BlackListHolder(v); return new MyViewHolder(itemView);
return vh;
} }
@Override @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 @Override
public int getItemCount(){ public int getItemCount() {
return blackListed.size(); 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); super(view);
ButterKnife.bind(this, view); ButterKnife.bind(this, view);
} }
} }
} }

View File

@ -76,11 +76,6 @@
app:srcCompat="@drawable/abc_ic_clear_material" /> app:srcCompat="@drawable/abc_ic_clear_material" />
<!-- A RecyclerView with some commonly used attributes --> <!-- 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 <TextView

View File

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