55 lines
2.1 KiB
Kotlin
55 lines
2.1 KiB
Kotlin
package ch.dissem.apps.abit.drawer
|
|
|
|
import android.content.Context
|
|
import android.content.Intent
|
|
import androidx.fragment.app.FragmentManager
|
|
import android.view.View
|
|
import android.widget.Toast
|
|
import android.widget.Toast.LENGTH_LONG
|
|
import ch.dissem.apps.abit.*
|
|
import ch.dissem.apps.abit.dialog.AddIdentityDialogFragment
|
|
import ch.dissem.apps.abit.service.Singleton
|
|
import ch.dissem.bitmessage.entity.BitmessageAddress
|
|
import com.mikepenz.materialdrawer.AccountHeader
|
|
import com.mikepenz.materialdrawer.model.ProfileDrawerItem
|
|
import com.mikepenz.materialdrawer.model.interfaces.IProfile
|
|
|
|
class ProfileSelectionListener(
|
|
private val ctx: Context,
|
|
private val fragmentManager: FragmentManager
|
|
) : AccountHeader.OnAccountHeaderListener {
|
|
|
|
override fun onProfileChanged(view: View, profile: IProfile<*>, current: Boolean): Boolean {
|
|
when (profile.identifier.toInt()) {
|
|
MainActivity.ADD_IDENTITY -> addIdentityDialog()
|
|
MainActivity.MANAGE_IDENTITY -> {
|
|
val identity = Singleton.getIdentity(ctx)
|
|
if (identity == null) {
|
|
Toast.makeText(ctx, R.string.no_identity_warning, LENGTH_LONG).show()
|
|
} else {
|
|
val show = Intent(ctx, AddressDetailActivity::class.java)
|
|
show.putExtra(AddressDetailFragment.ARG_ITEM, identity)
|
|
ctx.startActivity(show)
|
|
}
|
|
}
|
|
else -> if (profile is ProfileDrawerItem) {
|
|
val tag = profile.tag
|
|
if (tag is BitmessageAddress) {
|
|
Singleton.setIdentity(tag)
|
|
MainActivity.apply {
|
|
updateUnread()
|
|
val itemList = supportFragmentManager.findFragmentById(R.id.item_list)
|
|
if (itemList is ListHolder<*>) {
|
|
itemList.reloadList()
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
// false if it should close the drawer
|
|
return false
|
|
}
|
|
|
|
private fun addIdentityDialog() = AddIdentityDialogFragment().show(fragmentManager, "dialog")
|
|
}
|