Refactore logshipper to maintenance, move funcs from menu to plugin

This commit is contained in:
Markus M. May 2018-07-28 22:45:40 +02:00
parent c34104b906
commit f70909d6c6
10 changed files with 161 additions and 117 deletions

View file

@ -374,29 +374,6 @@ public class MainActivity extends AppCompatActivity {
case R.id.nav_setupwizard:
startActivity(new Intent(this, SetupWizardActivity.class));
return true;
case R.id.nav_resetdb:
new AlertDialog.Builder(this)
.setTitle(R.string.nav_resetdb)
.setMessage(R.string.reset_db_confirm)
.setNegativeButton(android.R.string.cancel, null)
.setPositiveButton(android.R.string.ok, (dialog, which) -> {
MainApp.getDbHelper().resetDatabases();
// should be handled by Plugin-Interface and
// additional service interface and plugin registry
FoodPlugin.getPlugin().getService().resetFood();
TreatmentsPlugin.getPlugin().getService().resetTreatments();
})
.create()
.show();
return true;
case R.id.nav_export:
ImportExportPrefs.verifyStoragePermissions(this);
ImportExportPrefs.exportSharedPreferences(this);
return true;
case R.id.nav_import:
ImportExportPrefs.verifyStoragePermissions(this);
ImportExportPrefs.importSharedPreferences(this);
return true;
case R.id.nav_show_logcat:
LogDialog.showLogcat(this);
return true;

View file

@ -10,7 +10,6 @@ import android.support.v4.content.LocalBroadcastManager;
import com.crashlytics.android.Crashlytics;
import com.crashlytics.android.answers.Answers;
import com.crashlytics.android.answers.CustomEvent;
import com.j256.ormlite.android.apptools.OpenHelperManager;
import com.squareup.otto.Bus;
import com.squareup.otto.LoggingBus;
@ -24,7 +23,6 @@ import org.slf4j.LoggerFactory;
import java.io.File;
import java.util.ArrayList;
import ch.qos.logback.classic.LoggerContext;
import info.nightscout.androidaps.Services.Intents;
import info.nightscout.androidaps.data.ConstraintChecker;
import info.nightscout.androidaps.db.DatabaseHelper;
@ -41,7 +39,7 @@ import info.nightscout.androidaps.plugins.Insulin.InsulinOrefFreePeakPlugin;
import info.nightscout.androidaps.plugins.Insulin.InsulinOrefRapidActingPlugin;
import info.nightscout.androidaps.plugins.Insulin.InsulinOrefUltraRapidActingPlugin;
import info.nightscout.androidaps.plugins.IobCobCalculator.IobCobCalculatorPlugin;
import info.nightscout.androidaps.plugins.LogShipper.LogShipperPlugin;
import info.nightscout.androidaps.plugins.Maintenance.MaintenancePlugin;
import info.nightscout.androidaps.plugins.Loop.LoopPlugin;
import info.nightscout.androidaps.plugins.NSClientInternal.NSClientPlugin;
import info.nightscout.androidaps.plugins.NSClientInternal.receivers.AckAlarmReceiver;
@ -191,7 +189,7 @@ public class MainApp extends Application {
pluginsList.add(StatuslinePlugin.initPlugin(this));
pluginsList.add(PersistentNotificationPlugin.getPlugin());
pluginsList.add(NSClientPlugin.getPlugin());
pluginsList.add(LogShipperPlugin.initPlugin(this));
pluginsList.add(MaintenancePlugin.initPlugin(this));
pluginsList.add(sConfigBuilder = ConfigBuilderPlugin.getPlugin());

View file

@ -1,34 +1,45 @@
package info.nightscout.androidaps.plugins.LogShipper;
package info.nightscout.androidaps.plugins.Maintenance;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v7.app.AlertDialog;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R;
import info.nightscout.androidaps.plugins.Food.FoodPlugin;
import info.nightscout.androidaps.plugins.Treatments.TreatmentsPlugin;
/**
*
*/
public class LogShipperFragment extends Fragment {
public class MaintenanceFragment extends Fragment {
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.logshipper_fragment, container, false);
View view = inflater.inflate(R.layout.maintenance_fragment, container, false);
view.findViewById(R.id.log_send).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
LogShipperPlugin.getPlugin().sendLogs();
MaintenancePlugin.getPlugin().sendLogs();
}
});
view.findViewById(R.id.log_delete).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
LogShipperPlugin.getPlugin().deleteLogs();
MaintenancePlugin.getPlugin().deleteLogs();
}
});
view.findViewById(R.id.nav_resetdb).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
}
});

View file

@ -1,9 +1,10 @@
package info.nightscout.androidaps.plugins.LogShipper;
package info.nightscout.androidaps.plugins.Maintenance;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.support.v4.content.FileProvider;
import android.support.v7.app.AlertDialog;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -22,50 +23,54 @@ import java.util.List;
import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R;
import info.nightscout.androidaps.interfaces.PluginBase;
import info.nightscout.androidaps.interfaces.PluginDescription;
import info.nightscout.androidaps.interfaces.PluginType;
import info.nightscout.androidaps.plugins.Food.FoodPlugin;
import info.nightscout.androidaps.plugins.Treatments.TreatmentsPlugin;
import info.nightscout.utils.ImportExportPrefs;
import info.nightscout.utils.LoggerUtils;
import info.nightscout.utils.SP;
public class LogShipperPlugin extends PluginBase {
public class MaintenancePlugin extends PluginBase {
private static final Logger LOG = LoggerFactory.getLogger(LogShipperPlugin.class);
private static final Logger LOG = LoggerFactory.getLogger(MaintenancePlugin.class);
private final Context ctx;
private static LogShipperPlugin logShipperPlugin;
private static MaintenancePlugin maintenancePlugin;
public static LogShipperPlugin getPlugin() {
return logShipperPlugin;
public static MaintenancePlugin getPlugin() {
return maintenancePlugin;
}
public static LogShipperPlugin initPlugin(Context ctx) {
public static MaintenancePlugin initPlugin(Context ctx) {
if (logShipperPlugin == null) {
logShipperPlugin = new LogShipperPlugin(ctx);
if (maintenancePlugin == null) {
maintenancePlugin = new MaintenancePlugin(ctx);
}
return logShipperPlugin;
return maintenancePlugin;
}
public LogShipperPlugin() {
public MaintenancePlugin() {
// required for testing
super(null);
this.ctx = null;
}
LogShipperPlugin(Context ctx) {
MaintenancePlugin(Context ctx) {
super(new PluginDescription()
.mainType(PluginType.GENERAL)
.fragmentClass(LogShipperFragment.class.getName())
.fragmentClass(MaintenanceFragment.class.getName())
.alwayVisible(true)
.alwaysEnabled(true)
.pluginName(R.string.logshipper)
.shortName(R.string.logship_shortname)
.preferencesId(R.xml.pref_logshipper)
.description(R.string.description_logship)
.pluginName(R.string.maintenance)
.shortName(R.string.maintenance_shortname)
.preferencesId(R.xml.pref_maintenance)
.description(R.string.description_maintenance)
);
this.ctx = ctx;
}
@ -81,8 +86,8 @@ public class LogShipperPlugin extends PluginBase {
}
public void sendLogs() {
String recipient = SP.getString("key_logshipper_email", "logs@androidaps.org");
int amount = SP.getInt("key_logshipper_amount", 2);
String recipient = SP.getString("key_maintenance_logs_email", "logs@androidaps.org");
int amount = SP.getInt("key_maintenance_logs_amount", 2);
String logDirectory = LoggerUtils.getLogDirectory();
List<File> logs = this.getLogfiles(logDirectory, amount);
@ -141,6 +146,32 @@ public class LogShipperPlugin extends PluginBase {
}
}
public void resetDb() {
// new AlertDialog.Builder(this)
// .setTitle(R.string.nav_resetdb)
// .setMessage(R.string.reset_db_confirm)
// .setNegativeButton(android.R.string.cancel, null)
// .setPositiveButton(android.R.string.ok, (dialog, which) -> {
// MainApp.getDbHelper().resetDatabases();
// // should be handled by Plugin-Interface and
// // additional service interface and plugin registry
// FoodPlugin.getPlugin().getService().resetFood();
// TreatmentsPlugin.getPlugin().getService().resetTreatments();
// })
// .create()
// .show();
}
public void exportSettings() {
// ImportExportPrefs.verifyStoragePermissions(this);
// ImportExportPrefs.exportSharedPreferences(this);
}
public void importSettings() {
// ImportExportPrefs.verifyStoragePermissions(this);
// ImportExportPrefs.importSharedPreferences(this);
}
/**
* returns a list of log files. The number of returned logs is given via the amount
* parameter. The log files are sorted by the name descending.

View file

@ -1,41 +0,0 @@
<FrameLayout 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:paddingTop="2dp"
tools:context="info.nightscout.androidaps.plugins.LogShipper.LogShipperFragment">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<Button
android:id="@+id/log_send"
style="?android:attr/buttonStyle"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="3dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="3dp"
android:layout_weight="0.5"
android:text="@string/send_all_logs"
android:textColor="@color/colorTreatmentButton" />
<Button
android:id="@+id/log_delete"
style="?android:attr/buttonStyle"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="3dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="3dp"
android:layout_weight="0.5"
android:text="@string/delete_logs"
android:textColor="@color/colorTreatmentButton" />
</LinearLayout>
</FrameLayout>

View file

@ -0,0 +1,80 @@
<FrameLayout 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:paddingTop="2dp"
tools:context="info.nightscout.androidaps.plugins.Maintenance.MaintenanceFragment">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<Button
android:id="@+id/log_send"
style="?android:attr/buttonStyle"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="3dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="3dp"
android:layout_weight="0.5"
android:text="@string/send_all_logs"
android:textColor="@color/colorTreatmentButton" />
<Button
android:id="@+id/log_delete"
style="?android:attr/buttonStyle"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="3dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="3dp"
android:layout_weight="0.5"
android:text="@string/delete_logs"
android:textColor="@color/colorTreatmentButton" />
<Button
android:id="@+id/nav_export"
style="?android:attr/buttonStyle"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="3dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="3dp"
android:layout_weight="0.5"
android:text="@string/nav_export"
android:textColor="@color/colorTreatmentButton" />
<Button
android:id="@+id/nav_import"
style="?android:attr/buttonStyle"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="3dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="3dp"
android:layout_weight="0.5"
android:text="@string/nav_import"
android:textColor="@color/colorTreatmentButton" />
<Button
android:id="@+id/nav_resetdb"
style="?android:attr/buttonStyle"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="3dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="3dp"
android:layout_weight="0.5"
android:text="@string/nav_resetdb"
android:textColor="@color/colorTreatmentButton" />
</LinearLayout>
</FrameLayout>

View file

@ -18,18 +18,6 @@
android:id="@+id/nav_setupwizard"
app:showAsAction="never"
android:title="@string/nav_setupwizard" />
<item
android:id="@+id/nav_resetdb"
app:showAsAction="never"
android:title="@string/nav_resetdb" />
<item
android:id="@+id/nav_export"
app:showAsAction="never"
android:title="@string/nav_export" />
<item
android:id="@+id/nav_import"
app:showAsAction="never"
android:title="@string/nav_import" />
<item
android:id="@+id/nav_show_logcat"
app:showAsAction="never"

View file

@ -1165,15 +1165,15 @@
<string name="storedsettingsfound">Stored settings found</string>
<string name="allow_hardware_pump_text">Attention: If you activate and connect to a hardware pump, AndroidAPS will copy the basal settings from the profile to the pump, overwriting the existing basal rate stored on the pump. Make sure you have the correct basal setting in AndroidAPS. If you are not sure or don\'t want to overwrite the basal settings on your pump, press cancel and repeat switching to the pump at a later time.</string>
<string name="error_adding_treatment_title">Treatment data incomplete</string>
<string name="logshipper_settings">Log Shipment Settings</string>
<string name="maintenance_settings">Maintenance Settings</string>
<string name="logshipper_email">Email</string>
<string name="key_logshipper_email" translatable="false">email</string>
<string name="key_maintenance_logs_email" translatable="false">email</string>
<string name="invalid_email_message">Invalid Email</string>
<string name="key_logshipper_amount" translatable="false">amount of logs to send</string>
<string name="key_maintenance_logs_amount" translatable="false">amount of logs to send</string>
<string name="logshipper_amount">No of Logs to send</string>
<string name="logshipper">Log Shipment</string>
<string name="logship_shortname">LOG</string>
<string name="description_logship">Send Logs via Email for support requests. Delete logs if wanted.</string>
<string name="maintenance">Wartung</string>
<string name="maintenance_shortname">MAINT</string>
<string name="description_maintenance">Provides several functions for maintenance (eg. log sending, log deletion).</string>
<string name="send_all_logs">Send Logs by Email</string>
<string name="delete_logs">Delete Logs</string>

View file

@ -3,14 +3,14 @@
xmlns:validatingEditText="http://schemas.android.com/apk/res/info.nightscout.androidaps">
<PreferenceCategory
android:key="logshipper"
android:title="@string/logshipper_settings">
android:key="maintenance"
android:title="@string/maintenance_settings">
<com.andreabaccega.widget.ValidatingEditTextPreference
android:defaultValue="logs@androidaps.org"
android:dialogMessage="@string/logshipper_email"
android:inputType="textEmailAddress"
android:key="@string/key_logshipper_email"
android:key="@string/key_maintenance_logs_email"
android:selectAllOnFocus="true"
android:title="@string/nsclientinternal_url_title"
validatingEditText:emptyAllowed="false"
@ -20,7 +20,7 @@
<EditTextPreference
android:defaultValue="2"
android:inputType="number"
android:key="@string/key_logshipper_amount"
android:key="@string/key_maintenance_logs_amount"
android:title="@string/logshipper_amount">
</EditTextPreference>

View file

@ -1,4 +1,4 @@
package info.nightscout.androidaps.plugins.LogShipper;
package info.nightscout.androidaps.plugins.Maintenance;
import org.junit.Test;
@ -8,9 +8,9 @@ import java.util.List;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
public class LogShipperPluginTest {
public class MaintenancePluginTest {
private LogShipperPlugin sut = new LogShipperPlugin();
private MaintenancePlugin sut = new MaintenancePlugin();
@Test
public void getLogfilesTest() {