Skip to content
This repository has been archived by the owner on Jul 20, 2023. It is now read-only.

Added Schedule Content (Pass Times) #20

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
138 changes: 74 additions & 64 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
plugins {
id "io.gitlab.arturbosch.detekt" version "1.0.0.RC6-4"
id "io.gitlab.arturbosch.detekt" version "1.0.0.RC6-4"
}
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
Expand All @@ -8,85 +8,95 @@ apply plugin: 'kotlin-kapt'
apply plugin: "org.jlleitschuh.gradle.ktlint"

detekt {
version = "1.0.0.RC6-4"
profile("main") {
config = "$rootDir/config/detekt/detekt-config.yml"
output = "$project.projectDir/build/reports/detekt/detekt.xml"
}
version = "1.0.0.RC6-4"
profile("main") {
config = "$rootDir/config/detekt/detekt-config.yml"
output = "$project.projectDir/build/reports/detekt/detekt.xml"
}
}

android {
compileSdkVersion 27

defaultConfig {
applicationId "com.ferranpons.spacehub"
minSdkVersion 15
targetSdkVersion 27
versionCode 4
versionName "1.0"
multiDexEnabled true
}

buildTypes {
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
compileSdkVersion 27

defaultConfig {
applicationId "com.ferranpons.spacehub"
minSdkVersion 17
targetSdkVersion 27
versionCode 4
versionName "1.0"
multiDexEnabled true
}

buildTypes {
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}

compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}

dexOptions {
javaMaxHeapSize "4g"
preDexLibraries = preDexEnabled && !travisBuild
}

lintOptions {
abortOnError false
disable 'IconMissingDensityFolder'
}
}

compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}

dexOptions {
javaMaxHeapSize "4g"
preDexLibraries = preDexEnabled && !travisBuild
}

lintOptions {
abortOnError false
disable 'IconMissingDensityFolder'
}
}

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation fileTree(dir: 'libs', include: ['*.jar'])

implementation 'com.android.support:multidex:1.0.3'

implementation 'com.android.support:multidex:1.0.3'
def supportLibraryVersion = '27.1.1'
implementation "com.android.support:appcompat-v7:$supportLibraryVersion"
implementation "com.android.support:design:${supportLibraryVersion}"
implementation "com.android.support:cardview-v7:$supportLibraryVersion"
implementation "com.android.support:recyclerview-v7:$supportLibraryVersion"
implementation 'com.android.support.constraint:constraint-layout:1.0.2'

def supportLibraryVersion = '27.1.1'
implementation "com.android.support:appcompat-v7:$supportLibraryVersion"
implementation "com.android.support:design:${supportLibraryVersion}"
implementation "com.android.support:cardview-v7:$supportLibraryVersion"
implementation "com.android.support:recyclerview-v7:$supportLibraryVersion"
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
def playServicesVersion = '12.0.1'
implementation "com.google.android.gms:play-services-maps:$playServicesVersion"
implementation "com.google.firebase:firebase-crash:$playServicesVersion"
implementation "com.google.firebase:firebase-core:$playServicesVersion"

implementation 'com.google.android.gms:play-services-maps:12.0.1'
implementation 'io.reactivex.rxjava2:rxandroid:2.0.2'
implementation 'io.reactivex.rxjava2:rxjava:2.1.12'

implementation 'io.reactivex.rxjava2:rxandroid:2.0.2'
implementation 'io.reactivex.rxjava2:rxjava:2.1.12'
implementation('com.schibstedspain.android:leku:4.0.1') {
exclude group: 'com.google.android.gms'
exclude group: 'com.android.support'
}

def butterKnife = '8.8.1'
implementation "com.jakewharton:butterknife:$butterKnife"
kapt "com.jakewharton:butterknife-compiler:$butterKnife"
def butterKnife = '8.8.1'
implementation "com.jakewharton:butterknife:$butterKnife"
kapt "com.jakewharton:butterknife-compiler:$butterKnife"

implementation 'net.danlew:android.joda:2.9.9.1'
implementation 'net.danlew:android.joda:2.9.9.1'

