Skip to content

Commit

Permalink
Fixed bug when fast clicking while refreshing crashes the app, now it…
Browse files Browse the repository at this point in the history
… only when you are clicking really really fast (probably not fixable), removed useless code from UkolyPageFragment
  • Loading branch information
vojta-horanek committed Jan 13, 2019
1 parent c9524bc commit 4738b3b
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ public Fragment getItem(int position) {
if (position == 0) {
return activeTab;
} else {
finishedTab.setTodo(true);
return finishedTab;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,9 @@ public class UkolyPageFragment extends Fragment implements SwipeRefreshLayout.On
private List<UkolItem> ukolList = new ArrayList<>();
private UkolyBasicAdapter adapter = new UkolyBasicAdapter(ukolList);
private Context context;
private boolean todo;
private boolean clickable;
private UkolyInterface mUkolyInterface;

public void setTodo(boolean todo) {
this.todo = todo;
}

public void setUkolyInterface(UkolyInterface fragment) {
mUkolyInterface = fragment;
}
Expand Down Expand Up @@ -73,9 +69,11 @@ public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceStat
ItemClickSupport.addTo(recyclerView).setOnItemClickListener(new ItemClickSupport.OnItemClickListener() {
@Override
public void onItemClicked(RecyclerView recyclerView, int position, View v) {
boolean expanded = adapter.ukolyList.get(position).isExpanded();
adapter.ukolyList.get(position).setExpanded(!expanded);
adapter.notifyItemChanged(position);
if (clickable) {
boolean expanded = adapter.ukolyList.get(position).isExpanded();
adapter.ukolyList.get(position).setExpanded(!expanded);
adapter.notifyItemChanged(position);
}
}
});
}
Expand All @@ -87,23 +85,21 @@ public void onDetach() {

@Override
public void onRefresh() {
adapter.notifyItemRangeRemoved(0, ukolList.size());
ukolList.clear();
mUkolyInterface.onPageRefresh();
}

@Override
@SuppressWarnings("unchecked")
// this is probably safe since it works and I want the compiler to shut up
public void onCallbackFinish(Object result) {

// TODO If there is nothing add placeholder
if (result != null) {

clickable = false;
ukolList.clear();
ukolList.addAll((List<UkolItem>) result);
adapter.notifyDataSetChanged();
swipeRefreshLayout.setRefreshing(false);

clickable = true;
} else {
Toast.makeText(context, "Chyba při zpracovávání úkolů", Toast.LENGTH_SHORT).show();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ public class ZnamkyFragment extends Fragment implements SwipeRefreshLayout.OnRef
private List<ZnamkaItem> znamkaList = new ArrayList<>();
private ZnamkyBasicAdapter adapter = new ZnamkyBasicAdapter(znamkaList);

private boolean clickable;

private Context context;

Expand Down Expand Up @@ -87,9 +88,11 @@ public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceStat
ItemClickSupport.addTo(recyclerView).setOnItemClickListener(new ItemClickSupport.OnItemClickListener() {
@Override
public void onItemClicked(RecyclerView recyclerView, int position, View v) {
boolean expanded = adapter.znamkyList.get(position).isExpanded();
adapter.znamkyList.get(position).setExpanded(!expanded);
adapter.notifyItemChanged(position);
if (clickable) {
boolean expanded = adapter.znamkyList.get(position).isExpanded();
adapter.znamkyList.get(position).setExpanded(!expanded);
adapter.notifyItemChanged(position);
}
}
});

Expand All @@ -109,8 +112,6 @@ public void onDetach() {

@Override
public void onRefresh() {
adapter.notifyItemRangeRemoved(0, znamkaList.size());
znamkaList.clear();
makeRequest();
}

Expand All @@ -126,11 +127,12 @@ private void makeRequest() {
public void onCallbackFinish(Object result) {

if (result != null) {

clickable = false;
znamkaList.clear();
znamkaList.addAll((List<ZnamkaItem>) result);
adapter.notifyDataSetChanged();
swipeRefreshLayout.setRefreshing(false);
clickable = true;

} else {
Toast.makeText(context, "Chyba při zpracovávání známek", Toast.LENGTH_SHORT).show();
Expand Down

0 comments on commit 4738b3b

Please sign in to comment.