Skip to content

Commit

Permalink
Реализована подгрузка картинок с сети. Добавлен разделитель элементов…
Browse files Browse the repository at this point in the history
… в списке.
  • Loading branch information
CesPaul committed Sep 25, 2019
1 parent c123ea1 commit 42233af
Show file tree
Hide file tree
Showing 9 changed files with 40 additions and 32 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ dependencies {
implementation 'com.squareup.retrofit2:converter-gson:2.6.1'
implementation 'com.squareup.retrofit2:adapter-rxjava2:2.6.1'
implementation "com.squareup.retrofit2:converter-moshi:2.6.1"
//Picasso pics
implementation 'com.squareup.picasso:picasso:2.71828'
//Fresco pics
implementation 'com.facebook.fresco:fresco:1.10.0'
// Custom Toasts
implementation 'com.github.GrenderG:Toasty:1.4.2'

Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
package com.cespaul.testjob.injection.component

import android.content.Context
import com.cespaul.testjob.base.BaseView
import com.cespaul.testjob.injection.module.ContextModule
import com.cespaul.testjob.injection.module.NetworkModule
import com.cespaul.testjob.ui.news.NewsPresenter
import dagger.BindsInstance
import dagger.Component
import dagger.Module
import javax.inject.Singleton


Expand Down
4 changes: 1 addition & 3 deletions app/src/main/java/com/cespaul/testjob/model/News.kt
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
package com.cespaul.testjob.model

import com.google.gson.annotations.SerializedName

data class News(
val title: String,
val description: String,
val url: String,
val publishDate: String,
val urlToImage: String,
val thumbnailUrl: String,
val publishedAt: String
)

2 changes: 1 addition & 1 deletion app/src/main/java/com/cespaul/testjob/ui/SplashActivity.kt
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package com.cespaul.testjob.ui

import android.content.Intent
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle
import android.support.v7.app.AppCompatActivity
import com.cespaul.testjob.R
import com.cespaul.testjob.ui.news.NewsActivity

Expand Down
8 changes: 5 additions & 3 deletions app/src/main/java/com/cespaul/testjob/ui/news/NewsActivity.kt
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
package com.cespaul.testjob.ui.news

import android.app.ProgressDialog
import android.databinding.DataBindingUtil
import android.os.Bundle
import android.support.v7.widget.DividerItemDecoration
import android.support.v7.widget.LinearLayoutManager
import android.widget.Toast
import com.cespaul.testjob.R
import com.cespaul.testjob.model.News
import com.cespaul.testjob.base.BaseActivity
import com.cespaul.testjob.utils.setDividerItemDecoration
import com.cespaul.testjob.model.News
import com.facebook.drawee.backends.pipeline.Fresco
import es.dmoral.toasty.Toasty
import kotlinx.android.synthetic.main.activity_news.*

Expand All @@ -21,9 +20,12 @@ class NewsActivity : BaseActivity<NewsPresenter>(), NewsView {

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
Fresco.initialize(this)
setContentView(R.layout.activity_news)
newsRecycler.adapter = newsAdapter
newsRecycler.layoutManager = layoutManager
newsRecycler.addItemDecoration(DividerItemDecoration(this, DividerItemDecoration.VERTICAL))


presenter.onViewCreated()
}
Expand Down
6 changes: 4 additions & 2 deletions app/src/main/java/com/cespaul/testjob/ui/news/NewsAdapter.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import android.view.ViewGroup
import android.widget.TextView
import com.cespaul.testjob.R
import com.cespaul.testjob.model.News
import kotlinx.android.synthetic.main.news_row.*
import com.facebook.drawee.view.SimpleDraweeView
import kotlinx.android.synthetic.main.news_row.view.*


Expand All @@ -29,7 +29,7 @@ class NewsAdapter(private val context: Context) : RecyclerView.Adapter<NewsAdapt

holderNews.titleTextView.text = news.title
holderNews.descTextView.text = news.url

holderNews.imgNewsView.setImageURI(news.thumbnailUrl)
}

fun updateNews(news: List<News>){
Expand All @@ -40,9 +40,11 @@ class NewsAdapter(private val context: Context) : RecyclerView.Adapter<NewsAdapt
class NewsViewHolder(private val itemLayoutView: View) : RecyclerView.ViewHolder(itemLayoutView) {
var titleTextView : TextView
var descTextView : TextView
var imgNewsView : SimpleDraweeView
init {
titleTextView = itemLayoutView.lblNewsTitle
descTextView = itemLayoutView.lblNewsDescription
imgNewsView = itemLayoutView.imgNews

}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.cespaul.testjob.ui.news

import com.cespaul.testjob.base.BasePresenter
import com.cespaul.testjob.base.BaseView
import com.cespaul.testjob.network.NewsApi
import io.reactivex.android.schedulers.AndroidSchedulers
import io.reactivex.disposables.Disposable
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/java/com/cespaul/testjob/ui/news/NewsView.kt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.cespaul.testjob.ui.news

import com.cespaul.testjob.model.News
import com.cespaul.testjob.base.BaseView
import com.cespaul.testjob.model.News

interface NewsView : BaseView {
fun updateNews(news : List<News>)
Expand Down
43 changes: 26 additions & 17 deletions app/src/main/res/layout/news_row.xml
Original file line number Diff line number Diff line change
@@ -1,29 +1,32 @@
<?xml version="1.0" encoding="utf-8"?>
<layout>
<layout xmlns:android="http://schemas.android.com/apk/res/android">

<data>
<variable
name="news"
type="com.cespaul.testjob.model.News" />
</data>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="8dp"
android:paddingBottom="8dp"
android:paddingStart="16dp"
android:paddingEnd="16dp"
android:gravity="center_vertical"
android:id="@+id/rowNews">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="8dp"
android:paddingBottom="8dp"
android:paddingStart="16dp"
android:paddingEnd="16dp"
android:gravity="center_vertical"
android:id="@+id/rowNews">
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView android:layout_width="32dp"
android:layout_height="32dp"
android:src="@mipmap/ic_launcher" android:id="@+id/imgNewsThumb"/>
<com.facebook.drawee.view.SimpleDraweeView
xmlns:fresco="http://schemas.android.com/apk/res-auto"
android:id="@+id/imgNews"
android:layout_width="100dp"
android:layout_height="wrap_content"
fresco:viewAspectRatio="1.33" />
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
Expand All @@ -36,11 +39,17 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content" android:id="@+id/lblNewsDescription" android:layout_weight="1"
android:layout_marginLeft="8dp" android:text="Description"/>

<TextView
android:id="@+id/lblNewsDate"
android:layout_width="match_parent"
android:layout_height="wrap_content" android:id="@+id/lblNewsDate" android:layout_marginLeft="8dp"
android:layout_gravity="right" android:foregroundGravity="right" android:gravity="right"
android:text="Date"/>
android:layout_height="wrap_content"
android:layout_gravity="right"
android:layout_marginLeft="8dp"
android:foregroundGravity="right"
android:gravity="right"
android:text="Date"
android:visibility="invisible" />
</LinearLayout>
</LinearLayout>

Expand Down

0 comments on commit 42233af

Please sign in to comment.