Edit user profile

This commit is contained in:
M M Arif 2024-03-28 16:08:36 +05:00
parent b3a0f97ff4
commit 2db6e9310a
12 changed files with 320 additions and 16 deletions

View File

@ -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")
}
}

View File

@ -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<?, String> 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;
}

View File

@ -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<UserSettings> saveUserSettings =
RetrofitClient.getApiInterface(context).customUpdateUserSettings(userSettings);
saveUserSettings.enqueue(
new Callback<>() {
@Override
public void onResponse(
@NonNull Call<UserSettings> call,
@NonNull retrofit2.Response<UserSettings> 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<UserSettings> call, @NonNull Throwable t) {
Toasty.error(context, getString(R.string.genericServerResponseError));
}
});
}
public void getUserProfileSettings() {
Call<UserSettings> call1 = RetrofitClient.getApiInterface(context).customGetUserSettings();
call1.enqueue(
new Callback<>() {
@Override
public void onResponse(
@NonNull Call<UserSettings> call,
@NonNull retrofit2.Response<UserSettings> 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<UserSettings> call, @NonNull Throwable t) {
Toasty.error(
context, context.getResources().getString(R.string.genericError));
}
});
}
public void getProfileDetail(String username) {
Call<User> 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)));

View File

@ -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();
}

View File

@ -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"

View File

@ -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"

View File

@ -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"

View File

@ -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"

View File

@ -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"

View File

@ -0,0 +1,149 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="@dimen/dimen8dp">
<androidx.core.widget.NestedScrollView
android:id="@+id/mainView"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="@dimen/dimen16dp"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/fullnameLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:hint="@string/userFullNameText"
android:textColorHint="?attr/hintColor"
app:boxBackgroundColor="?attr/inputBackgroundColor"
app:boxStrokeErrorColor="@color/darkRed"
app:hintTextColor="?attr/hintColor">
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/fullname"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="?attr/inputTextColor"
android:textColorHighlight="?attr/hintColor"
android:textColorHint="?attr/hintColor"
android:textSize="16sp" />
</com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/descriptionLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:layout_marginBottom="8dp"
android:hint="@string/description"
android:textColorHint="?attr/hintColor"
app:boxBackgroundColor="?attr/inputBackgroundColor"
app:boxStrokeErrorColor="@color/darkRed"
app:hintTextColor="?attr/hintColor">
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/description"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="top|start"
android:minHeight="@dimen/dimen80dp"
android:singleLine="false"
android:textColor="?attr/inputTextColor"
android:textColorHighlight="?attr/hintColor"
android:textColorHint="?attr/hintColor"
android:textSize="16sp" />
</com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/locationLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:hint="@string/locationText"
android:textColorHint="?attr/hintColor"
app:boxBackgroundColor="?attr/inputBackgroundColor"
app:boxStrokeErrorColor="@color/darkRed"
app:hintTextColor="?attr/hintColor">
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/location"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="?attr/inputTextColor"
android:textColorHighlight="?attr/hintColor"
android:textColorHint="?attr/hintColor"
android:textSize="16sp" />
</com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/websiteLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:hint="@string/websiteText"
android:textColorHint="?attr/hintColor"
app:boxBackgroundColor="?attr/inputBackgroundColor"
app:boxStrokeErrorColor="@color/darkRed"
app:hintTextColor="?attr/hintColor">
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/website"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="?attr/inputTextColor"
android:textColorHighlight="?attr/hintColor"
android:textColorHint="?attr/hintColor"
android:textSize="16sp" />
</com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.materialswitch.MaterialSwitch
android:id="@+id/hideEmail"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:checked="true"
android:text="@string/hideEmail"
android:textColor="?attr/primaryTextColor" />
<com.google.android.material.materialswitch.MaterialSwitch
android:id="@+id/hideActivity"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:checked="true"
android:text="@string/hideActivity"
android:textColor="?attr/primaryTextColor" />
</LinearLayout>
<com.google.android.material.button.MaterialButton
android:id="@+id/save"
android:layout_width="match_parent"
android:layout_height="@dimen/dimen54dp"
android:layout_marginTop="@dimen/dimen16dp"
android:text="@string/saveButton"
android:textColor="?attr/materialCardBackgroundColor"
android:textSize="16sp"
android:textStyle="bold" />
</LinearLayout>
</androidx.core.widget.NestedScrollView>
</LinearLayout>

View File

@ -91,6 +91,18 @@
android:textIsSelectable="true"
android:textSize="@dimen/dimen14sp" />
<com.google.android.material.button.MaterialButton
android:id="@+id/editProfile"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/editSettings"
android:textColor="?attr/materialCardBackgroundColor"
android:backgroundTint="?attr/fabColor"
app:iconTint="?attr/materialCardBackgroundColor"
app:icon="@drawable/ic_edit"
android:textSize="14sp"
android:visibility="gone" />
</LinearLayout>
</LinearLayout>

View File

@ -176,7 +176,6 @@
<string name="noReleaseBodyContent">Release notes are not provided by the publisher.</string>
<string name="newMilestoneTitle">Title</string>
<string name="newMilestoneDescription">Description</string>
<string name="newMilestoneDueDate">Due Date</string>
<string name="setDueDate" translatable="false">%1$d-%2$d-%3$d</string>
<string name="milestoneNameErrorEmpty">Milestone title is empty</string>
@ -193,7 +192,6 @@
<string name="newIssueSelectLabelsListTitle">Select Labels</string>
<string name="newIssueTitle">Title</string>
<string name="newIssueAssigneesListTitle">Assignees</string>
<string name="newIssueDescriptionTitle">Description</string>
<string name="newIssueDueDateTitle">Due Date</string>
<string name="newIssueMilestoneTitle">Milestone</string>
<string name="newIssueLabelsTitle">Labels</string>
@ -323,7 +321,6 @@
<!-- create team -->
<string name="newTeamTitle">Team Name</string>
<string name="newTeamDesc">Description</string>
<string name="newTeamPermission">Permission</string>
<string name="newTeamAccessControls">Access Controls</string>
<string name="newTeamPermissionRead">Members can view and clone team repositories</string>
@ -360,6 +357,9 @@
<string name="profileTabFollowers">Followers</string>
<string name="profileTabFollowing">Following</string>
<string name="usernameWithAt" translatable="false">\u0040%1$s</string>
<string name="editSettings">Edit Profile</string>
<string name="hideActivity">Hide Activity from profile page</string>
<string name="hideEmail">Hide Email</string>
<!-- profile section -->
<!-- account settings -->
@ -548,6 +548,7 @@
<string name="main">main</string>
<string name="license">License</string>
<string name="title">Title</string>
<string name="description">Description</string>
<!-- generic copy -->
<string name="exploreUsers">Explore users</string>