Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
SRCT
whats-open-android
Commits
0c726f03
Unverified
Commit
0c726f03
authored
Sep 22, 2019
by
Dylan Jones
Browse files
do some networking
parent
8ef821e8
Pipeline
#4784
passed with stages
in 3 minutes and 50 seconds
Changes
7
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
app/build.gradle
View file @
0c726f03
...
...
@@ -40,6 +40,11 @@ dependencies {
// insert added libraries here
implementation
'com.google.code.gson:gson:2.8.5'
implementation
'com.squareup.retrofit2:retrofit:2.6.1'
implementation
'com.squareup.retrofit2:adapter-rxjava2:2.6.1'
implementation
'com.squareup.retrofit2:converter-gson:2.6.1'
implementation
'io.reactivex.rxjava2:rxandroid:2.1.1'
implementation
'io.reactivex.rxjava2:rxjava:2.2.12'
testImplementation
'junit:junit:4.12'
androidTestImplementation
'androidx.test:runner:1.2.0'
...
...
app/src/main/AndroidManifest.xml
View file @
0c726f03
...
...
@@ -5,6 +5,8 @@
<dist:module
dist:instant=
"true"
/>
<uses-permission
android:name=
"android.permission.INTERNET"
/>
<application
android:allowBackup=
"true"
android:icon=
"@mipmap/ic_launcher"
...
...
app/src/main/java/srct/whatsopen/MainActivity.kt
View file @
0c726f03
package
srct.whatsopen
import
android.annotation.SuppressLint
import
android.os.Bundle
import
com.google.android.material.snackbar.Snackbar
import
androidx.appcompat.app.AppCompatActivity
import
android.view.Menu
import
android.view.MenuItem
import
android.widget.TextView
import
android.widget.Toast
import
androidx.swiperefreshlayout.widget.SwipeRefreshLayout
import
io.reactivex.android.schedulers.AndroidSchedulers
import
io.reactivex.schedulers.Schedulers
import
kotlinx.android.synthetic.main.activity_main.*
import
retrofit2.Retrofit
import
retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory
import
retrofit2.converter.gson.GsonConverterFactory
import
srct.whatsopen.util.WhatsOpenService
class
MainActivity
:
AppCompatActivity
()
{
private
var
service
:
WhatsOpenService
?
=
null
private
var
refreshLayout
:
SwipeRefreshLayout
?
=
null
override
fun
onCreate
(
savedInstanceState
:
Bundle
?)
{
super
.
onCreate
(
savedInstanceState
)
setContentView
(
R
.
layout
.
activity_main
)
setSupportActionBar
(
toolbar
)
fab
.
setOnClickListener
{
view
->
Snackbar
.
make
(
view
,
"Replace with your own action"
,
Snackbar
.
LENGTH_LONG
)
.
setAction
(
"Action"
,
null
).
show
()
}
val
retrofit
=
Retrofit
.
Builder
()
.
baseUrl
(
"https://api.srct.gmu.edu/whatsopen/v2/"
)
.
addCallAdapterFactory
(
RxJava2CallAdapterFactory
.
create
())
.
addConverterFactory
(
GsonConverterFactory
.
create
())
.
build
()
service
=
retrofit
.
create
(
WhatsOpenService
::
class
.
java
)
// setup refresh listener
refreshLayout
=
findViewById
<
SwipeRefreshLayout
>(
R
.
id
.
swipe_refresh
)
refreshLayout
!!
.
setOnRefreshListener
(
this
::
refresh
)
refresh
()
}
override
fun
onCreateOptionsMenu
(
menu
:
Menu
):
Boolean
{
...
...
@@ -35,4 +53,25 @@ class MainActivity : AppCompatActivity() {
else
->
super
.
onOptionsItemSelected
(
item
)
}
}
@SuppressLint
(
"CheckResult"
)
private
fun
refresh
()
{
refreshLayout
!!
.
isRefreshing
=
true
service
!!
.
getData
()
.
subscribeOn
(
Schedulers
.
io
())
.
doOnError
{
err
->
Toast
.
makeText
(
applicationContext
,
"Network Error: $err"
,
Toast
.
LENGTH_SHORT
).
show
()
}
.
observeOn
(
AndroidSchedulers
.
mainThread
())
.
subscribe
{
facilities
->
run
{
findViewById
<
TextView
>(
R
.
id
.
main_text
).
text
=
facilities
.
toString
()
refreshLayout
!!
.
isRefreshing
=
false
}
}
}
}
app/src/main/java/srct/whatsopen/util/WhatsOpenService.kt
0 → 100644
View file @
0c726f03
package
srct.whatsopen.util
import
io.reactivex.Observable
import
retrofit2.http.GET
import
srct.whatsopen.model.Facility
interface
WhatsOpenService
{
@GET
(
"facilities"
)
fun
getData
():
Observable
<
List
<
Facility
>>
}
\ No newline at end of file
app/src/main/res/layout/activity_main.xml
View file @
0c726f03
<?xml version="1.0" encoding="utf-8"?>
<androidx.coordinatorlayout.widget.CoordinatorLayout
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:tools=
"http://schemas.android.com/tools"
android:layout_width=
"match_parent"
android:layout_height=
"match_parent"
android:fitsSystemWindows=
"true"
android:orientation=
"vertical"
tools:context=
".MainActivity"
>
<com.google.android.material.appbar.AppBarLayout
android:id=
"@+id/app_bar"
android:fitsSystemWindows=
"true"
android:layout_height=
"@dimen/app_bar_height"
<androidx.appcompat.widget.Toolbar
android:id=
"@+id/toolbar"
android:layout_width=
"match_parent"
android:theme=
"@style/AppTheme.AppBarOverlay"
>
android:layout_height=
"wrap_content"
android:background=
"?attr/colorPrimary"
android:minHeight=
"?attr/actionBarSize"
android:theme=
"?attr/actionBarTheme"
>
<com.google.android.material.appbar.CollapsingToolbarLayout
android:id=
"@+id/toolbar_layout"
android:fitsSystemWindows=
"true"
<TextView
android:layout_width=
"match_parent"
android:layout_height=
"match_parent"
app:toolbarId=
"@+id/toolbar"
app:layout_scrollFlags=
"scroll|exitUntilCollapsed"
app:contentScrim=
"?attr/colorPrimary"
>
<androidx.appcompat.widget.Toolbar
android:id=
"@+id/toolbar"
android:layout_height=
"?attr/actionBarSize"
android:layout_width=
"match_parent"
app:layout_collapseMode=
"pin"
app:popupTheme=
"@style/AppTheme.PopupOverlay"
/>
android:layout_height=
"wrap_content"
android:text=
"@string/app_name"
android:textColor=
"@android:color/primary_text_dark"
android:textSize=
"18sp"
/>
</androidx.appcompat.widget.Toolbar>
</com.google.android.material.appbar.CollapsingToolbarLayout>
</com.google.android.material.appbar.AppBarLayout>
<include
layout=
"@layout/content_scrolling"
/>
<androidx.swiperefreshlayout.widget.SwipeRefreshLayout
android:id=
"@+id/swipe_refresh"
android:layout_width=
"match_parent"
android:layout_height=
"match_parent"
app:layout_behavior=
"@string/appbar_scrolling_view_behavior"
tools:context=
".MainActivity"
tools:showIn=
"@layout/activity_main"
>
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id=
"@+id/fab"
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:layout_margin=
"@dimen/fab_margin"
app:layout_anchor=
"@id/app_bar"
app:layout_anchorGravity=
"bottom|end"
app:srcCompat=
"@android:drawable/ic_dialog_email"
/>
<ScrollView
android:layout_width=
"match_parent"
android:layout_height=
"match_parent"
>
<LinearLayout
android:layout_width=
"match_parent"
android:layout_height=
"wrap_content"
android:orientation=
"vertical"
>
<TextView
android:id=
"@+id/main_text"
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:layout_margin=
"@dimen/text_margin"
android:text=
"@string/large_text"
/>
</LinearLayout>
</ScrollView>
</androidx.coordinatorlayout.widget.CoordinatorLayout>
\ No newline at end of file
</androidx.swiperefreshlayout.widget.SwipeRefreshLayout>
</LinearLayout>
\ No newline at end of file
app/src/main/res/layout/content_scrolling.xml
deleted
100644 → 0
View file @
8ef821e8
<?xml version="1.0" encoding="utf-8"?>
<androidx.core.widget.NestedScrollView
xmlns:android=
"http://schemas.android.com/apk/res/android"
xmlns:tools=
"http://schemas.android.com/tools"
xmlns:app=
"http://schemas.android.com/apk/res-auto"
app:layout_behavior=
"@string/appbar_scrolling_view_behavior"
tools:showIn=
"@layout/activity_main"
android:layout_width=
"match_parent"
android:layout_height=
"match_parent"
tools:context=
".MainActivity"
>
<TextView
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:layout_margin=
"@dimen/text_margin"
android:text=
"@string/large_text"
/>
</androidx.core.widget.NestedScrollView>
\ No newline at end of file
app/src/main/res/values/colors.xml
View file @
0c726f03
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color
name=
"colorPrimary"
>
#00
8577
</color>
<color
name=
"colorPrimaryDark"
>
#00
574B
</color>
<color
name=
"colorAccent"
>
#
D81B60
</color>
<color
name=
"colorPrimary"
>
#00
6633
</color>
<color
name=
"colorPrimaryDark"
>
#00
6633
</color>
<color
name=
"colorAccent"
>
#
FBC02D
</color>
</resources>
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment