Commit 719d8eaa authored by Mygod's avatar Mygod

Move reset functionality to drawer

parent 34fe03c9
...@@ -10,7 +10,4 @@ ...@@ -10,7 +10,4 @@
<SwitchPreference android:key="isNAT" <SwitchPreference android:key="isNAT"
android:title="@string/nat" android:title="@string/nat"
android:summary="@string/nat_summary"/> android:summary="@string/nat_summary"/>
<Preference android:key="recovery"
android:title="@string/recovery"
android:summary="@string/recovery_summary"/>
</PreferenceScreen> </PreferenceScreen>
package com.github.shadowsocks package com.github.shadowsocks
import android.app.ProgressDialog import android.os.Bundle
import android.os.{Bundle, Handler, Message}
import android.support.design.widget.Snackbar import android.support.design.widget.Snackbar
import android.support.v14.preference.SwitchPreference import android.support.v14.preference.SwitchPreference
import be.mygod.preference.PreferenceFragment import be.mygod.preference.PreferenceFragment
import com.github.shadowsocks.ShadowsocksApplication.app import com.github.shadowsocks.utils.{Key, TcpFastOpen}
import com.github.shadowsocks.utils.{Key, TcpFastOpen, Utils}
class GlobalConfigFragment extends PreferenceFragment { class GlobalConfigFragment extends PreferenceFragment {
private var progressDialog: ProgressDialog = _
override def onCreatePreferences(bundle: Bundle, key: String) { override def onCreatePreferences(bundle: Bundle, key: String) {
addPreferencesFromResource(R.xml.pref_global) addPreferencesFromResource(R.xml.pref_global)
val switch = findPreference(Key.isAutoConnect).asInstanceOf[SwitchPreference] val switch = findPreference(Key.isAutoConnect).asInstanceOf[SwitchPreference]
...@@ -37,33 +33,5 @@ class GlobalConfigFragment extends PreferenceFragment { ...@@ -37,33 +33,5 @@ class GlobalConfigFragment extends PreferenceFragment {
tfo.setEnabled(false) tfo.setEnabled(false)
tfo.setSummary(getString(R.string.tcp_fastopen_summary_unsupported, java.lang.System.getProperty("os.version"))) tfo.setSummary(getString(R.string.tcp_fastopen_summary_unsupported, java.lang.System.getProperty("os.version")))
} }
findPreference("recovery").setOnPreferenceClickListener(_ => {
app.track("GlobalConfigFragment", "reset")
Utils.stopSsService(getActivity)
val h = showProgress(R.string.recovering)
Utils.ThrowableFuture {
app.copyAssets()
h.sendEmptyMessage(0)
}
true
})
}
private def showProgress(msg: Int): Handler = {
clearDialog()
progressDialog = ProgressDialog.show(getActivity, "", getString(msg), true, false)
new Handler {
override def handleMessage(msg: Message) {
clearDialog()
}
}
}
def clearDialog() {
if (progressDialog != null && progressDialog.isShowing) {
if (!getActivity.isDestroyed) progressDialog.dismiss()
progressDialog = null
}
} }
} }
...@@ -24,13 +24,13 @@ import java.lang.System.currentTimeMillis ...@@ -24,13 +24,13 @@ import java.lang.System.currentTimeMillis
import java.net.{HttpURLConnection, URL} import java.net.{HttpURLConnection, URL}
import java.util.Locale import java.util.Locale
import android.app.Activity import android.app.{Activity, ProgressDialog}
import android.app.backup.BackupManager import android.app.backup.BackupManager
import android.content.SharedPreferences.OnSharedPreferenceChangeListener import android.content.SharedPreferences.OnSharedPreferenceChangeListener
import android.content._ import android.content._
import android.net.{Uri, VpnService} import android.net.{Uri, VpnService}
import android.nfc.{NdefMessage, NfcAdapter} import android.nfc.{NdefMessage, NfcAdapter}
import android.os.{Build, Bundle, Handler} import android.os.{Build, Bundle, Handler, Message}
import android.support.design.widget.{FloatingActionButton, Snackbar} import android.support.design.widget.{FloatingActionButton, Snackbar}
import android.support.v4.content.ContextCompat import android.support.v4.content.ContextCompat
import android.support.v7.app.AlertDialog import android.support.v7.app.AlertDialog
...@@ -57,8 +57,9 @@ object MainActivity { ...@@ -57,8 +57,9 @@ object MainActivity {
private final val DRAWER_PROFILES = 0L private final val DRAWER_PROFILES = 0L
// sticky drawer items have negative ids // sticky drawer items have negative ids
private final val DRAWER_GLOBAL_SETTINGS = -1L private final val DRAWER_RECOVERY = -1L
private final val DRAWER_ABOUT = -2L private final val DRAWER_GLOBAL_SETTINGS = -2L
private final val DRAWER_ABOUT = -3L
} }
class MainActivity extends Activity with ServiceBoundContext with Drawer.OnDrawerItemClickListener class MainActivity extends Activity with ServiceBoundContext with Drawer.OnDrawerItemClickListener
...@@ -73,6 +74,7 @@ class MainActivity extends Activity with ServiceBoundContext with Drawer.OnDrawe ...@@ -73,6 +74,7 @@ class MainActivity extends Activity with ServiceBoundContext with Drawer.OnDrawe
var currentProfile = new Profile var currentProfile = new Profile
var drawer: Drawer = _ var drawer: Drawer = _
private var progressDialog: ProgressDialog = _
private var currentFragment: ToolbarFragment = _ private var currentFragment: ToolbarFragment = _
private lazy val profilesFragment = new ProfilesFragment() private lazy val profilesFragment = new ProfilesFragment()
private lazy val globalSettingsFragment = new GlobalSettingsFragment() private lazy val globalSettingsFragment = new GlobalSettingsFragment()
...@@ -219,6 +221,12 @@ class MainActivity extends Activity with ServiceBoundContext with Drawer.OnDrawe ...@@ -219,6 +221,12 @@ class MainActivity extends Activity with ServiceBoundContext with Drawer.OnDrawe
.withIconTintingEnabled(true) .withIconTintingEnabled(true)
) )
.addStickyDrawerItems( .addStickyDrawerItems(
new SecondaryDrawerItem()
.withIdentifier(DRAWER_RECOVERY)
.withName(R.string.recovery)
.withIcon(ContextCompat.getDrawable(this, R.drawable.ic_navigation_refresh))
.withIconTintingEnabled(true)
.withSelectable(false),
new SecondaryDrawerItem() new SecondaryDrawerItem()
.withIdentifier(DRAWER_GLOBAL_SETTINGS) .withIdentifier(DRAWER_GLOBAL_SETTINGS)
.withName(R.string.settings) .withName(R.string.settings)
...@@ -355,6 +363,14 @@ class MainActivity extends Activity with ServiceBoundContext with Drawer.OnDrawe ...@@ -355,6 +363,14 @@ class MainActivity extends Activity with ServiceBoundContext with Drawer.OnDrawe
override def onItemClick(view: View, position: Int, drawerItem: IDrawerItem[_, _ <: ViewHolder]): Boolean = { override def onItemClick(view: View, position: Int, drawerItem: IDrawerItem[_, _ <: ViewHolder]): Boolean = {
drawerItem.getIdentifier match { drawerItem.getIdentifier match {
case DRAWER_PROFILES => displayFragment(profilesFragment) case DRAWER_PROFILES => displayFragment(profilesFragment)
case DRAWER_RECOVERY =>
app.track("GlobalConfigFragment", "reset")
serviceStop()
val handler = showProgress(R.string.recovering)
Utils.ThrowableFuture {
app.copyAssets()
handler.sendEmptyMessage(0)
}
case DRAWER_GLOBAL_SETTINGS => displayFragment(globalSettingsFragment) case DRAWER_GLOBAL_SETTINGS => displayFragment(globalSettingsFragment)
case DRAWER_ABOUT => case DRAWER_ABOUT =>
app.track(TAG, "about") app.track(TAG, "about")
...@@ -378,6 +394,21 @@ class MainActivity extends Activity with ServiceBoundContext with Drawer.OnDrawe ...@@ -378,6 +394,21 @@ class MainActivity extends Activity with ServiceBoundContext with Drawer.OnDrawe
true // unexpected cases will throw exception true // unexpected cases will throw exception
} }
private def showProgress(msg: Int): Handler = {
clearDialog()
progressDialog = ProgressDialog.show(this, "", getString(msg), true, false)
new Handler {
override def handleMessage(msg: Message): Unit = clearDialog()
}
}
private def clearDialog() {
if (progressDialog != null && progressDialog.isShowing) {
if (!isDestroyed) progressDialog.dismiss()
progressDialog = null
}
}
private def hideCircle() { private def hideCircle() {
try { try {
fabProgressCircle.hide() fabProgressCircle.hide()
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment