Commit f9e504b0 authored by Mygod's avatar Mygod

Refine profile name display

parent eae97bc1
...@@ -78,7 +78,7 @@ trait BaseService extends Service { ...@@ -78,7 +78,7 @@ trait BaseService extends Service {
state state
} }
override def getProfileName: String = if (profile == null) null else profile.name override def getProfileName: String = if (profile == null) null else profile.getName
override def unregisterCallback(cb: IShadowsocksServiceCallback) { override def unregisterCallback(cb: IShadowsocksServiceCallback) {
if (cb != null && callbacks.unregister(cb)) { if (cb != null && callbacks.unregister(cb)) {
......
...@@ -23,7 +23,7 @@ package com.github.shadowsocks ...@@ -23,7 +23,7 @@ package com.github.shadowsocks
import java.util.GregorianCalendar import java.util.GregorianCalendar
import android.content._ import android.content._
import android.os.{Build, Bundle, Handler, UserManager} import android.os.{Bundle, Handler}
import android.support.v4.content.LocalBroadcastManager import android.support.v4.content.LocalBroadcastManager
import android.support.v7.widget.RecyclerView.ViewHolder import android.support.v7.widget.RecyclerView.ViewHolder
import android.support.v7.widget.Toolbar.OnMenuItemClickListener import android.support.v7.widget.Toolbar.OnMenuItemClickListener
...@@ -69,12 +69,8 @@ final class ProfilesFragment extends ToolbarFragment with OnMenuItemClickListene ...@@ -69,12 +69,8 @@ final class ProfilesFragment extends ToolbarFragment with OnMenuItemClickListene
def updateText(txTotal: Long = 0, rxTotal: Long = 0) { def updateText(txTotal: Long = 0, rxTotal: Long = 0) {
val tx = item.tx + txTotal val tx = item.tx + txTotal
val rx = item.rx + rxTotal val rx = item.rx + rxTotal
var title = if (isDemoMode) "Profile #" + item.id else item.name val title = item.getName
var address = (if (item.host.contains(":")) "[%s]:%d" else "%s:%d").format(item.host, item.remotePort) val address = if (item.nameIsEmpty) "" else item.formattedAddress
if ((title == null || title.isEmpty) && address.nonEmpty) {
title = address
address = ""
}
val traffic = getString(R.string.stat_profiles, val traffic = getString(R.string.stat_profiles,
TrafficMonitor.formatTraffic(tx), TrafficMonitor.formatTraffic(rx)) TrafficMonitor.formatTraffic(tx), TrafficMonitor.formatTraffic(rx))
...@@ -214,8 +210,6 @@ final class ProfilesFragment extends ToolbarFragment with OnMenuItemClickListene ...@@ -214,8 +210,6 @@ final class ProfilesFragment extends ToolbarFragment with OnMenuItemClickListene
private var undoManager: UndoSnackbarManager[Profile] = _ private var undoManager: UndoSnackbarManager[Profile] = _
private lazy val clipboard = getActivity.getSystemService(Context.CLIPBOARD_SERVICE).asInstanceOf[ClipboardManager] private lazy val clipboard = getActivity.getSystemService(Context.CLIPBOARD_SERVICE).asInstanceOf[ClipboardManager]
private lazy val isDemoMode = Build.VERSION.SDK_INT >= 25 &&
getActivity.getSystemService(classOf[UserManager]).isDemoUser
private def startConfig(id: Int) = startActivity(new Intent(getActivity, classOf[ProfileConfigActivity]) private def startConfig(id: Int) = startActivity(new Intent(getActivity, classOf[ProfileConfigActivity])
.putExtra(Action.EXTRA_PROFILE_ID, id)) .putExtra(Action.EXTRA_PROFILE_ID, id))
......
...@@ -315,7 +315,7 @@ class ShadowsocksNatService extends BaseService { ...@@ -315,7 +315,7 @@ class ShadowsocksNatService extends BaseService {
AclSyncJob.schedule(profile.route) AclSyncJob.schedule(profile.route)
changeState(State.CONNECTED) changeState(State.CONNECTED)
notification = new ShadowsocksNotification(this, profile.name, true) notification = new ShadowsocksNotification(this, profile.getName, true)
} }
override def stopRunner(stopService: Boolean, msg: String = null) { override def stopRunner(stopService: Boolean, msg: String = null) {
......
...@@ -148,7 +148,7 @@ class ShadowsocksVpnService extends VpnService with BaseService { ...@@ -148,7 +148,7 @@ class ShadowsocksVpnService extends VpnService with BaseService {
if (profile.route != Route.ALL) if (profile.route != Route.ALL)
AclSyncJob.schedule(profile.route) AclSyncJob.schedule(profile.route)
notification = new ShadowsocksNotification(this, profile.name) notification = new ShadowsocksNotification(this, profile.getName)
} }
/** Called when the activity is first created. */ /** Called when the activity is first created. */
...@@ -318,7 +318,7 @@ class ShadowsocksVpnService extends VpnService with BaseService { ...@@ -318,7 +318,7 @@ class ShadowsocksVpnService extends VpnService with BaseService {
val builder = new Builder() val builder = new Builder()
builder builder
.setSession(profile.name) .setSession(profile.getName)
.setMtu(VPN_MTU) .setMtu(VPN_MTU)
.addAddress(PRIVATE_VLAN.formatLocal(Locale.ENGLISH, "1"), 24) .addAddress(PRIVATE_VLAN.formatLocal(Locale.ENGLISH, "1"), 24)
......
...@@ -52,7 +52,7 @@ class TaskerActivity extends AppCompatActivity { ...@@ -52,7 +52,7 @@ class TaskerActivity extends AppCompatActivity {
} }
def bind(item: Profile) { def bind(item: Profile) {
this.item = item this.item = item
text.setText(item.name) text.setText(item.getName)
text.setChecked(taskerOption.profileId == item.id) text.setChecked(taskerOption.profileId == item.id)
} }
......
...@@ -97,6 +97,10 @@ class Profile { ...@@ -97,6 +97,10 @@ class Profile {
@DatabaseField @DatabaseField
var kcpcli: String = "--crypt none --mode normal --mtu 1200 --nocomp --dscp 46 --parityshard 0" var kcpcli: String = "--crypt none --mode normal --mtu 1200 --nocomp --dscp 46 --parityshard 0"
def formattedAddress: String = (if (host.contains(":")) "[%s]:%d" else "%s:%d").format(host, remotePort)
def nameIsEmpty: Boolean = name == null || name.isEmpty
def getName: String = if (nameIsEmpty) formattedAddress else name
override def toString: String = "ss://" + Base64.encodeToString("%s%s:%s@%s:%d".formatLocal(Locale.ENGLISH, override def toString: String = "ss://" + Base64.encodeToString("%s%s:%s@%s:%d".formatLocal(Locale.ENGLISH,
method, if (auth) "-auth" else "", password, host, remotePort).getBytes, Base64.NO_PADDING | Base64.NO_WRAP) + method, if (auth) "-auth" else "", password, host, remotePort).getBytes, Base64.NO_PADDING | Base64.NO_WRAP) +
'#' + URLEncoder.encode(name, "utf-8") '#' + URLEncoder.encode(name, "utf-8")
......
...@@ -38,8 +38,7 @@ object Parser { ...@@ -38,8 +38,7 @@ object Parser {
profile.method = ss.group(2).toLowerCase profile.method = ss.group(2).toLowerCase
if (ss.group(3) != null) profile.auth = true if (ss.group(3) != null) profile.auth = true
profile.password = ss.group(4) profile.password = ss.group(4)
profile.name = ss.group(5) profile.host = ss.group(5)
profile.host = profile.name
profile.remotePort = ss.group(6).toInt profile.remotePort = ss.group(6).toInt
if (m.group(2) != null) profile.name = URLDecoder.decode(m.group(3), "utf-8") if (m.group(2) != null) profile.name = URLDecoder.decode(m.group(3), "utf-8")
profile profile
......
...@@ -46,7 +46,7 @@ class TaskerSettings(bundle: Bundle) { ...@@ -46,7 +46,7 @@ class TaskerSettings(bundle: Bundle) {
if (profileId >= 0) bundle.putInt(KEY_PROFILE_ID, profileId) if (profileId >= 0) bundle.putInt(KEY_PROFILE_ID, profileId)
new Intent().putExtra(ApiIntent.EXTRA_BUNDLE, bundle).putExtra(ApiIntent.EXTRA_STRING_BLURB, new Intent().putExtra(ApiIntent.EXTRA_BUNDLE, bundle).putExtra(ApiIntent.EXTRA_STRING_BLURB,
app.profileManager.getProfile(profileId) match { app.profileManager.getProfile(profileId) match {
case Some(p) => context.getString(if (switchOn) R.string.start_service else R.string.stop_service, p.name) case Some(p) => context.getString(if (switchOn) R.string.start_service else R.string.stop_service, p.getName)
case None => context.getString(if (switchOn) R.string.start_service_default else R.string.stop) case None => context.getString(if (switchOn) R.string.start_service_default else R.string.stop)
}) })
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment