naprawiono wyświetlnie opcji usun

This commit is contained in:
Naiki00 2021-02-20 16:32:16 +01:00
parent df64b16800
commit 2c15b66b03
6 changed files with 87 additions and 61 deletions

View File

@ -1,5 +1,7 @@
package com.example.notatkon.adapter; package com.example.notatkon.adapter;
import android.os.Handler;
import android.os.Looper;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
@ -15,20 +17,30 @@ import com.example.notatkon.listener.NoteListener;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Timer;
import java.util.TimerTask;
//https://developer.android.com/guide/topics/ui/layout/recyclerview /*
https://developer.android.com/guide/topics/ui/layout/recyclerview
https://developer.android.com/reference/java/util/Timer
/* Aby klasa była adapterem musi dziedziczyć po RecyclerView.Adapter oraz wskazywać na ViewHolder */
// Aby klasa była adapterem musi dziedziczyć po RecyclerView.Adapter oraz wskazywać na ViewHolder */
public class NoteAdapter extends RecyclerView.Adapter<NoteAdapter.ViewHolder>{ public class NoteAdapter extends RecyclerView.Adapter<NoteAdapter.ViewHolder>{
private List<NoteEntity> listNotes; private List<NoteEntity> listNotes;
private List<NoteEntity> source;
private NoteListener noteListener; private NoteListener noteListener;
private Timer searchTimer;
//konstruktor //konstruktor
public NoteAdapter(List<NoteEntity> listNotes, NoteListener noteListener) { public NoteAdapter(List<NoteEntity> listNotes, NoteListener noteListener) {
this.listNotes = listNotes; this.listNotes = listNotes;
this.noteListener = noteListener; this.noteListener = noteListener;
source = listNotes;
} }
//implementacja ViewHoldera //implementacja ViewHoldera
@ -58,6 +70,40 @@ public class NoteAdapter extends RecyclerView.Adapter<NoteAdapter.ViewHolder>{
} }
} }
public void searchNote(final String token) {
searchTimer = new Timer();
searchTimer.schedule(new TimerTask() {
@Override
public void run() {
if (token.trim().isEmpty()) {
listNotes = source;
} else {
ArrayList<NoteEntity> tempContainer = new ArrayList<>();
for (NoteEntity noteEntity : source) {
if (noteEntity.getTitle().toLowerCase().contains(token.toLowerCase())
|| noteEntity.getSubtitle().toLowerCase().contains(token.toLowerCase())
|| noteEntity.getContent().toLowerCase().contains(token.toLowerCase())) {
tempContainer.add(noteEntity);
}
}
listNotes = tempContainer;
}
new Handler(Looper.getMainLooper()).post(new Runnable() {
@Override
public void run() {
notifyDataSetChanged();
}
});
}
}, 1000);
}
public void cancelTimer() {
if (searchTimer != null) {
searchTimer.cancel();
}
}
@NonNull @NonNull
@Override @Override
public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {

View File

@ -143,6 +143,9 @@ public class CreateNote extends AppCompatActivity {
final BottomSheetBehavior<LinearLayout> bottomSheetBehavior = BottomSheetBehavior.from(bottomToolbar); final BottomSheetBehavior<LinearLayout> bottomSheetBehavior = BottomSheetBehavior.from(bottomToolbar);
//wysuwanie dolnego paska narzędzi //wysuwanie dolnego paska narzędzi
if (selectedNote != null) {
bottomToolbar.findViewById(R.id.textBottomToolbar).setVisibility(View.VISIBLE);
bottomToolbar.findViewById(R.id.deleteNote).setVisibility(View.VISIBLE);
bottomToolbar.findViewById(R.id.textBottomToolbar).setOnClickListener(new View.OnClickListener() { bottomToolbar.findViewById(R.id.textBottomToolbar).setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
@ -153,10 +156,6 @@ public class CreateNote extends AppCompatActivity {
} }
} }
}); });
if (selectedNote != null) {
bottomToolbar.findViewById(R.id.deleteNote).setVisibility(View.VISIBLE);
bottomToolbar.findViewById(R.id.deleteNote).setOnClickListener(new View.OnClickListener() { bottomToolbar.findViewById(R.id.deleteNote).setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
@ -167,7 +166,6 @@ public class CreateNote extends AppCompatActivity {
} }
} }
/* /*
https://developer.android.com/guide/topics/ui/dialogs#CustomLayout https://developer.android.com/guide/topics/ui/dialogs#CustomLayout
*/ */

View File

