mirror of
https://github.com/jfoucry/Pilldroid.git
synced 2024-11-21 20:19:23 +01:00
Merge branch 'feature/swip_to_remove' into develop
This commit is contained in:
commit
a4d2232b13
6 changed files with 115 additions and 7 deletions
|
@ -50,7 +50,6 @@ public class AlarmReceiver extends BroadcastReceiver {
|
|||
PrescriptionsDAO prescriptionsDAO = prescriptions.getPrescriptionsDAO();
|
||||
List<Prescription> prescriptionList = prescriptionsDAO.getAllMedics();
|
||||
Prescription firstPrescription = null ;
|
||||
//List<Drug> drugs = dbHelper.getAllDrugs();
|
||||
|
||||
try {
|
||||
firstPrescription = prescriptionList.get(1);
|
||||
|
|
|
@ -9,6 +9,9 @@ import android.content.Context;
|
|||
import android.content.Intent;
|
||||
import android.content.pm.ApplicationInfo;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.Paint;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.text.Editable;
|
||||
|
@ -30,9 +33,12 @@ import androidx.annotation.NonNull;
|
|||
import androidx.appcompat.app.AlertDialog;
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
import androidx.appcompat.widget.Toolbar;
|
||||
import androidx.core.content.ContextCompat;
|
||||
import androidx.recyclerview.widget.ItemTouchHelper;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
import androidx.room.Room;
|
||||
|
||||
import com.google.android.material.snackbar.Snackbar;
|
||||
import com.google.zxing.client.android.BuildConfig;
|
||||
import com.google.zxing.client.android.Intents;
|
||||
import com.journeyapps.barcodescanner.ScanOptions;
|
||||
|
@ -73,7 +79,7 @@ public class DrugListActivity extends AppCompatActivity {
|
|||
|
||||
private List<Prescription> prescriptionList; // used for prescriptions
|
||||
|
||||
private SimpleItemRecyclerViewAdapter mAdapter;
|
||||
private RecyclerViewAdapter mAdapter;
|
||||
|
||||
@Override
|
||||
public void onStart() {
|
||||
|
@ -463,19 +469,110 @@ public class DrugListActivity extends AppCompatActivity {
|
|||
*/
|
||||
private void setupRecyclerView(@NonNull RecyclerView recyclerView) {
|
||||
recyclerView.addItemDecoration(new SimpleDividerItemDecoration(getApplicationContext()));
|
||||
mAdapter = new SimpleItemRecyclerViewAdapter(prescriptionList);
|
||||
mAdapter = new RecyclerViewAdapter(prescriptionList);
|
||||
recyclerView.setAdapter(mAdapter);
|
||||
}
|
||||
|
||||
new ItemTouchHelper(new ItemTouchHelper.SimpleCallback(0, (ItemTouchHelper.RIGHT|ItemTouchHelper.LEFT)) {
|
||||
@Override
|
||||
public boolean onMove(@NonNull RecyclerView recyclerView, @NonNull RecyclerView.ViewHolder viewHolder, @NonNull RecyclerView.ViewHolder target) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSwiped(@NonNull RecyclerView.ViewHolder viewHolder, int direction) {
|
||||
int position = viewHolder.getBindingAdapterPosition();
|
||||
|
||||
Prescription prescription = prescriptionList.get(position);
|
||||
|
||||
if (direction == ItemTouchHelper.LEFT) {
|
||||
prescriptionList.remove(position);
|
||||
mAdapter.notifyItemRemoved(position);
|
||||
// Remove item form database
|
||||
PrescriptionsDAO prescriptionsDAO = prescriptions.getPrescriptionsDAO();
|
||||
prescriptionsDAO.delete(prescription);
|
||||
} else {
|
||||
// Call DetailView
|
||||
Intent intent = new Intent(getApplicationContext(), DrugDetailActivity.class);
|
||||
intent.putExtra("prescription", prescription);
|
||||
startActivityForResult(intent, CUSTOMIZED_REQUEST_CODE);
|
||||
}
|
||||
|
||||
|
||||
|
||||
Snackbar.make(recyclerView, prescription.getName(),
|
||||
Snackbar.LENGTH_LONG).setAction(R.string.Undo, new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
prescriptionList.add(position, prescription);
|
||||
mAdapter.notifyItemInserted(position);
|
||||
}
|
||||
}).show();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onChildDraw(@NonNull Canvas c, @NonNull RecyclerView recyclerView, @NonNull RecyclerView.ViewHolder viewHolder, float dX, float dY, int actionState, boolean isCurrentlyActive) {
|
||||
if (actionState == ItemTouchHelper.ACTION_STATE_SWIPE) {
|
||||
// Get RecyclerView item from the ViewHolder
|
||||
View itemView = viewHolder.itemView;
|
||||
|
||||
Paint p = new Paint();
|
||||
Drawable icon;
|
||||
icon = ContextCompat.getDrawable(getApplicationContext(), R.drawable.ic_trash_can_outline);
|
||||
|
||||
int xMarkMargin = (int) getApplicationContext().getResources().getDimension(R.dimen.fab_margin);
|
||||
|
||||
assert icon != null;
|
||||
int intrinsicWidth = icon.getIntrinsicWidth();
|
||||
int intrinsicHeight = icon.getIntrinsicHeight();
|
||||
int itemHeight = itemView.getBottom() - itemView.getTop();
|
||||
|
||||
if (dX > 0) {
|
||||
p.setColor(getColor(R.color.bg_screen3));
|
||||
icon = ContextCompat.getDrawable(getApplicationContext(), R.drawable.ic_edit_black_48dp);
|
||||
|
||||
// Draw Rect with varying right side, equal to displacement dX
|
||||
c.drawRect((float) itemView.getLeft(), (float) itemView.getTop(), dX,
|
||||
(float) itemView.getBottom(), p);
|
||||
|
||||
int xMarkLeft = itemView.getLeft() + xMarkMargin;
|
||||
int xMarkRight = itemView.getLeft() + xMarkMargin + intrinsicWidth;
|
||||
int xMarkTop = itemView.getTop() + (itemHeight - intrinsicHeight) / 2;
|
||||
int xMarkBottom = xMarkTop + intrinsicHeight;// +xMarkTop;
|
||||
assert icon != null;
|
||||
icon.setBounds(xMarkLeft, xMarkTop, xMarkRight, xMarkBottom);
|
||||
|
||||
} else {
|
||||
p.setColor(getColor(R.color.bg_screen4));
|
||||
// Draw Rect with varying left side, equal to the item's right side plus negative displacement dX
|
||||
c.drawRect((float) itemView.getRight() + dX, (float) itemView.getTop(),
|
||||
(float) itemView.getRight(), (float) itemView.getBottom(), p);
|
||||
|
||||
|
||||
int xMarkLeft = itemView.getRight() - xMarkMargin - intrinsicWidth;
|
||||
int xMarkRight = itemView.getRight() - xMarkMargin;
|
||||
int xMarkTop = itemView.getTop() + (itemHeight - intrinsicHeight) / 2;
|
||||
int xMarkBottom = xMarkTop + intrinsicHeight;
|
||||
icon.setBounds(xMarkLeft, xMarkTop, xMarkRight, xMarkBottom);
|
||||
|
||||
}
|
||||
icon.draw(c);
|
||||
|
||||
super.onChildDraw(c, recyclerView, viewHolder, dX, dY, actionState, isCurrentlyActive);
|
||||
}
|
||||
}
|
||||
}).attachToRecyclerView(recyclerView);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* SimpleItemRecyclerViewAdapter
|
||||
*/
|
||||
public class SimpleItemRecyclerViewAdapter extends
|
||||
RecyclerView.Adapter<SimpleItemRecyclerViewAdapter.ViewHolder> {
|
||||
public class RecyclerViewAdapter extends
|
||||
RecyclerView.Adapter<RecyclerViewAdapter.ViewHolder> {
|
||||
|
||||
private final List<Prescription> mValues;
|
||||
|
||||
SimpleItemRecyclerViewAdapter(List<Prescription> items) {
|
||||
RecyclerViewAdapter(List<Prescription> items) {
|
||||
mValues = items;
|
||||
}
|
||||
|
||||
|
|
4
app/src/main/res/drawable/ic_edit_black_48dp.xml
Normal file
4
app/src/main/res/drawable/ic_edit_black_48dp.xml
Normal file
|
@ -0,0 +1,4 @@
|
|||
<vector android:height="48dp" android:viewportHeight="24"
|
||||
android:viewportWidth="24" android:width="48dp" xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<path android:fillColor="#000000" android:pathData="M3,17.25V21h3.75L17.81,9.94l-3.75,-3.75L3,17.25zM20.71,7.04c0.39,-0.39 0.39,-1.02 0,-1.41l-2.34,-2.34c-0.39,-0.39 -1.02,-0.39 -1.41,0l-1.83,1.83 3.75,3.75 1.83,-1.83z"/>
|
||||
</vector>
|
4
app/src/main/res/drawable/ic_trash_can_outline.xml
Normal file
4
app/src/main/res/drawable/ic_trash_can_outline.xml
Normal file
|
@ -0,0 +1,4 @@
|
|||
<vector android:height="48dp" android:viewportHeight="24"
|
||||
android:viewportWidth="24" android:width="48dp" xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<path android:fillColor="#FF000000" android:pathData="M9,3V4H4V6H5V19A2,2 0,0 0,7 21H17A2,2 0,0 0,19 19V6H20V4H15V3H9M7,6H17V19H7V6M9,8V17H11V8H9M13,8V17H15V8H13Z"/>
|
||||
</vector>
|
|
@ -68,4 +68,6 @@
|
|||
<string name="missing_camera_permission">Autorisation appareil photo manquante</string>
|
||||
<string name="Yes">Oui, j\'ai compris</string>
|
||||
<string name="understood">Je comprends que le développeur de app_name n\'est pas responsable de la gestion de vos médicaments. CELA RELÈVE DE VOTRE SEULE RESPONSABILITË.</string>
|
||||
<string name="Undo">Annuler</string>
|
||||
<string name="trash_icon">Icone de poubelle</string>
|
||||
</resources>
|
|
@ -70,4 +70,6 @@
|
|||
<string name="missing_camera_permission">Missing camera permission</string>
|
||||
<string name="Yes">Yes, I understood</string>
|
||||
<string name="understood">I understood that de developer of app_name cannot be responsible ot your medication management. IT\'S YOU OWN RESPONSIBILITY.</string>
|
||||
<string name="Undo">Undo</string>
|
||||
<string name="trash_icon">Trash icon</string>
|
||||
</resources>
|
||||
|
|
Loading…
Reference in a new issue