improved settings panes on tablets

This commit is contained in:
Mariotaku Lee 2017-01-17 00:38:50 +08:00
parent 584b5debe1
commit 31b20a47fc
14 changed files with 103 additions and 252 deletions

View File

@ -568,11 +568,6 @@ public final class Utils implements Constants {
return null;
}
public static int getDefaultTextSize(final Context context) {
if (context == null) return 15;
return context.getResources().getInteger(R.integer.default_text_size);
}
public static String getErrorMessage(final Context context, final CharSequence message) {
if (context == null) return ParseUtils.parseString(message);
if (TextUtils.isEmpty(message)) return context.getString(R.string.error_unknown_error);

View File

@ -244,7 +244,7 @@ class ComposeActivity : BaseActivity(), OnMenuItemClickListener, OnClickListener
}
setMenu()
updateTextCount()
val textSize = preferences.getInt(KEY_TEXT_SIZE, Utils.getDefaultTextSize(this))
val textSize = preferences[textSizeKey]
editText.textSize = textSize * 1.25f
}

View File

@ -3,12 +3,13 @@ package org.mariotaku.twidere.adapter
import android.content.Context
import android.support.v4.text.BidiFormatter
import android.support.v7.widget.RecyclerView
import org.mariotaku.kpreferences.get
import org.mariotaku.twidere.R
import org.mariotaku.twidere.adapter.iface.IGapSupportedAdapter
import org.mariotaku.twidere.adapter.iface.IStatusesAdapter
import org.mariotaku.twidere.adapter.iface.IUserListsAdapter
import org.mariotaku.twidere.adapter.iface.IUsersAdapter
import org.mariotaku.twidere.constant.SharedPreferenceConstants
import org.mariotaku.twidere.constant.*
import org.mariotaku.twidere.model.*
import org.mariotaku.twidere.model.util.getActivityStatus
import org.mariotaku.twidere.util.*
@ -172,16 +173,16 @@ class DummyItemAdapter @JvmOverloads constructor(
}
fun updateOptions() {
profileImageStyle = Utils.getProfileImageStyle(preferences.getString(SharedPreferenceConstants.KEY_PROFILE_IMAGE_STYLE, null))
mediaPreviewStyle = Utils.getMediaPreviewStyle(preferences.getString(SharedPreferenceConstants.KEY_MEDIA_PREVIEW_STYLE, null))
textSize = preferences.getInt(SharedPreferenceConstants.KEY_TEXT_SIZE, context.resources.getInteger(R.integer.default_text_size)).toFloat()
nameFirst = preferences.getBoolean(SharedPreferenceConstants.KEY_NAME_FIRST, true)
profileImageEnabled = preferences.getBoolean(SharedPreferenceConstants.KEY_DISPLAY_PROFILE_IMAGE, true)
mediaPreviewEnabled = preferences.getBoolean(SharedPreferenceConstants.KEY_MEDIA_PREVIEW, false)
sensitiveContentEnabled = preferences.getBoolean(SharedPreferenceConstants.KEY_DISPLAY_SENSITIVE_CONTENTS, false)
showCardActions = !preferences.getBoolean(SharedPreferenceConstants.KEY_HIDE_CARD_ACTIONS, false)
linkHighlightingStyle = Utils.getLinkHighlightingStyleInt(preferences.getString(SharedPreferenceConstants.KEY_LINK_HIGHLIGHT_OPTION, null))
useStarsForLikes = preferences.getBoolean(SharedPreferenceConstants.KEY_I_WANT_MY_STARS_BACK)
isShowAbsoluteTime = preferences.getBoolean(SharedPreferenceConstants.KEY_SHOW_ABSOLUTE_TIME)
profileImageStyle = preferences[profileImageStyleKey]
mediaPreviewStyle = preferences[mediaPreviewStyleKey]
textSize = preferences[textSizeKey].toFloat()
nameFirst = preferences[nameFirstKey]
profileImageEnabled = preferences[displayProfileImageKey]
mediaPreviewEnabled = preferences[mediaPreviewKey]
sensitiveContentEnabled = preferences[displaySensitiveContentsKey]
showCardActions = !preferences[hideCardActionsKey]
linkHighlightingStyle = preferences[linkHighlightOptionKey]
useStarsForLikes = preferences[iWantMyStarsBackKey]
isShowAbsoluteTime = preferences[showAbsoluteTimeKey]
}
}

