-
Notifications
You must be signed in to change notification settings - Fork 0
11/17 milestone2 #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Yuki-YuXin
wants to merge
6
commits into
main
Choose a base branch
from
milestone2
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
de81e4d
11/17 milestone2
Yuki-YuXin 57941a5
Merge branch 'main' of https://github.com/Yuki-YuXin/assignment
Yuki-YuXin d52b47e
RecyclerView.Adapter
Yuki-YuXin 6b83fdf
refresh + text formart binding
Yuki-YuXin 42f8e9a
reply and action on comments
Yuki-YuXin 7757896
resolve milestone2 comments
Yuki-YuXin File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
app/src/main/java/com/example/assignment/BindingAdapters.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| package com.example.assignment | ||
|
|
||
| import android.provider.Settings.Global.getString | ||
| import android.util.Log | ||
| import android.widget.TextView | ||
| import androidx.databinding.BindingAdapter | ||
| import androidx.recyclerview.widget.RecyclerView | ||
| import com.example.assignment.adapter.MeteorsListAdapter | ||
| import com.example.assignment.model.MeteorData | ||
| import java.text.SimpleDateFormat | ||
| import java.util.* | ||
|
|
||
|
|
||
| /** | ||
| * Updates the data shown in the [RecyclerView]. | ||
| */ | ||
| @BindingAdapter("listData") | ||
| fun bindRecyclerView(recyclerView: RecyclerView, data: MutableList<MeteorData>?) { | ||
| val adapter = recyclerView.adapter as MeteorsListAdapter | ||
| if (data != null) { | ||
| adapter.submitList(data) | ||
| Log.d("Binding", data.toString()) | ||
| adapter.notifyDataSetChanged(); | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Transform mass attribute from Double to String with kg. | ||
| */ | ||
| @BindingAdapter("app:massText") | ||
| fun massText(view: TextView, mass: Double) { | ||
| view.text = String.format("%.1f", mass) + R.string.main_mass_unit | ||
| } | ||
|
|
||
| /** | ||
| * Transform date format. | ||
| */ | ||
| @BindingAdapter("app:dateText") | ||
| fun dateText(view: TextView, text: String) { | ||
| val format = SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss") | ||
| val date: Date = format.parse(text) | ||
| view.text = date.toString() | ||
| } | ||
|
|
||
| /** | ||
| * Combine reclat and reclong together | ||
| */ | ||
| @BindingAdapter("app:locationText") | ||
| fun locationText(view: TextView, meteor: MeteorData) { | ||
| view.text ='[' + meteor.reclat.toString() + ',' + meteor.reclong.toString() + ']' | ||
| } | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 9 additions & 8 deletions
17
app/src/main/java/com/example/assignment/model/MeteorData.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,12 +1,13 @@ | ||
| package com.example.assignment.model | ||
|
|
||
| import com.squareup.moshi.Json | ||
|
|
||
| open class MeteorData(){ | ||
| var id: String? = null | ||
| var mass = 0.0 | ||
| var name: String? = null | ||
| var reclat: String? = null | ||
| var reclong: String? = null | ||
| var year: String? = null | ||
|
|
||
| } | ||
| data class MeteorData( | ||
| @Json(name = "id") val id: String? = null, | ||
| @Json(name = "mass") val mass: Double = 0.0, | ||
| @Json(name = "name") val name: String? = null, | ||
| @Json(name = "reclat") val reclat: String? = null, | ||
| @Json(name = "reclong") val reclong: String? = null, | ||
| @Json(name = "year") val year: String? = null, | ||
| ) |
49 changes: 49 additions & 0 deletions
49
app/src/main/java/com/example/assignment/network/MeteorApiService.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| package com.example.assignment.network | ||
|
|
||
| import com.example.assignment.model.MeteorData | ||
| import com.squareup.moshi.Moshi | ||
| import com.squareup.moshi.kotlin.reflect.KotlinJsonAdapterFactory | ||
| import retrofit2.Retrofit | ||
| import retrofit2.converter.moshi.MoshiConverterFactory | ||
| import retrofit2.http.GET | ||
|
|
||
| private const val BASE_URL = "https://data.nasa.gov/" | ||
|
|
||
| /** | ||
| * Build the Moshi object that Retrofit will be using, making sure to add the Kotlin adapter for | ||
| * full Kotlin compatibility. | ||
| */ | ||
| private val moshi = Moshi.Builder() | ||
| .add(KotlinJsonAdapterFactory()) | ||
| .build() | ||
|
|
||
| /** | ||
| * Use the Retrofit builder to build a com.example.assignment.network.retrofit object using a Moshi converter with our Moshi | ||
| * object. | ||
| */ | ||
| private val retrofit = Retrofit.Builder() | ||
| .addConverterFactory(MoshiConverterFactory.create(moshi)) | ||
| .baseUrl(BASE_URL) | ||
| .build() | ||
|
|
||
| /** | ||
| * A public interface that exposes the [getMeteorsInfo] method | ||
| */ | ||
| interface MeteorsApiService { | ||
| /** | ||
| * Returns a [MutableList] of [MeteorData] and this method can be called from a Coroutine. | ||
| * The @GET annotation indicates that the "photos" endpoint will be requested with the GET | ||
| * HTTP method | ||
| */ | ||
| @GET("resource/y77d-th95.json?\$where=year>='1900-01-01T00:00:00.000'")//&\$limit=15") | ||
| suspend fun getMeteorsInfo(): MutableList<MeteorData> | ||
| } | ||
|
|
||
| /** | ||
| * A public Api object that exposes the lazy-initialized Retrofit service | ||
| */ | ||
| object MeteorsApi { | ||
| val retrofitService: MeteorsApiService by lazy { | ||
| retrofit.create(MeteorsApiService::class.java) | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.