Commit 2f56174d authored by Robert Hitt's avatar Robert Hitt

Added default tab setting

parent 77a0afd1
Pipeline #879 passed with stages
in 4 minutes and 34 seconds
...@@ -2,9 +2,11 @@ package srct.whatsopen.views.activities; ...@@ -2,9 +2,11 @@ package srct.whatsopen.views.activities;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle; import android.os.Bundle;
import android.support.v4.view.ViewPager; import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity; import android.support.v7.app.AppCompatActivity;
import android.support.v7.preference.PreferenceManager;
import android.support.v7.widget.Toolbar; import android.support.v7.widget.Toolbar;
import android.view.Menu; import android.view.Menu;
import android.view.MenuItem; import android.view.MenuItem;
...@@ -99,7 +101,24 @@ public class MainActivity extends AppCompatActivity implements MainView { ...@@ -99,7 +101,24 @@ public class MainActivity extends AppCompatActivity implements MainView {
tabStrip.setViewPager(mViewPager); tabStrip.setViewPager(mViewPager);
// Set the default tab to 'All' // Set the default tab to 'All'
mViewPager.setCurrentItem(1); int tabNumber = getDefaultTabNumber();
mViewPager.setCurrentItem(tabNumber);
}
private int getDefaultTabNumber() {
SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(this);
String tabName = pref.getString("list_view_default_tab_preference", "default_tab_all");
switch(tabName) {
case "default_tab_favorites":
return 0;
case "default_tab_all":default:
return 1;
case "default_tab_open":
return 2;
case "default_tab_closed":
return 3;
}
} }
@Override @Override
......
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
<!-- Strings for PreferenceFragment --> <!-- Strings for PreferenceFragment -->
<string name="title_list_view">List View</string> <string name="title_list_view">List View</string>
<string name="title_list_view_information">Duration display</string> <string name="title_list_view_information">Duration display</string>
<string name="title_list_view_default_tab">Default tab</string>
<string name="title_rotation">Rotation</string> <string name="title_rotation">Rotation</string>
<string name="title_turn_off_rotation">Turn off rotation</string> <string name="title_turn_off_rotation">Turn off rotation</string>
<string name="title_notification">Notifications</string> <string name="title_notification">Notifications</string>
...@@ -23,5 +24,17 @@ ...@@ -23,5 +24,17 @@
<item>display_duration_closed</item> <item>display_duration_closed</item>
<item>display_duration_none</item> <item>display_duration_none</item>
</string-array> </string-array>
<string-array name="entries_list_view_default_tab_preference">
<item>All</item>
<item>Favorites</item>
<item>Open</item>
<item>Closed</item>
</string-array>
<string-array name="entryvalues_list_view_default_tab_preference">
<item>default_tab_all</item>
<item>default_tab_favorites</item>
<item>default_tab_open</item>
<item>default_tab_closed</item>
</string-array>
</resources> </resources>
...@@ -11,6 +11,12 @@ ...@@ -11,6 +11,12 @@
android:entries="@array/entries_list_view_information_preference" android:entries="@array/entries_list_view_information_preference"
android:entryValues="@array/entryvalues_list_view_information_preference" /> android:entryValues="@array/entryvalues_list_view_information_preference" />
<ListPreference
android:key="list_view_default_tab_preference"
android:title="@string/title_list_view_default_tab"
android:entries="@array/entries_list_view_default_tab_preference"
android:entryValues="@array/entryvalues_list_view_default_tab_preference" />
</PreferenceCategory> </PreferenceCategory>
<PreferenceCategory <PreferenceCategory
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment