social-aggregator/app/src/main/java/pl/edu/amu/wmi/socialaggregator/activity/AddSocialActivity.kt

57 lines
2.2 KiB
Kotlin

package pl.edu.amu.wmi.socialaggregator.activity
import android.os.Bundle
import android.widget.Toast
import androidx.appcompat.app.AppCompatActivity
import androidx.recyclerview.widget.LinearLayoutManager
import kotlinx.android.synthetic.main.activity_add_social.*
import kotlinx.android.synthetic.main.content_add_social.*
import pl.edu.amu.wmi.socialaggregator.R
import pl.edu.amu.wmi.socialaggregator.utils.SocialPlatformsManager
import pl.edu.amu.wmi.socialaggregator.viewholders.SocialWithImageRecycler
class AddSocialActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_add_social)
setSupportActionBar(toolbar)
supportActionBar?.setDisplayHomeAsUpEnabled(true)
val notLoggedInSocials = SocialPlatformsManager.getNotLoggedIn(this)
val loggedInSocials = SocialPlatformsManager.getLoggedIn(this)
val recyclers = mutableListOf(availableSocialsRecyclerView, addSocialRecyclerView)
availableSocialsRecyclerView.apply {
layoutManager = LinearLayoutManager(this@AddSocialActivity)
adapter = SocialWithImageRecycler(
loggedInSocials,
R.mipmap.ic_opaque_remove
) {
it.logout(context)
loggedInSocials.remove(it)
notLoggedInSocials.add(it)
recyclers.forEach { it.adapter?.notifyDataSetChanged() }
Toast.makeText(context, "Logged out from ${it.getName()}!", Toast.LENGTH_SHORT).show()
}
}
addSocialRecyclerView.apply {
layoutManager = LinearLayoutManager(this@AddSocialActivity)
adapter = SocialWithImageRecycler(
notLoggedInSocials,
R.mipmap.ic_opaque_add
) {
it.login(context)
notLoggedInSocials.remove(it)
loggedInSocials.add(it)
recyclers.forEach { it.adapter?.notifyDataSetChanged() }
Toast.makeText(context, "Logged in to ${it.getName()}!", Toast.LENGTH_SHORT).show()
}
}
}
}