diff --git a/TODO b/TODO index 46a46b35057debd264385c2d6516f4e5805223d2..7a56683182a841e2cb1a9e59e3788ddf51bf770f 100644 --- a/TODO +++ b/TODO @@ -7,11 +7,6 @@ - Better addressbook column widths <zzz> on the i2ptunnel and addressbook pages on the tablet, the columns are too skinny, they aren't as wide as the tab <zzz> only a few addressbook entries wrap but on i2ptunnel everything is wrapped and most of the screen is empty -- Graph config issues - <zzz> all the graphs are disabled on the config page, but on the graphs page it shows a rate tab anyway - <zzz> and no clue that you have to enable the graphs - <zzz> not sure if they are enabled by default or not - I updated from old install - <zzz> but even after I enabled some graphs, it still shows this rate tab that does nothing on the tablet, but goes back to the other page on the phone # Short-term diff --git a/app/src/main/java/net/i2p/android/router/SettingsActivity.java b/app/src/main/java/net/i2p/android/router/SettingsActivity.java index 9ce24aa100f78082d4a4a5d9ee816ed4a1c9b3f8..7b02b29b4fd7756a7c9abe2bc71b214d91c3ddf1 100644 --- a/app/src/main/java/net/i2p/android/router/SettingsActivity.java +++ b/app/src/main/java/net/i2p/android/router/SettingsActivity.java @@ -36,7 +36,7 @@ import net.i2p.util.OrderedProperties; public class SettingsActivity extends PreferenceActivity { // Actions for legacy settings private static final String ACTION_PREFS_NET = "net.i2p.android.router.PREFS_NET"; - private static final String ACTION_PREFS_GRAPHS = "net.i2p.android.router.PREFS_GRAPHS"; + public static final String ACTION_PREFS_GRAPHS = "net.i2p.android.router.PREFS_GRAPHS"; private static final String ACTION_PREFS_LOGGING = "net.i2p.android.router.PREFS_LOGGING"; private static final String ACTION_PREFS_ADVANCED = "net.i2p.android.router.PREFS_ADVANCED"; diff --git a/app/src/main/java/net/i2p/android/router/stats/RateGraphActivity.java b/app/src/main/java/net/i2p/android/router/stats/RateGraphActivity.java index b9378c5b1e8643ac464eeeafce34321f5e0463ed..a99a65c1a013cc1f30eba640f2db53fe7407ef4c 100644 --- a/app/src/main/java/net/i2p/android/router/stats/RateGraphActivity.java +++ b/app/src/main/java/net/i2p/android/router/stats/RateGraphActivity.java @@ -6,12 +6,15 @@ import java.util.TreeSet; import net.i2p.android.router.I2PActivityBase; import net.i2p.android.router.R; +import net.i2p.android.router.SettingsActivity; import net.i2p.android.router.service.StatSummarizer; import net.i2p.android.router.service.SummaryListener; import net.i2p.stat.Rate; import android.app.AlertDialog; import android.app.Dialog; import android.content.DialogInterface; +import android.content.Intent; +import android.os.Build; import android.os.Bundle; import android.support.v4.app.DialogFragment; import android.support.v7.app.ActionBar; @@ -21,6 +24,8 @@ import android.widget.SpinnerAdapter; public class RateGraphActivity extends I2PActivityBase { private static final String SELECTED_RATE = "selected_rate"; + private boolean mFinishOnResume; + @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); @@ -28,46 +33,82 @@ public class RateGraphActivity extends I2PActivityBase { mDrawerToggle.setDrawerIndicatorEnabled(false); if (StatSummarizer.instance() != null) { - // Set up action bar for drop-down list - ActionBar actionBar = getSupportActionBar(); - actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_LIST); - // Get the rates currently being graphed List<SummaryListener> listeners = StatSummarizer.instance().getListeners(); TreeSet<SummaryListener> ordered = new TreeSet<SummaryListener>(new AlphaComparator()); ordered.addAll(listeners); - final String[] mRates = new String[ordered.size()]; - final long[] mPeriods = new long[ordered.size()]; - int i = 0; - for (SummaryListener listener : ordered) { - Rate r = listener.getRate(); - mRates[i] = r.getRateStat().getName(); - mPeriods[i] = r.getPeriod(); - i++; - } - SpinnerAdapter mSpinnerAdapter = new ArrayAdapter<String>(this, - android.R.layout.simple_spinner_dropdown_item, mRates); + if (ordered.size() > 0) { + // Extract the rates and periods + final String[] mRates = new String[ordered.size()]; + final long[] mPeriods = new long[ordered.size()]; + int i = 0; + for (SummaryListener listener : ordered) { + Rate r = listener.getRate(); + mRates[i] = r.getRateStat().getName(); + mPeriods[i] = r.getPeriod(); + i++; + } - ActionBar.OnNavigationListener mNavigationListener = new ActionBar.OnNavigationListener() { - String[] rates = mRates; - long[] periods = mPeriods; + // Set up action bar for drop-down list + ActionBar actionBar = getSupportActionBar(); + actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_LIST); - public boolean onNavigationItemSelected(int position, long itemId) { - String rateName = rates[position]; - long period = periods[position]; - RateGraphFragment f = RateGraphFragment.newInstance(rateName, period); - getSupportFragmentManager().beginTransaction() - .replace(R.id.main_fragment, f, rates[position]).commit(); - return true; - } - }; + SpinnerAdapter mSpinnerAdapter = new ArrayAdapter<String>(this, + android.R.layout.simple_spinner_dropdown_item, mRates); + + ActionBar.OnNavigationListener mNavigationListener = new ActionBar.OnNavigationListener() { + String[] rates = mRates; + long[] periods = mPeriods; - actionBar.setListNavigationCallbacks(mSpinnerAdapter, mNavigationListener); + public boolean onNavigationItemSelected(int position, long itemId) { + String rateName = rates[position]; + long period = periods[position]; + RateGraphFragment f = RateGraphFragment.newInstance(rateName, period); + getSupportFragmentManager().beginTransaction() + .replace(R.id.main_fragment, f, rates[position]).commit(); + return true; + } + }; - if (savedInstanceState != null) { - int selected = savedInstanceState.getInt(SELECTED_RATE); - actionBar.setSelectedNavigationItem(selected); + actionBar.setListNavigationCallbacks(mSpinnerAdapter, mNavigationListener); + + if (savedInstanceState != null) { + int selected = savedInstanceState.getInt(SELECTED_RATE); + actionBar.setSelectedNavigationItem(selected); + } + } else { + DialogFragment df = new DialogFragment() { + @Override + public Dialog onCreateDialog(Bundle savedInstanceState) { + AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); + builder.setMessage(R.string.no_graphs_configured) + .setPositiveButton(R.string.configure_graphs, new DialogInterface.OnClickListener() { + public void onClick(DialogInterface dialog, int which) { + dialog.dismiss(); + mFinishOnResume = true; + Intent i = new Intent(RateGraphActivity.this, SettingsActivity.class); + // Navigation to a sub-category doesn't seem to work yet + if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) { + i.setAction(SettingsActivity.ACTION_PREFS_GRAPHS); + } else { + i.putExtra("settings", "graphs"); + } + startActivity(i); + } + }) + .setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int i) { + dialog.cancel(); + finish(); + } + }) + .setCancelable(false); + return builder.create(); + } + }; + df.show(getSupportFragmentManager(), "nographs"); } } else { DialogFragment df = new DialogFragment() { @@ -75,16 +116,26 @@ public class RateGraphActivity extends I2PActivityBase { public Dialog onCreateDialog(Bundle savedInstanceState) { AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); builder.setMessage(R.string.graphs_not_ready) - .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() { - public void onClick(DialogInterface dialog, int which) { - dialog.dismiss(); - finish(); - } - }); + .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() { + public void onClick(DialogInterface dialog, int which) { + dialog.dismiss(); + finish(); + } + }) + .setCancelable(false); return builder.create(); } }; - df.show(getSupportFragmentManager(), "nographs"); + df.show(getSupportFragmentManager(), "graphsnotready"); + } + } + + @Override + public void onResume() { + super.onResume(); + + if (mFinishOnResume) { + finish(); } } diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index fe07e4b2cadf936803603ed6b8f8f0ec88b6c7c8..8c69e525fa1c065a51eb35e6c16037ee5519cf09 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -60,6 +60,8 @@ <string name="router_not_running">The router is not running.</string> <string name="stats_not_ready">The statistics manager is not ready yet. Try again later.</string> + <string name="no_graphs_configured">No graphs have been configured. You can choose statistics to graph in the settings menu. Any changes will take effect after 60 seconds.</string> + <string name="configure_graphs">Configure graphs</string> <string name="graphs_not_ready">Graphs are not ready, or the router is not running. Try again later.</string> <string name="netdb_routers_empty">No routers in your NetDB.</string>