View File

@ -10,8 +10,6 @@ import org.mariotaku.twidere.Constants.KEY_DISPLAY_PROFILE_IMAGE
import org.mariotaku.twidere.Constants.KEY_NO_CLOSE_AFTER_TWEET_SENT
import org.mariotaku.twidere.TwidereConstants.*
import org.mariotaku.twidere.annotation.AccountType
import org.mariotaku.twidere.constant.SharedPreferenceConstants.KEY_CUSTOM_API_TYPE
import org.mariotaku.twidere.constant.SharedPreferenceConstants.VALUE_MEDIA_PREVIEW_STYLE_CODE_CROP
import org.mariotaku.twidere.extension.getNonEmptyString
import org.mariotaku.twidere.model.CustomAPIConfig
import org.mariotaku.twidere.model.account.cred.Credentials
@ -33,7 +31,6 @@ val displaySensitiveContentsKey = KBooleanKey(KEY_DISPLAY_SENSITIVE_CONTENTS, fa
val hideCardActionsKey = KBooleanKey(KEY_HIDE_CARD_ACTIONS, false)
val iWantMyStarsBackKey = KBooleanKey(KEY_I_WANT_MY_STARS_BACK, false)
val showAbsoluteTimeKey = KBooleanKey(KEY_SHOW_ABSOLUTE_TIME, false)
val linkHighlightOptionKey = KStringKey(KEY_LINK_HIGHLIGHT_OPTION, VALUE_LINK_HIGHLIGHT_OPTION_NONE)
val statusShortenerKey = KNullableStringKey(KEY_STATUS_SHORTENER, null)
val mediaUploaderKey = KNullableStringKey(KEY_MEDIA_UPLOADER, null)
val newDocumentApiKey = KBooleanKey(KEY_NEW_DOCUMENT_API, Build.VERSION.SDK_INT == Build.VERSION_CODES.M)
@ -59,6 +56,7 @@ val themeColorKey = KIntKey(KEY_THEME_COLOR, 0)
val filterUnavailableQuoteStatusesKey = KBooleanKey("filter_unavailable_quote_statuses", false)
val filterPossibilitySensitiveStatusesKey = KBooleanKey("filter_possibility_sensitive_statuses", false)
val chromeCustomTabKey = KBooleanKey("chrome_custom_tab", true)
object themeBackgroundAlphaKey : KSimpleKey<Int>(KEY_THEME_BACKGROUND_ALPHA, 0xFF) {
override fun read(preferences: SharedPreferences): Int {
return preferences.getInt(KEY_THEME_BACKGROUND_ALPHA, DEFAULT_THEME_BACKGROUND_ALPHA)
@ -98,6 +96,26 @@ object mediaPreviewStyleKey : KSimpleKey<Int>(KEY_MEDIA_PREVIEW_STYLE, VALUE_MED
}
object linkHighlightOptionKey : KSimpleKey<Int>(KEY_LINK_HIGHLIGHT_OPTION, VALUE_LINK_HIGHLIGHT_OPTION_CODE_NONE) {
override fun read(preferences: SharedPreferences): Int = when (preferences.getString(key, null)) {
VALUE_LINK_HIGHLIGHT_OPTION_BOTH -> VALUE_LINK_HIGHLIGHT_OPTION_CODE_BOTH
VALUE_LINK_HIGHLIGHT_OPTION_UNDERLINE -> VALUE_LINK_HIGHLIGHT_OPTION_CODE_UNDERLINE
VALUE_LINK_HIGHLIGHT_OPTION_HIGHLIGHT -> VALUE_LINK_HIGHLIGHT_OPTION_CODE_HIGHLIGHT
else -> VALUE_LINK_HIGHLIGHT_OPTION_CODE_NONE
}
override fun write(editor: SharedPreferences.Editor, value: Int): Boolean {
editor.putString(key, when (value) {
VALUE_LINK_HIGHLIGHT_OPTION_CODE_BOTH -> VALUE_LINK_HIGHLIGHT_OPTION_BOTH
VALUE_LINK_HIGHLIGHT_OPTION_CODE_UNDERLINE -> VALUE_LINK_HIGHLIGHT_OPTION_UNDERLINE
VALUE_LINK_HIGHLIGHT_OPTION_CODE_HIGHLIGHT -> VALUE_LINK_HIGHLIGHT_OPTION_HIGHLIGHT
else -> VALUE_LINK_HIGHLIGHT_OPTION_NONE
})
return true
}
}
object refreshIntervalKey : KSimpleKey<Long>(KEY_REFRESH_INTERVAL, 15) {
override fun read(preferences: SharedPreferences): Long {
return preferences.getString(key, null).toLong(def)

View File

@ -113,9 +113,6 @@ abstract class AbsContentListViewFragment<A : ListAdapter> : BaseFragment(),
override fun onActivityCreated(savedInstanceState: Bundle?) {
super.onActivityCreated(savedInstanceState)
val view = view!!
val context = view.context
val backgroundColor = ThemeUtils.getThemeBackgroundColor(context)
val colorRes = TwidereColorUtils.getContrastYIQ(backgroundColor,
R.color.bg_refresh_progress_color_light, R.color.bg_refresh_progress_color_dark)

View File

@ -1,164 +0,0 @@
/*
* Twidere - Twitter client for Android
*
* Copyright (C) 2012-2014 Mariotaku Lee <mariotaku.lee@gmail.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.mariotaku.twidere.fragment
import android.content.ContentResolver
import android.content.Context
import android.content.SharedPreferences
import android.os.Bundle
import android.support.v4.app.ListFragment
import android.support.v4.app.ListFragmentAccessor
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.AbsListView
import android.widget.AbsListView.OnScrollListener
import android.widget.ProgressBar
import org.mariotaku.chameleon.Chameleon
import org.mariotaku.chameleon.view.ChameleonProgressBar
import org.mariotaku.twidere.app.TwidereApplication
import org.mariotaku.twidere.constant.IntentConstants.EXTRA_TAB_POSITION
import org.mariotaku.twidere.fragment.iface.RefreshScrollTopInterface
import org.mariotaku.twidere.util.AsyncTwitterWrapper
import org.mariotaku.twidere.util.SharedPreferencesWrapper
import org.mariotaku.twidere.util.Utils
import org.mariotaku.twidere.util.dagger.GeneralComponentHelper
import javax.inject.Inject
open class BaseListFragment : ListFragment(), OnScrollListener, RefreshScrollTopInterface {
@Inject
lateinit var twitterWrapper: AsyncTwitterWrapper
@Inject
lateinit var preferences: SharedPreferencesWrapper
var activityFirstCreated: Boolean = false
private set
var instanceStateSaved: Boolean = false
private set
var reachedBottom: Boolean = false
private set
private var notReachedBottomBefore = true
override fun onAttach(context: Context) {
super.onAttach(context)
GeneralComponentHelper.build(context).inject(this)
}
val application: TwidereApplication
get() = TwidereApplication.getInstance(activity)
val contentResolver: ContentResolver?
get() {
val activity = activity
if (activity != null) return activity.contentResolver
return null
}
fun getSharedPreferences(name: String, mode: Int): SharedPreferences? {
val activity = activity
if (activity != null) return activity.getSharedPreferences(name, mode)
return null
}
fun getSystemService(name: String): Any? {
val activity = activity
if (activity != null) return activity.getSystemService(name)
return null
}
val tabPosition: Int
get() {
return arguments?.getInt(EXTRA_TAB_POSITION, -1) ?: -1
}
override fun onActivityCreated(savedInstanceState: Bundle?) {
super.onActivityCreated(savedInstanceState)
instanceStateSaved = savedInstanceState != null
val lv = listView
lv.setOnScrollListener(this)
}
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
activityFirstCreated = true
}
override fun onDestroy() {
super.onDestroy()
activityFirstCreated = true
}
override fun onCreateView(inflater: LayoutInflater?, container: ViewGroup?, savedInstanceState: Bundle?): View? {
val view = super.onCreateView(inflater, container, savedInstanceState)!!
((view.findViewById(ListFragmentAccessor.INTERNAL_PROGRESS_CONTAINER_ID) as ViewGroup).getChildAt(0) as ProgressBar).apply {
val appearance = ChameleonProgressBar.Appearance()
appearance.progressColor = Chameleon.getOverrideTheme(activity, activity).colorPrimary
ChameleonProgressBar.Appearance.apply(this, appearance)
}
return view
}
override fun onScroll(view: AbsListView, firstVisibleItem: Int, visibleItemCount: Int,
totalItemCount: Int) {
val reached = firstVisibleItem + visibleItemCount >= totalItemCount && totalItemCount >= visibleItemCount
if (reachedBottom != reached) {
reachedBottom = reached
if (reachedBottom && notReachedBottomBefore) {
notReachedBottomBefore = false
return
}
if (reachedBottom && listAdapter.count > visibleItemCount) {
onReachedBottom()
}
}
}
override fun onScrollStateChanged(view: AbsListView, scrollState: Int) {
}
override fun onStart() {
super.onStart()
}
override fun onStop() {
activityFirstCreated = false
super.onStop()
}
override fun scrollToStart(): Boolean {
Utils.scrollListToTop(listView)
return true
}
override fun setSelection(position: Int) {
Utils.scrollListToPosition(listView, position)
}
override fun triggerRefresh(): Boolean {
return false
}
protected fun onReachedBottom() {
}
}

View File

@ -43,6 +43,7 @@ import android.widget.AdapterView
import android.widget.AdapterView.OnItemClickListener
import android.widget.ListView
import kotlinx.android.synthetic.main.fragment_drafts.*
import org.mariotaku.kpreferences.get
import org.mariotaku.ktextension.toStringArray
import org.mariotaku.sqliteqb.library.Columns.Column
import org.mariotaku.sqliteqb.library.Expression
@ -52,6 +53,7 @@ import org.mariotaku.twidere.TwidereConstants.*
import org.mariotaku.twidere.activity.iface.IExtendedActivity
import org.mariotaku.twidere.adapter.DraftsAdapter
import org.mariotaku.twidere.constant.IntentConstants
import org.mariotaku.twidere.constant.textSizeKey
import org.mariotaku.twidere.extension.invertSelection
import org.mariotaku.twidere.extension.selectAll
import org.mariotaku.twidere.extension.selectNone
@ -64,7 +66,6 @@ import org.mariotaku.twidere.provider.TwidereDataStore.Drafts
import org.mariotaku.twidere.service.LengthyOperationsService
import org.mariotaku.twidere.util.AsyncTaskUtils
import org.mariotaku.twidere.util.JsonSerializer
import org.mariotaku.twidere.util.Utils.getDefaultTextSize
import java.io.File
import java.util.*
@ -75,7 +76,7 @@ class DraftsFragment : BaseFragment(), LoaderCallbacks<Cursor?>, OnItemClickList
override fun onActivityCreated(savedInstanceState: Bundle?) {
super.onActivityCreated(savedInstanceState)
adapter = DraftsAdapter(activity).apply {
textSize = preferences.getInt(KEY_TEXT_SIZE, getDefaultTextSize(activity)).toFloat()
textSize = preferences[textSizeKey].toFloat()
}
listView.adapter = adapter

View File

@ -19,6 +19,7 @@
package org.mariotaku.twidere.fragment
import android.content.Context
import android.content.Intent
import android.content.pm.PackageManager
import android.net.Uri
@ -31,8 +32,10 @@ import android.view.ContextMenu.ContextMenuInfo
import android.view.MenuInflater
import android.view.MenuItem
import android.view.View
import android.widget.AdapterView
import android.widget.AdapterView.AdapterContextMenuInfo
import android.widget.ListView
import kotlinx.android.synthetic.main.fragment_content_listview.*
import org.mariotaku.ktextension.isNullOrEmpty
import org.mariotaku.ktextension.setItemAvailability
import org.mariotaku.twidere.R
import org.mariotaku.twidere.TwidereConstants.LOGTAG
@ -42,24 +45,25 @@ import org.mariotaku.twidere.loader.ExtensionsListLoader
import org.mariotaku.twidere.loader.ExtensionsListLoader.ExtensionInfo
import org.mariotaku.twidere.util.PermissionsManager
class ExtensionsListFragment : BaseListFragment(), LoaderCallbacks<List<ExtensionInfo>> {
class ExtensionsListFragment : AbsContentListViewFragment<ExtensionsAdapter>(),
LoaderCallbacks<List<ExtensionInfo>>, AdapterView.OnItemClickListener {
private var packageManager: PackageManager? = null
private var permissionsManager: PermissionsManager? = null
private var permissionsManager: PermissionsManager? = null
override fun onActivityCreated(savedInstanceState: Bundle?) {
super.onActivityCreated(savedInstanceState)
packageManager = activity.packageManager
permissionsManager = PermissionsManager(activity)
listAdapter = ExtensionsAdapter(activity)
listView.setOnCreateContextMenuListener(this)
listView.onItemClickListener = this
loaderManager.initLoader(0, null, this)
setEmptyText(getString(R.string.no_extension_installed))
setListShown(false)
showProgress()
}
override fun onStop() {
super.onStop()
override fun onCreateAdapter(context: Context): ExtensionsAdapter {
return ExtensionsAdapter(activity)
}
override fun onCreateLoader(id: Int, args: Bundle?): Loader<List<ExtensionInfo>> {
@ -67,28 +71,32 @@ class ExtensionsListFragment : BaseListFragment(), LoaderCallbacks<List<Extensio
}
override fun onLoadFinished(loader: Loader<List<ExtensionInfo>>, data: List<ExtensionInfo>) {
(listAdapter as ExtensionsAdapter).setData(data)
setListShown(true)
adapter.setData(data)
if (data.isNullOrEmpty()) {
showEmpty(R.drawable.ic_info_info_generic, getString(R.string.no_extension_installed))
} else {
showContent()
}
}
override fun onLoaderReset(loader: Loader<List<ExtensionInfo>>) {
(listAdapter as ExtensionsAdapter).setData(null)
adapter.setData(null)
}
override fun onListItemClick(l: ListView?, v: View?, position: Int, id: Long) {
openSettings((listAdapter as ExtensionsAdapter).getItem(position))
override fun onItemClick(parent: AdapterView<*>?, view: View?, position: Int, id: Long) {
openSettings(adapter.getItem(position))
}
override fun onResume() {
super.onResume()
(listAdapter as ExtensionsAdapter).notifyDataSetChanged()
adapter.notifyDataSetChanged()
}
override fun onCreateContextMenu(menu: ContextMenu, v: View, menuInfo: ContextMenuInfo) {
val inflater = MenuInflater(v.context)
inflater.inflate(R.menu.action_extension, menu)
val adapterMenuInfo = menuInfo as AdapterContextMenuInfo
val extensionInfo = (listAdapter as ExtensionsAdapter).getItem(adapterMenuInfo.position)
val extensionInfo = adapter.getItem(adapterMenuInfo.position)
if (extensionInfo.pname != null && extensionInfo.settings != null) {
val intent = Intent(IntentConstants.INTENT_ACTION_EXTENSION_SETTINGS)
intent.setClassName(extensionInfo.pname, extensionInfo.settings)
@ -101,7 +109,7 @@ class ExtensionsListFragment : BaseListFragment(), LoaderCallbacks<List<Extensio
override fun onContextItemSelected(item: MenuItem?): Boolean {
val adapterMenuInfo = item!!.menuInfo as AdapterContextMenuInfo
val extensionInfo = (listAdapter as ExtensionsAdapter).getItem(adapterMenuInfo.position)
val extensionInfo = adapter.getItem(adapterMenuInfo.position)
when (item.itemId) {
R.id.settings -> {
openSettings(extensionInfo)
@ -111,7 +119,7 @@ class ExtensionsListFragment : BaseListFragment(), LoaderCallbacks<List<Extensio
}
R.id.revoke -> {
permissionsManager!!.revoke(extensionInfo.pname)
(listAdapter as ExtensionsAdapter).notifyDataSetChanged()
adapter.notifyDataSetChanged()
}
else -> {
return false

View File

@ -34,6 +34,7 @@ import android.view.*
import android.widget.*
import android.widget.AbsListView.MultiChoiceModeListener
import android.widget.CompoundButton.OnCheckedChangeListener
import kotlinx.android.synthetic.main.fragment_content_listview.*
import org.apache.commons.lang3.StringUtils
import org.mariotaku.twidere.Constants
import org.mariotaku.twidere.R
@ -42,24 +43,26 @@ import org.mariotaku.twidere.adapter.ArrayAdapter
import org.mariotaku.twidere.util.ParseUtils
import org.mariotaku.twidere.util.SharedPreferencesWrapper
class HostMappingsListFragment : BaseListFragment(), MultiChoiceModeListener, OnSharedPreferenceChangeListener {
class HostMappingsListFragment : AbsContentListViewFragment<HostMappingsListFragment.HostMappingAdapter>(),
AdapterView.OnItemClickListener, MultiChoiceModeListener, OnSharedPreferenceChangeListener {
private var mAdapter: HostMappingAdapter? = null
private var mHostMapping: SharedPreferencesWrapper? = null
private lateinit var hostMapping: SharedPreferencesWrapper
override fun onActivityCreated(savedInstanceState: Bundle?) {
super.onActivityCreated(savedInstanceState)
setHasOptionsMenu(true)
mHostMapping = SharedPreferencesWrapper.getInstance(activity,
hostMapping = SharedPreferencesWrapper.getInstance(activity,
Constants.HOST_MAPPING_PREFERENCES_NAME, Context.MODE_PRIVATE)
mHostMapping!!.registerOnSharedPreferenceChangeListener(this)
mAdapter = HostMappingAdapter(activity)
listAdapter = mAdapter
hostMapping.registerOnSharedPreferenceChangeListener(this)
listView.choiceMode = ListView.CHOICE_MODE_MULTIPLE_MODAL
listView.setMultiChoiceModeListener(this)
reloadHostMappings()
}
override fun onCreateAdapter(context: Context): HostMappingAdapter {
return HostMappingAdapter(activity)
}
override fun onCreateActionMode(mode: ActionMode, menu: Menu): Boolean {
mode.menuInflater.inflate(R.menu.action_multi_select_items, menu)
return true
@ -73,15 +76,12 @@ class HostMappingsListFragment : BaseListFragment(), MultiChoiceModeListener, On
override fun onActionItemClicked(mode: ActionMode, item: MenuItem): Boolean {
when (item.itemId) {
R.id.delete -> {
val editor = mHostMapping!!.edit()
val editor = hostMapping.edit()
val array = listView!!.checkedItemPositions ?: return false
var i = 0
val size = array.size()
while (i < size) {
for (i in 0 until array.size()) {
if (array.valueAt(i)) {
editor.remove(mAdapter!!.getItem(i))
editor.remove(adapter.getItem(i).first)
}
i++
}
editor.apply()
reloadHostMappings()
@ -102,9 +102,8 @@ class HostMappingsListFragment : BaseListFragment(), MultiChoiceModeListener, On
inflater!!.inflate(R.menu.menu_host_mapping, menu)
}
override fun onListItemClick(l: ListView?, v: View?, position: Int, id: Long) {
val host = mAdapter!!.getItem(position)
val address = mAdapter!!.getAddress(host)
override fun onItemClick(parent: AdapterView<*>?, view: View?, position: Int, id: Long) {
val (host, address) = adapter.getItem(position)
val args = Bundle()
args.putString(EXTRA_HOST, host)
args.putString(EXTRA_ADDRESS, address)
@ -135,8 +134,16 @@ class HostMappingsListFragment : BaseListFragment(), MultiChoiceModeListener, On
}
fun reloadHostMappings() {
if (mAdapter == null) return
mAdapter!!.reload()
adapter.clear()
adapter.addAll(hostMapping.all.mapNotNull { entry ->
val value = entry.value?.toString() ?: return@mapNotNull null
return@mapNotNull Pair(entry.key, value)
})
if (adapter.isEmpty) {
showEmpty(R.drawable.ic_info_info_generic, getString(R.string.add_host_mapping))
} else {
showContent()
}
}
private fun updateTitle(mode: ActionMode?) {
@ -235,38 +242,22 @@ class HostMappingsListFragment : BaseListFragment(), MultiChoiceModeListener, On
}
}
internal class HostMappingAdapter(context: Context) : ArrayAdapter<String>(context, android.R.layout.simple_list_item_activated_2) {
private val mHostMapping: SharedPreferences
init {
mHostMapping = context.getSharedPreferences(Constants.HOST_MAPPING_PREFERENCES_NAME, Context.MODE_PRIVATE)
}
class HostMappingAdapter(context: Context) : ArrayAdapter<Pair<String, String>>(context,
android.R.layout.simple_list_item_activated_2) {
override fun getView(position: Int, convertView: View?, parent: ViewGroup): View {
val view = super.getView(position, convertView, parent)
val text1 = view.findViewById(android.R.id.text1) as TextView
val text2 = view.findViewById(android.R.id.text2) as TextView
val key = getItem(position)
val (key, value) = getItem(position)
text1.text = key
val value = getAddress(key)
if (StringUtils.equals(key, value)) {
if (key == value) {
text2.setText(R.string.excluded)
} else {
text2.text = value
}
return view
}
fun reload() {
clear()
val all = mHostMapping.all
addAll(all.keys)
}
fun getAddress(key: String): String {
return mHostMapping.getString(key, null)
}
}
companion object {

View File

@ -72,8 +72,6 @@ interface GeneralComponent {
fun inject(obj: TwidereDataProvider)
fun inject(obj: BaseListFragment)
fun inject(obj: BaseActivity)
fun inject(obj: BaseRecyclerViewAdapter<RecyclerView.ViewHolder>)

View File

@ -25,7 +25,7 @@
android:layout_height="match_parent">
<FrameLayout
android:layout_width="240dp"
android:layout_width="@dimen/settings_panel_width_entries"
android:layout_height="match_parent"
android:layout_gravity="start">
@ -43,8 +43,8 @@
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="end"
android:layout_marginLeft="@dimen/element_size_normal"
android:layout_marginStart="@dimen/element_size_normal"
android:layout_marginLeft="@dimen/settings_panel_margin_start_details"
android:layout_marginStart="@dimen/settings_panel_margin_start_details"
android:clickable="true"
tools:background="?android:colorBackground"/>
</android.support.v4.widget.SlidingPaneLayout>

View File

@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<dimen name="settings_panel_margin_start_details">@dimen/settings_panel_width_entries</dimen>
</resources>

View File

@ -3,7 +3,6 @@
<integer name="nyan_star_rows">15</integer>
<integer name="nyan_star_cols">19</integer>
<integer name="default_text_size">17</integer>
<integer name="unread_count_text_size">12</integer>
<integer name="default_multi_column_list_count">2</integer>
<integer name="theme_preview_pane_space_weight">2</integer>

View File

@ -95,4 +95,7 @@
<dimen name="element_size_quick_search_bar_item_icon">40dp</dimen>
<dimen name="settings_panel_width_entries">240dp</dimen>
<dimen name="settings_panel_margin_start_details">@dimen/element_size_normal</dimen>
</resources>