diff options
author | Ognjen Cirkovic <ciraboxkg@gmail.com> | 2022-11-28 11:54:31 +0100 |
---|---|---|
committer | Ognjen Cirkovic <ciraboxkg@gmail.com> | 2022-11-28 11:54:31 +0100 |
commit | 9c3cebe6f89586d2abd5f854cf5baa079d839b39 (patch) | |
tree | 1ab92d8fe683d89d38998ddf552b290692bb81ac | |
parent | d945204fba909a2dfeb25cae2d320ab6e62eaf51 (diff) |
Napravljen dialog za dodavanje imena lokacije. Dodata logika dodavanje lokacije. Uplodovanje lokacije. Dodata provera na backu ukoliko nema tagova. Omoguceno dodavanje objave pomocu novog dodavanja lokacije.
3 files changed, 101 insertions, 82 deletions
diff --git a/Backend/Api/Api/Services/PostService.cs b/Backend/Api/Api/Services/PostService.cs index b75656e..e2e4e40 100644 --- a/Backend/Api/Api/Services/PostService.cs +++ b/Backend/Api/Api/Services/PostService.cs @@ -39,8 +39,11 @@ namespace Api.Services p.comments = new List<Comment>(); p.images = new List<Models.File>(); p.createdAt = DateTime.Now.ToUniversalTime(); - var tags = post.tags.Split("|").ToList(); - p.tags = tags; + if (post.tags != null) + { + var tags = post.tags.Split("|").ToList(); + p.tags = tags; + } var folderPath = Path.Combine(Directory.GetCurrentDirectory(), "Files", p.ownerId); if (!Directory.Exists(folderPath)) { diff --git a/Client/BrzoDoLokacije/app/src/main/java/com/example/brzodolokacije/Activities/ActivityAddPost.kt b/Client/BrzoDoLokacije/app/src/main/java/com/example/brzodolokacije/Activities/ActivityAddPost.kt index f29db17..c2abf37 100644 --- a/Client/BrzoDoLokacije/app/src/main/java/com/example/brzodolokacije/Activities/ActivityAddPost.kt +++ b/Client/BrzoDoLokacije/app/src/main/java/com/example/brzodolokacije/Activities/ActivityAddPost.kt @@ -53,33 +53,27 @@ class ActivityAddPost : AppCompatActivity() { private lateinit var tagButtonAdd:Button private lateinit var tagList: MutableList<String> private var tagidcounter:Int = 0 - val incorectCoord:Double=1000.0 val LOCATIONREQCODE=123 - var longitude:Double=incorectCoord - var latitude:Double=incorectCoord + var locationId:String?=null var progressDialog:ProgressDialog?=null private lateinit var addDescription:Button - //private var paths :ArrayList<String?>?=null + private var place=0; override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_add_post) -// Toast.makeText( -// applicationContext, "Add new ", Toast.LENGTH_LONG -// ).show(); + uploadedImages= ArrayList() tagList = mutableListOf() tagButtons= mutableListOf() tagidcounter = 0 - //paths= ArrayList() uploadFromGallery=findViewById<View>(R.id.btnActivityAddPostUploadFromGalleryVisible) as Button showNextImage=findViewById<View>(R.id.nextImage) as Button showPreviousImage=findViewById<View>(R.id.previousImage) as Button switcher=findViewById<View>(R.id.isActivityAddPostSwitcher) as ImageSwitcher - //location=findViewById<View>(R.id.etActivityAddPostLocation) as EditText description=findViewById<View>(R.id.etActivityAddPostDescription) as EditText post=findViewById<View>(R.id.btnActivityAddPostPost) as Button addLocation=findViewById<View>(R.id.btnActivityAddPostAddLocation) as Button @@ -205,11 +199,11 @@ class ActivityAddPost : AppCompatActivity() { description.hint="Unesite opis" description.setHintTextColor(Color.RED) } - if(longitude!=incorectCoord && latitude!=incorectCoord){ + if(locationId==null || locationId!!.trim()==""){ Toast.makeText(this,"Unesite lokaciju klikom na dugme",Toast.LENGTH_LONG) } - if(!locationString.isEmpty() && !descriptionString.isEmpty() && longitude!=incorectCoord && latitude!=incorectCoord && uploadedImages!!.size>0){ + if(!descriptionString.isEmpty() && uploadedImages!!.size>0){ sendPost() } } @@ -249,9 +243,7 @@ class ActivityAddPost : AppCompatActivity() { } if(requestCode==LOCATIONREQCODE && resultCode== RESULT_OK){ var bundle=data!!.extras - longitude=bundle!!.getDouble("longitude",incorectCoord) - latitude=bundle!!.getDouble("latitude",incorectCoord) - var locName=bundle!!.getString("name") + locationId=bundle!!.getString("locationId") } } private fun sendPost(){ @@ -259,58 +251,8 @@ class ActivityAddPost : AppCompatActivity() { } fun uploadLocation() { - //TO DO SEARCH EXISTING LOCATION FROM DB - //IF NOT EXISTS ADD NEW LOCATION - progressDialog!!.show() - val api =RetrofitHelper.getInstance() - var geocoder=GeocoderHelper.getInstance() - var loc1=geocoder!!.getFromLocation(latitude,longitude,1) - if(loc1==null ||loc1.size<=0) - { - progressDialog!!.dismiss() - Toast.makeText(this,"Lokacija ne postoji",Toast.LENGTH_LONG); - return - } - var countryName=loc1[0].countryName - var address="todo not possible in query" - var city="its null" - if(loc1[0].adminArea!=null) - city=loc1[0].adminArea//not possible - var loc:Location=Location("",locationString,city,countryName,address,latitude,longitude,LocationType.GRAD) - var jwtString= SharedPreferencesHelper.getValue("jwt",this) - var data=api.addLocation("Bearer "+jwtString,loc) - - data.enqueue(object : retrofit2.Callback<Location?> { - override fun onResponse(call: Call<Location?>, response: Response<Location?>) { - if(response.isSuccessful()){ - - uploadPost(response.body()!!._id) - Toast.makeText( - applicationContext, "USPEH", Toast.LENGTH_LONG - ).show(); - - }else { - progressDialog!!.dismiss() - - if (response.errorBody() != null) { - Log.d("Main",response.errorBody()!!.string()) - Log.d("Main",response.message()) - } - Log.d("Main",response.errorBody()!!.string()) - Log.d("Main",response.message()) - } - - - } - - override fun onFailure(call: Call<Location?>, t: Throwable) { - Toast.makeText( - applicationContext, t.toString(), Toast.LENGTH_LONG - ).show(); - Log.d("Main",t.toString()) - progressDialog!!.dismiss() - } - }) + if(locationId!=null && locationId!!.trim()!="") + uploadPost(locationId!!) } fun uploadPost(loc:String){ val api =RetrofitHelper.getInstance() diff --git a/Client/BrzoDoLokacije/app/src/main/java/com/example/brzodolokacije/Activities/MapsActivity.kt b/Client/BrzoDoLokacije/app/src/main/java/com/example/brzodolokacije/Activities/MapsActivity.kt index 46cc5fe..faaa3b4 100644 --- a/Client/BrzoDoLokacije/app/src/main/java/com/example/brzodolokacije/Activities/MapsActivity.kt +++ b/Client/BrzoDoLokacije/app/src/main/java/com/example/brzodolokacije/Activities/MapsActivity.kt @@ -1,7 +1,9 @@ package com.example.brzodolokacije.Activities import android.Manifest +import android.app.AlertDialog import android.content.Context +import android.content.DialogInterface import android.content.pm.PackageManager import android.graphics.Color import android.location.Location @@ -22,6 +24,7 @@ import androidx.appcompat.app.AppCompatActivity import androidx.core.app.ActivityCompat import androidx.core.content.ContextCompat import androidx.core.widget.addTextChangedListener +import com.example.brzodolokacije.Models.LocationType import com.example.brzodolokacije.Models.PostPreview import com.example.brzodolokacije.R import com.example.brzodolokacije.Services.GeocoderHelper @@ -88,8 +91,12 @@ class MapsActivity : AppCompatActivity() { getLocation() } confirmButton.setOnClickListener{ - if(locLatitude!=null && locLatitude!=null) + if(selectedLocation!=null) returnValue() + else{ + addLocation() + + } } searchBar.setOnKeyListener(View.OnKeyListener { v1, keyCode, event -> // If the event is a key-down event on the "enter" button if (event.action === KeyEvent.ACTION_DOWN && @@ -116,6 +123,73 @@ class MapsActivity : AppCompatActivity() { } + fun addLocation(){ + var editText=EditText(this) + var dialog=AlertDialog.Builder(this).setTitle("Naziv").setMessage("Unesite naziv") + .setView(editText) + dialog.setPositiveButton("Dodaj") { dialog, which -> + uploadLocation(editText.text.toString()) + } + dialog.setNegativeButton("Prekini") { dialog, which -> + + } + dialog.show() + + } + fun uploadLocation(locationName:String){ + val api =RetrofitHelper.getInstance() + var geocoder=GeocoderHelper.getInstance() + var loc1=geocoder!!.getFromLocation(locLatitude!!,locLongitude!!,1) + if(loc1==null ||loc1.size<=0) + { + return + } + var countryName=loc1[0].countryName + var address="todo not possible in query" + var city="its null" + if(loc1[0].adminArea!=null) + city=loc1[0].adminArea//not possible + var loc: com.example.brzodolokacije.Models.Location = + com.example.brzodolokacije.Models.Location( + "", + locationName, + city, + countryName, + address, + locLatitude!!, + locLongitude!!, + LocationType.GRAD + ) + var jwtString= SharedPreferencesHelper.getValue("jwt",this) + var data=api.addLocation("Bearer "+jwtString,loc) + + data.enqueue(object : retrofit2.Callback<com.example.brzodolokacije.Models.Location?> { + override fun onResponse(call: Call<com.example.brzodolokacije.Models.Location?>, response: Response<com.example.brzodolokacije.Models.Location?>) { + if(response.isSuccessful()){ + selectedLocation=response.body() + returnValue() + + }else { + + if (response.errorBody() != null) { + Log.d("Main",response.errorBody()!!.string()) + Log.d("Main",response.message()) + } + Log.d("Main",response.errorBody()!!.string()) + Log.d("Main",response.message()) + } + + + } + + override fun onFailure(call: Call<com.example.brzodolokacije.Models.Location?>, t: Throwable) { + Toast.makeText( + applicationContext, t.toString(), Toast.LENGTH_LONG + ).show(); + Log.d("Main",t.toString()) + } + }) + } var arraySpinner :MutableList<String>?=null var spinnerAdapter: ArrayAdapter<String>?=null @@ -128,11 +202,23 @@ class MapsActivity : AppCompatActivity() { searchBar.setAdapter(spinnerAdapter) searchBar.setOnItemClickListener(OnItemClickListener { parent, view, position, id -> val selected = parent.getItemAtPosition(position) as String - Log.d("Main",selected) + selectedLocation=responseLocations!!.find { location -> location.name==selected } + Log.d("main",selectedLocation.toString()) + confirmButton.visibility=View.VISIBLE }) } + fun returnValue(){ + val intent = intent + val bundle = Bundle() + if(selectedLocation==null) + return + bundle.putString("locationId",selectedLocation!!._id) + intent.putExtras(bundle) + setResult(RESULT_OK, intent) + finish() + } fun onTextEnter(){ var api=RetrofitHelper.getInstance() var jwtString= SharedPreferencesHelper.getValue("jwt",this) @@ -164,18 +250,6 @@ class MapsActivity : AppCompatActivity() { } - fun returnValue(){ - val intent = intent - val bundle = Bundle() - bundle.putDouble("longitude", locLongitude!!) - bundle.putDouble("latitude", locLatitude!!) - if(searchBar.text!=null && !searchBar.text.toString().equals("")) - bundle.putString("name", searchBar.text.toString()) - intent.putExtras(bundle) - setResult(RESULT_OK, intent) - finish() - } - override fun onResume() { super.onResume() map!!.onResume() |