Just some minor adjustments

This commit is contained in:
2020-02-06 21:50:28 +00:00
parent 9379735a81
commit 5ff91b771e
3 changed files with 36 additions and 3 deletions

6
.idea/vcs.xml generated Normal file
View File

@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$" vcs="Git" />
</component>
</project>

View File

@@ -1,6 +1,9 @@
package com.example.h_mal.sliidenewsreader.ui.main package com.example.h_mal.sliidenewsreader.ui.main
import android.content.Context import android.content.Context
import android.content.Intent
import android.content.Intent.FLAG_ACTIVITY_NEW_TASK
import android.net.Uri
import android.view.LayoutInflater import android.view.LayoutInflater
import android.view.View import android.view.View
import android.view.ViewGroup import android.view.ViewGroup
@@ -25,14 +28,21 @@ class ListAdapter(context: Context, objects: MutableList<FeedResponse>) :
val currentFeedItem = getItem(position) val currentFeedItem = getItem(position)
//diplay the title and link to article
view.textView.text = currentFeedItem?.title view.textView.text = currentFeedItem?.title
view.textView.setOnClickListener {
openLink(position)
}
//initialise views
val slider = view.seekBar val slider = view.seekBar
val imageView = view.imageView val imageView = view.imageView
//hide views for now
slider.visibility = View.GONE slider.visibility = View.GONE
imageView.visibility = View.GONE imageView.visibility = View.GONE
//get array of images
val imgArray = currentFeedItem?.images val imgArray = currentFeedItem?.images
imgArray?.let { imgArray?.let {
@@ -44,6 +54,7 @@ class ListAdapter(context: Context, objects: MutableList<FeedResponse>) :
val count = it.count() -1 val count = it.count() -1
if (count > 0){ if (count > 0){
//setup slides to work with image view
slider.visibility = View.VISIBLE slider.visibility = View.VISIBLE
slider.max = count slider.max = count
slider.setOnSeekBarChangeListener(object : OnSeekBarChangeListener { slider.setOnSeekBarChangeListener(object : OnSeekBarChangeListener {
@@ -70,4 +81,17 @@ class ListAdapter(context: Context, objects: MutableList<FeedResponse>) :
.into(imageView) .into(imageView)
} }
//function for opening the link
fun openLink(position: Int){
val urlString = getItem(position)?.url
//open link to repo if the url is not null
if (urlString != null){
val openURL = Intent(Intent.ACTION_VIEW)
openURL.addFlags(FLAG_ACTIVITY_NEW_TASK)
openURL.data = Uri.parse(urlString)
context.startActivity(openURL)
}
}
} }

View File

@@ -2,20 +2,23 @@
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools" xmlns:tools="http://schemas.android.com/tools"
android:padding="16dp"
android:orientation="vertical" android:orientation="vertical"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent"> android:layout_height="wrap_content">
<TextView <TextView
android:id="@+id/textView" android:id="@+id/textView"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:text="TextView" /> tools:text="TextView"
android:layout_marginBottom="6dp"/>
<ImageView <ImageView
android:id="@+id/imageView" android:id="@+id/imageView"
android:layout_width="wrap_content" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginBottom="6dp"
tools:srcCompat="@mipmap/ic_launcher" /> tools:srcCompat="@mipmap/ic_launcher" />
<SeekBar <SeekBar