Private Fun

Private Fun



🔞 ALL INFORMATION CLICK HERE 👈🏻👈🏻👈🏻

































Private Fun
I am writing an application with Kotlin and Retrotif 2.
demo_wiki_search_count - A demo of Kotlin and Retrofit to read from Wiki API the hit count given.
How Retrofit Network Fetch API has evolved with the trend
Sometimes due to network fetching, we need to add Thread.sleep(..) or SystemClock.sleep(...) so that our instrumental…
Passionate about learning, and sharing mobile development and others https://twitter.com/elye_project https://www.facebook.com/elye.proj
Sharing iOS, Android and relevant Mobile App Development Technology and Learning
This blog, I will show you how to use Kotlin and Retrofit to read data from a server. Here, I also supply together the actual code example. Other than learning the general network call related info, hopefully you’ll get a few gist on Kotlin features that could be handy.
The tutorial here will guide you to create an App that allow you enter a keyword, and show you how many search-count it has on wiki as the image below shows. You can get the code at the bottom of the page. The explanation of how to get there in the following sections.
Instead of creating our own server, let’s use an existing popular API readily available, so we could focus on just creating the Android side of code. Here we use wiki provided API that given a search-string , it will return the search-count of the hit for the provided search-string .
i.e. we’ll perform a search on https://en.wikipedia.org/w/api.php?action=query&format=json&list=search&srsearch=Trump , it will return JSON result as below, with totalhits as the count we wanted.
Also note, in the URL given, there are 4 parameters i.e. action , format , list and srsearch . For the first 3, we’ll just fix the inputs to query , json and search , while the last one is the search-string we’ll have the user provide.
As we have seen the JSON data up there, we are actually only interested in totalhits . Since it is contained under searchinfo and query JSON scope, to simplify the transformation of our data model, we’ll model it according to the JSON, defining it as Kotlin data class as below
Also do note that I wrap them in Model object, as that allows me to preserved the class easily from proguard obfuscate as described in
Now, to use Retrofit, you’ll need to add the library to your gradle. Besides, you’ll also need the Rxjava library and the gson converter library, as that’s the best way to fetch data from the server known today, and automatically transform it from JSON to your data model.
Add the followings to your build.gradle
Also, don’t forget to add the needed Internet Permission in your AndroidManifest.xml
With the libraries included, now let’s get to the Retrofit 2 interface services definition. We define a service interface called WikiApiService . Since we only focus on one single API call, with 4 parameters of queries, I define them as below, matching the endpoint API service mentioned above.
Note: the result is return as Model.Result , and as a Observable , which is a Rxjava object that could analog as the endpoint fetcher result generator.
Once your interface is defined, you could add a static method (in your WikiApiService interface scope) that generates your retrofit service. Kotlin companion object is used to make the create function below resembler the static method of Java Factory pattern.
Here, we use the default Adaptor factory that convert between Rx Observables to Call type of retrofit, and also the default GsonConverter object.
The base Endpoint is also defined here https://en.wikipedia.org/w/ .
Once all that has been defined, it’s time for the fun bit: Fetch the data!
But before that, let’s defined two global variables
Finally after much preparation, now you could fetch your data from wikipedia by providing the srsearch keyworld. I wrote a function below
This is so far the best model that allows a network to be done in background and post the result in mainThread.
Last and not least, we need to remember, since the fetching is happening on background asynchronously, there’s a possibility your activity could be terminated before the background fetch is done. So it is very important to stop the fetching mission whenever your activity is terminated.
Fortunately, using Rxjava, the disposable that we have instantiated does link to the Rx fetching handling. We could get it to terminate the process by calling dispose as below
I do it onPause , but one could handle it onDestroy or wherever make sense to your code.
Hopes you learn something, either a little Retrofit 2.0, Rxjava 2.0 or some thing about Kotlin.
Oh yes, you could get the code from
If you like to see the coroutine approach, look at this blog.
If you like to explore on how to write test for it, check out
Thanks for reading. You can check out my other topics here .
You can follow me on Medium , Twitter , Facebook , and Reddit for little tips and learning on mobile development, medium writing, etc related topics. ~Elye~

