Commit f9e504b0 authored by Mygod's avatar Mygod

Refine profile name display

parent eae97bc1
......@@ -78,7 +78,7 @@ trait BaseService extends Service {
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) {
if (cb != null && callbacks.unregister(cb)) {
......
......@@ -23,7 +23,7 @@ package com.github.shadowsocks
import java.util.GregorianCalendar
import android.content._
import android.os.{Build, Bundle, Handler, UserManager}
import android.os.{Bundle, Handler}
import android.support.v4.content.LocalBroadcastManager
import android.support.v7.widget.RecyclerView.ViewHolder
import android.support.v7.widget.Toolbar.OnMenuItemClickListener
......@@ -69,12 +69,8 @@ final class ProfilesFragment extends ToolbarFragment with OnMenuItemClickListene
def updateText(txTotal: Long = 0, rxTotal: Long = 0) {
val tx = item.tx + txTotal
val rx = item.rx + rxTotal
var title = if (isDemoMode) "Profile #" + item.id else item.name
var address = (if (item.host.contains(":")) "[%s]:%d" else "%s:%d").format(item.host, item.remotePort)
if ((title == null || title.isEmpty) && address.nonEmpty) {
title = address
address = ""
}
val title = item.getName
val address = if (item.nameIsEmpty) "" else item.formattedAddress
val traffic = getString(R.string.stat_profiles,
TrafficMonitor.formatTraffic(tx), TrafficMonitor.formatTraffic(rx))
......@@ -214,8 +210,6 @@ final class ProfilesFragment extends ToolbarFragment with OnMenuItemClickListene
private var undoManager: UndoSnackbarManager[Profile] = _
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])
.putExtra(Action.EXTRA_PROFILE_ID, id))
......
......@@ -315,7 +315,7 @@ class ShadowsocksNatService extends BaseService {
AclSyncJob.schedule(profile.route)
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) {
......
......@@ -148,7 +148,7 @@ class ShadowsocksVpnService extends VpnService with BaseService {
if (profile.route != Route.ALL)
AclSyncJob.schedule(profile.route)
notification = new ShadowsocksNotification(this, profile.name)
notification = new ShadowsocksNotification(this, profile.getName)
}
/** Called when the activity is first created. */
......@@ -318,7 +318,7 @@ class ShadowsocksVpnService extends VpnService with BaseService {
val builder = new Builder()
builder
.setSession(profile.name)
.setSession(profile.getName)
.setMtu(VPN_MTU)
.addAddress(PRIVATE_VLAN.formatLocal(Locale.ENGLISH, "1"), 24)
......
......@@ -52,7 +52,7 @@ class TaskerActivity extends AppCompatActivity {
}
def bind(item: Profile) {
this.item = item
text.setText(item.name)
text.setText(item.getName)
text.setChecked(taskerOption.profileId == item.id)
}
......
......@@ -97,6 +97,10 @@ class Profile {
@DatabaseField
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,
method, if (auth) "-auth" else "", password, host, remotePort).getBytes, Base64.NO_PADDING | Base64.NO_WRAP) +
'#' + URLEncoder.encode(name, "utf-8")
......
......@@ -38,8 +38,7 @@ object Parser {
profile.method = ss.group(2).toLowerCase
if (ss.group(3) != null) profile.auth = true
profile.password = ss.group(4)
profile.name = ss.group(5)
profile.host = profile.name
profile.host = ss.group(5)
profile.remotePort = ss.group(6).toInt
if (m.group(2) != null) profile.name = URLDecoder.decode(m.group(3), "utf-8")
profile
......
......@@ -46,7 +46,7 @@ class TaskerSettings(bundle: Bundle) {
if (profileId >= 0) bundle.putInt(KEY_PROFILE_ID, profileId)
new Intent().putExtra(ApiIntent.EXTRA_BUNDLE, bundle).putExtra(ApiIntent.EXTRA_STRING_BLURB,
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)
})
}
......
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