54 lines
1.8 KiB
Kotlin
54 lines
1.8 KiB
Kotlin
package com.h.pixeldroid.fragments
|
|
|
|
import android.content.Context
|
|
import android.content.SharedPreferences
|
|
import android.os.Bundle
|
|
import android.view.LayoutInflater
|
|
import android.view.View
|
|
import android.view.ViewGroup
|
|
import androidx.fragment.app.Fragment
|
|
import androidx.recyclerview.widget.GridLayoutManager
|
|
import androidx.recyclerview.widget.LinearLayoutManager
|
|
import androidx.recyclerview.widget.RecyclerView
|
|
import com.h.pixeldroid.BuildConfig
|
|
import com.h.pixeldroid.R
|
|
import com.h.pixeldroid.api.PixelfedAPI
|
|
|
|
|
|
/**
|
|
* A fragment representing a list of Items.
|
|
* Activities containing this fragment MUST implement the
|
|
* [ProfilePostsFragment.OnListFragmentInteractionListener] interface.
|
|
*/
|
|
class ProfilePostsFragment : Fragment() {
|
|
private lateinit var preferences: SharedPreferences
|
|
private lateinit var pixelfedAPI: PixelfedAPI
|
|
private var accessToken: String? = null
|
|
|
|
private var columnCount = 3
|
|
|
|
override fun onCreateView(
|
|
inflater: LayoutInflater, container: ViewGroup?,
|
|
savedInstanceState: Bundle?
|
|
): View? {
|
|
val view = inflater.inflate(R.layout.fragment_profile_posts_list, container, false)
|
|
preferences = requireActivity().getSharedPreferences(
|
|
"${BuildConfig.APPLICATION_ID}.pref", Context.MODE_PRIVATE
|
|
)
|
|
pixelfedAPI = PixelfedAPI.create("${preferences.getString("domain", "")}")
|
|
accessToken = preferences.getString("accessToken", "")
|
|
|
|
// Set the adapter
|
|
if (view is RecyclerView) {
|
|
with(view) {
|
|
layoutManager = when {
|
|
columnCount <= 1 -> LinearLayoutManager(context)
|
|
else -> GridLayoutManager(context, columnCount)
|
|
}
|
|
adapter = ProfilePostsRecyclerViewAdapter()
|
|
}
|
|
}
|
|
return view
|
|
}
|
|
}
|