Skip to content

Commit e5c8591

Browse files
committed
Solve conflicts
2 parents 49f4b5b + 2ad9ced commit e5c8591

12 files changed

+228
-120
lines changed

app/build.gradle

+2
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ android {
137137
buildConfigField "String", "WIKIMEDIA_FORGE_API_HOST", "\"https://tools.wmflabs.org/\""
138138
buildConfigField "String", "IMAGE_URL_BASE", "\"https://upload.wikimedia.org/wikipedia/commons\""
139139
buildConfigField "String", "HOME_URL", "\"https://commons.wikimedia.org/wiki/\""
140+
buildConfigField "String", "COMMONS_URL", "\"https://commons.wikimedia.org\""
140141
buildConfigField "String", "MOBILE_HOME_URL", "\"https://commons.m.wikimedia.org/wiki/\""
141142
buildConfigField "String", "EVENTLOG_URL", "\"https://www.wikimedia.org/beacon/event\""
142143
buildConfigField "String", "EVENTLOG_WIKI", "\"commonswiki\""
@@ -152,6 +153,7 @@ android {
152153
buildConfigField "String", "WIKIMEDIA_FORGE_API_HOST", "\"https://tools.wmflabs.org/\""
153154
buildConfigField "String", "IMAGE_URL_BASE", "\"https://upload.beta.wmflabs.org/wikipedia/commons\""
154155
buildConfigField "String", "HOME_URL", "\"https://commons.wikimedia.beta.wmflabs.org/wiki/\""
156+
buildConfigField "String", "COMMONS_URL", "\"https://commons.wikimedia.beta.wmflabs.org\""
155157
buildConfigField "String", "MOBILE_HOME_URL", "\"https://commons.m.wikimedia.beta.wmflabs.org/wiki/\""
156158
buildConfigField "String", "EVENTLOG_URL", "\"https://commons.wikimedia.beta.wmflabs.org/beacon/event\""
157159
buildConfigField "String", "EVENTLOG_WIKI", "\"commonswiki\""

app/src/main/java/fr/free/nrw/commons/Utils.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ public static void rateApp(Context context) {
177177
}
178178
}
179179

180-
public static void handleWebUrl(Context context,Uri url){
180+
public static void handleWebUrl(Context context, Uri url) {
181181
Intent browserIntent = new Intent(Intent.ACTION_VIEW, url);
182182
if (browserIntent.resolveActivity(context.getPackageManager()) == null) {
183183
Toast toast = Toast.makeText(context, context.getString(R.string.no_web_browser), LENGTH_SHORT);

app/src/main/java/fr/free/nrw/commons/mwapi/ApacheHttpClientMediaWikiApi.java

+8-21
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
import org.apache.http.util.EntityUtils;
2424
import org.mediawiki.api.ApiResult;
2525
import org.mediawiki.api.MWApi;
26-
import org.w3c.dom.Node;
2726
import org.w3c.dom.NodeList;
2827

2928
import java.io.IOException;
@@ -41,16 +40,12 @@
4140
import fr.free.nrw.commons.BuildConfig;
4241
import fr.free.nrw.commons.PageTitle;
4342
import fr.free.nrw.commons.notification.Notification;
43+
import fr.free.nrw.commons.notification.NotificationUtils;
4444
import in.yuvi.http.fluent.Http;
4545
import io.reactivex.Observable;
4646
import io.reactivex.Single;
4747
import timber.log.Timber;
4848

49-
import static fr.free.nrw.commons.notification.NotificationType.UNKNOWN;
50-
import static fr.free.nrw.commons.notification.NotificationUtils.getNotificationFromApiResult;
51-
import static fr.free.nrw.commons.notification.NotificationUtils.getNotificationType;
52-
import static fr.free.nrw.commons.notification.NotificationUtils.isCommonsNotification;
53-
5449
/**
5550
* @author Addshore
5651
*/
@@ -434,33 +429,25 @@ public List<Notification> getNotifications() {
434429
.param("notprop", "list")
435430
.param("format", "xml")
436431
.param("meta", "notifications")
437-
.param("notfilter", "!read")
432+
// .param("meta", "notifications")
433+
.param("notformat", "model")
438434
.get()
439435
.getNode("/api/query/notifications/list");
440436
} catch (IOException e) {
441437
Timber.e("Failed to obtain searchCategories", e);
442438
}
443439

444-
if (notificationNode == null) {
440+
if (notificationNode == null
441+
|| notificationNode.getDocument() == null
442+
|| notificationNode.getDocument().getChildNodes() == null
443+
|| notificationNode.getDocument().getChildNodes().getLength() == 0) {
445444
return new ArrayList<>();
446445
}
447446

448-
List<Notification> notifications = new ArrayList<>();
449-
450447
NodeList childNodes = notificationNode.getDocument().getChildNodes();
451-
452-
for (int i = 0; i < childNodes.getLength(); i++) {
453-
Node node = childNodes.item(i);
454-
if (isCommonsNotification(node)
455-
&& !getNotificationType(node).equals(UNKNOWN)) {
456-
notifications.add(getNotificationFromApiResult(context, node));
457-
}
458-
}
459-
460-
return notifications;
448+
return NotificationUtils.getNotificationsFromList(context, childNodes);
461449
}
462450

463-
464451
@Override
465452
public boolean existingFile(String fileSha1) throws IOException {
466453
return api.action("query")

app/src/main/java/fr/free/nrw/commons/notification/Notification.java

+3-1
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,14 @@ public class Notification {
1010
public String date;
1111
public String description;
1212
public String link;
13+
public String iconUrl;
1314

14-
public Notification(NotificationType notificationType, String notificationText, String date, String description, String link) {
15+
public Notification(NotificationType notificationType, String notificationText, String date, String description, String link, String iconUrl) {
1516
this.notificationType = notificationType;
1617
this.notificationText = notificationText;
1718
this.date = date;
1819
this.description = description;
1920
this.link = link;
21+
this.iconUrl = iconUrl;
2022
}
2123
}

app/src/main/java/fr/free/nrw/commons/notification/NotificationActivity.java

+24-14
Original file line numberDiff line numberDiff line change
@@ -9,25 +9,28 @@
99
import android.support.v7.widget.DividerItemDecoration;
1010
import android.support.v7.widget.LinearLayoutManager;
1111
import android.support.v7.widget.RecyclerView;
12-
import android.widget.Toast;
12+
import android.view.View;
13+
import android.widget.ProgressBar;
14+
import android.widget.RelativeLayout;
1315

1416
import com.pedrogomez.renderers.RVRendererAdapter;
1517

18+
import java.util.Collections;
1619
import java.util.List;
1720

1821
import javax.inject.Inject;
1922

2023
import butterknife.BindView;
2124
import butterknife.ButterKnife;
2225
import fr.free.nrw.commons.R;
26+
import fr.free.nrw.commons.Utils;
2327
import fr.free.nrw.commons.theme.NavigationBaseActivity;
28+
import fr.free.nrw.commons.utils.ViewUtil;
2429
import io.reactivex.Observable;
2530
import io.reactivex.android.schedulers.AndroidSchedulers;
2631
import io.reactivex.schedulers.Schedulers;
2732
import timber.log.Timber;
2833

29-
import static android.widget.Toast.LENGTH_SHORT;
30-
3134
/**
3235
* Created by root on 18.12.2017.
3336
*/
@@ -36,6 +39,8 @@ public class NotificationActivity extends NavigationBaseActivity {
3639
NotificationAdapterFactory notificationAdapterFactory;
3740

3841
@BindView(R.id.listView) RecyclerView recyclerView;
42+
@BindView(R.id.progressBar) ProgressBar progressBar;
43+
@BindView(R.id.container) RelativeLayout relativeLayout;
3944

4045
@Inject NotificationController controller;
4146

@@ -65,14 +70,22 @@ private void addNotifications() {
6570
Timber.d("Add notifications");
6671

6772
if(mNotificationWorkerFragment == null){
68-
Observable.fromCallable(() -> controller.getNotifications())
73+
Observable.fromCallable(() -> {
74+
progressBar.setVisibility(View.VISIBLE);
75+
return controller.getNotifications();
76+
})
6977
.subscribeOn(Schedulers.io())
7078
.observeOn(AndroidSchedulers.mainThread())
7179
.subscribe(notificationList -> {
80+
Collections.reverse(notificationList);
7281
Timber.d("Number of notifications is %d", notificationList.size());
73-
initializeAndSetNotificationList(notificationList);
7482
setAdapter(notificationList);
75-
}, throwable -> Timber.e(throwable, "Error occurred while loading notifications"));
83+
progressBar.setVisibility(View.GONE);
84+
}, throwable -> {
85+
Timber.e(throwable, "Error occurred while loading notifications");
86+
ViewUtil.showSnackbar(relativeLayout, R.string.error_notifications);
87+
progressBar.setVisibility(View.GONE);
88+
});
7689
} else {
7790
setAdapter(mNotificationWorkerFragment.getNotificationList());
7891
}
@@ -82,17 +95,14 @@ private void handleUrl(String url) {
8295
if (url == null || url.equals("")) {
8396
return;
8497
}
85-
Intent browser = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
86-
//check if web browser available
87-
if(browser.resolveActivity(this.getPackageManager()) != null){
88-
startActivity(browser);
89-
} else {
90-
Toast toast = Toast.makeText(this, getString(R.string.no_web_browser), LENGTH_SHORT);
91-
toast.show();
92-
}
98+
Utils.handleWebUrl(this, Uri.parse(url));
9399
}
94100

95101
private void setAdapter(List<Notification> notificationList) {
102+
if(notificationList == null || notificationList.isEmpty()) {
103+
ViewUtil.showSnackbar(relativeLayout, R.string.no_notifications);
104+
return;
105+
}
96106
notificationAdapterFactory = new NotificationAdapterFactory(notification -> {
97107
Timber.d("Notification clicked %s", notification.link);
98108
handleUrl(notification.link);

app/src/main/java/fr/free/nrw/commons/notification/NotificationRenderer.java

+2-6
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020

2121
public class NotificationRenderer extends Renderer<Notification> {
2222
@BindView(R.id.title) ReadMoreTextView title;
23-
@BindView(R.id.description) ReadMoreTextView description;
2423
@BindView(R.id.time) TextView time;
2524
@BindView(R.id.icon) ImageView icon;
2625
private NotificationClicked listener;
@@ -48,13 +47,10 @@ protected View inflate(LayoutInflater layoutInflater, ViewGroup viewGroup) {
4847
@Override
4948
public void render() {
5049
Notification notification = getContent();
51-
StringBuilder str = new StringBuilder(notification.notificationText);
52-
str.append(" " );
50+
StringBuilder str = new StringBuilder(notification.notificationText.trim());
51+
str.append(" ");
5352
title.setText(str);
5453
time.setText(notification.date);
55-
StringBuilder desc = new StringBuilder(notification.description);
56-
desc.append(" ");
57-
description.setText(desc);
5854
switch (notification.notificationType) {
5955
case THANK_YOU_EDIT:
6056
icon.setImageResource(R.drawable.ic_edit_black_24dp);

0 commit comments

Comments
 (0)