Skip to content

Commit

Permalink
Swipe İşlemine başlandı
Browse files Browse the repository at this point in the history
  • Loading branch information
YunusCagliyan850 committed May 4, 2019
1 parent 101e5f0 commit 5d17ad8
Show file tree
Hide file tree
Showing 12 changed files with 634 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package com.yunuscagliyan.memorybook.adapter;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.drawable.Drawable;
import android.support.annotation.NonNull;
import android.support.design.widget.CoordinatorLayout;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;

import com.yunuscagliyan.memorybook.R;

public class Divider extends RecyclerView.ItemDecoration {
private Drawable mDivider;
private int mOrientation;
public Divider(Context context,int orientation) {
mDivider =context.getDrawable(R.drawable.divider);
//mDivider= ContextCompat.getDrawable(context,R.drawable.divider);
if(orientation!=LinearLayoutManager.VERTICAL){
throw new IllegalArgumentException("this argument don't belong here");
}
mOrientation= orientation;


}

@Override
public void onDraw(@NonNull Canvas c, @NonNull RecyclerView parent, @NonNull RecyclerView.State state) {
if(mOrientation==LinearLayoutManager.VERTICAL){
drawHorizontalDivider(c,parent,state);
}
}

private void drawHorizontalDivider(Canvas c, RecyclerView parent, RecyclerView.State state) {
int left,up,right,down;
left=parent.getPaddingLeft();
right=parent.getWidth()-parent.getPaddingRight();
int elementCount=parent.getChildCount();
for (int i=0;i<elementCount;i++){
View currentView=parent.getChildAt(i);
CoordinatorLayout.LayoutParams params= (CoordinatorLayout.LayoutParams) parent.getLayoutParams();
up=currentView.getTop()-params.topMargin;
down=up+mDivider.getIntrinsicHeight();
mDivider.setBounds(left,up,right,down);
mDivider.draw(c);

}

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
package com.yunuscagliyan.memorybook.adapter;

import android.content.Context;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.TextView;

import com.yunuscagliyan.memorybook.R;
import com.yunuscagliyan.memorybook.data.Notes;
import com.yunuscagliyan.memorybook.listeners.AddListener;

import java.util.List;


public class NoteListAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
private static final int ITEM = 0;
public static final int FOOTER=1;
private Context mContext;
private List<Notes> mAllNotes;
AddListener mAddListener;


public NoteListAdapter(Context context, List<Notes> allNotes) {
this.mContext=context;
this.mAllNotes=allNotes;
mAddListener= (AddListener) mContext;

}

@NonNull
@Override
public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {

if(i==ITEM){
View view= LayoutInflater.from(mContext).inflate(R.layout.one_row_note,viewGroup,false);
RecyclerView.ViewHolder noteViewHolder=new NoteViewHolder(view);
return noteViewHolder;
}if (i==FOOTER){
View view=LayoutInflater.from(mContext).inflate(R.layout.footer,viewGroup,false);
RecyclerView.ViewHolder footerViewHolder=new FooterViewHolder(view);
return footerViewHolder;

}
return null;


}

@Override
public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int i) {
if(holder instanceof NoteViewHolder && i!=1){
Notes temporaryNotes=mAllNotes.get(i);
NoteViewHolder noteViewHolder= (NoteViewHolder) holder;
noteViewHolder.noteContent.setText(temporaryNotes.getNoteContent());
noteViewHolder.noteDate.setText(temporaryNotes.getNoteDate());
}



}

@Override
public int getItemCount() {
return mAllNotes.size()+1;
}

@Override
public int getItemViewType(int position) {
if(mAllNotes== null|| mAllNotes.size()==0){
return ITEM;

}else if(position<mAllNotes.size()){
return ITEM;

}else {
return FOOTER;

}

}

class NoteViewHolder extends RecyclerView.ViewHolder{
TextView noteContent;
TextView noteDate;

public NoteViewHolder(@NonNull View itemView) {
super(itemView);
noteContent=itemView.findViewById(R.id.tvNoteContent);
noteDate=itemView.findViewById(R.id.tvNoteDate);

}
}
class FooterViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener{
Button btn_footer;

public FooterViewHolder(@NonNull View itemView) {
super(itemView);
btn_footer=itemView.findViewById(R.id.btn_footer);
btn_footer.setOnClickListener(this);


}

@Override
public void onClick(View v) {
mAddListener.showAddDialog();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
package com.yunuscagliyan.memorybook.adapter;

import android.content.Context;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.Toolbar;
import android.util.AttributeSet;
import android.view.View;

import java.util.Arrays;
import java.util.Collections;
import java.util.List;

public class NotesRecyclerView extends RecyclerView {
List<View> isEmptyInvisible= Collections.EMPTY_LIST;
List<View> isEmptyVisible= Collections.EMPTY_LIST;
private AdapterDataObserver mObserver=new AdapterDataObserver() {
@Override
public void onChanged() {
showOrHideView();

}

@Override
public void onItemRangeChanged(int positionStart, int itemCount) {
showOrHideView();

}

@Override
public void onItemRangeChanged(int positionStart, int itemCount, @Nullable Object payload) {
showOrHideView();

}

@Override
public void onItemRangeInserted(int positionStart, int itemCount) {
showOrHideView();

}

@Override
public void onItemRangeRemoved(int positionStart, int itemCount) {
showOrHideView();

}

@Override
public void onItemRangeMoved(int fromPosition, int toPosition, int itemCount) {
showOrHideView();

}
};
public void showOrHideView(){
if(getAdapter()!=null && !isEmptyVisible.isEmpty() &&!isEmptyInvisible.isEmpty()){
//no element state
if(getAdapter().getItemCount()==1){

for(View view:isEmptyInvisible){
view.setVisibility(View.GONE);
}
for(View view:isEmptyVisible){
view.setVisibility(View.VISIBLE);
}
setVisibility(View.GONE);
}else if (getAdapter().getItemCount()>1){
setVisibility(View.VISIBLE);
for(View view:isEmptyInvisible){
view.setVisibility(View.VISIBLE);
}
for(View view:isEmptyVisible){
view.setVisibility(View.GONE);
}

}

}
}

@Override
public void setAdapter(@Nullable Adapter adapter) {
super.setAdapter(adapter);
if(adapter!=null){
adapter.registerAdapterDataObserver(mObserver);
}
mObserver.onChanged();
}

public NotesRecyclerView(@NonNull Context context) {
super(context);
}

public NotesRecyclerView(@NonNull Context context, @Nullable AttributeSet attrs) {
super(context, attrs);
}

public NotesRecyclerView(@NonNull Context context, @Nullable AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}

public void isEmptyListInvisible(View... invisibleView) {
isEmptyInvisible=Arrays.asList(invisibleView);
mObserver.onChanged();

}

public void isEmptyListVisible(View visibleView) {
isEmptyVisible=Arrays.asList(visibleView);
mObserver.onChanged();

}
}
Loading

0 comments on commit 5d17ad8

Please sign in to comment.