Skip to content

Commit

Permalink
Database size on status page
Browse files Browse the repository at this point in the history
  • Loading branch information
Navid200 committed Nov 6, 2024
1 parent fe9ec2e commit 98afcd5
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
import com.eveningoutpost.dexdrip.models.UserError.Log;
import com.eveningoutpost.dexdrip.services.DexCollectionService;
import com.eveningoutpost.dexdrip.services.G5CollectionService;
import com.eveningoutpost.dexdrip.ui.activities.DatabaseAdmin;
import com.eveningoutpost.dexdrip.utilitymodels.CollectionServiceStarter;
import com.eveningoutpost.dexdrip.utilitymodels.SensorStatus;
import com.eveningoutpost.dexdrip.databinding.ActivitySystemStatusBinding;
Expand Down Expand Up @@ -80,6 +81,7 @@ public class SystemStatusFragment extends Fragment {
private ActiveBluetoothDevice activeBluetoothDevice;
private static final String TAG = "SystemStatus";
private BroadcastReceiver serviceDataReceiver;
private TextView db_size_view;

//@Inject
MicroStatus microStatus;
Expand Down Expand Up @@ -177,6 +179,7 @@ public void onActivityCreated(Bundle savedInstanceState) {
sensor_status_view = (TextView) v.findViewById(R.id.sensor_status);
transmitter_status_view = (TextView) v.findViewById(R.id.transmitter_status);
current_device = (TextView) v.findViewById(R.id.remembered_device);
db_size_view = (TextView) v.findViewById(R.id.db_size);

notes = (TextView) v.findViewById(R.id.other_notes);

Expand Down Expand Up @@ -238,6 +241,7 @@ private void set_current_values() {
setTransmitterStatus();
setNotes();
futureDataCheck();
setDbSize();

/* if (notes.getText().length()==0) {
notes.setText("Swipe for more status pages!");
Expand Down Expand Up @@ -274,6 +278,11 @@ private void setTransmitterStatus() {

}

private void setDbSize() {
DatabaseAdmin dataBaseAdmin = new DatabaseAdmin();
Float dbSize = dataBaseAdmin.getDbSizeFloat();
db_size_view.setText(dbSize + "M");
}

private void setSensorStatus() {
sensor_status_view.setText(SensorStatus.status());
Expand All @@ -285,7 +294,7 @@ private void setVersionName() {
try {
versionName = safeGetContext().getPackageManager().getPackageInfo(safeGetContext().getPackageName(), PackageManager.GET_META_DATA).versionName;
int versionNumber = safeGetContext().getPackageManager().getPackageInfo(safeGetContext().getPackageName(), PackageManager.GET_META_DATA).versionCode;
versionName += "\nCode: " + BuildConfig.buildVersion + "\nDowngradable to: " + versionNumber;
versionName += "\nCode: " + BuildConfig.buildVersion;
version_name_view.setText(versionName);
} catch (PackageManager.NameNotFoundException e) {
//e.printStackTrace();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ public class DatabaseAdmin extends BaseAppCompatActivity {
private final DbAdminProcessor databaseSize = new DatabaseSize();
// view model
public final ObservableField<String> console = new ObservableField<>();
public static float dbSizeResult; // Database size

@Override
protected void onCreate(Bundle savedInstanceState) {
Expand All @@ -57,6 +58,11 @@ public void getDbSize() {
dbTask(databaseSize, "pragma database_list");
}

public float getDbSizeFloat() {
getDbSize();
return dbSizeResult;
}

public void quickCheck() {
dbTask(consoleProcessor, "pragma quick_check");
}
Expand Down Expand Up @@ -157,6 +163,7 @@ class DatabaseSize implements DbAdminProcessor {

@Override
public void process(List<String> results) {
dbSizeResult = 0;
if (results.size() == 0) {
console.set("Cannot locate database!!");
} else {
Expand All @@ -170,7 +177,8 @@ public void process(List<String> results) {
}
final File dbFile = new File(filename);
if (dbFile.exists()) {
consoleAppend("Database " + insert + " size: " + JoH.roundFloat(((float) dbFile.length()) / (1024 * 1024), 2) + "M " + (dbFile.canWrite() ? "" : " CANNOT WRITE") + (dbFile.canRead() ? "" : " CANNOT READ") + "\n");
dbSizeResult = JoH.roundFloat(((float) dbFile.length()) / (1024 * 1024), 2);
consoleAppend("Database " + insert + " size: " + dbSizeResult + "M " + (dbFile.canWrite() ? "" : " CANNOT WRITE") + (dbFile.canRead() ? "" : " CANNOT READ") + "\n");
} else {
console.set("Cannot find database file! " + filename);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import com.eveningoutpost.dexdrip.models.UserNotification;
import com.eveningoutpost.dexdrip.R;
import com.eveningoutpost.dexdrip.SnoozeActivity;
import com.eveningoutpost.dexdrip.ui.activities.DatabaseAdmin;

import java.util.ArrayList;
import java.util.Iterator;
Expand Down Expand Up @@ -60,6 +61,7 @@ public void performAll() {
IncompatibleApps.notifyAboutIncompatibleApps();
CompatibleApps.notifyAboutCompatibleApps();
legacySettingsMoveLanguageFromNoToNb();
initiateGetDbSizeFloat();

}

Expand Down Expand Up @@ -160,4 +162,9 @@ private static void legacySettingsMoveLanguageFromNoToNb() {
Pref.setString("forced_language", "nb");
}
}

private static void initiateGetDbSizeFloat() { // Get database size once so that it will return a non-zero value next
DatabaseAdmin databaseAdmin = new DatabaseAdmin();
databaseAdmin.getDbSizeFloat();
}
}
21 changes: 21 additions & 0 deletions app/src/main/res/layout/activity_system_status.xml
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,27 @@
android:textAppearance="?android:attr/textAppearanceMedium" />
</LinearLayout>

<LinearLayout
android:id="@+id/layout_dbsize"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:paddingTop="10dp">

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/database_size"
android:textAppearance="@style/TextAppearance.AppCompat.Title" />

<TextView
android:id="@+id/db_size"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="5dp"
android:textAppearance="?android:attr/textAppearanceMedium" />
</LinearLayout>

<LinearLayout
android:id="@+id/layout_device"
app:showIfTrue="@{ms.bluetooth()}"
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1548,6 +1548,7 @@
<string name="progress">progress</string>
<string name="bluetooth_device">Bluetooth Device: </string>
<string name="transmitter_battery_status">Transmitter Battery: </string>
<string name="database_size">Database size: </string>
<string name="top">Top</string>
<string name="connect_device_usb_otg">Please connect your device via USB OTG cable.</string>
<string name="connection_status">Connection Status:</string>
Expand Down

0 comments on commit 98afcd5

Please sign in to comment.