improved tab type

This commit is contained in:
Mariotaku Lee 2016-12-16 08:13:05 +08:00
parent d765ef2185
commit 911498768f
8 changed files with 27 additions and 34 deletions

View File

@ -1,10 +1,9 @@
package org.mariotaku.twidere.util package org.mariotaku.twidere.util
import org.junit.Assert
import org.junit.Test import org.junit.Test
import junit.framework.Assert.assertEquals
import junit.framework.Assert.assertNull
/** /**
* Created by mariotaku on 16/2/9. * Created by mariotaku on 16/2/9.
@ -14,22 +13,22 @@ class UriUtilsTest {
@Test @Test
@Throws(Exception::class) @Throws(Exception::class)
fun testGetAuthority() { fun testGetAuthority() {
assertEquals("www.google.com", UriUtils.getAuthority("http://www.google.com/")) Assert.assertEquals("www.google.com", UriUtils.getAuthority("http://www.google.com/"))
assertEquals("twitter.com", UriUtils.getAuthority("https://twitter.com")) Assert.assertEquals("twitter.com", UriUtils.getAuthority("https://twitter.com"))
assertNull(UriUtils.getAuthority("www.google.com/")) Assert.assertNull(UriUtils.getAuthority("www.google.com/"))
} }
@Test @Test
@Throws(Exception::class) @Throws(Exception::class)
fun testGetPath() { fun testGetPath() {
assertEquals("/", UriUtils.getPath("http://www.example.com/")) Assert.assertEquals("/", UriUtils.getPath("http://www.example.com/"))
assertEquals("", UriUtils.getPath("http://www.example.com")) Assert.assertEquals("", UriUtils.getPath("http://www.example.com"))
assertEquals("/test/path", UriUtils.getPath("https://example.com/test/path")) Assert.assertEquals("/test/path", UriUtils.getPath("https://example.com/test/path"))
assertEquals("/test/path", UriUtils.getPath("https://example.com/test/path?with=query")) Assert.assertEquals("/test/path", UriUtils.getPath("https://example.com/test/path?with=query"))
assertEquals("/test/path/", UriUtils.getPath("https://example.com/test/path/?with=query")) Assert.assertEquals("/test/path/", UriUtils.getPath("https://example.com/test/path/?with=query"))
assertEquals("/test/path", UriUtils.getPath("https://example.com/test/path?with=query#fragment")) Assert.assertEquals("/test/path", UriUtils.getPath("https://example.com/test/path?with=query#fragment"))
assertEquals("/test/path/", UriUtils.getPath("https://example.com/test/path/?with=query#fragment")) Assert.assertEquals("/test/path/", UriUtils.getPath("https://example.com/test/path/?with=query#fragment"))
assertEquals("/test/path", UriUtils.getPath("https://example.com/test/path#fragment")) Assert.assertEquals("/test/path", UriUtils.getPath("https://example.com/test/path#fragment"))
assertEquals("/test/path/", UriUtils.getPath("https://example.com/test/path/#fragment")) Assert.assertEquals("/test/path/", UriUtils.getPath("https://example.com/test/path/#fragment"))
} }
} }

View File

@ -93,7 +93,7 @@ public class CustomTabUtils implements Constants {
List<SupportTabSpec> specs = new ArrayList<>(); List<SupportTabSpec> specs = new ArrayList<>();
for (Tab tab : getTabs(context)) { for (Tab tab : getTabs(context)) {
@CustomTabType @CustomTabType
final String type = tab.getType(); final String type = Tab.getTypeAlias(tab.getType());
final int position = tab.getPosition(); final int position = tab.getPosition();
final String iconType = tab.getIcon(); final String iconType = tab.getIcon();
final String name = tab.getName(); final String name = tab.getName();
@ -153,11 +153,6 @@ public class CustomTabUtils implements Constants {
return null; return null;
} }
public static TabConfiguration getTabConfiguration(final String tabType) {
if (tabType == null) return null;
return TabConfiguration.ofType(Tab.getTypeAlias(tabType));
}
public static Drawable getTabIconDrawable(final Context context, final DrawableHolder icon) { public static Drawable getTabIconDrawable(final Context context, final DrawableHolder icon) {
if (icon == null) { if (icon == null) {
return ContextCompat.getDrawable(context, R.drawable.ic_action_list); return ContextCompat.getDrawable(context, R.drawable.ic_action_list);

View File

@ -158,7 +158,7 @@ class ParcelableActivitiesAdapter(
} }
private fun bindTitleSummaryViewHolder(holder: ActivityTitleSummaryViewHolder, position: Int) { private fun bindTitleSummaryViewHolder(holder: ActivityTitleSummaryViewHolder, position: Int) {
holder.displayActivity(getActivity(position)!!, byFriends) holder.displayActivity(getActivity(position)!!)
} }
fun getData(): List<ParcelableActivity>? { fun getData(): List<ParcelableActivity>? {

View File

@ -469,7 +469,7 @@ class CustomTabsFragment : BaseSupportFragment(), LoaderCallbacks<Cursor?>, Mult
super.bindView(view, context, cursor) super.bindView(view, context, cursor)
val holder = view.tag as TwoLineWithIconViewHolder val holder = view.tag as TwoLineWithIconViewHolder
val indices = indices!! val indices = indices!!
val type = cursor.getString(indices.type) val type = Tab.getTypeAlias(cursor.getString(indices.type))
val name = cursor.getString(indices.name) val name = cursor.getString(indices.name)
val iconKey = cursor.getString(indices.icon) val iconKey = cursor.getString(indices.icon)
if (CustomTabUtils.isTabTypeValid(type)) { if (CustomTabUtils.isTabTypeValid(type)) {

View File

@ -72,25 +72,25 @@ class SavedSearchesListFragment : AbsContentListViewFragment<SavedSearchesAdapte
get() = arguments.getParcelable<UserKey>(EXTRA_ACCOUNT_KEY) get() = arguments.getParcelable<UserKey>(EXTRA_ACCOUNT_KEY)
override fun onItemLongClick(view: AdapterView<*>, child: View, position: Int, id: Long): Boolean { override fun onItemLongClick(view: AdapterView<*>, child: View, position: Int, id: Long): Boolean {
val item = adapter!!.findItem(id) ?: return false val item = adapter.findItem(id) ?: return false
DestroySavedSearchDialogFragment.show(fragmentManager, accountKey, item.id, item.name) DestroySavedSearchDialogFragment.show(fragmentManager, accountKey, item.id, item.name)
return true return true
} }
override fun onItemClick(view: AdapterView<*>, child: View, position: Int, id: Long) { override fun onItemClick(view: AdapterView<*>, child: View, position: Int, id: Long) {
val item = adapter!!.findItem(id) ?: return val item = adapter.findItem(id) ?: return
openTweetSearch(activity, accountKey, item.query) openTweetSearch(activity, accountKey, item.query)
} }
override fun onLoaderReset(loader: Loader<ResponseList<SavedSearch>?>) { override fun onLoaderReset(loader: Loader<ResponseList<SavedSearch>?>) {
adapter!!.setData(null) adapter.setData(null)
} }
override fun onLoadFinished(loader: Loader<ResponseList<SavedSearch>?>, data: ResponseList<SavedSearch>?) { override fun onLoadFinished(loader: Loader<ResponseList<SavedSearch>?>, data: ResponseList<SavedSearch>?) {
if (data != null) { if (data != null) {
Collections.sort(data, POSITION_COMPARATOR) Collections.sort(data, POSITION_COMPARATOR)
} }
adapter!!.setData(data) adapter.setData(data)
showContent() showContent()
refreshing = false refreshing = false
} }
@ -109,7 +109,7 @@ class SavedSearchesListFragment : AbsContentListViewFragment<SavedSearchesAdapte
@Subscribe @Subscribe
fun onSavedSearchDestroyed(event: SavedSearchDestroyedEvent) { fun onSavedSearchDestroyed(event: SavedSearchDestroyedEvent) {
val adapter = adapter val adapter = adapter
adapter!!.removeItem(event.accountKey, event.searchId) adapter.removeItem(event.accountKey, event.searchId)
} }
companion object { companion object {

View File

@ -33,15 +33,14 @@ object HttpClientFactory {
fun initOkHttpClient(context: Context, prefs: SharedPreferencesWrapper, fun initOkHttpClient(context: Context, prefs: SharedPreferencesWrapper,
builder: OkHttpClient.Builder, dns: Dns, builder: OkHttpClient.Builder, dns: Dns,
connectionPool: ConnectionPool) { connectionPool: ConnectionPool) {
updateHttpClientConfiguration(context, builder, prefs, dns, connectionPool) updateHttpClientConfiguration(builder, prefs, dns, connectionPool)
DebugModeUtils.initForOkHttpClient(builder) DebugModeUtils.initForOkHttpClient(builder)
} }
@SuppressLint("SSLCertificateSocketFactoryGetInsecure") @SuppressLint("SSLCertificateSocketFactoryGetInsecure")
fun updateHttpClientConfiguration(context: Context, fun updateHttpClientConfiguration(builder: OkHttpClient.Builder,
builder: OkHttpClient.Builder, prefs: SharedPreferencesWrapper,
prefs: SharedPreferencesWrapper, dns: Dns, dns: Dns, connectionPool: ConnectionPool) {
connectionPool: ConnectionPool) {
val enableProxy = prefs.getBoolean(KEY_ENABLE_PROXY, false) val enableProxy = prefs.getBoolean(KEY_ENABLE_PROXY, false)
builder.connectTimeout(prefs.getInt(KEY_CONNECTION_TIMEOUT, 10).toLong(), TimeUnit.SECONDS) builder.connectTimeout(prefs.getInt(KEY_CONNECTION_TIMEOUT, 10).toLong(), TimeUnit.SECONDS)
builder.connectionPool(connectionPool) builder.connectionPool(connectionPool)

View File

@ -207,7 +207,7 @@ class ApplicationModule(private val application: Application) {
@Provides @Provides
@Singleton @Singleton
fun twidereValidator(preferences: SharedPreferencesWrapper): TwidereValidator { fun twidereValidator(): TwidereValidator {
return TwidereValidator() return TwidereValidator()
} }

View File

@ -82,7 +82,7 @@ class ActivityTitleSummaryViewHolder(private val adapter: ParcelableActivitiesAd
timeView.setShowAbsoluteTime(adapter.isShowAbsoluteTime) timeView.setShowAbsoluteTime(adapter.isShowAbsoluteTime)
} }
fun displayActivity(activity: ParcelableActivity, byFriends: Boolean) { fun displayActivity(activity: ParcelableActivity) {
val context = adapter.context val context = adapter.context
val sources = ParcelableActivityUtils.getAfterFilteredSources(activity) val sources = ParcelableActivityUtils.getAfterFilteredSources(activity)
val message = ActivityTitleSummaryMessage.get(context, val message = ActivityTitleSummaryMessage.get(context,