Android Open Source - PrincePolo Branches Fragment






From Project

Back to project page PrincePolo.

License

The source code is released under:

GNU General Public License

If you think the Android project PrincePolo listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package se.agile.activities;  
/*w ww.  ja  v a2 s. c  o m*/
import java.util.ArrayList;
import java.util.List;

import se.agile.activities.MainActivity.VIEW;
import se.agile.asynctasks.RequestBranches;
import se.agile.asynctasks.RequestListenerAdapter;
import se.agile.githubdata.Branch;
import se.agile.model.BranchSelectionModel;
import se.agile.model.InteractiveArrayAdapter;
import se.agile.model.Preferences;
import se.agile.princepolo.R;
import android.app.ListFragment;
import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.ProgressBar;
import android.widget.TextView;
public class BranchesFragment extends ListFragment 

{
  ArrayList<Branch> allBranches;
  private final static String logTag = "PrincePolo";
  public static boolean unselectButton;
  Button selectionButton, nextButton;
  private ProgressBar spinner;
  private TextView tv,tv2;
  private CheckBox checkbox;
  private View line;
  
  RequestListenerAdapter<ArrayList<Branch>> listener = new RequestListenerAdapter<ArrayList<Branch>>() 
  {
    @Override
    public void requestFinished(ArrayList<Branch> result) 
    {
      allBranches = result;
      // Create an array of strings, that will be put to our ListActivity
      ArrayAdapter<BranchSelectionModel> adapter = new InteractiveArrayAdapter(getActivity(), getModel());
      setListAdapter(adapter);
      
      spinner.setVisibility(View.GONE);

          tv.setVisibility(View.VISIBLE);
          selectionButton.setVisibility(View.VISIBLE);
          checkbox.setVisibility(View.VISIBLE);
          nextButton.setVisibility(View.VISIBLE);  
          tv2.setVisibility(View.VISIBLE);
          line.setVisibility(View.VISIBLE);
    }
  };
  
  @Override
    public View onCreateView(final LayoutInflater inflater, final ViewGroup container, Bundle savedInstanceState) 
  {
      View rootView = inflater.inflate(R.layout.fragment_branches, container, false);
      
        spinner = (ProgressBar) rootView.findViewById(R.id.progressBar1);
        tv = (TextView) rootView.findViewById(R.id.selecttext);
        selectionButton = (Button) rootView.findViewById(R.id.unselectButton);
        checkbox = (CheckBox) rootView.findViewById(R.id.chkAll);
        nextButton = (Button) rootView.findViewById(R.id.nextButton);
        tv2 = (TextView) rootView.findViewById(R.id.allText);
        line = (View) rootView.findViewById(R.id.linee);
        
        spinner.setVisibility(View.VISIBLE);

        tv.setVisibility(View.INVISIBLE);
        selectionButton.setVisibility(View.INVISIBLE);
        checkbox.setVisibility(View.INVISIBLE);
        nextButton.setVisibility(View.INVISIBLE);  
        tv2.setVisibility(View.INVISIBLE);
        line.setVisibility(View.INVISIBLE);
        

        Button nextButton = (Button) rootView.findViewById(R.id.nextButton);
        nextButton.setOnClickListener(new OnClickListener() {
      
      @Override
      public void onClick(View v) 
      {
        Intent intent = new Intent(getActivity(), SelectWorkingFilesActivity.class);
        startActivity(intent);
        getActivity().overridePendingTransition(0, 0);
        ((MainActivity) getActivity()).displayView(VIEW.REPOSITORY_OVERVIEW);
        
      }
    });
        
    RequestBranches reqbranches = new RequestBranches(listener);
    reqbranches.execute();
    
    unselectButton = true;
    
    
    if (checkbox.isChecked())
//          checkbox.toggle(); Just removed this and it seemed to work fine /JL

        checkbox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() 
        {

          public void onCheckedChanged(CompoundButton arg0, boolean isChecked) 
          {
              RequestBranches reqbranches = new RequestBranches(listener);
              reqbranches.execute();
              
            if (checkbox.isChecked())
            {
                    unselectButton = true;
                    Preferences.removeAllBranches();    
                    
            }
            else
            {

                    unselectButton = false;
                    
                // All branches in an arraylist string
                List<String> namesOfAllBranches = new ArrayList<String>();
              for (int i = 0; i < allBranches.size(); i++)
              {
                namesOfAllBranches.add(allBranches.get(i).getName());
              }
                Preferences.setUnselectedBranchesArray(namesOfAllBranches);
            }
          }
        });

    

        // create our incredible click listener
        OnClickListener selectionClickListener = new OnClickListener() 
        {
          @Override
          public void onClick(View v) 
          {
          //ArrayList<Branch> allBranches = new ArrayList<Branch>();
          RequestBranches reqbranches = new RequestBranches(listener);
          reqbranches.execute();
          
          if (selectionButton.getText().equals("Unselect all")) 
          {
                  selectionButton.setText("Select all");
                  unselectButton = false;
                  
            // All branches in an arraylist string
            List<String> namesOfAllBranches = new ArrayList<String>();
          for (int i = 0; i < allBranches.size(); i++)
          {
            namesOfAllBranches.add(allBranches.get(i).getName());
          }
            Preferences.setUnselectedBranchesArray(namesOfAllBranches);
            //Log.d(logTag,Arrays.toString(namesOfAllBranches.toArray()));
            } 
          else 
          {
                  selectionButton.setText("Unselect all");
                  unselectButton = true;
                  Preferences.removeAllBranches();            
            }
          }
        };
    
