1
0
mirror of https://codeberg.org/gitnex/GitNex synced 2024-12-23 00:48:57 +01:00

Create repository from organization menu, refactors too

This commit is contained in:
M M Arif 2020-03-17 15:32:03 +05:00
parent b5b69f377e
commit 7e8d2c6ec2
23 changed files with 108 additions and 44 deletions

View File

@ -20,7 +20,7 @@
android:name=".activities.FileViewActivity"
android:theme="@style/AppTheme.NoActionBar" />
<activity
android:name=".activities.NewFileActivity"
android:name=".activities.CreateFileActivity"
android:theme="@style/AppTheme.NoActionBar" />
<activity
android:name=".activities.RepoWatchersActivity"
@ -41,16 +41,16 @@
<activity android:name=".activities.ProfileEmailActivity" />
<activity android:name=".activities.AddCollaboratorToRepositoryActivity" />
<activity android:name=".activities.CreateTeamByOrgActivity" />
<activity android:name=".activities.OrgTeamMembersActivity" />
<activity android:name=".activities.OrganizationTeamMembersActivity" />
<activity
android:name=".activities.OrgDetailActivity"
android:name=".activities.OrganizationDetailActivity"
android:label="@string/title_activity_org_detail"
android:theme="@style/AppTheme.NoActionBar" />
<activity android:name=".activities.SponsorsActivity" />
<activity android:name=".activities.CreditsActivity" />
<activity android:name=".activities.CreateLabelActivity" />
<activity android:name=".activities.CreateIssueActivity" />
<activity android:name=".activities.NewMilestoneActivity" />
<activity android:name=".activities.CreateMilestoneActivity" />
<activity android:name=".activities.ReplyToIssueActivity" />
<activity
android:name=".activities.IssueDetailActivity"
@ -69,8 +69,8 @@
<activity
android:name=".activities.LoginActivity"
android:launchMode="singleTask" android:theme="@android:style/Theme.NoTitleBar"/>
<activity android:name=".activities.NewRepoActivity" />
<activity android:name=".activities.NewOrganizationActivity" />
<activity android:name=".activities.CreateRepoActivity" />
<activity android:name=".activities.CreateOrganizationActivity" />
<activity android:name=".activities.OpenRepoInBrowserActivity" />
<activity android:name=".activities.FileDiffActivity" />
</application>

View File

@ -32,7 +32,7 @@ import retrofit2.Callback;
* Author M M Arif
*/
public class NewFileActivity extends BaseActivity {
public class CreateFileActivity extends BaseActivity {
public ImageView closeActivity;
private View.OnClickListener onClickListener;

View File

@ -28,7 +28,7 @@ import java.util.Calendar;
* Author M M Arif
*/
public class NewMilestoneActivity extends BaseActivity implements View.OnClickListener {
public class CreateMilestoneActivity extends BaseActivity implements View.OnClickListener {
private EditText milestoneDueDate;
private View.OnClickListener onClickListener;

View File

@ -24,7 +24,7 @@ import retrofit2.Callback;
* Author M M Arif
*/
public class NewOrganizationActivity extends BaseActivity {
public class CreateOrganizationActivity extends BaseActivity {
public ImageView closeActivity;
private View.OnClickListener onClickListener;

View File

@ -32,7 +32,7 @@ import retrofit2.Callback;
* Author M M Arif
*/
public class NewRepoActivity extends BaseActivity {
public class CreateRepoActivity extends BaseActivity {
public ImageView closeActivity;
private View.OnClickListener onClickListener;
@ -43,7 +43,7 @@ public class NewRepoActivity extends BaseActivity {
private CheckBox repoAccess;
final Context ctx = this;
List<OrgOwner> orgsList = new ArrayList<>();
List<OrgOwner> organizationsList = new ArrayList<>();
@Override
protected int getLayoutResourceId(){
@ -72,7 +72,7 @@ public class NewRepoActivity extends BaseActivity {
spinner = findViewById(R.id.ownerSpinner);
spinner.getBackground().setColorFilter(getResources().getColor(R.color.white), PorterDuff.Mode.SRC_ATOP);
getOrgs(instanceUrl, Authorization.returnAuthentication(getApplicationContext(), loginUid, instanceToken), userLogin);
getOrganizations(instanceUrl, Authorization.returnAuthentication(getApplicationContext(), loginUid, instanceToken), userLogin);
spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
@ -225,7 +225,9 @@ public class NewRepoActivity extends BaseActivity {
}
private void getOrgs(String instanceUrl, String instanceToken, final String userLogin) {
private void getOrganizations(String instanceUrl, String instanceToken, final String userLogin) {
TinyDB tinyDb = new TinyDB(getApplicationContext());
Call<List<OrgOwner>> call = RetrofitClient
.getInstance(instanceUrl, getApplicationContext())
@ -240,26 +242,37 @@ public class NewRepoActivity extends BaseActivity {
if(response.isSuccessful()) {
if(response.code() == 200) {
List<OrgOwner> orgsList_ = response.body();
int organizationId = 0;
orgsList.add(new OrgOwner(userLogin));
assert orgsList_ != null;
if(orgsList_.size() > 0) {
for (int i = 0; i < orgsList_.size(); i++) {
List<OrgOwner> organizationsList_ = response.body();
organizationsList.add(new OrgOwner(userLogin));
assert organizationsList_ != null;
if(organizationsList_.size() > 0) {
for (int i = 0; i < organizationsList_.size(); i++) {
if(Integer.parseInt(tinyDb.getString("organizationId")) == organizationsList_.get(i).getId()) {
organizationId = i + 1;
}
OrgOwner data = new OrgOwner(
orgsList_.get(i).getUsername()
organizationsList_.get(i).getUsername()
);
orgsList.add(data);
organizationsList.add(data);
}
}
ArrayAdapter<OrgOwner> adapter = new ArrayAdapter<>(getApplicationContext(),
R.layout.spinner_item, orgsList);
R.layout.spinner_item, organizationsList);
adapter.setDropDownViewResource(R.layout.spinner_dropdown_item);
spinner.setAdapter(adapter);
if (tinyDb.getBoolean("organizationAction")) {
spinner.setSelection(organizationId);
tinyDb.putBoolean("organizationAction", false);
}
enableProcessButton();
}

View File

@ -29,7 +29,7 @@ import java.util.Objects;
* Author M M Arif
*/
public class OrgDetailActivity extends BaseActivity implements BottomSheetOrganizationFragment.BottomSheetListener {
public class OrganizationDetailActivity extends BaseActivity implements BottomSheetOrganizationFragment.BottomSheetListener {
@Override
protected int getLayoutResourceId(){
@ -50,7 +50,7 @@ public class OrgDetailActivity extends BaseActivity implements BottomSheetOrgani
Objects.requireNonNull(getSupportActionBar()).setTitle(orgName);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
OrgDetailActivity.SectionsPagerAdapter mSectionsPagerAdapter = new OrgDetailActivity.SectionsPagerAdapter(getSupportFragmentManager());
OrganizationDetailActivity.SectionsPagerAdapter mSectionsPagerAdapter = new OrganizationDetailActivity.SectionsPagerAdapter(getSupportFragmentManager());
ViewPager mViewPager = findViewById(R.id.container);
mViewPager.setAdapter(mSectionsPagerAdapter);
@ -130,9 +130,15 @@ public class OrgDetailActivity extends BaseActivity implements BottomSheetOrgani
@Override
public void onButtonClicked(String text) {
TinyDB tinyDb = new TinyDB(getApplicationContext());
switch (text) {
case "repository":
tinyDb.putBoolean("organizationAction", true);
startActivity(new Intent(OrganizationDetailActivity.this, CreateRepoActivity.class));
break;
case "team":
startActivity(new Intent(OrgDetailActivity.this, CreateTeamByOrgActivity.class));
startActivity(new Intent(OrganizationDetailActivity.this, CreateTeamByOrgActivity.class));
break;
}
//Log.i("clicked", text);
@ -142,7 +148,7 @@ public class OrgDetailActivity extends BaseActivity implements BottomSheetOrgani
public class SectionsPagerAdapter extends FragmentPagerAdapter {
SectionsPagerAdapter(FragmentManager fm) {
super(fm);
super(fm, BEHAVIOR_RESUME_ONLY_CURRENT_FRAGMENT);
}
@NonNull
@ -151,7 +157,7 @@ public class OrgDetailActivity extends BaseActivity implements BottomSheetOrgani
TinyDB tinyDb = new TinyDB(getApplicationContext());
String orgName;
if(getIntent().getStringExtra("orgName") != null || !getIntent().getStringExtra("orgName").equals("")) {
if(getIntent().getStringExtra("orgName") != null || !Objects.equals(getIntent().getStringExtra("orgName"), "")) {
orgName = getIntent().getStringExtra("orgName");
}
else {

View File

@ -21,7 +21,7 @@ import java.util.Objects;
* Author M M Arif
*/
public class OrgTeamMembersActivity extends BaseActivity {
public class OrganizationTeamMembersActivity extends BaseActivity {
private TextView noDataMembers;
private View.OnClickListener onClickListener;

View File

@ -213,7 +213,7 @@ public class RepoDetailActivity extends BaseActivity implements BottomSheetRepoF
startActivity(new Intent(RepoDetailActivity.this, CreateIssueActivity.class));
break;
case "newMilestone":
startActivity(new Intent(RepoDetailActivity.this, NewMilestoneActivity.class));
startActivity(new Intent(RepoDetailActivity.this, CreateMilestoneActivity.class));
break;
case "addCollaborator":
startActivity(new Intent(RepoDetailActivity.this, AddCollaboratorToRepositoryActivity.class));
@ -233,7 +233,7 @@ public class RepoDetailActivity extends BaseActivity implements BottomSheetRepoF
startActivity(Intent.createChooser(sharingIntent, url.toString()));
break;
case "newFile":
startActivity(new Intent(RepoDetailActivity.this, NewFileActivity.class));
startActivity(new Intent(RepoDetailActivity.this, CreateFileActivity.class));
break;
}

View File

@ -2,6 +2,7 @@ package org.mian.gitnex.adapters;
import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;
import android.annotation.SuppressLint;
import android.content.Context;
import android.content.Intent;
import android.view.LayoutInflater;
@ -13,7 +14,7 @@ import android.widget.ImageView;
import android.widget.TextView;
import com.squareup.picasso.Picasso;
import org.mian.gitnex.R;
import org.mian.gitnex.activities.OrgDetailActivity;
import org.mian.gitnex.activities.OrganizationDetailActivity;
import org.mian.gitnex.models.UserOrganizations;
import org.mian.gitnex.helpers.RoundedTransformation;
import org.mian.gitnex.util.TinyDB;
@ -35,23 +36,27 @@ public class OrganizationsListAdapter extends RecyclerView.Adapter<Organizations
private ImageView image;
private TextView mTextView1;
private TextView mTextView2;
private TextView organizationId;
private OrganizationsViewHolder(View itemView) {
super(itemView);
mTextView1 = itemView.findViewById(R.id.orgUsername);
mTextView2 = itemView.findViewById(R.id.orgDescription);
image = itemView.findViewById(R.id.imageAvatar);
organizationId = itemView.findViewById(R.id.organizationId);
itemView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Context context = v.getContext();
Intent intent = new Intent(context, OrgDetailActivity.class);
Intent intent = new Intent(context, OrganizationDetailActivity.class);
intent.putExtra("orgName", mTextView1.getText().toString());
TinyDB tinyDb = new TinyDB(context);
tinyDb.putString("orgName", mTextView1.getText().toString());
tinyDb.putString("organizationId", organizationId.getText().toString());
tinyDb.putBoolean("organizationAction", true);
context.startActivity(intent);
}
@ -73,11 +78,13 @@ public class OrganizationsListAdapter extends RecyclerView.Adapter<Organizations
return new OrganizationsViewHolder(v);
}
@SuppressLint("SetTextI18n")
@Override
public void onBindViewHolder(@NonNull OrganizationsViewHolder holder, int position) {
UserOrganizations currentItem = orgList.get(position);
holder.mTextView2.setVisibility(View.GONE);
holder.organizationId.setText(Integer.toString(currentItem.getId()));
Picasso.get().load(currentItem.getAvatar_url()).transform(new RoundedTransformation(8, 0)).resize(120, 120).centerCrop().into(holder.image);
holder.mTextView1.setText(currentItem.getUsername());

View File

@ -9,7 +9,7 @@ import android.widget.Filter;
import android.widget.Filterable;
import android.widget.TextView;
import org.mian.gitnex.R;
import org.mian.gitnex.activities.OrgTeamMembersActivity;
import org.mian.gitnex.activities.OrganizationTeamMembersActivity;
import org.mian.gitnex.models.Teams;
import java.util.ArrayList;
import java.util.List;
@ -46,7 +46,7 @@ public class TeamsByOrgAdapter extends RecyclerView.Adapter<TeamsByOrgAdapter.Or
Context context = v.getContext();
Intent intent = new Intent(context, OrgTeamMembersActivity.class);
Intent intent = new Intent(context, OrganizationTeamMembersActivity.class);
intent.putExtra("teamTitle", teamTitle.getText().toString());
intent.putExtra("teamId", teamId.getText().toString());
context.startActivity(intent);

View File

@ -25,6 +25,7 @@ public class BottomSheetOrganizationFragment extends BottomSheetDialogFragment {
View v = inflater.inflate(R.layout.bottom_sheet_organization_layout, container, false);
TextView createTeam = v.findViewById(R.id.createTeam);
TextView createRepository = v.findViewById(R.id.createRepository);
createTeam.setOnClickListener(new View.OnClickListener() {
@Override
@ -34,6 +35,14 @@ public class BottomSheetOrganizationFragment extends BottomSheetDialogFragment {
}
});
createRepository.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
bmListener.onButtonClicked("repository");
dismiss();
}
});
return v;
}

View File

@ -24,7 +24,7 @@ import android.widget.ImageView;
import android.widget.ProgressBar;
import android.widget.TextView;
import org.mian.gitnex.R;
import org.mian.gitnex.activities.NewRepoActivity;
import org.mian.gitnex.activities.CreateRepoActivity;
import org.mian.gitnex.adapters.MyReposListAdapter;
import org.mian.gitnex.helpers.Authorization;
import org.mian.gitnex.models.UserRepositories;
@ -110,7 +110,7 @@ public class MyRepositoriesFragment extends Fragment {
@Override
public void onClick(View view) {
Intent intent = new Intent(view.getContext(), NewRepoActivity.class);
Intent intent = new Intent(view.getContext(), CreateRepoActivity.class);
startActivity(intent);
}

View File

@ -23,7 +23,7 @@ import android.widget.ImageView;
import android.widget.ProgressBar;
import android.widget.TextView;
import org.mian.gitnex.R;
import org.mian.gitnex.activities.NewOrganizationActivity;
import org.mian.gitnex.activities.CreateOrganizationActivity;
import org.mian.gitnex.adapters.OrganizationsListAdapter;
import org.mian.gitnex.helpers.Authorization;
import org.mian.gitnex.util.AppUtil;
@ -77,7 +77,7 @@ public class OrganizationsFragment extends Fragment {
@Override
public void onClick(View view) {
Intent intent = new Intent(view.getContext(), NewOrganizationActivity.class);
Intent intent = new Intent(view.getContext(), CreateOrganizationActivity.class);
startActivity(intent);
}

View File

@ -22,7 +22,7 @@ import android.widget.ImageView;
import android.widget.ProgressBar;
import android.widget.TextView;
import org.mian.gitnex.R;
import org.mian.gitnex.activities.NewRepoActivity;
import org.mian.gitnex.activities.CreateRepoActivity;
import org.mian.gitnex.adapters.ReposListAdapter;
import org.mian.gitnex.helpers.Authorization;
import org.mian.gitnex.models.UserRepositories;
@ -79,7 +79,7 @@ public class RepositoriesFragment extends Fragment {
@Override
public void onClick(View view) {
Intent intent = new Intent(view.getContext(), NewRepoActivity.class);
Intent intent = new Intent(view.getContext(), CreateRepoActivity.class);
startActivity(intent);
}

View File

@ -24,7 +24,7 @@ import android.widget.ImageView;
import android.widget.ProgressBar;
import android.widget.TextView;
import org.mian.gitnex.R;
import org.mian.gitnex.activities.NewRepoActivity;
import org.mian.gitnex.activities.CreateRepoActivity;
import org.mian.gitnex.adapters.StarredReposListAdapter;
import org.mian.gitnex.helpers.Authorization;
import org.mian.gitnex.models.UserRepositories;
@ -104,7 +104,7 @@ public class StarredRepositoriesFragment extends Fragment {
@Override
public void onClick(View view) {
Intent intent = new Intent(view.getContext(), NewRepoActivity.class);
Intent intent = new Intent(view.getContext(), CreateRepoActivity.class);
startActivity(intent);
}

View File

@ -6,6 +6,7 @@ package org.mian.gitnex.models;
public class OrgOwner {
private int id;
private String username;
public OrgOwner(String username) {
@ -16,6 +17,10 @@ public class OrgOwner {
return username;
}
public int getId() {
return id;
}
@Override
public String toString() {
return username;

View File

@ -6,6 +6,7 @@ package org.mian.gitnex.models;
public class UserOrganizations {
private int id;
private String username;
private String avatar_url;
private String description;
@ -20,6 +21,10 @@ public class UserOrganizations {
this.location = location;
}
public int getId() {
return id;
}
public String getUsername() {
return username;
}

View File

@ -7,7 +7,7 @@
android:layout_height="match_parent"
android:fitsSystemWindows="true"
android:background="?attr/primaryBackgroundColor"
tools:context=".activities.OrgDetailActivity">
tools:context=".activities.OrganizationDetailActivity">
<com.google.android.material.appbar.AppBarLayout
android:id="@+id/appbar"

View File

@ -17,6 +17,18 @@
android:orientation="vertical"
android:layout_height="wrap_content">
<TextView
android:id="@+id/createRepository"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:text="@string/createRepository"
android:drawableStart="@drawable/ic_repos"
android:drawablePadding="24dp"
android:textColor="?attr/primaryTextColor"
android:textSize="16sp"
android:padding="16dp" />
<TextView
android:id="@+id/createTeam"
android:layout_width="match_parent"

View File

@ -3,7 +3,7 @@
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".activities.OrgDetailActivity">
tools:context=".activities.OrganizationDetailActivity">
<androidx.swiperefreshlayout.widget.SwipeRefreshLayout
android:id="@+id/pullToRefresh"

View File

@ -3,7 +3,7 @@
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".activities.OrgDetailActivity">
tools:context=".activities.OrganizationDetailActivity">
<androidx.swiperefreshlayout.widget.SwipeRefreshLayout
android:id="@+id/pullToRefresh"

View File

@ -15,6 +15,12 @@
android:padding="10dp"
tools:context=".activities.MainActivity">
<TextView
android:id="@+id/organizationId"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibility="invisible"/>
<ImageView
android:id="@+id/imageAvatar"
android:layout_width="40dp"

View File

@ -559,4 +559,5 @@
<string name="sizeCopy">Size</string>
<string name="shareIssue">Share Issue</string>
<string name="shareRepository">Share Repository</string>
<string name="createRepository">Create Repository</string>
</resources>