android - Why can I access a private fun outside... - Stack Overflow
Kotlin and Retrofit 2: Tutorial with working codes | by Elye | Medium
LocationListener With Kotlin - Kotlin Codes
Kotlin Koin - Android Tutorial for Beginners - Step By Step Guide
Private Fun - YouTube

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:layout_width = "match_parent"
android:layout_marginRight = "12dp"
android:layout_height = "wrap_content"
android:text = "Start Location UPDates" />
android:layout_width = "match_parent"
android:layout_marginRight = "12dp"
android:layout_height = "wrap_content"
android:text = "Stop Location UPDates" />
android:layout_marginRight = "12dp"
android:layout_width = "wrap_content"
android:layout_gravity = "center_horizontal"
android:layout_height = "wrap_content"
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
fun checkPermissionForLocation ( context : Context) : Boolean {
return if (Build . VERSION . SDK_INT >= Build . VERSION_CODES . M) {
if (context . checkSelfPermission(Manifest . permission . ACCESS_FINE_LOCATION ) ==
PackageManager . PERMISSION_GRANTED ){
ActivityCompat . requestPermissions( this , arrayOf(android . Manifest . permission . ACCESS_FINE_LOCATION ),
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
override fun onRequestPermissionsResult ( requestCode : Int , permissions : Array< out String >, grantResults : IntArray ) {
if (requestCode == REQUEST_PERMISSION_LOCATION ) {
if (grantResults[ 0 ] == PackageManager . PERMISSION_GRANTED ) {
// We have to add startlocationUpdate() method later instead of Toast
Toast . makeText( this , " Permission granted " ,Toast . LENGTH_SHORT ) . show()
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
private fun buildAlertMessageNoGps () {
val builder = AlertDialog . Builder( this )
builder . setMessage( " Your GPS seems to be disabled, do you want to enable it? " )
. setPositiveButton( " Yes " ) { dialog, id ->
startActivityForResult(Intent(Settings . ACTION_LOCATION_SOURCE_SETTINGS )
. setNegativeButton( " No " ) { dialog, id ->
val alert : AlertDialog = builder . create()
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
private val mLocationCallback = object : LocationCallback () {
override fun onLocationResult ( locationResult : LocationResult) {
onLocationChanged(locationResult . lastLocation)
fun onLocationChanged ( location : Location) {
// New location has now been determined
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
protected fun startLocationUpdates () {
// Create the location request to start receiving updates
mLocationRequest = LocationRequest()
mLocationRequest !! . priority = LocationRequest . PRIORITY_HIGH_ACCURACY
mLocationRequest !! . setInterval(INTERVAL)
mLocationRequest !! . setFastestInterval(FASTEST_INTERVAL)
// Create LocationSettingsRequest object using location request
val builder = LocationSettingsRequest . Builder()
builder . addLocationRequest(mLocationRequest !! )
val locationSettingsRequest = builder . build()
val settingsClient = LocationServices . getSettingsClient( this )
settingsClient . checkLocationSettings(locationSettingsRequest)
mFusedLocationProviderClient = LocationServices . getFusedLocationProviderClient( this )
// new Google API SDK v11 uses getFusedLocationProviderClient(this)
if (ActivityCompat . checkSelfPermission( this , Manifest . permission . ACCESS_FINE_LOCATION ) != PackageManager . PERMISSION_GRANTED && ActivityCompat . checkSelfPermission( this , Manifest . permission . ACCESS_COARSE_LOCATION ) != PackageManager . PERMISSION_GRANTED ) {
mFusedLocationProviderClient !! . requestLocationUpdates(mLocationRequest, mLocationCallback,
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
private fun stoplocationUpdates () {
mFusedLocationProviderClient !! . removeLocationUpdates(mLocationCallback)
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
package com.kotlincodes.locationlistenerwithkotlin
import android . content . pm . PackageManager
import android . location . Location
import android . location . LocationManager
import android . provider . Settings
import android . support . v4 . app . ActivityCompat
import android . support . v7 . app . AlertDialog
import android . support . v7 . app . AppCompatActivity
import com . google . android . gms . location . *
import java . text . SimpleDateFormat
class MainActivity : AppCompatActivity () {
private var mFusedLocationProviderClient : FusedLocationProviderClient? = null
private val INTERVAL : Long = 2000
private val FASTEST_INTERVAL : Long = 1000
lateinit var mLastLocation : Location
internal lateinit var mLocationRequest : LocationRequest
private val REQUEST_PERMISSION_LOCATION = 10
lateinit var btnStartupdate : Button
lateinit var btnStopUpdates : Button
override fun onCreate ( savedInstanceState : Bundle?) {
super . onCreate(savedInstanceState)
setContentView(R . layout . activity_main)
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

kotlincodes/LocationListener-with-Kotlin

Contribute to kotlincodes/LocationListener-with-Kotlin development by creating an account on GitHub.
Installation First, add image_picker_gallery_camera as a dependency in your pubspec.yaml ... Read More
ListTile is generally used to populate a ListView in Flutter ... Read More
Date Picker is very usefull fuction which shows a picker ... Read More
A bottom sheet is a sheet that slides up from ... Read More
Flutter is an open-source UI software development kit created by ... Read More
Installation First, add image_picker_gallery_camera as a dependency in your pubspec.yaml ... Read More
ListTile is generally used to populate a ListView in Flutter ... Read More
Date Picker is very usefull fuction which shows a picker ... Read More
Many of the android applications we uses in daily life  needs users current locations continuously,   Here we are going to implement LocationListener with Kotlin using FusedLocationProviderClient . We have previously used FusedLocationProviderApi which is deprecated now.
To access the location from the device add the following permissions to the manifest.xml  file .

Add the following dependencies into app level  build.gradle ( Module:app) file.
implementation ‘com.google.android.gms:play-services-location:16.0.0’
Setup layout file for our home screen. It has two Buttons and three TextViews as shown below
Here we are going to learn how to implement location Listener in our MainActivity.kt Class with all details.
From android version 6 (Marshmallow ) user have to accept all the permissions in run time. So we have to check whether used accepted all the permissions needed in run time .
We have added the permissions in the manifest file already now to show the Runtime permission, You should do the following method.
Now we have to implement onRequestPermissionsResult method to check if the permission is granted or not by the user.
To check location is on we have to add the following code to our project.
Now we are going to setup the LocationListener using startLocationUpdates() method. Before that we have to add a LocationCallback as given below.
Now Add startLocationUpdates() method to your code as follows
To Stop Location Updates add the following
Now we are all set to run the project. Please find the Complete code for MainActivity.kt file below.
The full source code is available here .

21 Naked
Video Porn Sex Lesbians
Oral Orgasm Porn
Fucking Hard Massage
Oral Lesbian Porn

Report Page