From e2d080b8304c9ed51cdb120b57f3c4ffe2cb2b51 Mon Sep 17 00:00:00 2001 From: Mygod Date: Tue, 27 Dec 2016 23:54:14 +0800 Subject: [PATCH] Refine "Fix issues on Android 4.4" --- .../shadowsocks/GlobalSettingsFragment.scala | 9 +++------ .../com/github/shadowsocks/MainActivity.scala | 19 +++++++------------ .../com/github/shadowsocks/utils/Utils.scala | 11 ----------- 3 files changed, 10 insertions(+), 29 deletions(-) diff --git a/src/main/scala/com/github/shadowsocks/GlobalSettingsFragment.scala b/src/main/scala/com/github/shadowsocks/GlobalSettingsFragment.scala index bf749686..f43daa4f 100644 --- a/src/main/scala/com/github/shadowsocks/GlobalSettingsFragment.scala +++ b/src/main/scala/com/github/shadowsocks/GlobalSettingsFragment.scala @@ -33,11 +33,8 @@ class GlobalSettingsFragment extends ToolbarFragment { super.onViewCreated(view, savedInstanceState) toolbar.setTitle(R.string.settings) - val fm = getChildFragmentManager() - val fragment = new GlobalConfigFragment() - val ft = fm.beginTransaction() - ft.replace(R.id.content, fragment) - ft.commit() + val fm = getChildFragmentManager + fm.beginTransaction().replace(R.id.content, new GlobalConfigFragment()).commit() fm.executePendingTransactions() } @@ -49,7 +46,7 @@ class GlobalSettingsFragment extends ToolbarFragment { childFragmentManager.setAccessible(true) childFragmentManager.set(this, null) } catch { - case ex: Exception => // ignore + case _: Exception => // ignore } } } diff --git a/src/main/scala/com/github/shadowsocks/MainActivity.scala b/src/main/scala/com/github/shadowsocks/MainActivity.scala index 1c8be5b0..a20d29f9 100644 --- a/src/main/scala/com/github/shadowsocks/MainActivity.scala +++ b/src/main/scala/com/github/shadowsocks/MainActivity.scala @@ -34,6 +34,7 @@ import android.os.{Build, Bundle, Handler, Message} import android.support.design.widget.{FloatingActionButton, Snackbar} import android.support.v4.content.ContextCompat import android.support.v7.app.AlertDialog +import android.support.v7.content.res.AppCompatResources import android.support.v7.widget.RecyclerView.ViewHolder import android.text.TextUtils import android.util.Log @@ -45,8 +46,8 @@ import com.github.shadowsocks.aidl.IShadowsocksServiceCallback import com.github.shadowsocks.database.Profile import com.github.shadowsocks.utils.CloseUtils.autoDisconnect import com.github.shadowsocks.utils._ +import com.mikepenz.materialdrawer.model.PrimaryDrawerItem import com.mikepenz.materialdrawer.model.interfaces.IDrawerItem -import com.mikepenz.materialdrawer.model.{PrimaryDrawerItem, SecondaryDrawerItem} import com.mikepenz.materialdrawer.{Drawer, DrawerBuilder} object MainActivity { @@ -207,25 +208,25 @@ class MainActivity extends Activity with ServiceBoundContext with Drawer.OnDrawe new PrimaryDrawerItem() .withIdentifier(DRAWER_PROFILES) .withName(R.string.profiles) - .withIcon(Utils.getAPICompatVectorDrawable(this, R.drawable.ic_action_description)) + .withIcon(AppCompatResources.getDrawable(this, R.drawable.ic_action_description)) .withIconTintingEnabled(true), new PrimaryDrawerItem() .withIdentifier(DRAWER_GLOBAL_SETTINGS) .withName(R.string.settings) - .withIcon(Utils.getAPICompatVectorDrawable(this, R.drawable.ic_action_settings)) + .withIcon(AppCompatResources.getDrawable(this, R.drawable.ic_action_settings)) .withIconTintingEnabled(true) ) .addStickyDrawerItems( new PrimaryDrawerItem() .withIdentifier(DRAWER_RECOVERY) .withName(R.string.recovery) - .withIcon(Utils.getAPICompatVectorDrawable(this, R.drawable.ic_navigation_refresh)) + .withIcon(AppCompatResources.getDrawable(this, R.drawable.ic_navigation_refresh)) .withIconTintingEnabled(true) .withSelectable(false), new PrimaryDrawerItem() .withIdentifier(DRAWER_ABOUT) .withName(R.string.about) - .withIcon(Utils.getAPICompatVectorDrawable(this, R.drawable.ic_action_copyright)) + .withIcon(AppCompatResources.getDrawable(this, R.drawable.ic_action_copyright)) .withIconTintingEnabled(true) ) .withOnDrawerItemClickListener(this) @@ -302,13 +303,7 @@ class MainActivity extends Activity with ServiceBoundContext with Drawer.OnDrawe val intent = getIntent if (intent != null) handleShareIntent(intent) - app.profileManager.getFirstProfile match { - case Some(_) => // Ignore - case _ => { - val profile = app.profileManager.createProfile() - app.profileId(profile.id) - } - } + if (app.profileManager.getFirstProfile.isEmpty) app.profileId(app.profileManager.createProfile().id) } override def onNewIntent(intent: Intent) { diff --git a/src/main/scala/com/github/shadowsocks/utils/Utils.scala b/src/main/scala/com/github/shadowsocks/utils/Utils.scala index aeba7b8c..4f61de70 100644 --- a/src/main/scala/com/github/shadowsocks/utils/Utils.scala +++ b/src/main/scala/com/github/shadowsocks/utils/Utils.scala @@ -29,10 +29,7 @@ import android.animation.{Animator, AnimatorListenerAdapter} import android.content.pm.PackageManager import android.content.{Context, Intent} import android.graphics._ -import android.graphics.drawable.Drawable import android.os.Build -import android.support.v4.content.ContextCompat -import android.support.graphics.drawable.VectorDrawableCompat import android.util.{Base64, DisplayMetrics, Log} import android.view.View.MeasureSpec import android.view.{Gravity, View, Window} @@ -52,14 +49,6 @@ object Utils { def isLollipopOrAbove: Boolean = Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP - def getAPICompatVectorDrawable(callingContext: Context, resource_id: Int): Drawable = { - if (Build.VERSION.SDK_INT >= 21) { - return ContextCompat.getDrawable(callingContext.getApplicationContext(), resource_id); - } else { - return VectorDrawableCompat.create(callingContext.getResources(), resource_id, callingContext.getTheme()); - } - } - def getSignature(context: Context): String = { val info = context .getPackageManager