mirror of https://github.com/FongMi/TV.git
parent
e49782fc08
commit
39a048f13f
@ -0,0 +1,109 @@ |
|||||||
|
package com.fongmi.android.tv.ui.fragment; |
||||||
|
|
||||||
|
import android.os.Bundle; |
||||||
|
import android.view.LayoutInflater; |
||||||
|
import android.view.ViewGroup; |
||||||
|
|
||||||
|
import androidx.annotation.NonNull; |
||||||
|
import androidx.annotation.Nullable; |
||||||
|
import androidx.fragment.app.FragmentTransaction; |
||||||
|
import androidx.viewbinding.ViewBinding; |
||||||
|
|
||||||
|
import com.fongmi.android.tv.R; |
||||||
|
import com.fongmi.android.tv.bean.Result; |
||||||
|
import com.fongmi.android.tv.bean.Style; |
||||||
|
import com.fongmi.android.tv.bean.Value; |
||||||
|
import com.fongmi.android.tv.databinding.FragmentFolderBinding; |
||||||
|
import com.fongmi.android.tv.ui.base.BaseFragment; |
||||||
|
import com.github.catvod.utils.Prefers; |
||||||
|
|
||||||
|
import java.util.HashMap; |
||||||
|
import java.util.Optional; |
||||||
|
|
||||||
|
public class FolderFragment extends BaseFragment { |
||||||
|
|
||||||
|
public static FolderFragment newInstance(String key, String typeId, Style style, HashMap<String, String> extend, boolean folder, int y) { |
||||||
|
Bundle args = new Bundle(); |
||||||
|
args.putInt("y", y); |
||||||
|
args.putString("key", key); |
||||||
|
args.putString("typeId", typeId); |
||||||
|
args.putBoolean("folder", folder); |
||||||
|
args.putParcelable("style", style); |
||||||
|
args.putSerializable("extend", extend); |
||||||
|
FolderFragment fragment = new FolderFragment(); |
||||||
|
fragment.setArguments(args); |
||||||
|
return fragment; |
||||||
|
} |
||||||
|
|
||||||
|
private String getKey() { |
||||||
|
return getArguments().getString("key"); |
||||||
|
} |
||||||
|
|
||||||
|
private String getTypeId() { |
||||||
|
return getArguments().getString("typeId"); |
||||||
|
} |
||||||
|
|
||||||
|
private boolean getFolder() { |
||||||
|
return getArguments().getBoolean("folder"); |
||||||
|
} |
||||||
|
|
||||||
|
private Style getStyle() { |
||||||
|
return getArguments().getParcelable("style"); |
||||||
|
} |
||||||
|
|
||||||
|
private HashMap<String, String> getExtend() { |
||||||
|
return (HashMap<String, String>) getArguments().getSerializable("extend"); |
||||||
|
} |
||||||
|
|
||||||
|
private int getY() { |
||||||
|
return getArguments().getInt("y"); |
||||||
|
} |
||||||
|
|
||||||
|
private VodFragment getParent() { |
||||||
|
return (VodFragment) getParentFragment(); |
||||||
|
} |
||||||
|
|
||||||
|
private TypeFragment getChild() { |
||||||
|
return (TypeFragment) getChildFragmentManager().findFragmentById(R.id.container); |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
protected ViewBinding getBinding(@NonNull LayoutInflater inflater, @Nullable ViewGroup container) { |
||||||
|
return FragmentFolderBinding.inflate(inflater, container, false); |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
protected void initView() { |
||||||
|
getChildFragmentManager().beginTransaction().replace(R.id.container, TypeFragment.newInstance(getKey(), getTypeId(), getStyle(), getExtend(), getFolder(), getY())).commit(); |
||||||
|
} |
||||||
|
|
||||||
|
public void openFolder(String typeId, HashMap<String, String> extend) { |
||||||
|
Prefers.put("filter_" + getKey() + "_" + typeId, Prefers.getString("filter_" + getKey() + "_" + getTypeId())); |
||||||
|
TypeFragment next = TypeFragment.newInstance(getKey(), typeId, getStyle(), extend, getFolder(), getY()); |
||||||
|
FragmentTransaction ft = getChildFragmentManager().beginTransaction(); |
||||||
|
Optional.ofNullable(getChild()).ifPresent(ft::hide); |
||||||
|
ft.add(R.id.container, next); |
||||||
|
ft.addToBackStack(null); |
||||||
|
ft.commit(); |
||||||
|
} |
||||||
|
|
||||||
|
public Result getResult() { |
||||||
|
return getParent().getResult(); |
||||||
|
} |
||||||
|
|
||||||
|
public void scrollToTop() { |
||||||
|
Optional.ofNullable(getChild()).ifPresent(TypeFragment::scrollToTop); |
||||||
|
} |
||||||
|
|
||||||
|
public void setFilter(String key, Value value) { |
||||||
|
Optional.ofNullable(getChild()).ifPresent(f -> f.setFilter(key, value)); |
||||||
|
} |
||||||
|
|
||||||
|
public boolean canBack() { |
||||||
|
return getChildFragmentManager().getBackStackEntryCount() > 0; |
||||||
|
} |
||||||
|
|
||||||
|
public void goBack() { |
||||||
|
getChildFragmentManager().popBackStack(); |
||||||
|
} |
||||||
|
} |
||||||
@ -0,0 +1,11 @@ |
|||||||
|
<?xml version="1.0" encoding="utf-8"?> |
||||||
|
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" |
||||||
|
android:layout_width="match_parent" |
||||||
|
android:layout_height="match_parent"> |
||||||
|
|
||||||
|
<androidx.fragment.app.FragmentContainerView |
||||||
|
android:id="@+id/container" |
||||||
|
android:layout_width="match_parent" |
||||||
|
android:layout_height="match_parent" /> |
||||||
|
|
||||||
|
</FrameLayout> |
||||||
Loading…
Reference in new issue