Skip to content

Commit

Permalink
#34 다이제스트 알림, 제목을 최대 세 개까지 보여주도록 처리
Browse files Browse the repository at this point in the history
  • Loading branch information
jungilhan committed Mar 19, 2017
1 parent 86a9f1c commit aecae81
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,16 @@

import android.app.IntentService;
import android.content.Intent;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;

import org.petabytes.api.source.local.Entry;
import org.petabytes.awesomeblogs.AwesomeBlogsApp;
import org.petabytes.awesomeblogs.R;
import org.petabytes.awesomeblogs.fcm.Notifications;
import org.petabytes.awesomeblogs.util.Analytics;

import java.util.List;
import java.util.concurrent.TimeUnit;

import hugo.weaving.DebugLog;
Expand All @@ -34,12 +37,34 @@ protected void onHandleIntent(@Nullable Intent intent) {
.observeOn(AndroidSchedulers.mainThread())
.doOnNext($ -> Analytics.event(Analytics.Event.SEND_DIGEST))
.subscribe(entries ->
Notifications.send(this, getString(R.string.digest_title, entries.size()), entries.size() == 1
? getString(R.string.fresh_entries_title_0, entries.get(0).getTitle())
: getString(R.string.fresh_entries_title_1, entries.get(0).getTitle(), (entries.size() - 1))));
Notifications.send(this, getString(R.string.digest_title, entries.size()), createMessage(entries)));

AwesomeBlogsApp.get().api().getFeed("all", false)
.onErrorResumeNext(Observable.empty())
.subscribe();
}

private String createMessage(@NonNull List<Entry> entries) {
String message;
switch (entries.size()) {
case 0:
throw new IllegalStateException("Size cannot be zero.");
case 1:
message = getString(R.string.digest_message_1, entries.get(0).getTitle());
break;
case 2:
message = getString(R.string.digest_message_2,
entries.get(0).getTitle(), entries.get(1).getTitle());
break;
case 3:
message = getString(R.string.digest_message_3,
entries.get(0).getTitle(), entries.get(1).getTitle(), entries.get(2).getTitle());
break;
default:
message = getString(R.string.digest_message_4,
entries.get(0).getTitle(), entries.get(1).getTitle(), entries.get(2).getTitle(), entries.size() - 3);
break;
}
return message;
}
}
6 changes: 5 additions & 1 deletion app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@
<string name="error_invalid_link">이동할 수 없는 웹 사이트 주소입니다.</string>
<string name="error_sign_in">로그인 도중 문제가 발생했습니다. 잠시 후 다시 시도해 주세요.</string>
<string name="digest_title">새로운 소식 %1$d개 🕵️</string>
<string name="digest_message_1">\'%1$s\' 소식이 있습니다.</string>
<string name="digest_message_2">\'%1$s\', \'%2$s\' 소식이 있습니다.</string>
<string name="digest_message_3">\'%1$s\', \'%2$s\', \'%3$s\' 소식이 있습니다.</string>
<string name="digest_message_4">\'%1$s\', \'%2$s\', \'%3$s\' 외 %4$d개의 소식이 있습니다.</string>
<string name="fresh_entries_title_0">새로운 \'%1$s\' 소식이 있습니다.</string>
<string name="fresh_entries_title_1">\'%1$s\' 외 %2$d 개의 새로운 소식이 있습니다.</string>
<string name="fresh_entries_title_1">\'%1$s\' 외 %2$d개의 새로운 소식이 있습니다.</string>
</resources>

0 comments on commit aecae81

Please sign in to comment.