Skip to content

Commit

Permalink
minor fix
Browse files Browse the repository at this point in the history
  • Loading branch information
pratyaksh1610 committed Jul 21, 2022
1 parent 94d81c7 commit 205ba13
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 2 deletions.
Binary file added 10-inch tablet screenshots/1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added 10-inch tablet screenshots/2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added 7-inch tablet screenshots/1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added 7-inch tablet screenshots/2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Feature Graphic/funmemesgraphic.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ class MainActivity : AppCompatActivity() {
// Instantiate the RequestQueue.
progress_bar_loading.visibility = View.VISIBLE
//when meme is loading progress bar will load
val queue = Volley.newRequestQueue(this)
val url = "https://meme-api.herokuapp.com/gimme"
// api call is done to fetch image of meme

Expand Down Expand Up @@ -88,7 +87,7 @@ class MainActivity : AppCompatActivity() {
})

// Add the request to the RequestQueue.
queue.add(jsonObjectRequest)
MySingleton.getInstance(this).addToRequestQueue(jsonObjectRequest)
}

fun nextMeme(view: View) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package com.pratyakshkhurana.funmemes

import android.content.Context
import com.android.volley.Request
import com.android.volley.RequestQueue
import com.android.volley.toolbox.Volley

//Singleton class is the one , it has only one instance
//so app can call one request at at time
//so we call using singleton and follow singleton pattern
class MySingleton constructor(context: Context) {
companion object {
//volatile to make thread safe, ensure safety
@Volatile
private var INSTANCE: MySingleton? = null
fun getInstance(context: Context) =
INSTANCE ?: synchronized(this) {
INSTANCE ?: MySingleton(context).also {
INSTANCE = it
}
}
}
private val requestQueue: RequestQueue by lazy {
// applicationContext is key, it keeps you from leaking the
// Activity or BroadcastReceiver if someone passes one in.
Volley.newRequestQueue(context.applicationContext)
}
fun <T> addToRequestQueue(req: Request<T>) {
requestQueue.add(req)
}
}

0 comments on commit 205ba13

Please sign in to comment.