mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge
synced 2024-12-18 06:37:47 +01:00
Refactor the way the changelog is displayed
As described in #1065, once the changelog was selected from the navigation menu, and the user rotated the device, the changelog was disappearing. Using a DialogFragment seems to be the more idiomatic way on displaying the changelog, and it also takes care of recreating it when the device changes orientation. Partially fixes #1065 Signed-off-by: Linos Giannopoulos <linosgian00@gmail.com>
This commit is contained in:
parent
550e6a86f2
commit
ae02bbc9c3
@ -53,6 +53,7 @@ import androidx.annotation.RequiresApi;
|
|||||||
import androidx.appcompat.app.ActionBarDrawerToggle;
|
import androidx.appcompat.app.ActionBarDrawerToggle;
|
||||||
import androidx.appcompat.app.AppCompatActivity;
|
import androidx.appcompat.app.AppCompatActivity;
|
||||||
import androidx.appcompat.app.AppCompatDelegate;
|
import androidx.appcompat.app.AppCompatDelegate;
|
||||||
|
import androidx.appcompat.app.AlertDialog;
|
||||||
import androidx.core.app.ActivityCompat;
|
import androidx.core.app.ActivityCompat;
|
||||||
import androidx.core.app.NotificationManagerCompat;
|
import androidx.core.app.NotificationManagerCompat;
|
||||||
import androidx.core.content.ContextCompat;
|
import androidx.core.content.ContextCompat;
|
||||||
@ -114,6 +115,7 @@ public class ControlCenterv2 extends AppCompatActivity
|
|||||||
private FragmentStateAdapter pagerAdapter;
|
private FragmentStateAdapter pagerAdapter;
|
||||||
private SwipeRefreshLayout swipeLayout;
|
private SwipeRefreshLayout swipeLayout;
|
||||||
private static PhoneStateListener fakeStateListener;
|
private static PhoneStateListener fakeStateListener;
|
||||||
|
private AlertDialog clDialog;
|
||||||
|
|
||||||
//needed for KK compatibility
|
//needed for KK compatibility
|
||||||
static {
|
static {
|
||||||
@ -190,6 +192,22 @@ public class ControlCenterv2 extends AppCompatActivity
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (savedInstanceState != null) {
|
||||||
|
if (savedInstanceState.getBoolean("cl")) {
|
||||||
|
GBChangeLog cl = GBChangeLog.createChangeLog(this);
|
||||||
|
try {
|
||||||
|
if (cl.hasChanges(false)) {
|
||||||
|
clDialog = cl.getMaterialLogDialog();
|
||||||
|
} else {
|
||||||
|
clDialog = cl.getMaterialFullLogDialog();
|
||||||
|
}
|
||||||
|
clDialog.show();
|
||||||
|
} catch (Exception ignored) {
|
||||||
|
GB.toast(getBaseContext(), getString(R.string.error_showing_changelog), Toast.LENGTH_LONG, GB.ERROR);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// Initialize drawer
|
// Initialize drawer
|
||||||
NavigationView drawerNavigationView = findViewById(R.id.nav_view);
|
NavigationView drawerNavigationView = findViewById(R.id.nav_view);
|
||||||
@ -378,6 +396,14 @@ public class ControlCenterv2 extends AppCompatActivity
|
|||||||
GBApplication.deviceService().requestDeviceInfo();
|
GBApplication.deviceService().requestDeviceInfo();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onSaveInstanceState(@NonNull Bundle outState) {
|
||||||
|
if (clDialog != null){
|
||||||
|
outState.putBoolean("cl", clDialog.isShowing());
|
||||||
|
}
|
||||||
|
super.onSaveInstanceState(outState);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onResume() {
|
protected void onResume() {
|
||||||
super.onResume();
|
super.onResume();
|
||||||
@ -425,13 +451,14 @@ public class ControlCenterv2 extends AppCompatActivity
|
|||||||
startActivity(i);
|
startActivity(i);
|
||||||
return false;
|
return false;
|
||||||
} else if (itemId == R.id.external_changelog) {
|
} else if (itemId == R.id.external_changelog) {
|
||||||
final GBChangeLog cl = createChangeLog();
|
final GBChangeLog cl = GBChangeLog.createChangeLog(this);
|
||||||
try {
|
try {
|
||||||
if (cl.hasChanges(false)) {
|
if (cl.hasChanges(false)) {
|
||||||
cl.getMaterialLogDialog().show();
|
clDialog = cl.getMaterialLogDialog();
|
||||||
} else {
|
} else {
|
||||||
cl.getMaterialFullLogDialog().show();
|
clDialog = cl.getMaterialFullLogDialog();
|
||||||
}
|
}
|
||||||
|
clDialog.show();
|
||||||
} catch (Exception ignored) {
|
} catch (Exception ignored) {
|
||||||
GB.toast(getBaseContext(), getString(R.string.error_showing_changelog), Toast.LENGTH_LONG, GB.ERROR);
|
GB.toast(getBaseContext(), getString(R.string.error_showing_changelog), Toast.LENGTH_LONG, GB.ERROR);
|
||||||
}
|
}
|
||||||
@ -445,13 +472,6 @@ public class ControlCenterv2 extends AppCompatActivity
|
|||||||
return false; // we do not want the drawer menu item to get selected
|
return false; // we do not want the drawer menu item to get selected
|
||||||
}
|
}
|
||||||
|
|
||||||
private GBChangeLog createChangeLog() {
|
|
||||||
String css = GBChangeLog.DEFAULT_CSS;
|
|
||||||
css += "body { "
|
|
||||||
+ "color: " + AndroidUtils.getTextColorHex(getBaseContext()) + "; "
|
|
||||||
+ "}";
|
|
||||||
return new GBChangeLog(this, css);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void launchDiscoveryActivity() {
|
private void launchDiscoveryActivity() {
|
||||||
startActivity(new Intent(this, DiscoveryActivityV2.class));
|
startActivity(new Intent(this, DiscoveryActivityV2.class));
|
||||||
|
Loading…
Reference in New Issue
Block a user