mirror of
https://github.com/syncthing/syncthing-android.git
synced 2024-12-02 01:01:17 +00:00
* SettingsActivity: Fix var name * Add verbose logging * SettingsActivity: Use a handler to call sub pref screen (fixes #247) * Add verbose log * Fix toolbar ignoring input after going back from subpref screen when directly opened in subpref screen before (fixes #247) * Revert "Add verbose log" This reverts commit 33207d0721dd38ce5efa04dddb891557ade6f5c3. * SettingsActivity: Re-register actionbar after a subpref screen dismissal (fixes #247)
This commit is contained in:
parent
beee401baa
commit
71c5c494bc
1 changed files with 45 additions and 22 deletions
|
@ -13,6 +13,7 @@ import android.content.pm.PackageManager;
|
||||||
import android.os.AsyncTask;
|
import android.os.AsyncTask;
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
import android.os.Handler;
|
||||||
import android.os.IBinder;
|
import android.os.IBinder;
|
||||||
import android.preference.CheckBoxPreference;
|
import android.preference.CheckBoxPreference;
|
||||||
import android.preference.EditTextPreference;
|
import android.preference.EditTextPreference;
|
||||||
|
@ -192,6 +193,7 @@ public class SettingsActivity extends SyncthingActivity {
|
||||||
private Options mOptions;
|
private Options mOptions;
|
||||||
private Gui mGui;
|
private Gui mGui;
|
||||||
|
|
||||||
|
private Handler mHandler;
|
||||||
private Boolean mPendingConfig = false;
|
private Boolean mPendingConfig = false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -367,27 +369,33 @@ public class SettingsActivity extends SyncthingActivity {
|
||||||
}
|
}
|
||||||
screen.findPreference(KEY_SYNCTHING_DATABASE_SIZE).setSummary(getDatabaseSize());
|
screen.findPreference(KEY_SYNCTHING_DATABASE_SIZE).setSummary(getDatabaseSize());
|
||||||
|
|
||||||
openSubPrefScreen(screen);
|
// Check if we should directly show a sub preference screen.
|
||||||
|
Bundle bundle = getArguments();
|
||||||
|
if (bundle != null) {
|
||||||
|
// Fix issue #247: "Calling sub pref screen directly won't show toolbar on top"
|
||||||
|
mHandler = new Handler();
|
||||||
|
mHandler.post(() -> {
|
||||||
|
// Open sub preferences screen if EXTRA_OPEN_SUB_PREF_SCREEN was passed in bundle.
|
||||||
|
openSubPrefScreen(screen, bundle.getString(EXTRA_OPEN_SUB_PREF_SCREEN, ""));
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void openSubPrefScreen(PreferenceScreen prefScreen) {
|
private void openSubPrefScreen(PreferenceScreen parentPrefScreen, String subPrefScreenId) {
|
||||||
Bundle bundle = getArguments();
|
if (parentPrefScreen == null ||
|
||||||
if (bundle == null) {
|
subPrefScreenId == null ||
|
||||||
|
TextUtils.isEmpty(subPrefScreenId)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
String openSubPrefScreen = bundle.getString(EXTRA_OPEN_SUB_PREF_SCREEN, "");
|
Log.v(TAG, "Transitioning to pref screen " + subPrefScreenId);
|
||||||
// Open sub preferences screen if EXTRA_OPEN_SUB_PREF_SCREEN was passed in bundle.
|
PreferenceScreen desiredSubPrefScreen = (PreferenceScreen) findPreference(subPrefScreenId);
|
||||||
if (openSubPrefScreen != null && !TextUtils.isEmpty(openSubPrefScreen)) {
|
final ListAdapter listAdapter = parentPrefScreen.getRootAdapter();
|
||||||
Log.v(TAG, "Transitioning to pref screen " + openSubPrefScreen);
|
final int itemsCount = listAdapter.getCount();
|
||||||
PreferenceScreen categoryRunConditions = (PreferenceScreen) findPreference(openSubPrefScreen);
|
for (int itemNumber = 0; itemNumber < itemsCount; ++itemNumber) {
|
||||||
final ListAdapter listAdapter = prefScreen.getRootAdapter();
|
if (listAdapter.getItem(itemNumber).equals(desiredSubPrefScreen)) {
|
||||||
final int itemsCount = listAdapter.getCount();
|
// Simulates click on the sub-preference. This will invoke {@link #onPreferenceTreeClick} subsequently.
|
||||||
for (int itemNumber = 0; itemNumber < itemsCount; ++itemNumber) {
|
parentPrefScreen.onItemClick(null, null, itemNumber, 0);
|
||||||
if (listAdapter.getItem(itemNumber).equals(categoryRunConditions)) {
|
break;
|
||||||
// Simulates click on the sub-preference
|
|
||||||
prefScreen.onItemClick(null, null, itemNumber, 0);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -406,11 +414,7 @@ public class SettingsActivity extends SyncthingActivity {
|
||||||
Toolbar toolbar = (Toolbar) layoutInflater.inflate(R.layout.widget_toolbar, root, false);
|
Toolbar toolbar = (Toolbar) layoutInflater.inflate(R.layout.widget_toolbar, root, false);
|
||||||
root.addView(toolbar, 0);
|
root.addView(toolbar, 0);
|
||||||
toolbar.setTitle(((PreferenceScreen) preference).getTitle());
|
toolbar.setTitle(((PreferenceScreen) preference).getTitle());
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
|
registerActionBar(toolbar);
|
||||||
toolbar.setTouchscreenBlocksFocus(false);
|
|
||||||
}
|
|
||||||
syncthingActivity.setSupportActionBar(toolbar);
|
|
||||||
syncthingActivity.getSupportActionBar().setDisplayHomeAsUpEnabled(true);
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
/**
|
/**
|
||||||
* The above code has been verified working but due to known bugs in the
|
* The above code has been verified working but due to known bugs in the
|
||||||
|
@ -433,12 +437,31 @@ public class SettingsActivity extends SyncthingActivity {
|
||||||
// User is on a sub-preferences screen.
|
// User is on a sub-preferences screen.
|
||||||
mCurrentPrefScreenDialog.dismiss();
|
mCurrentPrefScreenDialog.dismiss();
|
||||||
mCurrentPrefScreenDialog = null;
|
mCurrentPrefScreenDialog = null;
|
||||||
|
|
||||||
|
// We need to re-register the action bar, see issue #247.
|
||||||
|
registerActionBar(null);
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return super.onOptionsItemSelected(item);
|
return super.onOptionsItemSelected(item);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void registerActionBar(Toolbar toolbar) {
|
||||||
|
SyncthingActivity syncthingActivity = (SyncthingActivity) getActivity();
|
||||||
|
if (toolbar == null) {
|
||||||
|
toolbar = (Toolbar) syncthingActivity.findViewById(R.id.toolbar);
|
||||||
|
}
|
||||||
|
if (toolbar == null) {
|
||||||
|
Log.w(TAG, "registerActionBar: toolbar == null");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
|
||||||
|
toolbar.setTouchscreenBlocksFocus(false);
|
||||||
|
}
|
||||||
|
syncthingActivity.setSupportActionBar(toolbar);
|
||||||
|
syncthingActivity.getSupportActionBar().setDisplayHomeAsUpEnabled(true);
|
||||||
|
}
|
||||||
|
|
||||||
public void setService(SyncthingService syncthingService) {
|
public void setService(SyncthingService syncthingService) {
|
||||||
mSyncthingService = syncthingService;
|
mSyncthingService = syncthingService;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue