Remove unused code

This commit is contained in:
maskara 2018-01-22 03:54:26 +05:30
parent 6664f7f324
commit 41d6abdf40
17 changed files with 0 additions and 653 deletions

View file

@ -1,101 +0,0 @@
package fr.free.nrw.commons.notification;
import android.support.annotation.NonNull;
import android.support.annotation.VisibleForTesting;
import android.text.TextUtils;
import com.google.gson.JsonParseException;
import java.util.List;
import fr.free.nrw.commons.mwapi.MwQueryResponse;
import fr.free.nrw.commons.network.RetrofitFactory;
import retrofit2.Call;
import retrofit2.Response;
import retrofit2.http.Field;
import retrofit2.http.FormUrlEncoded;
import retrofit2.http.GET;
import retrofit2.http.POST;
import retrofit2.http.Query;
import timber.log.Timber;
public final class NotificationClient {
@NonNull
private final Service service;
public interface Callback {
void success(@NonNull List<Notification> notifications);
void failure(Throwable t);
}
public NotificationClient(@NonNull String endpoint) {
service = RetrofitFactory.newInstance(endpoint).create(Service.class);
}
@VisibleForTesting
static class CallbackAdapter implements retrofit2.Callback<MwQueryResponse<NotificationObject.QueryNotifications>> {
@NonNull
private final Callback callback;
CallbackAdapter(@NonNull Callback callback) {
this.callback = callback;
}
@Override
public void onResponse(Call<MwQueryResponse<NotificationObject.QueryNotifications>> call,
Response<MwQueryResponse<NotificationObject.QueryNotifications>> response) {
Timber.d("Resonse is %s", response);
if (response.body() != null && response.body().query() != null) {
callback.success(response.body().query().get());
} else {
callback.failure(new JsonParseException("Notification response is malformed."));
}
}
@Override
public void onFailure(Call<MwQueryResponse<NotificationObject.QueryNotifications>> call, Throwable caught) {
Timber.e(caught, "Error occurred while fetching notifications");
callback.failure(caught);
}
}
/**
* Obrain a list of unread notifications for the user who is currently logged in.
*
* @param callback Callback that will receive the list of notifications.
* @param wikis List of wiki names for which notifications should be received. These must be
* in the "DB name" format, as in "enwiki", "zhwiki", "wikidatawiki", etc.
*/
public void getNotifications(@NonNull final Callback callback, @NonNull String... wikis) {
String wikiList = TextUtils.join("|", wikis);
requestNotifications(service, wikiList).enqueue(new CallbackAdapter(callback));
}
@VisibleForTesting
@NonNull
Call<MwQueryResponse<NotificationObject.QueryNotifications>> requestNotifications(@NonNull Service service, @NonNull String wikiList) {
return service.getNotifications(wikiList);
}
@VisibleForTesting
@NonNull
Call<MwQueryResponse<MarkReadResponse.QueryMarkReadResponse>> requestMarkRead(@NonNull Service service, @NonNull String token, @NonNull String idList) {
return service.markRead(token, idList);
}
@VisibleForTesting
interface Service {
String ACTION = "w/api.php?format=json&formatversion=2&action=";
@GET(ACTION + "query&meta=notifications&notfilter=!read&notprop=list")
@NonNull
Call<MwQueryResponse<NotificationObject.QueryNotifications>> getNotifications(@Query("notwikis") @NonNull String wikiList);
@FormUrlEncoded
@POST(ACTION + "echomarkread")
@NonNull
Call<MwQueryResponse<MarkReadResponse.QueryMarkReadResponse>> markRead(@Field("token") @NonNull String token,
@Field("list") @NonNull String idList);
}
}

View file

@ -1,106 +0,0 @@
package fr.free.nrw.commons.notification;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import com.google.gson.annotations.SerializedName;
import java.util.List;
public class NotificationObject {
public static final String TYPE_EDIT_USER_TALK = "edit-user-talk";
public static final String TYPE_REVERTED = "reverted";
public static final String TYPE_EDIT_THANK = "edit-thank";
public static final String WIKIDATA_WIKI = "wikidatawiki";
@SuppressWarnings("unused,NullableProblems") @NonNull
private String wiki;
@SuppressWarnings("unused") private int id;
@SuppressWarnings("unused,NullableProblems") @NonNull private String type;
@SuppressWarnings("unused,NullableProblems") @NonNull private String category;
@SuppressWarnings("unused") private int revid;
@SuppressWarnings("unused,NullableProblems") @NonNull private Title title;
@SuppressWarnings("unused,NullableProblems") @NonNull private Agent agent;
@NonNull public String wiki() {
return wiki;
}
public int id() {
return id;
}
@NonNull public String type() {
return type;
}
@NonNull public Agent agent() {
return agent;
}
@NonNull public Title title() {
return title;
}
public int revID() {
return revid;
}
public boolean isFromWikidata() {
return wiki.equals(WIKIDATA_WIKI);
}
@Override public String toString() {
return Integer.toString(id);
}
public static class Title {
@SuppressWarnings("unused,NullableProblems") @NonNull private String full;
@SuppressWarnings("unused,NullableProblems") @NonNull private String text;
@SuppressWarnings("unused") @Nullable
private String namespace;
@SuppressWarnings("unused") @SerializedName("namespace-key") private int namespaceKey;
@NonNull public String text() {
return text;
}
@NonNull public String full() {
return full;
}
public boolean isMainNamespace() {
return namespaceKey == 0;
}
public void setFull(@NonNull String title) {
full = title;
}
}
public static class Agent {
@SuppressWarnings("unused,NullableProblems") @NonNull private String id;
@SuppressWarnings("unused,NullableProblems") @NonNull private String name;
@NonNull public String name() {
return name;
}
}
public static class NotificationList {
@SuppressWarnings("unused,NullableProblems") @NonNull private List<Notification> list;
@NonNull public List<Notification> getNotifications() {
return list;
}
}
public static class QueryNotifications {
@SuppressWarnings("unused,NullableProblems") @NonNull private NotificationList notifications;
@NonNull public List<Notification> get() {
return notifications.getNotifications();
}
}
}