From 4204b45f2c61065408bf69bf06a4e7b134072f52 Mon Sep 17 00:00:00 2001 From: Felix Ableitner Date: Fri, 11 Sep 2015 16:18:01 +0200 Subject: [PATCH] Moved "my address" from settings to main activity menu. --- app/src/main/res/menu/main.xml | 4 ++++ app/src/main/res/xml/settings.xml | 4 ---- .../ensichat/fragments/ContactsFragment.scala | 14 +++++++++++++- .../ensichat/fragments/IdenticonFragment.scala | 15 ++------------- .../ensichat/fragments/SettingsFragment.scala | 18 +----------------- .../nutomic/ensichat/views/UsersAdapter.scala | 7 ++++++- 6 files changed, 26 insertions(+), 36 deletions(-) diff --git a/app/src/main/res/menu/main.xml b/app/src/main/res/menu/main.xml index c8a7f3c..43fbf21 100644 --- a/app/src/main/res/menu/main.xml +++ b/app/src/main/res/menu/main.xml @@ -13,6 +13,10 @@ android:id="@+id/share_app" android:title="@string/share_app" /> + + diff --git a/app/src/main/res/xml/settings.xml b/app/src/main/res/xml/settings.xml index 8ca232d..bdb49c5 100644 --- a/app/src/main/res/xml/settings.xml +++ b/app/src/main/res/xml/settings.xml @@ -10,10 +10,6 @@ android:title="@string/user_status" android:key="user_status" /> - - + val prefs = PreferenceManager.getDefaultSharedPreferences(getActivity) + val fragment = new IdenticonFragment() + val bundle = new Bundle() + bundle.putString( + IdenticonFragment.ExtraAddress, new Crypto(getActivity).localAddress.toString) + bundle.putString( + IdenticonFragment.ExtraUserName, prefs.getString(SettingsFragment.KeyUserName, "")) + fragment.setArguments(bundle) + fragment.show(getFragmentManager, "dialog") + true case R.id.settings => startActivity(new Intent(getActivity, classOf[SettingsActivity])) true diff --git a/app/src/main/scala/com/nutomic/ensichat/fragments/IdenticonFragment.scala b/app/src/main/scala/com/nutomic/ensichat/fragments/IdenticonFragment.scala index 3c55c1f..31ee33f 100644 --- a/app/src/main/scala/com/nutomic/ensichat/fragments/IdenticonFragment.scala +++ b/app/src/main/scala/com/nutomic/ensichat/fragments/IdenticonFragment.scala @@ -9,18 +9,8 @@ import com.nutomic.ensichat.protocol.Address import com.nutomic.ensichat.util.IdenticonGenerator object IdenticonFragment { - private val ExtraAddress = "address" - private val ExtraUserName = "user_name" - - def getInstance(address: Address, userName: String): IdenticonFragment = { - val bundle = new Bundle() - bundle.putString(IdenticonFragment.ExtraAddress, address.toString) - bundle.putString(IdenticonFragment.ExtraUserName, userName) - - val fragment = new IdenticonFragment() - fragment.setArguments(bundle) - fragment - } + val ExtraAddress = "address" + val ExtraUserName = "user_name" } /** @@ -33,7 +23,6 @@ class IdenticonFragment extends DialogFragment { private lazy val address = new Address(getArguments.getString(IdenticonFragment.ExtraAddress)) private lazy val userName = getArguments.getString(IdenticonFragment.ExtraUserName) - override def onCreateView(inflater: LayoutInflater, container: ViewGroup, savedInstanceState: Bundle): View = { getDialog.setTitle(userName) diff --git a/app/src/main/scala/com/nutomic/ensichat/fragments/SettingsFragment.scala b/app/src/main/scala/com/nutomic/ensichat/fragments/SettingsFragment.scala index 2b9248e..112c696 100644 --- a/app/src/main/scala/com/nutomic/ensichat/fragments/SettingsFragment.scala +++ b/app/src/main/scala/com/nutomic/ensichat/fragments/SettingsFragment.scala @@ -15,7 +15,6 @@ object SettingsFragment { val KeyUserName = "user_name" val KeyUserStatus = "user_status" - val KeyMyAddress = "my_address" val KeyScanInterval = "scan_interval_seconds" val MaxConnections = "max_connections" val Version = "version" @@ -25,14 +24,12 @@ object SettingsFragment { /** * Settings screen. */ -class SettingsFragment extends PreferenceFragment with OnPreferenceChangeListener - with OnPreferenceClickListener { +class SettingsFragment extends PreferenceFragment with OnPreferenceChangeListener { private lazy val database = new Database(getActivity) private lazy val name = findPreference(KeyUserName) private lazy val status = findPreference(KeyUserStatus) - private lazy val myAddress = findPreference(KeyMyAddress) private lazy val scanInterval = findPreference(KeyScanInterval) private lazy val maxConnections = findPreference(MaxConnections) private lazy val version = findPreference(Version) @@ -48,7 +45,6 @@ class SettingsFragment extends PreferenceFragment with OnPreferenceChangeListene name.setOnPreferenceChangeListener(this) status.setSummary(prefs.getString(KeyUserStatus, "")) status.setOnPreferenceChangeListener(this) - myAddress.setOnPreferenceClickListener(this) scanInterval.setOnPreferenceChangeListener(this) scanInterval.setSummary(prefs.getString( @@ -79,16 +75,4 @@ class SettingsFragment extends PreferenceFragment with OnPreferenceChangeListene true } - override def onPreferenceClick (preference: Preference): Boolean = { - preference.getKey match { - case KeyMyAddress => - val fragment = IdenticonFragment.getInstance(new Crypto(getActivity).localAddress, - prefs.getString(KeyUserName, "")) - fragment.show(getFragmentManager, "dialog") - true - case _ => - false - } - } - } diff --git a/app/src/main/scala/com/nutomic/ensichat/views/UsersAdapter.scala b/app/src/main/scala/com/nutomic/ensichat/views/UsersAdapter.scala index 63ea747..a1e93c4 100644 --- a/app/src/main/scala/com/nutomic/ensichat/views/UsersAdapter.scala +++ b/app/src/main/scala/com/nutomic/ensichat/views/UsersAdapter.scala @@ -2,6 +2,7 @@ package com.nutomic.ensichat.views import android.app.Activity import android.content.Context +import android.os.Bundle import android.view.View.OnClickListener import android.view.{LayoutInflater, View, ViewGroup} import android.widget.{ArrayAdapter, ImageView, TextView} @@ -39,7 +40,11 @@ class UsersAdapter(activity: Activity) extends ArrayAdapter[User](activity, 0) w override def onClick (v: View): Unit = { val user = v.getTag.asInstanceOf[User] - val fragment = IdenticonFragment.getInstance(user.address, user.name) + val fragment = new IdenticonFragment() + val bundle = new Bundle() + bundle.putString(IdenticonFragment.ExtraAddress, user.address.toString) + bundle.putString(IdenticonFragment.ExtraUserName, user.name) + fragment.setArguments(bundle) fragment.show(activity.getFragmentManager, "dialog") }