Fix ParserActivity
This commit is contained in:
@@ -66,7 +66,8 @@
|
||||
android:name=".ProfileManagerActivity"
|
||||
android:label="@string/profiles"
|
||||
android:parentActivityName=".Shadowsocks"
|
||||
android:exported="false">
|
||||
android:exported="false"
|
||||
android:launchMode="singleTask">
|
||||
<intent-filter>
|
||||
<action android:name="com.github.shadowsocks.ProfileManagerActivity"/>
|
||||
<category android:name="android.intent.category.DEFAULT"/>
|
||||
@@ -76,7 +77,8 @@
|
||||
<activity
|
||||
android:name=".AppManager"
|
||||
android:label="@string/proxied_apps"
|
||||
android:parentActivityName=".Shadowsocks"/>
|
||||
android:parentActivityName=".Shadowsocks"
|
||||
android:launchMode="singleTask"/>
|
||||
|
||||
<service
|
||||
android:name=".ShadowsocksRunnerService"
|
||||
|
||||
@@ -44,33 +44,33 @@ import android.content.DialogInterface
|
||||
import android.graphics.Color
|
||||
import android.graphics.drawable.ColorDrawable
|
||||
import android.os.Bundle
|
||||
import android.preference.PreferenceManager
|
||||
import android.view.WindowManager
|
||||
import com.github.shadowsocks.database.{Profile, ProfileManager}
|
||||
import com.github.shadowsocks.utils.Parser
|
||||
|
||||
class ParserActivity extends Activity {
|
||||
override def onCreate(savedInstanceState: Bundle) {
|
||||
super.onCreate(savedInstanceState)
|
||||
showAsPopup(this)
|
||||
val data = getIntent.getData.toString
|
||||
new AlertDialog.Builder(this)
|
||||
val profile = Parser.parse(data)
|
||||
if (profile.isEmpty) { // ignore
|
||||
finish()
|
||||
return
|
||||
}
|
||||
showAsPopup(this)
|
||||
val dialog = new AlertDialog.Builder(this)
|
||||
.setTitle(R.string.add_profile_dialog)
|
||||
.setCancelable(false)
|
||||
.setPositiveButton(android.R.string.yes, ((dialog: DialogInterface, id: Int) => {
|
||||
Parser.parse(data) match {
|
||||
case Some(profile) => addProfile(profile)
|
||||
case _ => // ignore
|
||||
}
|
||||
ShadowsocksApplication.profileManager.createOrUpdateProfile(profile.get)
|
||||
dialog.dismiss()
|
||||
}): DialogInterface.OnClickListener)
|
||||
.setNegativeButton(android.R.string.no, ((dialog: DialogInterface, id: Int) => {
|
||||
dialog.dismiss()
|
||||
finish()
|
||||
}): DialogInterface.OnClickListener)
|
||||
.setMessage(data)
|
||||
.create()
|
||||
.show()
|
||||
dialog.setOnDismissListener((dialog: DialogInterface) => finish()) // builder method was added in API 17
|
||||
dialog.show()
|
||||
}
|
||||
|
||||
def showAsPopup(activity: Activity) {
|
||||
@@ -82,13 +82,4 @@ class ParserActivity extends Activity {
|
||||
activity.getWindow.setAttributes(params.asInstanceOf[android.view.WindowManager.LayoutParams])
|
||||
activity.getWindow.setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT))
|
||||
}
|
||||
|
||||
def addProfile(profile: Profile) {
|
||||
val profileManager =
|
||||
new ProfileManager(PreferenceManager.getDefaultSharedPreferences(getBaseContext),
|
||||
ShadowsocksApplication.dbHelper)
|
||||
profileManager.createOrUpdateProfile(profile)
|
||||
profileManager.reload(profile.id)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -82,10 +82,8 @@ class ProfileManagerActivity extends AppCompatActivity with OnMenuItemClickListe
|
||||
removedSnackbar.dismiss
|
||||
commitRemoves
|
||||
val pos = getItemCount
|
||||
if (ShadowsocksApplication.profileManager.createOrUpdateProfile(item)) {
|
||||
profiles += item
|
||||
notifyItemInserted(pos)
|
||||
}
|
||||
profiles += item
|
||||
notifyItemInserted(pos)
|
||||
}
|
||||
|
||||
def remove(pos: Int) {
|
||||
@@ -126,6 +124,7 @@ class ProfileManagerActivity extends AppCompatActivity with OnMenuItemClickListe
|
||||
toolbar.inflateMenu(R.menu.add_profile_methods)
|
||||
toolbar.setOnMenuItemClickListener(this)
|
||||
|
||||
ShadowsocksApplication.profileManager.setProfileAddedListener(profilesAdapter.add)
|
||||
val profilesList = findViewById(R.id.profilesList).asInstanceOf[RecyclerView]
|
||||
profilesList.setLayoutManager(new LinearLayoutManager(this))
|
||||
profilesList.setItemAnimator(new DefaultItemAnimator)
|
||||
@@ -147,13 +146,14 @@ class ProfileManagerActivity extends AppCompatActivity with OnMenuItemClickListe
|
||||
|
||||
override def onDestroy {
|
||||
super.onDestroy
|
||||
ShadowsocksApplication.profileManager.setProfileAddedListener(null)
|
||||
profilesAdapter.commitRemoves
|
||||
}
|
||||
|
||||
override def onActivityResult(requestCode: Int, resultCode: Int, data: Intent) {
|
||||
val scanResult = IntentIntegrator.parseActivityResult(requestCode, resultCode, data)
|
||||
if (scanResult != null) Parser.parse(scanResult.getContents) match {
|
||||
case Some(profile) => profilesAdapter.add(profile)
|
||||
case Some(profile) => ShadowsocksApplication.profileManager.createOrUpdateProfile(profile)
|
||||
case _ => // ignore
|
||||
}
|
||||
}
|
||||
|
||||
@@ -424,14 +424,6 @@ class Shadowsocks
|
||||
serviceStop()
|
||||
}
|
||||
|
||||
def addProfile(profile: Profile) {
|
||||
currentProfile = profile
|
||||
ShadowsocksApplication.profileManager.createOrUpdateProfile(currentProfile)
|
||||
ShadowsocksApplication.profileManager.reload(currentProfile.id)
|
||||
|
||||
updatePreferenceScreen()
|
||||
}
|
||||
|
||||
protected override def onPause() {
|
||||
super.onPause()
|
||||
ShadowsocksApplication.profileManager.save
|
||||
|
||||
@@ -46,9 +46,13 @@ import com.github.shadowsocks.utils.Key
|
||||
|
||||
class ProfileManager(settings: SharedPreferences, dbHelper: DBHelper) {
|
||||
|
||||
var profileAddedListener: Profile => Any = _
|
||||
def setProfileAddedListener(listener: Profile => Any) = this.profileAddedListener = listener
|
||||
|
||||
def createOrUpdateProfile(profile: Profile): Boolean = {
|
||||
try {
|
||||
dbHelper.profileDao.createOrUpdate(profile)
|
||||
if (profileAddedListener != null) profileAddedListener(profile)
|
||||
true
|
||||
} catch {
|
||||
case ex: Exception =>
|
||||
|
||||
Reference in New Issue
Block a user