1
0
mirror of https://codeberg.org/Freeyourgadget/Gadgetbridge synced 2024-11-03 17:02:13 +01:00

no not refresh whole activity when deciding whether fab should be shown or not

This commit is contained in:
Andreas Shimokawa 2019-09-17 14:02:35 +02:00
parent 4641e51715
commit e491a8c21d

View File

@ -74,6 +74,7 @@ public class ControlCenterv2 extends AppCompatActivity
private GBDeviceAdapterv2 mGBDeviceAdapter; private GBDeviceAdapterv2 mGBDeviceAdapter;
private RecyclerView deviceListView; private RecyclerView deviceListView;
private FloatingActionButton fab;
private boolean isLanguageInvalid = false; private boolean isLanguageInvalid = false;
@ -128,8 +129,7 @@ public class ControlCenterv2 extends AppCompatActivity
deviceListView.setAdapter(this.mGBDeviceAdapter); deviceListView.setAdapter(this.mGBDeviceAdapter);
//we need deviceList so fab logic moved to here fab = findViewById(R.id.fab);
FloatingActionButton fab = findViewById(R.id.fab);
fab.setOnClickListener(new View.OnClickListener() { fab.setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
@ -137,15 +137,7 @@ public class ControlCenterv2 extends AppCompatActivity
} }
}); });
if (GBApplication.getPrefs().getBoolean("display_add_device_fab", true)) { showFabIfNeccessary();
fab.show();
} else {
if (deviceList.isEmpty()) {
fab.show();
} else {
fab.hide();
}
}
/* uncomment to enable fixed-swipe to reveal more actions /* uncomment to enable fixed-swipe to reveal more actions
@ -249,7 +241,7 @@ public class ControlCenterv2 extends AppCompatActivity
protected void onActivityResult(int requestCode, int resultCode, Intent data) { protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data); super.onActivityResult(requestCode, resultCode, data);
if (requestCode == MENU_REFRESH_CODE) { if (requestCode == MENU_REFRESH_CODE) {
this.recreate(); showFabIfNeccessary();
} }
} }
@ -303,7 +295,9 @@ public class ControlCenterv2 extends AppCompatActivity
+ "color: " + AndroidUtils.getTextColorHex(getBaseContext()) + "; " + "color: " + AndroidUtils.getTextColorHex(getBaseContext()) + "; "
+ "background-color: " + AndroidUtils.getBackgroundColorHex(getBaseContext()) + ";" + + "background-color: " + AndroidUtils.getBackgroundColorHex(getBaseContext()) + ";" +
"}"; "}";
return new ChangeLog(this, css);} return new ChangeLog(this, css);
}
private void launchDiscoveryActivity() { private void launchDiscoveryActivity() {
startActivity(new Intent(this, DiscoveryActivity.class)); startActivity(new Intent(this, DiscoveryActivity.class));
} }
@ -312,6 +306,18 @@ public class ControlCenterv2 extends AppCompatActivity
mGBDeviceAdapter.notifyDataSetChanged(); mGBDeviceAdapter.notifyDataSetChanged();
} }
private void showFabIfNeccessary() {
if (GBApplication.getPrefs().getBoolean("display_add_device_fab", true)) {
fab.show();
} else {
if (deviceListView.getChildCount() < 1) {
fab.show();
} else {
fab.hide();
}
}
}
@TargetApi(Build.VERSION_CODES.M) @TargetApi(Build.VERSION_CODES.M)
private void checkAndRequestPermissions() { private void checkAndRequestPermissions() {
List<String> wantedPermissions = new ArrayList<>(); List<String> wantedPermissions = new ArrayList<>();
@ -347,7 +353,7 @@ public class ControlCenterv2 extends AppCompatActivity
} }
if (!wantedPermissions.isEmpty()) if (!wantedPermissions.isEmpty())
ActivityCompat.requestPermissions(this, wantedPermissions.toArray(new String[wantedPermissions.size()]), 0); ActivityCompat.requestPermissions(this, wantedPermissions.toArray(new String[0]), 0);
} }
public void setLanguage(Locale language, boolean invalidateLanguage) { public void setLanguage(Locale language, boolean invalidateLanguage) {