Commit 7557afcc authored by Craig Earley's avatar Craig Earley
Browse files

Merge branch 'database-actions-design-enhancements' into 'master'

enhances database actions activity for small screens, fixes a related crash

See merge request !16
parents a9967092 4fac821d
......@@ -19,9 +19,11 @@ import android.text.TextWatcher;
import android.text.format.Formatter;
import android.util.Log;
import android.view.Gravity;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.PopupMenu;
import android.widget.TextView;
import android.widget.Toast;
......@@ -231,7 +233,7 @@ public class DatabaseActionsActivity extends AppCompatActivity {
}
});
Button clean = findViewById(R.id.wipeDatabase);
/* Button clean = findViewById(R.id.wipeDatabase);
clean.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v){
......@@ -261,7 +263,7 @@ public class DatabaseActionsActivity extends AppCompatActivity {
public void onClick(View v){
verify(v);
}
});
});*/
Button upload = findViewById(R.id.uploadButton);
upload.setOnClickListener(new View.OnClickListener() {
......@@ -271,6 +273,110 @@ public class DatabaseActionsActivity extends AppCompatActivity {
}
});
final Button cleanOptions = findViewById(R.id.cleanOptions);
cleanOptions.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v){
// verify(v);
PopupMenu popup = new PopupMenu(DatabaseActionsActivity.this, cleanOptions);
popup.getMenuInflater()
.inflate(R.menu.cleaning_options, popup.getMenu());
popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
public boolean onMenuItemClick(MenuItem item) {
AlertDialog.Builder builder = new AlertDialog.Builder(DatabaseActionsActivity.this);
builder.setNegativeButton("Cancel", null);
builder.setTitle("Please confirm");
switch (item.getItemId()){
case R.id.cleanReadingTable:
if(db.copyDatabase("archive")){
builder.setPositiveButton("Yes, I am sure.", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
db.cleanDatabase("reading");
makeToast("The readings table is now clean");
editor.putString("lastClean", getTimestamp());
cleanTV.setText(String.format(res.getString(R.string.lastClean), getTimestamp()));
displayDatabaseStatus(db.getStatus());
editor.apply();
}
});
builder.setMessage("You are about to clean recent data from reading. This will store an archived copy. Are you sure?");
builder.create();
builder.show();
}
break;
case R.id.cleanStreamingTable:
if(db.copyDatabase("archive")){
builder.setPositiveButton("Yes, I am sure.", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
db.cleanDatabase("streaming");
makeToast("The streaming table is now clean");
editor.putString("lastClean", getTimestamp());
cleanTV.setText(String.format(res.getString(R.string.lastClean), getTimestamp()));
displayDatabaseStatus(db.getStatus());
editor.apply();
}
});
builder.setMessage("You are about to clean recent data from streaming. This will store an archived copy. Are you sure?");
builder.create();
builder.show();
}
break;
case R.id.cleanReadAndStreamTables:
if(db.copyDatabase("archive")){
builder.setPositiveButton("Yes, I am sure.", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
db.cleanDatabase("field");
makeToast("Both reading and streaming tables are now clean");
editor.putString("lastClean", getTimestamp());
cleanTV.setText(String.format(res.getString(R.string.lastClean), getTimestamp()));
displayDatabaseStatus(db.getStatus());
editor.apply();
}
});
builder.setMessage("You are about to clear all recent data. Erasing the database will store an archived copy. Are you sure?");
builder.create();
builder.show();
}
break;
case R.id.eraseDatabase:
if(db.copyDatabase("archive")){
builder.setPositiveButton("Yes, I am sure.", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
db.cleanDatabase("all");
makeToast("The database has been erased, set up a new one immediately");
editor.putString("lastClean", getTimestamp());
cleanTV.setText(String.format(res.getString(R.string.lastClean), getTimestamp()));
displayDatabaseStatus(db.getStatus());
//editor.apply();
editor.putString("trip","");
editor.apply();
}
});
builder.setTitle("WARNING: You are about to erase the entire database");
builder.setMessage("Erasing the database will store an archived copy and will require you to set up the database again. Are you sure?");
builder.create();
builder.show();
}
break;
}
editor.putString("lastClean", getTimestamp());
cleanTV.setText(String.format(res.getString(R.string.lastClean), getTimestamp()));
displayDatabaseStatus(db.getStatus());
editor.apply();
return true;
}
});
popup.show();
}
});
progressDialog = new ProgressDialog(this);
progressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
progressDialog.setIndeterminate(false);
......@@ -301,9 +407,7 @@ public class DatabaseActionsActivity extends AppCompatActivity {
builder.setMessage("Are you sure that you want to upload your tables? Doing this will move all of the " +
"data in the current local database to an archive folder.");
break;
case R.id.wipeDatabase:
case R.id.wipeStreamingTable:
case R.id.wipeReadingsTable:
case R.id.cleanOptions:
builder.setMessage("Wiping the database will store an archived copy. Are you sure?");
break;
}
......@@ -316,7 +420,7 @@ public class DatabaseActionsActivity extends AppCompatActivity {
} else {
Log.d("TABLECLEAN",Integer.toString(view.getId()));
button = findViewById(view.getId());
if (button == findViewById(R.id.wipeDatabase)) {
if (button == findViewById(R.id.eraseDatabase)) {
if(db.copyDatabase("archive")){
db.cleanDatabase("all");
makeToast("Local database content is now erased");
......@@ -326,7 +430,7 @@ public class DatabaseActionsActivity extends AppCompatActivity {
editor.apply();
}
}
else if (button == findViewById(R.id.wipeReadingsTable)) {
else if (button == findViewById(R.id.cleanReadingTable)) {
if(db.copyDatabase("archive")){
db.cleanDatabase("reading");
makeToast("Readings table is now clean");
......@@ -336,7 +440,7 @@ public class DatabaseActionsActivity extends AppCompatActivity {
editor.apply();
}
}
else if (button == findViewById(R.id.wipeStreamingTable)) {
else if (button == findViewById(R.id.cleanStreamingTable)) {
if(db.copyDatabase("archive")){
db.cleanDatabase("streaming");
makeToast("Streaming table is now clean");
......@@ -346,7 +450,7 @@ public class DatabaseActionsActivity extends AppCompatActivity {
editor.apply();
}
}
else if (button == findViewById(R.id.wipeFieldData)) {
else if (button == findViewById(R.id.cleanReadAndStreamTables)) {
if(db.copyDatabase("archive")){
db.cleanDatabase("field");
makeToast("Both streaming and reading tables are now clean");
......
......@@ -9,6 +9,8 @@ import android.content.SharedPreferences;
import android.content.pm.PackageManager;
import android.os.Bundle;
import androidx.preference.PreferenceManager;
import android.util.Log;
import android.view.View;
import androidx.appcompat.app.AlertDialog;
......@@ -135,6 +137,7 @@ public class MainScreenActivity extends AppCompatActivity {
.create();
d.show();
} else {
Log.d("DATABASE TRIP",tripName);
intent.putExtra(SensorSampleActivity.REMOTE_DB, true);
startActivity(intent);
}
......
......@@ -111,22 +111,14 @@
android:text="@string/upload_tables"
android:id="@+id/uploadButton"
style="@style/database_button_landscape" />
<Button
android:text="@string/wipeDB"
android:id="@+id/wipeDatabase"
style="@style/database_button_landscape" />
<Button
android:text="@string/clean_field_data"
android:id="@+id/wipeFieldData"
style="@style/database_button_landscape" />
<Button
android:text="@string/clean_readings_table"
android:id="@+id/wipeReadingsTable"
style="@style/database_button_landscape" />
android:text="@string/copy_to_sd_card"
android:id="@+id/exportDatabaseButton"
android:onClick="exportDatabase"
style="@style/database_button_portrait" />
<Button
android:text="@string/clean_streaming_table"
android:id="@+id/wipeStreamingTable"
android:text="@string/clean_menu_toggle"
android:id="@+id/cleanOptions"
style="@style/database_button_landscape" />
</LinearLayout>
......
......@@ -43,6 +43,7 @@
android:drawableStart="@drawable/database_actions_icon"
android:contentDescription="@string/databaseActions"
android:layout_gravity="center"
android:textSize="@dimen/database_actions_button_font_size"
android:text="@string/database_actions_text"
android:fontFamily="@font/comfortaaregular"
android:textAllCaps="false"
......
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
android:layout_height="match_parent"
android:padding="20dp"
android:orientation="vertical">
<EditText
android:id="@+id/serverIp"
style="@style/credentialBoxes"
android:layout_marginTop="31dp"
android:layout_alignEnd="@id/serverIp"
android:layout_alignParentTop="true"
android:layout_alignStart="@id/serverIp"
android:hint="@string/server_ip"
android:text="@string/default_ip"
android:inputType=""
......@@ -20,9 +18,6 @@
<EditText
android:id="@+id/database"
style="@style/credentialBoxes"
android:layout_alignEnd="@id/serverIp"
android:layout_alignStart="@id/serverIp"
android:layout_below="@+id/serverIp"
android:hint="@string/database_name"
android:text="@string/default_database_name"
android:inputType=""
......@@ -32,9 +27,6 @@
<EditText
android:id="@+id/username"
style="@style/credentialBoxes"
android:layout_alignEnd="@id/serverIp"
android:layout_alignStart="@id/serverIp"
android:layout_below="@+id/database"
android:hint="@string/username"
android:text="@string/default_username"
android:inputType=""
......@@ -47,9 +39,6 @@
android:text=""
android:inputType="textPassword"
android:hint="@string/password"
android:layout_alignStart="@id/serverIp"
android:layout_alignEnd="@id/serverIp"
android:layout_below="@+id/username"
android:autofillHints=""
tools:targetApi="o" />
......@@ -58,70 +47,56 @@
android:id="@+id/port"
android:text="@string/default_port"
android:hint="@string/port_of_db"
android:layout_alignStart="@id/serverIp"
android:layout_alignEnd="@id/serverIp"
android:layout_below="@+id/password"
android:inputType=""
android:autofillHints=""
tools:targetApi="o" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:gravity="center">
<Button
android:text="@string/connect"
android:id="@+id/setupDbButton"
android:layout_below="@+id/port"
android:layout_centerHorizontal="true"
style="@style/database_button_portrait" />
<Button
android:text="@string/upload_tables"
android:id="@+id/uploadButton"
android:layout_below="@id/setupDbButton"
android:layout_alignParentStart="true"
style="@style/database_button_portrait" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:gravity="center">
<Button
android:text="@string/copy_to_sd_card"
android:id="@+id/exportDatabaseButton"
android:layout_below="@id/setupDbButton"
android:layout_alignParentEnd="true"
android:onClick="exportDatabase"
style="@style/database_button_portrait" />
<Button
android:text="@string/wipeDB"
android:id="@+id/wipeDatabase"
android:layout_below="@id/exportDatabaseButton"
android:layout_alignParentEnd="true"
style="@style/database_button_portrait" />
<Button
android:text="@string/clean_field_data"
android:id="@+id/wipeFieldData"
android:layout_below="@id/exportDatabaseButton"
android:layout_alignParentStart="true"
style="@style/database_button_portrait" />
<Button
android:text="@string/clean_readings_table"
android:id="@+id/wipeReadingsTable"
android:layout_below="@id/wipeDatabase"
android:layout_alignParentStart="true"
style="@style/database_button_portrait" />
<Button
android:text="@string/clean_streaming_table"
android:id="@+id/wipeStreamingTable"
android:layout_below="@id/wipeDatabase"
android:layout_alignParentEnd="true"
android:text="@string/clean_menu_toggle"
android:id="@+id/cleanOptions"
style="@style/database_button_portrait" />
</LinearLayout>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/databaseStatus"
android:id="@+id/databaseStatus"
android:textAppearance="@android:style/TextAppearance.Medium"
android:textStyle="bold"
android:textColor="@color/dark_gray_blue" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/lastUpload"
android:id="@+id/lastUpload"
android:layout_alignStart="@id/uploadButton"
android:textColor="@color/dark_gray_blue"
android:textAppearance="@android:style/TextAppearance.Medium"
android:textStyle="bold"
android:layout_above="@+id/lastDownload" />
android:textStyle="bold" />
<TextView
android:layout_width="wrap_content"
......@@ -130,9 +105,7 @@
android:id="@+id/lastDownload"
android:textAppearance="@android:style/TextAppearance.Medium"
android:textColor="@color/dark_gray_blue"
android:textStyle="bold"
android:layout_above="@+id/lastClean"
android:layout_alignStart="@+id/lastUpload" />
android:textStyle="bold"/>
<TextView
android:layout_width="wrap_content"
......@@ -141,9 +114,7 @@
android:id="@+id/lastClean"
android:textAppearance="@android:style/TextAppearance.Medium"
android:textStyle="bold"
android:textColor="@color/dark_gray_blue"
android:layout_alignStart="@id/lastUpload"
android:layout_above="@+id/databaseSize" />
android:textColor="@color/dark_gray_blue" />
<TextView
android:layout_width="wrap_content"
......@@ -152,20 +123,6 @@
android:id="@+id/databaseSize"
android:textAppearance="@android:style/TextAppearance.Medium"
android:textStyle="bold"
android:textColor="@color/dark_gray_blue"
android:layout_above="@+id/databaseStatus"
android:layout_alignStart="@id/lastUpload" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/databaseStatus"
android:id="@+id/databaseStatus"
android:textAppearance="@android:style/TextAppearance.Medium"
android:textStyle="bold"
android:textColor="@color/dark_gray_blue"
android:layout_alignParentBottom="true"
android:layout_alignStart="@id/lastUpload"
android:layout_marginBottom="25dp" />
android:textColor="@color/dark_gray_blue" />
</RelativeLayout>
\ No newline at end of file
</LinearLayout>
\ No newline at end of file
......@@ -43,6 +43,7 @@
android:drawableStart="@drawable/database_actions_icon"
android:contentDescription="@string/databaseActions"
android:layout_gravity="center"
android:textSize="@dimen/database_actions_button_font_size"
android:text="@string/database_actions_text"
android:fontFamily="@font/comfortaaregular"
android:textAllCaps="false"
......
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:title="@string/clean_readings_table"
android:id="@+id/cleanReadingTable" />
<item
android:title="@string/clean_streaming_table"
android:id="@+id/cleanStreamingTable" />
<item
android:title="@string/clean_field_data"
android:id="@+id/cleanReadAndStreamTables" />
<item
android:title="@string/wipeDB"
android:id="@+id/eraseDatabase" />
</menu>
\ No newline at end of file
<resources>
<!-- Default screen margins, per the Android Design guidelines. -->
<dimen name="sample_button_font_size">30sp</dimen>
<dimen name="database_actions_button_font_size">20sp</dimen>
</resources>
......@@ -104,7 +104,7 @@
<string name="create_folder">Create Folder</string>
<string name="create_file">Create File</string>
<string name="upload_tables">Upload tables</string>
<string name="clean_field_data">Clean field data</string>
<string name="clean_field_data">Clean both reading and streaming tables</string>
<string name="clean_readings_table">Clean readings table</string>
<string name="clean_streaming_table">Clean streaming table</string>
<string name="copy_to_sd_card">Copy to SD card</string>
......
......@@ -2,7 +2,7 @@
<!-- Base application theme. -->
<style name="credentialBoxes">
<item name="android:layout_width">wrap_content</item>
<item name="android:layout_width">match_parent</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:layout_centerHorizontal">true</item>
<item name="android:singleLine">true</item>
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment