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
import org.junit.Assert
import org.junit.Test
import junit.framework.Assert.assertEquals
import junit.framework.Assert.assertNull
/**
* Created by mariotaku on 16/2/9.
@ -14,22 +13,22 @@ class UriUtilsTest {
@Test
@Throws(Exception::class)
fun testGetAuthority() {
assertEquals("www.google.com", UriUtils.getAuthority("http://www.google.com/"))
assertEquals("twitter.com", UriUtils.getAuthority("https://twitter.com"))
assertNull(UriUtils.getAuthority("www.google.com/"))
Assert.assertEquals("www.google.com", UriUtils.getAuthority("http://www.google.com/"))
Assert.assertEquals("twitter.com", UriUtils.getAuthority("https://twitter.com"))
Assert.assertNull(UriUtils.getAuthority("www.google.com/"))
}
@Test
@Throws(Exception::class)
fun testGetPath() {
assertEquals("/", UriUtils.getPath("http://www.example.com/"))
assertEquals("", UriUtils.getPath("http://www.example.com"))
assertEquals("/test/path", UriUtils.getPath("https://example.com/test/path"))
assertEquals("/test/path", UriUtils.getPath("https://example.com/test/path?with=query"))
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"))
assertEquals("/test/path/", UriUtils.getPath("https://example.com/test/path/?with=query#fragment"))
assertEquals("/test/path", UriUtils.getPath("https://example.com/test/path#fragment"))
assertEquals("/test/path/", UriUtils.getPath("https://example.com/test/path/#fragment"))
Assert.assertEquals("/", UriUtils.getPath("http://www.example.com/"))
Assert.assertEquals("", UriUtils.getPath("http://www.example.com"))
Assert.assertEquals("/test/path", UriUtils.getPath("https://example.com/test/path"))
Assert.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"))
Assert.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"))
Assert.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<>();
for (Tab tab : getTabs(context)) {
@CustomTabType
final String type = tab.getType();
final String type = Tab.getTypeAlias(tab.getType());
final int position = tab.getPosition();
final String iconType = tab.getIcon();
final String name = tab.getName();
@ -153,11 +153,6 @@ public class CustomTabUtils implements Constants {
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) {
if (icon == null) {
return ContextCompat.getDrawable(context, R.drawable.ic_action_list);

View File

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

View File

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

View File

@ -72,25 +72,25 @@ class SavedSearchesListFragment : AbsContentListViewFragment<SavedSearchesAdapte
get() = arguments.getParcelable<UserKey>(EXTRA_ACCOUNT_KEY)
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)
return true
}
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)
}
override fun onLoaderReset(loader: Loader<ResponseList<SavedSearch>?>) {
adapter!!.setData(null)
adapter.setData(null)
}
override fun onLoadFinished(loader: Loader<ResponseList<SavedSearch>?>, data: ResponseList<SavedSearch>?) {
if (data != null) {
Collections.sort(data, POSITION_COMPARATOR)
}
adapter!!.setData(data)
adapter.setData(data)
showContent()
refreshing = false
}
@ -109,7 +109,7 @@ class SavedSearchesListFragment : AbsContentListViewFragment<SavedSearchesAdapte
@Subscribe
fun onSavedSearchDestroyed(event: SavedSearchDestroyedEvent) {
val adapter = adapter
adapter!!.removeItem(event.accountKey, event.searchId)
adapter.removeItem(event.accountKey, event.searchId)
}
companion object {

View File

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

View File

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

View File

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