def retrofitVersion = '2.3.0'
implementation "com.squareup.retrofit2:retrofit:$retrofitVersion"
implementation "com.squareup.retrofit2:adapter-rxjava2:$retrofitVersion"
implementation "com.squareup.retrofit2:converter-gson:$retrofitVersion"
def retrofitVersion = '2.3.0'
implementation "com.squareup.retrofit2:retrofit:$retrofitVersion"
implementation "com.squareup.retrofit2:adapter-rxjava2:$retrofitVersion"
implementation "com.squareup.retrofit2:converter-gson:$retrofitVersion"

implementation 'io.swagger:swagger-annotations:1.5.17'
implementation "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"
implementation 'io.swagger:swagger-annotations:1.5.17'
implementation "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"

implementation ("com.ashokvarma.android:bottom-navigation-bar:2.0.4") {
exclude group: 'com.android.support'
}
implementation("com.ashokvarma.android:bottom-navigation-bar:2.0.4") {
exclude group: 'com.android.support'
}

implementation 'com.google.code.gson:gson:2.8.2'
implementation 'com.google.code.gson:gson:2.8.2'

testImplementation 'org.mockito:mockito-core:2.12.0'
testImplementation 'junit:junit:4.12'
testImplementation 'org.mockito:mockito-core:2.12.0'
testImplementation 'junit:junit:4.12'
}

//apply plugin: 'com.google.gms.google-services'
Original file line number Diff line number Diff line change
@@ -1,60 +1,50 @@
package com.ferranpons.spacehub.passTimes

import android.annotation.TargetApi
import android.content.Context
import android.icu.text.SimpleDateFormat
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.ArrayAdapter
import android.widget.TextView
import com.ferranpons.spacehub.R
import com.ferranpons.spacehub.issTracking.IssTrackingApiInterface
import java.util.Locale
import java.util.concurrent.TimeUnit
import org.joda.time.DateTime

