Moved "my address" from settings to main activity menu.

This commit is contained in:
Felix Ableitner 2015-09-11 16:18:01 +02:00
parent 0a61af733e
commit 4204b45f2c
6 changed files with 26 additions and 36 deletions

View file

@ -13,6 +13,10 @@
android:id="@+id/share_app" android:id="@+id/share_app"
android:title="@string/share_app" /> android:title="@string/share_app" />
<item
android:id="@+id/my_address"
android:title="@string/my_address" />
<item <item
android:id="@+id/settings" android:id="@+id/settings"
android:title="@string/settings" /> android:title="@string/settings" />

View file

@ -10,10 +10,6 @@
android:title="@string/user_status" android:title="@string/user_status"
android:key="user_status" /> android:key="user_status" />
<Preference
android:title="@string/my_address"
android:key="my_address" />
<CheckBoxPreference <CheckBoxPreference
android:title="@string/notification_sounds" android:title="@string/notification_sounds"
android:key="notification_sounds" android:key="notification_sounds"

View file

@ -6,12 +6,13 @@ import android.app.ListFragment
import android.content.{IntentFilter, Context, BroadcastReceiver, Intent} import android.content.{IntentFilter, Context, BroadcastReceiver, Intent}
import android.net.Uri import android.net.Uri
import android.os.Bundle import android.os.Bundle
import android.preference.PreferenceManager
import android.support.v4.content.LocalBroadcastManager import android.support.v4.content.LocalBroadcastManager
import android.view._ import android.view._
import android.widget.ListView import android.widget.ListView
import com.nutomic.ensichat.R import com.nutomic.ensichat.R
import com.nutomic.ensichat.activities.{AddContactsActivity, EnsichatActivity, MainActivity, SettingsActivity} import com.nutomic.ensichat.activities.{AddContactsActivity, EnsichatActivity, MainActivity, SettingsActivity}
import com.nutomic.ensichat.protocol.ChatService import com.nutomic.ensichat.protocol.{Crypto, ChatService}
import com.nutomic.ensichat.util.Database import com.nutomic.ensichat.util.Database
import com.nutomic.ensichat.views.UsersAdapter import com.nutomic.ensichat.views.UsersAdapter
import scala.collection.JavaConversions._ import scala.collection.JavaConversions._
@ -65,6 +66,17 @@ class ContactsFragment extends ListFragment {
intent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(new File(ai.get.sourceDir))) intent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(new File(ai.get.sourceDir)))
startActivity(intent) startActivity(intent)
true true
case R.id.my_address =>
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 => case R.id.settings =>
startActivity(new Intent(getActivity, classOf[SettingsActivity])) startActivity(new Intent(getActivity, classOf[SettingsActivity]))
true true

View file

@ -9,18 +9,8 @@ import com.nutomic.ensichat.protocol.Address
import com.nutomic.ensichat.util.IdenticonGenerator import com.nutomic.ensichat.util.IdenticonGenerator
object IdenticonFragment { object IdenticonFragment {
private val ExtraAddress = "address" val ExtraAddress = "address"
private val ExtraUserName = "user_name" 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
}
} }
/** /**
@ -33,7 +23,6 @@ class IdenticonFragment extends DialogFragment {
private lazy val address = new Address(getArguments.getString(IdenticonFragment.ExtraAddress)) private lazy val address = new Address(getArguments.getString(IdenticonFragment.ExtraAddress))
private lazy val userName = getArguments.getString(IdenticonFragment.ExtraUserName) private lazy val userName = getArguments.getString(IdenticonFragment.ExtraUserName)
override def onCreateView(inflater: LayoutInflater, container: ViewGroup, override def onCreateView(inflater: LayoutInflater, container: ViewGroup,
savedInstanceState: Bundle): View = { savedInstanceState: Bundle): View = {
getDialog.setTitle(userName) getDialog.setTitle(userName)

View file

@ -15,7 +15,6 @@ object SettingsFragment {
val KeyUserName = "user_name" val KeyUserName = "user_name"
val KeyUserStatus = "user_status" val KeyUserStatus = "user_status"
val KeyMyAddress = "my_address"
val KeyScanInterval = "scan_interval_seconds" val KeyScanInterval = "scan_interval_seconds"
val MaxConnections = "max_connections" val MaxConnections = "max_connections"
val Version = "version" val Version = "version"
@ -25,14 +24,12 @@ object SettingsFragment {
/** /**
* Settings screen. * Settings screen.
*/ */
class SettingsFragment extends PreferenceFragment with OnPreferenceChangeListener class SettingsFragment extends PreferenceFragment with OnPreferenceChangeListener {
with OnPreferenceClickListener {
private lazy val database = new Database(getActivity) private lazy val database = new Database(getActivity)
private lazy val name = findPreference(KeyUserName) private lazy val name = findPreference(KeyUserName)
private lazy val status = findPreference(KeyUserStatus) private lazy val status = findPreference(KeyUserStatus)
private lazy val myAddress = findPreference(KeyMyAddress)
private lazy val scanInterval = findPreference(KeyScanInterval) private lazy val scanInterval = findPreference(KeyScanInterval)
private lazy val maxConnections = findPreference(MaxConnections) private lazy val maxConnections = findPreference(MaxConnections)
private lazy val version = findPreference(Version) private lazy val version = findPreference(Version)
@ -48,7 +45,6 @@ class SettingsFragment extends PreferenceFragment with OnPreferenceChangeListene
name.setOnPreferenceChangeListener(this) name.setOnPreferenceChangeListener(this)
status.setSummary(prefs.getString(KeyUserStatus, "")) status.setSummary(prefs.getString(KeyUserStatus, ""))
status.setOnPreferenceChangeListener(this) status.setOnPreferenceChangeListener(this)
myAddress.setOnPreferenceClickListener(this)
scanInterval.setOnPreferenceChangeListener(this) scanInterval.setOnPreferenceChangeListener(this)
scanInterval.setSummary(prefs.getString( scanInterval.setSummary(prefs.getString(
@ -79,16 +75,4 @@ class SettingsFragment extends PreferenceFragment with OnPreferenceChangeListene
true 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
}
}
} }

View file

@ -2,6 +2,7 @@ package com.nutomic.ensichat.views
import android.app.Activity import android.app.Activity
import android.content.Context import android.content.Context
import android.os.Bundle
import android.view.View.OnClickListener import android.view.View.OnClickListener
import android.view.{LayoutInflater, View, ViewGroup} import android.view.{LayoutInflater, View, ViewGroup}
import android.widget.{ArrayAdapter, ImageView, TextView} 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 = { override def onClick (v: View): Unit = {
val user = v.getTag.asInstanceOf[User] 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") fragment.show(activity.getFragmentManager, "dialog")
} }