1
0
mirror of https://github.com/moparisthebest/k-9 synced 2025-01-30 23:00:09 -05:00

Add setting to configure the splitview mode

This commit is contained in:
cketti 2013-01-24 20:30:07 +01:00
parent 573058bffc
commit c5b1e1d0e5
8 changed files with 174 additions and 18 deletions

View File

@ -713,4 +713,15 @@
<item name="3">ALWAYS</item> <item name="3">ALWAYS</item>
</string-array> </string-array>
<string-array name="global_settings_splitview_mode_entries">
<item>@string/global_settings_splitview_always</item>
<item>@string/global_settings_splitview_never</item>
<item>@string/global_settings_splitview_when_in_landscape</item>
</string-array>
<string-array name="global_settings_splitview_mode_values">
<item>ALWAYS</item>
<item>NEVER</item>
<item>WHEN_IN_LANDSCAPE</item>
</string-array>
</resources> </resources>

View File

@ -4,7 +4,7 @@
<!-- <!--
When removing strings from the main file, please cleanup the translations. When removing strings from the main file, please cleanup the translations.
This doesn't work on multiline strings, nor strings with the NEW tag. This doesn't work on multiline strings, nor strings with the NEW tag.
find . -name strings.xml | xargs perl -pi -e's!^\s+<string name="string_name_here".+?</string>\s*\z!!' find . -name strings.xml | xargs perl -pi -e's!^\s+<string name="string_name_here".+?</string>\s*\z!!'
--> -->
@ -1129,4 +1129,9 @@ Please submit bug reports, contribute new features and ask questions at
<string name="upgrade_database_format">Upgrading database of account \"<xliff:g id="account">%s</xliff:g>\"</string> <string name="upgrade_database_format">Upgrading database of account \"<xliff:g id="account">%s</xliff:g>\"</string>
<string name="message_list_loading">Loading…</string> <string name="message_list_loading">Loading…</string>
<string name="global_settings_splitview_mode_label">Show split-screen</string>
<string name="global_settings_splitview_always">Always</string>
<string name="global_settings_splitview_never">Never</string>
<string name="global_settings_splitview_when_in_landscape">When in Landscape orientation</string>
</resources> </resources>

View File

@ -156,6 +156,14 @@
android:title="@string/global_settings_threaded_view_label" android:title="@string/global_settings_threaded_view_label"
android:summary="@string/global_settings_threaded_view_summary" /> android:summary="@string/global_settings_threaded_view_summary" />
<ListPreference
android:persistent="false"
android:key="splitview_mode"
android:title="@string/global_settings_splitview_mode_label"
android:entries="@array/global_settings_splitview_mode_entries"
android:entryValues="@array/global_settings_splitview_mode_values"
android:dialogTitle="@string/global_settings_splitview_mode_label" />
</PreferenceCategory> </PreferenceCategory>
<PreferenceCategory <PreferenceCategory

View File

