diff --git a/app/build.gradle b/app/build.gradle index 1b026151..0f5f6358 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -110,14 +110,14 @@ dependencies { implementation 'com.github.chrisvest:stormpot:2.4.2' implementation 'androidx.browser:browser:1.8.0' implementation 'com.google.android.flexbox:flexbox:3.0.0' - implementation('org.codeberg.gitnex:tea4j-autodeploy:3f8f9fce13') { + implementation('org.codeberg.gitnex:tea4j-autodeploy:5f0dc819a3') { exclude module: 'org.apache.oltu.oauth2.common' } implementation 'io.github.amrdeveloper:codeview:1.3.9' constraints { - implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.8.0") - implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.8.0") + it.implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.8.0") + it.implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.8.0") } } diff --git a/app/src/main/java/org/mian/gitnex/clients/RetrofitClient.java b/app/src/main/java/org/mian/gitnex/clients/RetrofitClient.java index d8050f79..2e5ed433 100644 --- a/app/src/main/java/org/mian/gitnex/clients/RetrofitClient.java +++ b/app/src/main/java/org/mian/gitnex/clients/RetrofitClient.java @@ -2,6 +2,7 @@ package org.mian.gitnex.clients; import android.content.Context; import android.util.Log; +import androidx.annotation.NonNull; import com.google.gson.GsonBuilder; import java.io.File; import java.lang.annotation.Annotation; @@ -230,7 +231,9 @@ public class RetrofitClient { @Override public Converter stringConverter( - @NotNull Type type, @NotNull Annotation[] annotations, @NotNull Retrofit retrofit) { + @NotNull Type type, + @NonNull @NotNull Annotation[] annotations, + @NotNull Retrofit retrofit) { if (type == Date.class) { return DateQueryConverter.INSTANCE; } diff --git a/app/src/main/java/org/mian/gitnex/fragments/profile/DetailFragment.java b/app/src/main/java/org/mian/gitnex/fragments/profile/DetailFragment.java index 5f564573..e9d0c7b3 100644 --- a/app/src/main/java/org/mian/gitnex/fragments/profile/DetailFragment.java +++ b/app/src/main/java/org/mian/gitnex/fragments/profile/DetailFragment.java @@ -6,16 +6,22 @@ import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import androidx.annotation.NonNull; +import androidx.appcompat.app.AlertDialog; import androidx.fragment.app.Fragment; +import com.google.android.material.dialog.MaterialAlertDialogBuilder; import java.io.IOException; import java.util.Locale; import okhttp3.ResponseBody; import org.gitnex.tea4j.v2.models.Repository; import org.gitnex.tea4j.v2.models.User; +import org.gitnex.tea4j.v2.models.UserSettings; +import org.gitnex.tea4j.v2.models.UserSettingsOptions; import org.mian.gitnex.R; +import org.mian.gitnex.activities.BaseActivity; import org.mian.gitnex.activities.ProfileActivity; import org.mian.gitnex.clients.PicassoService; import org.mian.gitnex.clients.RetrofitClient; +import org.mian.gitnex.databinding.CustomEditProfileBinding; import org.mian.gitnex.databinding.FragmentProfileDetailBinding; import org.mian.gitnex.helpers.AlertDialogs; import org.mian.gitnex.helpers.AppUtil; @@ -39,6 +45,9 @@ public class DetailFragment extends Fragment { private Context context; private FragmentProfileDetailBinding binding; private String username; + private CustomEditProfileBinding customEditProfileBinding; + private MaterialAlertDialogBuilder materialAlertDialogBuilder; + private AlertDialog dialogEditSettings; public DetailFragment() {} @@ -70,6 +79,10 @@ public class DetailFragment extends Fragment { getProfileDetail(username); getProfileRepository(username); + materialAlertDialogBuilder = + new MaterialAlertDialogBuilder( + context, R.style.ThemeOverlay_Material3_Dialog_Alert); + binding.userFollowersCount.setOnClickListener( metaFollowersFrame -> ((ProfileActivity) requireActivity()).viewPager.setCurrentItem(4)); @@ -80,9 +93,135 @@ public class DetailFragment extends Fragment { metaStarredReposFrame -> ((ProfileActivity) requireActivity()).viewPager.setCurrentItem(2)); + if (username.equals(((BaseActivity) context).getAccount().getAccount().getUserName())) { + binding.editProfile.setVisibility(View.VISIBLE); + } else { + binding.editProfile.setVisibility(View.GONE); + } + + binding.editProfile.setOnClickListener( + editProfileSettings -> { + customEditProfileBinding = + CustomEditProfileBinding.inflate(LayoutInflater.from(context)); + showEditProfileDialog(); + }); + return binding.getRoot(); } + private void showEditProfileDialog() { + + View view = customEditProfileBinding.getRoot(); + materialAlertDialogBuilder.setView(view); + + customEditProfileBinding.save.setOnClickListener( + saveKey -> + saveUserProfile( + String.valueOf(customEditProfileBinding.fullname.getText()), + String.valueOf(customEditProfileBinding.description.getText()), + String.valueOf(customEditProfileBinding.location.getText()), + String.valueOf(customEditProfileBinding.website.getText()), + customEditProfileBinding.hideEmail.isChecked(), + customEditProfileBinding.hideActivity.isChecked())); + + dialogEditSettings = materialAlertDialogBuilder.show(); + + getUserProfileSettings(); + } + + private void saveUserProfile( + String fullname, + String description, + String location, + String website, + boolean hideEmail, + boolean hideActivity) { + + UserSettingsOptions userSettings = new UserSettingsOptions(); + userSettings.setFullName(fullname); + userSettings.setDescription(description); + userSettings.setLocation(location); + userSettings.setWebsite(website); + userSettings.setHideEmail(hideEmail); + userSettings.setHideActivity(hideActivity); + + Call saveUserSettings = + RetrofitClient.getApiInterface(context).customUpdateUserSettings(userSettings); + + saveUserSettings.enqueue( + new Callback<>() { + + @Override + public void onResponse( + @NonNull Call call, + @NonNull retrofit2.Response response) { + + if (response.code() == 200) { + + dialogEditSettings.dismiss(); + getProfileDetail(username); + Toasty.success(context, getString(R.string.settingsSave)); + } else { + + Toasty.error(context, getString(R.string.genericError)); + } + } + + @Override + public void onFailure(@NonNull Call call, @NonNull Throwable t) { + + Toasty.error(context, getString(R.string.genericServerResponseError)); + } + }); + } + + public void getUserProfileSettings() { + + Call call1 = RetrofitClient.getApiInterface(context).customGetUserSettings(); + + call1.enqueue( + new Callback<>() { + + @Override + public void onResponse( + @NonNull Call call, + @NonNull retrofit2.Response response) { + + if (response.isSuccessful() && response.body() != null) { + if (response.code() == 200) { + + if (!response.body().getFullName().isEmpty()) { + customEditProfileBinding.fullname.setText( + response.body().getFullName()); + } + if (!response.body().getDescription().isEmpty()) { + customEditProfileBinding.fullname.setText( + response.body().getDescription()); + } + if (!response.body().getLocation().isEmpty()) { + customEditProfileBinding.fullname.setText( + response.body().getLocation()); + } + if (!response.body().getWebsite().isEmpty()) { + customEditProfileBinding.fullname.setText( + response.body().getWebsite()); + } + customEditProfileBinding.hideEmail.setChecked( + response.body().isHideEmail()); + customEditProfileBinding.hideActivity.setChecked( + response.body().isHideActivity()); + } + } + } + + @Override + public void onFailure(@NonNull Call call, @NonNull Throwable t) { + Toasty.error( + context, context.getResources().getString(R.string.genericError)); + } + }); + } + public void getProfileDetail(String username) { Call call = RetrofitClient.getApiInterface(context).userGet(username); @@ -117,19 +256,19 @@ public class DetailFragment extends Fragment { binding.userEmail.setText(email); binding.userFollowersCount.setText( - String.valueOf( + String.format( response.body().getFollowersCount() + " " + getString( R.string.profileTabFollowers))); binding.userFollowingCount.setText( - String.valueOf( + String.format( response.body().getFollowingCount() + " " + getString( R.string.profileTabFollowing))); binding.userStarredReposCount.setText( - String.valueOf( + String.format( response.body().getStarredReposCount() + " " + getString(R.string.starredRepos))); diff --git a/app/src/main/java/org/mian/gitnex/helpers/contexts/AccountContext.java b/app/src/main/java/org/mian/gitnex/helpers/contexts/AccountContext.java index f6da3b87..4e15f79f 100644 --- a/app/src/main/java/org/mian/gitnex/helpers/contexts/AccountContext.java +++ b/app/src/main/java/org/mian/gitnex/helpers/contexts/AccountContext.java @@ -74,7 +74,7 @@ public class AccountContext implements Serializable { public String getFullName() { return userInfo != null - ? !userInfo.getFullName().equals("") ? userInfo.getFullName() : userInfo.getLogin() + ? !userInfo.getFullName().isEmpty() ? userInfo.getFullName() : userInfo.getLogin() : account.getUserName(); } diff --git a/app/src/main/res/layout/activity_create_issue.xml b/app/src/main/res/layout/activity_create_issue.xml index 50e8b7b9..44473e5a 100644 --- a/app/src/main/res/layout/activity_create_issue.xml +++ b/app/src/main/res/layout/activity_create_issue.xml @@ -91,7 +91,7 @@ android:layout_height="wrap_content" android:layout_marginTop="@dimen/dimen8dp" android:layout_marginBottom="@dimen/dimen8dp" - android:hint="@string/newIssueDescriptionTitle" + android:hint="@string/description" android:textColorHint="?attr/hintColor" app:boxStrokeErrorColor="@color/darkRed" app:endIconMode="clear_text" diff --git a/app/src/main/res/layout/activity_create_milestone.xml b/app/src/main/res/layout/activity_create_milestone.xml index a5aab4c1..2b566f39 100644 --- a/app/src/main/res/layout/activity_create_milestone.xml +++ b/app/src/main/res/layout/activity_create_milestone.xml @@ -79,7 +79,7 @@ android:layout_height="wrap_content" android:layout_marginTop="@dimen/dimen8dp" android:layout_marginBottom="@dimen/dimen8dp" - android:hint="@string/newMilestoneDescription" + android:hint="@string/description" android:textColorHint="?attr/hintColor" app:boxStrokeErrorColor="@color/darkRed" app:counterEnabled="true" diff --git a/app/src/main/res/layout/activity_create_pr.xml b/app/src/main/res/layout/activity_create_pr.xml index 7980eea0..5c9627e4 100644 --- a/app/src/main/res/layout/activity_create_pr.xml +++ b/app/src/main/res/layout/activity_create_pr.xml @@ -91,7 +91,7 @@ android:layout_height="wrap_content" android:layout_marginTop="@dimen/dimen8dp" android:layout_marginBottom="@dimen/dimen8dp" - android:hint="@string/newIssueDescriptionTitle" + android:hint="@string/description" android:textColorHint="?attr/hintColor" app:boxStrokeErrorColor="@color/darkRed" app:endIconMode="clear_text" diff --git a/app/src/main/res/layout/activity_create_team_by_org.xml b/app/src/main/res/layout/activity_create_team_by_org.xml index f1d455d5..87c13ad7 100644 --- a/app/src/main/res/layout/activity_create_team_by_org.xml +++ b/app/src/main/res/layout/activity_create_team_by_org.xml @@ -79,7 +79,7 @@ android:layout_height="wrap_content" android:layout_marginTop="@dimen/dimen8dp" android:layout_marginBottom="@dimen/dimen8dp" - android:hint="@string/newTeamDesc" + android:hint="@string/description" android:textColorHint="?attr/hintColor" app:boxStrokeErrorColor="@color/darkRed" app:counterEnabled="true" diff --git a/app/src/main/res/layout/activity_edit_issue.xml b/app/src/main/res/layout/activity_edit_issue.xml index 96138291..1c7199e6 100644 --- a/app/src/main/res/layout/activity_edit_issue.xml +++ b/app/src/main/res/layout/activity_edit_issue.xml @@ -79,7 +79,7 @@ android:layout_height="wrap_content" android:layout_marginTop="@dimen/dimen8dp" android:layout_marginBottom="@dimen/dimen8dp" - android:hint="@string/newIssueDescriptionTitle" + android:hint="@string/description" android:textColorHint="?attr/hintColor" app:boxStrokeErrorColor="@color/darkRed" app:endIconMode="clear_text" diff --git a/app/src/main/res/layout/custom_edit_profile.xml b/app/src/main/res/layout/custom_edit_profile.xml new file mode 100644 index 00000000..ed5c4b7d --- /dev/null +++ b/app/src/main/res/layout/custom_edit_profile.xml @@ -0,0 +1,149 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/app/src/main/res/layout/fragment_profile_detail.xml b/app/src/main/res/layout/fragment_profile_detail.xml index ade31705..784a4a12 100644 --- a/app/src/main/res/layout/fragment_profile_detail.xml +++ b/app/src/main/res/layout/fragment_profile_detail.xml @@ -91,6 +91,18 @@ android:textIsSelectable="true" android:textSize="@dimen/dimen14sp" /> + + diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index afe2c66a..d3bb8e0d 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -176,7 +176,6 @@ Release notes are not provided by the publisher. Title - Description Due Date %1$d-%2$d-%3$d Milestone title is empty @@ -193,7 +192,6 @@ Select Labels Title Assignees - Description Due Date Milestone Labels @@ -323,7 +321,6 @@ Team Name - Description Permission Access Controls Members can view and clone team repositories @@ -360,6 +357,9 @@ Followers Following \u0040%1$s + Edit Profile + Hide Activity from profile page + Hide Email @@ -548,6 +548,7 @@ main License Title + Description Explore users