Skip to content
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
wants to merge 23 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 19 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
944c5da
Implement news section.
nikiJava Nov 11, 2018
c299774
Add another layout (viewType) for criminal news.
nikiJava Nov 16, 2018
df14019
Add placeholder and error drawable into news list.
nikiJava Nov 16, 2018
86afeed
Merge branch 'develop' into feature/ex-3
nikiJava Nov 16, 2018
3858912
Add CollapsingToolbar on news details screen.
nikiJava Nov 16, 2018
3675333
Reformat news list layout.
nikiJava Nov 16, 2018
7c5bab9
Replace GridLayoutManager with StaggeredGridLayoutManager because of …
nikiJava Nov 16, 2018
cae3a12
Remove duplicate keys in gradle properties.
nikiJava Nov 16, 2018
bdf3bd1
Remove redundant chars remained from merge conflict in styles.xml.
nikiJava Nov 17, 2018
6d36e46
Remove redundant strings.xml with the only Russian locale (ru-rRu) (r…
nikiJava Nov 17, 2018
8a82737
Add contentDescription for images in news items.
nikiJava Nov 17, 2018
ceb6a58
Remove redundant kotlin gradle plugin.
nikiJava Dec 1, 2018
8dd910b
Extract androidx version of RecyclerView and CardView into separate v…
nikiJava Dec 1, 2018
69c66b3
Make DateFormatter field in news details screen static so don't creat…
nikiJava Dec 1, 2018
2665259
Extract background color from item_news_big into color resources.
nikiJava Dec 1, 2018
0f67b6d
Replace HashMap with ArrayMap in CompositeDelegateAdapter for better …
nikiJava Dec 1, 2018
4523c9b
Remove from build gradle compiling .jar files from /libs.
nikiJava Dec 1, 2018
554ea4f
Remove redundant contentDescription for RecyclerView in news list lay…
nikiJava Dec 1, 2018
069cefb
Remove redundant attributes of ConstraintLayout in news details layout.
nikiJava Dec 1, 2018
aee79da
Set DateFormatter's formatDateTime method as static
nikiJava Dec 8, 2018
cdd95e1
Create separate color constant for big news item title background
nikiJava Dec 8, 2018
0cbd83f
Implement ratio 1:1 for image in news item
nikiJava Dec 8, 2018
c3ff950
Set StaggeredGridLayoutManager for news list in all configurations
nikiJava Dec 8, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,25 @@ android {
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
packagingOptions {
exclude 'META-INF/proguard/androidx-annotations.pro'
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}

dependencies {
implementation "androidx.cardview:cardview:$androidx_version"
implementation project(":delegateadapter")
implementation 'androidx.appcompat:appcompat:1.0.2'
implementation 'com.google.android.material:material:1.1.0-alpha01'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.1.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.0'
implementation 'com.google.android.material:material:1.1.0-alpha01'
implementation "androidx.recyclerview:recyclerview:$androidx_version"
implementation 'com.github.bumptech.glide:glide:4.8.0'
implementation 'androidx.vectordrawable:vectordrawable:1.0.1'
implementation "com.github.bumptech.glide:glide:$glide_version"
}
11 changes: 8 additions & 3 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
xmlns:tools="http://schemas.android.com/tools"
package="ru.nikijava.androidacademynewsapp">

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

<application
android:name=".AndroidAcademyNewsApp"
android:allowBackup="false"
Expand All @@ -12,13 +15,15 @@
android:supportsRtl="true"
android:theme="@style/AppTheme"
tools:ignore="GoogleAppIndexingWarning">
<activity android:name=".presentation.about.AboutActivity">
<activity android:name=".presentation.news.list.NewsListActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>

<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
</application>

</manifest>
<activity android:name=".presentation.about.AboutActivity"/>
<activity android:name=".presentation.news.details.NewsDetailsActivity"/>
</application>
</manifest>
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) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Вообще похоже на то, что тебе не нужен инстанс. Это просто статический метод, самый обычный.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Если делать метод как static, то в таком случае и вызывать его нужно будет не через инстанс, а через класс. И как явную зависимость этот класс уже не объявишь потом - как такового смысла в этом не будет. Или такие классы с небольшой и просто логикой не стоит всегда указывать, как явную зависимость? Или суть в том, что у этого класса нет состояния и, следовательно, создавать инстанс смысла нет?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Нет состояния, и он больше как Utils-класс. Если бы у тебя была возможность разные конфигурации сделать, подменять реализацию, то да - инстанс

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Исправил метод на static

return DateUtils.getRelativeDateTimeString(
context,
dateTime.getTime(),
HOUR_IN_MILLIS,
5 * DAY_IN_MILLIS,
FORMAT_ABBREV_RELATIVE
);
}
}
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 app/src/main/java/ru/nikijava/androidacademynewsapp/data/News.java
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;
}
}
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();
}
Loading