Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main'
Browse files Browse the repository at this point in the history
  • Loading branch information
rajitdeb committed Dec 30, 2023
2 parents 20331d3 + 6ca2962 commit 1e48b60
Show file tree
Hide file tree
Showing 16 changed files with 151 additions and 58 deletions.
10 changes: 10 additions & 0 deletions .idea/deploymentTargetDropDown.xml

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

5 changes: 2 additions & 3 deletions .idea/gradle.xml

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

10 changes: 10 additions & 0 deletions .idea/migrations.xml

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

2 changes: 1 addition & 1 deletion .idea/misc.xml

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

19 changes: 12 additions & 7 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ plugins {

android {

compileSdk 33
compileSdk 34

defaultConfig {
applicationId "com.rajit.memeology"
minSdkVersion 23
targetSdkVersion 33
targetSdkVersion 34
versionCode 1
versionName "1.0"

Expand All @@ -27,12 +27,12 @@ android {
}

compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
sourceCompatibility JavaVersion.VERSION_17
targetCompatibility JavaVersion.VERSION_17
}

kotlinOptions {
jvmTarget = '1.8'
jvmTarget = '17'
}

buildFeatures{
Expand All @@ -45,10 +45,12 @@ android {

dependencies {

implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
def room_version = "2.5.0"
def nav_version = "2.6.0"
def browser_version = "1.7.0"

implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
implementation 'androidx.legacy:legacy-support-v4:1.0.0'

implementation 'androidx.core:core-ktx:1.10.1'
implementation 'androidx.appcompat:appcompat:1.6.1'
Expand Down Expand Up @@ -98,4 +100,7 @@ dependencies {

// GSON
implementation 'com.squareup.retrofit2:converter-gson:2.9.0'

// AndroidX Browser Library
implementation "androidx.browser:browser:$browser_version"
}
3 changes: 2 additions & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@
<activity
android:name=".ui.activity.MainActivity"
android:theme="@style/SplashScreenStyle"
android:exported="true">
android:exported="true"
android:launchMode="singleTask">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import com.rajit.memeology.R
import com.rajit.memeology.data.local.entities.FavouritesEntity
import com.rajit.memeology.databinding.ItemDiscoverMemeBinding
import com.rajit.memeology.models.Meme
import com.rajit.memeology.utils.CustomTab
import com.rajit.memeology.utils.MemesDiffUtil
import com.rajit.memeology.utils.PostActions
import com.rajit.memeology.viewmodels.MainViewModel
Expand Down Expand Up @@ -47,6 +48,12 @@ class DiscoverMemesAdapter(
)
postActions.shareMeme(it.context, shareText)
}

binding.itemLinkToPost.setOnClickListener {
val postUrl = currentMeme.url
CustomTab.loadURL(it.context, postUrl)
}

}

companion object {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
package com.rajit.memeology.adapters

import android.Manifest
import android.content.ActivityNotFoundException
import android.content.Intent
import android.content.pm.PackageManager
import android.net.Uri
import android.util.Log
import android.view.ActionMode
import android.view.LayoutInflater
Expand All @@ -15,13 +12,13 @@ import android.view.ViewGroup
import android.widget.Toast
import androidx.coordinatorlayout.widget.CoordinatorLayout
import androidx.core.content.ContextCompat
import androidx.core.content.ContextCompat.startActivity
import androidx.fragment.app.FragmentActivity
import androidx.recyclerview.widget.DiffUtil
import androidx.recyclerview.widget.RecyclerView
import com.rajit.memeology.R
import com.rajit.memeology.data.local.entities.FavouritesEntity
import com.rajit.memeology.databinding.ItemFavouriteRowBinding
import com.rajit.memeology.utils.CustomTab
import com.rajit.memeology.utils.DownloadUtil
import com.rajit.memeology.utils.MemesDiffUtil
import com.rajit.memeology.utils.PermissionUtil
Expand Down Expand Up @@ -155,17 +152,9 @@ class FavouriteMemesAdapter(
}

holder.binding.itemLinkToPost.setOnClickListener {
val postUrl = Uri.parse(currentFavourite.meme.postLink)
val takeMeToOriginalPost = Intent(Intent.ACTION_VIEW, postUrl)
try {
startActivity(it.context, takeMeToOriginalPost, null)
} catch (e: ActivityNotFoundException) {
Log.e(
"FavouriteMemesAdapter",
"takeMeToOriginalPost: Error occurred - ${e.message}"
)
Toast.makeText(it.context, "${e.message}", Toast.LENGTH_SHORT).show()
}
val postUrl = currentFavourite.meme.postLink
CustomTab.loadURL(recyclerViewLayout.context, postUrl)

}

saveOnItemScroll(currentFavourite, holder)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
package com.rajit.memeology.data.local

import android.content.Context
import androidx.room.Database
import androidx.room.Room
import androidx.room.RoomDatabase
import androidx.room.TypeConverters
import com.rajit.memeology.data.local.dao.MemesDao
import com.rajit.memeology.data.local.entities.FavouritesEntity
import com.rajit.memeology.utils.Constants.Companion.DATABASE_NAME

@Database(
entities = [FavouritesEntity::class],
Expand Down
29 changes: 11 additions & 18 deletions app/src/main/java/com/rajit/memeology/ui/fragment/RandomMeme.kt
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
package com.rajit.memeology.ui.fragment

import android.Manifest
import android.content.ActivityNotFoundException
import android.content.Context
import android.content.Intent
import android.content.pm.PackageManager
import android.hardware.Sensor
import android.hardware.SensorEvent
import android.hardware.SensorEventListener
import android.hardware.SensorManager
import android.net.Uri
import android.os.Build
import android.os.Bundle
import android.util.Log
Expand All @@ -19,16 +16,18 @@ import android.view.ViewGroup
import androidx.core.content.ContextCompat
import androidx.fragment.app.Fragment
import androidx.fragment.app.viewModels
import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.lifecycleScope
import com.rajit.memeology.data.local.entities.FavouritesEntity
import com.rajit.memeology.databinding.FragmentRandomMemeBinding
import com.rajit.memeology.models.Meme
import com.rajit.memeology.utils.*
import com.rajit.memeology.utils.CustomTab
import com.rajit.memeology.utils.DownloadUtil
import com.rajit.memeology.utils.NetworkResult
import com.rajit.memeology.utils.PermissionUtil
import com.rajit.memeology.utils.PostActions
import com.rajit.memeology.utils.sdk29AndUp
import com.rajit.memeology.viewmodels.MainViewModel
import dagger.hilt.android.AndroidEntryPoint
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch

@AndroidEntryPoint
Expand Down Expand Up @@ -128,17 +127,11 @@ class RandomMeme : Fragment(), SensorEventListener {
}

binding.itemLinkToPost.setOnClickListener {
val postUrl = Uri.parse(memeData.postLink)
val takeMeToOriginalPost = Intent(Intent.ACTION_VIEW, postUrl)
try {
startActivity(takeMeToOriginalPost)
} catch (e: ActivityNotFoundException) {
Log.e(TAG, "takeMeToOriginalPost: Error occurred - ${e.message}")
postActions.showSnackBarMessage(
binding.coordinatorLayout,
e.message.toString()
)
}
val postUrl = memeData.postLink

// Load URL on Custom Tab
CustomTab.loadURL(requireContext(), postUrl)

}

binding.nextBtn.setOnClickListener {
Expand Down
73 changes: 73 additions & 0 deletions app/src/main/java/com/rajit/memeology/utils/CustomTab.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
package com.rajit.memeology.utils

import android.content.Context
import android.net.Uri
import androidx.appcompat.content.res.AppCompatResources
import androidx.browser.customtabs.CustomTabColorSchemeParams
import androidx.browser.customtabs.CustomTabsIntent
import androidx.core.content.ContextCompat
import androidx.core.graphics.drawable.toBitmap
import com.rajit.memeology.R

object CustomTab {

/**
* Load @param [url] in the Custom Tav
* [CustomTabsIntent.Builder] is used to build the custom tab along with the specified customizations
**/
fun loadURL(context: Context, url: String) {

val customCloseIcon = AppCompatResources.getDrawable(context, R.drawable.ic_custom_tab_back)

// Light Mode Toolbar Color
val lightModeColor = ContextCompat.getColor(
context,
R.color.actionBarColor
)

// Dark Mode Toolbar Color
val darkModeColor = ContextCompat.getColor(
context,
R.color.actionBarColor
)

// Setting the Custom Tab Toolbar Configuration for Light Mode
val customTabToolbarColorLight = CustomTabColorSchemeParams
.Builder()
.setToolbarColor(lightModeColor)
.build()

// Setting the Custom Tab Toolbar Configuration for Dark Mode
val customTabToolbarColorDark = CustomTabColorSchemeParams
.Builder()
.setToolbarColor(darkModeColor)
.build()

CustomTabsIntent.Builder().apply {

// Show Title of the Website in Custom Tab ToolBar
setShowTitle(true)

// Set Custom Close Button for Custom Tab
setCloseButtonIcon(customCloseIcon!!.toBitmap())

// applying light mode color
setDefaultColorSchemeParams(customTabToolbarColorLight)

// applying dark mode color
setColorSchemeParams(
CustomTabsIntent.COLOR_SCHEME_DARK,
customTabToolbarColorDark
)

// Build & Launch URL in Custom Tab
build().launchUrl(
context,
Uri.parse(url)
)

}

}

}
9 changes: 2 additions & 7 deletions app/src/main/java/com/rajit/memeology/utils/DownloadUtil.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,10 @@ import android.graphics.Bitmap
import android.graphics.drawable.BitmapDrawable
import android.graphics.drawable.Drawable
import android.net.Uri
import android.os.Environment.DIRECTORY_DCIM
import android.os.Environment.DIRECTORY_PICTURES
import android.provider.MediaStore
import android.widget.Toast
import com.bumptech.glide.load.resource.gif.GifDrawable
import java.io.File
import java.io.FileOutputStream
import java.io.IOException
import java.nio.ByteBuffer

class DownloadUtil {

Expand Down Expand Up @@ -63,12 +58,12 @@ class DownloadUtil {
context.contentResolver.openOutputStream(uri).use { outputStream ->
when {
fileName.contains(".jpg") -> {
if (!bmp.compress(Bitmap.CompressFormat.JPEG, 95, outputStream)) {
if (!bmp.compress(Bitmap.CompressFormat.JPEG, 95, outputStream!!)) {
throw IOException("couldn't save bitmap")
}
}
fileName.contains(".png") -> {
if (!bmp.compress(Bitmap.CompressFormat.PNG, 95, outputStream)) {
if (!bmp.compress(Bitmap.CompressFormat.PNG, 95, outputStream!!)) {
throw IOException("couldn't save bitmap")
}
}
Expand Down
11 changes: 11 additions & 0 deletions app/src/main/res/drawable/ic_custom_tab_back.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:autoMirrored="true"
android:tint="#000000"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:fillColor="@android:color/white"
android:pathData="M20,11H7.83l5.59,-5.59L12,4l-8,8 8,8 1.41,-1.41L7.83,13H20v-2z" />
</vector>
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ buildscript {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:7.4.2'
classpath 'com.android.tools.build:gradle:8.1.4'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath "com.google.dagger:hilt-android-gradle-plugin:$hilt_version"

Expand Down
5 changes: 4 additions & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,7 @@ org.gradle.jvmargs=-Xmx2048m -Dfile.encoding=UTF-8
# https://developer.android.com/topic/libraries/support-library/androidx-rn
android.useAndroidX=true
# Kotlin code style for this project: "official" or "obsolete":
kotlin.code.style=official
kotlin.code.style=official
android.defaults.buildfeatures.buildconfig=true
android.nonTransitiveRClass=false
android.nonFinalResIds=false
Loading

0 comments on commit 1e48b60

Please sign in to comment.