Skip to content

Commit

Permalink
Add user elimination API support
Browse files Browse the repository at this point in the history
  • Loading branch information
solkin committed Nov 12, 2021
1 parent fde790a commit e8c30e9
Show file tree
Hide file tree
Showing 8 changed files with 142 additions and 11 deletions.
6 changes: 3 additions & 3 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
9 changes: 8 additions & 1 deletion app/src/main/java/com/tomclaw/appsend/core/StoreService.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -179,4 +180,10 @@ Call<ApiResponse<VoidResponse>> deleteApp(
@Query("app_id") String appId
);

@DELETE("api/1/user/eliminate")
Call<ApiResponse<EliminateUserResponse>> eliminateUser(
@Query("guid") String guid,
@Query("user_id") Long userId
);

}
Original file line number Diff line number Diff line change
@@ -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<EliminateUserResponse> CREATOR = new Creator<EliminateUserResponse>() {
@Override
public EliminateUserResponse createFromParcel(Parcel in) {
return new EliminateUserResponse(in);
}

@Override
public EliminateUserResponse[] newArray(int size) {
return new EliminateUserResponse[size];
}
};
}
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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.
*/
Expand All @@ -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);
Expand Down Expand Up @@ -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;
}
Expand All @@ -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<ApiResponse<EliminateUserResponse>> call = serviceHolder.getService().eliminateUser(guid, userId);
call.enqueue(new Callback<ApiResponse<EliminateUserResponse>>() {
@Override
public void onResponse(Call<ApiResponse<EliminateUserResponse>> call, final Response<ApiResponse<EliminateUserResponse>> 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<ApiResponse<EliminateUserResponse>> 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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
5 changes: 5 additions & 0 deletions app/src/main/res/menu/profile_menu.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,9 @@
android:icon="@drawable/ic_share_variant"
android:title="@string/share_url"
app:showAsAction="ifRoom|withText" />
<item
android:id="@+id/eliminate"
android:icon="@drawable/ic_delete_forever"
android:title="@string/eliminate_user"
app:showAsAction="ifRoom|withText" />
</menu>
5 changes: 5 additions & 0 deletions app/src/main/res/values-ru/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -297,4 +297,9 @@
<string name="delete_from_store">Удалить из обменника</string>
<string name="app_deleted">Приложение было успешно удалено</string>
<string name="error_app_deleted">Произошла ошибка при удалении приложения</string>
<string name="eliminate_user">Уничтожить</string>
<string name="eliminate_user_title">Уничтожить пользователя</string>
<string name="eliminate_user_message">Вы уверены, что хотите уничтожить пользователя?</string>
<string name="eliminate_user_success">Пользователь успешно уничтожен\n%d files\n%d messages\n%d ratings</string>
<string name="eliminate_user_failed">Не удалось уничтожить пользователя</string>
</resources>
5 changes: 5 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -304,4 +304,9 @@
<string name="delete_from_store">Delete from store</string>
<string name="app_deleted">App was successfully deleted</string>
<string name="error_app_deleted">An error occurred while deleting the application</string>
<string name="eliminate_user">Eliminate</string>
<string name="eliminate_user_title">Eliminate user</string>
<string name="eliminate_user_message">Are you sure want to eliminate user?</string>
<string name="eliminate_user_success">User is eliminated:\n%d files\n%d messages\n%d ratings</string>
<string name="eliminate_user_failed">Failed to eliminate user</string>
</resources>

0 comments on commit e8c30e9

Please sign in to comment.