Move branch commits to files popup (#682)
Move commits to file sub menu Co-authored-by: M M Arif <mmarif@swatian.com> Reviewed-on: https://codeberg.org/gitnex/GitNex/pulls/682 Reviewed-by: 6543 <6543@noreply.codeberg.org>
This commit is contained in:
		| @@ -33,7 +33,6 @@ import org.mian.gitnex.fragments.BottomSheetIssuesFilterFragment; | ||||
| import org.mian.gitnex.fragments.BottomSheetMilestonesFilterFragment; | ||||
| import org.mian.gitnex.fragments.BottomSheetPullRequestFilterFragment; | ||||
| import org.mian.gitnex.fragments.BottomSheetRepoFragment; | ||||
| import org.mian.gitnex.fragments.BranchesFragment; | ||||
| import org.mian.gitnex.fragments.CollaboratorsFragment; | ||||
| import org.mian.gitnex.fragments.FilesFragment; | ||||
| import org.mian.gitnex.fragments.IssuesFragment; | ||||
| @@ -163,7 +162,7 @@ public class RepoDetailActivity extends BaseActivity implements BottomSheetRepoF | ||||
| 		} | ||||
|  | ||||
| 		// Only show collaborators tab, if you have permission to | ||||
| 		View collaboratorTab = viewGroup.getChildAt(8); | ||||
| 		View collaboratorTab = viewGroup.getChildAt(7); | ||||
|  | ||||
| 		if(tinyDB.getBoolean("isRepoAdmin") || new Version(tinyDB.getString("giteaVersion")).higherOrEqual("1.12.0")) { | ||||
|  | ||||
| @@ -229,8 +228,8 @@ public class RepoDetailActivity extends BaseActivity implements BottomSheetRepoF | ||||
|  | ||||
| 				if(textViewBadgeRelease.getText() != "") { // only show if API returned a number | ||||
|  | ||||
| 					Objects.requireNonNull(tabLayout.getTabAt(5)).setCustomView(tabHeader6); | ||||
| 					TabLayout.Tab tabOpenRelease = tabLayout.getTabAt(5); | ||||
| 					Objects.requireNonNull(tabLayout.getTabAt(4)).setCustomView(tabHeader6); | ||||
| 					TabLayout.Tab tabOpenRelease = tabLayout.getTabAt(4); | ||||
| 					assert tabOpenRelease != null; // FIXME This should be cleaned up | ||||
| 					TextView openReleaseTabView = Objects.requireNonNull(tabOpenRelease.getCustomView()).findViewById(R.id.counterBadgeReleaseText); | ||||
| 					openReleaseTabView.setTextColor(textColor); | ||||
| @@ -300,6 +299,12 @@ public class RepoDetailActivity extends BaseActivity implements BottomSheetRepoF | ||||
| 				chooseBranch(); | ||||
| 				return true; | ||||
|  | ||||
| 			case R.id.branchCommits: | ||||
| 				Intent intent = new Intent(ctx, CommitsActivity.class); | ||||
| 				intent.putExtra("branchName", tinyDB.getString("repoBranch")); | ||||
| 				ctx.startActivity(intent); | ||||
| 				return true; | ||||
|  | ||||
| 			default: | ||||
| 				return super.onOptionsItemSelected(item); | ||||
|  | ||||
| @@ -490,20 +495,17 @@ public class RepoDetailActivity extends BaseActivity implements BottomSheetRepoF | ||||
| 					fragment = new PullRequestsFragment(); | ||||
| 					break; | ||||
|  | ||||
| 				case 4: // Branches | ||||
| 					return BranchesFragment.newInstance(repositoryOwner, repositoryName); | ||||
|  | ||||
| 				case 5: // Releases | ||||
| 				case 4: // Releases | ||||
| 					return ReleasesFragment.newInstance(repositoryOwner, repositoryName); | ||||
|  | ||||
| 				case 6: // Milestones | ||||
| 				case 5: // Milestones | ||||
| 					fragment = new MilestonesFragment(); | ||||
| 					break; | ||||
|  | ||||
| 				case 7: // Labels | ||||
| 				case 6: // Labels | ||||
| 					return LabelsFragment.newInstance(repositoryOwner, repositoryName); | ||||
|  | ||||
| 				case 8: // Collaborators | ||||
| 				case 7: // Collaborators | ||||
| 					return CollaboratorsFragment.newInstance(repositoryOwner, repositoryName); | ||||
|  | ||||
| 			} | ||||
|   | ||||
| @@ -1,90 +0,0 @@ | ||||
| package org.mian.gitnex.adapters; | ||||
|  | ||||
| import android.content.Context; | ||||
| import android.content.Intent; | ||||
| import android.view.LayoutInflater; | ||||
| import android.view.View; | ||||
| import android.view.ViewGroup; | ||||
| import android.widget.Button; | ||||
| import android.widget.TextView; | ||||
| import androidx.annotation.NonNull; | ||||
| import androidx.recyclerview.widget.RecyclerView; | ||||
| import org.mian.gitnex.R; | ||||
| import org.mian.gitnex.activities.CommitsActivity; | ||||
| import org.mian.gitnex.helpers.TinyDB; | ||||
| import org.mian.gitnex.models.Branches; | ||||
| import java.util.List; | ||||
| import java.util.Objects; | ||||
|  | ||||
| /** | ||||
|  * Author M M Arif | ||||
|  */ | ||||
|  | ||||
| public class BranchesAdapter extends RecyclerView.Adapter<BranchesAdapter.BranchesViewHolder> { | ||||
|  | ||||
|     private List<Branches> branchesList; | ||||
|     private Context mCtx; | ||||
|  | ||||
|     static class BranchesViewHolder extends RecyclerView.ViewHolder { | ||||
|  | ||||
|         private TextView branchNameTv; | ||||
|         private TextView branchCommitAuthor; | ||||
|  | ||||
|         private BranchesViewHolder(View itemView) { | ||||
|             super(itemView); | ||||
|  | ||||
|             branchNameTv = itemView.findViewById(R.id.branchName); | ||||
|             branchCommitAuthor = itemView.findViewById(R.id.branchCommitAuthor); | ||||
|             Button branchCommitHash = itemView.findViewById(R.id.branchCommitHash); | ||||
|  | ||||
|             branchCommitHash.setOnClickListener(new View.OnClickListener() { | ||||
|                 public void onClick(View v) { | ||||
|  | ||||
|                     Intent intent = new Intent(v.getContext(), CommitsActivity.class); | ||||
|                     intent.putExtra("branchName", String.valueOf(branchNameTv.getText())); | ||||
|                     Objects.requireNonNull(v.getContext()).startActivity(intent); | ||||
|  | ||||
|                 } | ||||
|             }); | ||||
|  | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     public BranchesAdapter(Context mCtx, List<Branches> branchesMain) { | ||||
|         this.mCtx = mCtx; | ||||
|         this.branchesList = branchesMain; | ||||
|     } | ||||
|  | ||||
|     @NonNull | ||||
|     @Override | ||||
|     public BranchesAdapter.BranchesViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { | ||||
|         View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.list_branches, parent, false); | ||||
|         return new BranchesAdapter.BranchesViewHolder(v); | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public void onBindViewHolder(@NonNull BranchesAdapter.BranchesViewHolder holder, int position) { | ||||
|  | ||||
|         final TinyDB tinyDb = new TinyDB(mCtx); | ||||
|         final String instanceUrl = tinyDb.getString("instanceUrl"); | ||||
|  | ||||
|         Branches currentItem = branchesList.get(position); | ||||
|         holder.branchNameTv.setText(currentItem.getName()); | ||||
|  | ||||
|         if(currentItem.getCommit().getAuthor().getName() != null || !currentItem.getCommit().getAuthor().getName().equals("")) { | ||||
|             holder.branchCommitAuthor.setText(mCtx.getResources().getString(R.string.commitAuthor, currentItem.getCommit().getAuthor().getName())); | ||||
|         } | ||||
|         else { | ||||
|             holder.branchCommitAuthor.setText(mCtx.getResources().getString(R.string.commitAuthor, currentItem.getCommit().getAuthor().getUsername())); | ||||
|         } | ||||
|  | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public int getItemCount() { | ||||
|         return branchesList.size(); | ||||
|     } | ||||
|  | ||||
| } | ||||
|  | ||||
|  | ||||
| @@ -1,149 +0,0 @@ | ||||
| package org.mian.gitnex.fragments; | ||||
|  | ||||
| import android.net.Uri; | ||||
| import android.os.Bundle; | ||||
| import android.os.Handler; | ||||
| import android.view.LayoutInflater; | ||||
| import android.view.View; | ||||
| import android.view.ViewGroup; | ||||
| import android.widget.ProgressBar; | ||||
| import android.widget.TextView; | ||||
| import androidx.annotation.NonNull; | ||||
| import androidx.annotation.Nullable; | ||||
| import androidx.fragment.app.Fragment; | ||||
| import androidx.lifecycle.Observer; | ||||
| import androidx.lifecycle.ViewModelProvider; | ||||
| import androidx.recyclerview.widget.DividerItemDecoration; | ||||
| import androidx.recyclerview.widget.LinearLayoutManager; | ||||
| import androidx.recyclerview.widget.RecyclerView; | ||||
| import androidx.swiperefreshlayout.widget.SwipeRefreshLayout; | ||||
| import org.mian.gitnex.R; | ||||
| import org.mian.gitnex.adapters.BranchesAdapter; | ||||
| import org.mian.gitnex.helpers.Authorization; | ||||
| import org.mian.gitnex.helpers.TinyDB; | ||||
| import org.mian.gitnex.models.Branches; | ||||
| import org.mian.gitnex.viewmodels.BranchesViewModel; | ||||
| import java.util.List; | ||||
|  | ||||
| /** | ||||
|  * Author M M Arif | ||||
|  */ | ||||
|  | ||||
| public class BranchesFragment extends Fragment { | ||||
|  | ||||
|     private ProgressBar mProgressBar; | ||||
|     private BranchesAdapter adapter; | ||||
|     private RecyclerView mRecyclerView; | ||||
|     private TextView noDataBranches; | ||||
|     private static String repoNameF = "param2"; | ||||
|     private static String repoOwnerF = "param1"; | ||||
|  | ||||
|     private String repoName; | ||||
|     private String repoOwner; | ||||
|  | ||||
|     private OnFragmentInteractionListener mListener; | ||||
|  | ||||
|     public BranchesFragment() { | ||||
|     } | ||||
|  | ||||
|     public static BranchesFragment newInstance(String param1, String param2) { | ||||
|         BranchesFragment fragment = new BranchesFragment(); | ||||
|         Bundle args = new Bundle(); | ||||
|         args.putString(repoOwnerF, param1); | ||||
|         args.putString(repoNameF, param2); | ||||
|         fragment.setArguments(args); | ||||
|         return fragment; | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public void onCreate(Bundle savedInstanceState) { | ||||
|         super.onCreate(savedInstanceState); | ||||
|         if (getArguments() != null) { | ||||
|             repoName = getArguments().getString(repoNameF); | ||||
|             repoOwner = getArguments().getString(repoOwnerF); | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, | ||||
|                              Bundle savedInstanceState) { | ||||
|         View v = inflater.inflate(R.layout.fragment_branches, container, false); | ||||
|  | ||||
|         TinyDB tinyDb = new TinyDB(getContext()); | ||||
|         final String instanceUrl = tinyDb.getString("instanceUrl"); | ||||
|         final String loginUid = tinyDb.getString("loginUid"); | ||||
|         final String instanceToken = "token " + tinyDb.getString(loginUid + "-token"); | ||||
|         final String locale = tinyDb.getString("locale"); | ||||
|         final String timeFormat = tinyDb.getString("dateFormat"); | ||||
|         noDataBranches = v.findViewById(R.id.noDataBranches); | ||||
|  | ||||
|         final SwipeRefreshLayout swipeRefresh = v.findViewById(R.id.pullToRefresh); | ||||
|  | ||||
|         mRecyclerView = v.findViewById(R.id.recyclerView); | ||||
|         mRecyclerView.setHasFixedSize(true); | ||||
|         mRecyclerView.setLayoutManager(new LinearLayoutManager(getContext())); | ||||
|  | ||||
|         DividerItemDecoration dividerItemDecoration = new DividerItemDecoration(mRecyclerView.getContext(), | ||||
|                 DividerItemDecoration.VERTICAL); | ||||
|         mRecyclerView.addItemDecoration(dividerItemDecoration); | ||||
|  | ||||
|         mProgressBar = v.findViewById(R.id.progress_bar); | ||||
|  | ||||
|         swipeRefresh.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() { | ||||
|             @Override | ||||
|             public void onRefresh() { | ||||
|                 new Handler().postDelayed(new Runnable() { | ||||
|                     @Override | ||||
|                     public void run() { | ||||
|                         swipeRefresh.setRefreshing(false); | ||||
|                         BranchesViewModel.loadBranchesList(instanceUrl, instanceToken, repoOwner, repoName, getContext()); | ||||
|                     } | ||||
|                 }, 50); | ||||
|             } | ||||
|         }); | ||||
|  | ||||
|         fetchDataAsync(instanceUrl, Authorization.returnAuthentication(getContext(), loginUid, instanceToken), repoOwner, repoName); | ||||
|  | ||||
|         return v; | ||||
|     } | ||||
|  | ||||
|     public void onButtonPressed(Uri uri) { | ||||
|         if (mListener != null) { | ||||
|             mListener.onFragmentInteraction(uri); | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public void onDetach() { | ||||
|         super.onDetach(); | ||||
|         mListener = null; | ||||
|     } | ||||
|  | ||||
|     public interface OnFragmentInteractionListener { | ||||
|         void onFragmentInteraction(Uri uri); | ||||
|     } | ||||
|  | ||||
|     private void fetchDataAsync(String instanceUrl, String instanceToken, String owner, String repo) { | ||||
|  | ||||
|         BranchesViewModel branchesModel = new ViewModelProvider(this).get(BranchesViewModel.class); | ||||
|  | ||||
|         branchesModel.getBranchesList(instanceUrl, instanceToken, owner, repo, getContext()).observe(getViewLifecycleOwner(), new Observer<List<Branches>>() { | ||||
|             @Override | ||||
|             public void onChanged(@Nullable List<Branches> branchesListMain) { | ||||
|                 adapter = new BranchesAdapter(getContext(), branchesListMain); | ||||
|                 if(adapter.getItemCount() > 0) { | ||||
|                     mRecyclerView.setAdapter(adapter); | ||||
|                     noDataBranches.setVisibility(View.GONE); | ||||
|                 } | ||||
|                 else { | ||||
|                     adapter.notifyDataSetChanged(); | ||||
|                     mRecyclerView.setAdapter(adapter); | ||||
|                     noDataBranches.setVisibility(View.VISIBLE); | ||||
|                 } | ||||
|                 mProgressBar.setVisibility(View.GONE); | ||||
|             } | ||||
|         }); | ||||
|  | ||||
|     } | ||||
|  | ||||
| } | ||||
| @@ -30,7 +30,6 @@ import org.mian.gitnex.helpers.TinyDB; | ||||
| import org.mian.gitnex.viewmodels.FilesViewModel; | ||||
| import java.util.ArrayList; | ||||
| import java.util.Collections; | ||||
| import java.util.Objects; | ||||
| import moe.feng.common.view.breadcrumbs.BreadcrumbsView; | ||||
| import moe.feng.common.view.breadcrumbs.DefaultBreadcrumbsCallback; | ||||
| import moe.feng.common.view.breadcrumbs.model.BreadcrumbItem; | ||||
| @@ -111,7 +110,7 @@ public class FilesFragment extends Fragment implements FilesAdapter.FilesAdapter | ||||
| 		mBreadcrumbsView = v.findViewById(R.id.breadcrumbs_view); | ||||
| 		mBreadcrumbsView.setItems(new ArrayList<>(Collections.singletonList(BreadcrumbItem.createSimpleItem(getResources().getString(R.string.filesBreadcrumbRoot) + getResources().getString(R.string.colonDivider) + ref)))); | ||||
|  | ||||
| 		((RepoDetailActivity) Objects.requireNonNull(getActivity())).setFragmentRefreshListenerFiles(repoBranch -> { | ||||
| 		((RepoDetailActivity) requireActivity()).setFragmentRefreshListenerFiles(repoBranch -> { | ||||
|  | ||||
| 			fileStructure.setText(""); | ||||
| 			ref = repoBranch; | ||||
| @@ -198,7 +197,7 @@ public class FilesFragment extends Fragment implements FilesAdapter.FilesAdapter | ||||
| 			intent.putExtra("singleFileName", fileName); | ||||
| 		} | ||||
|  | ||||
| 		Objects.requireNonNull(getContext()).startActivity(intent); | ||||
| 		requireContext().startActivity(intent); | ||||
| 	} | ||||
|  | ||||
| 	private void fetchDataAsync(String instanceUrl, String instanceToken, String owner, String repo, String ref) { | ||||
| @@ -263,6 +262,7 @@ public class FilesFragment extends Fragment implements FilesAdapter.FilesAdapter | ||||
| 	@Override | ||||
| 	public void onCreateOptionsMenu(@NonNull Menu menu, @NonNull MenuInflater inflater) { | ||||
|  | ||||
| 		menu.clear(); | ||||
| 		inflater.inflate(R.menu.search_menu, menu); | ||||
| 		inflater.inflate(R.menu.files_switch_branches_menu, menu); | ||||
| 		super.onCreateOptionsMenu(menu, inflater); | ||||
|   | ||||
		Reference in New Issue
	
	Block a user