        // assign click listener to the OK button (btnOK)
        selectionButton.setOnClickListener(selectionClickListener);
          
        return rootView;
  }
  
  // The branch selection model
  private List<BranchSelectionModel> getModel() 
  {
    List<BranchSelectionModel> list = new ArrayList<BranchSelectionModel>();
    ArrayList<Branch> allUnselectedBranches = Preferences.getUnselectedBranches();
    
    // Adds checkboxes for all branches
    for (Branch s : allBranches)
    {
      list.add(get(s.getName()));
    }
    
    // Not finished
    if (unselectButton == false)
    {
      return list;
    }
    else
    {
    // If no branches have been saved to preferences, then select all the checkboxes
    if (allUnselectedBranches.isEmpty())
    {
      for (int i = 0; i< list.size(); i++)
      {
        list.get(i).setSelected(true);
      }
      selectionButton.setText("Unselect all");
    }
    
    // If branches have been saved to preferences, then select just them
    else
    {
      // Unselected branches in an arraylist string
      ArrayList<String> namesOfUnselectedBranches = new ArrayList<String>();
      for (int i = 0; i < allUnselectedBranches.size(); i++)
      {
        namesOfUnselectedBranches.add(allUnselectedBranches.get(i).getName());
      }
      
      // All branches in an arraylist string
      ArrayList<String> namesOfAllBranches = new ArrayList<String>();
      for (int i = 0; i < allBranches.size(); i++)
      {
        namesOfAllBranches.add(allBranches.get(i).getName());
      }
      
      // Pick those branches which belong to both arraylists ..    
      for (int i = 0; i < namesOfAllBranches.size(); i++)
      {
        if (!namesOfUnselectedBranches.contains(namesOfAllBranches.get(i)))
        {
          list.get(i).setSelected(true);
        }
      }
      
    }
    
    return list;
    }
  }
  
  private BranchSelectionModel get(String s) 
  {
    return new BranchSelectionModel(s);
  }
}




Java Source Code List

se.agile.activities.AboutFragment.java
se.agile.activities.BranchFragment.java
se.agile.activities.BranchesFragment.java
se.agile.activities.CardFragment.java
se.agile.activities.CollaboratorsFragment.java
se.agile.activities.CommitFragment.java
se.agile.activities.ConflictFragment.java
se.agile.activities.ConnectToGitHubFragment.java
se.agile.activities.LoginActivity.java
se.agile.activities.MainActivity.java
se.agile.activities.NotificationFragmentSwitcher.java
se.agile.activities.NotificationsFragment.java
se.agile.activities.PersonalNotesFragment.java
se.agile.activities.PokerFragment.java
se.agile.activities.RepositoryOverviewFragment.java
se.agile.activities.SelectRepositoryFragment.java
se.agile.activities.SelectWorkingFilesActivity.java
se.agile.activities.SelectWorkingFilesFragment.java
se.agile.activities.SelectWorkingFilesOverviewFragment.java
se.agile.activities.SettingsFragment.java
se.agile.activities.SignOutFragment.java
se.agile.asynctasks.RequestAccessToken.java
se.agile.asynctasks.RequestAllCommitsForBranch.java
se.agile.asynctasks.RequestAllFilesForBranch.java
se.agile.asynctasks.RequestBranch.java
se.agile.asynctasks.RequestBranches.java
se.agile.asynctasks.RequestFiles.java
se.agile.asynctasks.RequestFullCommit.java
se.agile.asynctasks.RequestListenerAdapter.java
se.agile.asynctasks.RequestListener.java
se.agile.asynctasks.RequestRepositories.java
se.agile.asynctasks.RequestShortCommit.java
se.agile.asynctasks.RequestTask.java
se.agile.asynctasks.RequestUser.java
se.agile.controller.MainActivityController.java
se.agile.controller.settingsFragmentController.java
se.agile.githubdata.Branch.java
se.agile.githubdata.Commit.java
se.agile.githubdata.Directory.java
se.agile.githubdata.File.java
se.agile.githubdata.Folder.java
se.agile.githubdata.GitHubDataInterface.java
se.agile.githubdata.Repository.java
se.agile.githubdata.User.java
se.agile.model.BranchNotification.java
se.agile.model.BranchSelectionModel.java
se.agile.model.CommitNotification.java
se.agile.model.ConflictNotification.java
se.agile.model.CreateNotificationActivity.java
se.agile.model.DirectoryListArrayAdapter.java
se.agile.model.InteractiveArrayAdapter.java
se.agile.model.JSONParser.java
se.agile.model.NotificationDialog.java
se.agile.model.NotificationHandler.java
se.agile.model.NotificationListArrayAdapter.java
se.agile.model.NotificationListener.java
se.agile.model.Notification.java
se.agile.model.PreferenceListener.java
se.agile.model.Preferences.java
se.agile.model.TemporaryStorage.java
se.agile.model.Tuple.java
se.agile.model.WorkingFileListArrayAdapter.java
se.agile.navigator.NavDrawerItem.java
se.agile.navigator.NavDrawerListAdapter.java