2020-03-04 18:04:55 +01:00
|
|
|
package com.h.pixeldroid.objects
|
|
|
|
|
2020-04-09 22:36:59 +02:00
|
|
|
import android.content.Context
|
|
|
|
import android.content.Intent
|
2020-04-23 17:48:45 +02:00
|
|
|
import android.util.Log
|
2020-04-09 22:36:59 +02:00
|
|
|
import androidx.core.content.ContextCompat.startActivity
|
|
|
|
import com.h.pixeldroid.ProfileActivity
|
2020-04-23 17:48:45 +02:00
|
|
|
import com.h.pixeldroid.api.PixelfedAPI
|
|
|
|
import retrofit2.Call
|
|
|
|
import retrofit2.Callback
|
|
|
|
import retrofit2.Response
|
As a user I want to be able to see posts in a feed (#28)
* Got posts working and linked them to the profile
* added tests for Post
* layout changes
* moved a test file
* refactoring
* refactoring
* 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
* rebased from master
* 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
* rebased from master
* 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
* fixed another merge problem
* trying my best to merge
* removed drawable definition in activity_post.xml
* implements swipe motion
add a new class to implement swipe motion
add the swipe right from home page to display settings
passed the homepage in a fragment
* transform profile activity into fragment
transformed profile activity and layout into fragment
linked it with a swipe motion
* Implement swipeable tabs
* Ask for login on first start, add API endpoints, change profile to show the user's profile
* Started converting Post to a fragment
* got a working feed
* WI
* removed non-valid 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
* 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)
Co-authored-by: Matthieu <61561059+Wv5twkFEKh54vo4tta9yu7dHa3@users.noreply.github.com>
Co-authored-by: Ulysse Widmer <ulysse.widmer@epfl.ch>
2020-03-16 09:38:35 +01:00
|
|
|
import java.io.Serializable
|
2020-03-04 18:04:55 +01:00
|
|
|
|
|
|
|
/*
|
|
|
|
Represents a user and their associated profile.
|
|
|
|
https://docs.joinmastodon.org/entities/account/
|
|
|
|
*/
|
|
|
|
|
|
|
|
data class Account(
|
2020-04-23 17:48:45 +02:00
|
|
|
//Base attributes
|
2020-11-01 18:44:32 +01:00
|
|
|
override val id: String?,
|
|
|
|
val username: String?,
|
|
|
|
val acct: String? = "",
|
|
|
|
val url: String? = "", //HTTPS URL
|
2020-04-23 17:48:45 +02:00
|
|
|
//Display attributes
|
2020-11-01 18:44:32 +01:00
|
|
|
val display_name: String? = "",
|
|
|
|
val note: String? = "", //HTML
|
|
|
|
val avatar: String? = "", //URL
|
|
|
|
val avatar_static: String? = "", //URL
|
|
|
|
val header: String? = "", //URL
|
|
|
|
val header_static: String? = "", //URL
|
|
|
|
val locked: Boolean? = false,
|
2020-04-30 20:01:35 +02:00
|
|
|
val emojis: List<Emoji>? = null,
|
2020-11-01 18:44:32 +01:00
|
|
|
val discoverable: Boolean? = true,
|
2020-04-23 17:48:45 +02:00
|
|
|
//Statistical attributes
|
2020-11-01 18:44:32 +01:00
|
|
|
val created_at: String? = "", //ISO 8601 Datetime (maybe can use a date type)
|
|
|
|
val statuses_count: Int? = 0,
|
|
|
|
val followers_count: Int? = 0,
|
|
|
|
val following_count: Int? = 0,
|
2020-04-23 17:48:45 +02:00
|
|
|
//Optional attributes
|
|
|
|
val moved: Account? = null,
|
|
|
|
val fields: List<Field>? = emptyList(),
|
2020-11-01 18:44:32 +01:00
|
|
|
val bot: Boolean? = false,
|
2020-11-27 17:02:52 +01:00
|
|
|
val source: Source? = null,
|
|
|
|
) : Serializable, FeedContent {
|
2020-04-23 17:48:45 +02:00
|
|
|
companion object {
|
|
|
|
const val ACCOUNT_TAG = "AccountTag"
|
2020-04-24 12:10:25 +02:00
|
|
|
const val ACCOUNT_ID_TAG = "AccountIdTag"
|
2020-09-26 00:25:08 +02:00
|
|
|
const val FOLLOWERS_TAG = "FollowingTag"
|
2020-04-23 17:48:45 +02:00
|
|
|
|
2020-11-01 18:44:32 +01:00
|
|
|
|
2020-04-23 17:48:45 +02:00
|
|
|
/**
|
2020-04-30 17:54:21 +02:00
|
|
|
* @brief Opens an activity of the profile with the given id
|
2020-04-23 17:48:45 +02:00
|
|
|
*/
|
|
|
|
fun getAccountFromId(id: String, api : PixelfedAPI, context: Context, credential: String) {
|
|
|
|
Log.e("ACCOUNT_ID", id)
|
|
|
|
api.getAccount(credential, id).enqueue( object : Callback<Account> {
|
|
|
|
override fun onFailure(call: Call<Account>, t: Throwable) {
|
|
|
|
Log.e("GET ACCOUNT ERROR", t.toString())
|
|
|
|
}
|
|
|
|
|
|
|
|
override fun onResponse(
|
|
|
|
call: Call<Account>,
|
|
|
|
response: Response<Account>
|
|
|
|
) {
|
|
|
|
if(response.code() == 200) {
|
|
|
|
val account = response.body()!!
|
2020-04-09 22:36:59 +02:00
|
|
|
|
2020-09-26 00:25:08 +02:00
|
|
|
//Open the account page in a separate activity
|
2020-04-23 17:48:45 +02:00
|
|
|
account.openProfile(context)
|
|
|
|
} else {
|
|
|
|
Log.e("ERROR CODE", response.code().toString())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
})
|
2020-04-09 22:36:59 +02:00
|
|
|
}
|
2020-04-23 17:48:45 +02:00
|
|
|
}
|
2020-04-10 12:55:02 +02:00
|
|
|
|
2020-11-01 18:44:32 +01:00
|
|
|
fun getDisplayName() : String = when {
|
|
|
|
username.isNullOrBlank() && display_name.isNullOrBlank() -> ""
|
2020-11-02 13:28:27 +01:00
|
|
|
display_name.isNullOrBlank() -> "@$username"
|
|
|
|
else -> display_name.orEmpty()
|
2020-11-01 18:44:32 +01:00
|
|
|
}
|
|
|
|
|
2020-05-01 11:26:18 +02:00
|
|
|
/**
|
|
|
|
* @brief Open profile activity with given account
|
|
|
|
*/
|
2020-04-23 17:48:45 +02:00
|
|
|
fun openProfile(context: Context) {
|
|
|
|
val intent = Intent(context, ProfileActivity::class.java)
|
2020-05-01 11:26:18 +02:00
|
|
|
intent.putExtra(ACCOUNT_TAG, this as Serializable)
|
2020-04-23 17:48:45 +02:00
|
|
|
startActivity(context, intent, null)
|
|
|
|
}
|
2020-04-24 12:10:25 +02:00
|
|
|
}
|