Skip to content

Commit

Permalink
Swipe İşlemi
Browse files Browse the repository at this point in the history
  • Loading branch information
YunusCagliyan850 committed May 7, 2019
1 parent cf6fad4 commit 9cb1566
Show file tree
Hide file tree
Showing 91 changed files with 1,500 additions and 225 deletions.
7 changes: 7 additions & 0 deletions .idea/dictionaries/Yunus.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,15 @@ dependencies {
//Glide library
implementation 'com.github.bumptech.glide:glide:4.9.0'
implementation 'com.android.support:recyclerview-v7:28.0.0'
//Eventbus Library
implementation 'org.greenrobot:eventbus:3.1.1'









}
1 change: 1 addition & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:name=".adapter.MemoryBookApp"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
Expand Down
230 changes: 207 additions & 23 deletions app/src/main/java/com/yunuscagliyan/memorybook/MainActivity.java
Original file line number Diff line number Diff line change
@@ -1,63 +1,124 @@
package com.yunuscagliyan.memorybook;

import android.database.Cursor;
import android.graphics.PorterDuff;
import android.net.Uri;
import android.support.annotation.NonNull;
import android.support.design.widget.FloatingActionButton;
import android.support.v4.app.FragmentTransaction;
import android.support.design.widget.NavigationView;
import android.support.v4.widget.DrawerLayout;
import android.support.v7.app.ActionBarDrawerToggle;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.DividerItemDecoration;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.Toolbar;
import android.support.v7.widget.helper.ItemTouchHelper;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.request.RequestOptions;
import com.yunuscagliyan.memorybook.adapter.Divider;
import com.yunuscagliyan.memorybook.adapter.MemoryBookApp;
import com.yunuscagliyan.memorybook.adapter.NoteListAdapter;
import com.yunuscagliyan.memorybook.adapter.NotesRecyclerView;
import com.yunuscagliyan.memorybook.adapter.SimpleTouchCallBack;
import com.yunuscagliyan.memorybook.data.NoteProvider;
import com.yunuscagliyan.memorybook.data.Notes;
import com.yunuscagliyan.memorybook.dataEventBus.DataEvent;
import com.yunuscagliyan.memorybook.fragments.DialogFragmentNewNote;
import com.yunuscagliyan.memorybook.listeners.AddListener;
import com.yunuscagliyan.memorybook.fragments.FragmentDialogNoteCompleted;
import com.yunuscagliyan.memorybook.listeners.Filters;


import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;

