diff --git a/app/build.gradle b/app/build.gradle index b1057225..f94ac7cf 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -49,17 +49,17 @@ dependencies { implementation 'androidx.core:core-ktx:1.7.0' kapt 'org.androidannotations:androidannotations:4.7.0' implementation 'org.androidannotations:androidannotations-api:4.7.0' - implementation 'androidx.appcompat:appcompat:1.4.0' + implementation 'androidx.appcompat:appcompat:1.4.1' kapt 'androidx.annotation:annotation:1.3.0' implementation 'androidx.annotation:annotation:1.3.0' implementation 'androidx.recyclerview:recyclerview:1.2.1' - implementation 'com.google.android.material:material:1.4.0' + implementation 'com.google.android.material:material:1.5.0' implementation 'com.greysonparrelli.permiso:permiso:0.3.0' implementation 'com.microsoft.appcenter:appcenter-analytics:4.1.0' implementation 'com.microsoft.appcenter:appcenter-crashes:4.1.0' implementation 'com.jaeger.statusbarutil:library:1.5.1' implementation 'com.orhanobut:logger:1.15' - implementation 'com.google.code.gson:gson:2.8.6' + implementation 'com.google.code.gson:gson:2.8.7' implementation 'com.squareup.retrofit2:retrofit:2.9.0' implementation 'com.squareup.retrofit2:converter-gson:2.9.0' implementation 'com.squareup.retrofit2:adapter-rxjava3:2.9.0' diff --git a/app/src/main/java/com/tomclaw/appsend/core/StoreService.java b/app/src/main/java/com/tomclaw/appsend/core/StoreService.java index 9ba7336f..f2b5ce1e 100644 --- a/app/src/main/java/com/tomclaw/appsend/core/StoreService.java +++ b/app/src/main/java/com/tomclaw/appsend/core/StoreService.java @@ -6,11 +6,12 @@ import com.tomclaw.appsend.main.dto.ApiResponse; import com.tomclaw.appsend.main.dto.StoreInfo; import com.tomclaw.appsend.main.meta.MetaResponse; +import com.tomclaw.appsend.main.profile.EliminateUserResponse; import com.tomclaw.appsend.main.profile.EmpowerResponse; import com.tomclaw.appsend.main.profile.ProfileResponse; import com.tomclaw.appsend.main.profile.list.ListResponse; -import com.tomclaw.appsend.main.ratings.VoidResponse; import com.tomclaw.appsend.main.ratings.RatingsResponse; +import com.tomclaw.appsend.main.ratings.VoidResponse; import com.tomclaw.appsend.main.unlink.UnlinkResponse; import com.tomclaw.appsend.main.unpublish.UnpublishResponse; import com.tomclaw.appsend.net.CheckUpdatesRequest; @@ -179,4 +180,10 @@ Call> deleteApp( @Query("app_id") String appId ); + @DELETE("api/1/user/eliminate") + Call> eliminateUser( + @Query("guid") String guid, + @Query("user_id") Long userId + ); + } diff --git a/app/src/main/java/com/tomclaw/appsend/main/profile/EliminateUserResponse.java b/app/src/main/java/com/tomclaw/appsend/main/profile/EliminateUserResponse.java new file mode 100644 index 00000000..b3f646be --- /dev/null +++ b/app/src/main/java/com/tomclaw/appsend/main/profile/EliminateUserResponse.java @@ -0,0 +1,59 @@ +package com.tomclaw.appsend.main.profile; + +import android.os.Parcel; +import android.os.Parcelable; + +import com.google.gson.annotations.SerializedName; +import com.tomclaw.appsend.util.Unobfuscatable; + +public class EliminateUserResponse implements Parcelable, Unobfuscatable { + + @SerializedName("files_count") + private int filesCount; + @SerializedName("msgs_count") + private int msgsCount; + @SerializedName("ratings_count") + private int ratingsCount; + + protected EliminateUserResponse(Parcel in) { + filesCount = in.readInt(); + msgsCount = in.readInt(); + ratingsCount = in.readInt(); + } + + public int getFilesCount() { + return filesCount; + } + + public int getMessagesCount() { + return msgsCount; + } + + public int getRatingsCount() { + return ratingsCount; + } + + @Override + public void writeToParcel(Parcel dest, int flags) { + dest.writeInt(filesCount); + dest.writeInt(msgsCount); + dest.writeInt(ratingsCount); + } + + @Override + public int describeContents() { + return 0; + } + + public static final Creator CREATOR = new Creator() { + @Override + public EliminateUserResponse createFromParcel(Parcel in) { + return new EliminateUserResponse(in); + } + + @Override + public EliminateUserResponse[] newArray(int size) { + return new EliminateUserResponse[size]; + } + }; +} diff --git a/app/src/main/java/com/tomclaw/appsend/main/profile/ProfileActivity.java b/app/src/main/java/com/tomclaw/appsend/main/profile/ProfileActivity.java index aefea785..a3a69ae6 100644 --- a/app/src/main/java/com/tomclaw/appsend/main/profile/ProfileActivity.java +++ b/app/src/main/java/com/tomclaw/appsend/main/profile/ProfileActivity.java @@ -1,7 +1,6 @@ package com.tomclaw.appsend.main.profile; import static com.microsoft.appcenter.analytics.Analytics.trackEvent; -import static com.tomclaw.appsend.util.IntentHelper.formatText; import static com.tomclaw.appsend.util.IntentHelper.shareUrl; import android.annotation.SuppressLint; @@ -10,29 +9,36 @@ import android.os.Bundle; import android.view.Menu; import android.view.MenuItem; +import android.widget.Toast; import androidx.annotation.Nullable; import androidx.appcompat.app.ActionBar; +import androidx.appcompat.app.AlertDialog; import androidx.appcompat.app.AppCompatActivity; import androidx.appcompat.widget.Toolbar; import com.tomclaw.appsend.R; -import com.tomclaw.appsend.main.download.DownloadActivity; +import com.tomclaw.appsend.core.MainExecutor; +import com.tomclaw.appsend.core.StoreServiceHolder; +import com.tomclaw.appsend.main.dto.ApiResponse; import com.tomclaw.appsend.main.home.HomeActivity; -import com.tomclaw.appsend.util.LocaleHelper; +import com.tomclaw.appsend.net.Session; import com.tomclaw.appsend.util.ThemeHelper; import org.androidannotations.annotations.AfterViews; +import org.androidannotations.annotations.Bean; import org.androidannotations.annotations.EActivity; import org.androidannotations.annotations.Extra; import org.androidannotations.annotations.FragmentById; import org.androidannotations.annotations.InstanceState; -import org.androidannotations.annotations.OptionsItem; -import org.androidannotations.annotations.OptionsMenu; import org.androidannotations.annotations.ViewById; import java.util.List; +import retrofit2.Call; +import retrofit2.Callback; +import retrofit2.Response; + /** * Created by solkin on 16/03/2018. */ @@ -52,6 +58,12 @@ public class ProfileActivity extends AppCompatActivity { @InstanceState Boolean isShowHomeOnFinish; + @Bean + StoreServiceHolder serviceHolder; + + @Bean + Session session; + @Override protected void onCreate(@Nullable Bundle savedInstanceState) { ThemeHelper.updateTheme(this); @@ -94,6 +106,9 @@ void init() { public boolean onCreateOptionsMenu(Menu menu) { if (profileFragment.profile != null) { getMenuInflater().inflate(R.menu.profile_menu, menu); + if (session.getUserData().getRole() != 300) { + menu.removeItem(R.id.eliminate); + } } return true; } @@ -109,6 +124,41 @@ public boolean onOptionsItemSelected(MenuItem item) { shareUrl(ProfileActivity.this, text); trackEvent("share-user-url"); break; + case R.id.eliminate: + new AlertDialog.Builder(this) + .setTitle(getString(R.string.eliminate_user_title)) + .setMessage(getString(R.string.eliminate_user_message)) + .setNegativeButton(R.string.yes, (dialog, which) -> { + profileFragment.showProgress(); + String guid = Session.getInstance().getUserData().getGuid(); + Call> call = serviceHolder.getService().eliminateUser(guid, userId); + call.enqueue(new Callback>() { + @Override + public void onResponse(Call> call, final Response> response) { + MainExecutor.execute(() -> { + EliminateUserResponse result = response.body().getResult(); + if (response.isSuccessful() && result != null) { + String message = getString(R.string.eliminate_user_success, result.getFilesCount(), result.getMessagesCount(), result.getRatingsCount()); + Toast.makeText(ProfileActivity.this, message, Toast.LENGTH_LONG).show(); + finish(); + } else { + Toast.makeText(ProfileActivity.this, R.string.eliminate_user_failed, Toast.LENGTH_LONG).show(); + profileFragment.showContent(); + } + }); + } + + @Override + public void onFailure(Call> call, Throwable t) { + MainExecutor.execute(() -> Toast.makeText(ProfileActivity.this, R.string.eliminate_user_failed, Toast.LENGTH_LONG).show()); + profileFragment.showContent(); + } + }); + }) + .setPositiveButton(R.string.no, null) + .show(); + trackEvent("fire-user"); + break; } return true; } diff --git a/app/src/main/java/com/tomclaw/appsend/main/profile/ProfileFragment.java b/app/src/main/java/com/tomclaw/appsend/main/profile/ProfileFragment.java index 188c4e56..06e1472d 100644 --- a/app/src/main/java/com/tomclaw/appsend/main/profile/ProfileFragment.java +++ b/app/src/main/java/com/tomclaw/appsend/main/profile/ProfileFragment.java @@ -491,11 +491,11 @@ private void showError() { swipeRefresh.setRefreshing(false); } - private void showProgress() { + public void showProgress() { viewFlipper.setDisplayedChild(0); } - private void showContent() { + public void showContent() { viewFlipper.setDisplayedChild(1); } diff --git a/app/src/main/res/menu/profile_menu.xml b/app/src/main/res/menu/profile_menu.xml index d3384d7d..919a3798 100644 --- a/app/src/main/res/menu/profile_menu.xml +++ b/app/src/main/res/menu/profile_menu.xml @@ -6,4 +6,9 @@ android:icon="@drawable/ic_share_variant" android:title="@string/share_url" app:showAsAction="ifRoom|withText" /> + \ No newline at end of file diff --git a/app/src/main/res/values-ru/strings.xml b/app/src/main/res/values-ru/strings.xml index f3483262..de656d9b 100644 --- a/app/src/main/res/values-ru/strings.xml +++ b/app/src/main/res/values-ru/strings.xml @@ -297,4 +297,9 @@ Удалить из обменника Приложение было успешно удалено Произошла ошибка при удалении приложения + Уничтожить + Уничтожить пользователя + Вы уверены, что хотите уничтожить пользователя? + Пользователь успешно уничтожен\n%d files\n%d messages\n%d ratings + Не удалось уничтожить пользователя diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 66f197a2..99909103 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -304,4 +304,9 @@ Delete from store App was successfully deleted An error occurred while deleting the application + Eliminate + Eliminate user + Are you sure want to eliminate user? + User is eliminated:\n%d files\n%d messages\n%d ratings + Failed to eliminate user