From: Soren Stoutner Date: Tue, 18 Jul 2017 03:01:00 +0000 (-0700) Subject: Load domain settings after creating a new domain in single-paned mode. Implements... X-Git-Tag: v2.5~13 X-Git-Url: https://gitweb.stoutner.com/?a=commitdiff_plain;h=ff7805a7cc8f85fb54302fcf7fa3ca146a89dc4f;p=PrivacyBrowserAndroid.git Load domain settings after creating a new domain in single-paned mode. Implements https://redmine.stoutner.com/issues/108. --- diff --git a/app/src/main/java/com/stoutner/privacybrowser/activities/DomainsActivity.java b/app/src/main/java/com/stoutner/privacybrowser/activities/DomainsActivity.java index 7c0b17a6..a2697663 100644 --- a/app/src/main/java/com/stoutner/privacybrowser/activities/DomainsActivity.java +++ b/app/src/main/java/com/stoutner/privacybrowser/activities/DomainsActivity.java @@ -377,11 +377,33 @@ public class DomainsActivity extends AppCompatActivity implements AddDomainDialo EditText domainNameEditText = (EditText) dialogFragment.getDialog().findViewById(R.id.domain_name_edittext); String domainNameString = domainNameEditText.getText().toString(); - // Create the domain. - domainsDatabaseHelper.addDomain(domainNameString); + // Create the domain and store the database ID in `currentDomainDatabaseId`. + currentDomainDatabaseId = domainsDatabaseHelper.addDomain(domainNameString); - // Populate the `ListView`. - populateDomainsListView(); + // Add `currentDomainDatabaseId` to `argumentsBundle`. + Bundle argumentsBundle = new Bundle(); + argumentsBundle.putInt(DomainSettingsFragment.DATABASE_ID, currentDomainDatabaseId); + + // Add `argumentsBundle` to `domainSettingsFragment`. + DomainSettingsFragment domainSettingsFragment = new DomainSettingsFragment(); + domainSettingsFragment.setArguments(argumentsBundle); + + // Display the newly created domain. + if (twoPanedMode) { + + } else { + // Hide `add_domain_fab`. + addDomainFAB.setVisibility(View.GONE); + + // Show and enable `deleteMenuItem`. + DomainsActivity.deleteMenuItem.setVisible(true); + + // Set `domainSettingsFragmentDisplayed`. + DomainsActivity.domainSettingsFragmentDisplayed = true; + + // Display `domainSettingsFragment`. + supportFragmentManager.beginTransaction().replace(R.id.domains_listview_fragment_container, domainSettingsFragment).commit(); + } } private void saveDomainSettings() { diff --git a/app/src/main/java/com/stoutner/privacybrowser/helpers/DomainsDatabaseHelper.java b/app/src/main/java/com/stoutner/privacybrowser/helpers/DomainsDatabaseHelper.java index 86a1ed12..bb1a9c5c 100644 --- a/app/src/main/java/com/stoutner/privacybrowser/helpers/DomainsDatabaseHelper.java +++ b/app/src/main/java/com/stoutner/privacybrowser/helpers/DomainsDatabaseHelper.java @@ -131,7 +131,7 @@ public class DomainsDatabaseHelper extends SQLiteOpenHelper { return domainsDatabase.rawQuery(GET_CURSOR_FOR_DOMAIN_NAME, null); } - public void addDomain(String domainName) { + public int addDomain(String domainName) { // Store the domain data in a `ContentValues`. ContentValues domainContentValues = new ContentValues(); @@ -149,11 +149,13 @@ public class DomainsDatabaseHelper extends SQLiteOpenHelper { // Get a writable database handle. SQLiteDatabase domainsDatabase = this.getWritableDatabase(); - // Insert a new row. The second argument is `null`, which makes it so that a completely null row cannot be created. - domainsDatabase.insert(DOMAINS_TABLE, null, domainContentValues); + // Insert a new row and store the resulting database ID. The second argument is `null`, which makes it so that a completely null row cannot be created. + int newDomainDatabaseId = (int) domainsDatabase.insert(DOMAINS_TABLE, null, domainContentValues); // Close the database handle. domainsDatabase.close(); + + return newDomainDatabaseId; } public void saveDomain(int databaseId, String domainName, boolean javaScriptEnabled, boolean firstPartyCookiesEnabled, boolean thirdPartyCookiesEnabled, boolean domStorageEnabled, boolean formDataEnabled, String userAgent, int fontSize,