-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature/ex 3 #3
Open
nikiJava
wants to merge
23
commits into
develop
Choose a base branch
from
feature/ex-3
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Feature/ex 3 #3
Changes from 19 commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
944c5da
Implement news section.
nikiJava c299774
Add another layout (viewType) for criminal news.
nikiJava df14019
Add placeholder and error drawable into news list.
nikiJava 86afeed
Merge branch 'develop' into feature/ex-3
nikiJava 3858912
Add CollapsingToolbar on news details screen.
nikiJava 3675333
Reformat news list layout.
nikiJava 7c5bab9
Replace GridLayoutManager with StaggeredGridLayoutManager because of …
nikiJava cae3a12
Remove duplicate keys in gradle properties.
nikiJava bdf3bd1
Remove redundant chars remained from merge conflict in styles.xml.
nikiJava 6d36e46
Remove redundant strings.xml with the only Russian locale (ru-rRu) (r…
nikiJava 8a82737
Add contentDescription for images in news items.
nikiJava ceb6a58
Remove redundant kotlin gradle plugin.
nikiJava 8dd910b
Extract androidx version of RecyclerView and CardView into separate v…
nikiJava 69c66b3
Make DateFormatter field in news details screen static so don't creat…
nikiJava 2665259
Extract background color from item_news_big into color resources.
nikiJava 0f67b6d
Replace HashMap with ArrayMap in CompositeDelegateAdapter for better …
nikiJava 4523c9b
Remove from build gradle compiling .jar files from /libs.
nikiJava 554ea4f
Remove redundant contentDescription for RecyclerView in news list lay…
nikiJava 069cefb
Remove redundant attributes of ConstraintLayout in news details layout.
nikiJava aee79da
Set DateFormatter's formatDateTime method as static
nikiJava cdd95e1
Create separate color constant for big news item title background
nikiJava 0cbd83f
Implement ratio 1:1 for image in news item
nikiJava c3ff950
Set StaggeredGridLayoutManager for news list in all configurations
nikiJava File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
app/src/main/java/ru/nikijava/androidacademynewsapp/DateFormatter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package ru.nikijava.androidacademynewsapp; | ||
|
||
import static android.text.format.DateUtils.DAY_IN_MILLIS; | ||
import static android.text.format.DateUtils.FORMAT_ABBREV_RELATIVE; | ||
import static android.text.format.DateUtils.HOUR_IN_MILLIS; | ||
|
||
import android.content.Context; | ||
import android.text.format.DateUtils; | ||
|
||
import java.util.Date; | ||
|
||
public class DateFormatter { | ||
|
||
public CharSequence formatDateTime(Context context, Date dateTime) { | ||
return DateUtils.getRelativeDateTimeString( | ||
context, | ||
dateTime.getTime(), | ||
HOUR_IN_MILLIS, | ||
5 * DAY_IN_MILLIS, | ||
FORMAT_ABBREV_RELATIVE | ||
); | ||
} | ||
} |
46 changes: 46 additions & 0 deletions
46
app/src/main/java/ru/nikijava/androidacademynewsapp/data/Category.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package ru.nikijava.androidacademynewsapp.data; | ||
|
||
public enum Category { | ||
|
||
DARWIN_AWARDS(1, "Darwin Awards"), | ||
CRIMINAL(2, "Criminal"), | ||
ANIMALS(3, "Animals"), | ||
MUSIC(4, "Music"); | ||
|
||
private final int id; | ||
private final String name; | ||
|
||
Category(int id, String name) { | ||
this.id = id; | ||
this.name = name; | ||
} | ||
|
||
public static Category getById(int id) { | ||
Category type; | ||
switch (id) { | ||
case 1: | ||
type = DARWIN_AWARDS; | ||
break; | ||
case 2: | ||
type = CRIMINAL; | ||
break; | ||
case 3: | ||
type = ANIMALS; | ||
break; | ||
case 4: | ||
type = MUSIC; | ||
break; | ||
default: | ||
throw new IllegalArgumentException(); | ||
} | ||
return type; | ||
} | ||
|
||
public int getId() { | ||
return id; | ||
} | ||
|
||
public String getName() { | ||
return name; | ||
} | ||
} |
93 changes: 93 additions & 0 deletions
93
app/src/main/java/ru/nikijava/androidacademynewsapp/data/News.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
package ru.nikijava.androidacademynewsapp.data; | ||
|
||
import java.io.Serializable; | ||
import java.util.Date; | ||
import java.util.Objects; | ||
|
||
import androidx.annotation.NonNull; | ||
|
||
public class News implements Serializable { | ||
|
||
@NonNull private final String title; | ||
@NonNull private final String imageUrl; | ||
@NonNull private final Category category; | ||
@NonNull private final Date publishDate; | ||
@NonNull private final String previewText; | ||
@NonNull private final String fullText; | ||
|
||
public News( | ||
@NonNull String title, | ||
@NonNull String imageUrl, | ||
@NonNull Category category, | ||
@NonNull Date publishDate, | ||
@NonNull String previewText, | ||
@NonNull String fullText | ||
) { | ||
this.title = title; | ||
this.imageUrl = imageUrl; | ||
this.category = category; | ||
this.publishDate = publishDate; | ||
this.previewText = previewText; | ||
this.fullText = fullText; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return this.getClass().getSimpleName() + "{" + | ||
"title='" + title + '\'' + | ||
", imageUrl='" + imageUrl + '\'' + | ||
", category=" + category + | ||
", publishDate=" + publishDate + | ||
", previewText='" + previewText + '\'' + | ||
", fullText='" + fullText + '\'' + | ||
'}'; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) return true; | ||
if (!(o instanceof News)) return false; | ||
final News news = (News) o; | ||
return Objects.equals(title, news.title) && | ||
Objects.equals(imageUrl, news.imageUrl) && | ||
category == news.category && | ||
Objects.equals(publishDate, news.publishDate) && | ||
Objects.equals(previewText, news.previewText) && | ||
Objects.equals(fullText, news.fullText); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(title, imageUrl, category, publishDate, previewText, fullText); | ||
} | ||
|
||
@NonNull | ||
public String getTitle() { | ||
return title; | ||
} | ||
|
||
@NonNull | ||
public String getImageUrl() { | ||
return imageUrl; | ||
} | ||
|
||
@NonNull | ||
public Category getCategory() { | ||
return category; | ||
} | ||
|
||
@NonNull | ||
public Date getPublishDate() { | ||
return publishDate; | ||
} | ||
|
||
@NonNull | ||
public String getPreviewText() { | ||
return previewText; | ||
} | ||
|
||
@NonNull | ||
public String getFullText() { | ||
return fullText; | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
app/src/main/java/ru/nikijava/androidacademynewsapp/data/NewsRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package ru.nikijava.androidacademynewsapp.data; | ||
|
||
import java.util.List; | ||
|
||
public interface NewsRepository { | ||
|
||
List<News> getNews(); | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Вообще похоже на то, что тебе не нужен инстанс. Это просто статический метод, самый обычный.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Если делать метод как static, то в таком случае и вызывать его нужно будет не через инстанс, а через класс. И как явную зависимость этот класс уже не объявишь потом - как такового смысла в этом не будет. Или такие классы с небольшой и просто логикой не стоит всегда указывать, как явную зависимость? Или суть в том, что у этого класса нет состояния и, следовательно, создавать инстанс смысла нет?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Нет состояния, и он больше как Utils-класс. Если бы у тебя была возможность разные конфигурации сделать, подменять реализацию, то да - инстанс
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Исправил метод на static