mirror of
https://github.com/hmalik144/Android-developer-tech-test---Sliide.git
synced 2025-12-10 00:25:19 +00:00
Just some minor adjustments
This commit is contained in:
@@ -1,6 +1,9 @@
|
||||
package com.example.h_mal.sliidenewsreader.ui.main
|
||||
|
||||
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.View
|
||||
import android.view.ViewGroup
|
||||
@@ -25,14 +28,21 @@ class ListAdapter(context: Context, objects: MutableList<FeedResponse>) :
|
||||
|
||||
val currentFeedItem = getItem(position)
|
||||
|
||||
//diplay the title and link to article
|
||||
view.textView.text = currentFeedItem?.title
|
||||
view.textView.setOnClickListener {
|
||||
openLink(position)
|
||||
}
|
||||
|
||||
//initialise views
|
||||
val slider = view.seekBar
|
||||
val imageView = view.imageView
|
||||
|
||||
//hide views for now
|
||||
slider.visibility = View.GONE
|
||||
imageView.visibility = View.GONE
|
||||
|
||||
//get array of images
|
||||
val imgArray = currentFeedItem?.images
|
||||
|
||||
imgArray?.let {
|
||||
@@ -44,6 +54,7 @@ class ListAdapter(context: Context, objects: MutableList<FeedResponse>) :
|
||||
val count = it.count() -1
|
||||
|
||||
if (count > 0){
|
||||
//setup slides to work with image view
|
||||
slider.visibility = View.VISIBLE
|
||||
slider.max = count
|
||||
slider.setOnSeekBarChangeListener(object : OnSeekBarChangeListener {
|
||||
@@ -70,4 +81,17 @@ class ListAdapter(context: Context, objects: MutableList<FeedResponse>) :
|
||||
.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)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -2,20 +2,23 @@
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:padding="16dp"
|
||||
android:orientation="vertical"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
android:layout_height="wrap_content">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/textView"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="TextView" />
|
||||
tools:text="TextView"
|
||||
android:layout_marginBottom="6dp"/>
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/imageView"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginBottom="6dp"
|
||||
tools:srcCompat="@mipmap/ic_launcher" />
|
||||
|
||||
<SeekBar
|
||||
|
||||
Reference in New Issue
Block a user