refine UI
This commit is contained in:
@@ -23,6 +23,7 @@
|
||||
<!-- Variation on the Light theme that turns off the title -->
|
||||
<style name="Theme.Shadowsocks" parent="@style/Theme.Shadow">
|
||||
<item name="switchStyle">@style/Widget.Shadow.Switch</item>
|
||||
<item name="menuDrawerStyle">@style/MenuDrawerStyle</item>
|
||||
</style>
|
||||
|
||||
<style name="Theme.AppManager" parent="@style/Theme.Shadow">
|
||||
@@ -60,5 +61,9 @@
|
||||
<item name="android:gravity">center_vertical</item>
|
||||
</style>
|
||||
|
||||
<style name="MenuDrawerStyle" parent="Widget.MenuDrawer">
|
||||
<item name="mdActiveIndicator">@drawable/menu_arrow</item>
|
||||
<item name="mdMenuSize">250dp</item>
|
||||
</style>
|
||||
|
||||
</resources>
|
||||
@@ -289,6 +289,9 @@ class Shadowsocks
|
||||
private val MSG_CRASH_RECOVER: Int = 1
|
||||
private val MSG_INITIAL_FINISH: Int = 2
|
||||
|
||||
private val STATE_MENUDRAWER = "com.github.shadowsocks.menuDrawer"
|
||||
private val STATE_ACTIVE_VIEW_ID = "com.github.shadowsocks.activeViewId"
|
||||
|
||||
private var switchButton: Switch = null
|
||||
private var progressDialog: ProgressDialog = null
|
||||
|
||||
@@ -483,6 +486,8 @@ class Shadowsocks
|
||||
profileManager.getProfile(settings.getInt(Key.profileId, -1)) getOrElse new Profile()
|
||||
}
|
||||
|
||||
menuAdapter.setActiveId(settings.getInt(Key.profileId, -1))
|
||||
menuAdapter.setListener(this)
|
||||
listView.setAdapter(menuAdapter)
|
||||
drawer.setMenuView(listView)
|
||||
|
||||
@@ -522,17 +527,53 @@ class Shadowsocks
|
||||
}
|
||||
}
|
||||
|
||||
override def onRestoreInstanceState(inState: Bundle) {
|
||||
super.onRestoreInstanceState(inState)
|
||||
drawer.restoreState(inState.getParcelable(STATE_MENUDRAWER))
|
||||
}
|
||||
|
||||
override def onSaveInstanceState(outState: Bundle) {
|
||||
super.onSaveInstanceState(outState)
|
||||
outState.putParcelable(STATE_MENUDRAWER, drawer.saveState())
|
||||
outState.putInt(STATE_ACTIVE_VIEW_ID, Shadowsocks.currentProfile.id)
|
||||
}
|
||||
|
||||
override def onBackPressed() {
|
||||
val drawerState = drawer.getDrawerState
|
||||
if (drawerState == MenuDrawer.STATE_OPEN || drawerState == MenuDrawer.STATE_OPENING) {
|
||||
drawer.closeMenu()
|
||||
return
|
||||
}
|
||||
super.onBackPressed()
|
||||
}
|
||||
|
||||
override def onActiveViewChanged(v: View, pos: Int) {
|
||||
drawer.setActiveView(v, pos)
|
||||
}
|
||||
|
||||
def addProfile(id: Int) {
|
||||
drawer.closeMenu(true)
|
||||
|
||||
handler.postDelayed(new Runnable {
|
||||
def run() {
|
||||
Shadowsocks.currentProfile = profileManager.reload(id)
|
||||
updatePreferenceScreen()
|
||||
profileManager.save()
|
||||
menuAdapter.updateList(getMenuList, Shadowsocks.currentProfile.id)
|
||||
}
|
||||
}, 600)
|
||||
|
||||
if (!isSinglePane) sendBroadcast(new Intent(Action.UPDATE_FRAGMENT))
|
||||
}
|
||||
|
||||
def updateProfile(id: Int) {
|
||||
drawer.closeMenu(true)
|
||||
|
||||
handler.postDelayed(new Runnable {
|
||||
def run() {
|
||||
Shadowsocks.currentProfile = profileManager.load(id)
|
||||
Shadowsocks.currentProfile = profileManager.reload(id)
|
||||
updatePreferenceScreen()
|
||||
menuAdapter.setActiveId(id)
|
||||
}
|
||||
}, 600)
|
||||
|
||||
@@ -573,11 +614,7 @@ class Shadowsocks
|
||||
|
||||
buf ++= getProfileList
|
||||
|
||||
buf += new Item(-1, getString(R.string.add_profile), android.R.drawable.ic_menu_add, _ => {
|
||||
updateProfile(-1)
|
||||
profileManager.save()
|
||||
menuAdapter.updateList(getMenuList, Shadowsocks.currentProfile.id)
|
||||
})
|
||||
buf += new Item(-1, getString(R.string.add_profile), android.R.drawable.ic_menu_add, addProfile)
|
||||
|
||||
buf += new Category("Settings")
|
||||
|
||||
|
||||
@@ -70,8 +70,8 @@ class MenuAdapter(context: Context, var items: List[Any]) extends BaseAdapter {
|
||||
this.listener = listener
|
||||
}
|
||||
|
||||
def setActivePosition(activePosition: Int) {
|
||||
this.activePosition = activePosition
|
||||
def setActiveId(activeId: Int) {
|
||||
this.activeId = activeId
|
||||
}
|
||||
|
||||
@Override def getCount: Int = {
|
||||
@@ -139,28 +139,26 @@ class MenuAdapter(context: Context, var items: List[Any]) extends BaseAdapter {
|
||||
|
||||
v.setTag(R.id.mdItem, value)
|
||||
|
||||
if (value.id == activeId) {
|
||||
if (listener != null) listener.onActiveViewChanged(v, position)
|
||||
}
|
||||
|
||||
case _ =>
|
||||
}
|
||||
v.setTag(R.id.mdActiveViewPosition, position)
|
||||
|
||||
if (position == activePosition) {
|
||||
if (listener != null) listener.onActiveViewChanged(v, position)
|
||||
}
|
||||
|
||||
v
|
||||
}
|
||||
|
||||
def updateList(list: List[Any], activeId: Int) {
|
||||
items = list
|
||||
activePosition = items.indexWhere{
|
||||
case item: Item => item.id == activeId
|
||||
case _ => false
|
||||
}
|
||||
this.activeId = activeId
|
||||
notifyDataSetChanged()
|
||||
}
|
||||
|
||||
private var listener: MenuAdapter.MenuListener = null
|
||||
private var activePosition: Int = -1
|
||||
private var activeId: Int = -1
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -91,11 +91,12 @@ class ProfileManager(settings: SharedPreferences, dbHelper: DBHelper) {
|
||||
}
|
||||
}
|
||||
|
||||
def load(id: Int): Profile = {
|
||||
|
||||
Log.d(Shadowsocks.TAG, id + " ")
|
||||
|
||||
def reload(id: Int): Profile = {
|
||||
save()
|
||||
load(id)
|
||||
}
|
||||
|
||||
def load(id: Int): Profile = {
|
||||
|
||||
val profile = getProfile(id) getOrElse {
|
||||
val p = new Profile()
|
||||
@@ -103,8 +104,6 @@ class ProfileManager(settings: SharedPreferences, dbHelper: DBHelper) {
|
||||
p
|
||||
}
|
||||
|
||||
Log.d(Shadowsocks.TAG, "load " + profile.id + " " + profile.name)
|
||||
|
||||
val edit = settings.edit()
|
||||
edit.putBoolean(Key.isGlobalProxy, profile.global)
|
||||
edit.putBoolean(Key.isGFWList, profile.chnroute)
|
||||
|
||||
Reference in New Issue
Block a user