some progress on fixing profile stuff

This commit is contained in:
Matthieu 2021-01-22 19:25:57 +01:00
parent 567fa40c20
commit b221808f9c
9 changed files with 33 additions and 124 deletions

View File

@ -80,7 +80,7 @@ dependencies {
implementation "androidx.swiperefreshlayout:swiperefreshlayout:1.1.0"
implementation 'androidx.navigation:navigation-fragment-ktx:2.3.2'
implementation 'androidx.navigation:navigation-ui-ktx:2.3.2'
implementation 'androidx.paging:paging-runtime-ktx:3.0.0-alpha11'
implementation 'androidx.paging:paging-runtime-ktx:3.0.0-alpha12'
implementation 'androidx.lifecycle:lifecycle-livedata-ktx:2.2.0'
implementation 'androidx.lifecycle:lifecycle-viewmodel-savedstate:2.2.0'
implementation "androidx.lifecycle:lifecycle-runtime-ktx:2.2.0"

View File

@ -30,7 +30,7 @@ open class UncachedFeedFragment<T: FeedContent> : BaseFragment() {
internal lateinit var viewModel: FeedViewModel<T>
internal lateinit var adapter: PagingDataAdapter<T, RecyclerView.ViewHolder>
private lateinit var binding: FragmentFeedBinding
lateinit var binding: FragmentFeedBinding
private var job: Job? = null

View File

@ -11,6 +11,7 @@ import androidx.lifecycle.ViewModelProvider
import androidx.paging.ExperimentalPagingApi
import androidx.paging.PagingDataAdapter
import androidx.recyclerview.widget.DiffUtil
import androidx.recyclerview.widget.GridLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.h.pixeldroid.R
import com.h.pixeldroid.databinding.FragmentProfilePostsBinding
@ -34,8 +35,7 @@ class ProfileFeedFragment : UncachedFeedFragment<Status>() {
super.onCreate(savedInstanceState)
adapter = ProfileAdapter()
accountId = arguments?.getSerializable(ACCOUNT_ID_TAG) as String
accountId = arguments?.getSerializable(ACCOUNT_ID_TAG) as String? ?: db.userDao().getActiveUser()!!.user_id
}
@ExperimentalPagingApi
@ -57,11 +57,17 @@ class ProfileFeedFragment : UncachedFeedFragment<Status>() {
)
).get(FeedViewModel::class.java) as FeedViewModel<Status>
binding.list.layoutManager = GridLayoutManager(context, 3)
launch()
initSearch()
return view
}
fun refresh(){
//TODO implement refresh here
}
}

View File

@ -14,18 +14,16 @@ class ProfilePagingSource(
override suspend fun load(params: LoadParams<Int>): LoadResult<Int, Status> {
val position = params.key
return try {
val response = api.accountPosts("Bearer $accessToken", account_id = accountId)
val posts = if(response.isSuccessful){
response.body().orEmpty()
} else {
throw HttpException(response)
}
val posts = api.accountPosts("Bearer $accessToken",
account_id = accountId,
min_id = position?.toString(),
limit = params.loadSize
)
LoadResult.Page(
data = posts,
prevKey = null,
nextKey = if(posts.isEmpty()) null else (position ?: 0) + posts.size
nextKey = posts.lastOrNull()?.id?.toIntOrNull()
)
} catch (exception: IOException) {
LoadResult.Error(exception)

View File

@ -45,8 +45,7 @@ class SearchAccountFragment : UncachedFeedFragment<Account>() {
query
)
)
)
.get(FeedViewModel::class.java) as FeedViewModel<Account>
).get(FeedViewModel::class.java) as FeedViewModel<Account>
launch()
initSearch()

View File

@ -1,40 +1,30 @@
package com.h.pixeldroid.profile
import android.content.Intent
import android.graphics.Typeface
import android.os.Bundle
import android.util.Log
import android.view.View
import android.widget.*
import androidx.annotation.StringRes
import androidx.constraintlayout.motion.widget.MotionLayout
import androidx.core.content.ContextCompat
import androidx.lifecycle.lifecycleScope
import androidx.recyclerview.widget.GridLayoutManager
import androidx.recyclerview.widget.RecyclerView
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout
import com.h.pixeldroid.R
import com.h.pixeldroid.databinding.ActivityProfileBinding
import com.h.pixeldroid.databinding.FragmentProfileFeedBinding
import com.h.pixeldroid.databinding.FragmentProfilePostsBinding
import com.h.pixeldroid.posts.parseHTMLText
import com.h.pixeldroid.utils.BaseActivity
import com.h.pixeldroid.utils.ImageConverter
import com.h.pixeldroid.utils.api.PixelfedAPI
import com.h.pixeldroid.utils.api.objects.Account
import com.h.pixeldroid.utils.api.objects.Status
import com.h.pixeldroid.utils.db.entities.UserDatabaseEntity
import com.h.pixeldroid.utils.openUrl
import kotlinx.coroutines.launch
import retrofit2.Call
import retrofit2.Callback
import retrofit2.HttpException
import retrofit2.Response
import java.io.IOException
class ProfileActivity : BaseActivity() {
private lateinit var pixelfedAPI : PixelfedAPI
// private lateinit var adapter : ProfilePostsRecyclerViewAdapter
private lateinit var accessToken : String
private lateinit var domain : String
@ -42,7 +32,6 @@ class ProfileActivity : BaseActivity() {
private var postsFragment = ProfileFeedFragment()
private lateinit var activityBinding: ActivityProfileBinding
private lateinit var feedFragmentBinding: FragmentProfileFeedBinding
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
@ -57,15 +46,11 @@ class ProfileActivity : BaseActivity() {
pixelfedAPI = apiHolder.api ?: apiHolder.setDomainToCurrentUser(db)
accessToken = user?.accessToken.orEmpty()
// Set posts RecyclerView as a grid with 3 columns
feedFragmentBinding.profilePostsRecyclerView.layoutManager = GridLayoutManager(applicationContext, 3)
// adapter = ProfilePostsRecyclerViewAdapter()
// binding.profilePostsRecyclerView.adapter = adapter
// Set profile according to given account
val account = intent.getSerializableExtra(Account.ACCOUNT_TAG) as Account?
setContent(account)
startFragment(account?.id)
activityBinding.profileRefreshLayout.setOnRefreshListener {
getAndSetAccount(account?.id ?: user!!.user_id)
@ -80,8 +65,6 @@ class ProfileActivity : BaseActivity() {
private fun setContent(account: Account?) {
if(account != null) {
setViews(account)
// setPosts(account)
startFragment(account)
} else {
lifecycleScope.launchWhenResumed {
val myAccount: Account = try {
@ -93,9 +76,6 @@ class ProfileActivity : BaseActivity() {
return@launchWhenResumed showError()
}
setViews(myAccount)
// Populate profile page with user's posts
// setPosts(myAccount)
startFragment(myAccount)
}
}
@ -126,14 +106,14 @@ class ProfileActivity : BaseActivity() {
}
private fun showError(@StringRes errorText: Int = R.string.loading_toast, show: Boolean = true){
val motionLayout = activityBinding.motionLayout
/*val motionLayout = activityBinding.motionLayout
if(show){
motionLayout.transitionToEnd()
} else {
motionLayout.transitionToStart()
}
activityBinding.profileProgressBar.visibility = View.GONE
activityBinding.profileRefreshLayout.isRefreshing = false
activityBinding.profileRefreshLayout.isRefreshing = false*/
}
/**
@ -172,42 +152,15 @@ class ProfileActivity : BaseActivity() {
.format(account.following_count.toString())
}
private fun startFragment(account: Account) {
private fun startFragment(accountId: String?) {
val arguments = Bundle()
arguments.putSerializable(Account.ACCOUNT_ID_TAG, account.id)
arguments.putSerializable(Account.ACCOUNT_ID_TAG, accountId)
postsFragment.arguments = arguments
supportFragmentManager.beginTransaction().add(R.id.fragment_profile_feed, postsFragment).commit()
}
/**
* Populate profile page with user's posts
*/
// private fun setPosts(account: Account) {
// pixelfedAPI.accountPosts("Bearer $accessToken", account_id = account.id)
// .enqueue(object : Callback<List<Status>> {
//
// override fun onFailure(call: Call<List<Status>>, t: Throwable) {
// showError()
// Log.e("ProfileActivity.Posts:", t.toString())
// }
//
// override fun onResponse(
// call: Call<List<Status>>,
// response: Response<List<Status>>
// ) {
// if (response.code() == 200) {
// val statuses = response.body()!!
// adapter.addPosts(statuses)
// showError(show = false)
// } else {
// showError()
// }
// }
// })
// }
private fun onClickEditButton() {
val url = "$domain/settings/home"

View File

@ -2,10 +2,7 @@ package com.h.pixeldroid.utils.api
import com.h.pixeldroid.utils.api.objects.*
import io.reactivex.Observable
import io.reactivex.Single
import kotlinx.coroutines.Deferred
import okhttp3.MultipartBody
import retrofit2.Call
import retrofit2.Response
import retrofit2.Retrofit
import retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory
@ -209,9 +206,11 @@ interface PixelfedAPI {
@GET("/api/v1/accounts/{id}/statuses")
suspend fun accountPosts(
@Header("Authorization") authorization: String,
@Path("id") account_id: String? = null
) : Response<List<Status>>
@Header("Authorization") authorization: String,
@Path("id") account_id: String,
@Query("min_id") min_id: String?,
@Query("limit") limit: Int
) : List<Status>
@GET("/api/v1/accounts/relationships")
suspend fun checkRelationships(

View File

@ -10,6 +10,7 @@
<androidx.core.widget.NestedScrollView
android:layout_width="match_parent"
android:fillViewport="true"
android:layout_height="match_parent">
<androidx.constraintlayout.widget.ConstraintLayout
@ -120,45 +121,15 @@
app:layout_constraintStart_toStartOf="@+id/profilePictureImageView"
app:layout_constraintTop_toBottomOf="@+id/descriptionTextView" />
<ProgressBar
android:id="@+id/profileProgressBar"
style="?android:attr/progressBarStyle"
android:layout_width="wrap_content"
<FrameLayout
android:id="@+id/fragment_profile_feed"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
app:layout_constraintBottom_toBottomOf="parent"
tools:context=".profile.ProfileFeedFragment"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/followButton" />
<androidx.constraintlayout.motion.widget.MotionLayout
android:id="@+id/motionLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="8dp"
android:visibility="visible"
app:layoutDescription="@xml/error_layout_xml_error_scene"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/followButton"
tools:visibility="visible">
<include
layout="@layout/error_layout"
tools:layout_editor_absoluteX="50dp" />
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/profilePostsRecyclerView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="5dp"
android:nestedScrollingEnabled="false"
app:layoutManager="LinearLayoutManager"
app:layout_constraintTop_toBottomOf="@id/errorLayout"
tools:listitem="@layout/fragment_profile_posts" />
</androidx.constraintlayout.motion.widget.MotionLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.core.widget.NestedScrollView>

View File

@ -1,17 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/fragment_profile_feed"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".profile.ProfileFeedFragment">
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/profilePostsRecyclerView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="5dp"
android:nestedScrollingEnabled="false"
tools:listitem="@layout/fragment_profile_posts" />
</FrameLayout>