mirror of
https://github.com/syncthing/syncthing-android.git
synced 2024-12-23 03:11:30 +00:00
Fixed crash on screen rotate and drawer not refreshing after screen rotate.
This commit is contained in:
parent
9d041d0bb3
commit
0984ba1b2d
2 changed files with 34 additions and 14 deletions
|
@ -64,16 +64,7 @@ public class LocalNodeInfoFragment extends Fragment
|
|||
@Override
|
||||
public void onDrawerOpened(View drawerView) {
|
||||
super.onDrawerOpened(drawerView);
|
||||
mTimer = new Timer();
|
||||
mTimer.schedule(new TimerTask() {
|
||||
@Override
|
||||
public void run() {
|
||||
updateGui();
|
||||
}
|
||||
|
||||
}, 0, SyncthingService.GUI_UPDATE_INTERVAL);
|
||||
mActivity.getSupportActionBar().setTitle(R.string.system_info);
|
||||
mActivity.supportInvalidateOptionsMenu();
|
||||
LocalNodeInfoFragment.this.onDrawerOpened();
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -94,6 +85,29 @@ public class LocalNodeInfoFragment extends Fragment
|
|||
public void onActivityCreated(Bundle savedInstanceState) {
|
||||
super.onActivityCreated(savedInstanceState);
|
||||
mActivity = (MainActivity) getActivity();
|
||||
|
||||
if (savedInstanceState != null && savedInstanceState.getBoolean("active")) {
|
||||
onDrawerOpened();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSaveInstanceState(Bundle outState) {
|
||||
super.onSaveInstanceState(outState);
|
||||
outState.putBoolean("active", mTimer != null);
|
||||
}
|
||||
|
||||
private void onDrawerOpened() {
|
||||
mTimer = new Timer();
|
||||
mTimer.schedule(new TimerTask() {
|
||||
@Override
|
||||
public void run() {
|
||||
updateGui();
|
||||
}
|
||||
|
||||
}, 0, SyncthingService.GUI_UPDATE_INTERVAL);
|
||||
mActivity.getSupportActionBar().setTitle(R.string.system_info);
|
||||
mActivity.supportInvalidateOptionsMenu();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -119,6 +133,9 @@ public class LocalNodeInfoFragment extends Fragment
|
|||
*/
|
||||
@Override
|
||||
public void onReceiveSystemInfo(RestApi.SystemInfo info) {
|
||||
if (getActivity() == null)
|
||||
return;
|
||||
|
||||
mNodeId.setText(info.myID);
|
||||
mCpuUsage.setText(new DecimalFormat("0.00").format(info.cpuPercent) + "%");
|
||||
mRamUsage.setText(RestApi.readableFileSize(mActivity, info.sys));
|
||||
|
|
|
@ -13,6 +13,7 @@ import android.os.IBinder;
|
|||
import android.support.v4.app.ActionBarDrawerToggle;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.support.v4.app.FragmentManager;
|
||||
import android.support.v4.app.FragmentPagerAdapter;
|
||||
import android.support.v4.app.FragmentStatePagerAdapter;
|
||||
import android.support.v4.app.FragmentTransaction;
|
||||
import android.support.v4.view.ViewPager;
|
||||
|
@ -21,9 +22,11 @@ import android.support.v7.app.ActionBar;
|
|||
import android.support.v7.app.ActionBar.Tab;
|
||||
import android.support.v7.app.ActionBar.TabListener;
|
||||
import android.support.v7.app.ActionBarActivity;
|
||||
import android.util.Log;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
import android.view.OrientationEventListener;
|
||||
import android.view.View;
|
||||
import android.widget.FrameLayout;
|
||||
import android.widget.ProgressBar;
|
||||
|
@ -91,8 +94,8 @@ public class MainActivity extends ActionBarActivity
|
|||
getSupportActionBar().setHomeButtonEnabled(true);
|
||||
}
|
||||
|
||||
private final FragmentStatePagerAdapter mSectionsPagerAdapter =
|
||||
new FragmentStatePagerAdapter(getSupportFragmentManager()) {
|
||||
private final FragmentPagerAdapter mSectionsPagerAdapter =
|
||||
new FragmentPagerAdapter(getSupportFragmentManager()) {
|
||||
|
||||
@Override
|
||||
public Fragment getItem(int position) {
|
||||
|
@ -216,7 +219,8 @@ public class MainActivity extends ActionBarActivity
|
|||
protected void onSaveInstanceState(Bundle outState) {
|
||||
super.onSaveInstanceState(outState);
|
||||
// Avoid crash if called during startup.
|
||||
if (mRepositoriesFragment != null && mNodesFragment != null) {
|
||||
if (mRepositoriesFragment != null && mNodesFragment != null &&
|
||||
mLocalNodeInfoFragment != null) {
|
||||
FragmentManager fm = getSupportFragmentManager();
|
||||
fm.putFragment(outState, ReposFragment.class.getName(), mRepositoriesFragment);
|
||||
fm.putFragment(outState, NodesFragment.class.getName(), mNodesFragment);
|
||||
|
@ -297,5 +301,4 @@ public class MainActivity extends ActionBarActivity
|
|||
? mSyncthingService.getApi()
|
||||
: null;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue