From 194fd7f0a670fb1d5555b6750c600c33b81d3808 Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Thu, 4 May 2017 15:25:41 +0200 Subject: [PATCH 1/3] check for null --- app/src/main/java/info/nightscout/androidaps/db/TempBasal.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/app/src/main/java/info/nightscout/androidaps/db/TempBasal.java b/app/src/main/java/info/nightscout/androidaps/db/TempBasal.java index deccb18049..5ef0767c59 100644 --- a/app/src/main/java/info/nightscout/androidaps/db/TempBasal.java +++ b/app/src/main/java/info/nightscout/androidaps/db/TempBasal.java @@ -78,6 +78,9 @@ public class TempBasal { Long date = (long) (timeStart.getTime() + j * tempBolusSpacing * 60 * 1000 + 0.5d * tempBolusSpacing * 60 * 1000); Double basalRate = profile.getBasal(NSProfile.secondsFromMidnight(date)); + + if (basalRate == null) + continue; if (isExtended) { netBasalRate = this.absolute; } else { From a83ff12ca81cc0b44beab0084a4d524d570ad788 Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Thu, 4 May 2017 16:30:01 +0200 Subject: [PATCH 2/3] remove unneeded code --- .../java/info/nightscout/androidaps/tabs/TabPageAdapter.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/tabs/TabPageAdapter.java b/app/src/main/java/info/nightscout/androidaps/tabs/TabPageAdapter.java index 4f7b4a7a30..0ec2921a14 100644 --- a/app/src/main/java/info/nightscout/androidaps/tabs/TabPageAdapter.java +++ b/app/src/main/java/info/nightscout/androidaps/tabs/TabPageAdapter.java @@ -18,7 +18,6 @@ import info.nightscout.androidaps.interfaces.PluginBase; */ public class TabPageAdapter extends FragmentStatePagerAdapter { - ArrayList fragmentList = new ArrayList<>(); ArrayList visibleFragmentList = new ArrayList<>(); FragmentManager fm; @@ -62,7 +61,6 @@ public class TabPageAdapter extends FragmentStatePagerAdapter { } public void registerNewFragment(PluginBase plugin) { - fragmentList.add(plugin); if (plugin.isVisibleInTabs(plugin.getType())) { visibleFragmentList.add(plugin); notifyDataSetChanged(); From 070867af283986141059ff93361a3bc6e076a12a Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Thu, 4 May 2017 19:13:56 +0200 Subject: [PATCH 3/3] menu on top --- .../nightscout/androidaps/MainActivity.java | 96 ++++++++++++++++++- .../plugins/Overview/OverviewFragment.java | 74 -------------- app/src/main/res/layout/activity_main.xml | 45 ++++++--- app/src/main/res/layout/overview_fragment.xml | 42 +++----- 4 files changed, 139 insertions(+), 118 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/MainActivity.java b/app/src/main/java/info/nightscout/androidaps/MainActivity.java index fc58a81a0b..9ae5081dbc 100644 --- a/app/src/main/java/info/nightscout/androidaps/MainActivity.java +++ b/app/src/main/java/info/nightscout/androidaps/MainActivity.java @@ -1,8 +1,10 @@ package info.nightscout.androidaps; import android.Manifest; +import android.app.Activity; import android.content.ActivityNotFoundException; import android.content.Context; +import android.content.DialogInterface; import android.content.Intent; import android.content.pm.PackageManager; import android.graphics.Rect; @@ -16,10 +18,15 @@ import android.support.v4.content.ContextCompat; import android.support.v4.view.ViewPager; import android.support.v7.app.AlertDialog; import android.support.v7.app.AppCompatActivity; +import android.support.v7.widget.PopupMenu; +import android.util.AttributeSet; +import android.view.MenuInflater; +import android.view.MenuItem; import android.view.MotionEvent; import android.view.View; import android.view.inputmethod.InputMethodManager; import android.widget.EditText; +import android.widget.ImageButton; import com.joanzapata.iconify.Iconify; import com.joanzapata.iconify.fonts.FontAwesomeModule; @@ -28,17 +35,21 @@ import com.squareup.otto.Subscribe; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import info.nightscout.androidaps.events.EventAppExit; import info.nightscout.androidaps.events.EventPreferenceChange; import info.nightscout.androidaps.events.EventRefreshGui; import info.nightscout.androidaps.interfaces.PluginBase; import info.nightscout.androidaps.tabs.SlidingTabLayout; import info.nightscout.androidaps.tabs.TabPageAdapter; +import info.nightscout.utils.ImportExportPrefs; import info.nightscout.utils.LocaleHelper; +import info.nightscout.utils.LogDialog; import info.nightscout.utils.OKDialog; +import info.nightscout.utils.PasswordProtection; import info.nightscout.utils.SP; import info.nightscout.utils.ToastUtils; -public class MainActivity extends AppCompatActivity { +public class MainActivity extends AppCompatActivity implements View.OnClickListener { private static Logger log = LoggerFactory.getLogger(MainActivity.class); static final int CASE_STORAGE = 0x1; @@ -46,12 +57,18 @@ public class MainActivity extends AppCompatActivity { private boolean askForSMS = false; + ImageButton menuButton; + + @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Iconify.with(new FontAwesomeModule()); LocaleHelper.onCreate(this, "en"); setContentView(R.layout.activity_main); + menuButton = (ImageButton) findViewById(R.id.overview_menuButton); + menuButton.setOnClickListener(this); + checkEula(); if (Build.VERSION.SDK_INT > Build.VERSION_CODES.LOLLIPOP_MR1) { askForPermission(new String[]{Manifest.permission.READ_EXTERNAL_STORAGE, @@ -228,4 +245,81 @@ public class MainActivity extends AppCompatActivity { } return super.dispatchTouchEvent(event); } + + @Override + public void onClick(final View v) { + final Activity activity = this; + switch (v.getId()) { + case R.id.overview_menuButton: + PopupMenu popup = new PopupMenu(v.getContext(), v); + MenuInflater inflater = popup.getMenuInflater(); + inflater.inflate(R.menu.menu_main, popup.getMenu()); + popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() { + @Override + public boolean onMenuItemClick(MenuItem item) { + int id = item.getItemId(); + switch (id) { + case R.id.nav_preferences: + PasswordProtection.QueryPassword(v.getContext(), R.string.settings_password, "settings_password", new Runnable() { + @Override + public void run() { + Intent i = new Intent(v.getContext(), PreferencesActivity.class); + startActivity(i); + } + }, null); + break; + case R.id.nav_resetdb: + new AlertDialog.Builder(v.getContext()) + .setTitle(R.string.nav_resetdb) + .setMessage(R.string.reset_db_confirm) + .setNegativeButton(android.R.string.cancel, null) + .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { + MainApp.getDbHelper().resetDatabases(); + } + }) + .create() + .show(); + break; + case R.id.nav_export: + ImportExportPrefs.verifyStoragePermissions(activity); + ImportExportPrefs.exportSharedPreferences(activity); + break; + case R.id.nav_import: + ImportExportPrefs.verifyStoragePermissions(activity); + ImportExportPrefs.importSharedPreferences(activity); + break; + case R.id.nav_show_logcat: + LogDialog.showLogcat(v.getContext()); + break; + case R.id.nav_about: + AlertDialog.Builder builder = new AlertDialog.Builder(v.getContext()); + builder.setTitle(getString(R.string.app_name) + " " + BuildConfig.VERSION); + if (BuildConfig.NSCLIENTOLNY) + builder.setIcon(R.mipmap.yellowowl); + else + builder.setIcon(R.mipmap.blueowl); + builder.setMessage("Build: " + BuildConfig.BUILDVERSION); + builder.setPositiveButton(MainApp.sResources.getString(R.string.ok), null); + AlertDialog alertDialog = builder.create(); + alertDialog.show(); + break; + case R.id.nav_exit: + log.debug("Exiting"); + MainApp.instance().stopKeepAliveService(); + MainApp.bus().post(new EventAppExit()); + MainApp.closeDbHelper(); + finish(); + System.runFinalization(); + System.exit(0); + break; + } + return false; + } + }); + popup.show(); + break; + } + } } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/OverviewFragment.java b/app/src/main/java/info/nightscout/androidaps/plugins/Overview/OverviewFragment.java index 747c9c067c..dd3e1d33e7 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/OverviewFragment.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Overview/OverviewFragment.java @@ -148,7 +148,6 @@ public class OverviewFragment extends Fragment implements View.OnClickListener, GraphView bgGraph; GraphView iobGraph; RelativeLayout iobGraphLayout; - ImageButton menuButton; CheckBox showPredictionView; CheckBox showBasalsView; @@ -225,9 +224,6 @@ public class OverviewFragment extends Fragment implements View.OnClickListener, iobGraph = (GraphView) view.findViewById(R.id.overview_iobgraph); iobGraphLayout = (RelativeLayout) view.findViewById(R.id.overview_iobgraphlayout); - menuButton = (ImageButton) view.findViewById(R.id.overview_menuButton); - menuButton.setOnClickListener(this); - cancelTempButton = (Button) view.findViewById(R.id.overview_canceltempbutton); cancelTempButton.setOnClickListener(this); treatmentButton = (Button) view.findViewById(R.id.overview_treatmentbutton); @@ -470,76 +466,6 @@ public class OverviewFragment extends Fragment implements View.OnClickListener, } }); break; - case R.id.overview_menuButton: - PopupMenu popup = new PopupMenu(getContext(), v); - MenuInflater inflater = popup.getMenuInflater(); - inflater.inflate(R.menu.menu_main, popup.getMenu()); - popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() { - @Override - public boolean onMenuItemClick(MenuItem item) { - int id = item.getItemId(); - switch (id) { - case R.id.nav_preferences: - PasswordProtection.QueryPassword(getContext(), R.string.settings_password, "settings_password", new Runnable() { - @Override - public void run() { - Intent i = new Intent(getContext(), PreferencesActivity.class); - startActivity(i); - } - }, null); - break; - case R.id.nav_resetdb: - new AlertDialog.Builder(getContext()) - .setTitle(R.string.nav_resetdb) - .setMessage(R.string.reset_db_confirm) - .setNegativeButton(android.R.string.cancel, null) - .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialog, int which) { - MainApp.getDbHelper().resetDatabases(); - } - }) - .create() - .show(); - break; - case R.id.nav_export: - ImportExportPrefs.verifyStoragePermissions(getActivity()); - ImportExportPrefs.exportSharedPreferences(getActivity()); - break; - case R.id.nav_import: - ImportExportPrefs.verifyStoragePermissions(getActivity()); - ImportExportPrefs.importSharedPreferences(getActivity()); - break; - case R.id.nav_show_logcat: - LogDialog.showLogcat(getContext()); - break; - case R.id.nav_about: - AlertDialog.Builder builder = new AlertDialog.Builder(getContext()); - builder.setTitle(getString(R.string.app_name) + " " + BuildConfig.VERSION); - if (BuildConfig.NSCLIENTOLNY) - builder.setIcon(R.mipmap.yellowowl); - else - builder.setIcon(R.mipmap.blueowl); - builder.setMessage("Build: " + BuildConfig.BUILDVERSION); - builder.setPositiveButton(MainApp.sResources.getString(R.string.ok), null); - AlertDialog alertDialog = builder.create(); - alertDialog.show(); - break; - case R.id.nav_exit: - log.debug("Exiting"); - MainApp.instance().stopKeepAliveService(); - MainApp.bus().post(new EventAppExit()); - MainApp.closeDbHelper(); - getActivity().finish(); - System.runFinalization(); - System.exit(0); - break; - } - return false; - } - }); - popup.show(); - break; } } diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index 91681d5ef2..75b54a74cb 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -6,24 +6,41 @@ android:layout_width="match_parent" android:layout_height="match_parent"> - + android:layout_height="match_parent"> - - + + + + + + + + + + android:layout_alignParentEnd="true" + android:layout_alignParentTop="true" + android:background="@color/tabBgColor" + android:paddingTop="5dp" + app:srcCompat="@drawable/ic_more_vert_black_24dp" /> - - - + \ No newline at end of file diff --git a/app/src/main/res/layout/overview_fragment.xml b/app/src/main/res/layout/overview_fragment.xml index 3200fe5014..2297d2590f 100644 --- a/app/src/main/res/layout/overview_fragment.xml +++ b/app/src/main/res/layout/overview_fragment.xml @@ -122,39 +122,23 @@ android:layout_width="match_parent" android:layout_height="match_parent" android:layout_weight="0.5" - android:orientation="horizontal"> + android:orientation="vertical"> - - - - - - - - - + android:textAppearance="?android:attr/textAppearanceMedium" /> + +