@ -4,7 +4,10 @@ import android.annotation.SuppressLint;
import android.content.Intent; import android.content.Intent;
import android.os.AsyncTask; import android.os.AsyncTask;
import android.os.Bundle; import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
import android.util.Log; import android.util.Log;
import android.widget.EditText;
import android.widget.ImageView; import android.widget.ImageView;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
@ -70,6 +73,26 @@ public class MainActivity extends AppCompatActivity implements NoteListener {
// wyświetl na początku wszystkie notatki z bazy // wyświetl na początku wszystkie notatki z bazy
getAllNotes(REQUEST_SHOW_NOTE, false); getAllNotes(REQUEST_SHOW_NOTE, false);
EditText searchNote = findViewById(R.id.inputSearch);
searchNote.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
noteAdapter.cancelTimer();
}
@Override
public void afterTextChanged(Editable s) {
if (noteEntityList.size() != 0) {
noteAdapter.searchNote(s.toString());
}
}
});
} }

View File

@ -2,6 +2,6 @@
<shape xmlns:android="http://schemas.android.com/apk/res/android" <shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle"> android:shape="rectangle">
<solid android:color="@color/colorDialogWindow" /> <solid android:color="@color/colorBottomToolbar" />
<corners android:radius="@dimen/_15sdp" /> <corners android:radius="@dimen/_15sdp" />
</shape> </shape>

View File

@ -118,41 +118,12 @@
android:padding="@dimen/_10sdp" android:padding="@dimen/_10sdp"
app:layout_constraintBottom_toBottomOf="parent" > app:layout_constraintBottom_toBottomOf="parent" >
<ImageView
android:id="@+id/imageAddNote"
android:layout_weight="0.5"
android:layout_width="@dimen/_23sdp"
android:layout_height="@dimen/_23sdp"
android:contentDescription="@string/app_name"
android:src="@drawable/ic_baseline_add_circle_outline_24"
app:tint="@color/colorIcon" />
<ImageView
android:id="@+id/imageAddImage"
android:layout_weight="0.5"
android:layout_width="@dimen/_10sdp"
android:layout_height="@dimen/_23sdp"
android:layout_marginStart="@dimen/_5sdp"
android:layout_marginEnd="@dimen/_5sdp"
android:contentDescription="@string/app_name"
android:src="@drawable/ic_baseline_image_24"
app:tint="@color/colorIcon" />
<ImageView
android:id="@+id/imageAddWebLink"
android:layout_weight="0.5"
android:layout_width="@dimen/_20sdp"
android:layout_height="@dimen/_23sdp"
android:contentDescription="@string/app_name"
android:src="@drawable/ic_baseline_language_24"
app:tint="@color/colorIcon" />
</LinearLayout> </LinearLayout>
<ImageView <ImageView
android:id="@+id/AddNote" android:id="@+id/AddNote"
android:layout_width="wrap_content" android:layout_width="@dimen/_40sdp"
android:layout_height="wrap_content" android:layout_height="@dimen/_40sdp"
android:layout_gravity="bottom|end" android:layout_gravity="bottom|end"
android:layout_marginEnd="28dp" android:layout_marginEnd="28dp"
android:layout_marginBottom="20dp" android:layout_marginBottom="20dp"
@ -164,18 +135,4 @@
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"
app:tint="@color/colorPrimary" /> app:tint="@color/colorPrimary" />
<!--
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="@+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
android:layout_marginEnd="28dp"
android:layout_marginBottom="20dp"
app:backgroundTint="@color/colorAccent"
app:layout_constraintBottom_toTopOf="@id/QuickActions"
app:layout_constraintEnd_toEndOf="parent"
app:srcCompat="@drawable/ic_baseline_add_24" />
app:layout_constraintTop_toTopOf="@+id/QuickActions" -->
</androidx.constraintlayout.widget.ConstraintLayout> </androidx.constraintlayout.widget.ConstraintLayout>

View File

@ -15,6 +15,7 @@
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="@dimen/_35sdp" android:layout_height="@dimen/_35sdp"
android:text="Opcje" android:text="Opcje"
android:visibility="gone"
android:textColor="@color/black" android:textColor="@color/black"
android:textSize="@dimen/_12ssp" android:textSize="@dimen/_12ssp"
android:gravity="center"/> android:gravity="center"/>
@ -27,6 +28,7 @@
android:layout_marginEnd="@dimen/_12sdp" android:layout_marginEnd="@dimen/_12sdp"
android:layout_marginBottom="@dimen/_12sdp" android:layout_marginBottom="@dimen/_12sdp"
android:orientation="horizontal" android:orientation="horizontal"
android:visibility="gone"
android:gravity="center_vertical" android:gravity="center_vertical"
tools:ignore="UseCompoundDrawables"> tools:ignore="UseCompoundDrawables">