share location to chat by button click

Signed-off-by: Marcel Hibbe <dev@mhibbe.de>
This commit is contained in:
Marcel Hibbe 2021-05-30 01:00:27 +02:00 committed by Andy Scherzinger
parent ae485d1d80
commit 095c13172c
No known key found for this signature in database
GPG key ID: 6CADC7E3523C308B
4 changed files with 61 additions and 2 deletions

View file

@ -406,4 +406,12 @@ public interface NcApi {
@GET
Call<ResponseBody> downloadResizedImage(@Header("Authorization") String authorization,
@Url String url);
@FormUrlEncoded
@POST
Observable<GenericOverall> sendLocation(@Header("Authorization") String authorization,
@Url String url,
@Field("objectType") String objectType,
@Field("objectId") String objectId,
@Field("metaData") String metaData);
}

View file

@ -822,7 +822,7 @@ class ChatController(args: Bundle) :
Log.d(TAG, "showShareLocationScreen")
val bundle = Bundle()
// bundle.putBoolean(, true)
bundle.putString(BundleKeys.KEY_ROOM_TOKEN,roomToken)
router.pushController(
RouterTransaction.with(LocationController(bundle))
.pushChangeHandler(HorizontalChangeHandler())

View file

@ -17,9 +17,18 @@ import androidx.preference.PreferenceManager
import autodagger.AutoInjector
import butterknife.BindView
import com.nextcloud.talk.R
import com.nextcloud.talk.api.NcApi
import com.nextcloud.talk.application.NextcloudTalkApplication
import com.nextcloud.talk.controllers.base.BaseController
import com.nextcloud.talk.models.json.generic.GenericOverall
import com.nextcloud.talk.utils.ApiUtils
import com.nextcloud.talk.utils.bundle.BundleKeys.KEY_ROOM_TOKEN
import com.nextcloud.talk.utils.database.user.UserUtils
import com.nextcloud.talk.utils.preferences.AppPreferences
import io.reactivex.Observer
import io.reactivex.android.schedulers.AndroidSchedulers
import io.reactivex.disposables.Disposable
import io.reactivex.schedulers.Schedulers
import org.osmdroid.config.Configuration.getInstance
import org.osmdroid.tileprovider.tilesource.TileSourceFactory
import org.osmdroid.util.GeoPoint
@ -32,6 +41,12 @@ import javax.inject.Inject
@AutoInjector(NextcloudTalkApplication::class)
class LocationController(args: Bundle) : BaseController(args) {
@Inject
lateinit var ncApi: NcApi
@Inject
lateinit var userUtils: UserUtils
@Inject
@JvmField
var appPreferences: AppPreferences? = null
@ -52,9 +67,13 @@ class LocationController(args: Bundle) : BaseController(args) {
@JvmField
var btnSelectLocation: Button? = null
var roomToken : String?
init {
NextcloudTalkApplication.sharedApplication!!.componentApplication.inject(this)
getInstance().load(context, PreferenceManager.getDefaultSharedPreferences(context))
roomToken = args.getString(KEY_ROOM_TOKEN)
}
override fun inflateView(inflater: LayoutInflater, container: ViewGroup): View {
@ -70,7 +89,35 @@ class LocationController(args: Bundle) : BaseController(args) {
btnSelectLocation?.setOnClickListener {
val selectedLat: Double? = map?.mapCenter?.latitude
val selectedLon: Double? = map?.mapCenter?.longitude
Toast.makeText(activity, "Lat: $selectedLat Lon: $selectedLon", Toast.LENGTH_LONG).show()
ncApi.sendLocation(
ApiUtils.getCredentials(userUtils.currentUser?.username, userUtils.currentUser?.token),
ApiUtils.getUrlToSendLocation(userUtils.currentUser?.baseUrl, roomToken),
"geo-location",
"geo:$selectedLat,$selectedLon",
"{\"type\":\"geo-location\",\"id\":\"geo:$selectedLat,$selectedLon\",\"latitude\":\"$selectedLat\"," +
"\"longitude\":\"$selectedLon\",\"name\":\"examplePlace\"}"
)
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(object : Observer<GenericOverall> {
override fun onSubscribe(d: Disposable) {
}
override fun onNext(t: GenericOverall) {
Log.d(TAG, "shared location")
router.popCurrentController()
}
override fun onError(e: Throwable) {
Log.e(TAG, "error when trying to share location", e)
Toast.makeText(context, R.string.nc_common_error_sorry, Toast.LENGTH_LONG).show()
router.popCurrentController()
}
override fun onComplete() {
}
})
}
}

View file

@ -389,4 +389,8 @@ public class ApiUtils {
public static String getUrlForUserFields(String baseUrl) {
return baseUrl + ocsApiVersion + "/cloud/user/fields";
}
public static String getUrlToSendLocation(String baseUrl, String roomToken) {
return baseUrl + ocsApiVersion + "/apps/spreed/api/v1/chat/" + roomToken + "/share";
}
}