@ -210,6 +210,15 @@ public class K9 extends Application {
NEVER NEVER
} }
/**
* Controls when to use the message list split view.
*/
public enum SplitViewMode {
ALWAYS,
NEVER,
WHEN_IN_LANDSCAPE
}
private static boolean mMessageListCheckboxes = false; private static boolean mMessageListCheckboxes = false;
private static int mMessageListPreviewLines = 2; private static int mMessageListPreviewLines = 2;
@ -251,6 +260,7 @@ public class K9 extends Application {
private static boolean sUseBackgroundAsUnreadIndicator = true; private static boolean sUseBackgroundAsUnreadIndicator = true;
private static boolean sThreadedViewEnabled = true; private static boolean sThreadedViewEnabled = true;
private static SplitViewMode sSplitViewMode = SplitViewMode.WHEN_IN_LANDSCAPE;
/** /**
* @see #areDatabasesUpToDate() * @see #areDatabasesUpToDate()
@ -530,6 +540,7 @@ public class K9 extends Application {
editor.putString("attachmentdefaultpath", mAttachmentDefaultPath); editor.putString("attachmentdefaultpath", mAttachmentDefaultPath);
editor.putBoolean("useBackgroundAsUnreadIndicator", sUseBackgroundAsUnreadIndicator); editor.putBoolean("useBackgroundAsUnreadIndicator", sUseBackgroundAsUnreadIndicator);
editor.putBoolean("threadedView", sThreadedViewEnabled); editor.putBoolean("threadedView", sThreadedViewEnabled);
editor.putString("splitViewMode", sSplitViewMode.name());
fontSizes.save(editor); fontSizes.save(editor);
} }
@ -737,6 +748,11 @@ public class K9 extends Application {
sNotificationQuickDelete = NotificationQuickDelete.valueOf(notificationQuickDelete); sNotificationQuickDelete = NotificationQuickDelete.valueOf(notificationQuickDelete);
} }
String splitViewMode = sprefs.getString("splitViewMode", null);
if (splitViewMode != null) {
sSplitViewMode = SplitViewMode.valueOf(splitViewMode);
}
mAttachmentDefaultPath = sprefs.getString("attachmentdefaultpath", Environment.getExternalStorageDirectory().toString()); mAttachmentDefaultPath = sprefs.getString("attachmentdefaultpath", Environment.getExternalStorageDirectory().toString());
sUseBackgroundAsUnreadIndicator = sprefs.getBoolean("useBackgroundAsUnreadIndicator", true); sUseBackgroundAsUnreadIndicator = sprefs.getBoolean("useBackgroundAsUnreadIndicator", true);
sThreadedViewEnabled = sprefs.getBoolean("threadedView", true); sThreadedViewEnabled = sprefs.getBoolean("threadedView", true);
@ -1218,10 +1234,10 @@ public class K9 extends Application {
} }
public static boolean wrapFolderNames() { public static boolean wrapFolderNames() {
return mWrapFolderNames; return mWrapFolderNames;
} }
public static void setWrapFolderNames(final boolean state) { public static void setWrapFolderNames(final boolean state) {
mWrapFolderNames = state; mWrapFolderNames = state;
} }
public static String getAttachmentDefaultPath() { public static String getAttachmentDefaultPath() {
@ -1267,6 +1283,14 @@ public class K9 extends Application {
sThreadedViewEnabled = enable; sThreadedViewEnabled = enable;
} }
public static synchronized SplitViewMode getSplitViewMode() {
return sSplitViewMode;
}
public static synchronized void setSplitViewMode(SplitViewMode mode) {
sSplitViewMode = mode;
}
/** /**
* Check if we already know whether all databases are using the current database schema. * Check if we already know whether all databases are using the current database schema.
* *

View File

@ -3,6 +3,7 @@ package com.fsck.k9.activity;
import android.app.SearchManager; import android.app.SearchManager;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.content.res.Configuration;
import android.os.Build; import android.os.Build;
import android.os.Bundle; import android.os.Bundle;
import android.support.v4.app.FragmentManager; import android.support.v4.app.FragmentManager;
@ -66,6 +67,8 @@ public class MessageList extends K9FragmentActivity implements MessageListFragme
public static final String EXTRA_SEARCH_ACCOUNT = "com.fsck.k9.search_account"; public static final String EXTRA_SEARCH_ACCOUNT = "com.fsck.k9.search_account";
private static final String EXTRA_SEARCH_FOLDER = "com.fsck.k9.search_folder"; private static final String EXTRA_SEARCH_FOLDER = "com.fsck.k9.search_folder";
private static final String STATE_DISPLAY_MODE = "displayMode";
public static void actionDisplaySearch(Context context, SearchSpecification search, public static void actionDisplaySearch(Context context, SearchSpecification search,
boolean noThreading, boolean newTask) { boolean noThreading, boolean newTask) {
actionDisplaySearch(context, search, noThreading, newTask, true); actionDisplaySearch(context, search, noThreading, newTask, true);
@ -103,6 +106,12 @@ public class MessageList extends K9FragmentActivity implements MessageListFragme
return intent; return intent;
} }
private enum DisplayMode {
MESSAGE_LIST,
MESSAGE_VIEW,
SPLIT_VIEW
}
private StorageManager.StorageListener mStorageListener = new StorageListenerImplementation(); private StorageManager.StorageListener mStorageListener = new StorageListenerImplementation();
@ -112,6 +121,7 @@ public class MessageList extends K9FragmentActivity implements MessageListFragme
private TextView mActionBarUnread; private TextView mActionBarUnread;
private Menu mMenu; private Menu mMenu;
private ViewGroup mMessageListContainer;
private ViewGroup mMessageViewContainer; private ViewGroup mMessageViewContainer;
private View mMessageViewPlaceHolder; private View mMessageViewPlaceHolder;
@ -134,6 +144,9 @@ public class MessageList extends K9FragmentActivity implements MessageListFragme
*/ */
private boolean mNoThreading; private boolean mNoThreading;
private DisplayMode mDisplayMode;
@Override @Override
public void onCreate(Bundle savedInstanceState) { public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
@ -152,6 +165,7 @@ public class MessageList extends K9FragmentActivity implements MessageListFragme
decodeExtras(getIntent()); decodeExtras(getIntent());
initializeFragments(); initializeFragments();
initializeDisplayMode(savedInstanceState);
initializeLayout(); initializeLayout();
ChangeLog cl = new ChangeLog(this); ChangeLog cl = new ChangeLog(this);
@ -176,12 +190,56 @@ public class MessageList extends K9FragmentActivity implements MessageListFragme
} }
} }
private void initializeDisplayMode(Bundle savedInstanceState) {
if (savedInstanceState != null) {
mDisplayMode = (DisplayMode) savedInstanceState.getSerializable(STATE_DISPLAY_MODE);
} else {
mDisplayMode = DisplayMode.MESSAGE_LIST;
}
switch (K9.getSplitViewMode()) {
case ALWAYS: {
mDisplayMode = DisplayMode.SPLIT_VIEW;
break;
}
case NEVER: {
// Either use the restored setting or DisplayMode.MESSAGE_LIST set above
break;
}
case WHEN_IN_LANDSCAPE: {
int orientation = getResources().getConfiguration().orientation;
if (orientation == Configuration.ORIENTATION_LANDSCAPE) {
mDisplayMode = DisplayMode.SPLIT_VIEW;
} else if (mMessageViewFragment != null) {
mDisplayMode = DisplayMode.MESSAGE_VIEW;
} else {
mDisplayMode = DisplayMode.MESSAGE_LIST;
}
break;
}
}
}
private void initializeLayout() { private void initializeLayout() {
mMessageListContainer = (ViewGroup) findViewById(R.id.message_list_container);
mMessageViewContainer = (ViewGroup) findViewById(R.id.message_view_container); mMessageViewContainer = (ViewGroup) findViewById(R.id.message_view_container);
mMessageViewPlaceHolder = getLayoutInflater().inflate(R.layout.empty_message_view, null); mMessageViewPlaceHolder = getLayoutInflater().inflate(R.layout.empty_message_view, null);
if (mMessageViewFragment == null) { switch (mDisplayMode) {
showMessageViewPlaceHolder(); case MESSAGE_LIST: {
showMessageList();
break;
}
case MESSAGE_VIEW: {
showMessageView();
break;
}
case SPLIT_VIEW: {
if (mMessageViewFragment == null) {
showMessageViewPlaceHolder();
}
break;
}
} }
} }
@ -272,6 +330,13 @@ public class MessageList extends K9FragmentActivity implements MessageListFragme
StorageManager.getInstance(getApplication()).addListener(mStorageListener); StorageManager.getInstance(getApplication()).addListener(mStorageListener);
} }
@Override
public void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
outState.putSerializable(STATE_DISPLAY_MODE, mDisplayMode);
}
private void initializeActionBar() { private void initializeActionBar() {
mActionBar = getSupportActionBar(); mActionBar = getSupportActionBar();
@ -628,7 +693,11 @@ public class MessageList extends K9FragmentActivity implements MessageListFragme
mMessageViewFragment = fragment; mMessageViewFragment = fragment;
ft.commit(); ft.commit();
mMessageListFragment.setActiveMessage(messageReference); if (mDisplayMode == DisplayMode.SPLIT_VIEW) {
mMessageListFragment.setActiveMessage(messageReference);
} else {
showMessageView();
}
} }
} }
@ -673,8 +742,12 @@ public class MessageList extends K9FragmentActivity implements MessageListFragme
FragmentManager fragmentManager = getSupportFragmentManager(); FragmentManager fragmentManager = getSupportFragmentManager();
mMessageListFragment = (MessageListFragment) fragmentManager.findFragmentById( mMessageListFragment = (MessageListFragment) fragmentManager.findFragmentById(
R.id.message_list_container); R.id.message_list_container);
mMessageViewFragment = (MessageViewFragment) fragmentManager.findFragmentById(
R.id.message_view_container);
showMessageViewPlaceHolder(); if (mDisplayMode == DisplayMode.SPLIT_VIEW) {
showMessageViewPlaceHolder();
}
configureMenu(mMenu); configureMenu(mMenu);
} }
@ -753,13 +826,7 @@ public class MessageList extends K9FragmentActivity implements MessageListFragme
} }
private void showMessageViewPlaceHolder() { private void showMessageViewPlaceHolder() {
// Remove MessageViewFragment if necessary removeMessageViewFragment();
if (mMessageViewFragment != null) {
FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
ft.remove(mMessageViewFragment);
mMessageViewFragment = null;
ft.commit();
}
// Add placeholder view if necessary // Add placeholder view if necessary
if (mMessageViewPlaceHolder.getParent() == null) { if (mMessageViewPlaceHolder.getParent() == null) {
@ -769,6 +836,18 @@ public class MessageList extends K9FragmentActivity implements MessageListFragme
mMessageListFragment.setActiveMessage(null); mMessageListFragment.setActiveMessage(null);
} }
/**
* Remove MessageViewFragment if necessary.
*/
private void removeMessageViewFragment() {
if (mMessageViewFragment != null) {
FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
ft.remove(mMessageViewFragment);
mMessageViewFragment = null;
ft.commit();
}
}
@Override @Override
public void remoteSearchStarted() { public void remoteSearchStarted() {
// Remove action button for remote search // Remove action button for remote search
@ -778,9 +857,10 @@ public class MessageList extends K9FragmentActivity implements MessageListFragme
@Override @Override
public void goBack() { public void goBack() {
FragmentManager fragmentManager = getSupportFragmentManager(); FragmentManager fragmentManager = getSupportFragmentManager();
if (fragmentManager.getBackStackEntryCount() > 0) { if (mDisplayMode == DisplayMode.MESSAGE_VIEW) {
showMessageList();
} else if (fragmentManager.getBackStackEntryCount() > 0) {
fragmentManager.popBackStack(); fragmentManager.popBackStack();
showMessageViewPlaceHolder();
} else if (mMessageListFragment.isManualSearch()) { } else if (mMessageListFragment.isManualSearch()) {
onBackPressed(); onBackPressed();
} else if (!mSingleFolderMode) { } else if (!mSingleFolderMode) {
@ -871,4 +951,20 @@ public class MessageList extends K9FragmentActivity implements MessageListFragme
private void showNextMessage() { private void showNextMessage() {
//TODO: implement //TODO: implement
} }
private void showMessageList() {
mDisplayMode = DisplayMode.MESSAGE_LIST;
mMessageViewContainer.setVisibility(View.GONE);
mMessageListContainer.setVisibility(View.VISIBLE);
removeMessageViewFragment();
mMessageListFragment.setActiveMessage(null);
}
private void showMessageView() {
mDisplayMode = DisplayMode.MESSAGE_VIEW;
mMessageListContainer.setVisibility(View.GONE);
mMessageViewContainer.setVisibility(View.VISIBLE);
}
} }

View File

@ -24,6 +24,7 @@ import com.fsck.k9.Account;
import com.fsck.k9.K9; import com.fsck.k9.K9;
import com.fsck.k9.K9.NotificationHideSubject; import com.fsck.k9.K9.NotificationHideSubject;
import com.fsck.k9.K9.NotificationQuickDelete; import com.fsck.k9.K9.NotificationQuickDelete;
import com.fsck.k9.K9.SplitViewMode;
import com.fsck.k9.Preferences; import com.fsck.k9.Preferences;
import com.fsck.k9.R; import com.fsck.k9.R;
import com.fsck.k9.activity.ColorPickerDialog; import com.fsck.k9.activity.ColorPickerDialog;
@ -93,6 +94,7 @@ public class Prefs extends K9PreferenceActivity {
private static final String PREFERENCE_BACKGROUND_AS_UNREAD_INDICATOR = "messagelist_background_as_unread_indicator"; private static final String PREFERENCE_BACKGROUND_AS_UNREAD_INDICATOR = "messagelist_background_as_unread_indicator";
private static final String PREFERENCE_THREADED_VIEW = "threaded_view"; private static final String PREFERENCE_THREADED_VIEW = "threaded_view";
private static final String PREFERENCE_FOLDERLIST_WRAP_NAME = "folderlist_wrap_folder_name"; private static final String PREFERENCE_FOLDERLIST_WRAP_NAME = "folderlist_wrap_folder_name";
private static final String PREFERENCE_SPLITVIEW_MODE = "splitview_mode";
private static final int ACTIVITY_CHOOSE_FOLDER = 1; private static final int ACTIVITY_CHOOSE_FOLDER = 1;
@ -139,6 +141,7 @@ public class Prefs extends K9PreferenceActivity {
private CheckBoxPreference mBatchButtonsUnselect; private CheckBoxPreference mBatchButtonsUnselect;
private CheckBoxPreference mBackgroundAsUnreadIndicator; private CheckBoxPreference mBackgroundAsUnreadIndicator;
private CheckBoxPreference mThreadedView; private CheckBoxPreference mThreadedView;
private ListPreference mSplitViewMode;
public static void actionPrefs(Context context) { public static void actionPrefs(Context context) {
@ -396,7 +399,7 @@ public class Prefs extends K9PreferenceActivity {
} }
}; };
}); });
mWrapFolderNames = (CheckBoxPreference)findPreference(PREFERENCE_FOLDERLIST_WRAP_NAME); mWrapFolderNames = (CheckBoxPreference)findPreference(PREFERENCE_FOLDERLIST_WRAP_NAME);
mWrapFolderNames.setChecked(K9.wrapFolderNames()); mWrapFolderNames.setChecked(K9.wrapFolderNames());
@ -425,6 +428,10 @@ public class Prefs extends K9PreferenceActivity {
mBatchButtonsArchive.setEnabled(false); mBatchButtonsArchive.setEnabled(false);
mBatchButtonsArchive.setSummary(R.string.global_settings_archive_disabled_reason); mBatchButtonsArchive.setSummary(R.string.global_settings_archive_disabled_reason);
} }
mSplitViewMode = (ListPreference) findPreference(PREFERENCE_SPLITVIEW_MODE);
initListPreference(mSplitViewMode, K9.getSplitViewMode().name(),
mSplitViewMode.getEntries(), mSplitViewMode.getEntryValues());
} }
private void saveSettings() { private void saveSettings() {
@ -487,6 +494,7 @@ public class Prefs extends K9PreferenceActivity {
K9.setBatchButtonsFlag(mBatchButtonsFlag.isChecked()); K9.setBatchButtonsFlag(mBatchButtonsFlag.isChecked());
K9.setBatchButtonsUnselect(mBatchButtonsUnselect.isChecked()); K9.setBatchButtonsUnselect(mBatchButtonsUnselect.isChecked());
K9.setSplitViewMode(SplitViewMode.valueOf(mSplitViewMode.getValue()));
K9.setAttachmentDefaultPath(mAttachmentPathPreference.getSummary().toString()); K9.setAttachmentDefaultPath(mAttachmentPathPreference.getSummary().toString());
boolean needsRefresh = K9.setBackgroundOps(mBackgroundOps.getValue()); boolean needsRefresh = K9.setBackgroundOps(mBackgroundOps.getValue());
K9.setUseGalleryBugWorkaround(mUseGalleryBugWorkaround.isChecked()); K9.setUseGalleryBugWorkaround(mUseGalleryBugWorkaround.isChecked());

View File

@ -18,6 +18,7 @@ import com.fsck.k9.Account;
import com.fsck.k9.FontSizes; import com.fsck.k9.FontSizes;
import com.fsck.k9.K9; import com.fsck.k9.K9;
import com.fsck.k9.K9.NotificationHideSubject; import com.fsck.k9.K9.NotificationHideSubject;
import com.fsck.k9.K9.SplitViewMode;
import com.fsck.k9.R; import com.fsck.k9.R;
import com.fsck.k9.Account.SortType; import com.fsck.k9.Account.SortType;
import com.fsck.k9.helper.DateFormatter; import com.fsck.k9.helper.DateFormatter;
@ -228,6 +229,9 @@ public class GlobalSettings {
s.put("threadedView", Settings.versions( s.put("threadedView", Settings.versions(
new V(20, new BooleanSetting(true)) new V(20, new BooleanSetting(true))
)); ));
s.put("splitViewMode", Settings.versions(
new V(23, new EnumSetting(SplitViewMode.class, SplitViewMode.WHEN_IN_LANDSCAPE))
));
SETTINGS = Collections.unmodifiableMap(s); SETTINGS = Collections.unmodifiableMap(s);

View File

@ -35,7 +35,7 @@ public class Settings {
* *
* @see SettingsExporter * @see SettingsExporter
*/ */
public static final int VERSION = 22; public static final int VERSION = 23;
public static Map<String, Object> validate(int version, Map<String, public static Map<String, Object> validate(int version, Map<String,
TreeMap<Integer, SettingsDescription>> settings, TreeMap<Integer, SettingsDescription>> settings,