Skip to content

Commit

Permalink
Close open dialogs onPause()
Browse files Browse the repository at this point in the history
  • Loading branch information
baron committed Feb 8, 2021
1 parent def51fb commit 886e8d2
Showing 1 changed file with 19 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

package org.secuso.privacyfriendlypasswordgenerator.activities;

import androidx.fragment.app.DialogFragment;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
Expand Down Expand Up @@ -78,6 +79,8 @@ public class MainActivity extends BaseActivity {

private LinearLayout initialAlert;

private DialogFragment activeDialog;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Expand Down Expand Up @@ -134,9 +137,9 @@ public void onItemClick(View view, int position) {
bundle.putInt("number_iterations", number_iterations);

FragmentManager fragmentManager = getSupportFragmentManager();
GeneratePasswordDialog generatePasswordDialog = new GeneratePasswordDialog();
generatePasswordDialog.setArguments(bundle);
generatePasswordDialog.show(fragmentManager, "GeneratePasswordDialog");
activeDialog = new GeneratePasswordDialog();
activeDialog.setArguments(bundle);
activeDialog.show(fragmentManager, "GeneratePasswordDialog");

PrefManager prefManager = new PrefManager(getBaseContext());
if (prefManager.isFirstTimeGen()) {
Expand All @@ -161,9 +164,9 @@ public void onLongItemClick(View view, int position) {
bundle.putBoolean("bindToDevice_enabled", bindToDevice_enabled);

FragmentManager fragmentManager = getSupportFragmentManager();
UpdateMetadataDialog updateMetadataDialog = new UpdateMetadataDialog();
updateMetadataDialog.setArguments(bundle);
updateMetadataDialog.show(fragmentManager, "UpdateMetadataDialog");
activeDialog = new UpdateMetadataDialog();
activeDialog.setArguments(bundle);
activeDialog.show(fragmentManager, "UpdateMetadataDialog");
}
})
);
Expand Down Expand Up @@ -206,8 +209,8 @@ public void onDismissedBySwipeLeft(RecyclerView recyclerView, int[] reverseSorte
@Override
public void onClick(View view) {
FragmentManager fragmentManager = getSupportFragmentManager();
AddMetaDataDialog addMetaDataDialog = new AddMetaDataDialog();
addMetaDataDialog.show(fragmentManager, "AddMetaDataDialog");
activeDialog = new AddMetaDataDialog();
activeDialog.show(fragmentManager, "AddMetaDataDialog");
}
});

Expand Down Expand Up @@ -304,6 +307,14 @@ public void onResume() {
loadDatabase();
}

@Override
public void onPause() {
super.onPause();
if (activeDialog != null) {
activeDialog.dismissAllowingStateLoss();
activeDialog = null;
}

private void loadDatabase() {
if(database != null) {
metadatalist = database.getAllMetaData();
Expand Down

1 comment on commit 886e8d2

@fgndev
Copy link

@fgndev fgndev commented on 886e8d2 Feb 8, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, this was actually meant to be a separate PR fixing #18

Please sign in to comment.