diff --git a/app/build.gradle b/app/build.gradle index ced48f5..19f2e3e 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -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' @@ -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' diff --git a/app/src/main/java/com/ferranpons/spacehub/passTimes/PassTimesAdapter.kt b/app/src/main/java/com/ferranpons/spacehub/passTimes/PassTimesAdapter.kt index a6f51f6..5720623 100644 --- a/app/src/main/java/com/ferranpons/spacehub/passTimes/PassTimesAdapter.kt +++ b/app/src/main/java/com/ferranpons/spacehub/passTimes/PassTimesAdapter.kt @@ -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) : ArrayAdapter(context, R.layout.row_pass_time, passTimes) { +class PassTimesAdapter(private val passTimes: List) : RecyclerView.Adapter() { - 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(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 } } diff --git a/app/src/main/java/com/ferranpons/spacehub/schedule/ScheduleFragment.kt b/app/src/main/java/com/ferranpons/spacehub/schedule/ScheduleFragment.kt index 9592a01..34af163 100644 --- a/app/src/main/java/com/ferranpons/spacehub/schedule/ScheduleFragment.kt +++ b/app/src/main/java/com/ferranpons/spacehub/schedule/ScheduleFragment.kt @@ -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?) { @@ -39,6 +57,7 @@ class ScheduleFragment : Fragment(), IssTrackingViewInterface { } override fun setIssPosition(position: IssTrackingApiInterface.IssPosition?) { + issTrackingPresenter.retrievePassTimes(position?.latitude!!, position.longitude) } override fun willRetrievePassTimes() { @@ -60,6 +79,10 @@ class ScheduleFragment : Fragment(), IssTrackingViewInterface { } override fun showPassTimes(passTimes: MutableList?) { + val scheduleAdapter = PassTimesAdapter(passTimes!!) + + recyclerView.adapter = scheduleAdapter + scheduleAdapter.notifyDataSetChanged() } override fun showPeopleInSpace(people: MutableList?) { diff --git a/app/src/main/res/layout/fragment_schedule.xml b/app/src/main/res/layout/fragment_schedule.xml index de144fa..084f537 100644 --- a/app/src/main/res/layout/fragment_schedule.xml +++ b/app/src/main/res/layout/fragment_schedule.xml @@ -1,8 +1,103 @@ - + android:layout_height="match_parent" + android:orientation="vertical"> - \ No newline at end of file + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/loading_custom_view.xml b/app/src/main/res/layout/loading_custom_view.xml new file mode 100644 index 0000000..efbf65e --- /dev/null +++ b/app/src/main/res/layout/loading_custom_view.xml @@ -0,0 +1,23 @@ + + + + + + \ No newline at end of file diff --git a/app/src/main/res/values/dimens.xml b/app/src/main/res/values/dimens.xml new file mode 100644 index 0000000..55b13a7 --- /dev/null +++ b/app/src/main/res/values/dimens.xml @@ -0,0 +1,21 @@ + + + 16dp + 16dp + + 72dp + 48dp + 56dp + 40dp + 32dp + 36dp + 24dp + 20dp + 16dp + 12dp + 10dp + 8dp + 6dp + 4dp + 2dp + diff --git a/app/src/main/res/values/styles.xml b/app/src/main/res/values/styles.xml index dee0b47..55ea946 100644 --- a/app/src/main/res/values/styles.xml +++ b/app/src/main/res/values/styles.xml @@ -1,7 +1,7 @@