Automatically switch to different screen when hiding current one from drawer (#6254)
This commit is contained in:
parent
4096aaf47e
commit
8248bc6bb1
|
@ -76,7 +76,6 @@ public class MainActivity extends CastEnabledActivity {
|
||||||
public static final String PREF_NAME = "MainActivityPrefs";
|
public static final String PREF_NAME = "MainActivityPrefs";
|
||||||
public static final String PREF_IS_FIRST_LAUNCH = "prefMainActivityIsFirstLaunch";
|
public static final String PREF_IS_FIRST_LAUNCH = "prefMainActivityIsFirstLaunch";
|
||||||
|
|
||||||
public static final String EXTRA_FRAGMENT_TAG = "fragment_tag";
|
|
||||||
public static final String EXTRA_FRAGMENT_ARGS = "fragment_args";
|
public static final String EXTRA_FRAGMENT_ARGS = "fragment_args";
|
||||||
public static final String EXTRA_FEED_ID = "fragment_feed_id";
|
public static final String EXTRA_FEED_ID = "fragment_feed_id";
|
||||||
public static final String EXTRA_REFRESH_ON_START = "refresh_on_start";
|
public static final String EXTRA_REFRESH_ON_START = "refresh_on_start";
|
||||||
|
@ -444,6 +443,9 @@ public class MainActivity extends CastEnabledActivity {
|
||||||
finish();
|
finish();
|
||||||
startActivity(new Intent(this, MainActivity.class));
|
startActivity(new Intent(this, MainActivity.class));
|
||||||
}
|
}
|
||||||
|
if (UserPreferences.getHiddenDrawerItems().contains(NavDrawerFragment.getLastNavFragment(this))) {
|
||||||
|
loadFragment(UserPreferences.getDefaultPage(), null);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -515,9 +517,10 @@ public class MainActivity extends CastEnabledActivity {
|
||||||
|
|
||||||
private void handleNavIntent() {
|
private void handleNavIntent() {
|
||||||
Intent intent = getIntent();
|
Intent intent = getIntent();
|
||||||
if (intent.hasExtra(EXTRA_FEED_ID) || intent.hasExtra(EXTRA_FRAGMENT_TAG) || intent.hasExtra(EXTRA_REFRESH_ON_START)) {
|
if (intent.hasExtra(EXTRA_FEED_ID) || intent.hasExtra(MainActivityStarter.EXTRA_FRAGMENT_TAG)
|
||||||
|
|| intent.hasExtra(EXTRA_REFRESH_ON_START)) {
|
||||||
Log.d(TAG, "handleNavIntent()");
|
Log.d(TAG, "handleNavIntent()");
|
||||||
String tag = intent.getStringExtra(EXTRA_FRAGMENT_TAG);
|
String tag = intent.getStringExtra(MainActivityStarter.EXTRA_FRAGMENT_TAG);
|
||||||
Bundle args = intent.getBundleExtra(EXTRA_FRAGMENT_ARGS);
|
Bundle args = intent.getBundleExtra(EXTRA_FRAGMENT_ARGS);
|
||||||
boolean refreshOnStart = intent.getBooleanExtra(EXTRA_REFRESH_ON_START, false);
|
boolean refreshOnStart = intent.getBooleanExtra(EXTRA_REFRESH_ON_START, false);
|
||||||
if (refreshOnStart) {
|
if (refreshOnStart) {
|
||||||
|
@ -543,6 +546,10 @@ public class MainActivity extends CastEnabledActivity {
|
||||||
} else if (Intent.ACTION_VIEW.equals(intent.getAction())) {
|
} else if (Intent.ACTION_VIEW.equals(intent.getAction())) {
|
||||||
handleDeeplink(intent.getData());
|
handleDeeplink(intent.getData());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (intent.hasExtra(MainActivityStarter.EXTRA_OPEN_DRAWER) && drawerLayout != null) {
|
||||||
|
drawerLayout.open();
|
||||||
|
}
|
||||||
// to avoid handling the intent twice when the configuration changes
|
// to avoid handling the intent twice when the configuration changes
|
||||||
setIntent(new Intent(MainActivity.this, MainActivity.class));
|
setIntent(new Intent(MainActivity.this, MainActivity.class));
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,16 +13,17 @@ import de.danoeh.antennapod.core.DownloadServiceCallbacks;
|
||||||
import de.danoeh.antennapod.net.download.serviceinterface.DownloadRequest;
|
import de.danoeh.antennapod.net.download.serviceinterface.DownloadRequest;
|
||||||
import de.danoeh.antennapod.fragment.CompletedDownloadsFragment;
|
import de.danoeh.antennapod.fragment.CompletedDownloadsFragment;
|
||||||
import de.danoeh.antennapod.fragment.QueueFragment;
|
import de.danoeh.antennapod.fragment.QueueFragment;
|
||||||
|
import de.danoeh.antennapod.ui.appstartintent.MainActivityStarter;
|
||||||
|
|
||||||
|
|
||||||
public class DownloadServiceCallbacksImpl implements DownloadServiceCallbacks {
|
public class DownloadServiceCallbacksImpl implements DownloadServiceCallbacks {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public PendingIntent getNotificationContentIntent(Context context) {
|
public PendingIntent getNotificationContentIntent(Context context) {
|
||||||
Intent intent = new Intent(context, MainActivity.class);
|
MainActivityStarter starter = new MainActivityStarter(context)
|
||||||
intent.putExtra(MainActivity.EXTRA_FRAGMENT_TAG, CompletedDownloadsFragment.TAG);
|
.withFragmentLoaded(CompletedDownloadsFragment.TAG);
|
||||||
return PendingIntent.getActivity(context,
|
return PendingIntent.getActivity(context,
|
||||||
R.id.pending_intent_download_service_notification, intent,
|
R.id.pending_intent_download_service_notification, starter.getIntent(),
|
||||||
PendingIntent.FLAG_UPDATE_CURRENT | (Build.VERSION.SDK_INT >= 23 ? PendingIntent.FLAG_IMMUTABLE : 0));
|
PendingIntent.FLAG_UPDATE_CURRENT | (Build.VERSION.SDK_INT >= 23 ? PendingIntent.FLAG_IMMUTABLE : 0));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -39,7 +40,7 @@ public class DownloadServiceCallbacksImpl implements DownloadServiceCallbacks {
|
||||||
@Override
|
@Override
|
||||||
public PendingIntent getReportNotificationContentIntent(Context context) {
|
public PendingIntent getReportNotificationContentIntent(Context context) {
|
||||||
Intent intent = new Intent(context, MainActivity.class);
|
Intent intent = new Intent(context, MainActivity.class);
|
||||||
intent.putExtra(MainActivity.EXTRA_FRAGMENT_TAG, CompletedDownloadsFragment.TAG);
|
intent.putExtra(MainActivityStarter.EXTRA_FRAGMENT_TAG, CompletedDownloadsFragment.TAG);
|
||||||
Bundle args = new Bundle();
|
Bundle args = new Bundle();
|
||||||
args.putBoolean(CompletedDownloadsFragment.ARG_SHOW_LOGS, true);
|
args.putBoolean(CompletedDownloadsFragment.ARG_SHOW_LOGS, true);
|
||||||
intent.putExtra(MainActivity.EXTRA_FRAGMENT_ARGS, args);
|
intent.putExtra(MainActivity.EXTRA_FRAGMENT_ARGS, args);
|
||||||
|
@ -50,7 +51,7 @@ public class DownloadServiceCallbacksImpl implements DownloadServiceCallbacks {
|
||||||
@Override
|
@Override
|
||||||
public PendingIntent getAutoDownloadReportNotificationContentIntent(Context context) {
|
public PendingIntent getAutoDownloadReportNotificationContentIntent(Context context) {
|
||||||
Intent intent = new Intent(context, MainActivity.class);
|
Intent intent = new Intent(context, MainActivity.class);
|
||||||
intent.putExtra(MainActivity.EXTRA_FRAGMENT_TAG, QueueFragment.TAG);
|
intent.putExtra(MainActivityStarter.EXTRA_FRAGMENT_TAG, QueueFragment.TAG);
|
||||||
return PendingIntent.getActivity(context, R.id.pending_intent_download_service_autodownload_report, intent,
|
return PendingIntent.getActivity(context, R.id.pending_intent_download_service_autodownload_report, intent,
|
||||||
PendingIntent.FLAG_UPDATE_CURRENT | (Build.VERSION.SDK_INT >= 23 ? PendingIntent.FLAG_IMMUTABLE : 0));
|
PendingIntent.FLAG_UPDATE_CURRENT | (Build.VERSION.SDK_INT >= 23 ? PendingIntent.FLAG_IMMUTABLE : 0));
|
||||||
}
|
}
|
||||||
|
|
|
@ -40,6 +40,7 @@ import de.danoeh.antennapod.event.FeedListUpdateEvent;
|
||||||
import de.danoeh.antennapod.event.QueueEvent;
|
import de.danoeh.antennapod.event.QueueEvent;
|
||||||
import de.danoeh.antennapod.event.UnreadItemsUpdateEvent;
|
import de.danoeh.antennapod.event.UnreadItemsUpdateEvent;
|
||||||
import de.danoeh.antennapod.model.feed.Feed;
|
import de.danoeh.antennapod.model.feed.Feed;
|
||||||
|
import de.danoeh.antennapod.ui.appstartintent.MainActivityStarter;
|
||||||
import de.danoeh.antennapod.ui.home.HomeFragment;
|
import de.danoeh.antennapod.ui.home.HomeFragment;
|
||||||
import io.reactivex.Observable;
|
import io.reactivex.Observable;
|
||||||
import io.reactivex.android.schedulers.AndroidSchedulers;
|
import io.reactivex.android.schedulers.AndroidSchedulers;
|
||||||
|
@ -338,7 +339,13 @@ public class NavDrawerFragment extends Fragment implements SharedPreferences.OnS
|
||||||
@Override
|
@Override
|
||||||
public boolean onItemLongClick(int position) {
|
public boolean onItemLongClick(int position) {
|
||||||
if (position < navAdapter.getFragmentTags().size()) {
|
if (position < navAdapter.getFragmentTags().size()) {
|
||||||
DrawerPreferencesDialog.show(getContext(), () -> navAdapter.notifyDataSetChanged());
|
DrawerPreferencesDialog.show(getContext(), () -> {
|
||||||
|
navAdapter.notifyDataSetChanged();
|
||||||
|
if (UserPreferences.getHiddenDrawerItems().contains(getLastNavFragment(getContext()))) {
|
||||||
|
new MainActivityStarter(getContext())
|
||||||
|
.withFragmentLoaded(UserPreferences.getDefaultPage()).start();
|
||||||
|
}
|
||||||
|
});
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
contextPressedItem = flatItemList.get(position - navAdapter.getSubscriptionOffset());
|
contextPressedItem = flatItemList.get(position - navAdapter.getSubscriptionOffset());
|
||||||
|
|
|
@ -14,6 +14,8 @@ public class MainActivityStarter {
|
||||||
public static final String EXTRA_OPEN_PLAYER = "open_player";
|
public static final String EXTRA_OPEN_PLAYER = "open_player";
|
||||||
public static final String EXTRA_FEED_ID = "fragment_feed_id";
|
public static final String EXTRA_FEED_ID = "fragment_feed_id";
|
||||||
public static final String EXTRA_ADD_TO_BACK_STACK = "add_to_back_stack";
|
public static final String EXTRA_ADD_TO_BACK_STACK = "add_to_back_stack";
|
||||||
|
public static final String EXTRA_FRAGMENT_TAG = "fragment_tag";
|
||||||
|
public static final String EXTRA_OPEN_DRAWER = "open_drawer";
|
||||||
|
|
||||||
private final Intent intent;
|
private final Intent intent;
|
||||||
private final Context context;
|
private final Context context;
|
||||||
|
@ -51,4 +53,14 @@ public class MainActivityStarter {
|
||||||
intent.putExtra(EXTRA_ADD_TO_BACK_STACK, true);
|
intent.putExtra(EXTRA_ADD_TO_BACK_STACK, true);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public MainActivityStarter withFragmentLoaded(String fragmentName) {
|
||||||
|
intent.putExtra(EXTRA_FRAGMENT_TAG, fragmentName);
|
||||||
|
return withDrawerOpen();
|
||||||
|
}
|
||||||
|
|
||||||
|
private MainActivityStarter withDrawerOpen() {
|
||||||
|
intent.putExtra(EXTRA_OPEN_DRAWER, true);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue