From d23be09cb0ab5109639fcfff36eb4c01c4a507d0 Mon Sep 17 00:00:00 2001 From: Mygod Date: Sun, 4 Feb 2018 04:29:54 -0800 Subject: [PATCH] Add snackbars everywhere --- .../java/com/github/shadowsocks/AppManager.kt | 11 ++-- .../github/shadowsocks/ProfilesFragment.kt | 9 +-- mobile/src/main/res/layout/layout_apps.xml | 60 +++++++++++-------- 3 files changed, 45 insertions(+), 35 deletions(-) diff --git a/mobile/src/main/java/com/github/shadowsocks/AppManager.kt b/mobile/src/main/java/com/github/shadowsocks/AppManager.kt index 41e0995b..9c6c1d5f 100644 --- a/mobile/src/main/java/com/github/shadowsocks/AppManager.kt +++ b/mobile/src/main/java/com/github/shadowsocks/AppManager.kt @@ -34,6 +34,7 @@ import android.content.pm.PackageManager import android.graphics.drawable.Drawable import android.os.Bundle import android.os.Handler +import android.support.design.widget.Snackbar import android.support.v4.app.TaskStackBuilder import android.support.v7.app.AppCompatActivity import android.support.v7.widget.DefaultItemAnimator @@ -231,14 +232,14 @@ class AppManager : AppCompatActivity(), Toolbar.OnMenuItemClickListener { ProfileManager.updateProfile(it) } if (DataStore.directBootAware) DirectBoot.update() - Toast.makeText(this, R.string.action_apply_all, Toast.LENGTH_SHORT).show() - } else Toast.makeText(this, R.string.action_export_err, Toast.LENGTH_SHORT).show() + Snackbar.make(appListView, R.string.action_apply_all, Snackbar.LENGTH_LONG).show() + } else Snackbar.make(appListView, R.string.action_export_err, Snackbar.LENGTH_LONG).show() return true } R.id.action_export -> { clipboard.primaryClip = ClipData.newPlainText(Key.individual, "${DataStore.bypass}\n${DataStore.individual}") - Toast.makeText(this, R.string.action_export_msg, Toast.LENGTH_SHORT).show() + Snackbar.make(appListView, R.string.action_export_msg, Snackbar.LENGTH_LONG).show() return true } R.id.action_import -> { @@ -251,13 +252,13 @@ class AppManager : AppCompatActivity(), Toolbar.OnMenuItemClickListener { bypassSwitch.isChecked = enabled.toBoolean() DataStore.individual = apps DataStore.dirty = true - Toast.makeText(this, R.string.action_import_msg, Toast.LENGTH_SHORT).show() + Snackbar.make(appListView, R.string.action_import_msg, Snackbar.LENGTH_LONG).show() initProxiedApps(apps) reloadApps() return true } catch (_: IllegalArgumentException) { } } - Toast.makeText(this, R.string.action_import_err, Toast.LENGTH_SHORT).show() + Snackbar.make(appListView, R.string.action_import_err, Snackbar.LENGTH_LONG).show() } } return false diff --git a/mobile/src/main/java/com/github/shadowsocks/ProfilesFragment.kt b/mobile/src/main/java/com/github/shadowsocks/ProfilesFragment.kt index 6a379aa6..dddf5383 100644 --- a/mobile/src/main/java/com/github/shadowsocks/ProfilesFragment.kt +++ b/mobile/src/main/java/com/github/shadowsocks/ProfilesFragment.kt @@ -370,7 +370,8 @@ class ProfilesFragment : ToolbarFragment(), Toolbar.OnMenuItemClickListener { val profiles = Profile.findAll(clipboard.primaryClip.getItemAt(0).text).toList() if (profiles.isNotEmpty()) { profiles.forEach { ProfileManager.createProfile(it) } - Toast.makeText(activity, R.string.action_import_msg, Toast.LENGTH_SHORT).show() + Snackbar.make(activity!!.findViewById(R.id.snackbar), R.string.action_import_msg, + Snackbar.LENGTH_LONG).show() return true } } catch (exc: Exception) { @@ -386,10 +387,10 @@ class ProfilesFragment : ToolbarFragment(), Toolbar.OnMenuItemClickListener { } R.id.action_export -> { val profiles = ProfileManager.getAllProfiles() - if (profiles != null) { + Snackbar.make(activity!!.findViewById(R.id.snackbar), if (profiles != null) { clipboard.primaryClip = ClipData.newPlainText(null, profiles.joinToString("\n")) - Toast.makeText(activity, R.string.action_export_msg, Toast.LENGTH_SHORT).show() - } else Toast.makeText(activity, R.string.action_export_err, Toast.LENGTH_SHORT).show() + R.string.action_export_msg + } else R.string.action_export_err, Snackbar.LENGTH_LONG).show() true } else -> false diff --git a/mobile/src/main/res/layout/layout_apps.xml b/mobile/src/main/res/layout/layout_apps.xml index 8dbc5f3f..3798dbab 100644 --- a/mobile/src/main/res/layout/layout_apps.xml +++ b/mobile/src/main/res/layout/layout_apps.xml @@ -3,8 +3,8 @@ xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" - android:layout_width="fill_parent" - android:layout_height="fill_parent" + android:layout_width="match_parent" + android:layout_height="match_parent" android:orientation="vertical" android:duplicateParentState="false"> @@ -41,28 +41,36 @@ android:textColor="?android:attr/textColorSecondary" android:textSize="18sp"/> - - - - - + + + + + + +