diff --git a/app/src/main/java/info/nightscout/androidaps/MainActivity.java b/app/src/main/java/info/nightscout/androidaps/MainActivity.java
index 40dd2f64ab..d37995dea5 100644
--- a/app/src/main/java/info/nightscout/androidaps/MainActivity.java
+++ b/app/src/main/java/info/nightscout/androidaps/MainActivity.java
@@ -65,6 +65,8 @@ public class MainActivity extends AppCompatActivity {
private ActionBarDrawerToggle actionBarDrawerToggle;
+ private MenuItem pluginPreferencesMenuItem;
+
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
@@ -93,6 +95,29 @@ public class MainActivity extends AppCompatActivity {
registerBus();
setupTabs();
setupViews(false);
+
+ final ViewPager viewPager = findViewById(R.id.pager);
+ viewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
+ @Override
+ public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
+ }
+
+ @Override
+ public void onPageSelected(int position) {
+ checkPluginPreferences(viewPager);
+ }
+
+ @Override
+ public void onPageScrollStateChanged(int state) {
+ }
+ });
+ }
+
+ private void checkPluginPreferences(ViewPager viewPager) {
+ if (pluginPreferencesMenuItem == null) return;
+ if (((TabPageAdapter) viewPager.getAdapter()).getPluginAt(viewPager.getCurrentItem()).getPreferencesId() != -1)
+ pluginPreferencesMenuItem.setEnabled(true);
+ else pluginPreferencesMenuItem.setEnabled(false);
}
@Override
@@ -191,6 +216,7 @@ public class MainActivity extends AppCompatActivity {
mPager.setAdapter(pageAdapter);
if (switchToLast)
mPager.setCurrentItem(pageAdapter.getCount() - 1, false);
+ checkPluginPreferences(mPager);
}
private void setupTabs() {
@@ -312,6 +338,8 @@ public class MainActivity extends AppCompatActivity {
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.menu_main, menu);
+ pluginPreferencesMenuItem = menu.findItem(R.id.nav_plugin_preferences);
+ checkPluginPreferences(findViewById(R.id.pager));
return true;
}
@@ -388,6 +416,15 @@ public class MainActivity extends AppCompatActivity {
System.runFinalization();
System.exit(0);
return true;
+ case R.id.nav_plugin_preferences:
+ ViewPager viewPager = findViewById(R.id.pager);
+ final PluginBase plugin = ((TabPageAdapter) viewPager.getAdapter()).getPluginAt(viewPager.getCurrentItem());
+ PasswordProtection.QueryPassword(this, R.string.settings_password, "settings_password", () -> {
+ Intent i = new Intent(this, PreferencesActivity.class);
+ i.putExtra("id", plugin.getPreferencesId());
+ startActivity(i);
+ }, null);
+ return true;
}
return actionBarDrawerToggle.onOptionsItemSelected(item);
}
diff --git a/app/src/main/java/info/nightscout/androidaps/SingleFragmentActivity.java b/app/src/main/java/info/nightscout/androidaps/SingleFragmentActivity.java
index ef72c577d3..567799fe5e 100644
--- a/app/src/main/java/info/nightscout/androidaps/SingleFragmentActivity.java
+++ b/app/src/main/java/info/nightscout/androidaps/SingleFragmentActivity.java
@@ -1,21 +1,28 @@
package info.nightscout.androidaps;
+import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
+import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;
+import android.view.Menu;
import android.view.MenuItem;
import info.nightscout.androidaps.interfaces.PluginBase;
+import info.nightscout.androidaps.tabs.TabPageAdapter;
+import info.nightscout.utils.PasswordProtection;
public class SingleFragmentActivity extends AppCompatActivity {
+ private PluginBase plugin;
+
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_single_fragment);
- PluginBase plugin = MainApp.getPluginsList().get(getIntent().getIntExtra("plugin", -1));
+ this.plugin = MainApp.getPluginsList().get(getIntent().getIntExtra("plugin", -1));
setTitle(plugin.getName());
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setDisplayShowHomeEnabled(true);
@@ -28,7 +35,25 @@ public class SingleFragmentActivity extends AppCompatActivity {
@Override
public boolean onOptionsItemSelected(MenuItem item) {
- if (item.getItemId() == android.R.id.home) finish();
+ if (item.getItemId() == android.R.id.home) {
+ finish();
+ return true;
+ }
+ else if (item.getItemId() == R.id.nav_plugin_preferences) {
+ PasswordProtection.QueryPassword(this, R.string.settings_password, "settings_password", () -> {
+ Intent i = new Intent(this, PreferencesActivity.class);
+ i.putExtra("id", plugin.getPreferencesId());
+ startActivity(i);
+ }, null);
+ return true;
+ }
return false;
}
+
+ @Override
+ public boolean onCreateOptionsMenu(Menu menu) {
+ if (plugin.getPreferencesId() != -1)
+ getMenuInflater().inflate(R.menu.menu_single_fragment, menu);
+ return super.onCreateOptionsMenu(menu);
+ }
}
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 8397da97aa..c17646e901 100644
--- a/app/src/main/java/info/nightscout/androidaps/tabs/TabPageAdapter.java
+++ b/app/src/main/java/info/nightscout/androidaps/tabs/TabPageAdapter.java
@@ -39,6 +39,10 @@ public class TabPageAdapter extends FragmentStatePagerAdapter {
return Fragment.instantiate(context, visibleFragmentList.get(position).pluginDescription.getFragmentClass());
}
+ public PluginBase getPluginAt(int position) {
+ return visibleFragmentList.get(position);
+ }
+
@Override
public void finishUpdate(ViewGroup container) {
try{
diff --git a/app/src/main/res/menu/menu_main.xml b/app/src/main/res/menu/menu_main.xml
index d68793d4cc..09bd20a631 100644
--- a/app/src/main/res/menu/menu_main.xml
+++ b/app/src/main/res/menu/menu_main.xml
@@ -6,6 +6,10 @@
android:id="@+id/nav_preferences"
app:showAsAction="never"
android:title="@string/nav_preferences" />
+
-
+
+
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index a1c5001150..4ee76190ad 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -1090,4 +1090,5 @@
Exit
Open navigation
Close navigation
+ Plugin preferences