public class MainActivity extends AppCompatActivity implements AddListener {
public class MainActivity extends AppCompatActivity implements NavigationView.OnNavigationItemSelectedListener {
private static final Uri CONTENT_URI = NoteProvider.CONTENT_URI;
public static final String NOTE_NOT_INLINE="UNORDERED";
public static final String NOTE_COMPLETED_UNIMPORTANT ="UNIMPORTANT_COMPLETED";

Toolbar mToolbar;
DrawerLayout mDrawerLayout;
Button btnAddNote;
NavigationView navView;


NotesRecyclerView rVNoteList;
NoteListAdapter adapter;


View emptyList;
FloatingActionButton fab;
ArrayList<Notes> mAllNotes;


@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

initialize();

setBackgroundImage();
initialize();

//update recyclerView//
updateAdapter();
rVNoteList.isEmptyListInvisible(mToolbar);


rVNoteList.isEmptyListInvisible(mToolbar,fab);
rVNoteList.isEmptyListVisible(emptyList);
implementFilter();

}
private void implementFilter(){
int selectedFilter= MemoryBookApp.readShared(this);
switch (selectedFilter){
case Filters.NOFILTER:
updateAdapter(NOTE_NOT_INLINE, NOTE_COMPLETED_UNIMPORTANT);
break;
case Filters.LONG_TIME:
updateAdapter(NoteProvider.COLUMN_NOTE_DATE+" DESC", NOTE_COMPLETED_UNIMPORTANT);
break;
case Filters.SHORT_TIME:
updateAdapter(NoteProvider.COLUMN_NOTE_DATE+" ASC", NOTE_COMPLETED_UNIMPORTANT);
break;
case Filters.COMPLETED_NOTE:
updateAdapter(NOTE_NOT_INLINE,"1");
break;
case Filters.NOT_COMPLETED_NOTE:
updateAdapter(NoteProvider.COLUMN_NOTE_DATE+" ASC","0");
break;
}
}
private void initialize(){
mToolbar=findViewById(R.id.toolbar);
setSupportActionBar(mToolbar);
mDrawerLayout=findViewById(R.id.drawerLayout);
ActionBarDrawerToggle drawerToggle=new ActionBarDrawerToggle(this,mDrawerLayout,mToolbar,R.string.open_drawer,R.string.close_drawer);
mDrawerLayout.addDrawerListener(drawerToggle);
drawerToggle.syncState();
navView=findViewById(R.id.nav_view);
navView.setItemIconTintList(null);
navView.setNavigationItemSelectedListener(this);


Calendar cal= Calendar.getInstance();
SimpleDateFormat month_date = new SimpleDateFormat("MMMM");
int day=cal.get(Calendar.DAY_OF_MONTH);
String month_name = month_date.format(cal.getTime());
String currentDate=day+"/"+month_name;

mToolbar.setSubtitle(currentDate);

btnAddNote=findViewById(R.id.btn_addNote);
fab=findViewById(R.id.fab);

mAllNotes=getAllNotesFromDatabase(NOTE_NOT_INLINE, NOTE_COMPLETED_UNIMPORTANT);

rVNoteList=findViewById(R.id.recyclerViewNoteList);
rVNoteList.addItemDecoration(new Divider(this,LinearLayoutManager.VERTICAL));
Expand All @@ -67,6 +128,18 @@ private void initialize(){

LinearLayoutManager manager=new LinearLayoutManager(this);
rVNoteList.setLayoutManager(manager);
adapter=new NoteListAdapter(this,mAllNotes);
adapter.setHasStableIds(true);
rVNoteList.setAdapter(adapter);

/**
*
* Swipe Processing Stuff
*
* */
SimpleTouchCallBack callBack=new SimpleTouchCallBack();
ItemTouchHelper helper=new ItemTouchHelper(callBack);
helper.attachToRecyclerView(rVNoteList);

btnAddNote.setOnClickListener(new View.OnClickListener() {
@Override
Expand All @@ -85,29 +158,49 @@ public void onClick(View v) {


}
public void updateAdapter(){
mAllNotes=getAllNotesFromDatabase();
NoteListAdapter adapter=new NoteListAdapter(this,mAllNotes);
rVNoteList.setAdapter(adapter);
public void updateAdapter(String order,String completed){
mAllNotes.clear();
mAllNotes=getAllNotesFromDatabase(order,completed);
adapter.updateData(mAllNotes);

}
private ArrayList<Notes> getAllNotesFromDatabase(){
private ArrayList<Notes> getAllNotesFromDatabase(String order,String completed){
String orderQuery=order;
String selection=NoteProvider.COLUMN_NOTE_COMPLETE+"=?";
String[] selectionArgs={completed};

if(order.equals(NOTE_NOT_INLINE)){
orderQuery=null;
}
if(completed.equals(NOTE_COMPLETED_UNIMPORTANT)){
selection=null;
selectionArgs=null;
}
String[] projection={
NoteProvider.COLUMN_NOTE_ID,
NoteProvider.COLUMN_NOTE_CONTENT,
NoteProvider.COLUMN_NOTE_DATE,
NoteProvider.COLUMN_NOTE_COMPLETE
};
Cursor cursor=getContentResolver().query(CONTENT_URI,projection,null,null,null);
Cursor cursor=getContentResolver().query(CONTENT_URI,projection,selection,selectionArgs,orderQuery);
Notes temporaryNote;
ArrayList<Notes> allNotes=new ArrayList<>();
if(cursor!=null){
while (cursor.moveToNext()){
int idColumnIndex=cursor.getColumnIndex(NoteProvider.COLUMN_NOTE_ID);
int contentColumnIndex=cursor.getColumnIndex(NoteProvider.COLUMN_NOTE_CONTENT);
int dateColumnIndex=cursor.getColumnIndex(NoteProvider.COLUMN_NOTE_DATE);
int completedColumnIndex=cursor.getColumnIndex(NoteProvider.COLUMN_NOTE_COMPLETE);

String noteContent=cursor.getString(contentColumnIndex);
String noteDate=cursor.getString(dateColumnIndex);
long noteDate=cursor.getLong(dateColumnIndex);
int noteId=cursor.getInt(idColumnIndex);
int noteCompleted=cursor.getInt(completedColumnIndex);

temporaryNote=new Notes(noteContent);
temporaryNote.setId(noteId);
temporaryNote.setNoteDate(noteDate);
temporaryNote.setNoteComplete(noteCompleted);
allNotes.add(temporaryNote);
}
}
Expand All @@ -120,18 +213,109 @@ private void showDialogNewNote() {
dialogFragmentNewNote.show(getSupportFragmentManager(),"dialog_new_note");
}

private void showDialogNoteCompleted(int position) {
EventBus.getDefault().postSticky(new DataEvent.DialogPositionComplete(position));
FragmentDialogNoteCompleted dialogNoteCompleted=new FragmentDialogNoteCompleted();
dialogNoteCompleted.show(getSupportFragmentManager(),"dialog_note_complete");
}

@Override
protected void onStart() {
EventBus.getDefault().register(this);
super.onStart();
}

@Subscribe
public void onDialogFragmentNewNote(DataEvent.ShowAddNoteDialog event){
if(event.getTrigger()==1){
showDialogNewNote();
}

}
@Subscribe
public void onUpdateDate(DataEvent.UpdateDataTrigger event){
if(event.getTrigger()==1){
updateAdapter(NOTE_NOT_INLINE, NOTE_COMPLETED_UNIMPORTANT);
}
}
@Subscribe
public void onDialogComplete(DataEvent.DialogNotePositionComplete event){
showDialogNoteCompleted(event.getPosition());

}


@Override
protected void onStop() {
EventBus.getDefault().unregister(this);
super.onStop();
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.menu_main,menu);
return true;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
boolean result=true;
switch (item.getItemId()){
case R.id.menu_new_note:
showDialogNewNote();
break;
case R.id.menu_no_filter:
MemoryBookApp.writeShared(this,Filters.NOFILTER);
updateAdapter(NOTE_NOT_INLINE, NOTE_COMPLETED_UNIMPORTANT);

break;
case R.id.menu_long_time:
MemoryBookApp.writeShared(this,Filters.LONG_TIME);
updateAdapter(NoteProvider.COLUMN_NOTE_DATE+" DESC", NOTE_COMPLETED_UNIMPORTANT);
break;
case R.id.menu_short_time:
MemoryBookApp.writeShared(this,Filters.SHORT_TIME);
updateAdapter(NoteProvider.COLUMN_NOTE_DATE+" ASC", NOTE_COMPLETED_UNIMPORTANT);
break;
case R.id.menu_completed_notes:
MemoryBookApp.writeShared(this,Filters.COMPLETED_NOTE);
updateAdapter(NOTE_NOT_INLINE,"1");
break;
case R.id.menu_not_completed_notes:
MemoryBookApp.writeShared(this,Filters.NOT_COMPLETED_NOTE);
updateAdapter(NoteProvider.COLUMN_NOTE_DATE+" ASC","0");
break;
default:
result=false;
MemoryBookApp.writeShared(this,Filters.NOFILTER);
}
return result;
}



private void setBackgroundImage() {
/*
ImageView imageView=findViewById(R.id.ivBackground);
ImageView imageView=findViewById(R.id.collapsingImage);
Glide.with(this)
.load(R.drawable.blue_background)
.load(R.drawable.collapsing_image)
.apply(new RequestOptions().centerCrop())
.into(imageView);
*/

}

@Override
public void showAddDialog() {
showDialogNewNote();
public boolean onNavigationItemSelected(@NonNull MenuItem menuItem) {
switch (menuItem.getItemId()){
case R.id.menu_my_day:
updateAdapter(NoteProvider.COLUMN_NOTE_DATE+" ASC", NOTE_COMPLETED_UNIMPORTANT);
mDrawerLayout.closeDrawers();


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

import android.app.Application;
import android.content.Context;
import android.content.SharedPreferences;
import android.preference.PreferenceManager;

import com.yunuscagliyan.memorybook.listeners.Filters;

public class MemoryBookApp extends Application {
public static void writeShared(Context context, int selectedFilter){
SharedPreferences preferences= PreferenceManager.getDefaultSharedPreferences(context);
SharedPreferences.Editor editor=preferences.edit();
editor.putInt("filter",selectedFilter);
editor.apply();
}
public static int readShared(Context context){
SharedPreferences preferences=PreferenceManager.getDefaultSharedPreferences(context);
int selectedFilter=preferences.getInt("filter", Filters.NOFILTER);
return selectedFilter;

}
}
Loading

0 comments on commit 9cb1566

Please sign in to comment.