I want to pick first phone number automatically from HintRequest android.
Is there any possible solution for it?
is there any solution, user cannot dismiss the HintRequest Dialog without selecting at least one mobile number?
// Example From Kotlin
implementation 'com.google.android.gms:play-services-ads-identifier:17.0.0'
implementation 'com.google.android.gms:play-services-auth-api-phone:17.3.0'
implementation 'com.google.android.gms:play-services-base:17.1.0'
implementation 'com.google.android.gms:play-services-identity:17.0.0'
implementation 'com.google.android.gms:play-services-auth:17.0.0'
// Class : AutoDetectMobileNo
class AutoDetectMobileNo internal constructor(context: Context) {
private var googleApiClient: GoogleApiClient? = null
private val context: Context
private val appCompatActivity: AppCompatActivity = context as AppCompatActivity
fun requestPhoneNoHint() {
googleApiClient = GoogleApiClient.Builder(context)
.enableAutoManage(
appCompatActivity
) { }
.addApi(Auth.CREDENTIALS_API)
.build()
val hintRequest = HintRequest.Builder()
.setHintPickerConfig(
CredentialPickerConfig.Builder()
.setShowCancelButton(true)
.build()
)
.setPhoneNumberIdentifierSupported(true)
.build()
val intent =
Auth.CredentialsApi.getHintPickerIntent(googleApiClient, hintRequest)
try {
appCompatActivity.startIntentSenderForResult(
intent.intentSender,
RC_HINT,
null,
0,
0,
0
)
} catch (e: Throwable) {
Log.e("PHONE_HINT", "Could not start hint picker Intent", e)
}
}
fun getPhoneNo(data: Intent): String {
val cred: Credential =
data.getParcelableExtra(Credential.EXTRA_KEY)!!
return cred.id
}
interface Callback
companion object {
const val RC_HINT = 1000
}
init {
this.context = appCompatActivity.applicationContext
}
}
// On Your Activity / Fragment
val autoDetectMobileNo = AutoDetectMobileNo(this)
autoDetectMobileNo!!.requestPhoneNoHint()
override fun onActivityResult(
requestCode: Int,
resultCode: Int,
data: Intent?
) {
super.onActivityResult(requestCode, resultCode, data)
if (requestCode == AutoDetectMobileNo.RC_HINT) {
if (resultCode == Activity.RESULT_OK) {
val mPhoneNumber = autoDetectMobileNo!!.getPhoneNo(data)
}
}
}
Related
I need to transform this and some other code made in kotlin to java, but it is not working. Here is one of them.
BackgroundActivity.kt (this I need to transform to java):
#RequiresApi(Build.VERSION_CODES.LOLLIPOP)
override fun surfaceChanged(holder: SurfaceHolder, p1: Int, p2: Int, p3: Int) {
RtpService.setView(surfaceView)
RtpService.startPreview()
}
This function is inside a kotlin class, that I will keep
RtpService.kt
package com.wifi.service.backgroundexample
import android.app.Notification
import android.app.NotificationChannel
import android.app.NotificationManager
import android.app.Service
import android.content.Context
import android.content.Intent
import android.os.Build
import android.os.IBinder
import android.util.Log
import androidx.annotation.RequiresApi
import androidx.core.app.NotificationCompat
import com.wifi.rtplibrary.base.Camera2Base
import com.wifi.rtplibrary.rtmp.RtmpCamera2
import com.wifi.rtplibrary.rtsp.RtspCamera2
import com.wifi.rtplibrary.view.OpenGlView
import com.wifi.service.R
/**
* Basic RTMP/RTSP service streaming implementation with camera2
*/
#RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
class RtpService : Service() {
private var endpoint: String? = null
override fun onCreate() {
super.onCreate()
Log.e(TAG, "RTP service create")
notificationManager = getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
val channel = NotificationChannel(channelId, channelId, NotificationManager.IMPORTANCE_HIGH)
notificationManager?.createNotificationChannel(channel)
}
keepAliveTrick()
}
private fun keepAliveTrick() {
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.O) {
val notification = NotificationCompat.Builder(this, channelId)
.setSmallIcon(R.drawable.ic_baseline_settings_24_branco)
.setSilent(true)
.setOngoing(false)
//.setContentTitle("")
.build()
startForeground(1, notification)
} else {
startForeground(1, Notification())
}
}
override fun onBind(p0: Intent?): IBinder? {
return null
}
override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {
Log.e(TAG, "RTP service started")
endpoint = intent?.extras?.getString("endpoint")
if (endpoint != null) {
prepareStreamRtp()
startStreamRtp(endpoint!!)
}
return START_STICKY
}
companion object {
private const val TAG = "RtpService"
//private const val channelId = "rtpStreamChannel"
private const val channelId = "Android"
private const val notifyId = 123456
private var notificationManager: NotificationManager? = null
private var camera2Base: Camera2Base? = null
private var openGlView: OpenGlView? = null
private var contextApp: Context? = null
fun setView(openGlView: OpenGlView) {
this.openGlView = openGlView
camera2Base?.replaceView(openGlView)
}
fun setView(context: Context) {
contextApp = context
this.openGlView = null
camera2Base?.replaceView(context)
}
fun startPreview() {
camera2Base?.startPreview()
}
fun init(context: Context) {
contextApp = context
if (camera2Base == null) camera2Base = RtmpCamera2(context, true, connectCheckerRtp)
}
fun stopStream() {
if (camera2Base != null) {
if (camera2Base!!.isStreaming) camera2Base!!.stopStream()
}
}
fun stopPreview() {
if (camera2Base != null) {
if (camera2Base!!.isOnPreview) camera2Base!!.stopPreview()
}
}
private val connectCheckerRtp = object : ConnectCheckerRtp {
override fun onConnectionStartedRtp(rtpUrl: String) {
//showNotification("Stream connection started")
}
override fun onConnectionSuccessRtp() {
//showNotification("Stream started")
Log.e(TAG, "RTP service destroy")
}
override fun onNewBitrateRtp(bitrate: Long) {
}
override fun onConnectionFailedRtp(reason: String) {
//showNotification("Stream connection failed")
Log.e(TAG, "RTP service destroy")
}
override fun onDisconnectRtp() {
//showNotification("Stream stopped")
}
override fun onAuthErrorRtp() {
//showNotification("Stream auth error")
}
override fun onAuthSuccessRtp() {
//showNotification("Stream auth success")
}
}
private fun showNotification(text: String) {
contextApp?.let {
val notification = NotificationCompat.Builder(it, channelId)
//.setSmallIcon(R.mipmap.ic_launcher)
.setSmallIcon(R.drawable.ic_baseline_settings_24_branco)
.setContentTitle("RTP Stream")
.setSilent(true)
.setOngoing(false)
.setContentText(text).build()
notificationManager?.notify(notifyId, notification)
}
}
}
override fun onDestroy() {
super.onDestroy()
Log.e(TAG, "RTP service destroy")
stopStream()
}
private fun prepareStreamRtp() {
stopStream()
stopPreview()
if (endpoint!!.startsWith("rtmp")) {
camera2Base = if (openGlView == null) {
RtmpCamera2(baseContext, true, connectCheckerRtp)
} else {
RtmpCamera2(openGlView, connectCheckerRtp)
}
} else {
camera2Base = if (openGlView == null) {
RtspCamera2(baseContext, true, connectCheckerRtp)
} else {
RtspCamera2(openGlView, connectCheckerRtp)
}
}
}
private fun startStreamRtp(endpoint: String) {
if (!camera2Base!!.isStreaming) {
if (camera2Base!!.prepareVideo() && camera2Base!!.prepareAudio()) {
camera2Base!!.startStream(endpoint)
}
} else {
//showNotification("You are already streaming :(")
}
}
}
I tried this with java:
JavaVersion.java
RtpService rtpService = new RtpService();
rtpService.init(this);
init is not recognized, I don't work well with kotlin yet
can you try this
#RequiresApi(Build.VERSION_CODES.LOLLIPOP)
public void surfaceChanged(SurfaceHolder holder, int p1, int p2, int p3) {
Intrinsics.checkNotNullParameter(holder, "holder");
RtpService.setView(surfaceView);
RtpService.startPreview();
}
public void setView(OpenGlView openGlView) {
this.openGlView = openGlView;
camera2Base.replaceView(openGlView);
}
I tried the codes from the forum all of which is in Java. It was converted to Kotlin by IDE but it's not working. I've just started learning Android. Please help me with this. I've attached the converted code below. Also, I added this -
val webUrl = webView.url
if (webUrl != null) {
shouldOverrideUrlLoading(webView,webUrl)
}
inside OnCreate. Not sure if that's correct or not.
Below is the code---
private fun shouldOverrideUrlLoading(view: WebView, url: String) {
view.loadUrl(url)
if (url.startsWith("whatsapp://")) {
view.stopLoading()
try {
val whatsappIntent = Intent(Intent.ACTION_SEND)
whatsappIntent.type = "text/plain"
whatsappIntent.setPackage("com.whatsapp")
whatsappIntent.putExtra(
Intent.EXTRA_TEXT,
view.url.toString() + " - Shared from webview "
)
startActivity(whatsappIntent)
} catch (ex: ActivityNotFoundException) {
val makeShortText = "Whatsapp has not been installed"
Toast.makeText(this, makeShortText, Toast.LENGTH_SHORT).show()
}
}
}
Expecting your quick support. Thanks.
i had the same issue this is the solution i found
class KaboekieWebsite : AppCompatActivity() {
lateinit var myWebView: WebView
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_kaboekie_website)
myWebView = findViewById(R.id.KaboekieWebsiteView)
myWebView.webViewClient = WebViewClient()
myWebView.settings.setSupportZoom(true)
myWebView.settings.loadsImagesAutomatically
myWebView.settings.javaScriptEnabled = true
myWebView.setWebViewClient(Callback())
myWebView.loadUrl("https://www.Kaboekie.be/")
myWebView.webViewClient = object : WebViewClient() {
override fun shouldOverrideUrlLoading(webView: WebView, url: String): Boolean {
if (url.startsWith("intent://")) {
val intent = Intent.parseUri(url, Intent.URI_INTENT_SCHEME)
if (intent != null) {
val fallbackUrl = intent.getStringExtra("browser_fallback_url")
return if (fallbackUrl != null) {
webView.loadUrl(fallbackUrl)
true
} else {
false
}
}
}
else if (url.startsWith("tel:")){
val intent = Intent(Intent.ACTION_DIAL)
intent.data = Uri.parse(url)
startActivity(intent)
return true
}
else if (url.startsWith("mailto:")) {
val intent = Intent(Intent.ACTION_VIEW)
val data = Uri.parse(
url + Uri.encode("subject") + "&body=" + Uri.encode(
"body"
)
)
intent.data = data
startActivity(intent)
return true
}
return false
}
}
}
override fun onKeyDown(keyCode: Int, event: KeyEvent?): Boolean {
// Check if the key event was the Back button and if there's history
if (keyCode == KeyEvent.KEYCODE_BACK && myWebView.canGoBack()) {
myWebView.goBack()
return true
}
// If it wasn't the Back key or there's no web page history, bubble up to the default
// system behavior (probably exit the activity)
return super.onKeyDown(keyCode, event)
}
private class Callback : WebViewClient() {
override fun shouldOverrideKeyEvent(view: WebView?, event: KeyEvent?): Boolean {
return false
}
}
}
This question already has answers here:
Android: Internet connectivity change listener
(12 answers)
How to set timer in android?
(24 answers)
Closed last year.
How can I make something in my Java constantly check for connectivity of internet I already have something that checks for connectivity of internet but do not know how to make it constant
Current connectivity checker
public static boolean isNetworkAvailable(Context context) {
ConnectivityManager connectivityManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
if (connectivityManager != null) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
NetworkCapabilities capabilities = connectivityManager.getNetworkCapabilities(connectivityManager.getActiveNetwork());
return capabilities != null && (capabilities.hasTransport(NetworkCapabilities.TRANSPORT_WIFI) || capabilities.hasTransport(NetworkCapabilities.TRANSPORT_CELLULAR) || capabilities.hasTransport(NetworkCapabilities.TRANSPORT_ETHERNET));
} else {
NetworkInfo activeNetwork = connectivityManager.getActiveNetworkInfo();
return activeNetwork != null && activeNetwork.isConnected();
}
}
return false;
}]
I have done it in Kotlin. If you face problem in converting Kotlin into Java you can ask me for help.
So, I am using Broadcast Receiver and detect whenever the network state changed and when there is no Internet, a dialogBox will show.
MainActivity.kt
class MainActivity : AppCompatActivity() {
private var br: BroadcastReceiver? = null
private var filter: IntentFilter? = null
private var mContext: MainActivity? = null
private var isPaused = false
private var toConfirm = true
private var noInternetBuilder: AlertDialog.Builder? = null
private var noInternetDialog: AlertDialog? = null
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
br = MyBroadCastReceiver()
filter = IntentFilter()
filter?.addAction("android.net.conn.CONNECTIVITY_CHANGE")
mContext = this#MainActivity
mContext?.registerReceiver(br, filter)
}
/**
* Broadcast for Internet Checking
*
*/
inner class MyBroadCastReceiver : BroadcastReceiver() {
override fun onReceive(context: Context?, intent: Intent?) {
if (!isNetworkStatusAvailable(this#MainActivity)) {
if (!isPaused) {
toConfirm = true
if (noInternetDialog != null) {
noInternetDialog?.dismiss()
}
showDialogNoInternet(this#MainActivity)
}
toConfirm = false
} else {
toConfirm = true
if (noInternetDialog != null) {
if (noInternetDialog!!.isShowing) {
noInternetDialog?.dismiss()
}
}
}
}
}
fun isNetworkStatusAvailable(context: Context): Boolean {
var result = false
val connectivityManager =
context.getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
val networkCapabilities = connectivityManager.activeNetwork ?: return false
val actNw =
connectivityManager.getNetworkCapabilities(networkCapabilities) ?: return false
result = when {
actNw.hasTransport(NetworkCapabilities.TRANSPORT_WIFI) -> true
actNw.hasTransport(NetworkCapabilities.TRANSPORT_CELLULAR) -> true
actNw.hasTransport(NetworkCapabilities.TRANSPORT_ETHERNET) -> true
else -> false
}
} else {
#Suppress("DEPRECATION")
connectivityManager.run {
connectivityManager.activeNetworkInfo?.run {
result = when (type) {
ConnectivityManager.TYPE_WIFI -> true
ConnectivityManager.TYPE_MOBILE -> true
ConnectivityManager.TYPE_ETHERNET -> true
else -> false
}
}
}
}
return result
}
fun showDialogNoInternet(activity: Activity) {
noInternetBuilder = AlertDialog.Builder(activity)
val viewGroup = findViewById<ViewGroup>(android.R.id.content)
val dialogView: View = LayoutInflater.from(viewGroup.context)
.inflate(R.layout.dialog_nointernet, viewGroup, false)
noInternetBuilder!!.setView(dialogView)
noInternetDialog = noInternetBuilder!!.create()
noInternetDialog!!.setCancelable(false)
noInternetDialog!!.window!!.setBackgroundDrawable(ColorDrawable(Color.TRANSPARENT))
val btn = dialogView.findViewById<View>(R.id.btnOkInternet) as Button
btn.setOnClickListener {
resultInternetLauncher.launch(Intent(Settings.ACTION_WIFI_SETTINGS))
noInternetDialog?.dismiss()
}
noInternetDialog!!.show()
}
override fun onPause() {
super.onPause()
isPaused = true
}
override fun onResume() {
super.onResume()
isPaused = false
if (!toConfirm) {
if (noInternetDialog != null) {
noInternetDialog?.dismiss()
}
showDialogNoInternet(mContext!!)
}
}
}
Must implement override fun onPause() and override fun onResume() along with it because it will control the crashes of dialogBox.
I have a RecyclerView created in Kotlin and would like to save the data from the RecyclerView (the ArrayList) for example with GSON Libary. I've already searched a lot but can't find a working solution. Here's my current code: (without saving function)
MainActivity.kt:
class MainActivity : AppCompatActivity(), ExampleAdapter.OnItemClickListener {
private val exampleList = generateDummyList(500)
private val adapter = ExampleAdapter(exampleList, this)
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
recycler_view.adapter = adapter
recycler_view.layoutManager = LinearLayoutManager(this)
recycler_view.setHasFixedSize(true)
}
fun insertItem(view: View) {
val index = Random.nextInt(8)
val newItem = ExampleItem(
R.drawable.ic_android,
"New item at position $index",
"Line 2"
)
exampleList.add(index, newItem)
adapter.notifyItemInserted(index)
}
fun removeItem(view: View) {
val index = Random.nextInt(8)
exampleList.removeAt(index)
adapter.notifyItemRemoved(index)
}
override fun onItemClick(position: Int) {
Toast.makeText(this, "Item $position clicked", Toast.LENGTH_SHORT).show()
val clickedItem = exampleList[position]
clickedItem.text1 = "Clicked"
adapter.notifyItemChanged(position)
}
private fun generateDummyList(size: Int): ArrayList<ExampleItem> {
val list = ArrayList<ExampleItem>()
for (i in 0 until size) {
val drawable = when (i % 3) {
0 -> R.drawable.ic_android
1 -> R.drawable.ic_audio
else -> R.drawable.ic_sun
}
val item = ExampleItem(drawable, "Item $i", "Line 2")
list += item
}
return list
}
}
ExampleItem.kt:
data class ExampleItem(val imageResource: Int, var text1: String, var text2: String)
ExampleAdapter.kt:
class ExampleAdapter(
private val exampleList: List<ExampleItem>,
private val listener: OnItemClickListener) :
RecyclerView.Adapter<ExampleAdapter.ExampleViewHolder>() {
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ExampleViewHolder {
val itemView = LayoutInflater.from(parent.context).inflate(R.layout.example_item,
parent, false)
return ExampleViewHolder(itemView)
}
override fun onBindViewHolder(holder: ExampleViewHolder, position: Int) {
val currentItem = exampleList[position]
holder.imageView.setImageResource(currentItem.imageResource)
holder.textView1.text = currentItem.text1
holder.textView2.text = currentItem.text2
}
override fun getItemCount() = exampleList.size
inner class ExampleViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView),
View.OnClickListener {
val imageView: ImageView = itemView.image_view
val textView1: TextView = itemView.text_view_1
val textView2: TextView = itemView.text_view_2
init {
itemView.setOnClickListener(this)
}
override fun onClick(v: View?) {
val position = adapterPosition
if (position != RecyclerView.NO_POSITION) {
listener.onItemClick(position)
}
}
}
interface OnItemClickListener {
fun onItemClick(position: Int)
}
}
First you need to convert you Data in to json by using json object in onBindViewHolder using
String json = {"phonetype":"N95","cat":"WP"};
try {
JSONObject obj = new JSONObject(json);
Log.d("My App", obj.toString());
} catch (Throwable t) {
Log.e("My App", "Could not parse malformed JSON: \"" + json + "\"");
}
And if you want to save then you can use shared preferences.
I am new in Kotlin MVVM also, I tried to achieved Pagination with legacy approach and stucked in a issue with my RecyclerView, whenever I scroll it the data duplicated, I tried DiffUtils but no help.
I Logged the data in VIEWMODEL class the data is not repeating
but, when I logged in Activity where I am observing it is showing duplicate values
SEARCHRESULTACTIVITY.KT
class SearchResultActivity : AppCompatActivity() {
private lateinit var layoutManager: LinearLayoutManager
private lateinit var recyclerView: RecyclerView
private lateinit var pullAdapter: CustomAdapter
private var pageNumber = 1
private var totalItemsCount = 0
private var firstVisibleItemsCount = 0
private var visibleItemsCount = 0
private var previousTotal = 0
private var loading = true
private var fillPullList: ArrayList<RepoPull> = ArrayList()
private var userName: String = ""
private var repoName: String = ""
private var isEnd = false
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
initialize()
getDataPull(userName, repoName)
loadNextData()
}
private fun initialize() {
setContentView(R.layout.activity_search_result)
recyclerView = findViewById(R.id.repoRecView)
layoutManager = LinearLayoutManager(this)
getSearchQuery()
}
private fun getSearchQuery() {
userName = intent.getStringExtra("owner").toString()
repoName = intent.getStringExtra("repo").toString()
populatePullRv()
}
private fun populatePullRv() {
recyclerView.addItemDecoration(DividerItemDecoration(this, DividerItemDecoration.VERTICAL))
recyclerView.layoutManager = layoutManager
pullAdapter = CustomAdapter(this, fillPullList)
recyclerView.adapter = pullAdapter
progressBar.visibility = View.VISIBLE
}
private fun loadNextData() {
recyclerView.addOnScrollListener(object : RecyclerView.OnScrollListener() {
override fun onScrolled(recyclerView: RecyclerView, dx: Int, dy: Int) {
super.onScrolled(recyclerView, dx, dy)
val mLayoutManger = recyclerView.layoutManager as LinearLayoutManager
visibleItemsCount = mLayoutManger.childCount
totalItemsCount = mLayoutManger.itemCount
firstVisibleItemsCount = mLayoutManger.findFirstVisibleItemPosition()
if (loading) {
if (totalItemsCount > previousTotal) {
previousTotal = totalItemsCount
pageNumber++
loading = false
progressBar.visibility = View.GONE
}
}
if (!loading && (firstVisibleItemsCount + visibleItemsCount) >= totalItemsCount) {
getDataPull(userName, repoName)
loading = true
Log.d("PAGE", pageNumber.toString())
}
}
})
}
private fun getDataPull(username: String?, reponame: String?) {
val myViewModel = ViewModelProviders.of(this).get(PullVM::class.java)
myViewModel.endofList.observe(this, {
if (it == true) {
isEnd = true
progressBar.visibility = View.GONE
Toast.makeText(this#SearchResultActivity, "All PR Fetched", Toast.LENGTH_SHORT)
.show()
}
})
myViewModel.status.observe(this, {
if (it == false) {
showError(getString(R.string.no_net))
}
})
myViewModel.getPullDataFromVM().observe(this, {
if (it != null) {
listRepos(it) **//DUPLICATE VALUE COMING**
} else {
showError(getString(R.string.nothing_found))
}
})
myViewModel.getPullList(username.toString(), reponame.toString(), pageNumber)
}
private fun showError(s: String) {
progressBar.visibility = View.GONE
val theView =
this#SearchResultActivity.findViewById<View>(android.R.id.content)
Snackbar.make(
theView,
s,
Snackbar.LENGTH_LONG
).show()
}
#SuppressLint("NotifyDataSetChanged")
fun listRepos(repos: List<RepoPull>) {
if (!isEnd) {
progressBar.visibility = View.GONE
fillPullList.addAll(repos)
pullAdapter.notifyDataSetChanged()
}
}}
PULLVM(View Model).kt
class PullVM : ViewModel() {
var pullList: MutableLiveData<List<RepoPull>>
var status = MutableLiveData<Boolean?>()
var endofList = MutableLiveData<Boolean?>()
init {
pullList = MutableLiveData()
}
fun getPullDataFromVM(): MutableLiveData<List<RepoPull>> {
return pullList
}
fun getPullList(ownerName: String, repoName: String, pgNo: Int) {
val retriever = GitHubRetriever
val callback = object : Callback<List<RepoPull>> {
override fun onFailure(call: Call<List<RepoPull>>, t: Throwable) {
status.value = false
}
override fun onResponse(
call: Call<List<RepoPull>>,
response: Response<List<RepoPull>>
) {
if (response.body()?.size == 0) {
endofList.value = true
}
if (response.code() == 404) {
pullList.postValue(null)
} else {
status.value = true
val repos = response.body()
if (repos != null) {
pullList.postValue(repos)
}
}
}
}
retriever.userRepos(
callback,
ownerName,
repoName,
pgNo
)
}
Try moving your viewModel instantiation and observer settings to onCreate so you don't have to create a new viewModel instance and set a new observable to your LiveDatas.
Declare myViewModel as a lateinit property of your Activity and move this part to onCreate
myViewModel = ViewModelProviders.of(this).get(PullVM::class.java)
myViewModel.endofList.observe(this, {
if (it == true) {
isEnd = true
progressBar.visibility = View.GONE
Toast.makeText(this#SearchResultActivity, "All PR Fetched", Toast.LENGTH_SHORT)
.show()
}
})
myViewModel.status.observe(this, {
if (it == false) {
showError(getString(R.string.no_net))
}
})
myViewModel.getPullDataFromVM().observe(this, {
if (it != null) {
listRepos(it) **//DUPLICATE VALUE COMING**
} else {
showError(getString(R.string.nothing_found))
}
})
And
private fun getDataPull(username: String?, reponame: String?)
should only contain
myViewModel.getPullList(username.toString(), reponame.toString(), pageNumber)