mirror of
https://github.com/jfoucry/Pilldroid.git
synced 2024-11-21 20:19:23 +01:00
commit with some errors.
This commit is contained in:
parent
38eeafa550
commit
855f66e3f5
3 changed files with 173 additions and 81 deletions
|
@ -15,6 +15,7 @@ import android.graphics.Color;
|
||||||
import android.graphics.Paint;
|
import android.graphics.Paint;
|
||||||
import android.graphics.drawable.ColorDrawable;
|
import android.graphics.drawable.ColorDrawable;
|
||||||
import android.graphics.drawable.Drawable;
|
import android.graphics.drawable.Drawable;
|
||||||
|
import android.net.Uri;
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.text.Editable;
|
import android.text.Editable;
|
||||||
|
@ -26,8 +27,6 @@ import android.view.MenuInflater;
|
||||||
import android.view.MenuItem;
|
import android.view.MenuItem;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
import android.view.Window;
|
|
||||||
import android.widget.Button;
|
|
||||||
import android.widget.EditText;
|
import android.widget.EditText;
|
||||||
import android.widget.ImageView;
|
import android.widget.ImageView;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
@ -35,9 +34,11 @@ import android.widget.Toast;
|
||||||
|
|
||||||
import androidx.activity.result.ActivityResultLauncher;
|
import androidx.activity.result.ActivityResultLauncher;
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
|
import androidx.annotation.RequiresApi;
|
||||||
import androidx.appcompat.app.AlertDialog;
|
import androidx.appcompat.app.AlertDialog;
|
||||||
import androidx.appcompat.app.AppCompatActivity;
|
import androidx.appcompat.app.AppCompatActivity;
|
||||||
import androidx.appcompat.widget.Toolbar;
|
import androidx.appcompat.widget.Toolbar;
|
||||||
|
import androidx.core.app.ActivityCompat;
|
||||||
import androidx.core.content.ContextCompat;
|
import androidx.core.content.ContextCompat;
|
||||||
import androidx.recyclerview.widget.ItemTouchHelper;
|
import androidx.recyclerview.widget.ItemTouchHelper;
|
||||||
import androidx.recyclerview.widget.RecyclerView;
|
import androidx.recyclerview.widget.RecyclerView;
|
||||||
|
@ -70,6 +71,7 @@ import java.util.Locale;
|
||||||
*/
|
*/
|
||||||
public class DrugListActivity extends AppCompatActivity {
|
public class DrugListActivity extends AppCompatActivity {
|
||||||
private static final String TAG = DrugListActivity.class.getName();
|
private static final String TAG = DrugListActivity.class.getName();
|
||||||
|
private static final int POST_NOTIFICATIONS_PERMISSION = 100;
|
||||||
public final int CUSTOMIZED_REQUEST_CODE = 0x0000ffff;
|
public final int CUSTOMIZED_REQUEST_CODE = 0x0000ffff;
|
||||||
public final String BARCODE_FORMAT_NAME = "Barcode Format name";
|
public final String BARCODE_FORMAT_NAME = "Barcode Format name";
|
||||||
public final String BARCODE_CONTENT = "Barcode Content";
|
public final String BARCODE_CONTENT = "Barcode Content";
|
||||||
|
@ -82,6 +84,39 @@ public class DrugListActivity extends AppCompatActivity {
|
||||||
|
|
||||||
private RecyclerViewAdapter mAdapter;
|
private RecyclerViewAdapter mAdapter;
|
||||||
|
|
||||||
|
// Register the permissions callback, which handles the user's response to the
|
||||||
|
// system permissions dialog. Save the return value, an instance of
|
||||||
|
// ActivityResultLauncher, as an instance variable.
|
||||||
|
/*private final ActivityResultLauncher<String> requestPermissionLauncher =
|
||||||
|
registerForActivityResult(new ActivityResultContracts.RequestPermission(), isGranted -> {
|
||||||
|
if (isGranted) {
|
||||||
|
// Permission is granted. Continue the action or workflow in your
|
||||||
|
// app.
|
||||||
|
Log.d(TAG, "Permission already granted");
|
||||||
|
} else {
|
||||||
|
// Explain to the user that the feature is unavailable because the
|
||||||
|
// features requires a permission that the user has denied. At the
|
||||||
|
// same time, respect the user's decision. Don't link to system
|
||||||
|
// settings in an effort to convince the user to change their
|
||||||
|
// decision.
|
||||||
|
AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(this);
|
||||||
|
alertDialogBuilder.setMessage("This app will not run has expected without this permission");
|
||||||
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
|
||||||
|
alertDialogBuilder.setPositiveButton("Yes",
|
||||||
|
(arg0, arg1) -> makePermissionRequest());
|
||||||
|
}
|
||||||
|
|
||||||
|
alertDialogBuilder.setNegativeButton("No", new DialogInterface.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(DialogInterface dialog, int which) {
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
AlertDialog alertDialog = alertDialogBuilder.create();
|
||||||
|
alertDialog.show();
|
||||||
|
}
|
||||||
|
});*/
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onStart() {
|
public void onStart() {
|
||||||
super.onStart();
|
super.onStart();
|
||||||
|
@ -140,13 +175,92 @@ public class DrugListActivity extends AppCompatActivity {
|
||||||
nm.cancelAll();
|
nm.cancelAll();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
|
||||||
|
checkForPermissions();
|
||||||
|
}
|
||||||
// start tutorial (only in non debug mode)
|
// start tutorial (only in non debug mode)
|
||||||
// if(!net.foucry.pilldroid.BuildConfig.DEBUG) {
|
// if(!net.foucry.pilldroid.BuildConfig.DEBUG) {
|
||||||
Log.i(TAG, "Launch tutorial");
|
Log.i(TAG, "Launch tutorial");
|
||||||
startActivity(new Intent(this, WelcomeActivity.class));
|
//startActivity(new Intent(this, WelcomeActivity.class));
|
||||||
// }
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@RequiresApi(api = Build.VERSION_CODES.TIRAMISU)
|
||||||
|
private void checkForPermissions() {
|
||||||
|
if (ContextCompat.checkSelfPermission(this,
|
||||||
|
Manifest.permission.DYNAMIC_RECEIVER_NOT_EXPORTED_PERMISSION)
|
||||||
|
!= PackageManager.PERMISSION_GRANTED) {
|
||||||
|
|
||||||
|
ActivityCompat.requestPermissions(this,
|
||||||
|
new String[]{Manifest.permission.DYNAMIC_RECEIVER_NOT_EXPORTED_PERMISSION},
|
||||||
|
POST_NOTIFICATIONS_PERMISSION);
|
||||||
|
} else {
|
||||||
|
Log.d(TAG,"Nothing to do");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
public void onRequestPermissionsResult(int requestCode,
|
||||||
|
@NonNull String[] permissions, @NonNull int[] grantResults) {
|
||||||
|
if (requestCode == POST_NOTIFICATIONS_PERMISSION) {
|
||||||
|
if (grantResults.length > 0
|
||||||
|
&& grantResults[0] == PackageManager.PERMISSION_GRANTED) {
|
||||||
|
Log.d(TAG, "Permission granted");
|
||||||
|
} else {
|
||||||
|
showAlertDialog();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
|
||||||
|
}
|
||||||
|
// is called if the permission is not given.
|
||||||
|
public void showAlertDialog() {
|
||||||
|
AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(this);
|
||||||
|
alertDialogBuilder.setMessage("This app requires your location to function!");
|
||||||
|
alertDialogBuilder.setPositiveButton("Try again",
|
||||||
|
new DialogInterface.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(DialogInterface arg0, int arg1) {
|
||||||
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
|
||||||
|
checkForPermissions();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
alertDialogBuilder.setNegativeButton("Settings", new DialogInterface.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(DialogInterface dialog, int which) {
|
||||||
|
Intent i = new Intent(android.provider.Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
|
||||||
|
i.addCategory(Intent.CATEGORY_DEFAULT);
|
||||||
|
i.setData(Uri.parse("package:dk.redweb.intern.findetlokum"));
|
||||||
|
startActivity(i);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
AlertDialog alertDialog = alertDialogBuilder.create();
|
||||||
|
alertDialog.show();
|
||||||
|
}
|
||||||
|
|
||||||
|
/* @RequiresApi(api = Build.VERSION_CODES.TIRAMISU)
|
||||||
|
private void makePermissionRequest() {
|
||||||
|
requestPermissionLauncher.launch(android.Manifest.permission.POST_NOTIFICATIONS);
|
||||||
|
}*/
|
||||||
|
|
||||||
|
/*private void checkPermissionRequest() {
|
||||||
|
int permission = ActivityCompat.checkSelfPermission(this, Manifest.permission.POST_NOTIFICATIONS);
|
||||||
|
if (permission == PackageManager.PERMISSION_GRANTED) {
|
||||||
|
*//*if (ContextCompat.checkSelfPermission(this, Manifest.permission.POST_NOTIFICATIONS)
|
||||||
|
== PackageManager.PERMISSION_GRANTED) {*//*
|
||||||
|
// continue running app
|
||||||
|
Log.d(TAG, "Permission already granted");
|
||||||
|
|
||||||
|
} else if (shouldShowRequestPermissionRationale(Manifest.permission.POST_NOTIFICATIONS)) {
|
||||||
|
showAlertDialog();
|
||||||
|
} else {
|
||||||
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
|
||||||
|
makePermissionRequest();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}*/
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onStop() {
|
public void onStop() {
|
||||||
super.onStop();
|
super.onStop();
|
||||||
|
@ -336,23 +450,29 @@ public class DrugListActivity extends AppCompatActivity {
|
||||||
* show keyboardInput dialog
|
* show keyboardInput dialog
|
||||||
*/
|
*/
|
||||||
protected void showInputDialog() {
|
protected void showInputDialog() {
|
||||||
final Dialog dialog = new Dialog(this);
|
// get prompts.xml view
|
||||||
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
|
LayoutInflater layoutInflater = LayoutInflater.from(DrugListActivity.this);
|
||||||
dialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
|
View promptView = layoutInflater.inflate(R.layout.input_dialog, null);
|
||||||
|
AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(DrugListActivity.this);
|
||||||
|
alertDialogBuilder.setView(promptView);
|
||||||
|
|
||||||
dialog.setCancelable(true);
|
final EditText editText = promptView.findViewById(R.id.edittext);
|
||||||
dialog.setCanceledOnTouchOutside(true);
|
// setup a dialog window
|
||||||
dialog.setContentView(R.layout.input_dialog);
|
|
||||||
|
|
||||||
Button ok = (Button) dialog.findViewById(R.id.agreed);
|
alertDialogBuilder.setCancelable(false)
|
||||||
Button cancel = (Button) dialog.findViewById(R.id.notagreed);
|
.setPositiveButton(R.string.button_ok, (dialog, id) -> {
|
||||||
ok.setEnabled(false);
|
//String cip13 = editText.getText().toString();
|
||||||
//TextView title = (TextView ) dialog.findViewById(R.id.title);
|
String cip13 = "34009" + editText.getText().toString();
|
||||||
final EditText editText=(EditText)dialog.findViewById(R.id.editcip13);
|
MedicinesDAO medicineDAO = medicines.getMedicinesDAO();
|
||||||
String cip13 = String.valueOf(editText.getText());
|
Medicine aMedicine = medicineDAO.getMedicineByCIP13(cip13);
|
||||||
|
askToAddInDB(aMedicine);
|
||||||
|
})
|
||||||
|
.setNegativeButton(R.string.button_cancel,
|
||||||
|
(dialog, id) -> dialog.cancel());
|
||||||
|
|
||||||
|
// create an alert dialog
|
||||||
|
AlertDialog alert = alertDialogBuilder.create();
|
||||||
|
|
||||||
ok.setText(R.string.button_ok);
|
|
||||||
cancel.setText(R.string.button_cancel);
|
|
||||||
editText.addTextChangedListener(new TextWatcher() {
|
editText.addTextChangedListener(new TextWatcher() {
|
||||||
@Override
|
@Override
|
||||||
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
|
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
|
||||||
|
@ -364,28 +484,10 @@ public class DrugListActivity extends AppCompatActivity {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void afterTextChanged(Editable s) {
|
public void afterTextChanged(Editable s) {
|
||||||
//alert.getButton(alert.BUTTON_POSITIVE).setEnabled(s.length() == 8);
|
alert.getButton(alert.BUTTON_POSITIVE).setEnabled(s.length() == 8);
|
||||||
ok.setEnabled(s.length() == 8);
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
ok.setOnClickListener(new View.OnClickListener() {
|
alert.show();
|
||||||
public void onClick(View v) {
|
|
||||||
dialog.cancel();
|
|
||||||
Log.i("EditText Value",editText.getEditableText().toString());
|
|
||||||
MedicinesDAO medicinesDAO = medicines.getMedicinesDAO();
|
|
||||||
Medicine aMedicine = medicinesDAO.getMedicineByCIP13(cip13);
|
|
||||||
askToAddInDB(aMedicine);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
cancel.setOnClickListener(new View.OnClickListener() {
|
|
||||||
@Override
|
|
||||||
public void onClick(View v) {
|
|
||||||
dialog.cancel();
|
|
||||||
Log.i(TAG, "dismiss dialog");
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
dialog.show();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -395,48 +497,24 @@ public class DrugListActivity extends AppCompatActivity {
|
||||||
* @param aMedicine Prescription- medication to be added
|
* @param aMedicine Prescription- medication to be added
|
||||||
*/
|
*/
|
||||||
private void askToAddInDB(Medicine aMedicine) {
|
private void askToAddInDB(Medicine aMedicine) {
|
||||||
final Dialog dlg = new Dialog(this);
|
AlertDialog.Builder dlg = new AlertDialog.Builder(this);
|
||||||
dlg.requestWindowFeature(Window.FEATURE_NO_TITLE);
|
dlg.setTitle(getString(R.string.app_name));
|
||||||
dlg.getWindow().setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT));
|
|
||||||
dlg.setContentView(R.layout.custom_dialog_layout_one_button);
|
|
||||||
dlg.setCancelable(false);
|
|
||||||
TextView msg = dlg.findViewById(R.id.msg);
|
|
||||||
String msgString;
|
|
||||||
TextView cpl = dlg.findViewById(R.id.cpl);
|
|
||||||
String cplString;
|
|
||||||
ImageView icon = dlg.findViewById(R.id.image);
|
|
||||||
Button btn = dlg.findViewById(R.id.txtClose);
|
|
||||||
dlg.show();
|
|
||||||
|
|
||||||
if (aMedicine != null) {
|
if (aMedicine != null) {
|
||||||
msgString = aMedicine.getName() + " " + getString(R.string.msgFound);
|
String msg = aMedicine.getName() + " " + getString(R.string.msgFound);
|
||||||
msg.setText(msgString);
|
|
||||||
cplString = getString(R.string.addInList);
|
dlg.setMessage(msg);
|
||||||
if (cplString.equals("")) {
|
dlg.setNegativeButton(getString(R.string.button_cancel), (dialog, which) -> {
|
||||||
cpl.setEnabled(false);
|
// Nothing to do in case of cancel
|
||||||
}
|
});
|
||||||
icon.setImageResource(R.drawable.tickmark);
|
dlg.setPositiveButton(getString(R.string.button_ok), (dialog, which) -> {
|
||||||
btn.setOnClickListener(new View.OnClickListener() {
|
// Add Drug to DB then try to show it
|
||||||
@Override
|
|
||||||
public void onClick(View v) {
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
dlg.dismiss();
|
|
||||||
finish();
|
|
||||||
addDrugToList(Utils.medicine2prescription(aMedicine));
|
addDrugToList(Utils.medicine2prescription(aMedicine));
|
||||||
}
|
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
msgString = getString(R.string.msgNotFound);
|
dlg.setMessage(getString(R.string.msgNotFound));
|
||||||
msg.setText(msgString);
|
dlg.setPositiveButton("OK", (dialog, which) -> {
|
||||||
cpl.setText("");
|
// nothing to do to just dismiss dialog
|
||||||
icon.setImageResource(R.drawable.tickcross);
|
|
||||||
btn.setOnClickListener(new View.OnClickListener() {
|
|
||||||
@Override
|
|
||||||
public void onClick(View v) {
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
dlg.dismiss();
|
|
||||||
finish();
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
dlg.show();
|
dlg.show();
|
||||||
|
@ -456,7 +534,6 @@ public class DrugListActivity extends AppCompatActivity {
|
||||||
dlg.show();
|
dlg.show();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add New drug to the user database
|
* Add New drug to the user database
|
||||||
*
|
*
|
||||||
|
|
|
@ -0,0 +1,13 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<selector xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" tools:ignore="ExtraText">
|
||||||
|
<android:background:@drawable/background_dialog.xml/>
|
||||||
|
<android:orientation="vertical"/>
|
||||||
|
<ImageView
|
||||||
|
android:id="@+id/image"
|
||||||
|
android:layout_width="61dp"
|
||||||
|
android:layout_height="61dp"
|
||||||
|
android:layout_gravity="center"
|
||||||
|
android:layout_marginTop="12dp"
|
||||||
|
android:src="@drawable/tickmark"
|
||||||
|
tools:ignore="ContentDescription,ImageContrastCheck" />
|
||||||
|
</selector>
|
|
@ -38,14 +38,14 @@
|
||||||
app:layout_constraintStart_toStartOf="parent"
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
tools:ignore="HardcodedText,RtlHardcoded,SpUsage" />
|
tools:ignore="HardcodedText,RtlHardcoded,SpUsage" />
|
||||||
|
|
||||||
<Space
|
<!--<Space
|
||||||
android:id="@+id/space"
|
android:id="@+id/space"
|
||||||
android:layout_width="0dp"
|
android:layout_width="0dp"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_marginBottom="1dp"
|
android:layout_marginBottom="1dp"
|
||||||
app:layout_constraintEnd_toStartOf="@+id/agreed"
|
app:layout_constraintEnd_toStartOf="@+id/agreed"
|
||||||
app:layout_constraintStart_toEndOf="@+id/notagreed" />
|
app:layout_constraintStart_toEndOf="@+id/notagreed" />
|
||||||
|
-->
|
||||||
<Button
|
<Button
|
||||||
android:id="@+id/agreed"
|
android:id="@+id/agreed"
|
||||||
style="?android:attr/buttonBarButtonStyle"
|
style="?android:attr/buttonBarButtonStyle"
|
||||||
|
@ -68,10 +68,10 @@
|
||||||
tools:ignore="HardcodedText,RtlHardcoded,SpUsage" />
|
tools:ignore="HardcodedText,RtlHardcoded,SpUsage" />
|
||||||
|
|
||||||
<EditText
|
<EditText
|
||||||
android:id="@+id/editcip13"
|
android:id="@+id/edittext"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_marginEnd="28dp"
|
android:layout_marginEnd="@dimen/desc_padding"
|
||||||
android:autofillHints="cip13"
|
android:autofillHints="cip13"
|
||||||
android:ems="10"
|
android:ems="10"
|
||||||
android:hint="@string/enter_cip_13"
|
android:hint="@string/enter_cip_13"
|
||||||
|
@ -104,12 +104,14 @@
|
||||||
android:text="340009"
|
android:text="340009"
|
||||||
android:textAlignment="textEnd"
|
android:textAlignment="textEnd"
|
||||||
android:textSize="16sp"
|
android:textSize="16sp"
|
||||||
|
android:layout_marginStart="@dimen/desc_padding"
|
||||||
app:layout_constraintBottom_toBottomOf="parent"
|
app:layout_constraintBottom_toBottomOf="parent"
|
||||||
app:layout_constraintEnd_toStartOf="@+id/editcip13"
|
app:layout_constraintEnd_toStartOf="@+id/editcip13"
|
||||||
app:layout_constraintHorizontal_bias="0.525"
|
app:layout_constraintHorizontal_bias="0.525"
|
||||||
app:layout_constraintStart_toStartOf="parent"
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
app:layout_constraintTop_toTopOf="parent"
|
app:layout_constraintTop_toTopOf="parent"
|
||||||
app:layout_constraintVertical_bias="0.438" />
|
app:layout_constraintVertical_bias="0.438"
|
||||||
|
tools:ignore="UnknownId" />
|
||||||
|
|
||||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue