Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class SecondFragment extends Fragment{
- ImageView back, back_home;
- TextView tvTitle;
- private ThirdFragment thirdFragment = new ThirdFragment();
- private static List<PhotoItemDao> dao;
- private static String albumnName;
- private LinearLayout layout;
- private ArrayList<String> childs;
- private View v;
- private int checker=0;
- public String getAlbumnName() {
- return albumnName;
- }
- public void setAlbumnName(String albumnName){
- this.albumnName = albumnName;
- }
- public SecondFragment(){super();}
- public static SecondFragment newInstance(){
- SecondFragment fragment = new SecondFragment();
- Bundle args = new Bundle();
- fragment.setArguments(args);
- return fragment;
- }
- @Nullable
- @Override
- public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
- View rootView = inflater.inflate(R.layout.fragment_second, container, false);
- v = rootView;
- initInstances(v);
- return rootView;
- }
- public void initInstances(View rootView){
- // Toast.makeText(getContext(), getDao().get(1).getSoundStep().getSound1(), Toast.LENGTH_SHORT).show();
- //
- back_home = (ImageView) rootView.findViewById(R.id.back_home);
- tvTitle = (TextView) rootView.findViewById(R.id.tvTitle);
- layout = (LinearLayout) rootView.findViewById(R.id.childs);
- tvTitle.setText(getAlbumnName());
- back_home.setOnClickListener(clickListener);
- int count = 0;
- int temp=0;
- int temp2=0;
- LinearLayout a = new LinearLayout(getContext());
- a.setOrientation(LinearLayout.HORIZONTAL);
- for(int i=0;i<getDao().size();i++){
- Button button = new Button(getContext());
- if(getDao().get(i).getAlbumnName().equals(getAlbumnName())){
- if(getDao().get(i).getShow() == 1){
- count++;
- if(getDao().get(i).getType().equals("image")){
- // Toast.makeText(getContext(), "case 1 again", Toast.LENGTH_LONG).show();
- thirdFragment.setDao(getDao());
- getActivity().getSupportFragmentManager().beginTransaction()
- .replace(R.id.contentContainer, ThirdFragment.newInstance(albumnName))
- .commit();
- }else{
- ForthFragment forthFragment = new ForthFragment();
- forthFragment.setDao(getDao());
- forthFragment.setAlbumnName(albumnName);
- getActivity().getSupportFragmentManager().beginTransaction()
- .replace(R.id.contentContainer, ForthFragment.newInstance(1412))
- .commit();
- }
- // Do it when it's albumn.
- /* Toast.makeText(getContext(), "case 1", Toast.LENGTH_LONG).show();
- button.setText(dao.get(i).getAlbumnName()+"1");
- button.setOnClickListener(clickListener);
- layout.addView(button);*/
- break;
- }
- }
- else if(getDao().get(i).getParent().equals(getAlbumnName())){
- // Do it when it's only parent.
- if(temp%2==0){
- a = new LinearLayout(getContext());
- a.setOrientation(LinearLayout.HORIZONTAL);
- LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(300, 100);
- lp.weight = 3;
- View view = new View(getContext());
- a.addView(view, lp);
- }
- LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(
- LinearLayout.LayoutParams.WRAP_CONTENT,
- LinearLayout.LayoutParams.WRAP_CONTENT);
- lp.weight = 3;
- button.setText(dao.get(i).getAlbumnName());
- button.setBackgroundResource(R.drawable.button_grid2);
- button.setTextColor(Color.BLACK);
- button.setTextSize(20);
- button.setOnClickListener(clickListener);
- a.addView(button, lp);
- temp++;
- count++;
- if(temp%2==0) {layout.addView(a);}
- }
- else if(count==0 && i == getDao().size()-1){
- Toast.makeText(getContext(), "ยังไม่มีอัลรูปภาพในอัลบั้มนี้", Toast.LENGTH_LONG).show();
- }
- setDao(getDao());
- }if(temp%2!=0){
- LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(
- LinearLayout.LayoutParams.WRAP_CONTENT,
- LinearLayout.LayoutParams.WRAP_CONTENT);
- lp.setMargins(0,0,0,0);
- lp.weight = 3;
- Button button = new Button(getContext());
- button.setText("");
- button.setBackgroundResource(R.drawable.button_grid2);
- button.setTextColor(Color.BLACK);
- button.setTextSize(20);
- button.setOnClickListener(clickListener);
- button.setVisibility(View.INVISIBLE);
- a.addView(button,lp);
- lp = new LinearLayout.LayoutParams(
- LinearLayout.LayoutParams.WRAP_CONTENT,
- LinearLayout.LayoutParams.WRAP_CONTENT);
- lp.setMargins(0,0,0,0);
- layout.addView(a, lp);
- }
- back = (ImageView) rootView.findViewById(R.id.back);
- back.setOnClickListener(clickListener);
- }
- View.OnClickListener clickListener = new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- if(v==back_home){
- getFragmentManager().popBackStack(null, getFragmentManager().POP_BACK_STACK_INCLUSIVE);
- }
- else if(v==back){
- for(int i=0;i<getDao().size();i++){
- if(getDao().get(i).getAlbumnName().equals(getAlbumnName())){
- if(getDao().get(i).getParent().equals("")){
- getActivity().getSupportFragmentManager().beginTransaction()
- .replace(R.id.contentContainer, MainFragment.newInstance(1412))
- .commit();
- break;
- }else{
- setDao(getDao());
- setAlbumnName(getDao().get(i).getParent());
- getActivity().getSupportFragmentManager().beginTransaction()
- .replace(R.id.contentContainer, SecondFragment.newInstance())
- .commit();
- // Toast.makeText(getContext(), "This is "+getDao().get(i).getParent(), Toast.LENGTH_LONG).show();
- tvTitle.setText(getDao().get(i).getParent());
- int o=0;
- while(o<getDao().size()){
- if(getDao().get(o).getParent().equals(getAlbumnName())){
- }
- Button button = new Button(getContext());
- button.setText(getDao().get(o).getAlbumnName());
- button.setTag(getDao().get(o).getAlbumnName());
- button.setOnClickListener(clickListener);
- layout.addView(button);
- o++;
- }
- }
- }
- }
- }else{
- int count=0;
- Button b = (Button) v;
- List<String> temp = new ArrayList<String>();
- for(int i=0;i<getDao().size();i++){
- Button button = new Button(getContext());
- if(getDao().get(i).getAlbumnName().equals(b.getText().toString())){
- if(getDao().get(i).getShow() == 1){
- count++;
- // Do it when it's already uplaod an albumn.
- if(getDao().get(i).getType().equals("image")){
- Toast.makeText(getContext(), "case image", Toast.LENGTH_LONG).show();
- thirdFragment.setDao(getDao());
- getActivity().getSupportFragmentManager().beginTransaction()
- .replace(R.id.contentContainer, ThirdFragment.newInstance(b.getText().toString()))
- .addToBackStack(null)
- .commit();
- }else{
- Toast.makeText(getContext(), "case video", Toast.LENGTH_LONG).show();
- ForthFragment forthFragment = new ForthFragment();
- forthFragment.setDao(getDao());
- forthFragment.setAlbumnName(b.getText().toString());
- getActivity().getSupportFragmentManager().beginTransaction()
- .replace(R.id.contentContainer, ForthFragment.newInstance(1412))
- .addToBackStack(null)
- .commit();
- }
- break;
- }else {
- for(int j=0;j< getDao().size();j++){
- if((getDao().get(i).getNode()+"").equals(getDao().get(j).getpNode())){
- break;
- }
- if(j == getDao().size()-1) Toast.makeText(getContext(), "หมวดหมู่นี้ยังไม่มีข้อมูล", Toast.LENGTH_SHORT).show();
- }
- }
- }
- else if(getDao().get(i).getParent().equals(b.getText().toString())){
- // Do it when it's parent.
- temp.add(getDao().get(i).getAlbumnName());
- }
- }
- if(temp.size() > 0){
- getActivity().getSupportFragmentManager().beginTransaction()
- .replace(R.id.contentContainer, SecondFragment.newInstance())
- .commit();
- Toast.makeText(getContext(), "case 2", Toast.LENGTH_LONG).show();
- for(String i : temp){
- Button button = new Button(getContext());
- button.setText(i);
- button.setTag(i);
- button.setOnClickListener(clickListener);
- layout.addView(button);
- }
- setDao(getDao());
- setAlbumnName(b.getText().toString());
- }
- }
- }
- };
- @Override
- public void onResume() {
- /* checker = 1;
- initInstances(v);*/
- super.onResume();
- }
- @Override
- public void onStart() {
- super.onStart();
- }
- @Override
- public void onStop() {
- super.onStop();
- }
- @Override
- public void onSaveInstanceState(Bundle outState) {
- outState.putStringArrayList("childs", childs);
- super.onSaveInstanceState(outState);
- }
- @Override
- public void onActivityCreated(@Nullable Bundle savedInstanceState) {
- super.onActivityCreated(savedInstanceState);
- if(savedInstanceState != null){
- }
- }
- public List<PhotoItemDao> getDao() {
- return dao;
- }
- public void setDao(List<PhotoItemDao> dao) {
- SecondFragment.dao = dao;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement