mirror of
https://codeberg.org/gitnex/GitNex.git
synced 2024-12-16 15:48:13 +08:00
Organization labels (#771)
List, Create, Edit & Delete OrgLabels Co-authored-by: M M Arif <mmarif@swatian.com> Co-authored-by: 6543 <6543@obermui.de> Reviewed-on: https://codeberg.org/gitnex/GitNex/pulls/771 Reviewed-by: 6543 <6543@noreply.codeberg.org>
This commit is contained in:
parent
b871a1fb22
commit
bbbcb56b98
@ -23,6 +23,7 @@ import org.mian.gitnex.helpers.Toasty;
|
|||||||
import org.mian.gitnex.models.CreateLabel;
|
import org.mian.gitnex.models.CreateLabel;
|
||||||
import org.mian.gitnex.models.Labels;
|
import org.mian.gitnex.models.Labels;
|
||||||
import org.mian.gitnex.viewmodels.LabelsViewModel;
|
import org.mian.gitnex.viewmodels.LabelsViewModel;
|
||||||
|
import org.mian.gitnex.viewmodels.OrganizationLabelsViewModel;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
import retrofit2.Call;
|
import retrofit2.Call;
|
||||||
import retrofit2.Callback;
|
import retrofit2.Callback;
|
||||||
@ -37,6 +38,7 @@ public class CreateLabelActivity extends BaseActivity {
|
|||||||
private TextView colorPicker;
|
private TextView colorPicker;
|
||||||
private EditText labelName;
|
private EditText labelName;
|
||||||
private Button createLabelButton;
|
private Button createLabelButton;
|
||||||
|
private TinyDB tinyDB;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected int getLayoutResourceId(){
|
protected int getLayoutResourceId(){
|
||||||
@ -50,20 +52,17 @@ public class CreateLabelActivity extends BaseActivity {
|
|||||||
|
|
||||||
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
|
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
|
||||||
|
|
||||||
final TinyDB tinyDb = TinyDB.getInstance(appCtx);
|
tinyDB = TinyDB.getInstance(appCtx);
|
||||||
String repoFullName = tinyDb.getString("repoFullName");
|
String repoFullName = tinyDB.getString("repoFullName");
|
||||||
String[] parts = repoFullName.split("/");
|
String[] parts = repoFullName.split("/");
|
||||||
final String repoOwner = parts[0];
|
final String repoOwner = parts[0];
|
||||||
final String repoName = parts[1];
|
final String repoName = parts[1];
|
||||||
final String loginUid = tinyDb.getString("loginUid");
|
|
||||||
final String instanceToken = "token " + tinyDb.getString(loginUid + "-token");
|
|
||||||
|
|
||||||
if(getIntent().getStringExtra("labelAction") != null && Objects.requireNonNull(getIntent().getStringExtra("labelAction")).equals("delete")) {
|
if(getIntent().getStringExtra("labelAction") != null && Objects.requireNonNull(getIntent().getStringExtra("labelAction")).equals("delete")) {
|
||||||
|
|
||||||
deleteLabel(instanceToken, repoOwner, repoName, Integer.parseInt(Objects.requireNonNull(getIntent().getStringExtra("labelId"))), loginUid);
|
deleteLabel(repoOwner, repoName, Integer.parseInt(Objects.requireNonNull(getIntent().getStringExtra("labelId"))));
|
||||||
finish();
|
finish();
|
||||||
return;
|
return;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean connToInternet = AppUtil.hasNetworkConnection(appCtx);
|
boolean connToInternet = AppUtil.hasNetworkConnection(appCtx);
|
||||||
@ -87,7 +86,7 @@ public class CreateLabelActivity extends BaseActivity {
|
|||||||
|
|
||||||
//Log.i("#Hex no alpha", String.format("#%06X", (0xFFFFFF & color)));
|
//Log.i("#Hex no alpha", String.format("#%06X", (0xFFFFFF & color)));
|
||||||
colorPicker.setBackgroundColor(color);
|
colorPicker.setBackgroundColor(color);
|
||||||
tinyDb.putString("labelColor", String.format("#%06X", (0xFFFFFF & color)));
|
tinyDB.putString("labelColor", String.format("#%06X", (0xFFFFFF & color)));
|
||||||
cp.dismiss();
|
cp.dismiss();
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -96,7 +95,7 @@ public class CreateLabelActivity extends BaseActivity {
|
|||||||
labelName.setText(getIntent().getStringExtra("labelTitle"));
|
labelName.setText(getIntent().getStringExtra("labelTitle"));
|
||||||
int labelColor_ = Color.parseColor("#" + getIntent().getStringExtra("labelColor"));
|
int labelColor_ = Color.parseColor("#" + getIntent().getStringExtra("labelColor"));
|
||||||
colorPicker.setBackgroundColor(labelColor_);
|
colorPicker.setBackgroundColor(labelColor_);
|
||||||
tinyDb.putString("labelColorDefault", "#" + getIntent().getStringExtra("labelColor"));
|
tinyDB.putString("labelColorDefault", "#" + getIntent().getStringExtra("labelColor"));
|
||||||
|
|
||||||
TextView toolbar_title = findViewById(R.id.toolbar_title);
|
TextView toolbar_title = findViewById(R.id.toolbar_title);
|
||||||
toolbar_title.setText(getResources().getString(R.string.pageTitleLabelUpdate));
|
toolbar_title.setText(getResources().getString(R.string.pageTitleLabelUpdate));
|
||||||
@ -123,26 +122,23 @@ public class CreateLabelActivity extends BaseActivity {
|
|||||||
|
|
||||||
private void processUpdateLabel() {
|
private void processUpdateLabel() {
|
||||||
|
|
||||||
final TinyDB tinyDb = TinyDB.getInstance(appCtx);
|
|
||||||
boolean connToInternet = AppUtil.hasNetworkConnection(appCtx);
|
boolean connToInternet = AppUtil.hasNetworkConnection(appCtx);
|
||||||
AppUtil appUtil = new AppUtil();
|
AppUtil appUtil = new AppUtil();
|
||||||
String repoFullName = tinyDb.getString("repoFullName");
|
String repoFullName = tinyDB.getString("repoFullName");
|
||||||
String[] parts = repoFullName.split("/");
|
String[] parts = repoFullName.split("/");
|
||||||
final String repoOwner = parts[0];
|
final String repoOwner = parts[0];
|
||||||
final String repoName = parts[1];
|
final String repoName = parts[1];
|
||||||
final String loginUid = tinyDb.getString("loginUid");
|
|
||||||
final String instanceToken = "token " + tinyDb.getString(loginUid + "-token");
|
|
||||||
|
|
||||||
String updateLabelName = labelName.getText().toString();
|
String updateLabelName = labelName.getText().toString();
|
||||||
|
|
||||||
String updateLabelColor;
|
String updateLabelColor;
|
||||||
if(tinyDb.getString("labelColor").isEmpty()) {
|
if(tinyDB.getString("labelColor").isEmpty()) {
|
||||||
|
|
||||||
updateLabelColor = tinyDb.getString("labelColorDefault");
|
updateLabelColor = tinyDB.getString("labelColorDefault");
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|
||||||
updateLabelColor = tinyDb.getString("labelColor");
|
updateLabelColor = tinyDB.getString("labelColor");
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!connToInternet) {
|
if(!connToInternet) {
|
||||||
@ -164,8 +160,8 @@ public class CreateLabelActivity extends BaseActivity {
|
|||||||
}
|
}
|
||||||
|
|
||||||
disableProcessButton();
|
disableProcessButton();
|
||||||
patchLabel(instanceToken, repoOwner, repoName, updateLabelName, updateLabelColor, Integer.parseInt(
|
patchLabel(repoOwner, repoName, updateLabelName, updateLabelColor, Integer.parseInt(
|
||||||
Objects.requireNonNull(getIntent().getStringExtra("labelId"))), loginUid);
|
Objects.requireNonNull(getIntent().getStringExtra("labelId"))));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -173,24 +169,22 @@ public class CreateLabelActivity extends BaseActivity {
|
|||||||
|
|
||||||
boolean connToInternet = AppUtil.hasNetworkConnection(appCtx);
|
boolean connToInternet = AppUtil.hasNetworkConnection(appCtx);
|
||||||
AppUtil appUtil = new AppUtil();
|
AppUtil appUtil = new AppUtil();
|
||||||
TinyDB tinyDb = TinyDB.getInstance(appCtx);
|
|
||||||
String repoFullName = tinyDb.getString("repoFullName");
|
String repoFullName = tinyDB.getString("repoFullName");
|
||||||
String[] parts = repoFullName.split("/");
|
String[] parts = repoFullName.split("/");
|
||||||
final String repoOwner = parts[0];
|
final String repoOwner = parts[0];
|
||||||
final String repoName = parts[1];
|
final String repoName = parts[1];
|
||||||
final String loginUid = tinyDb.getString("loginUid");
|
|
||||||
final String instanceToken = "token " + tinyDb.getString(loginUid + "-token");
|
|
||||||
|
|
||||||
String newLabelName = labelName.getText().toString();
|
String newLabelName = labelName.getText().toString();
|
||||||
String newLabelColor;
|
String newLabelColor;
|
||||||
|
|
||||||
if(tinyDb.getString("labelColor").isEmpty()) {
|
if(tinyDB.getString("labelColor").isEmpty()) {
|
||||||
|
|
||||||
newLabelColor = String.format("#%06X", (0xFFFFFF & ContextCompat.getColor(ctx, R.color.releasePre)));
|
newLabelColor = String.format("#%06X", (0xFFFFFF & ContextCompat.getColor(ctx, R.color.releasePre)));
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|
||||||
newLabelColor = tinyDb.getString("labelColor");
|
newLabelColor = tinyDB.getString("labelColor");
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!connToInternet) {
|
if(!connToInternet) {
|
||||||
@ -212,19 +206,23 @@ public class CreateLabelActivity extends BaseActivity {
|
|||||||
}
|
}
|
||||||
|
|
||||||
disableProcessButton();
|
disableProcessButton();
|
||||||
createNewLabel(instanceToken, repoOwner, repoName, newLabelName, newLabelColor, loginUid);
|
createNewLabel(repoOwner, repoName, newLabelName, newLabelColor);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void createNewLabel(final String instanceToken, String repoOwner, String repoName, String newLabelName, String newLabelColor, String loginUid) {
|
private void createNewLabel(String repoOwner, String repoName, String newLabelName, String newLabelColor) {
|
||||||
|
|
||||||
CreateLabel createLabelFunc = new CreateLabel(newLabelName, newLabelColor);
|
CreateLabel createLabelFunc = new CreateLabel(newLabelName, newLabelColor);
|
||||||
final TinyDB tinyDb = TinyDB.getInstance(appCtx);
|
|
||||||
|
|
||||||
Call<CreateLabel> call;
|
Call<CreateLabel> call;
|
||||||
|
|
||||||
call = RetrofitClient
|
if(getIntent().getStringExtra("type") != null && Objects.requireNonNull(getIntent().getStringExtra("type")).equals("org")) {
|
||||||
.getApiInterface(ctx)
|
|
||||||
.createLabel(Authorization.get(ctx), repoOwner, repoName, createLabelFunc);
|
call = RetrofitClient.getApiInterface(ctx).createOrganizationLabel(Authorization.get(ctx), getIntent().getStringExtra("orgName"), createLabelFunc);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
|
||||||
|
call = RetrofitClient.getApiInterface(ctx).createLabel(Authorization.get(ctx), repoOwner, repoName, createLabelFunc);
|
||||||
|
}
|
||||||
|
|
||||||
call.enqueue(new Callback<CreateLabel>() {
|
call.enqueue(new Callback<CreateLabel>() {
|
||||||
|
|
||||||
@ -234,8 +232,8 @@ public class CreateLabelActivity extends BaseActivity {
|
|||||||
if(response.code() == 201) {
|
if(response.code() == 201) {
|
||||||
|
|
||||||
Toasty.success(ctx, getString(R.string.labelCreated));
|
Toasty.success(ctx, getString(R.string.labelCreated));
|
||||||
tinyDb.putString("labelColor", "");
|
tinyDB.putString("labelColor", "");
|
||||||
tinyDb.putBoolean("labelsRefresh", true);
|
tinyDB.putBoolean("labelsRefresh", true);
|
||||||
finish();
|
finish();
|
||||||
}
|
}
|
||||||
else if(response.code() == 401) {
|
else if(response.code() == 401) {
|
||||||
@ -249,7 +247,7 @@ public class CreateLabelActivity extends BaseActivity {
|
|||||||
else {
|
else {
|
||||||
|
|
||||||
enableProcessButton();
|
enableProcessButton();
|
||||||
tinyDb.putString("labelColor", "");
|
tinyDB.putString("labelColor", "");
|
||||||
Toasty.error(ctx, getString(R.string.labelGeneralError));
|
Toasty.error(ctx, getString(R.string.labelGeneralError));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -257,7 +255,7 @@ public class CreateLabelActivity extends BaseActivity {
|
|||||||
@Override
|
@Override
|
||||||
public void onFailure(@NonNull Call<CreateLabel> call, @NonNull Throwable t) {
|
public void onFailure(@NonNull Call<CreateLabel> call, @NonNull Throwable t) {
|
||||||
|
|
||||||
tinyDb.putString("labelColor", "");
|
tinyDB.putString("labelColor", "");
|
||||||
Log.e("onFailure", t.toString());
|
Log.e("onFailure", t.toString());
|
||||||
enableProcessButton();
|
enableProcessButton();
|
||||||
}
|
}
|
||||||
@ -265,16 +263,20 @@ public class CreateLabelActivity extends BaseActivity {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void patchLabel(final String instanceToken, String repoOwner, String repoName, String updateLabelName, String updateLabelColor, int labelId, String loginUid) {
|
private void patchLabel(String repoOwner, String repoName, String updateLabelName, String updateLabelColor, int labelId) {
|
||||||
|
|
||||||
CreateLabel createLabelFunc = new CreateLabel(updateLabelName, updateLabelColor);
|
CreateLabel createLabelFunc = new CreateLabel(updateLabelName, updateLabelColor);
|
||||||
final TinyDB tinyDb = TinyDB.getInstance(appCtx);
|
|
||||||
|
|
||||||
Call<CreateLabel> call;
|
Call<CreateLabel> call;
|
||||||
|
|
||||||
call = RetrofitClient
|
if(getIntent().getStringExtra("type") != null && Objects.requireNonNull(getIntent().getStringExtra("type")).equals("org")) {
|
||||||
.getApiInterface(appCtx)
|
|
||||||
.patchLabel(Authorization.get(ctx), repoOwner, repoName, labelId, createLabelFunc);
|
call = RetrofitClient.getApiInterface(ctx).patchOrganizationLabel(Authorization.get(ctx), getIntent().getStringExtra("orgName"), labelId, createLabelFunc);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
|
||||||
|
call = RetrofitClient.getApiInterface(appCtx).patchLabel(Authorization.get(ctx), repoOwner, repoName, labelId, createLabelFunc);
|
||||||
|
}
|
||||||
|
|
||||||
call.enqueue(new Callback<CreateLabel>() {
|
call.enqueue(new Callback<CreateLabel>() {
|
||||||
|
|
||||||
@ -286,13 +288,14 @@ public class CreateLabelActivity extends BaseActivity {
|
|||||||
if(response.code() == 200) {
|
if(response.code() == 200) {
|
||||||
|
|
||||||
Toasty.success(ctx, getString(R.string.labelUpdated));
|
Toasty.success(ctx, getString(R.string.labelUpdated));
|
||||||
tinyDb.putString("labelColor", "");
|
tinyDB.putString("labelColor", "");
|
||||||
tinyDb.putBoolean("labelsRefresh", true);
|
tinyDB.putBoolean("labelsRefresh", true);
|
||||||
tinyDb.putString("labelColorDefault", "");
|
tinyDB.putString("labelColorDefault", "");
|
||||||
getIntent().removeExtra("labelAction");
|
getIntent().removeExtra("labelAction");
|
||||||
getIntent().removeExtra("labelId");
|
getIntent().removeExtra("labelId");
|
||||||
getIntent().removeExtra("labelTitle");
|
getIntent().removeExtra("labelTitle");
|
||||||
getIntent().removeExtra("labelColor");
|
getIntent().removeExtra("labelColor");
|
||||||
|
getIntent().removeExtra("type");
|
||||||
finish();
|
finish();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -307,8 +310,8 @@ public class CreateLabelActivity extends BaseActivity {
|
|||||||
else {
|
else {
|
||||||
|
|
||||||
enableProcessButton();
|
enableProcessButton();
|
||||||
tinyDb.putString("labelColor", "");
|
tinyDB.putString("labelColor", "");
|
||||||
tinyDb.putString("labelColorDefault", "");
|
tinyDB.putString("labelColorDefault", "");
|
||||||
Toasty.error(ctx, getString(R.string.labelGeneralError));
|
Toasty.error(ctx, getString(R.string.labelGeneralError));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -316,8 +319,8 @@ public class CreateLabelActivity extends BaseActivity {
|
|||||||
@Override
|
@Override
|
||||||
public void onFailure(@NonNull Call<CreateLabel> call, @NonNull Throwable t) {
|
public void onFailure(@NonNull Call<CreateLabel> call, @NonNull Throwable t) {
|
||||||
|
|
||||||
tinyDb.putString("labelColor", "");
|
tinyDB.putString("labelColor", "");
|
||||||
tinyDb.putString("labelColorDefault", "");
|
tinyDB.putString("labelColorDefault", "");
|
||||||
Log.e("onFailure", t.toString());
|
Log.e("onFailure", t.toString());
|
||||||
enableProcessButton();
|
enableProcessButton();
|
||||||
}
|
}
|
||||||
@ -333,17 +336,23 @@ public class CreateLabelActivity extends BaseActivity {
|
|||||||
getIntent().removeExtra("labelId");
|
getIntent().removeExtra("labelId");
|
||||||
getIntent().removeExtra("labelTitle");
|
getIntent().removeExtra("labelTitle");
|
||||||
getIntent().removeExtra("labelColor");
|
getIntent().removeExtra("labelColor");
|
||||||
|
getIntent().removeExtra("type");
|
||||||
finish();
|
finish();
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
private void deleteLabel(final String instanceToken, final String repoOwner, final String repoName, int labelId, String loginUid) {
|
private void deleteLabel(final String repoOwner, final String repoName, int labelId) {
|
||||||
|
|
||||||
Call<Labels> call;
|
Call<Labels> call;
|
||||||
|
|
||||||
call = RetrofitClient
|
if(getIntent().getStringExtra("type") != null && Objects.requireNonNull(getIntent().getStringExtra("type")).equals("org")) {
|
||||||
.getApiInterface(appCtx)
|
|
||||||
.deleteLabel(Authorization.get(ctx), repoOwner, repoName, labelId);
|
call = RetrofitClient.getApiInterface(appCtx).deleteOrganizationLabel(Authorization.get(ctx), getIntent().getStringExtra("orgName"), labelId);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
|
||||||
|
call = RetrofitClient.getApiInterface(appCtx).deleteLabel(Authorization.get(ctx), repoOwner, repoName, labelId);
|
||||||
|
}
|
||||||
|
|
||||||
call.enqueue(new Callback<Labels>() {
|
call.enqueue(new Callback<Labels>() {
|
||||||
|
|
||||||
@ -355,9 +364,17 @@ public class CreateLabelActivity extends BaseActivity {
|
|||||||
if(response.code() == 204) {
|
if(response.code() == 204) {
|
||||||
|
|
||||||
Toasty.success(ctx, getString(R.string.labelDeleteText));
|
Toasty.success(ctx, getString(R.string.labelDeleteText));
|
||||||
LabelsViewModel.loadLabelsList(instanceToken, repoOwner, repoName, ctx);
|
if(getIntent().getStringExtra("type") != null && Objects.requireNonNull(getIntent().getStringExtra("type")).equals("org")) {
|
||||||
|
|
||||||
|
OrganizationLabelsViewModel.loadOrgLabelsList(Authorization.get(ctx), getIntent().getStringExtra("orgName"), ctx, null, null);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
|
||||||
|
LabelsViewModel.loadLabelsList(Authorization.get(ctx), repoOwner, repoName, ctx);
|
||||||
|
}
|
||||||
getIntent().removeExtra("labelAction");
|
getIntent().removeExtra("labelAction");
|
||||||
getIntent().removeExtra("labelId");
|
getIntent().removeExtra("labelId");
|
||||||
|
getIntent().removeExtra("type");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if(response.code() == 401) {
|
else if(response.code() == 401) {
|
||||||
|
@ -23,6 +23,7 @@ import org.mian.gitnex.R;
|
|||||||
import org.mian.gitnex.fragments.BottomSheetOrganizationFragment;
|
import org.mian.gitnex.fragments.BottomSheetOrganizationFragment;
|
||||||
import org.mian.gitnex.fragments.MembersByOrgFragment;
|
import org.mian.gitnex.fragments.MembersByOrgFragment;
|
||||||
import org.mian.gitnex.fragments.OrganizationInfoFragment;
|
import org.mian.gitnex.fragments.OrganizationInfoFragment;
|
||||||
|
import org.mian.gitnex.fragments.OrganizationLabelsFragment;
|
||||||
import org.mian.gitnex.fragments.RepositoriesByOrgFragment;
|
import org.mian.gitnex.fragments.RepositoriesByOrgFragment;
|
||||||
import org.mian.gitnex.fragments.TeamsByOrgFragment;
|
import org.mian.gitnex.fragments.TeamsByOrgFragment;
|
||||||
import org.mian.gitnex.helpers.Toasty;
|
import org.mian.gitnex.helpers.Toasty;
|
||||||
@ -145,6 +146,13 @@ public class OrganizationDetailActivity extends BaseActivity implements BottomSh
|
|||||||
tinyDB.putBoolean("organizationAction", true);
|
tinyDB.putBoolean("organizationAction", true);
|
||||||
startActivity(new Intent(OrganizationDetailActivity.this, CreateRepoActivity.class));
|
startActivity(new Intent(OrganizationDetailActivity.this, CreateRepoActivity.class));
|
||||||
break;
|
break;
|
||||||
|
case "label":
|
||||||
|
|
||||||
|
Intent intent = new Intent(ctx, CreateLabelActivity.class);
|
||||||
|
intent.putExtra("orgName", getIntent().getStringExtra("orgName"));
|
||||||
|
intent.putExtra("type", "org");
|
||||||
|
ctx.startActivity(intent);
|
||||||
|
break;
|
||||||
case "team":
|
case "team":
|
||||||
|
|
||||||
startActivity(new Intent(OrganizationDetailActivity.this, CreateTeamByOrgActivity.class));
|
startActivity(new Intent(OrganizationDetailActivity.this, CreateTeamByOrgActivity.class));
|
||||||
@ -192,10 +200,13 @@ public class OrganizationDetailActivity extends BaseActivity implements BottomSh
|
|||||||
case 1: // repos
|
case 1: // repos
|
||||||
|
|
||||||
return RepositoriesByOrgFragment.newInstance(orgName);
|
return RepositoriesByOrgFragment.newInstance(orgName);
|
||||||
case 2: // teams
|
case 2: // labels
|
||||||
|
|
||||||
|
return OrganizationLabelsFragment.newInstance(orgName);
|
||||||
|
case 3: // teams
|
||||||
|
|
||||||
return TeamsByOrgFragment.newInstance(orgName);
|
return TeamsByOrgFragment.newInstance(orgName);
|
||||||
case 3: // members
|
case 4: // members
|
||||||
|
|
||||||
return MembersByOrgFragment.newInstance(orgName);
|
return MembersByOrgFragment.newInstance(orgName);
|
||||||
}
|
}
|
||||||
|
@ -32,6 +32,8 @@ public class LabelsAdapter extends RecyclerView.Adapter<LabelsAdapter.LabelsView
|
|||||||
private List<Labels> labelsList;
|
private List<Labels> labelsList;
|
||||||
final private Context mCtx;
|
final private Context mCtx;
|
||||||
private ArrayList<Integer> labelsArray = new ArrayList<>();
|
private ArrayList<Integer> labelsArray = new ArrayList<>();
|
||||||
|
private static String type;
|
||||||
|
private static String orgName;
|
||||||
|
|
||||||
static class LabelsViewHolder extends RecyclerView.ViewHolder {
|
static class LabelsViewHolder extends RecyclerView.ViewHolder {
|
||||||
|
|
||||||
@ -77,6 +79,8 @@ public class LabelsAdapter extends RecyclerView.Adapter<LabelsAdapter.LabelsView
|
|||||||
intent.putExtra("labelTitle", labelTitle.getText());
|
intent.putExtra("labelTitle", labelTitle.getText());
|
||||||
intent.putExtra("labelColor", labelColor.getText());
|
intent.putExtra("labelColor", labelColor.getText());
|
||||||
intent.putExtra("labelAction", "edit");
|
intent.putExtra("labelAction", "edit");
|
||||||
|
intent.putExtra("type", type);
|
||||||
|
intent.putExtra("orgName", orgName);
|
||||||
context.startActivity(intent);
|
context.startActivity(intent);
|
||||||
dialog.dismiss();
|
dialog.dismiss();
|
||||||
|
|
||||||
@ -87,8 +91,9 @@ public class LabelsAdapter extends RecyclerView.Adapter<LabelsAdapter.LabelsView
|
|||||||
AlertDialogs.labelDeleteDialog(context, labelTitle.getText().toString(), labelId.getText().toString(),
|
AlertDialogs.labelDeleteDialog(context, labelTitle.getText().toString(), labelId.getText().toString(),
|
||||||
context.getResources().getString(R.string.labelDeleteTitle),
|
context.getResources().getString(R.string.labelDeleteTitle),
|
||||||
context.getResources().getString(R.string.labelDeleteMessage),
|
context.getResources().getString(R.string.labelDeleteMessage),
|
||||||
context.getResources().getString(R.string.labelDeletePositiveButton),
|
context.getResources().getString(R.string.labelDeleteTitle),
|
||||||
context.getResources().getString(R.string.labelDeleteNegativeButton));
|
context.getResources().getString(R.string.labelDeleteNegativeButton),
|
||||||
|
type, orgName);
|
||||||
dialog.dismiss();
|
dialog.dismiss();
|
||||||
|
|
||||||
});
|
});
|
||||||
@ -98,9 +103,12 @@ public class LabelsAdapter extends RecyclerView.Adapter<LabelsAdapter.LabelsView
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public LabelsAdapter(Context mCtx, List<Labels> labelsMain) {
|
public LabelsAdapter(Context mCtx, List<Labels> labelsMain, String type, String orgName) {
|
||||||
|
|
||||||
this.mCtx = mCtx;
|
this.mCtx = mCtx;
|
||||||
this.labelsList = labelsMain;
|
this.labelsList = labelsMain;
|
||||||
|
LabelsAdapter.type = type;
|
||||||
|
LabelsAdapter.orgName = orgName;
|
||||||
}
|
}
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
|
@ -45,9 +45,7 @@ public class OrganizationsListAdapter extends RecyclerView.Adapter<Organizations
|
|||||||
image = itemView.findViewById(R.id.imageAvatar);
|
image = itemView.findViewById(R.id.imageAvatar);
|
||||||
organizationId = itemView.findViewById(R.id.organizationId);
|
organizationId = itemView.findViewById(R.id.organizationId);
|
||||||
|
|
||||||
itemView.setOnClickListener(new View.OnClickListener() {
|
itemView.setOnClickListener(v -> {
|
||||||
@Override
|
|
||||||
public void onClick(View v) {
|
|
||||||
|
|
||||||
Context context = v.getContext();
|
Context context = v.getContext();
|
||||||
Intent intent = new Intent(context, OrganizationDetailActivity.class);
|
Intent intent = new Intent(context, OrganizationDetailActivity.class);
|
||||||
@ -58,14 +56,12 @@ public class OrganizationsListAdapter extends RecyclerView.Adapter<Organizations
|
|||||||
tinyDb.putString("organizationId", organizationId.getText().toString());
|
tinyDb.putString("organizationId", organizationId.getText().toString());
|
||||||
tinyDb.putBoolean("organizationAction", true);
|
tinyDb.putBoolean("organizationAction", true);
|
||||||
context.startActivity(intent);
|
context.startActivity(intent);
|
||||||
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public OrganizationsListAdapter(Context mCtx, List<UserOrganizations> orgsListMain) {
|
public OrganizationsListAdapter(Context mCtx, List<UserOrganizations> orgsListMain) {
|
||||||
|
|
||||||
this.mCtx = mCtx;
|
this.mCtx = mCtx;
|
||||||
this.orgList = orgsListMain;
|
this.orgList = orgsListMain;
|
||||||
orgListFull = new ArrayList<>(orgList);
|
orgListFull = new ArrayList<>(orgList);
|
||||||
@ -74,6 +70,7 @@ public class OrganizationsListAdapter extends RecyclerView.Adapter<Organizations
|
|||||||
@NonNull
|
@NonNull
|
||||||
@Override
|
@Override
|
||||||
public OrganizationsViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
|
public OrganizationsViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
|
||||||
|
|
||||||
View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.list_organizations, parent, false);
|
View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.list_organizations, parent, false);
|
||||||
return new OrganizationsViewHolder(v);
|
return new OrganizationsViewHolder(v);
|
||||||
}
|
}
|
||||||
@ -88,11 +85,12 @@ public class OrganizationsListAdapter extends RecyclerView.Adapter<Organizations
|
|||||||
|
|
||||||
PicassoService.getInstance(mCtx).get().load(currentItem.getAvatar_url()).placeholder(R.drawable.loader_animated).transform(new RoundedTransformation(8, 0)).resize(120, 120).centerCrop().into(holder.image);
|
PicassoService.getInstance(mCtx).get().load(currentItem.getAvatar_url()).placeholder(R.drawable.loader_animated).transform(new RoundedTransformation(8, 0)).resize(120, 120).centerCrop().into(holder.image);
|
||||||
holder.mTextView1.setText(currentItem.getUsername());
|
holder.mTextView1.setText(currentItem.getUsername());
|
||||||
|
|
||||||
if (!currentItem.getDescription().equals("")) {
|
if (!currentItem.getDescription().equals("")) {
|
||||||
|
|
||||||
holder.mTextView2.setVisibility(View.VISIBLE);
|
holder.mTextView2.setVisibility(View.VISIBLE);
|
||||||
holder.mTextView2.setText(currentItem.getDescription());
|
holder.mTextView2.setText(currentItem.getDescription());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -105,14 +103,19 @@ public class OrganizationsListAdapter extends RecyclerView.Adapter<Organizations
|
|||||||
return orgFilter;
|
return orgFilter;
|
||||||
}
|
}
|
||||||
|
|
||||||
private Filter orgFilter = new Filter() {
|
private final Filter orgFilter = new Filter() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected FilterResults performFiltering(CharSequence constraint) {
|
protected FilterResults performFiltering(CharSequence constraint) {
|
||||||
|
|
||||||
List<UserOrganizations> filteredList = new ArrayList<>();
|
List<UserOrganizations> filteredList = new ArrayList<>();
|
||||||
|
|
||||||
if (constraint == null || constraint.length() == 0) {
|
if (constraint == null || constraint.length() == 0) {
|
||||||
|
|
||||||
filteredList.addAll(orgListFull);
|
filteredList.addAll(orgListFull);
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
|
|
||||||
String filterPattern = constraint.toString().toLowerCase().trim();
|
String filterPattern = constraint.toString().toLowerCase().trim();
|
||||||
|
|
||||||
for (UserOrganizations item : orgListFull) {
|
for (UserOrganizations item : orgListFull) {
|
||||||
@ -130,6 +133,7 @@ public class OrganizationsListAdapter extends RecyclerView.Adapter<Organizations
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void publishResults(CharSequence constraint, FilterResults results) {
|
protected void publishResults(CharSequence constraint, FilterResults results) {
|
||||||
|
|
||||||
orgList.clear();
|
orgList.clear();
|
||||||
orgList.addAll((List) results.values);
|
orgList.addAll((List) results.values);
|
||||||
notifyDataSetChanged();
|
notifyDataSetChanged();
|
||||||
|
@ -28,6 +28,7 @@ public class BottomSheetOrganizationFragment extends BottomSheetDialogFragment {
|
|||||||
TextView createTeam = v.findViewById(R.id.createTeam);
|
TextView createTeam = v.findViewById(R.id.createTeam);
|
||||||
TextView createRepository = v.findViewById(R.id.createRepository);
|
TextView createRepository = v.findViewById(R.id.createRepository);
|
||||||
TextView copyOrgUrl = v.findViewById(R.id.copyOrgUrl);
|
TextView copyOrgUrl = v.findViewById(R.id.copyOrgUrl);
|
||||||
|
TextView createLabel = v.findViewById(R.id.createLabel);
|
||||||
|
|
||||||
createTeam.setOnClickListener(v1 -> {
|
createTeam.setOnClickListener(v1 -> {
|
||||||
|
|
||||||
@ -35,6 +36,12 @@ public class BottomSheetOrganizationFragment extends BottomSheetDialogFragment {
|
|||||||
dismiss();
|
dismiss();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
createLabel.setOnClickListener(v1 -> {
|
||||||
|
|
||||||
|
bmListener.onButtonClicked("label");
|
||||||
|
dismiss();
|
||||||
|
});
|
||||||
|
|
||||||
createRepository.setOnClickListener(v12 -> {
|
createRepository.setOnClickListener(v12 -> {
|
||||||
|
|
||||||
bmListener.onButtonClicked("repository");
|
bmListener.onButtonClicked("repository");
|
||||||
|
@ -10,9 +10,7 @@ import android.view.ViewGroup;
|
|||||||
import android.widget.ProgressBar;
|
import android.widget.ProgressBar;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
import androidx.annotation.Nullable;
|
|
||||||
import androidx.fragment.app.Fragment;
|
import androidx.fragment.app.Fragment;
|
||||||
import androidx.lifecycle.Observer;
|
|
||||||
import androidx.lifecycle.ViewModelProvider;
|
import androidx.lifecycle.ViewModelProvider;
|
||||||
import androidx.recyclerview.widget.DividerItemDecoration;
|
import androidx.recyclerview.widget.DividerItemDecoration;
|
||||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||||
@ -22,9 +20,7 @@ import org.mian.gitnex.R;
|
|||||||
import org.mian.gitnex.adapters.LabelsAdapter;
|
import org.mian.gitnex.adapters.LabelsAdapter;
|
||||||
import org.mian.gitnex.helpers.Authorization;
|
import org.mian.gitnex.helpers.Authorization;
|
||||||
import org.mian.gitnex.helpers.TinyDB;
|
import org.mian.gitnex.helpers.TinyDB;
|
||||||
import org.mian.gitnex.models.Labels;
|
|
||||||
import org.mian.gitnex.viewmodels.LabelsViewModel;
|
import org.mian.gitnex.viewmodels.LabelsViewModel;
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Author M M Arif
|
* Author M M Arif
|
||||||
@ -38,6 +34,7 @@ public class LabelsFragment extends Fragment {
|
|||||||
private TextView noData;
|
private TextView noData;
|
||||||
private static String repoNameF = "param2";
|
private static String repoNameF = "param2";
|
||||||
private static String repoOwnerF = "param1";
|
private static String repoOwnerF = "param1";
|
||||||
|
private final String type = "repo";
|
||||||
|
|
||||||
private String repoName;
|
private String repoName;
|
||||||
private String repoOwner;
|
private String repoOwner;
|
||||||
@ -48,6 +45,7 @@ public class LabelsFragment extends Fragment {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static LabelsFragment newInstance(String param1, String param2) {
|
public static LabelsFragment newInstance(String param1, String param2) {
|
||||||
|
|
||||||
LabelsFragment fragment = new LabelsFragment();
|
LabelsFragment fragment = new LabelsFragment();
|
||||||
Bundle args = new Bundle();
|
Bundle args = new Bundle();
|
||||||
args.putString(repoOwnerF, param1);
|
args.putString(repoOwnerF, param1);
|
||||||
@ -58,8 +56,11 @@ public class LabelsFragment extends Fragment {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreate(Bundle savedInstanceState) {
|
public void onCreate(Bundle savedInstanceState) {
|
||||||
|
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
|
|
||||||
if (getArguments() != null) {
|
if (getArguments() != null) {
|
||||||
|
|
||||||
repoName = getArguments().getString(repoNameF);
|
repoName = getArguments().getString(repoNameF);
|
||||||
repoOwner = getArguments().getString(repoOwnerF);
|
repoOwner = getArguments().getString(repoOwnerF);
|
||||||
}
|
}
|
||||||
@ -88,17 +89,16 @@ public class LabelsFragment extends Fragment {
|
|||||||
|
|
||||||
swipeRefresh.setRefreshing(false);
|
swipeRefresh.setRefreshing(false);
|
||||||
LabelsViewModel.loadLabelsList(Authorization.get(getContext()), repoOwner, repoName, getContext());
|
LabelsViewModel.loadLabelsList(Authorization.get(getContext()), repoOwner, repoName, getContext());
|
||||||
|
|
||||||
}, 200));
|
}, 200));
|
||||||
|
|
||||||
fetchDataAsync(Authorization.get(getContext()), repoOwner, repoName);
|
fetchDataAsync(Authorization.get(getContext()), repoOwner, repoName);
|
||||||
|
|
||||||
return v;
|
return v;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onResume() {
|
public void onResume() {
|
||||||
|
|
||||||
super.onResume();
|
super.onResume();
|
||||||
final TinyDB tinyDb = TinyDB.getInstance(getContext());
|
final TinyDB tinyDb = TinyDB.getInstance(getContext());
|
||||||
|
|
||||||
@ -108,24 +108,29 @@ public class LabelsFragment extends Fragment {
|
|||||||
final String repoName = parts[1];
|
final String repoName = parts[1];
|
||||||
|
|
||||||
if(tinyDb.getBoolean("labelsRefresh")) {
|
if(tinyDb.getBoolean("labelsRefresh")) {
|
||||||
|
|
||||||
LabelsViewModel.loadLabelsList(Authorization.get(getContext()), repoOwner, repoName, getContext());
|
LabelsViewModel.loadLabelsList(Authorization.get(getContext()), repoOwner, repoName, getContext());
|
||||||
tinyDb.putBoolean("labelsRefresh", false);
|
tinyDb.putBoolean("labelsRefresh", false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onButtonPressed(Uri uri) {
|
public void onButtonPressed(Uri uri) {
|
||||||
|
|
||||||
if (mListener != null) {
|
if (mListener != null) {
|
||||||
|
|
||||||
mListener.onFragmentInteraction(uri);
|
mListener.onFragmentInteraction(uri);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onDetach() {
|
public void onDetach() {
|
||||||
|
|
||||||
super.onDetach();
|
super.onDetach();
|
||||||
mListener = null;
|
mListener = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public interface OnFragmentInteractionListener {
|
public interface OnFragmentInteractionListener {
|
||||||
|
|
||||||
void onFragmentInteraction(Uri uri);
|
void onFragmentInteraction(Uri uri);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -133,21 +138,23 @@ public class LabelsFragment extends Fragment {
|
|||||||
|
|
||||||
LabelsViewModel labelsModel = new ViewModelProvider(this).get(LabelsViewModel.class);
|
LabelsViewModel labelsModel = new ViewModelProvider(this).get(LabelsViewModel.class);
|
||||||
|
|
||||||
labelsModel.getLabelsList(instanceToken, owner, repo, getContext()).observe(getViewLifecycleOwner(), new Observer<List<Labels>>() {
|
labelsModel.getLabelsList(instanceToken, owner, repo, getContext()).observe(getViewLifecycleOwner(), labelsListMain -> {
|
||||||
@Override
|
|
||||||
public void onChanged(@Nullable List<Labels> labelsListMain) {
|
adapter = new LabelsAdapter(getContext(), labelsListMain, type, owner);
|
||||||
adapter = new LabelsAdapter(getContext(), labelsListMain);
|
|
||||||
if(adapter.getItemCount() > 0) {
|
if(adapter.getItemCount() > 0) {
|
||||||
|
|
||||||
mRecyclerView.setAdapter(adapter);
|
mRecyclerView.setAdapter(adapter);
|
||||||
noData.setVisibility(View.GONE);
|
noData.setVisibility(View.GONE);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|
||||||
adapter.notifyDataSetChanged();
|
adapter.notifyDataSetChanged();
|
||||||
mRecyclerView.setAdapter(adapter);
|
mRecyclerView.setAdapter(adapter);
|
||||||
noData.setVisibility(View.VISIBLE);
|
noData.setVisibility(View.VISIBLE);
|
||||||
}
|
}
|
||||||
|
|
||||||
mProgressBar.setVisibility(View.GONE);
|
mProgressBar.setVisibility(View.GONE);
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,151 @@
|
|||||||
|
package org.mian.gitnex.fragments;
|
||||||
|
|
||||||
|
import android.net.Uri;
|
||||||
|
import android.os.Bundle;
|
||||||
|
import android.os.Handler;
|
||||||
|
import android.os.Looper;
|
||||||
|
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.fragment.app.Fragment;
|
||||||
|
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.LabelsAdapter;
|
||||||
|
import org.mian.gitnex.helpers.Authorization;
|
||||||
|
import org.mian.gitnex.helpers.TinyDB;
|
||||||
|
import org.mian.gitnex.viewmodels.OrganizationLabelsViewModel;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Author M M Arif
|
||||||
|
*/
|
||||||
|
|
||||||
|
public class OrganizationLabelsFragment extends Fragment {
|
||||||
|
|
||||||
|
private ProgressBar mProgressBar;
|
||||||
|
private RecyclerView mRecyclerView;
|
||||||
|
private LabelsAdapter adapter;
|
||||||
|
private TextView noData;
|
||||||
|
private static final String repoOwnerF = "param1";
|
||||||
|
private final String type = "org";
|
||||||
|
|
||||||
|
private String repoOwner;
|
||||||
|
|
||||||
|
private OnFragmentInteractionListener mListener;
|
||||||
|
|
||||||
|
public static OrganizationLabelsFragment newInstance(String param1) {
|
||||||
|
|
||||||
|
OrganizationLabelsFragment fragment = new OrganizationLabelsFragment();
|
||||||
|
Bundle args = new Bundle();
|
||||||
|
args.putString(repoOwnerF, param1);
|
||||||
|
fragment.setArguments(args);
|
||||||
|
return fragment;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onCreate(Bundle savedInstanceState) {
|
||||||
|
|
||||||
|
super.onCreate(savedInstanceState);
|
||||||
|
|
||||||
|
if (getArguments() != null) {
|
||||||
|
|
||||||
|
repoOwner = getArguments().getString(repoOwnerF);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||||
|
|
||||||
|
final View v = inflater.inflate(R.layout.fragment_labels, container, false);
|
||||||
|
setHasOptionsMenu(true);
|
||||||
|
|
||||||
|
final SwipeRefreshLayout swipeRefresh = v.findViewById(R.id.pullToRefresh);
|
||||||
|
noData = v.findViewById(R.id.noData);
|
||||||
|
|
||||||
|
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 Handler(Looper.getMainLooper()).postDelayed(() -> {
|
||||||
|
|
||||||
|
swipeRefresh.setRefreshing(false);
|
||||||
|
OrganizationLabelsViewModel.loadOrgLabelsList(Authorization.get(getContext()), repoOwner, getContext(), mProgressBar, noData);
|
||||||
|
|
||||||
|
}, 200));
|
||||||
|
|
||||||
|
fetchDataAsync(Authorization.get(getContext()), repoOwner);
|
||||||
|
|
||||||
|
return v;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onResume() {
|
||||||
|
|
||||||
|
super.onResume();
|
||||||
|
final TinyDB tinyDb = TinyDB.getInstance(getContext());
|
||||||
|
|
||||||
|
if(tinyDb.getBoolean("labelsRefresh")) {
|
||||||
|
|
||||||
|
OrganizationLabelsViewModel.loadOrgLabelsList(Authorization.get(getContext()), repoOwner, getContext(), mProgressBar, noData);
|
||||||
|
tinyDb.putBoolean("labelsRefresh", false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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 instanceToken, String owner) {
|
||||||
|
|
||||||
|
OrganizationLabelsViewModel organizationLabelsViewModel = new ViewModelProvider(this).get(OrganizationLabelsViewModel.class);
|
||||||
|
|
||||||
|
organizationLabelsViewModel.getOrgLabelsList(instanceToken, owner, getContext(), mProgressBar, noData).observe(getViewLifecycleOwner(), labelsListMain -> {
|
||||||
|
|
||||||
|
adapter = new LabelsAdapter(getContext(), labelsListMain, type, owner);
|
||||||
|
|
||||||
|
if(adapter.getItemCount() > 0) {
|
||||||
|
|
||||||
|
mRecyclerView.setAdapter(adapter);
|
||||||
|
noData.setVisibility(View.GONE);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
|
||||||
|
adapter.notifyDataSetChanged();
|
||||||
|
mRecyclerView.setAdapter(adapter);
|
||||||
|
noData.setVisibility(View.VISIBLE);
|
||||||
|
}
|
||||||
|
|
||||||
|
mProgressBar.setVisibility(View.GONE);
|
||||||
|
});
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
@ -62,7 +62,7 @@ public class AlertDialogs {
|
|||||||
alertDialogBuilder.create().show();
|
alertDialogBuilder.create().show();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void labelDeleteDialog(final Context context, final String labelTitle, final String labelId, String title, String message, String positiveButton, String negativeButton) {
|
public static void labelDeleteDialog(final Context context, final String labelTitle, final String labelId, String title, String message, String positiveButton, String negativeButton, String type, String orgName) {
|
||||||
|
|
||||||
new AlertDialog.Builder(context)
|
new AlertDialog.Builder(context)
|
||||||
.setTitle(title + labelTitle)
|
.setTitle(title + labelTitle)
|
||||||
@ -73,6 +73,8 @@ public class AlertDialogs {
|
|||||||
Intent intent = new Intent(context, CreateLabelActivity.class);
|
Intent intent = new Intent(context, CreateLabelActivity.class);
|
||||||
intent.putExtra("labelId", labelId);
|
intent.putExtra("labelId", labelId);
|
||||||
intent.putExtra("labelAction", "delete");
|
intent.putExtra("labelAction", "delete");
|
||||||
|
intent.putExtra("type", type);
|
||||||
|
intent.putExtra("orgName", orgName);
|
||||||
context.startActivity(intent);
|
context.startActivity(intent);
|
||||||
|
|
||||||
})
|
})
|
||||||
|
@ -229,6 +229,15 @@ public interface ApiInterface {
|
|||||||
@GET("orgs/{owner}/labels") // get org labels list
|
@GET("orgs/{owner}/labels") // get org labels list
|
||||||
Call<List<Labels>> getOrganizationLabels(@Header("Authorization") String token, @Path("owner") String ownerName);
|
Call<List<Labels>> getOrganizationLabels(@Header("Authorization") String token, @Path("owner") String ownerName);
|
||||||
|
|
||||||
|
@POST("orgs/{owner}/labels") // create org label
|
||||||
|
Call<CreateLabel> createOrganizationLabel(@Header("Authorization") String token, @Path("owner") String ownerName, @Body CreateLabel jsonStr);
|
||||||
|
|
||||||
|
@PATCH("orgs/{owner}/labels/{id}") // update / patch org label
|
||||||
|
Call<CreateLabel> patchOrganizationLabel(@Header("Authorization") String token, @Path("owner") String ownerName, @Path("id") int labelID, @Body CreateLabel jsonStr);
|
||||||
|
|
||||||
|
@DELETE("orgs/{owner}/labels/{id}") // delete org label
|
||||||
|
Call<Labels> deleteOrganizationLabel(@Header("Authorization") String token, @Path("owner") String ownerName, @Path("id") int labelID);
|
||||||
|
|
||||||
@GET("users/{username}/repos") // get current logged in user repositories
|
@GET("users/{username}/repos") // get current logged in user repositories
|
||||||
Call<List<UserRepositories>> getCurrentUserRepositories(@Header("Authorization") String token, @Path("username") String username, @Query("page") int page, @Query("limit") int limit);
|
Call<List<UserRepositories>> getCurrentUserRepositories(@Header("Authorization") String token, @Path("username") String username, @Query("page") int page, @Query("limit") int limit);
|
||||||
|
|
||||||
|
@ -0,0 +1,67 @@
|
|||||||
|
package org.mian.gitnex.viewmodels;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.util.Log;
|
||||||
|
import android.view.View;
|
||||||
|
import android.widget.ProgressBar;
|
||||||
|
import android.widget.TextView;
|
||||||
|
import androidx.annotation.NonNull;
|
||||||
|
import androidx.lifecycle.LiveData;
|
||||||
|
import androidx.lifecycle.MutableLiveData;
|
||||||
|
import androidx.lifecycle.ViewModel;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.mian.gitnex.clients.RetrofitClient;
|
||||||
|
import org.mian.gitnex.models.Labels;
|
||||||
|
import java.util.List;
|
||||||
|
import retrofit2.Call;
|
||||||
|
import retrofit2.Callback;
|
||||||
|
import retrofit2.Response;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Author M M Arif
|
||||||
|
*/
|
||||||
|
|
||||||
|
public class OrganizationLabelsViewModel extends ViewModel {
|
||||||
|
|
||||||
|
private static MutableLiveData<List<Labels>> orgLabelsList;
|
||||||
|
|
||||||
|
public LiveData<List<Labels>> getOrgLabelsList(String token, String owner, Context ctx, ProgressBar progressBar, TextView noData) {
|
||||||
|
|
||||||
|
orgLabelsList = new MutableLiveData<>();
|
||||||
|
loadOrgLabelsList(token, owner, ctx, progressBar = null, noData = null);
|
||||||
|
|
||||||
|
return orgLabelsList;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void loadOrgLabelsList(String token, String owner, Context ctx, ProgressBar progressBar, TextView noData) {
|
||||||
|
|
||||||
|
Call<List<Labels>> call = RetrofitClient
|
||||||
|
.getApiInterface(ctx)
|
||||||
|
.getOrganizationLabels(token, owner);
|
||||||
|
|
||||||
|
call.enqueue(new Callback<List<Labels>>() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onResponse(@NonNull Call<List<Labels>> call, @NonNull Response<List<Labels>> response) {
|
||||||
|
|
||||||
|
if(response.isSuccessful()) {
|
||||||
|
|
||||||
|
orgLabelsList.postValue(response.body());
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
|
||||||
|
progressBar.setVisibility(View.GONE);
|
||||||
|
noData.setVisibility(View.VISIBLE);
|
||||||
|
Log.i("onResponse-org-labels", String.valueOf(response.code()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onFailure(@NonNull Call<List<Labels>> call, @NotNull Throwable t) {
|
||||||
|
Log.i("onFailure", t.toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
@ -56,6 +56,12 @@
|
|||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:text="@string/orgTabRepos" />
|
android:text="@string/orgTabRepos" />
|
||||||
|
|
||||||
|
<com.google.android.material.tabs.TabItem
|
||||||
|
android:id="@+id/tabItem_labels"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="@string/tab_text_labels" />
|
||||||
|
|
||||||
<com.google.android.material.tabs.TabItem
|
<com.google.android.material.tabs.TabItem
|
||||||
android:id="@+id/tabItem_teams"
|
android:id="@+id/tabItem_teams"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
|
@ -30,6 +30,18 @@
|
|||||||
android:padding="12dp"
|
android:padding="12dp"
|
||||||
app:drawableStartCompat="@drawable/ic_repo" />
|
app:drawableStartCompat="@drawable/ic_repo" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/createLabel"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_gravity="center_vertical"
|
||||||
|
android:text="@string/createLabel"
|
||||||
|
android:drawablePadding="24dp"
|
||||||
|
android:textColor="?attr/primaryTextColor"
|
||||||
|
android:textSize="16sp"
|
||||||
|
android:padding="12dp"
|
||||||
|
app:drawableStartCompat="@drawable/ic_label" />
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/createTeam"
|
android:id="@+id/createTeam"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
|
Loading…
Reference in New Issue
Block a user