Advertisement
aunkang

second

May 24th, 2017
216
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 12.15 KB | None | 0 0
  1. public class SecondFragment extends Fragment{
  2.  
  3.     ImageView back, back_home;
  4.     TextView tvTitle;
  5.      private ThirdFragment thirdFragment = new ThirdFragment();
  6.      private static List<PhotoItemDao> dao;
  7.      private static String albumnName;
  8.      private LinearLayout layout;
  9.      private ArrayList<String> childs;
  10.     private View v;
  11.      private int checker=0;
  12.  
  13.     public String getAlbumnName() {
  14.         return albumnName;
  15.     }
  16.  
  17.     public void setAlbumnName(String albumnName){
  18.         this.albumnName = albumnName;
  19.     }
  20.  
  21.     public SecondFragment(){super();}
  22.  
  23.     public static SecondFragment newInstance(){
  24.         SecondFragment fragment = new SecondFragment();
  25.         Bundle args = new Bundle();
  26.         fragment.setArguments(args);
  27.         return fragment;
  28.     }
  29.  
  30.     @Nullable
  31.     @Override
  32.     public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
  33.     View rootView = inflater.inflate(R.layout.fragment_second, container, false);
  34.         v = rootView;
  35.         initInstances(v);
  36.         return rootView;
  37.  
  38.  
  39.         }
  40.  
  41.     public void initInstances(View rootView){
  42.     //    Toast.makeText(getContext(), getDao().get(1).getSoundStep().getSound1(), Toast.LENGTH_SHORT).show();
  43.         //
  44.         back_home = (ImageView) rootView.findViewById(R.id.back_home);
  45.         tvTitle = (TextView) rootView.findViewById(R.id.tvTitle);
  46.         layout = (LinearLayout) rootView.findViewById(R.id.childs);
  47.         tvTitle.setText(getAlbumnName());
  48.         back_home.setOnClickListener(clickListener);
  49.         int count = 0;
  50.         int temp=0;
  51.         int temp2=0;
  52.         LinearLayout a = new LinearLayout(getContext());
  53.         a.setOrientation(LinearLayout.HORIZONTAL);
  54.         for(int i=0;i<getDao().size();i++){
  55.             Button button = new Button(getContext());
  56.  
  57.             if(getDao().get(i).getAlbumnName().equals(getAlbumnName())){
  58.                 if(getDao().get(i).getShow() == 1){
  59.                     count++;
  60.                     if(getDao().get(i).getType().equals("image")){
  61.                       //  Toast.makeText(getContext(), "case 1 again", Toast.LENGTH_LONG).show();
  62.  
  63.                         thirdFragment.setDao(getDao());
  64.                         getActivity().getSupportFragmentManager().beginTransaction()
  65.                                 .replace(R.id.contentContainer, ThirdFragment.newInstance(albumnName))
  66.                                 .commit();
  67.  
  68.                     }else{
  69.                         ForthFragment forthFragment = new ForthFragment();
  70.                         forthFragment.setDao(getDao());
  71.                         forthFragment.setAlbumnName(albumnName);
  72.                         getActivity().getSupportFragmentManager().beginTransaction()
  73.                                 .replace(R.id.contentContainer, ForthFragment.newInstance(1412))
  74.                                 .commit();
  75.                     }
  76.                    // Do it when it's albumn.
  77.                   /*  Toast.makeText(getContext(), "case 1", Toast.LENGTH_LONG).show();
  78.                     button.setText(dao.get(i).getAlbumnName()+"1");
  79.                     button.setOnClickListener(clickListener);
  80.                     layout.addView(button);*/
  81.                     break;
  82.  
  83.  
  84.                 }
  85.             }
  86.             else if(getDao().get(i).getParent().equals(getAlbumnName())){
  87.                     // Do it when it's only parent.
  88.                 if(temp%2==0){
  89.                     a = new LinearLayout(getContext());
  90.                     a.setOrientation(LinearLayout.HORIZONTAL);
  91.                     LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(300, 100);
  92.                     lp.weight = 3;
  93.                     View view = new View(getContext());
  94.                     a.addView(view, lp);
  95.                 }
  96.  
  97.                 LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(
  98.                             LinearLayout.LayoutParams.WRAP_CONTENT,
  99.                             LinearLayout.LayoutParams.WRAP_CONTENT);
  100.                     lp.weight = 3;
  101.                     button.setText(dao.get(i).getAlbumnName());
  102.                     button.setBackgroundResource(R.drawable.button_grid2);
  103.                     button.setTextColor(Color.BLACK);
  104.                     button.setTextSize(20);
  105.                     button.setOnClickListener(clickListener);
  106.                     a.addView(button, lp);
  107.                     temp++;
  108.                     count++;
  109.                 if(temp%2==0) {layout.addView(a);}
  110.             }
  111.             else if(count==0 && i == getDao().size()-1){
  112.                 Toast.makeText(getContext(), "ยังไม่มีอัลรูปภาพในอัลบั้มนี้", Toast.LENGTH_LONG).show();
  113.             }
  114.  
  115.             setDao(getDao());
  116.         }if(temp%2!=0){
  117.             LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(
  118.                     LinearLayout.LayoutParams.WRAP_CONTENT,
  119.                     LinearLayout.LayoutParams.WRAP_CONTENT);
  120.             lp.setMargins(0,0,0,0);
  121.             lp.weight = 3;
  122.             Button button = new Button(getContext());
  123.             button.setText("");
  124.             button.setBackgroundResource(R.drawable.button_grid2);
  125.             button.setTextColor(Color.BLACK);
  126.             button.setTextSize(20);
  127.             button.setOnClickListener(clickListener);
  128.             button.setVisibility(View.INVISIBLE);
  129.             a.addView(button,lp);
  130.             lp = new LinearLayout.LayoutParams(
  131.                     LinearLayout.LayoutParams.WRAP_CONTENT,
  132.                     LinearLayout.LayoutParams.WRAP_CONTENT);
  133.             lp.setMargins(0,0,0,0);
  134.             layout.addView(a, lp);
  135.         }
  136.  
  137.         back = (ImageView) rootView.findViewById(R.id.back);
  138.         back.setOnClickListener(clickListener);
  139.     }
  140.     View.OnClickListener clickListener = new View.OnClickListener() {
  141.         @Override
  142.         public void onClick(View v) {
  143.  
  144.             if(v==back_home){
  145.                 getFragmentManager().popBackStack(null, getFragmentManager().POP_BACK_STACK_INCLUSIVE);
  146.             }
  147.             else if(v==back){
  148.  
  149.                 for(int i=0;i<getDao().size();i++){
  150.                     if(getDao().get(i).getAlbumnName().equals(getAlbumnName())){
  151.                         if(getDao().get(i).getParent().equals("")){
  152.                             getActivity().getSupportFragmentManager().beginTransaction()
  153.                                     .replace(R.id.contentContainer, MainFragment.newInstance(1412))
  154.                                     .commit();
  155.                             break;
  156.                         }else{
  157.                             setDao(getDao());
  158.                             setAlbumnName(getDao().get(i).getParent());
  159.                             getActivity().getSupportFragmentManager().beginTransaction()
  160.                                     .replace(R.id.contentContainer, SecondFragment.newInstance())
  161.                                     .commit();
  162.                         //    Toast.makeText(getContext(), "This is "+getDao().get(i).getParent(), Toast.LENGTH_LONG).show();
  163.  
  164.                             tvTitle.setText(getDao().get(i).getParent());
  165.  
  166.                             int o=0;
  167.                             while(o<getDao().size()){
  168.                                 if(getDao().get(o).getParent().equals(getAlbumnName())){
  169.  
  170.                                 }
  171.                                 Button button = new Button(getContext());
  172.                                 button.setText(getDao().get(o).getAlbumnName());
  173.                                 button.setTag(getDao().get(o).getAlbumnName());
  174.                                 button.setOnClickListener(clickListener);
  175.                                 layout.addView(button);
  176.                                 o++;
  177.                             }
  178.  
  179.                         }
  180.                     }
  181.                 }
  182.  
  183.             }else{
  184.                 int count=0;
  185.                 Button b = (Button) v;
  186.                 List<String> temp = new ArrayList<String>();
  187.                 for(int i=0;i<getDao().size();i++){
  188.                     Button button = new Button(getContext());
  189.  
  190.                     if(getDao().get(i).getAlbumnName().equals(b.getText().toString())){
  191.                         if(getDao().get(i).getShow() == 1){
  192.                             count++;
  193.                             // Do it when it's already uplaod an albumn.
  194.                             if(getDao().get(i).getType().equals("image")){
  195.                                 Toast.makeText(getContext(), "case image", Toast.LENGTH_LONG).show();
  196.                                 thirdFragment.setDao(getDao());
  197.                                 getActivity().getSupportFragmentManager().beginTransaction()
  198.                                         .replace(R.id.contentContainer, ThirdFragment.newInstance(b.getText().toString()))
  199.                                         .addToBackStack(null)
  200.                                         .commit();
  201.                             }else{
  202.                                 Toast.makeText(getContext(), "case video", Toast.LENGTH_LONG).show();
  203.                                 ForthFragment forthFragment = new ForthFragment();
  204.                                 forthFragment.setDao(getDao());
  205.                                 forthFragment.setAlbumnName(b.getText().toString());
  206.                                 getActivity().getSupportFragmentManager().beginTransaction()
  207.  
  208.  
  209.                                         .replace(R.id.contentContainer, ForthFragment.newInstance(1412))
  210.                                         .addToBackStack(null)
  211.                                         .commit();
  212.                             }
  213.  
  214.                             break;
  215.                         }else {
  216.                             for(int j=0;j< getDao().size();j++){
  217.                                 if((getDao().get(i).getNode()+"").equals(getDao().get(j).getpNode())){
  218.                                     break;
  219.                                 }
  220.                                 if(j == getDao().size()-1) Toast.makeText(getContext(), "หมวดหมู่นี้ยังไม่มีข้อมูล", Toast.LENGTH_SHORT).show();
  221.                             }
  222.  
  223.                         }
  224.                     }
  225.                     else if(getDao().get(i).getParent().equals(b.getText().toString())){
  226.                         // Do it when it's parent.
  227.                         temp.add(getDao().get(i).getAlbumnName());
  228.  
  229.                     }
  230.  
  231.                 }
  232.                 if(temp.size() > 0){
  233.                     getActivity().getSupportFragmentManager().beginTransaction()
  234.                             .replace(R.id.contentContainer, SecondFragment.newInstance())
  235.                             .commit();
  236.                     Toast.makeText(getContext(), "case 2", Toast.LENGTH_LONG).show();
  237.                     for(String i : temp){
  238.                         Button button = new Button(getContext());
  239.                         button.setText(i);
  240.                         button.setTag(i);
  241.                         button.setOnClickListener(clickListener);
  242.                         layout.addView(button);
  243.                     }
  244.                     setDao(getDao());
  245.                     setAlbumnName(b.getText().toString());
  246.                 }
  247.             }
  248.  
  249.         }
  250.     };
  251.  
  252.     @Override
  253.     public void onResume() {
  254.        /* checker = 1;
  255.         initInstances(v);*/
  256.         super.onResume();
  257.     }
  258.  
  259.     @Override
  260.     public void onStart() {
  261.         super.onStart();
  262.     }
  263.  
  264.     @Override
  265.     public void onStop() {
  266.  
  267.         super.onStop();
  268.     }
  269.  
  270.     @Override
  271.     public void onSaveInstanceState(Bundle outState) {
  272.  
  273.         outState.putStringArrayList("childs", childs);
  274.         super.onSaveInstanceState(outState);
  275.     }
  276.  
  277.     @Override
  278.     public void onActivityCreated(@Nullable Bundle savedInstanceState) {
  279.         super.onActivityCreated(savedInstanceState);
  280.         if(savedInstanceState != null){
  281.  
  282.  
  283.  
  284.         }
  285.     }
  286.  
  287.     public List<PhotoItemDao> getDao() {
  288.         return dao;
  289.     }
  290.  
  291.     public void setDao(List<PhotoItemDao> dao) {
  292.         SecondFragment.dao = dao;
  293.     }
  294.  
  295.  
  296. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement