Skip to content

Commit

Permalink
Add back-button navigation in pinned addons directories
Browse files Browse the repository at this point in the history
Following xbmc#980, and for consistency, this also applies the back navigation to pinned addons directories.
  • Loading branch information
SyncedSynapse committed Nov 13, 2023
1 parent 7e1fb80 commit ba3cf05
Showing 1 changed file with 42 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,11 @@
*/
package org.xbmc.kore.ui.sections.addon;

import android.content.Context;
import android.content.SharedPreferences;
import android.os.Bundle;

import androidx.fragment.app.Fragment;
import androidx.preference.PreferenceManager;
import android.view.View;

Expand All @@ -29,14 +32,19 @@
import org.xbmc.kore.jsonrpc.method.Files;
import org.xbmc.kore.ui.AbstractInfoFragment;
import org.xbmc.kore.ui.AbstractTabsFragment;
import org.xbmc.kore.ui.BaseMediaActivity;
import org.xbmc.kore.ui.OnBackPressedListener;
import org.xbmc.kore.ui.sections.file.MediaFileListFragment;
import org.xbmc.kore.utils.LogUtils;
import org.xbmc.kore.utils.TabsAdapter;

import java.util.Collections;
import java.util.Set;

public class AddonListContainerFragment extends AbstractTabsFragment {
public class AddonListContainerFragment
extends AbstractTabsFragment
implements OnBackPressedListener {

private static final String TAG = LogUtils.makeLogTag(AddonListContainerFragment.class);

@Override
Expand Down Expand Up @@ -80,6 +88,39 @@ protected TabsAdapter createTabsAdapter(AbstractInfoFragment.DataHolder dataHold
return tabsAdapter;
}

@Override
public void onAttach(@NonNull Context context) {
super.onAttach(context);
try {
BaseMediaActivity listenerActivity = (BaseMediaActivity) context;
listenerActivity.setBackPressedListener(this);
} catch (ClassCastException e) {
throw new ClassCastException(context + " unable to register BackPressedListener");
}
}

@Override
public void onDestroy() {
try {
BaseMediaActivity listenerActivity = (BaseMediaActivity) getContext();
assert listenerActivity != null;
listenerActivity.setBackPressedListener(null);
} catch (ClassCastException e) {
throw new ClassCastException(getContext() + " unable to unregister BackPressedListener");
}
super.onDestroy();
}

@Override
public boolean onBackPressed() {
// Tell current fragment to move up one directory, if possible
Fragment fragment = getCurrentSelectedFragment();
if (fragment instanceof MediaFileListFragment) {
return ((MediaFileListFragment) fragment).navigateToParentDir();
}
return false;
}

@Override
protected boolean shouldRememberLastTab() {
return true;
Expand Down

0 comments on commit ba3cf05

Please sign in to comment.