Button for plugin preferences
This commit is contained in:
parent
80e9d769e4
commit
f7b19e37a1
6 changed files with 83 additions and 2 deletions
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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{
|
||||
|
|
|
@ -6,6 +6,10 @@
|
|||
android:id="@+id/nav_preferences"
|
||||
app:showAsAction="never"
|
||||
android:title="@string/nav_preferences" />
|
||||
<item
|
||||
android:id="@+id/nav_plugin_preferences"
|
||||
app:showAsAction="never"
|
||||
android:title="@string/nav_plugin_preferences" />
|
||||
<item
|
||||
android:id="@+id/nav_historybrowser"
|
||||
app:showAsAction="never"
|
||||
|
|
10
app/src/main/res/menu/menu_single_fragment.xml
Normal file
10
app/src/main/res/menu/menu_single_fragment.xml
Normal file
|
@ -0,0 +1,10 @@
|
|||
<menu xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
tools:context=".MainActivity">
|
||||
<item
|
||||
android:id="@+id/nav_plugin_preferences"
|
||||
app:showAsAction="ifRoom"
|
||||
android:icon="@drawable/ic_settings"
|
||||
android:title="@string/nav_plugin_preferences" />
|
||||
</menu>
|
|
@ -1090,4 +1090,5 @@
|
|||
<string name="exit">Exit</string>
|
||||
<string name="open_navigation">Open navigation</string>
|
||||
<string name="close_navigation">Close navigation</string>
|
||||
<string name="nav_plugin_preferences">Plugin preferences</string>
|
||||
</resources>
|
||||
|
|
Loading…
Reference in a new issue