Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 44be9131 authored by Fan Zhang's avatar Fan Zhang
Browse files

Open personal settings tab when launching homepage

Change-Id: I341e1a128fda7db8f953f9a0800050cc007554c5
Fixes: 114441682
Test: manual/robotest
parent ea0b32d1
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -124,7 +124,7 @@
                android:value="true" />
        </activity>

        <activity android:name=".SettingsHomepageActivity"
        <activity android:name=".homepage.SettingsHomepageActivity"
                  android:taskAffinity="com.android.settings.root"
                  android:label="@string/settings_label_launcher"
                  android:theme="@style/Theme.Settings.Home"
@@ -136,7 +136,7 @@
                android:taskAffinity="com.android.settings.root"
                android:label="@string/settings_label_launcher"
                android:launchMode="singleTask"
                android:targetActivity=".SettingsHomepageActivity">
                android:targetActivity=".homepage.SettingsHomepageActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.DEFAULT" />
+1 −0
Original line number Diff line number Diff line
@@ -62,6 +62,7 @@ import com.android.settings.core.SubSettingLauncher;
import com.android.settings.core.gateway.SettingsGateway;
import com.android.settings.dashboard.DashboardFeatureProvider;
import com.android.settings.dashboard.DashboardSummary;
import com.android.settings.homepage.SettingsHomepageActivity;
import com.android.settings.homepage.TopLevelSettings;
import com.android.settings.overlay.FeatureFactory;
import com.android.settings.search.DeviceIndexFeatureProvider;
+16 −12
Original line number Diff line number Diff line
@@ -14,32 +14,31 @@
 * limitations under the License.
 */

package com.android.settings;
package com.android.settings.homepage;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.util.FeatureFlagUtils;

import androidx.annotation.VisibleForTesting;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentTransaction;

import com.android.settings.R;
import com.android.settings.core.FeatureFlags;
import com.android.settings.core.SettingsBaseActivity;
import com.android.settings.dashboard.DashboardSummary;
import com.android.settings.homepage.PersonalSettingsFragment;
import com.android.settings.homepage.TopLevelSettings;
import com.android.settings.overlay.FeatureFactory;
import com.android.settings.search.SearchFeatureProvider;

import com.google.android.material.bottomnavigation.BottomNavigationView;
import com.google.android.material.floatingactionbutton.FloatingActionButton;

public class SettingsHomepageActivity extends SettingsBaseActivity {

    @VisibleForTesting
    static final String PERSONAL_SETTINGS_TAG = "personal_settings";
    private static final String ALL_SETTINGS_TAG = "all_settings";
    private static final String PERSONAL_SETTINGS_TAG = "personal_settings";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
@@ -63,25 +62,31 @@ public class SettingsHomepageActivity extends SettingsBaseActivity {
        navigation.setOnNavigationItemSelectedListener(item -> {
            switch (item.getItemId()) {
                case R.id.homepage_personal_settings:
                    switchFragment(PersonalSettingsFragment.class.getName(), PERSONAL_SETTINGS_TAG,
                    switchFragment(new PersonalSettingsFragment(), PERSONAL_SETTINGS_TAG,
                            ALL_SETTINGS_TAG);
                    return true;

                case R.id.homepage_all_settings:
                    switchFragment(TopLevelSettings.class.getName(), ALL_SETTINGS_TAG,
                    switchFragment(new TopLevelSettings(), ALL_SETTINGS_TAG,
                            PERSONAL_SETTINGS_TAG);
                    return true;
            }
            return false;
        });

        if (savedInstanceState == null) {
            // savedInstanceState is null, this is first load.
            // Default to open contextual cards.
            switchFragment(new PersonalSettingsFragment(), PERSONAL_SETTINGS_TAG,
                    ALL_SETTINGS_TAG);
        }
    }

    public static boolean isDynamicHomepageEnabled(Context context) {
        return FeatureFlagUtils.isEnabled(context, FeatureFlags.DYNAMIC_HOMEPAGE);
    }

    private void switchFragment(String fragmentName, String showFragmentTag,
            String hideFragmentTag) {
    private void switchFragment(Fragment fragment, String showFragmentTag, String hideFragmentTag) {
        final FragmentManager fragmentManager = getSupportFragmentManager();
        final FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();

@@ -92,8 +97,7 @@ public class SettingsHomepageActivity extends SettingsBaseActivity {

        Fragment showFragment = fragmentManager.findFragmentByTag(showFragmentTag);
        if (showFragment == null) {
            showFragment = Fragment.instantiate(this, fragmentName, null /* args */);
            fragmentTransaction.add(R.id.main_content, showFragment, showFragmentTag);
            fragmentTransaction.add(R.id.main_content, fragment, showFragmentTag);
        } else {
            fragmentTransaction.show(showFragment);
        }
+10 −1
Original line number Diff line number Diff line
@@ -7,4 +7,13 @@
    <!-- Override the main app's style for ActionPrimaryButton to get around lack of new style
         support in robolectric  -->
    <style name="ActionPrimaryButton" parent="android:Widget.DeviceDefault.Button"/>

    <!-- Test version of Theme.Settings.Home. Needed to build homepage activity in Robolectric -->
    <style name="Theme.Settings.Home" parent="Theme.AppCompat.DayNight.NoActionBar">
        <item name="colorPrimary">#ffffff</item>
        <item name="colorPrimaryDark">#ffffff</item>
        <item name="colorAccent">#ffffff</item>
        <item name="preferenceTheme">@style/PreferenceTheme</item>
        <item name="android:windowLightStatusBar">true</item>
    </style>
</resources>
+57 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2018 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.settings.homepage;

import static com.android.settings.homepage.SettingsHomepageActivity.PERSONAL_SETTINGS_TAG;

import static com.google.common.truth.Truth.assertThat;

import android.content.Context;
import android.util.FeatureFlagUtils;

import androidx.fragment.app.Fragment;

import com.android.settings.core.FeatureFlags;
import com.android.settings.testutils.SettingsRobolectricTestRunner;

import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.robolectric.Robolectric;
import org.robolectric.RuntimeEnvironment;

@RunWith(SettingsRobolectricTestRunner.class)
public class SettingsHomepageActivityTest {

    private Context mContext;
    private SettingsHomepageActivity mActivity;

    @Before
    public void setUp() {
        mContext = RuntimeEnvironment.application;
        FeatureFlagUtils.setEnabled(mContext, FeatureFlags.DYNAMIC_HOMEPAGE, true);
    }

    @Test
    public void launchHomepage_shouldOpenPersonalSettings() {
        mActivity = Robolectric.setupActivity(SettingsHomepageActivity.class);
        final Fragment fragment = mActivity.getSupportFragmentManager()
                .findFragmentByTag(PERSONAL_SETTINGS_TAG);

        assertThat(fragment).isInstanceOf(PersonalSettingsFragment.class);
    }
}
Loading