Compare commits

..

No commits in common. "06e879a9ae43a8d3522ef592e23c736b5b2f1903" and "0784d5672c1b2b0860755d741bac126a4e4d30b3" have entirely different histories.

4 changed files with 83 additions and 91 deletions

View file

@ -10,8 +10,10 @@ import android.widget.TextView;
import androidx.appcompat.app.ActionBar; import androidx.appcompat.app.ActionBar;
import androidx.appcompat.app.AppCompatActivity; import androidx.appcompat.app.AppCompatActivity;
import com.google.android.material.appbar.MaterialToolbar; import com.google.android.material.appbar.MaterialToolbar;
import com.google.android.material.floatingactionbutton.ExtendedFloatingActionButton; import com.google.android.material.floatingactionbutton.ExtendedFloatingActionButton;
import net.foucry.pilldroid.dao.PrescriptionsDAO; import net.foucry.pilldroid.dao.PrescriptionsDAO;
import net.foucry.pilldroid.databases.PrescriptionDatabase; import net.foucry.pilldroid.databases.PrescriptionDatabase;
import net.foucry.pilldroid.models.Prescription; import net.foucry.pilldroid.models.Prescription;

View file

@ -40,9 +40,12 @@ 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.content.ContextCompat; import androidx.core.content.ContextCompat;
import androidx.lifecycle.ViewModelProvider;
import androidx.recyclerview.widget.ItemTouchHelper; import androidx.recyclerview.widget.ItemTouchHelper;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView; import androidx.recyclerview.widget.RecyclerView;
import androidx.room.Room; import androidx.room.Room;
import androidx.room.RoomDatabase;
import com.google.android.material.dialog.MaterialAlertDialogBuilder; import com.google.android.material.dialog.MaterialAlertDialogBuilder;
import com.google.android.material.floatingactionbutton.FloatingActionButton; import com.google.android.material.floatingactionbutton.FloatingActionButton;
@ -58,6 +61,7 @@ import net.foucry.pilldroid.databases.PrescriptionDatabase;
import net.foucry.pilldroid.models.Medicine; import net.foucry.pilldroid.models.Medicine;
import net.foucry.pilldroid.models.Prescription; import net.foucry.pilldroid.models.Prescription;
import de.raphaelebner.roomdatabasebackup.core.RoomBackup;
import java.io.File; import java.io.File;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.Date; import java.util.Date;
@ -65,8 +69,6 @@ import java.util.List;
import java.util.Locale; import java.util.Locale;
import java.util.Objects; import java.util.Objects;
import de.raphaelebner.roomdatabasebackup.core.RoomBackup;
/** /**
* An activity representing a list of Drugs is activity * An activity representing a list of Drugs is activity
* has different presentations for handset and tablet-size devices. On * has different presentations for handset and tablet-size devices. On
@ -77,6 +79,7 @@ import de.raphaelebner.roomdatabasebackup.core.RoomBackup;
*/ */
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 String SECRET_PASSWORD = ;
public final int CUSTOMIZED_REQUEST_CODE = 0x0000ffff; public final int CUSTOMIZED_REQUEST_CODE = 0x0000ffff;
// Barcode Scanner usage // Barcode Scanner usage
@ -201,7 +204,7 @@ public class DrugListActivity extends AppCompatActivity {
} }
FloatingActionButton mFloatingActionButton = findViewById(R.id.fab); FloatingActionButton mFloatingActionButton = findViewById(R.id.fab);
mFloatingActionButton.setOnClickListener(v -> onButtonClick()); mFloatingActionButton.setOnClickListener(v-> onButtonClick());
if (DEMO) { if (DEMO) {
PrescriptionsDAO prescriptionsDAO = prescriptions.getPrescriptionsDAO(); PrescriptionsDAO prescriptionsDAO = prescriptions.getPrescriptionsDAO();
@ -391,7 +394,8 @@ public class DrugListActivity extends AppCompatActivity {
if (s.length() == 8) { if (s.length() == 8) {
ok.setEnabled(true); ok.setEnabled(true);
ok.setBackground(Objects.requireNonNull(ContextCompat.getDrawable(editText.getContext(), R.drawable.rounded_btn))); ok.setBackground(Objects.requireNonNull(ContextCompat.getDrawable(editText.getContext(), R.drawable.rounded_btn)));
} else { }
else {
ok.setEnabled(false); ok.setEnabled(false);
ok.setBackground(Objects.requireNonNull(ContextCompat.getDrawable(editText.getContext(), R.drawable.rounded_btn_disabled))); ok.setBackground(Objects.requireNonNull(ContextCompat.getDrawable(editText.getContext(), R.drawable.rounded_btn_disabled)));
} }
@ -753,7 +757,10 @@ public class DrugListActivity extends AppCompatActivity {
}); });
dlg.show();*/ dlg.show();*/
Button btn_export = findViewById(R.id.switch_btn_export);
Button btn_import = findViewById(R.id.switch_btn_import);
Button btn_properties = findViewById(R.id.btn_properties);
Button btn_backupLocation = findViewById(R.id.btn_backup_location);
/*recyclerView.setAdapter(adapter); /*recyclerView.setAdapter(adapter);
recyclerView.setLayoutManager(new LinearLayoutManager(this)); recyclerView.setLayoutManager(new LinearLayoutManager(this));
@ -793,22 +800,17 @@ public class DrugListActivity extends AppCompatActivity {
// startActivity(intent); // startActivity(intent);
// }); // });
Button btn_export = findViewById(R.id.switch_btn_export);
Button btn_import = findViewById(R.id.switch_btn_import);
Button btn_properties = findViewById(R.id.btn_properties);
Button btn_backupLocation = findViewById(R.id.btn_backup_location);
encryptBackup = sharedPreferences.getBoolean(spEncryptBackup, true); encryptBackup = sharedPreferences.getBoolean(spEncryptBackup, true);
storageLocation = sharedPreferences.getInt(spStorageLocation, 1); storageLocation = sharedPreferences.getInt(spStorageLocation, 1);
enableLog = sharedPreferences.getBoolean(spEnableLog, true); enableLog = sharedPreferences.getBoolean(spEnableLog, true);
useMaxFileCount = sharedPreferences.getBoolean(spUseMaxFileCount, false); useMaxFileCount = sharedPreferences.getBoolean(spUseMaxFileCount, false);
final String[] multiItems = new String[]{"Encrypt Backup", "enable Log", "use maxFileCount = 5"}; final String[] multiItems = new String[] { "Encrypt Backup", "enable Log", "use maxFileCount = 5" };
final boolean[] checkedItems = new boolean[]{encryptBackup, enableLog, useMaxFileCount}; final boolean[] checkedItems = new boolean[] { encryptBackup, enableLog, useMaxFileCount };
final String[] storageItems = new String[]{"Internal", "External", "Custom Dialog", "Custom File"}; final String[] storageItems = new String[] { "Internal", "External", "Custom Dialog", "Custom File" };
/*---------------------set Properties--------------------------*/ /*---------------------set Properties--------------------------*/
btn_properties.setOnClickListener(v -> { // TODO: Null pointer exception application crash [should be the same with other button] btn_properties.setOnClickListener(v -> {
MaterialAlertDialogBuilder materialAlertDialogBuilder = new MaterialAlertDialogBuilder( MaterialAlertDialogBuilder materialAlertDialogBuilder = new MaterialAlertDialogBuilder(
DrugListActivity.this); DrugListActivity.this);
materialAlertDialogBuilder.setTitle("Change Properties"); materialAlertDialogBuilder.setTitle("Change Properties");
@ -866,46 +868,32 @@ public class DrugListActivity extends AppCompatActivity {
}); });
Log.i(TAG, "ok button"); Log.i(TAG, "ok button");
PrescriptionDatabase prescriptions = PrescriptionDatabase.getInstanceDatabase(this); PrescriptionDatabase prescriptions = PrescriptionDatabase.getInstanceDatabase(this);
final RoomBackup roomBackup = new RoomBackup(DrugListActivity.this); final RoomBackup roomBackup = new RoomBackup(DrugListActivity.this);
if (btn_export.isEnabled()) { if ( btn_export.isEnabled() ) {
btn_export.setOnClickListener(v -> { // TODO: call `make backup
roomBackup.backupLocation(storageLocation); roomBackup.backupLocation(storageLocation);
roomBackup.backupLocationCustomFile(new File(this.getFilesDir() + "/databasebackup/geilesBackup.sqlite3")); roomBackup.database(PrescriptionDatabase.getInstanceDatabase(this));
roomBackup.database(PrescriptionDatabase.getInstanceDatabase(getApplicationContext())); roomBackup.enableLogDebug(enableLog);
roomBackup.enableLogDebug(enableLog); roomBackup.backupIsEncrypted(encryptBackup);
roomBackup.backupIsEncrypted(encryptBackup); roomBackup.customEncryptPassword(DrugListActivity.SECRET_PASSWORD);
//roomBackup.customEncryptPassword(MainActivity.SECRET_PASSWORD); if (useMaxFileCount)
if (useMaxFileCount) roomBackup.maxFileCount(5);
roomBackup.maxFileCount(5); roomBackup.onCompleteListener((success, message, exitCode) -> {
roomBackup.onCompleteListener((success, message, exitCode) -> { Log.d(TAG, "oncomplete: " + success + "message: " + message + ",exitCode: " + exitCode);
Log.d(TAG, "oncomplete: " + success + ", message: " + message + ", exitCode: " + exitCode); if (success)
if (success) roomBackup.restartApp(new Intent(getApplicationContext(), DrugListActivity.class));
roomBackup.restartApp(new Intent(getApplicationContext(), DrugListActivity.class)); });
}); roomBackup.backup();
roomBackup.backup();
});
} else {
btn_import.setOnClickListener(v -> {
roomBackup.backupLocation(storageLocation);
roomBackup.backupLocationCustomFile(new File(this.getFilesDir() + "/databasebackup/geilesBackup.sqlite3"));
roomBackup.database(PrescriptionDatabase.getInstanceDatabase(getApplicationContext()));
roomBackup.enableLogDebug(enableLog);
roomBackup.backupIsEncrypted(encryptBackup);
//roomBackup.customEncryptPassword(MainActivity.SECRET_PASSWORD);
roomBackup.onCompleteListener((success, message, exitCode) -> {
Log.d(TAG, "oncomplete: " + success + ", message: " + message + ", exitCode: " + exitCode);
if (success)
roomBackup.restartApp(new Intent(getApplicationContext(), DrugListActivity.class));
});
roomBackup.restore();
}); } else {
} // TODO: call restore backup
//prescriptions.restore();
} }
} }
}
/* /*

View file

@ -12,7 +12,7 @@
android:layout_height="319dp" android:layout_height="319dp"
android:layout_marginStart="12dp" android:layout_marginStart="12dp"
android:layout_marginEnd="12dp" android:layout_marginEnd="12dp"
android:background="@color/white" android:background="@color/lightgrey"
app:cardCornerRadius="@dimen/btn_radius" app:cardCornerRadius="@dimen/btn_radius"
app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"
@ -26,33 +26,25 @@
style="@style/Widget.MaterialComponents.Button.OutlinedButton" style="@style/Widget.MaterialComponents.Button.OutlinedButton"
android:layout_width="0dp" android:layout_width="0dp"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginTop="100dp" android:layout_marginEnd="68dp"
android:layout_marginEnd="76dp"
android:layout_weight="1" android:layout_weight="1"
android:backgroundTint="@color/selected_background" android:backgroundTint="@color/selected_background"
android:bottomLeftRadius="0dp"
android:bottomRightRadius="10dp"
android:gravity="center" android:gravity="center"
android:paddingStart="25dp" android:paddingStart="25dp"
android:paddingEnd="25dp" android:paddingEnd="25dp"
android:text="@string/export_prescriptions" android:text="@string/export_prescriptions"
android:textColor="@color/white" android:textColor="@color/white"
android:topLeftRadius="0dp" app:layout_constraintBottom_toBottomOf="@+id/switch_btn_import"
android:topRightRadius="10dp"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent" /> app:layout_constraintTop_toTopOf="@+id/switch_btn_import" />
<com.google.android.material.button.MaterialButton <com.google.android.material.button.MaterialButton
android:id="@+id/switch_btn_import" android:id="@+id/switch_btn_import"
style="@style/Widget.MaterialComponents.Button.OutlinedButton" style="@style/Widget.MaterialComponents.Button.OutlinedButton"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginStart="76dp"
android:layout_marginTop="100dp"
android:layout_weight="1" android:layout_weight="1"
android:backgroundTint="@color/unselected_background" android:backgroundTint="@color/unselected_background"
android:bottomLeftRadius="10dp"
android:bottomRightRadius="0dp"
android:gravity="center" android:gravity="center"
android:maxLines="1" android:maxLines="1"
android:minWidth="100dp" android:minWidth="100dp"
@ -60,10 +52,9 @@
android:paddingEnd="25dp" android:paddingEnd="25dp"
android:text="@string/import_prescriptions" android:text="@string/import_prescriptions"
android:textColor="@color/white" android:textColor="@color/white"
android:topLeftRadius="10dp" app:layout_constraintBottom_toBottomOf="@+id/switch_btn_export"
android:topRightRadius="0dp" app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toTopOf="@+id/switch_btn_export" />
app:layout_constraintTop_toTopOf="parent" />
<com.google.android.material.button.MaterialButton <com.google.android.material.button.MaterialButton
android:id="@+id/notagreed" android:id="@+id/notagreed"
@ -81,31 +72,17 @@
android:textColor="@color/white" android:textColor="@color/white"
android:textSize="16sp" android:textSize="16sp"
app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@+id/agreed"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
tools:ignore="HardcodedText,SpUsage" /> tools:ignore="HardcodedText,SpUsage" />
<com.google.android.material.button.MaterialButton
android:id="@+id/btn_properties"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="64dp"
android:layout_marginBottom="100dp"
android:background="@drawable/rounded_btn"
android:gravity="center"
android:maxLines="1"
android:minWidth="100dp"
android:paddingStart="25dp"
android:paddingEnd="25dp"
android:text="@string/properties"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent" />
<com.google.android.material.button.MaterialButton <com.google.android.material.button.MaterialButton
android:id="@+id/btn_backup_location" android:id="@+id/btn_backup_location"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginStart="76dp" android:layout_marginStart="76dp"
android:layout_marginBottom="100dp" android:layout_marginEnd="2dp"
android:background="@drawable/rounded_btn" android:background="@drawable/rounded_btn"
android:gravity="center" android:gravity="center"
android:maxLines="1" android:maxLines="1"
@ -113,15 +90,38 @@
android:paddingStart="25dp" android:paddingStart="25dp"
android:paddingEnd="25dp" android:paddingEnd="25dp"
android:text="@string/location" android:text="@string/location"
app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintBottom_toBottomOf="@+id/btn_properties"
app:layout_constraintStart_toStartOf="parent" /> app:layout_constraintEnd_toStartOf="@+id/btn_properties"
app:layout_constraintHorizontal_bias="1.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="@+id/btn_properties"
app:layout_constraintVertical_bias="0.0" />
<com.google.android.material.button.MaterialButton
android:id="@+id/btn_properties"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="68dp"
android:background="@drawable/rounded_btn"
android:gravity="center"
android:maxLines="1"
android:minWidth="100dp"
android:paddingStart="25dp"
android:paddingEnd="25dp"
android:text="@string/properties"
app:layout_constraintBottom_toBottomOf="@+id/btn_backup_location"
app:layout_constraintEnd_toStartOf="@+id/btn_backup_location"
app:layout_constraintHorizontal_bias="1.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="@+id/btn_backup_location"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintVertical_bias="0.0"/>
<com.google.android.material.button.MaterialButton <com.google.android.material.button.MaterialButton
android:id="@+id/agreed" android:id="@+id/agreed"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginEnd="16dp" android:layout_marginEnd="16dp"
android:layout_marginBottom="16dp"
android:background="@drawable/rounded_btn" android:background="@drawable/rounded_btn"
android:gravity="center" android:gravity="center"
android:maxLines="1" android:maxLines="1"
@ -131,22 +131,23 @@
android:text="@string/button_ok" android:text="@string/button_ok"
android:textColor="@color/white" android:textColor="@color/white"
android:textSize="16sp" android:textSize="16sp"
app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintBottom_toBottomOf="@+id/notagreed"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="@+id/notagreed"
app:layout_constraintVertical_bias="0.0"
tools:ignore="HardcodedText,SpUsage" /> tools:ignore="HardcodedText,SpUsage" />
<com.google.android.material.imageview.ShapeableImageView <com.google.android.material.imageview.ShapeableImageView
android:id="@+id/shapeableImageView" android:id="@+id/shapeableImageView"
android:layout_width="60dp" android:layout_width="60dp"
android:layout_height="60dp" android:layout_height="60dp"
android:layout_marginBottom="256dp" android:layout_marginTop="4dp"
android:background="@drawable/shadow_bg" android:background="@drawable/shadow_bg"
android:foreground="@drawable/ic_launcher_foreground" android:foreground="@drawable/ic_launcher_foreground"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:layout_conversion_absoluteHeight="61dp" tools:layout_conversion_absoluteHeight="61dp"
tools:layout_conversion_absoluteWidth="61dp" /> tools:layout_conversion_absoluteWidth="61dp" />
</androidx.constraintlayout.widget.ConstraintLayout> </androidx.constraintlayout.widget.ConstraintLayout>
</androidx.constraintlayout.widget.ConstraintLayout> </androidx.constraintlayout.widget.ConstraintLayout>

View file

@ -20,4 +20,5 @@
<color name="grey">#777</color> <color name="grey">#777</color>
<color name="unselected_background">#777777</color> <color name="unselected_background">#777777</color>
<color name="selected_background">#4f91ff</color> <color name="selected_background">#4f91ff</color>
<color name="lightgrey">#ACABAC</color>
</resources> </resources>