class PassTimesAdapter(context: Context, passTimes: List<IssTrackingApiInterface.PassTime>) : ArrayAdapter<IssTrackingApiInterface.PassTime>(context, R.layout.row_pass_time, passTimes) {
class PassTimesAdapter(private val passTimes: List<IssTrackingApiInterface.PassTime>) : RecyclerView.Adapter<PassTimesAdapter.PassTimesViewHolder>() {

class ViewHolder(view: View) {
internal var riseTime: TextView = view.findViewById(R.id.riseTime) as TextView
internal var duration: TextView = view.findViewById(R.id.duration) as TextView
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): PassTimesViewHolder {
val v = LayoutInflater.from(parent.context).inflate(R.layout.row_pass_time, parent, false)
return PassTimesViewHolder(v)
}

@TargetApi(24)
override fun getView(position: Int, view: View?, parent: ViewGroup): View? {
val holder: ViewHolder
var customView = view
if (view == null) {
customView = View.inflate(parent.context, R.layout.row_pass_time, null)
holder = ViewHolder(customView)
customView.tag = holder
} else {
holder = view.tag as ViewHolder
}
val passTime = getItem(position)
if (passTime != null && passTime.riseTime > -1) {
val date = DateTime(passTime.riseTime * 1000L)
override fun getItemCount(): Int = passTimes.size

override fun onBindViewHolder(holder: PassTimesViewHolder, position: Int) {
val passTime = passTimes[position]
if (passTime.riseTime > -1) {
/*val date = DateTime(passTime.riseTime * 1000L)
var sdf: SimpleDateFormat? = null
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.N) {
sdf = SimpleDateFormat("yyyy-MM-dd HH:mm", Locale.getDefault())
}
var riseTimeUnformatted = arrayOfNulls<String>(0)
if (sdf != null) {
riseTimeUnformatted = sdf.format(date).split(" ".toRegex()).dropLastWhile { it.isEmpty() }.toTypedArray()
}
val riseTime = riseTimeUnformatted[0] + " at " + riseTimeUnformatted[1] + "h"
holder.riseTime.text = riseTime
val riseTimeUnformatted = sdf.format(date).split(" ".toRegex()).dropLastWhile { it.isEmpty() }.toTypedArray()
val riseTime = riseTimeUnformatted[0] + " at " + riseTimeUnformatted[1] + "h"
holder.riseTime.text = riseTime
}*/
}
if (passTime != null && passTime.duration > -1) {
if (passTime.duration > -1) {
val duration = TimeUnit.SECONDS.toMinutes(passTime.duration.toLong())
val durationTime: String
if (duration >= 1) {
durationTime = "during " + java.lang.Long.toString(duration) + " min"
durationTime = if (duration >= 1) {
"during " + java.lang.Long.toString(duration) + " min"
} else {
durationTime = "during " + Integer.toString(passTime.duration) + " secs"
"during " + Integer.toString(passTime.duration) + " secs"
}
holder.duration.text = durationTime
}
return customView
}

inner class PassTimesViewHolder(view: View) : RecyclerView.ViewHolder(view) {
var riseTime = view.findViewById(R.id.riseTime) as TextView
var duration = view.findViewById(R.id.duration) as TextView
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,30 +3,48 @@ package com.ferranpons.spacehub.schedule
import android.content.Context
import android.os.Bundle
import android.support.v4.app.Fragment
import android.support.v7.widget.DefaultItemAnimator
import android.support.v7.widget.LinearLayoutManager
import android.support.v7.widget.RecyclerView
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import com.ferranpons.spacehub.R
import com.ferranpons.spacehub.issTracking.IssTrackingApi
import com.ferranpons.spacehub.issTracking.IssTrackingApiInterface
import com.ferranpons.spacehub.issTracking.IssTrackingInteractor
import com.ferranpons.spacehub.issTracking.IssTrackingPresenter
import com.ferranpons.spacehub.issTracking.IssTrackingPresenterInterface
import com.ferranpons.spacehub.issTracking.IssTrackingViewInterface
import com.ferranpons.spacehub.issTracking.IssTrackingPresenter
import com.ferranpons.spacehub.issTracking.IssTrackingInteractor
import com.ferranpons.spacehub.passTimes.PassTimesAdapter

class ScheduleFragment : Fragment(), IssTrackingViewInterface {
private lateinit var issTrackingPresenter: IssTrackingPresenterInterface
private lateinit var recyclerView: RecyclerView

companion object {
const val OPEN_NOTIFY_API = "http://api.open-notify.org"
}

override fun onAttach(context: Context?) {
super.onAttach(context)

issTrackingPresenter = IssTrackingPresenter(IssTrackingInteractor(IssTrackingApi.getIssTrackingApi("http://api.open-notify.org")))
issTrackingPresenter = IssTrackingPresenter(IssTrackingInteractor(IssTrackingApi.getIssTrackingApi(OPEN_NOTIFY_API)))
(issTrackingPresenter as IssTrackingPresenter).setView(this)
}

override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
val view = inflater.inflate(R.layout.fragment_schedule, container, false)
return view
return inflater.inflate(R.layout.fragment_schedule, container, false)
}

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)

val layoutManager = LinearLayoutManager(view.context)
recyclerView = view.findViewById(R.id.schedule_recyclerview)
recyclerView.layoutManager = layoutManager
recyclerView.setHasFixedSize(true)
recyclerView.itemAnimator = DefaultItemAnimator()
}

override fun onCreate(savedInstanceState: Bundle?) {
Expand All @@ -39,6 +57,7 @@ class ScheduleFragment : Fragment(), IssTrackingViewInterface {
}

override fun setIssPosition(position: IssTrackingApiInterface.IssPosition?) {
issTrackingPresenter.retrievePassTimes(position?.latitude!!, position.longitude)
}

override fun willRetrievePassTimes() {
Expand All @@ -60,6 +79,10 @@ class ScheduleFragment : Fragment(), IssTrackingViewInterface {
}

override fun showPassTimes(passTimes: MutableList<IssTrackingApiInterface.PassTime>?) {
val scheduleAdapter = PassTimesAdapter(passTimes!!)

recyclerView.adapter = scheduleAdapter
scheduleAdapter.notifyDataSetChanged()
}

override fun showPeopleInSpace(people: MutableList<IssTrackingApiInterface.Person>?) {
Expand Down
Loading