2020-03-21 18:12:00 +01:00
|
|
|
package com.h.pixeldroid.fragments.feeds
|
|
|
|
|
2020-04-02 19:57:07 +02:00
|
|
|
import android.content.Context
|
|
|
|
import android.content.Intent
|
|
|
|
import android.graphics.drawable.Drawable
|
2020-03-21 18:12:00 +01:00
|
|
|
import android.os.Bundle
|
2020-07-26 20:56:01 +02:00
|
|
|
import android.util.Log
|
2020-03-21 18:12:00 +01:00
|
|
|
import android.view.LayoutInflater
|
|
|
|
import android.view.View
|
|
|
|
import android.view.ViewGroup
|
2020-04-02 19:57:07 +02:00
|
|
|
import android.widget.ImageView
|
|
|
|
import android.widget.TextView
|
2020-04-03 09:11:57 +02:00
|
|
|
import androidx.lifecycle.LiveData
|
2020-04-02 19:57:07 +02:00
|
|
|
import androidx.lifecycle.Observer
|
|
|
|
import androidx.paging.LivePagedListBuilder
|
|
|
|
import androidx.paging.PagedList
|
|
|
|
import androidx.recyclerview.widget.RecyclerView
|
|
|
|
import com.bumptech.glide.Glide
|
|
|
|
import com.bumptech.glide.ListPreloader
|
|
|
|
import com.bumptech.glide.RequestBuilder
|
|
|
|
import com.bumptech.glide.integration.recyclerview.RecyclerViewPreloader
|
|
|
|
import com.bumptech.glide.request.RequestOptions
|
|
|
|
import com.bumptech.glide.util.ViewPreloadSizeProvider
|
|
|
|
import com.h.pixeldroid.PostActivity
|
2020-04-09 22:36:59 +02:00
|
|
|
import com.h.pixeldroid.ProfileActivity
|
2020-03-21 18:12:00 +01:00
|
|
|
import com.h.pixeldroid.R
|
2020-04-09 22:36:59 +02:00
|
|
|
import com.h.pixeldroid.objects.Account
|
2020-03-21 18:12:00 +01:00
|
|
|
import com.h.pixeldroid.objects.Notification
|
2020-04-02 19:57:07 +02:00
|
|
|
import com.h.pixeldroid.objects.Status
|
2020-04-23 17:48:45 +02:00
|
|
|
import com.h.pixeldroid.utils.HtmlUtils.Companion.parseHTMLText
|
2020-09-10 20:20:23 +02:00
|
|
|
import com.h.pixeldroid.utils.Utils.Companion.setTextViewFromISO8601
|
2020-04-02 19:57:07 +02:00
|
|
|
import kotlinx.android.synthetic.main.fragment_notifications.view.*
|
2020-04-03 09:11:57 +02:00
|
|
|
import retrofit2.Call
|
2020-07-26 20:56:01 +02:00
|
|
|
import retrofit2.Callback
|
|
|
|
import retrofit2.Response
|
2020-03-21 18:12:00 +01:00
|
|
|
|
2020-04-01 19:38:21 +02:00
|
|
|
|
2020-03-21 18:12:00 +01:00
|
|
|
/**
|
|
|
|
* A fragment representing a list of Items.
|
|
|
|
*/
|
2020-07-26 20:56:01 +02:00
|
|
|
class NotificationsFragment : FeedFragment() {
|
2020-03-21 18:12:00 +01:00
|
|
|
|
2020-04-02 19:57:07 +02:00
|
|
|
lateinit var profilePicRequest: RequestBuilder<Drawable>
|
2020-07-26 20:56:01 +02:00
|
|
|
protected lateinit var adapter : FeedsRecyclerViewAdapter<Notification, NotificationsRecyclerViewAdapter.ViewHolder>
|
|
|
|
lateinit var factory: FeedDataSourceFactory<String, Notification>
|
|
|
|
|
|
|
|
|
2020-03-21 18:12:00 +01:00
|
|
|
|
|
|
|
override fun onCreateView(
|
|
|
|
inflater: LayoutInflater, container: ViewGroup?,
|
|
|
|
savedInstanceState: Bundle?
|
|
|
|
): View? {
|
|
|
|
|
2020-04-02 19:57:07 +02:00
|
|
|
val view = super.onCreateView(inflater, container, savedInstanceState)
|
|
|
|
|
2020-04-02 22:16:03 +02:00
|
|
|
//RequestBuilder that is re-used for every image
|
2020-04-02 19:57:07 +02:00
|
|
|
profilePicRequest = Glide.with(this)
|
|
|
|
.asDrawable().apply(RequestOptions().circleCrop())
|
|
|
|
.placeholder(R.drawable.ic_default_user)
|
2020-03-21 18:12:00 +01:00
|
|
|
|
2020-04-01 19:38:21 +02:00
|
|
|
|
2020-03-21 18:12:00 +01:00
|
|
|
adapter = NotificationsRecyclerViewAdapter()
|
|
|
|
list.adapter = adapter
|
|
|
|
|
2020-04-02 19:57:07 +02:00
|
|
|
|
2020-04-02 22:16:03 +02:00
|
|
|
//Make Glide be aware of the recyclerview and pre-load images
|
2020-04-02 19:57:07 +02:00
|
|
|
val sizeProvider: ListPreloader.PreloadSizeProvider<Notification> = ViewPreloadSizeProvider()
|
|
|
|
val preloader: RecyclerViewPreloader<Notification> = RecyclerViewPreloader(
|
2020-04-30 17:54:21 +02:00
|
|
|
Glide.with(this), adapter as NotificationsFragment.NotificationsRecyclerViewAdapter, sizeProvider, 4
|
2020-04-02 19:57:07 +02:00
|
|
|
)
|
|
|
|
list.addOnScrollListener(preloader)
|
|
|
|
|
2020-03-21 18:12:00 +01:00
|
|
|
return view
|
|
|
|
}
|
|
|
|
|
Commenting & seeing comments on a post ( issues: #37 #77 ) (#87)
Comment and like buttons added + a few UI tweaks
* WIP posts
* WIP posts
* trying to add images
* trying to add images
* Got posts working and linked them to the profile
* added tests for Post
* layout changes
* moved a test file
* refactoring
* refactoring
* removed wrong annotation in unit test
* removed an import that was breaking the build
* removed tests that broke from merge, will override with master
* added UI test for the post activity
* WIP posts
* WIP posts
* trying to add images
* trying to add images
* Got posts working and linked them to the profile
* layout changes
* refactoring
* refactoring
* WIP posts
* WIP posts
* trying to add images
* trying to add images
* Got posts working and linked them to the profile
* added tests for Post
* layout changes
* moved a test file
* refactoring
* refactoring
* removed wrong annotation in unit test
* removed an import that was breaking the build
* removed tests that broke from merge, will override with master
* fixed merging errors
* trying my best to merge
* removed drawable definition in activity_post.xml
* Started converting Post to a fragment
* got a working feed
* WI
* removed non-valid test
* rebase on other branch
* moved the feed to the home page
* Add tests
* delete test for now
* Adapt test to changes (no more profile from drawer)
* Add unit test for api
* Add test for profile, refactor to allow testing, add exception to security policy to allow tests
* Adapt test to new situation
* Fix typo due to change
* refactor somewhat
* added a feed test
* WIP posts
* trying to add images
* WIP posts
* trying to add images
* Got posts working and linked them to the profile
* added tests for Post
* layout changes
* moved a test file
* refactoring
* refactoring
* WIP posts
* WIP posts
* trying to add images
* trying to add images
* Got posts working and linked them to the profile
* added tests for Post
* layout changes
* moved a test file
* refactoring
* refactoring
* removed wrong annotation in unit test
* removed an import that was breaking the build
* removed tests that broke from merge, will override with master
* added UI test for the post activity
* WIP posts
* trying to add images
* WIP posts
* trying to add images
* Got posts working and linked them to the profile
* added tests for Post
* layout changes
* moved a test file
* refactoring
* refactoring
* WIP posts
* WIP posts
* trying to add images
* trying to add images
* Got posts working and linked them to the profile
* added tests for Post
* layout changes
* moved a test file
* refactoring
* refactoring
* removed wrong annotation in unit test
* removed an import that was breaking the build
* removed tests that broke from merge, will override with master
* added UI test for the post activity
* fixed merging errors
* trying my best to merge
* removed drawable definition in activity_post.xml
* Started converting Post to a fragment
* got a working feed
* WI
* removed non-valid test
* WIP posts
* WIP posts
* trying to add images
* trying to add images
* Got posts working and linked them to the profile
* added tests for Post
* layout changes
* moved a test file
* WIP posts
* WIP posts
* trying to add images
* trying to add images
* Got posts working and linked them to the profile
* added tests for Post
* layout changes
* moved a test file
* refactoring
* refactoring
* refactoring
* refactoring
* removed wrong annotation in unit test
* WIP posts
* WIP posts
* WIP posts
* WIP posts
* trying to add images
* trying to add images
* trying to add images
* trying to add images
* Got posts working and linked them to the profile
* Got posts working and linked them to the profile
* added tests for Post
* layout changes
* layout changes
* moved a test file
* refactoring
* refactoring
* refactoring
* refactoring
* removed wrong annotation in unit test
* removed an import that was breaking the build
* removed an import that was breaking the build
* removed tests that broke from merge, will override with master
* removed tests that broke from merge, will override with master
* added UI test for the post activity
* fixed merging errors
* trying my best to merge
* removed drawable definition in activity_post.xml
* Started converting Post to a fragment
* got a working feed
* WI
* removed non-valid test
* rebase on other branch
* moved the feed to the home page
* added a feed test
* added a working feed test
* fixed broken test
* merged with master
* added a max height for images and made profile pictures round
* Added a default image for the post
* created a PostActivity to look a single posts
* fixed buggy postActivity
* Complete overhall of the feed UI
* removed test that didn't please Travis
* removed legacy test
* changed feedAdapter init location (outside of network callback)
* changed the feed from public timeline to home timeline
* Refactored myProfile page
* Converted profile picture to round image
* restored feed test
* I can like a post, but unlike is still a WIP
* Liking kind of works now and added tests
* fixed an error, now we can unlike as well
* fixed travis constraint error
* Display user's posts on profile page
* moved test to Mock server tests
* fixed test
* last resort debugging
* Changed fixed size of profile posts
* last resort debugging
* last resort debugging
* last resort debugging
* made post_activity profilepic round
* Total refactor of profile posts
* still have a weird bug with the comments: input is always null (WIP)
* still trying to fix coments
* removed annoying side margins in the home feed
* trying to fix comments
* fixed null comment
* converted all posts back to statuses and got rid of post
* Refactored recycler view
* Merged with my-profile
* Posts displayed on profile page
* Added links to profile activity where needed
* fixed comment posting
* finished implementing comments, but api is buggy so none are visible
* removed useless space in profile page
* fixed ci config bug
* trying to trigger ci hook (github was down last time)
* updated tests with master tests
* added tests for the comments
* added tests for the comments
* added first() matcher to fix comment test
* still trying to fix comment tests' null progress bar
* getting rid of that null progress bar
* added comment test
* fixed merge error
* added like button test
* added more post tests
* took pr coments into account
* added back an old test
* added mockServer response for comment test and fixed comment null pointer bug
* changed notification UI to better separate notifications
* added mockserver response for likes and corrected like toggling error
* added a test for posting comments
* fixed typo in test
* a gift for code climate
* refactored stuff
* fixed broken imports
* comment refactored as xml
Co-authored-by: Matthieu <61561059+Wv5twkFEKh54vo4tta9yu7dHa3@users.noreply.github.com>
Co-authored-by: mjaillot <marie.jaillot@epfl.ch>
2020-04-11 12:55:06 +02:00
|
|
|
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
|
|
|
super.onViewCreated(view, savedInstanceState)
|
2020-07-26 20:56:01 +02:00
|
|
|
val content = makeContent()
|
Commenting & seeing comments on a post ( issues: #37 #77 ) (#87)
Comment and like buttons added + a few UI tweaks
* WIP posts
* WIP posts
* trying to add images
* trying to add images
* Got posts working and linked them to the profile
* added tests for Post
* layout changes
* moved a test file
* refactoring
* refactoring
* removed wrong annotation in unit test
* removed an import that was breaking the build
* removed tests that broke from merge, will override with master
* added UI test for the post activity
* WIP posts
* WIP posts
* trying to add images
* trying to add images
* Got posts working and linked them to the profile
* layout changes
* refactoring
* refactoring
* WIP posts
* WIP posts
* trying to add images
* trying to add images
* Got posts working and linked them to the profile
* added tests for Post
* layout changes
* moved a test file
* refactoring
* refactoring
* removed wrong annotation in unit test
* removed an import that was breaking the build
* removed tests that broke from merge, will override with master
* fixed merging errors
* trying my best to merge
* removed drawable definition in activity_post.xml
* Started converting Post to a fragment
* got a working feed
* WI
* removed non-valid test
* rebase on other branch
* moved the feed to the home page
* Add tests
* delete test for now
* Adapt test to changes (no more profile from drawer)
* Add unit test for api
* Add test for profile, refactor to allow testing, add exception to security policy to allow tests
* Adapt test to new situation
* Fix typo due to change
* refactor somewhat
* added a feed test
* WIP posts
* trying to add images
* WIP posts
* trying to add images
* Got posts working and linked them to the profile
* added tests for Post
* layout changes
* moved a test file
* refactoring
* refactoring
* WIP posts
* WIP posts
* trying to add images
* trying to add images
* Got posts working and linked them to the profile
* added tests for Post
* layout changes
* moved a test file
* refactoring
* refactoring
* removed wrong annotation in unit test
* removed an import that was breaking the build
* removed tests that broke from merge, will override with master
* added UI test for the post activity
* WIP posts
* trying to add images
* WIP posts
* trying to add images
* Got posts working and linked them to the profile
* added tests for Post
* layout changes
* moved a test file
* refactoring
* refactoring
* WIP posts
* WIP posts
* trying to add images
* trying to add images
* Got posts working and linked them to the profile
* added tests for Post
* layout changes
* moved a test file
* refactoring
* refactoring
* removed wrong annotation in unit test
* removed an import that was breaking the build
* removed tests that broke from merge, will override with master
* added UI test for the post activity
* fixed merging errors
* trying my best to merge
* removed drawable definition in activity_post.xml
* Started converting Post to a fragment
* got a working feed
* WI
* removed non-valid test
* WIP posts
* WIP posts
* trying to add images
* trying to add images
* Got posts working and linked them to the profile
* added tests for Post
* layout changes
* moved a test file
* WIP posts
* WIP posts
* trying to add images
* trying to add images
* Got posts working and linked them to the profile
* added tests for Post
* layout changes
* moved a test file
* refactoring
* refactoring
* refactoring
* refactoring
* removed wrong annotation in unit test
* WIP posts
* WIP posts
* WIP posts
* WIP posts
* trying to add images
* trying to add images
* trying to add images
* trying to add images
* Got posts working and linked them to the profile
* Got posts working and linked them to the profile
* added tests for Post
* layout changes
* layout changes
* moved a test file
* refactoring
* refactoring
* refactoring
* refactoring
* removed wrong annotation in unit test
* removed an import that was breaking the build
* removed an import that was breaking the build
* removed tests that broke from merge, will override with master
* removed tests that broke from merge, will override with master
* added UI test for the post activity
* fixed merging errors
* trying my best to merge
* removed drawable definition in activity_post.xml
* Started converting Post to a fragment
* got a working feed
* WI
* removed non-valid test
* rebase on other branch
* moved the feed to the home page
* added a feed test
* added a working feed test
* fixed broken test
* merged with master
* added a max height for images and made profile pictures round
* Added a default image for the post
* created a PostActivity to look a single posts
* fixed buggy postActivity
* Complete overhall of the feed UI
* removed test that didn't please Travis
* removed legacy test
* changed feedAdapter init location (outside of network callback)
* changed the feed from public timeline to home timeline
* Refactored myProfile page
* Converted profile picture to round image
* restored feed test
* I can like a post, but unlike is still a WIP
* Liking kind of works now and added tests
* fixed an error, now we can unlike as well
* fixed travis constraint error
* Display user's posts on profile page
* moved test to Mock server tests
* fixed test
* last resort debugging
* Changed fixed size of profile posts
* last resort debugging
* last resort debugging
* last resort debugging
* made post_activity profilepic round
* Total refactor of profile posts
* still have a weird bug with the comments: input is always null (WIP)
* still trying to fix coments
* removed annoying side margins in the home feed
* trying to fix comments
* fixed null comment
* converted all posts back to statuses and got rid of post
* Refactored recycler view
* Merged with my-profile
* Posts displayed on profile page
* Added links to profile activity where needed
* fixed comment posting
* finished implementing comments, but api is buggy so none are visible
* removed useless space in profile page
* fixed ci config bug
* trying to trigger ci hook (github was down last time)
* updated tests with master tests
* added tests for the comments
* added tests for the comments
* added first() matcher to fix comment test
* still trying to fix comment tests' null progress bar
* getting rid of that null progress bar
* added comment test
* fixed merge error
* added like button test
* added more post tests
* took pr coments into account
* added back an old test
* added mockServer response for comment test and fixed comment null pointer bug
* changed notification UI to better separate notifications
* added mockserver response for likes and corrected like toggling error
* added a test for posting comments
* fixed typo in test
* a gift for code climate
* refactored stuff
* fixed broken imports
* comment refactored as xml
Co-authored-by: Matthieu <61561059+Wv5twkFEKh54vo4tta9yu7dHa3@users.noreply.github.com>
Co-authored-by: mjaillot <marie.jaillot@epfl.ch>
2020-04-11 12:55:06 +02:00
|
|
|
|
|
|
|
content.observe(viewLifecycleOwner,
|
|
|
|
Observer { c ->
|
|
|
|
adapter.submitList(c)
|
|
|
|
//after a refresh is done we need to stop the pull to refresh spinner
|
|
|
|
swipeRefreshLayout.isRefreshing = false
|
|
|
|
})
|
2020-07-26 20:56:01 +02:00
|
|
|
|
|
|
|
swipeRefreshLayout.setOnRefreshListener {
|
2020-10-31 11:21:56 +01:00
|
|
|
showError(show = false)
|
|
|
|
|
2020-07-26 20:56:01 +02:00
|
|
|
//by invalidating data, loadInitial will be called again
|
|
|
|
factory.liveData.value!!.invalidate()
|
|
|
|
}
|
Commenting & seeing comments on a post ( issues: #37 #77 ) (#87)
Comment and like buttons added + a few UI tweaks
* WIP posts
* WIP posts
* trying to add images
* trying to add images
* Got posts working and linked them to the profile
* added tests for Post
* layout changes
* moved a test file
* refactoring
* refactoring
* removed wrong annotation in unit test
* removed an import that was breaking the build
* removed tests that broke from merge, will override with master
* added UI test for the post activity
* WIP posts
* WIP posts
* trying to add images
* trying to add images
* Got posts working and linked them to the profile
* layout changes
* refactoring
* refactoring
* WIP posts
* WIP posts
* trying to add images
* trying to add images
* Got posts working and linked them to the profile
* added tests for Post
* layout changes
* moved a test file
* refactoring
* refactoring
* removed wrong annotation in unit test
* removed an import that was breaking the build
* removed tests that broke from merge, will override with master
* fixed merging errors
* trying my best to merge
* removed drawable definition in activity_post.xml
* Started converting Post to a fragment
* got a working feed
* WI
* removed non-valid test
* rebase on other branch
* moved the feed to the home page
* Add tests
* delete test for now
* Adapt test to changes (no more profile from drawer)
* Add unit test for api
* Add test for profile, refactor to allow testing, add exception to security policy to allow tests
* Adapt test to new situation
* Fix typo due to change
* refactor somewhat
* added a feed test
* WIP posts
* trying to add images
* WIP posts
* trying to add images
* Got posts working and linked them to the profile
* added tests for Post
* layout changes
* moved a test file
* refactoring
* refactoring
* WIP posts
* WIP posts
* trying to add images
* trying to add images
* Got posts working and linked them to the profile
* added tests for Post
* layout changes
* moved a test file
* refactoring
* refactoring
* removed wrong annotation in unit test
* removed an import that was breaking the build
* removed tests that broke from merge, will override with master
* added UI test for the post activity
* WIP posts
* trying to add images
* WIP posts
* trying to add images
* Got posts working and linked them to the profile
* added tests for Post
* layout changes
* moved a test file
* refactoring
* refactoring
* WIP posts
* WIP posts
* trying to add images
* trying to add images
* Got posts working and linked them to the profile
* added tests for Post
* layout changes
* moved a test file
* refactoring
* refactoring
* removed wrong annotation in unit test
* removed an import that was breaking the build
* removed tests that broke from merge, will override with master
* added UI test for the post activity
* fixed merging errors
* trying my best to merge
* removed drawable definition in activity_post.xml
* Started converting Post to a fragment
* got a working feed
* WI
* removed non-valid test
* WIP posts
* WIP posts
* trying to add images
* trying to add images
* Got posts working and linked them to the profile
* added tests for Post
* layout changes
* moved a test file
* WIP posts
* WIP posts
* trying to add images
* trying to add images
* Got posts working and linked them to the profile
* added tests for Post
* layout changes
* moved a test file
* refactoring
* refactoring
* refactoring
* refactoring
* removed wrong annotation in unit test
* WIP posts
* WIP posts
* WIP posts
* WIP posts
* trying to add images
* trying to add images
* trying to add images
* trying to add images
* Got posts working and linked them to the profile
* Got posts working and linked them to the profile
* added tests for Post
* layout changes
* layout changes
* moved a test file
* refactoring
* refactoring
* refactoring
* refactoring
* removed wrong annotation in unit test
* removed an import that was breaking the build
* removed an import that was breaking the build
* removed tests that broke from merge, will override with master
* removed tests that broke from merge, will override with master
* added UI test for the post activity
* fixed merging errors
* trying my best to merge
* removed drawable definition in activity_post.xml
* Started converting Post to a fragment
* got a working feed
* WI
* removed non-valid test
* rebase on other branch
* moved the feed to the home page
* added a feed test
* added a working feed test
* fixed broken test
* merged with master
* added a max height for images and made profile pictures round
* Added a default image for the post
* created a PostActivity to look a single posts
* fixed buggy postActivity
* Complete overhall of the feed UI
* removed test that didn't please Travis
* removed legacy test
* changed feedAdapter init location (outside of network callback)
* changed the feed from public timeline to home timeline
* Refactored myProfile page
* Converted profile picture to round image
* restored feed test
* I can like a post, but unlike is still a WIP
* Liking kind of works now and added tests
* fixed an error, now we can unlike as well
* fixed travis constraint error
* Display user's posts on profile page
* moved test to Mock server tests
* fixed test
* last resort debugging
* Changed fixed size of profile posts
* last resort debugging
* last resort debugging
* last resort debugging
* made post_activity profilepic round
* Total refactor of profile posts
* still have a weird bug with the comments: input is always null (WIP)
* still trying to fix coments
* removed annoying side margins in the home feed
* trying to fix comments
* fixed null comment
* converted all posts back to statuses and got rid of post
* Refactored recycler view
* Merged with my-profile
* Posts displayed on profile page
* Added links to profile activity where needed
* fixed comment posting
* finished implementing comments, but api is buggy so none are visible
* removed useless space in profile page
* fixed ci config bug
* trying to trigger ci hook (github was down last time)
* updated tests with master tests
* added tests for the comments
* added tests for the comments
* added first() matcher to fix comment test
* still trying to fix comment tests' null progress bar
* getting rid of that null progress bar
* added comment test
* fixed merge error
* added like button test
* added more post tests
* took pr coments into account
* added back an old test
* added mockServer response for comment test and fixed comment null pointer bug
* changed notification UI to better separate notifications
* added mockserver response for likes and corrected like toggling error
* added a test for posting comments
* fixed typo in test
* a gift for code climate
* refactored stuff
* fixed broken imports
* comment refactored as xml
Co-authored-by: Matthieu <61561059+Wv5twkFEKh54vo4tta9yu7dHa3@users.noreply.github.com>
Co-authored-by: mjaillot <marie.jaillot@epfl.ch>
2020-04-11 12:55:06 +02:00
|
|
|
}
|
|
|
|
|
2020-04-03 09:11:57 +02:00
|
|
|
private fun makeContent(): LiveData<PagedList<Notification>> {
|
2020-07-26 20:56:01 +02:00
|
|
|
val config: PagedList.Config = PagedList.Config.Builder().setPageSize(10).build()
|
|
|
|
val dataSource = NotificationListDataSource()
|
|
|
|
factory = FeedDataSourceFactory(dataSource)
|
|
|
|
return LivePagedListBuilder(factory, config).build()
|
|
|
|
}
|
|
|
|
|
|
|
|
inner class NotificationListDataSource: FeedDataSource<String, Notification>() {
|
|
|
|
|
|
|
|
override fun newSource(): NotificationListDataSource {
|
|
|
|
return NotificationListDataSource()
|
|
|
|
}
|
|
|
|
|
|
|
|
//We use the id as the key
|
|
|
|
override fun getKey(item: Notification): String {
|
|
|
|
return item.id
|
|
|
|
}
|
|
|
|
|
|
|
|
override fun makeInitialCall(requestedLoadSize: Int): Call<List<Notification>> {
|
2020-04-03 09:11:57 +02:00
|
|
|
return pixelfedAPI
|
2020-05-19 09:49:34 +02:00
|
|
|
.notifications("Bearer $accessToken", limit="$requestedLoadSize")
|
2020-04-03 09:11:57 +02:00
|
|
|
}
|
2020-07-26 20:56:01 +02:00
|
|
|
override fun makeAfterCall(requestedLoadSize: Int, key: String): Call<List<Notification>> {
|
2020-04-03 09:11:57 +02:00
|
|
|
return pixelfedAPI
|
|
|
|
.notifications("Bearer $accessToken", max_id=key, limit="$requestedLoadSize")
|
2020-04-02 19:57:07 +02:00
|
|
|
}
|
2020-04-03 09:11:57 +02:00
|
|
|
|
2020-07-26 20:56:01 +02:00
|
|
|
override fun enqueueCall(call: Call<List<Notification>>, callback: LoadCallback<Notification>){
|
|
|
|
|
|
|
|
call.enqueue(object : Callback<List<Notification>> {
|
|
|
|
override fun onResponse(call: Call<List<Notification>>, response: Response<List<Notification>>) {
|
|
|
|
if (response.isSuccessful && response.body() != null) {
|
|
|
|
val data = response.body()!!
|
|
|
|
callback.onResult(data)
|
2020-10-31 11:21:56 +01:00
|
|
|
} else {
|
|
|
|
showError()
|
2020-07-26 20:56:01 +02:00
|
|
|
}
|
|
|
|
swipeRefreshLayout.isRefreshing = false
|
|
|
|
loadingIndicator.visibility = View.GONE
|
|
|
|
}
|
|
|
|
|
|
|
|
override fun onFailure(call: Call<List<Notification>>, t: Throwable) {
|
2020-10-31 11:21:56 +01:00
|
|
|
showError(errorText = R.string.feed_failed)
|
2020-07-26 20:56:01 +02:00
|
|
|
Log.e("NotificationsFragment", t.toString())
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
2020-04-03 09:11:57 +02:00
|
|
|
}
|
|
|
|
|
2020-04-02 19:57:07 +02:00
|
|
|
/**
|
|
|
|
* [RecyclerView.Adapter] that can display a [Notification]
|
|
|
|
*/
|
2020-04-30 17:54:21 +02:00
|
|
|
inner class NotificationsRecyclerViewAdapter: FeedsRecyclerViewAdapter<Notification, NotificationsRecyclerViewAdapter.ViewHolder>(),
|
|
|
|
ListPreloader.PreloadModelProvider<Notification> {
|
2020-04-02 19:57:07 +02:00
|
|
|
|
|
|
|
private val mOnClickListener: View.OnClickListener
|
|
|
|
|
|
|
|
init {
|
|
|
|
mOnClickListener = View.OnClickListener { v ->
|
|
|
|
val notification = v.tag as Notification
|
|
|
|
openActivity(notification)
|
|
|
|
}
|
|
|
|
}
|
2020-05-01 10:39:25 +02:00
|
|
|
|
2020-11-01 19:57:56 +01:00
|
|
|
private fun openPostFromNotification(notification: Notification) : Intent {
|
2020-05-01 10:39:25 +02:00
|
|
|
val intent = Intent(context, PostActivity::class.java)
|
|
|
|
intent.putExtra(Status.POST_TAG, notification.status)
|
|
|
|
return intent
|
|
|
|
}
|
|
|
|
|
2020-04-02 19:57:07 +02:00
|
|
|
private fun openActivity(notification: Notification){
|
|
|
|
val intent: Intent
|
|
|
|
when (notification.type){
|
2020-11-01 19:57:56 +01:00
|
|
|
Notification.NotificationType.mention, Notification.NotificationType.favourite,
|
|
|
|
Notification.NotificationType.poll, Notification.NotificationType.reblog -> {
|
|
|
|
intent = openPostFromNotification(notification)
|
2020-04-02 19:57:07 +02:00
|
|
|
}
|
|
|
|
Notification.NotificationType.follow -> {
|
2020-04-09 22:36:59 +02:00
|
|
|
intent = Intent(context, ProfileActivity::class.java)
|
|
|
|
intent.putExtra(Account.ACCOUNT_TAG, notification.account)
|
2020-04-02 19:57:07 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
context.startActivity(intent)
|
|
|
|
}
|
|
|
|
|
|
|
|
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
|
|
|
|
val view = LayoutInflater.from(parent.context)
|
|
|
|
.inflate(R.layout.fragment_notifications, parent, false)
|
|
|
|
context = view.context
|
|
|
|
return ViewHolder(view)
|
|
|
|
}
|
|
|
|
|
|
|
|
override fun onBindViewHolder(holder: ViewHolder, position: Int) {
|
|
|
|
val notification = getItem(position) ?: return
|
|
|
|
profilePicRequest.load(notification.account.avatar_static).into(holder.avatar)
|
|
|
|
|
|
|
|
val previewUrl = notification.status?.media_attachments?.getOrNull(0)?.preview_url
|
|
|
|
if(!previewUrl.isNullOrBlank()){
|
|
|
|
Glide.with(holder.mView).load(previewUrl)
|
|
|
|
.placeholder(R.drawable.ic_picture_fallback).into(holder.photoThumbnail)
|
|
|
|
} else{
|
|
|
|
holder.photoThumbnail.visibility = View.GONE
|
|
|
|
}
|
|
|
|
|
2020-11-01 18:44:32 +01:00
|
|
|
setNotificationType(notification.type, notification.account.username!!, holder.notificationType)
|
2020-09-10 20:20:23 +02:00
|
|
|
setTextViewFromISO8601(notification.created_at, holder.notificationTime, false, context)
|
2020-04-02 19:57:07 +02:00
|
|
|
|
2020-04-23 17:48:45 +02:00
|
|
|
//Convert HTML to clickable text
|
|
|
|
holder.postDescription.text =
|
|
|
|
parseHTMLText(
|
|
|
|
notification.status?.content ?: "",
|
|
|
|
notification.status?.mentions,
|
|
|
|
pixelfedAPI,
|
|
|
|
context,
|
|
|
|
"Bearer $accessToken"
|
|
|
|
)
|
2020-04-02 19:57:07 +02:00
|
|
|
|
|
|
|
|
|
|
|
with(holder.mView) {
|
|
|
|
tag = notification
|
|
|
|
setOnClickListener(mOnClickListener)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private fun setNotificationType(type: Notification.NotificationType, username: String,
|
|
|
|
textView: TextView
|
|
|
|
){
|
|
|
|
val context = textView.context
|
|
|
|
val (format: String, drawable: Drawable?) = when(type) {
|
|
|
|
Notification.NotificationType.follow -> {
|
|
|
|
setNotificationTypeTextView(context, R.string.followed_notification, R.drawable.ic_follow)
|
|
|
|
}
|
|
|
|
Notification.NotificationType.mention -> {
|
|
|
|
setNotificationTypeTextView(context, R.string.mention_notification, R.drawable.ic_apenstaart)
|
|
|
|
}
|
|
|
|
|
|
|
|
Notification.NotificationType.reblog -> {
|
2020-04-23 17:48:45 +02:00
|
|
|
setNotificationTypeTextView(context, R.string.shared_notification, R.drawable.ic_reblog_blue)
|
2020-04-02 19:57:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
Notification.NotificationType.favourite -> {
|
2020-04-23 17:48:45 +02:00
|
|
|
setNotificationTypeTextView(context, R.string.liked_notification, R.drawable.ic_like_full)
|
2020-04-02 19:57:07 +02:00
|
|
|
}
|
2020-11-01 19:57:56 +01:00
|
|
|
Notification.NotificationType.poll -> {
|
|
|
|
setNotificationTypeTextView(context, R.string.poll_notification, R.drawable.poll)
|
|
|
|
}
|
2020-04-02 19:57:07 +02:00
|
|
|
}
|
|
|
|
textView.text = format.format(username)
|
|
|
|
textView.setCompoundDrawablesWithIntrinsicBounds(
|
|
|
|
drawable,null,null,null
|
|
|
|
)
|
|
|
|
}
|
|
|
|
private fun setNotificationTypeTextView(context: Context, format: Int, drawable: Int): Pair<String, Drawable?> {
|
|
|
|
return Pair(context.getString(format), context.getDrawable(drawable))
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
inner class ViewHolder(val mView: View) : RecyclerView.ViewHolder(mView) {
|
|
|
|
val notificationType: TextView = mView.notification_type
|
2020-09-10 20:20:23 +02:00
|
|
|
val notificationTime: TextView = mView.notification_time
|
2020-04-02 19:57:07 +02:00
|
|
|
val postDescription: TextView = mView.notification_post_description
|
|
|
|
val avatar: ImageView = mView.notification_avatar
|
|
|
|
val photoThumbnail: ImageView = mView.notification_photo_thumbnail
|
|
|
|
}
|
|
|
|
|
|
|
|
override fun getPreloadItems(position: Int): MutableList<Notification> {
|
|
|
|
val notification = getItem(position) ?: return mutableListOf()
|
|
|
|
return mutableListOf(notification)
|
|
|
|
}
|
|
|
|
|
|
|
|
override fun getPreloadRequestBuilder(item: Notification): RequestBuilder<*>? {
|
|
|
|
return profilePicRequest.load(item.account.avatar_static)
|
2020-03-21 18:12:00 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|