AccountDetailsFragment.kt (3484B)
1 /* 2 This file is part of GNUnet. 3 Copyright (C) 2021--2025 GNUnet e.V. 4 5 GNUnet is free software: you can redistribute it and/or modify it 6 under the terms of the GNU Affero General Public License as published 7 by the Free Software Foundation, either version 3 of the License, 8 or (at your option) any later version. 9 10 GNUnet is distributed in the hope that it will be useful, but 11 WITHOUT ANY WARRANTY; without even the implied warranty of 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 Affero General Public License for more details. 14 15 You should have received a copy of the GNU Affero General Public License 16 along with this program. If not, see <http://www.gnu.org/licenses/>. 17 18 SPDX-License-Identifier: AGPL3.0-or-later 19 */ 20 /* 21 * @author t3sserakt 22 * @file GNUnetMessenger/app/src/main/java/org/gnunet/gnunetmessenger/ui/account/AccountDetailsFragment.kt 23 */ 24 25 package org.gnunet.gnunetmessenger.ui.account 26 27 import android.os.Bundle 28 import android.graphics.BitmapFactory 29 import android.view.LayoutInflater 30 import android.view.View 31 import android.view.ViewGroup 32 import androidx.lifecycle.lifecycleScope 33 import androidx.navigation.fragment.findNavController 34 import kotlinx.coroutines.launch 35 import org.gnunet.gnunetmessenger.MainActivity 36 import org.gnunet.gnunetmessenger.R 37 import org.gnunet.gnunetmessenger.ui.BaseProfileFragment 38 import org.gnunet.gnunetmessenger.util.AvatarStorageUtil 39 40 class AccountDetailsFragment : BaseProfileFragment() { 41 42 override fun onCreateView( 43 inflater: LayoutInflater, container: ViewGroup?, 44 savedInstanceState: Bundle? 45 ): View { 46 return inflater.inflate(R.layout.fragment_profile_base, container, false) 47 } 48 49 override fun setupUI() { 50 val activity = requireActivity() as MainActivity 51 val gnunetChat = activity.getGnunetChatInstance() 52 val handle = activity.getChatHandle() 53 54 55 viewLifecycleOwner.lifecycleScope.launch { 56 try { 57 nameEdit.setText(gnunetChat.getProfileName(handle)) 58 } catch (t: Throwable) { 59 // optional: Fehlermeldung / Toast 60 } 61 } 62 nameText.visibility = View.GONE 63 nameEdit.visibility = View.VISIBLE 64 saveNameButton.visibility = View.VISIBLE 65 66 67 saveNameButton.setOnClickListener { 68 val newName = nameEdit.text.toString() 69 viewLifecycleOwner.lifecycleScope.launch { 70 try { 71 gnunetChat.setProfileName(handle, newName) 72 } catch (t: Throwable) { 73 // optional: Fehlermeldung / Toast 74 } 75 } 76 } 77 78 val avatar = AvatarStorageUtil.loadAvatar(requireContext(), gnunetChat.getProfileKey(handle)) 79 avatarImage.setImageBitmap(avatar ?: BitmapFactory.decodeResource(resources, R.drawable.ic_account_circle)) 80 81 shareIdentityButton.setOnClickListener { 82 val action = AccountDetailsFragmentDirections.actionAccountDetailsFragmentToLobbyDisplayFragment( 83 lobbyId = gnunetChat.getProfileKey(handle), 84 lifetime = "0" 85 ) 86 findNavController().navigate(action) 87 } 88 89 /*listAttributesButton.setOnClickListener { 90 val action = AccountDetailsFragmentDirections 91 .actionAccountDetailsFragmentToAttributeListFragment(null, editable = true) 92 findNavController().navigate(action) 93 }*/ 94 } 95 }