2018-07-29 00:08:28 +02:00
|
|
|
package info.nightscout.androidaps.activities;
|
2018-06-03 23:28:04 +02:00
|
|
|
|
2018-06-04 21:56:31 +02:00
|
|
|
import android.content.Intent;
|
2018-06-03 23:28:04 +02:00
|
|
|
import android.os.Bundle;
|
|
|
|
import android.support.annotation.Nullable;
|
|
|
|
import android.support.v4.app.Fragment;
|
|
|
|
import android.support.v7.app.AppCompatActivity;
|
2018-06-04 21:56:31 +02:00
|
|
|
import android.view.Menu;
|
2018-06-03 23:28:04 +02:00
|
|
|
import android.view.MenuItem;
|
|
|
|
|
2018-07-29 00:08:28 +02:00
|
|
|
import info.nightscout.androidaps.MainApp;
|
|
|
|
import info.nightscout.androidaps.R;
|
|
|
|
import info.nightscout.androidaps.activities.PreferencesActivity;
|
2018-06-03 23:28:04 +02:00
|
|
|
import info.nightscout.androidaps.interfaces.PluginBase;
|
2018-06-04 21:56:31 +02:00
|
|
|
import info.nightscout.utils.PasswordProtection;
|
2018-06-03 23:28:04 +02:00
|
|
|
|
|
|
|
public class SingleFragmentActivity extends AppCompatActivity {
|
|
|
|
|
2018-06-04 21:56:31 +02:00
|
|
|
private PluginBase plugin;
|
|
|
|
|
2018-06-03 23:28:04 +02:00
|
|
|
@Override
|
|
|
|
protected void onCreate(@Nullable Bundle savedInstanceState) {
|
|
|
|
super.onCreate(savedInstanceState);
|
|
|
|
setContentView(R.layout.activity_single_fragment);
|
|
|
|
|
2018-06-04 21:56:31 +02:00
|
|
|
this.plugin = MainApp.getPluginsList().get(getIntent().getIntExtra("plugin", -1));
|
2018-06-03 23:28:04 +02:00
|
|
|
setTitle(plugin.getName());
|
|
|
|
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
|
|
|
|
getSupportActionBar().setDisplayShowHomeEnabled(true);
|
|
|
|
|
|
|
|
if (savedInstanceState == null) {
|
|
|
|
getSupportFragmentManager().beginTransaction().replace(R.id.frame_layout,
|
|
|
|
Fragment.instantiate(this, plugin.pluginDescription.getFragmentClass())).commit();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean onOptionsItemSelected(MenuItem item) {
|
2018-06-04 21:56:31 +02:00
|
|
|
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;
|
|
|
|
}
|
2018-06-03 23:28:04 +02:00
|
|
|
return false;
|
|
|
|
}
|
2018-06-04 21:56:31 +02:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean onCreateOptionsMenu(Menu menu) {
|
|
|
|
if (plugin.getPreferencesId() != -1)
|
|
|
|
getMenuInflater().inflate(R.menu.menu_single_fragment, menu);
|
|
|
|
return super.onCreateOptionsMenu(menu);
|
|
|
|
}
|
2018-06-03 23:28:04 +02:00
|
|
|
}
|