Skip to content
Snippets Groups Projects
Commit 32beb375 authored by Mgs. Tabrani's avatar Mgs. Tabrani
Browse files

resolve conflict

parents c8ddbae3 40142ac6
Branches dev
2 merge requests!14final push part 2,!13Final push
Showing
with 2 additions and 591 deletions
plugins { plugins {
id 'com.android.application' id 'com.android.application'
id 'kotlin-android' id 'kotlin-android'
id 'kotlin-android-extensions'
} }
android { android {
...@@ -33,38 +32,12 @@ android { ...@@ -33,38 +32,12 @@ android {
} }
dependencies { dependencies {
apply plugin: 'kotlin-android-extensions'
implementation 'androidx.core:core-ktx:1.7.0' implementation 'androidx.core:core-ktx:1.7.0'
implementation 'androidx.appcompat:appcompat:1.4.1' implementation 'androidx.appcompat:appcompat:1.4.1'
implementation 'com.google.android.material:material:1.5.0' implementation 'com.google.android.material:material:1.5.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.3' implementation 'androidx.constraintlayout:constraintlayout:2.1.3'
implementation 'androidx.navigation:navigation-fragment-ktx:2.4.1'
implementation 'androidx.navigation:navigation-ui-ktx:2.4.1'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
testImplementation 'junit:junit:4.+' testImplementation 'junit:junit:4.+'
// Retrofit
implementation 'com.google.code.gson:gson:2.9.0'
implementation 'com.squareup.retrofit2:retrofit:2.9.0'
implementation 'com.squareup.retrofit2:converter-gson:2.9.0'
// Okhttp3 for the POST requests
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.6.0'
implementation 'com.squareup.okhttp3:okhttp:4.9.0'
// View
implementation 'androidx.recyclerview:recyclerview:1.2.1'
implementation 'androidx.cardview:cardview:1.0.0'
// QRScanner
implementation 'com.journeyapps:zxing-android-embedded:4.3.0'
// Location
implementation 'com.google.android.gms:play-services-location:19.0.1'
androidTestImplementation 'androidx.test.ext:junit:1.1.3' androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0' androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
implementation 'com.github.bumptech.glide:glide:4.13.0'
annotationProcessor 'com.github.bumptech.glide:compiler:4.13.0'
} }
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" <manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.example.perludilindungi"> package="com.example.perludilindungi">
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.CAMERA" />
<application <application
android:allowBackup="true" android:allowBackup="true"
android:icon="@mipmap/ic_launcher" android:icon="@mipmap/ic_launcher"
...@@ -16,26 +10,14 @@ ...@@ -16,26 +10,14 @@
android:supportsRtl="true" android:supportsRtl="true"
android:theme="@style/Theme.PerluDilindungi"> android:theme="@style/Theme.PerluDilindungi">
<activity <activity
android:name=".checkin" android:name=".MainActivity"
android:exported="true" android:exported="true">
android:parentActivityName=".MainActivity"/>
<activity
android:name=".SplashScreen"
android:exported="true"
android:theme="@style/Theme.AppCompat.Light.NoActionBar">
<intent-filter> <intent-filter>
<action android:name="android.intent.action.MAIN" /> <action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" /> <category android:name="android.intent.category.LAUNCHER" />
</intent-filter> </intent-filter>
</activity> </activity>
<activity
android:name=".MainActivity"
android:exported="true"></activity>
<activity
android:name="com.journeyapps.barcodescanner.CaptureActivity"
android:screenOrientation="portrait"
tools:replace="screenOrientation" />
</application> </application>
</manifest> </manifest>
\ No newline at end of file
app/src/main/ic_launcher-playstore.png

58.8 KiB

package com.example.perludilindungi
import com.example.perludilindungi.Model.DaerahResponse
import com.example.perludilindungi.Model.FaskesResponse
import com.example.perludilindungi.Model.NewsModel
import okhttp3.RequestBody
import okhttp3.ResponseBody
import retrofit2.Response
import retrofit2.Call
import retrofit2.Retrofit
import retrofit2.converter.gson.GsonConverterFactory
import retrofit2.http.Body
import retrofit2.http.GET
import retrofit2.http.POST
import retrofit2.http.Query
interface PerluDilindungiService {
@GET("api/get-province")
fun getProvince(): Call<DaerahResponse>
@GET("api/get-city")
fun getCity(@Query("start_id") start_id: String?): Call<DaerahResponse>
@GET("api/get-faskes-vaksinasi")
fun getFaskes(@Query("province") province: String?, @Query("city") city: String?): Call<FaskesResponse>
@GET("api/get-news")
fun getNews(): Call<NewsModel>
@POST("/check-in")
suspend fun checkIn(@Body requestBody: RequestBody): Response<ResponseBody>
companion object{
var BASE_URL: String = "https://perludilindungi.herokuapp.com/"
fun create(): PerluDilindungiService {
val retrofit = Retrofit.Builder()
.addConverterFactory(GsonConverterFactory.create())
.baseUrl(BASE_URL)
.build()
return retrofit.create(PerluDilindungiService::class.java)
}
}
}
\ No newline at end of file
package com.example.perludilindungi package com.example.perludilindungi
import android.content.Intent
import androidx.appcompat.app.AppCompatActivity import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle import android.os.Bundle
import androidx.navigation.findNavController
import androidx.navigation.ui.setupWithNavController
import com.google.android.material.bottomnavigation.BottomNavigationView
import com.google.android.material.floatingactionbutton.FloatingActionButton
class MainActivity : AppCompatActivity() { class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
......
package com.example.perludilindungi.Model
import com.google.gson.annotations.SerializedName
data class CheckInResponse(
@SerializedName("userStatus")
val userStatus : String?,
@SerializedName("reason")
val reason : String?
)
\ No newline at end of file
package com.example.perludilindungi.Model
data class Daerah(val key: String) {
override fun toString(): String {
return key
}
}
package com.example.perludilindungi.Model
data class DaerahResponse(val message : String?, val results : ArrayList<Daerah>)
package com.example.perludilindungi.Model
class EnclosureModel {
val _url : String = "null"
get() {
return field
}
}
\ No newline at end of file
package com.example.perludilindungi.Model
data class Faskes(val kode: String?,
val nama: String?,
val alamat: String?,
val telp: String?,
val jenis_faskes: String?,
val status: String?,
val latitude: String?,
val longitude: String?)
\ No newline at end of file
package com.example.perludilindungi.Model
data class FaskesResponse(val message : String?, val data : ArrayList<Faskes>)
package com.example.perludilindungi.Model
class NewsModel {
val count_total : Int = 0
get() {
return field
}
val results : Array<ResultNews>? = null
get() {
return field
}
}
package com.example.perludilindungi.Model
import com.google.gson.annotations.SerializedName
data class PostResponse(val message : String?, val results : List<Any>)
\ No newline at end of file
package com.example.perludilindungi.Model
class ResultNews {
val title : String = "null"
get() {
return field
}
val pubDate : String = "null"
get() {
return field
}
val guid : String = "null"
get() {
return field
}
val enclosure : EnclosureModel? = null
get() {
return field
}
}
\ No newline at end of file
package com.example.perludilindungi
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.webkit.WebSettings
import android.webkit.WebView
import androidx.fragment.app.Fragment
class News_Webview : Fragment() {
override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
val bundle:Bundle? = arguments
val urlData : String? = bundle?.getString("urlNews")
val myView = inflater.inflate(R.layout.fragment_news_webview, container, false)
val webView : WebView = myView.findViewById(R.id.news_webview)
webView.loadUrl(urlData.toString())
val webSettings : WebSettings = webView.settings
webSettings.javaScriptEnabled
return myView
}
}
\ No newline at end of file
package com.example.perludilindungi
import android.annotation.SuppressLint
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.ImageView
import android.widget.TextView
import androidx.appcompat.app.AppCompatActivity
import androidx.recyclerview.widget.RecyclerView
import com.bumptech.glide.Glide
import com.example.perludilindungi.Model.NewsModel
class RecyclerAdapter(val results : NewsModel?) : RecyclerView.Adapter<RecyclerAdapter.ViewHolder>() {
inner class ViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView){
var itemTitle: TextView = itemView.findViewById(R.id.news_title)
var itemImage: ImageView = itemView.findViewById(R.id.news_image)
var itemDate: TextView = itemView.findViewById(R.id.news_date)
}
override fun onCreateViewHolder(viewGroup: ViewGroup, i: Int): ViewHolder {
val v = LayoutInflater.from(viewGroup.context)
.inflate(R.layout.card_news, viewGroup, false)
return ViewHolder(v)
}
override fun onBindViewHolder(viewHolder: ViewHolder, @SuppressLint("RecyclerView") i: Int) {
viewHolder.itemTitle.text = results?.results?.get(i)?.title
viewHolder.itemDate.text = results?.results?.get(i)?.pubDate
Glide.with(viewHolder.itemImage)
.load(results?.results?.get(i)?.enclosure?._url)
.into(viewHolder.itemImage)
viewHolder.itemView.setOnClickListener(object : View.OnClickListener{
override fun onClick(v: View?) {
val bundle = Bundle()
bundle.putString(
"urlNews",
results?.results?.get(i)?.guid.toString()
)
val webViewFragment = News_Webview()
webViewFragment.arguments = bundle
val activity = v?.context as AppCompatActivity
activity.supportFragmentManager.beginTransaction().replace(R.id.news_fragment, webViewFragment).addToBackStack(null).commit()
}
})
}
override fun getItemCount(): Int {
return results?.count_total!!
}
}
\ No newline at end of file
package com.example.perludilindungi
import android.content.Intent
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.os.Handler
import android.view.WindowManager
@Suppress("DEPRECATION")
class SplashScreen : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_splash_screen)
// Remove top bar
window.setFlags(
WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN,
)
Handler().postDelayed({
val intent = Intent(this, MainActivity::class.java)
startActivity(intent)
finish()
}, 3000)
}
}
\ No newline at end of file
package com.example.perludilindungi
import android.os.Bundle
import androidx.fragment.app.Fragment
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.example.perludilindungi.Model.Faskes
import kotlinx.android.synthetic.main.fragment_bookmark.*
class bookmark : Fragment() {
private var layoutManager: RecyclerView.LayoutManager? = null
private var adapter: RecyclerView.Adapter<FaskesAdapter.ViewHolder>? = null
override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
// Inflate the layout for this fragment
return inflater.inflate(R.layout.fragment_bookmark, container, false)
}
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
val dataFaskes = ArrayList<Faskes>()
val faskes1 = Faskes("0112R066", "RSUD PASAR MINGGU", "Jl. TB Simatupang No.1, RT.1/RW.5, Ragunan, Kec. Ps. Minggu, Kota Jakarta Selatan, Daerah Khusus Ibukota Jakarta 12550, Indonesia", "(021) 29059999", "RUMAH SAKIT", "Siap Vaksinasi", "-6.2941632", "106.8199995")
val faskes2 = Faskes("9020100", "KEC. TEBET", "Jl. Tebet Timur II No.6, RT.6/RW.5, Tebet Tim., Kec. Tebet, Kota Jakarta Selatan, Daerah Khusus Ibukota Jakarta 12820, Indonesia", "(021) 8350632", "PUSKESMAS", "Siap Vaksinasi", "-6.2353314", "106.8567144")
val faskes3 = Faskes("N0002025", "KU MEDIKA PLAZA WTC 2", "Jl. TB. Simatupang Kav. 41, BELTWAY OFFICE PARK, ANNEX BUILDING, Ground Floor, Jakarta Selatan, RT.7/RW.2, Ragunan, Kec. Ps. Minggu, Kota Jakarta Selatan, Daerah Khusus Ibukota Jakarta 12550, Indonesia", "(021) 80866099", "", "Siap Vaksinasi", "6.2911926", "106.8182204")
dataFaskes.add(faskes1)
dataFaskes.add(faskes2)
dataFaskes.add(faskes3)
recycler_faskes.apply {
layoutManager = LinearLayoutManager(activity)
adapter = FaskesAdapter(dataFaskes)
}
}
}
\ No newline at end of file
package com.example.perludilindungi
import android.content.Context
import android.content.Intent
import android.content.pm.PackageManager
import android.graphics.Bitmap
import android.graphics.Color
import android.hardware.Sensor;
import android.hardware.SensorEvent;
import android.hardware.SensorEventListener;
import android.hardware.SensorManager;
import android.location.Location
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.util.Log
import android.view.Window
import android.widget.Button
import android.widget.ImageView
import android.widget.TextView
import com.google.zxing.BarcodeFormat
import com.google.zxing.integration.android.IntentIntegrator
import com.google.zxing.qrcode.QRCodeWriter
import android.widget.Toast
import androidx.core.app.ActivityCompat
import com.google.android.gms.location.FusedLocationProviderClient
import com.google.android.gms.location.LocationServices
import com.google.android.gms.tasks.Task
import com.google.gson.GsonBuilder
import com.google.gson.JsonParser
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import okhttp3.MediaType.Companion.toMediaTypeOrNull
import okhttp3.RequestBody.Companion.toRequestBody
import org.json.JSONObject
import org.json.JSONTokener
class checkin : AppCompatActivity(), SensorEventListener {
private lateinit var sensorManager: SensorManager
lateinit var fusedLocationProviderClient: FusedLocationProviderClient
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
requestWindowFeature(Window.FEATURE_NO_TITLE); //will hide the title
getSupportActionBar()?.hide(); // hide the title bar
setContentView(R.layout.activity_checkin)
val back = findViewById<Button>(R.id.back_button)
back.setOnClickListener {
finish()
}
val intentIntegrator = IntentIntegrator(this)
intentIntegrator.setPrompt("Please focus the camera on the QR Code");
intentIntegrator.setOrientationLocked(false);
intentIntegrator.setDesiredBarcodeFormats(listOf(IntentIntegrator.QR_CODE))
intentIntegrator.initiateScan()
sensorManager = getSystemService(Context.SENSOR_SERVICE) as SensorManager
fusedLocationProviderClient = LocationServices.getFusedLocationProviderClient(this)
}
private fun getResponse(contents: String, latitude: Double, longitude: Double) {
val resultView = findViewById<ImageView>(R.id.result)
val resultText = findViewById<TextView>(R.id.textResult)
val jsonObject = JSONObject()
jsonObject.put("qrCode", contents)
jsonObject.put("latitude", latitude)
jsonObject.put("longitude", longitude)
val jsonObjectString = jsonObject.toString()
val requestBody = jsonObjectString.toRequestBody("application/json".toMediaTypeOrNull())
CoroutineScope(Dispatchers.IO).launch {
val response = PerluDilindungiService.create().checkIn(requestBody)
withContext(Dispatchers.Main) {
if (response.isSuccessful) {
val gson = GsonBuilder().setPrettyPrinting().create()
val prettyJson = gson.toJson(JsonParser.parseString(response.body()?.string()))
val jsonObject = JSONTokener(prettyJson).nextValue() as JSONObject
val data = jsonObject.getJSONObject("data")
val userStatus = data.getString("userStatus")
if (userStatus == "red" || userStatus == "black"){
val reason = data.getString("reason")
resultView.setImageResource(R.drawable.ic_declined)
resultText.text = "Gagal\n" + reason
} else {
resultView.setImageResource(R.drawable.ic_accepted)
resultText.text = "Berhasil"
}
Log.d("check-in Response :", prettyJson)
} else {
resultView.setImageResource(R.drawable.ic_declined)
resultText.text = "Gagal\n" + response.message()
Log.e("RETROFIT_ERROR", response.code().toString())
}
}
}
}
private fun fetchLocation(contents : String) {
val task : Task<Location> = fusedLocationProviderClient.lastLocation
if (ActivityCompat.checkSelfPermission(
this,
android.Manifest.permission.ACCESS_COARSE_LOCATION
) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(
this,
android.Manifest.permission.ACCESS_FINE_LOCATION
) != PackageManager.PERMISSION_GRANTED
) {
ActivityCompat.requestPermissions(
this,
arrayOf(
android.Manifest.permission.ACCESS_FINE_LOCATION,
android.Manifest.permission.ACCESS_COARSE_LOCATION
),
101
)
return
}
task.addOnSuccessListener {
if (it != null) {
getResponse(contents,it.latitude,it.longitude)
}
}
}
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
super.onActivityResult(requestCode, resultCode, data)
var result = IntentIntegrator.parseActivityResult(resultCode, data)
if (result != null) {
generateQRCode(result.contents)
fetchLocation(result.contents)
} else {
// do nothing
}
}
private fun generateQRCode(content: String) {
val writer = QRCodeWriter()
val bitMatrix = writer.encode(content, BarcodeFormat.QR_CODE, 512, 512)
val width = bitMatrix.width
val height = bitMatrix.height
val bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.RGB_565)
for (x in 0 until width) {
for (y in 0 until height) {
bitmap.setPixel(x, y, if (bitMatrix.get(x, y)) Color.BLACK else Color.WHITE)
}
}
val imageView = findViewById<ImageView>(R.id.cameraView)
imageView.setImageBitmap(bitmap)
}
override fun onSensorChanged(event: SensorEvent) {
val temperature = findViewById<TextView>(R.id.temperature)
temperature.text = event.values[0].toString()
}
override fun onAccuracyChanged(sensor: Sensor, accuracy: Int) {
// do nothing
}
override fun onResume() {
super.onResume()
loadAmbientTemperature();
}
override fun onPause() {
super.onPause()
sensorManager.unregisterListener(this)
}
private fun loadAmbientTemperature() {
val sensor = sensorManager.getDefaultSensor(Sensor.TYPE_AMBIENT_TEMPERATURE)
if (sensor != null) {
sensorManager.registerListener(this, sensor, SensorManager.SENSOR_DELAY_FASTEST)
} else {
Toast.makeText(this, "No Ambient Temperature Sensor !", Toast.LENGTH_LONG).show()
}
}
}
package com.example.perludilindungi
import android.os.Bundle
import android.util.Log
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.Fragment
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.example.perludilindungi.Model.NewsModel
import com.example.perludilindungi.Model.PostResponse
import kotlinx.android.synthetic.main.fragment_news.*
import retrofit2.Call
import retrofit2.Callback
import retrofit2.Response
class news : Fragment() {
private var layoutManager: RecyclerView.LayoutManager? = null
private var adapter: RecyclerView.Adapter<RecyclerAdapter.ViewHolder>? = null
override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
// Inflate the layout for this fragment
return inflater.inflate(R.layout.fragment_news, container, false)
}
override fun onViewCreated(itemView: View, savedInstanceState: Bundle?) {
super.onViewCreated(itemView, savedInstanceState)
PerluDilindungiService.create().getNews()
.enqueue(object : Callback<NewsModel>{
override fun onResponse(call: Call<NewsModel>?, response: Response<NewsModel>?) {
if (response != null) {
if(response.isSuccessful) {
Log.i("news", response.body()?.count_total.toString())
recycler_view.apply {
layoutManager = LinearLayoutManager(activity)
adapter = RecyclerAdapter(response.body())
}
}
}
}
override fun onFailure(call: Call<NewsModel>?, t: Throwable?) {
Log.i("get","failed")
}
})
}
}
\ No newline at end of file
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment