2020-10-31 11:21:56 +01:00
|
|
|
package com.h.pixeldroid.fragments.feeds
|
2020-03-21 18:12:00 +01:00
|
|
|
|
|
|
|
import android.content.Context
|
|
|
|
import android.os.Bundle
|
|
|
|
import android.view.LayoutInflater
|
|
|
|
import android.view.View
|
2020-10-31 11:21:56 +01:00
|
|
|
import android.view.View.GONE
|
|
|
|
import android.view.View.VISIBLE
|
2020-03-21 18:12:00 +01:00
|
|
|
import android.view.ViewGroup
|
2020-04-09 22:36:59 +02:00
|
|
|
import android.widget.ProgressBar
|
2020-11-02 13:28:27 +01:00
|
|
|
import android.widget.TextView
|
2020-10-31 11:21:56 +01:00
|
|
|
import androidx.annotation.StringRes
|
2020-10-31 22:11:01 +01:00
|
|
|
import androidx.constraintlayout.widget.ConstraintLayout
|
2020-03-21 18:12:00 +01:00
|
|
|
import androidx.fragment.app.Fragment
|
2020-04-03 09:11:57 +02:00
|
|
|
import androidx.lifecycle.MutableLiveData
|
|
|
|
import androidx.paging.DataSource
|
2020-04-02 19:57:07 +02:00
|
|
|
import androidx.paging.ItemKeyedDataSource
|
|
|
|
import androidx.paging.PagedListAdapter
|
|
|
|
import androidx.recyclerview.widget.DiffUtil
|
2020-03-21 18:12:00 +01:00
|
|
|
import androidx.recyclerview.widget.LinearLayoutManager
|
|
|
|
import androidx.recyclerview.widget.RecyclerView
|
|
|
|
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout
|
2020-07-26 20:56:01 +02:00
|
|
|
import com.h.pixeldroid.Pixeldroid
|
2020-03-21 18:12:00 +01:00
|
|
|
import com.h.pixeldroid.R
|
|
|
|
import com.h.pixeldroid.api.PixelfedAPI
|
2020-05-19 09:49:34 +02:00
|
|
|
import com.h.pixeldroid.db.AppDatabase
|
|
|
|
import com.h.pixeldroid.db.UserDatabaseEntity
|
2020-07-26 20:56:01 +02:00
|
|
|
import com.h.pixeldroid.di.PixelfedAPIHolder
|
2020-04-02 19:57:07 +02:00
|
|
|
import com.h.pixeldroid.objects.FeedContent
|
2020-10-31 11:21:56 +01:00
|
|
|
import kotlinx.android.synthetic.main.fragment_feed.*
|
2020-03-21 18:12:00 +01:00
|
|
|
import kotlinx.android.synthetic.main.fragment_feed.view.*
|
2020-11-02 13:28:27 +01:00
|
|
|
import org.w3c.dom.Text
|
2020-03-21 18:12:00 +01:00
|
|
|
import retrofit2.Call
|
2020-07-26 20:56:01 +02:00
|
|
|
import javax.inject.Inject
|
2020-03-21 18:12:00 +01:00
|
|
|
|
2020-07-26 20:56:01 +02:00
|
|
|
open class FeedFragment: Fragment() {
|
2020-04-01 19:38:21 +02:00
|
|
|
|
2020-03-21 18:12:00 +01:00
|
|
|
protected var accessToken: String? = null
|
2020-07-26 20:56:01 +02:00
|
|
|
@Inject
|
|
|
|
lateinit var apiHolder: PixelfedAPIHolder
|
|
|
|
|
2020-03-21 18:12:00 +01:00
|
|
|
protected lateinit var pixelfedAPI: PixelfedAPI
|
|
|
|
|
|
|
|
protected lateinit var list : RecyclerView
|
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
|
|
|
protected lateinit var swipeRefreshLayout: SwipeRefreshLayout
|
2020-04-30 17:54:21 +02:00
|
|
|
internal lateinit var loadingIndicator: ProgressBar
|
2020-07-26 20:56:01 +02:00
|
|
|
var user: UserDatabaseEntity? = null
|
|
|
|
@Inject
|
|
|
|
lateinit var db: AppDatabase
|
2020-05-19 09:49:34 +02:00
|
|
|
|
|
|
|
|
2020-03-21 18:12:00 +01:00
|
|
|
|
2020-04-02 19:57:07 +02:00
|
|
|
override fun onCreateView(
|
|
|
|
inflater: LayoutInflater,
|
|
|
|
container: ViewGroup?,
|
|
|
|
savedInstanceState: Bundle?
|
|
|
|
): View? {
|
|
|
|
val view = inflater.inflate(R.layout.fragment_feed, container, false)
|
2020-03-21 18:12:00 +01:00
|
|
|
|
2020-07-26 20:56:01 +02:00
|
|
|
(requireActivity().application as Pixeldroid).getAppComponent().inject(this)
|
|
|
|
|
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
|
|
|
//Initialize lateinit fields that are needed as soon as the view is created
|
2020-03-21 18:12:00 +01:00
|
|
|
swipeRefreshLayout = view.findViewById(R.id.swipeRefreshLayout)
|
2020-04-09 22:36:59 +02:00
|
|
|
loadingIndicator = view.findViewById(R.id.progressBar)
|
2020-03-21 18:12:00 +01:00
|
|
|
list = swipeRefreshLayout.list
|
|
|
|
list.layoutManager = LinearLayoutManager(context)
|
2020-05-19 09:49:34 +02:00
|
|
|
user = db.userDao().getActiveUser()
|
2020-07-26 20:56:01 +02:00
|
|
|
|
|
|
|
pixelfedAPI = apiHolder.api ?: apiHolder.setDomainToCurrentUser(db)
|
2020-05-19 09:49:34 +02:00
|
|
|
accessToken = user?.accessToken.orEmpty()
|
2020-03-21 18:12:00 +01:00
|
|
|
|
|
|
|
return view
|
|
|
|
}
|
|
|
|
|
2020-10-31 11:21:56 +01:00
|
|
|
fun showError(@StringRes errorText: Int = R.string.loading_toast, show: Boolean = true){
|
2020-10-31 22:11:01 +01:00
|
|
|
val errorLayout = view?.findViewById<ConstraintLayout>(R.id.errorLayout)
|
|
|
|
val progressBar = view?.findViewById<ProgressBar>(R.id.progressBar)
|
|
|
|
|
2020-10-31 11:21:56 +01:00
|
|
|
if(show){
|
2020-11-02 13:28:27 +01:00
|
|
|
view?.findViewById<TextView>(R.id.error_text)?.setText(errorText)
|
2020-10-31 22:11:01 +01:00
|
|
|
errorLayout?.visibility = VISIBLE
|
|
|
|
progressBar?.visibility = GONE
|
2020-10-31 11:21:56 +01:00
|
|
|
} else {
|
2020-10-31 22:11:01 +01:00
|
|
|
errorLayout?.visibility = GONE
|
|
|
|
progressBar?.visibility = VISIBLE
|
2020-10-31 11:21:56 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-07-26 20:56:01 +02:00
|
|
|
open inner class FeedDataSourceFactory<ObjectId, APIObject: FeedContent>(
|
|
|
|
private val dataSource: FeedDataSource<ObjectId, APIObject>
|
|
|
|
): DataSource.Factory<ObjectId, APIObject>() {
|
|
|
|
internal lateinit var liveData: MutableLiveData<FeedDataSource<ObjectId, APIObject>>
|
2020-04-30 17:54:21 +02:00
|
|
|
|
2020-07-26 20:56:01 +02:00
|
|
|
override fun create(): DataSource<ObjectId, APIObject> {
|
|
|
|
val dataSource = dataSource.newSource()
|
|
|
|
liveData = MutableLiveData()
|
|
|
|
liveData.postValue(dataSource)
|
|
|
|
return dataSource
|
2020-04-03 09:11:57 +02:00
|
|
|
}
|
2020-07-26 20:56:01 +02:00
|
|
|
}
|
|
|
|
abstract inner class FeedDataSource<ObjectId, APIObject: FeedContent>: ItemKeyedDataSource<ObjectId, APIObject>(){
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Used in the initial call to initialize the list [loadInitial].
|
|
|
|
* @param requestedLoadSize number of objects requested in a call
|
|
|
|
* @return [Call] that gets the list of [APIObject]
|
|
|
|
*/
|
|
|
|
abstract fun makeInitialCall(requestedLoadSize: Int): Call<List<APIObject>>
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Used in the subsequent calls to get more objects.
|
|
|
|
* @param requestedLoadSize number of objects requested in a call
|
|
|
|
* @param key of the last object we already have
|
|
|
|
* @return [Call] that gets the list of [APIObject]
|
|
|
|
*/
|
|
|
|
abstract fun makeAfterCall(requestedLoadSize: Int, key: ObjectId): Call<List<APIObject>>
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This is called to initialize the list, so we want some of the most recent objects.
|
|
|
|
* @param params holds the requestedLoadSize
|
|
|
|
* @param callback to call after network request completes
|
|
|
|
*/
|
2020-04-03 09:11:57 +02:00
|
|
|
override fun loadInitial(
|
2020-07-26 20:56:01 +02:00
|
|
|
params: LoadInitialParams<ObjectId>,
|
|
|
|
callback: LoadInitialCallback<APIObject>
|
2020-04-03 09:11:57 +02:00
|
|
|
) {
|
2020-07-26 20:56:01 +02:00
|
|
|
enqueueCall(makeInitialCall(params.requestedLoadSize), callback)
|
2020-04-03 09:11:57 +02:00
|
|
|
}
|
|
|
|
|
2020-07-26 20:56:01 +02:00
|
|
|
/**
|
|
|
|
* This is called to when we get to the bottom of the loaded content, so we want objects
|
|
|
|
* older than the given key (params.key).
|
|
|
|
* @param params holds the requestedLoadSize
|
|
|
|
* @param callback to call after network request completes
|
|
|
|
*/
|
|
|
|
override fun loadAfter(params: LoadParams<ObjectId>, callback: LoadCallback<APIObject>) {
|
|
|
|
enqueueCall(makeAfterCall(params.requestedLoadSize, params.key), callback)
|
2020-04-03 09:11:57 +02:00
|
|
|
}
|
|
|
|
|
2020-07-26 20:56:01 +02:00
|
|
|
/**
|
2020-10-04 23:27:06 +02:00
|
|
|
* Do nothing here, it is expected to pull to refresh to load newer items
|
2020-07-26 20:56:01 +02:00
|
|
|
*/
|
|
|
|
override fun loadBefore(params: LoadParams<ObjectId>, callback: LoadCallback<APIObject>) {}
|
2020-04-03 09:11:57 +02:00
|
|
|
|
2020-07-26 20:56:01 +02:00
|
|
|
abstract fun enqueueCall(call: Call<List<APIObject>>, callback: LoadCallback<APIObject>)
|
2020-04-03 09:11:57 +02:00
|
|
|
|
2020-07-26 20:56:01 +02:00
|
|
|
abstract fun newSource(): FeedDataSource<ObjectId, APIObject>
|
2020-04-03 09:11:57 +02:00
|
|
|
|
2020-04-02 19:57:07 +02:00
|
|
|
}
|
2020-03-21 18:12:00 +01:00
|
|
|
}
|
|
|
|
|
2020-04-02 19:57:07 +02:00
|
|
|
abstract class FeedsRecyclerViewAdapter<T: FeedContent, VH : RecyclerView.ViewHolder?>: PagedListAdapter<T, VH>(
|
|
|
|
object : DiffUtil.ItemCallback<T>() {
|
|
|
|
override fun areItemsTheSame(oldItem: T, newItem: T): Boolean {
|
|
|
|
return oldItem.id === newItem.id
|
|
|
|
}
|
|
|
|
|
|
|
|
override fun areContentsTheSame(oldItem: T, newItem: T): Boolean {
|
2020-05-15 09:23:06 +02:00
|
|
|
return oldItem.equals(newItem)
|
2020-04-02 19:57:07 +02:00
|
|
|
}
|
|
|
|
}
|
2020-04-30 17:54:21 +02:00
|
|
|
){
|
2020-03-21 18:12:00 +01:00
|
|
|
protected lateinit var context: Context
|
2020-04-03 09:11:57 +02:00
|
|
|
}
|
|
|
|
|