Skip to content

Commit

Permalink
added recycler view and chrome custom tabs
Browse files Browse the repository at this point in the history
  • Loading branch information
pratyaksh1610 committed Aug 3, 2022
1 parent 205ba13 commit 5700860
Show file tree
Hide file tree
Showing 35 changed files with 330 additions and 242 deletions.
3 changes: 3 additions & 0 deletions .idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions .idea/FunMemes.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion MemeShare/.idea/vcs.xml → .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 17 additions & 0 deletions MemeShare/.idea/deploymentTargetDropDown.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

30 changes: 0 additions & 30 deletions MemeShare/.idea/jarRepositories.xml

This file was deleted.

11 changes: 2 additions & 9 deletions MemeShare/.idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 10 additions & 14 deletions MemeShare/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,12 @@ plugins {
}

android {
compileSdk 31

buildFeatures {
viewBinding = true
}
compileSdk 32

defaultConfig {
applicationId "com.pratyakshkhurana.memeshare"
minSdk 26
targetSdk 31
applicationId "com.pratyakshkhurana.memes_recycler_view_demo"
minSdk 21
targetSdk 32
versionCode 1
versionName "1.0"

Expand All @@ -27,7 +23,6 @@ android {
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}

compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
Expand All @@ -38,14 +33,15 @@ android {
}

dependencies {
implementation 'androidx.core:core-ktx:1.8.0'
implementation 'com.github.bumptech.glide:glide:4.13.2'
annotationProcessor 'com.github.bumptech.glide:compiler:4.13.2'
implementation("androidx.cardview:cardview:1.0.0")
implementation 'androidx.core:core-ktx:1.7.0'
implementation 'androidx.appcompat:appcompat:1.4.2'
implementation 'com.google.android.material:material:1.6.1'
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
implementation 'com.android.volley:volley:1.2.1'
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
implementation("com.android.volley:volley:1.2.1")
implementation 'com.github.bumptech.glide:glide:4.13.0'
annotationProcessor 'com.github.bumptech.glide:compiler:4.13.0'
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.pratyakshkhurana.funmemes
package com.pratyakshkhurana.memes_recycler_view_demo

import androidx.test.platform.app.InstrumentationRegistry
import androidx.test.ext.junit.runners.AndroidJUnit4
Expand All @@ -19,6 +19,6 @@ class ExampleInstrumentedTest {
fun useAppContext() {
// Context of the app under test.
val appContext = InstrumentationRegistry.getInstrumentation().targetContext
assertEquals("com.example.memeshare", appContext.packageName)
assertEquals("com.pratyakshkhurana.memes_recycler_view_demo", appContext.packageName)
}
}
18 changes: 9 additions & 9 deletions MemeShare/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.pratyakshkhurana.funmemes">
xmlns:tools="http://schemas.android.com/tools"
package="com.pratyakshkhurana.memes_recycler_view_demo">

<!-- permissions for internet and storage-->
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />

<application
android:allowBackup="true"
android:icon="@drawable/app_icon_new"
android:dataExtractionRules="@xml/data_extraction_rules"
android:fullBackupContent="@xml/backup_rules"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@drawable/app_icon_new"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.MemeShare">
android:theme="@style/Theme.Memes_recycler_view_demo"
tools:targetApi="31">
<activity
android:name="com.pratyakshkhurana.funmemes.MainActivity"
android:name="com.pratyakshkhurana.memes_recycler_view_demo.MainActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,123 +1,99 @@
package com.pratyakshkhurana.funmemes
package com.pratyakshkhurana.memes_recycler_view_demo

import android.content.ContentValues
import android.content.Intent
import android.graphics.Bitmap
import android.graphics.Canvas
import android.graphics.drawable.Drawable
import android.net.Uri
import android.os.*
import android.os.Build
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.os.Environment
import android.provider.MediaStore
import android.util.Log
import android.view.View
import android.widget.Toast
import androidx.appcompat.app.AppCompatActivity
import androidx.recyclerview.widget.LinearLayoutManager
import com.android.volley.Request
import com.android.volley.toolbox.JsonObjectRequest
import com.android.volley.toolbox.Volley
import com.bumptech.glide.Glide
import com.bumptech.glide.load.DataSource
import com.bumptech.glide.load.engine.GlideException
import com.bumptech.glide.request.RequestListener
import com.bumptech.glide.request.target.Target
import kotlinx.android.synthetic.main.activity_main.*
import java.io.File
import java.io.FileOutputStream
import java.io.OutputStream


class MainActivity : AppCompatActivity() {

private var currentImageUrl:String? = null
private lateinit var mMemeAdapter: MemeAdapter

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
}

override fun onStart() {
super.onStart()
loadMeme()
//layout manager
recyclerView.layoutManager = LinearLayoutManager(this, LinearLayoutManager.VERTICAL, false)
fetch()
mMemeAdapter = MemeAdapter(this)
recyclerView.adapter = mMemeAdapter

}

// manifest file is single source of truth , includes name of app,user permission
// launcher activity and title , label, icon, theme etc
private fun loadMeme(){
// Instantiate the RequestQueue.
progress_bar_loading.visibility = View.VISIBLE
//when meme is loading progress bar will load
val url = "https://meme-api.herokuapp.com/gimme"
// api call is done to fetch image of meme
private fun fetch() {
val url = "https://meme-api.herokuapp.com/gimme/memes/50"

// Request a string response from the provided URL.
//creating json object request
val jsonObjectRequest = JsonObjectRequest(
Request.Method.GET, url, null,
{ response ->
currentImageUrl = response.getString("url")
//glide library for image processing
Glide.with(this)
.load(currentImageUrl)
.fitCenter()
.listener(object :RequestListener<Drawable>{
override fun onLoadFailed(
e: GlideException?,
model: Any?,
target: Target<Drawable>?,
isFirstResource: Boolean
): Boolean {
progress_bar_loading.visibility = View.GONE
return false
}
override fun onResourceReady(
resource: Drawable?,
model: Any?,
target: Target<Drawable>?,
dataSource: DataSource?,
isFirstResource: Boolean
): Boolean {
progress_bar_loading.visibility = View.GONE
return false
}
}).into(imgView)


{
//extract memes json array
val memesJsonArray = it.getJSONArray("memes")
val memesArrayToAdapter = ArrayList<MemeData>()
//traverse json array and extract each object and pass to memesArrayToAdapter
//and finally to adapter to load in recycler view by binding.....
for (i in 0 until memesJsonArray.length()) {
//extract eachObj of array at position 'i'
val eachObj = memesJsonArray.getJSONObject(i)
val obj = MemeData(
eachObj.getString("title"),
eachObj.getString("author"),
eachObj.getString("url")
)
memesArrayToAdapter.add(obj)
}
mMemeAdapter.update(memesArrayToAdapter)
},
{
Toast.makeText(this, "something went wrong", Toast.LENGTH_SHORT).show()
})

// Add the request to the RequestQueue.
//if error occurs due to glitch , will display this toast
//short message for the user
Toast.makeText(this, "Error !", Toast.LENGTH_LONG).show()
}
)
// Access the RequestQueue through your singleton class.
//made singleton so that there is only one instance of volley for entire app
MySingleton.getInstance(this).addToRequestQueue(jsonObjectRequest)
}

fun nextMeme(view: View) {
//for getting next meme on the screen
loadMeme()
}

fun shareMeme(view: View) {
fun shareImage(url: String) {
val intent = Intent(Intent.ACTION_SEND)
intent.type = "text/plain"
intent.putExtra(Intent.EXTRA_TEXT,"Hey, checkout this cool meme I got from Reddit $currentImageUrl ")
intent.putExtra(Intent.EXTRA_TEXT, "Hi, checkout this cool meme I got from Reddit $url ")

//chooser where to send
val chooser = Intent.createChooser(intent,"Share this meme using...")
//chooser where to send and it will display all apps capable of sharing in android device
val chooser = Intent.createChooser(intent, "Share this meme using...")
startActivity(chooser)
}

fun saveImg(view: View){
// on click of this btnSve button it will capture
// screenshot of imgView and save it to gallery
btnSave.setOnClickListener {
// extract the bitmap of the imgView using
// getBitmapOfImgView
val bitmap = getBitmapOfImgView(imgView)
val bitmap = getBitmapOfImgView(view)
// if bitmap is not null then
// save it to gallery
if (bitmap != null) {
saveImgViewToStorage(bitmap)
}
}
}

private fun getBitmapOfImgView(v: View): Bitmap? {
Expand Down Expand Up @@ -167,7 +143,7 @@ class MainActivity : AppCompatActivity() {
// contentResolver and getting the Uri
val imageUri: Uri? = resolver.insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, contentValues)

// Opening an outputstream with the Uri that we got
// Opening an output stream with the Uri that we got
fos = imageUri?.let { resolver.openOutputStream(it) }
}
} else {
Expand All @@ -184,4 +160,6 @@ class MainActivity : AppCompatActivity() {
}
}



}
Loading

0 comments on commit 5700860

Please sign in to comment.