diff --git a/app/src/androidTest/java/com/h/pixeldroid/MockedServerTest.kt b/app/src/androidTest/java/com/h/pixeldroid/MockedServerTest.kt index 4eb861d1..c4b9e32b 100644 --- a/app/src/androidTest/java/com/h/pixeldroid/MockedServerTest.kt +++ b/app/src/androidTest/java/com/h/pixeldroid/MockedServerTest.kt @@ -245,6 +245,38 @@ class MockedServerTest { onView(withId(R.id.list)).check(matches(isDisplayed())) } + @Test + fun swipingLeftStopsAtPublicTimeline() { + activityScenario.onActivity { + a -> a.findViewById(R.id.tabs).getTabAt(0)?.select() + } + + Thread.sleep(1000) + onView(withId(R.id.main_activity_main_linear_layout)) + .perform(ViewActions.swipeLeft()) // notifications + .perform(ViewActions.swipeLeft()) // camera + .perform(ViewActions.swipeLeft()) // search + .perform(ViewActions.swipeLeft()) // homepage + .perform(ViewActions.swipeLeft()) // should stop at homepage + onView(withId(R.id.list)).check(matches(isDisplayed())) + } + + @Test + fun swipingPublicTimelineWorks() { + activityScenario.onActivity { + a -> a.findViewById(R.id.tabs).getTabAt(4)?.select() + } // go to the last tab + + Thread.sleep(1000) + onView(withId(R.id.main_activity_main_linear_layout)) + .perform(ViewActions.swipeUp()) // notifications + .perform(ViewActions.swipeUp()) // camera + .perform(ViewActions.swipeUp()) // search + .perform(ViewActions.swipeUp()) // homepage + .perform(ViewActions.swipeUp()) // should stop at homepage + onView(withId(R.id.list)).check(matches(isDisplayed())) + } + @Test fun clickingTabOnAlbumShowsNextPhoto() { ActivityScenario.launch(MainActivity::class.java).onActivity { diff --git a/app/src/androidTest/java/com/h/pixeldroid/testUtility/MockServer.kt b/app/src/androidTest/java/com/h/pixeldroid/testUtility/MockServer.kt index dc575f18..fa67b91b 100644 --- a/app/src/androidTest/java/com/h/pixeldroid/testUtility/MockServer.kt +++ b/app/src/androidTest/java/com/h/pixeldroid/testUtility/MockServer.kt @@ -202,6 +202,12 @@ class MockServer { "application/json; charset=utf-8" ).setResponseCode(200).setBody(feedJson) } + request.path?.startsWith("/api/v1/timelines/public") == true -> { + return MockResponse().addHeader( + "Content-Type", + "application/json; charset=utf-8" + ).setResponseCode(200).setBody(feedJson) + } request.path?.startsWith("/api/v1/accounts/0/statuses") == true -> { return MockResponse().setHttp2ErrorCode(401) } diff --git a/app/src/main/java/com/h/pixeldroid/MainActivity.kt b/app/src/main/java/com/h/pixeldroid/MainActivity.kt index fc73d126..1d45cdc3 100644 --- a/app/src/main/java/com/h/pixeldroid/MainActivity.kt +++ b/app/src/main/java/com/h/pixeldroid/MainActivity.kt @@ -24,6 +24,7 @@ import com.h.pixeldroid.fragments.NewPostFragment import com.h.pixeldroid.fragments.SearchDiscoverFragment import com.h.pixeldroid.fragments.feeds.PostsFeedFragment import com.h.pixeldroid.fragments.feeds.NotificationsFragment +import com.h.pixeldroid.fragments.feeds.PublicTimelineFragment import com.h.pixeldroid.objects.Account import com.h.pixeldroid.utils.ImageConverter import retrofit2.Call @@ -59,7 +60,7 @@ class MainActivity : AppCompatActivity(), NavigationView.OnNavigationItemSelecte searchDiscoverFragment, NewPostFragment(), NotificationsFragment(), - Fragment() + PublicTimelineFragment() ) setupTabs(tabs) @@ -121,7 +122,7 @@ class MainActivity : AppCompatActivity(), NavigationView.OnNavigationItemSelecte 1 -> tab.icon = getDrawable(R.drawable.ic_search_white_24dp) 2 -> tab.icon = getDrawable(R.drawable.ic_photo_camera_white_24dp) 3 -> tab.icon = getDrawable(R.drawable.ic_heart) - 4 -> tab.icon = getDrawable(R.drawable.ic_person_white_24dp) + 4 -> tab.icon = getDrawable(R.drawable.ic_filter_black_24dp) } }.attach() } diff --git a/app/src/main/java/com/h/pixeldroid/fragments/feeds/FeedFragment.kt b/app/src/main/java/com/h/pixeldroid/fragments/feeds/FeedFragment.kt index fbe75e09..ead3be45 100644 --- a/app/src/main/java/com/h/pixeldroid/fragments/feeds/FeedFragment.kt +++ b/app/src/main/java/com/h/pixeldroid/fragments/feeds/FeedFragment.kt @@ -104,7 +104,7 @@ open class FeedFragment: Fragment( //do nothing here, it is expected to pull to refresh to load newer notifications } - private fun enqueueCall(call: Call>, callback: LoadCallback){ + protected open fun enqueueCall(call: Call>, callback: LoadCallback){ call.enqueue(object : Callback> { override fun onResponse(call: Call>, response: Response>) { diff --git a/app/src/main/java/com/h/pixeldroid/fragments/feeds/PostsFeedFragment.kt b/app/src/main/java/com/h/pixeldroid/fragments/feeds/PostsFeedFragment.kt index 3ac8e642..a6ac8488 100644 --- a/app/src/main/java/com/h/pixeldroid/fragments/feeds/PostsFeedFragment.kt +++ b/app/src/main/java/com/h/pixeldroid/fragments/feeds/PostsFeedFragment.kt @@ -24,7 +24,6 @@ import com.h.pixeldroid.R import com.h.pixeldroid.objects.Status import retrofit2.Call - open class PostsFeedFragment : FeedFragment() { lateinit var picRequest: RequestBuilder diff --git a/app/src/main/java/com/h/pixeldroid/fragments/feeds/PublicTimelineFragment.kt b/app/src/main/java/com/h/pixeldroid/fragments/feeds/PublicTimelineFragment.kt new file mode 100644 index 00000000..936ee8f1 --- /dev/null +++ b/app/src/main/java/com/h/pixeldroid/fragments/feeds/PublicTimelineFragment.kt @@ -0,0 +1,45 @@ +package com.h.pixeldroid.fragments.feeds + +import androidx.lifecycle.LiveData +import androidx.paging.LivePagedListBuilder +import androidx.paging.PagedList +import com.h.pixeldroid.objects.Status +import retrofit2.Call + +class PublicTimelineFragment: PostsFeedFragment() { + + inner class SearchFeedDataSource( + ) : FeedDataSource(null, null){ + + override fun newSource(): FeedDataSource { + return SearchFeedDataSource() + } + + private fun makeInitialCall(requestedLoadSize: Int): Call> { + return pixelfedAPI.timelinePublic(limit="$requestedLoadSize") + } + private fun makeAfterCall(requestedLoadSize: Int, key: String): Call> { + return pixelfedAPI.timelinePublic( max_id=key, limit="$requestedLoadSize") + } + + override fun loadInitial( + params: LoadInitialParams, + callback: LoadInitialCallback + ) { + enqueueCall(makeInitialCall(params.requestedLoadSize), callback) + } + + //This is called to when we get to the bottom of the loaded content, so we want statuses + //older than the given key (params.key) + override fun loadAfter(params: LoadParams, callback: LoadCallback) { + enqueueCall(makeAfterCall(params.requestedLoadSize, params.key), callback) + } + } + + override fun makeContent(): LiveData> { + val config: PagedList.Config = PagedList.Config.Builder().setPageSize(10).build() + factory = FeedFragment() + .FeedDataSourceFactory(SearchFeedDataSource()) + return LivePagedListBuilder(factory, config).build() + } +} \ No newline at end of file diff --git a/app/src/main/java/com/h/pixeldroid/fragments/feeds/search/SearchAccountFragment.kt b/app/src/main/java/com/h/pixeldroid/fragments/feeds/search/SearchAccountFragment.kt index 3bb11ec4..c5f2ec20 100644 --- a/app/src/main/java/com/h/pixeldroid/fragments/feeds/search/SearchAccountFragment.kt +++ b/app/src/main/java/com/h/pixeldroid/fragments/feeds/search/SearchAccountFragment.kt @@ -55,15 +55,15 @@ class SearchAccountFragment: AccountListFragment(){ params: LoadInitialParams, callback: LoadInitialCallback ) { - enqueueCall(makeInitialCall(params.requestedLoadSize), callback) + searchEnqueueCall(makeInitialCall(params.requestedLoadSize), callback) } //This is called to when we get to the bottom of the loaded content, so we want statuses //older than the given key (params.key) override fun loadAfter(params: LoadParams, callback: LoadCallback) { - enqueueCall(makeAfterCall(params.requestedLoadSize, params.key), callback) + searchEnqueueCall(makeAfterCall(params.requestedLoadSize, params.key), callback) } - private fun enqueueCall(call: Call, callback: LoadCallback){ + private fun searchEnqueueCall(call: Call, callback: LoadCallback) { call.enqueue(object : Callback { override fun onResponse(call: Call, response: Response) { diff --git a/app/src/main/java/com/h/pixeldroid/fragments/feeds/search/SearchHashtagFragment.kt b/app/src/main/java/com/h/pixeldroid/fragments/feeds/search/SearchHashtagFragment.kt index d2f887e1..37f9e823 100644 --- a/app/src/main/java/com/h/pixeldroid/fragments/feeds/search/SearchHashtagFragment.kt +++ b/app/src/main/java/com/h/pixeldroid/fragments/feeds/search/SearchHashtagFragment.kt @@ -92,16 +92,16 @@ class SearchHashtagFragment: FeedFragment, callback: LoadInitialCallback ) { - enqueueCall(makeInitialCall(params.requestedLoadSize), callback) + searchEnqueueCall(makeInitialCall(params.requestedLoadSize), callback) } //This is called to when we get to the bottom of the loaded content, so we want statuses //older than the given key (params.key) override fun loadAfter(params: LoadParams, callback: LoadCallback) { - enqueueCall(makeAfterCall(params.requestedLoadSize, params.key), callback) + searchEnqueueCall(makeAfterCall(params.requestedLoadSize, params.key), callback) } - private fun enqueueCall(call: Call, callback: LoadCallback){ + private fun searchEnqueueCall(call: Call, callback: LoadCallback){ call.enqueue(object : Callback { override fun onResponse(call: Call, response: Response) { diff --git a/app/src/main/java/com/h/pixeldroid/fragments/feeds/search/SearchPostsFragment.kt b/app/src/main/java/com/h/pixeldroid/fragments/feeds/search/SearchPostsFragment.kt index 30b4ff30..436ef1e8 100644 --- a/app/src/main/java/com/h/pixeldroid/fragments/feeds/search/SearchPostsFragment.kt +++ b/app/src/main/java/com/h/pixeldroid/fragments/feeds/search/SearchPostsFragment.kt @@ -57,16 +57,16 @@ class SearchPostsFragment: PostsFeedFragment(){ params: LoadInitialParams, callback: LoadInitialCallback ) { - enqueueCall(makeInitialCall(params.requestedLoadSize), callback) + searchEnqueueCall(makeInitialCall(params.requestedLoadSize), callback) } //This is called to when we get to the bottom of the loaded content, so we want statuses //older than the given key (params.key) override fun loadAfter(params: LoadParams, callback: LoadCallback) { - enqueueCall(makeAfterCall(params.requestedLoadSize, params.key), callback) + searchEnqueueCall(makeAfterCall(params.requestedLoadSize, params.key), callback) } - private fun enqueueCall(call: Call, callback: LoadCallback){ + private fun searchEnqueueCall(call: Call, callback: LoadCallback){ call.enqueue(object : Callback { override fun onResponse(call: Call, response: Response) { diff --git a/app/src/main/java/com/h/pixeldroid/objects/Status.kt b/app/src/main/java/com/h/pixeldroid/objects/Status.kt index 2fa29d2d..d20dc3ef 100644 --- a/app/src/main/java/com/h/pixeldroid/objects/Status.kt +++ b/app/src/main/java/com/h/pixeldroid/objects/Status.kt @@ -132,7 +132,12 @@ data class Status( } private fun ISO8601toDate(dateString : String, textView: TextView, isActivity: Boolean) { - val format = SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.'000000Z'") + var format = SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.hhmmss'Z'") + if(dateString.matches("[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}.[0-9]{6}Z".toRegex())) { + format = SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.hhmmss'Z'") + } else if(dateString.matches("[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}+[0-9]{2}:[0-9]{2}".toRegex())) { + format = SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss+hh:mm") + } val now = Date().time try { diff --git a/app/src/main/res/drawable/ic_filter_black_24dp.xml b/app/src/main/res/drawable/ic_filter_black_24dp.xml new file mode 100644 index 00000000..e21abb34 --- /dev/null +++ b/app/src/main/res/drawable/ic_filter_black_24dp.xml @@ -0,0 +1,9 @@ + + +