From e2a3184715d2c9ded7b556ca55ddddc054f4d4d0 Mon Sep 17 00:00:00 2001 From: Mygod Date: Tue, 29 Mar 2016 10:21:17 +0800 Subject: [PATCH] Refine #614 #615 --- src/main/res/values-zh-rCN/strings.xml | 1 - src/main/res/values-zh-rTW/strings.xml | 2 - .../shadowsocks/ProfileManagerActivity.scala | 77 +++++++------------ 3 files changed, 28 insertions(+), 52 deletions(-) diff --git a/src/main/res/values-zh-rCN/strings.xml b/src/main/res/values-zh-rCN/strings.xml index c883dbb0..5abb0486 100644 --- a/src/main/res/values-zh-rCN/strings.xml +++ b/src/main/res/values-zh-rCN/strings.xml @@ -1,5 +1,4 @@ - 影梭 全局设置 diff --git a/src/main/res/values-zh-rTW/strings.xml b/src/main/res/values-zh-rTW/strings.xml index bf7d6f75..e5e022d9 100644 --- a/src/main/res/values-zh-rTW/strings.xml +++ b/src/main/res/values-zh-rTW/strings.xml @@ -1,9 +1,7 @@  - Shadowsocks - Shadowsocks 全域設定 其他 伺服器設定 diff --git a/src/main/scala/com/github/shadowsocks/ProfileManagerActivity.scala b/src/main/scala/com/github/shadowsocks/ProfileManagerActivity.scala index 041b006d..0bd1efe7 100644 --- a/src/main/scala/com/github/shadowsocks/ProfileManagerActivity.scala +++ b/src/main/scala/com/github/shadowsocks/ProfileManagerActivity.scala @@ -5,9 +5,8 @@ import java.nio.charset.Charset import android.content._ import android.nfc.NfcAdapter.CreateNdefMessageCallback import android.nfc.{NdefMessage, NdefRecord, NfcAdapter, NfcEvent} -import android.os.{Build, Bundle, Handler} +import android.os.{Bundle, Handler} import android.provider.Settings -import android.support.v4.app.{NavUtils, TaskStackBuilder} import android.support.v7.app.{AlertDialog, AppCompatActivity} import android.support.v7.widget.RecyclerView.ViewHolder import android.support.v7.widget.Toolbar.OnMenuItemClickListener @@ -38,7 +37,7 @@ class ProfileManagerActivity extends AppCompatActivity with OnMenuItemClickListe val shareBtn = itemView.findViewById(R.id.share) shareBtn.setOnClickListener(_ => { val url = item.toString - if (nfcBeamEnable) { + if (isNfcBeamEnabled) { nfcAdapter.setNdefPushMessageCallback(ProfileManagerActivity.this,ProfileManagerActivity.this) nfcShareItem = url.getBytes(Charset.forName("UTF-8")) } @@ -57,23 +56,15 @@ class ProfileManagerActivity extends AppCompatActivity with OnMenuItemClickListe .setView(image) .setTitle(R.string.share) .create() - if (!nfcAvailable){ - dialog.setMessage(getString(R.string.share_message_without_nfc)) + if (!isNfcAvailable) dialog.setMessage(getString(R.string.share_message_without_nfc)) + else if (!isNfcBeamEnabled) { + dialog.setMessage(getString(R.string.share_message_nfc_disabled)) + dialog.setButton(DialogInterface.BUTTON_NEUTRAL, getString(R.string.turn_on_nfc), + ((_, _) => startActivity(new Intent(Settings.ACTION_NFC_SETTINGS))): DialogInterface.OnClickListener) } else { - if (!nfcBeamEnable) { - dialog.setMessage(getString(R.string.share_message_nfc_disabled)) - dialog.setButton(DialogInterface.BUTTON_NEUTRAL, getString(R.string.turn_on_nfc), ((_, _) => - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { - startActivity(new Intent(Settings.ACTION_NFC_SETTINGS)) - } else { - startActivity(new Intent(Settings.ACTION_WIRELESS_SETTINGS)) - } - ): DialogInterface.OnClickListener) - } else { - dialog.setMessage(getString(R.string.share_message)) - dialog.setOnDismissListener(_ => - nfcAdapter.setNdefPushMessageCallback(null, ProfileManagerActivity.this)) - } + dialog.setMessage(getString(R.string.share_message)) + dialog.setOnDismissListener(_ => + nfcAdapter.setNdefPushMessageCallback(null, ProfileManagerActivity.this)) } dialog.show() }) @@ -111,12 +102,9 @@ class ProfileManagerActivity extends AppCompatActivity with OnMenuItemClickListe } } - def onClick(v: View) = { + def onClick(v: View) { ShadowsocksApplication.switchProfile(item.id) finish - if (isLauncherFromShareIntent){ - TaskStackBuilder.create(ProfileManagerActivity.this).addNextIntentWithParentStack(NavUtils.getParentActivityIntent(ProfileManagerActivity.this)).startActivities() - } } } @@ -181,11 +169,9 @@ class ProfileManagerActivity extends AppCompatActivity with OnMenuItemClickListe private var nfcAdapter : NfcAdapter = _ private var nfcShareItem: Array[Byte] = _ - private var nfcAvailable = false - private var nfcEnable = false - private var nfcBeamEnable = false - - private var isLauncherFromShareIntent = false + private var isNfcAvailable: Boolean = _ + private var isNfcEnabled: Boolean = _ + private var isNfcBeamEnabled: Boolean = _ override def onCreate(savedInstanceState: Bundle) { super.onCreate(savedInstanceState) @@ -235,46 +221,40 @@ class ProfileManagerActivity extends AppCompatActivity with OnMenuItemClickListe new AlertDialog.Builder(this).setTitle(R.string.profile_manager_dialog) .setMessage(R.string.profile_manager_dialog_content).setPositiveButton(R.string.gotcha, null).create.show } + + val intent = getIntent + if (intent != null) handleShareIntent(intent) } override def onResume() { super.onResume() - isLauncherFromShareIntent = false - handledShareIntent() - updateNFCState() + updateNfcState() } override def onNewIntent(intent: Intent): Unit ={ super.onNewIntent(intent) - setIntent(intent) + handleShareIntent(intent) } - def updateNFCState(): Unit = { + def updateNfcState() { + isNfcAvailable = false + isNfcEnabled = false + isNfcBeamEnabled = false nfcAdapter = NfcAdapter.getDefaultAdapter(this) - if (nfcAdapter != null){ - nfcAvailable = true + if (nfcAdapter != null) { + isNfcAvailable = true if (nfcAdapter.isEnabled) { - nfcEnable = true + isNfcEnabled = true if (nfcAdapter.isNdefPushEnabled) { - nfcBeamEnable = true + isNfcBeamEnabled = true nfcAdapter.setNdefPushMessageCallback(null, ProfileManagerActivity.this) - } else { - nfcBeamEnable = false } - } else{ - nfcEnable = false - nfcBeamEnable = false } - } else { - nfcAvailable = false - nfcEnable = false - nfcBeamEnable = false } } - def handledShareIntent() { - val intent = getIntent() + def handleShareIntent(intent: Intent) { val sharedStr = intent.getAction match { case Intent.ACTION_VIEW => intent.getData.toString case NfcAdapter.ACTION_NDEF_DISCOVERED => @@ -298,7 +278,6 @@ class ProfileManagerActivity extends AppCompatActivity with OnMenuItemClickListe .setMessage(profiles.mkString("\n")) .create() dialog.show() - isLauncherFromShareIntent = true } override def onStart() {