Merge branch 'action_bar_actionify' into 'master'
Action bar actionify See merge request pixeldroid/PixelDroid!248
This commit is contained in:
commit
a769d404a6
|
@ -3,14 +3,13 @@ package com.h.pixeldroid
|
|||
import android.os.Bundle
|
||||
import android.util.Log
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import com.h.pixeldroid.api.PixelfedAPI
|
||||
import com.h.pixeldroid.db.AppDatabase
|
||||
import com.h.pixeldroid.di.PixelfedAPIHolder
|
||||
import com.h.pixeldroid.fragments.feeds.AccountListFragment
|
||||
import com.h.pixeldroid.objects.Account
|
||||
import com.h.pixeldroid.objects.Account.Companion.ACCOUNT_ID_TAG
|
||||
import com.h.pixeldroid.objects.Account.Companion.FOLLOWING_TAG
|
||||
import com.h.pixeldroid.utils.DBUtils
|
||||
import com.h.pixeldroid.objects.Account.Companion.ACCOUNT_TAG
|
||||
import com.h.pixeldroid.objects.Account.Companion.FOLLOWERS_TAG
|
||||
import retrofit2.Call
|
||||
import retrofit2.Callback
|
||||
import retrofit2.Response
|
||||
|
@ -28,13 +27,14 @@ class FollowsActivity : AppCompatActivity() {
|
|||
super.onCreate(savedInstanceState)
|
||||
setContentView(R.layout.activity_followers)
|
||||
(this.application as Pixeldroid).getAppComponent().inject(this)
|
||||
supportActionBar?.setDisplayHomeAsUpEnabled(true)
|
||||
|
||||
|
||||
// Get account id
|
||||
val id = intent.getSerializableExtra(ACCOUNT_ID_TAG) as String?
|
||||
val following = intent.getSerializableExtra(FOLLOWING_TAG) as Boolean
|
||||
val account = intent.getSerializableExtra(ACCOUNT_TAG) as Account?
|
||||
val followers = intent.getSerializableExtra(FOLLOWERS_TAG) as Boolean
|
||||
|
||||
if(id == null) {
|
||||
if(account == null) {
|
||||
val user = db.userDao().getActiveUser()
|
||||
|
||||
val accessToken = user?.accessToken.orEmpty()
|
||||
|
@ -50,18 +50,32 @@ class FollowsActivity : AppCompatActivity() {
|
|||
override fun onResponse(call: Call<Account>, response: Response<Account>) {
|
||||
if(response.code() == 200) {
|
||||
val id = response.body()!!.id
|
||||
launchActivity(id, following)
|
||||
val displayName = response.body()!!.display_name
|
||||
startFragment(id, displayName, followers)
|
||||
}
|
||||
}
|
||||
})
|
||||
} else {
|
||||
launchActivity(id, following)
|
||||
startFragment(account.id, account.display_name, followers)
|
||||
}
|
||||
}
|
||||
|
||||
private fun launchActivity(id : String, following : Boolean) {val arguments = Bundle()
|
||||
override fun onSupportNavigateUp(): Boolean {
|
||||
onBackPressed()
|
||||
return true
|
||||
}
|
||||
|
||||
private fun startFragment(id : String, displayName: String, followers : Boolean) {
|
||||
supportActionBar?.title =
|
||||
if (followers) {
|
||||
getString(R.string.followers_title).format(displayName)
|
||||
} else {
|
||||
getString(R.string.follows_title).format(displayName)
|
||||
}
|
||||
|
||||
val arguments = Bundle()
|
||||
arguments.putSerializable(ACCOUNT_ID_TAG, id)
|
||||
arguments.putSerializable(FOLLOWING_TAG, following)
|
||||
arguments.putSerializable(FOLLOWERS_TAG, followers)
|
||||
followsFragment.arguments = arguments
|
||||
|
||||
supportFragmentManager.beginTransaction()
|
||||
|
|
|
@ -33,6 +33,7 @@ class PostActivity : AppCompatActivity() {
|
|||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
setContentView(R.layout.activity_post)
|
||||
supportActionBar?.setDisplayHomeAsUpEnabled(true)
|
||||
|
||||
(this.application as Pixeldroid).getAppComponent().inject(this)
|
||||
|
||||
|
@ -57,6 +58,11 @@ class PostActivity : AppCompatActivity() {
|
|||
}
|
||||
}
|
||||
|
||||
override fun onSupportNavigateUp(): Boolean {
|
||||
onBackPressed()
|
||||
return true
|
||||
}
|
||||
|
||||
private fun getDiscoverPost(
|
||||
arguments: Bundle,
|
||||
discoverPost: DiscoverPost
|
||||
|
@ -80,6 +86,7 @@ class PostActivity : AppCompatActivity() {
|
|||
}
|
||||
|
||||
private fun initializeFragment(arguments: Bundle, status: Status?){
|
||||
supportActionBar?.title = getString(R.string.post_title).format(status!!.account?.display_name)
|
||||
arguments.putSerializable(POST_TAG, status)
|
||||
postFragment.arguments = arguments
|
||||
supportFragmentManager.beginTransaction()
|
||||
|
|
|
@ -19,10 +19,8 @@ import com.h.pixeldroid.api.PixelfedAPI
|
|||
import com.h.pixeldroid.db.AppDatabase
|
||||
import com.h.pixeldroid.di.PixelfedAPIHolder
|
||||
import com.h.pixeldroid.objects.Account
|
||||
import com.h.pixeldroid.objects.Account.Companion.ACCOUNT_TAG
|
||||
import com.h.pixeldroid.objects.Relationship
|
||||
import com.h.pixeldroid.objects.Status
|
||||
import com.h.pixeldroid.utils.DBUtils
|
||||
import com.h.pixeldroid.utils.HtmlUtils.Companion.parseHTMLText
|
||||
import com.h.pixeldroid.utils.ImageConverter
|
||||
import retrofit2.Call
|
||||
|
@ -47,6 +45,7 @@ class ProfileActivity : AppCompatActivity() {
|
|||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
setContentView(R.layout.activity_profile)
|
||||
supportActionBar?.setDisplayHomeAsUpEnabled(true)
|
||||
|
||||
(this.application as Pixeldroid).getAppComponent().inject(this)
|
||||
|
||||
|
@ -65,9 +64,14 @@ class ProfileActivity : AppCompatActivity() {
|
|||
setContent()
|
||||
}
|
||||
|
||||
override fun onSupportNavigateUp(): Boolean {
|
||||
onBackPressed()
|
||||
return true
|
||||
}
|
||||
|
||||
private fun setContent() {
|
||||
// Set profile according to given account
|
||||
account = intent.getSerializableExtra(ACCOUNT_TAG) as Account?
|
||||
account = intent.getSerializableExtra(Account.ACCOUNT_TAG) as Account?
|
||||
|
||||
account?.let {
|
||||
setViews()
|
||||
|
@ -108,14 +112,26 @@ class ProfileActivity : AppCompatActivity() {
|
|||
*/
|
||||
private fun setViews() {
|
||||
val profilePicture = findViewById<ImageView>(R.id.profilePictureImageView)
|
||||
ImageConverter.setRoundImageFromURL(View(applicationContext), account!!.avatar, profilePicture)
|
||||
ImageConverter.setRoundImageFromURL(
|
||||
View(applicationContext),
|
||||
account!!.avatar,
|
||||
profilePicture
|
||||
)
|
||||
|
||||
val description = findViewById<TextView>(R.id.descriptionTextView)
|
||||
description.text = parseHTMLText(account!!.note, emptyList(), pixelfedAPI,
|
||||
applicationContext, "Bearer $accessToken")
|
||||
description.text = parseHTMLText(
|
||||
account!!.note, emptyList(), pixelfedAPI,
|
||||
applicationContext, "Bearer $accessToken"
|
||||
)
|
||||
|
||||
val accountName = findViewById<TextView>(R.id.accountNameTextView)
|
||||
accountName.text = account!!.display_name
|
||||
|
||||
supportActionBar?.title = account!!.display_name
|
||||
if(account!!.display_name != account!!.acct){
|
||||
supportActionBar?.subtitle = "@${account!!.acct}"
|
||||
}
|
||||
|
||||
accountName.setTypeface(null, Typeface.BOLD)
|
||||
|
||||
val nbPosts = findViewById<TextView>(R.id.nbPostsTextView)
|
||||
|
@ -141,17 +157,20 @@ class ProfileActivity : AppCompatActivity() {
|
|||
pixelfedAPI.accountPosts("Bearer $accessToken", account_id = account!!.id)
|
||||
.enqueue(object : Callback<List<Status>> {
|
||||
|
||||
override fun onFailure(call: Call<List<Status>>, t: Throwable) {
|
||||
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)
|
||||
override fun onFailure(call: Call<List<Status>>, t: Throwable) {
|
||||
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)
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
private fun onClickEditButton() {
|
||||
|
@ -167,7 +186,7 @@ class ProfileActivity : AppCompatActivity() {
|
|||
|
||||
private fun onClickFollowers() {
|
||||
val intent = Intent(this, FollowsActivity::class.java)
|
||||
intent.putExtra(Account.FOLLOWING_TAG, true)
|
||||
intent.putExtra(Account.FOLLOWERS_TAG, true)
|
||||
intent.putExtra(Account.ACCOUNT_ID_TAG, account?.id)
|
||||
|
||||
ContextCompat.startActivity(this, intent, null)
|
||||
|
@ -175,8 +194,8 @@ class ProfileActivity : AppCompatActivity() {
|
|||
|
||||
private fun onClickFollowing() {
|
||||
val intent = Intent(this, FollowsActivity::class.java)
|
||||
intent.putExtra(Account.FOLLOWING_TAG, false)
|
||||
intent.putExtra(Account.ACCOUNT_ID_TAG, account?.id)
|
||||
intent.putExtra(Account.FOLLOWERS_TAG, false)
|
||||
intent.putExtra(Account.ACCOUNT_TAG, account)
|
||||
|
||||
ContextCompat.startActivity(this, intent, null)
|
||||
}
|
||||
|
@ -189,86 +208,104 @@ class ProfileActivity : AppCompatActivity() {
|
|||
pixelfedAPI.checkRelationships("Bearer $accessToken", listOf(account!!.id))
|
||||
.enqueue(object : Callback<List<Relationship>> {
|
||||
|
||||
override fun onFailure(call: Call<List<Relationship>>, t: Throwable) {
|
||||
Log.e("FOLLOW ERROR", t.toString())
|
||||
Toast.makeText(applicationContext,getString(R.string.follow_status_failed),
|
||||
Toast.LENGTH_SHORT).show()
|
||||
}
|
||||
|
||||
override fun onResponse(call: Call<List<Relationship>>, response: Response<List<Relationship>>) {
|
||||
if(response.code() == 200) {
|
||||
if(response.body()!!.isNotEmpty()) {
|
||||
val followButton = findViewById<Button>(R.id.followButton)
|
||||
|
||||
if (response.body()!![0].following) {
|
||||
followButton.text = "Unfollow"
|
||||
setOnClickUnfollow()
|
||||
} else {
|
||||
followButton.text = "Follow"
|
||||
setOnClickFollow()
|
||||
}
|
||||
followButton.visibility = View.VISIBLE
|
||||
}
|
||||
} else {
|
||||
Toast.makeText(applicationContext, getString(R.string.follow_button_failed),
|
||||
Toast.LENGTH_SHORT).show()
|
||||
override fun onFailure(call: Call<List<Relationship>>, t: Throwable) {
|
||||
Log.e("FOLLOW ERROR", t.toString())
|
||||
Toast.makeText(
|
||||
applicationContext, getString(R.string.follow_status_failed),
|
||||
Toast.LENGTH_SHORT
|
||||
).show()
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
override fun onResponse(
|
||||
call: Call<List<Relationship>>,
|
||||
response: Response<List<Relationship>>
|
||||
) {
|
||||
if (response.code() == 200) {
|
||||
if (response.body()!!.isNotEmpty()) {
|
||||
val followButton = findViewById<Button>(R.id.followButton)
|
||||
|
||||
if (response.body()!![0].following) {
|
||||
setOnClickUnfollow()
|
||||
} else {
|
||||
setOnClickFollow()
|
||||
}
|
||||
followButton.visibility = View.VISIBLE
|
||||
}
|
||||
} else {
|
||||
Toast.makeText(
|
||||
applicationContext, getString(R.string.follow_button_failed),
|
||||
Toast.LENGTH_SHORT
|
||||
).show()
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
private fun setOnClickFollow() {
|
||||
val followButton = findViewById<Button>(R.id.followButton)
|
||||
|
||||
followButton.setText(R.string.follow)
|
||||
|
||||
followButton.setOnClickListener {
|
||||
pixelfedAPI.follow(account!!.id, "Bearer $accessToken")
|
||||
.enqueue(object : Callback<Relationship> {
|
||||
|
||||
override fun onFailure(call: Call<Relationship>, t: Throwable) {
|
||||
Log.e("FOLLOW ERROR", t.toString())
|
||||
Toast.makeText(applicationContext, getString(R.string.follow_error),
|
||||
Toast.LENGTH_SHORT).show()
|
||||
}
|
||||
|
||||
override fun onResponse(
|
||||
call: Call<Relationship>,
|
||||
response: Response<Relationship>
|
||||
) {
|
||||
if (response.code() == 200) {
|
||||
followButton.text = "Unfollow"
|
||||
setOnClickUnfollow()
|
||||
} else if (response.code() == 403) {
|
||||
Toast.makeText(applicationContext, getString(R.string.action_not_allowed),
|
||||
Toast.LENGTH_SHORT).show()
|
||||
override fun onFailure(call: Call<Relationship>, t: Throwable) {
|
||||
Log.e("FOLLOW ERROR", t.toString())
|
||||
Toast.makeText(
|
||||
applicationContext, getString(R.string.follow_error),
|
||||
Toast.LENGTH_SHORT
|
||||
).show()
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
override fun onResponse(
|
||||
call: Call<Relationship>,
|
||||
response: Response<Relationship>
|
||||
) {
|
||||
if (response.code() == 200) {
|
||||
setOnClickUnfollow()
|
||||
} else if (response.code() == 403) {
|
||||
Toast.makeText(
|
||||
applicationContext, getString(R.string.action_not_allowed),
|
||||
Toast.LENGTH_SHORT
|
||||
).show()
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
private fun setOnClickUnfollow() {
|
||||
val followButton = findViewById<Button>(R.id.followButton)
|
||||
|
||||
followButton.setText(R.string.unfollow)
|
||||
|
||||
followButton.setOnClickListener {
|
||||
pixelfedAPI.unfollow(account!!.id, "Bearer $accessToken")
|
||||
.enqueue(object : Callback<Relationship> {
|
||||
|
||||
override fun onFailure(call: Call<Relationship>, t: Throwable) {
|
||||
Log.e("UNFOLLOW ERROR", t.toString())
|
||||
Toast.makeText(applicationContext, getString(R.string.unfollow_error),
|
||||
Toast.LENGTH_SHORT).show()
|
||||
}
|
||||
|
||||
override fun onResponse(call: Call<Relationship>, response: Response<Relationship>) {
|
||||
if (response.code() == 200) {
|
||||
followButton.text = "Follow"
|
||||
setOnClickFollow()
|
||||
} else if (response.code() == 401) {
|
||||
Toast.makeText(applicationContext, getString(R.string.access_token_invalid),
|
||||
Toast.LENGTH_SHORT).show()
|
||||
override fun onFailure(call: Call<Relationship>, t: Throwable) {
|
||||
Log.e("UNFOLLOW ERROR", t.toString())
|
||||
Toast.makeText(
|
||||
applicationContext, getString(R.string.unfollow_error),
|
||||
Toast.LENGTH_SHORT
|
||||
).show()
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
override fun onResponse(
|
||||
call: Call<Relationship>,
|
||||
response: Response<Relationship>
|
||||
) {
|
||||
if (response.code() == 200) {
|
||||
setOnClickFollow()
|
||||
} else if (response.code() == 401) {
|
||||
Toast.makeText(
|
||||
applicationContext, getString(R.string.access_token_invalid),
|
||||
Toast.LENGTH_SHORT
|
||||
).show()
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
|
@ -51,7 +51,6 @@ class PostFragment : Fragment() {
|
|||
|
||||
val user = db.userDao().getActiveUser()
|
||||
|
||||
val domain = user?.instance_uri.orEmpty()
|
||||
val accessToken = user?.accessToken.orEmpty()
|
||||
val api = apiHolder.api ?: apiHolder.setDomainToCurrentUser(db)
|
||||
|
||||
|
|
|
@ -23,7 +23,7 @@ import com.bumptech.glide.util.ViewPreloadSizeProvider
|
|||
import com.h.pixeldroid.R
|
||||
import com.h.pixeldroid.objects.Account
|
||||
import com.h.pixeldroid.objects.Account.Companion.ACCOUNT_ID_TAG
|
||||
import com.h.pixeldroid.objects.Account.Companion.FOLLOWING_TAG
|
||||
import com.h.pixeldroid.objects.Account.Companion.FOLLOWERS_TAG
|
||||
import kotlinx.android.synthetic.main.account_list_entry.view.*
|
||||
import retrofit2.Call
|
||||
import retrofit2.Callback
|
||||
|
@ -78,7 +78,7 @@ open class AccountListFragment : FeedFragment() {
|
|||
|
||||
internal open fun makeContent(): LiveData<PagedList<Account>> {
|
||||
val id = arguments?.getSerializable(ACCOUNT_ID_TAG) as String
|
||||
val following = arguments?.getSerializable(FOLLOWING_TAG) as Boolean
|
||||
val following = arguments?.getSerializable(FOLLOWERS_TAG) as Boolean
|
||||
|
||||
val config: PagedList.Config = PagedList.Config.Builder().setPageSize(10).build()
|
||||
val dataSource = AccountListDataSource(following, id)
|
||||
|
|
|
@ -46,7 +46,7 @@ data class Account(
|
|||
companion object {
|
||||
const val ACCOUNT_TAG = "AccountTag"
|
||||
const val ACCOUNT_ID_TAG = "AccountIdTag"
|
||||
const val FOLLOWING_TAG = "FollowingTag"
|
||||
const val FOLLOWERS_TAG = "FollowingTag"
|
||||
|
||||
/**
|
||||
* @brief Opens an activity of the profile with the given id
|
||||
|
@ -65,7 +65,7 @@ data class Account(
|
|||
if(response.code() == 200) {
|
||||
val account = response.body()!!
|
||||
|
||||
//Open the account page in a seperate activity
|
||||
//Open the account page in a separate activity
|
||||
account.openProfile(context)
|
||||
} else {
|
||||
Log.e("ERROR CODE", response.code().toString())
|
||||
|
|
|
@ -97,6 +97,7 @@
|
|||
<string name="default_nfollowing">-\nFollowing</string>
|
||||
<string name="no_username">No Username</string>
|
||||
<string name="follow">Follow</string>
|
||||
<string name="unfollow">Unfollow</string>
|
||||
<string name="edit_profile">Edit profile</string>
|
||||
<!-- Search page -->
|
||||
<string name="search">Search</string>
|
||||
|
@ -117,4 +118,9 @@
|
|||
<string name="project_website">Project website: https://pixeldroid.org</string>
|
||||
<string name="license_info">PixelDroid is free and open source software, licensed under the GNU General Public License (version 3 or later)</string>
|
||||
<string name="about">About</string>
|
||||
<string name="post_title">%1$s\'s post</string>
|
||||
<string name="followers_title">%1$s\'s followers</string>
|
||||
<string name="follows_title">%1$s\'s follows</string>
|
||||
|
||||
|
||||
</resources>
|
Loading…
Reference in New Issue