Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Arabic Language Configuration #155

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 0 additions & 16 deletions .idea/codeStyles/Project.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/gradle.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.

5 changes: 4 additions & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ android {

defaultConfig {
applicationId "com.rajat.sample.pdfviewer"
minSdkVersion 16
minSdkVersion 23
targetSdkVersion 33
versionCode 2
versionName "1.1"
Expand Down Expand Up @@ -47,4 +47,7 @@ dependencies {
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
implementation 'com.android.support:multidex:2.0.0'
implementation project(":pdfViewer")
// easy permissions
implementation 'com.vmadalin:easypermissions-ktx:1.0.0'
implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.4.0'
}
14 changes: 10 additions & 4 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,25 +1,31 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.rajat.sample.pdfviewer">
package="com.rajat.pdfviewer">

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_MEDIA_LOCATION" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"
<uses-permission
android:name="android.permission.WRITE_EXTERNAL_STORAGE"
tools:ignore="ScopedStorage" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.READ_MEDIA_AUDIO" />
<uses-permission android:name="android.permission.READ_MEDIA_IMAGES" />
<uses-permission android:name="android.permission.READ_MEDIA_VIDEO" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />


<application
android:requestLegacyExternalStorage="true"
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:requestLegacyExternalStorage="true"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity"
<activity
android:name="com.rajat.sample.pdfviewer.MainActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
Expand Down
79 changes: 32 additions & 47 deletions app/src/main/java/com/rajat/sample/pdfviewer/MainActivity.kt
Original file line number Diff line number Diff line change
@@ -1,28 +1,20 @@
package com.rajat.sample.pdfviewer

import android.Manifest
import android.content.pm.PackageManager
import android.Manifest.permission.READ_EXTERNAL_STORAGE
import android.Manifest.permission.READ_MEDIA_IMAGES
import android.os.Build
import android.os.Bundle
import android.widget.Toast
import androidx.appcompat.app.AppCompatActivity
import androidx.core.app.ActivityCompat
import androidx.core.content.ContextCompat
import com.rajat.pdfviewer.PdfViewerActivity
import com.rajat.sample.pdfviewer.databinding.ActivityMainBinding
import com.rajat.pdfviewer.databinding.ActivityMainBinding
import com.vmadalin.easypermissions.EasyPermissions


class MainActivity : AppCompatActivity() {
class MainActivity : AppCompatActivity(), EasyPermissions.PermissionCallbacks {

private lateinit var binding: ActivityMainBinding

private val requiredPermissionList = arrayOf(
Manifest.permission.WRITE_EXTERNAL_STORAGE,
Manifest.permission.READ_EXTERNAL_STORAGE
)

private var download_file_url = "https://github.com/afreakyelf/afreakyelf/raw/main/Log4_Shell_Mid_Term_final.pdf"
var per = 0f
private val PERMISSION_CODE = 4040
private var download_file_url =
"https://github.com/afreakyelf/afreakyelf/raw/main/Log4_Shell_Mid_Term_final.pdf"

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
Expand All @@ -31,40 +23,42 @@ class MainActivity : AppCompatActivity() {
setContentView(view)

binding.openPdf.setOnClickListener {
if (checkAndRequestPermission())
launchPdf()
requestFilesPermission()
}
}

private fun launchPdf() {
startActivity(
PdfViewerActivity.launchPdfFromUrl(
context = this, pdfUrl = download_file_url,
pdfTitle = "Title", directoryName = "dir", enableDownload = true)
pdfTitle = "Title", directoryName = "dir", enableDownload = true
)
)
}

private fun checkAndRequestPermission(): Boolean {
val permissionsNeeded = ArrayList<String>()

for (permission in requiredPermissionList) {
if (ContextCompat.checkSelfPermission(this, permission) !=
PackageManager.PERMISSION_GRANTED
) {
permissionsNeeded.add(permission)
private fun requestFilesPermission() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
if (hasPermission(READ_MEDIA_IMAGES)) {
launchPdf()
} else if (enableRequestPermission(READ_MEDIA_IMAGES)) {
requestPermission(READ_MEDIA_IMAGES, 1, "")
}
} else {
if (this.hasPermission(READ_EXTERNAL_STORAGE)) {
launchPdf()
} else if (enableRequestPermission(READ_EXTERNAL_STORAGE)) {
requestPermission(READ_EXTERNAL_STORAGE, 1, "")
}
}
}

if (permissionsNeeded.isNotEmpty()) {
ActivityCompat.requestPermissions(
this,
permissionsNeeded.toTypedArray(),
PERMISSION_CODE
)
return false
}
override fun onPermissionsDenied(requestCode: Int, perms: List<String>) {
}

return true
override fun onPermissionsGranted(requestCode: Int, perms: List<String>) {
if (requestCode == 1) {
launchPdf()
}
}

override fun onRequestPermissionsResult(
Expand All @@ -73,17 +67,8 @@ class MainActivity : AppCompatActivity() {
grantResults: IntArray
) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults)
when (requestCode) {
PERMISSION_CODE -> if (grantResults.isNotEmpty()) {
val readPermission = grantResults[0] == PackageManager.PERMISSION_GRANTED
val writePermission = grantResults[1] == PackageManager.PERMISSION_GRANTED
if (readPermission && writePermission)
launchPdf()
else {
Toast.makeText(this, " Permission Denied", Toast.LENGTH_SHORT).show()
}
}
if (requestCode == 1) {
launchPdf()
}
}

}
37 changes: 37 additions & 0 deletions app/src/main/java/com/rajat/sample/pdfviewer/Permissions.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package com.rajat.sample.pdfviewer

import android.annotation.SuppressLint
import android.app.Activity
import android.content.Context
import android.content.pm.PackageManager
import android.view.View
import androidx.core.content.ContextCompat
import com.vmadalin.easypermissions.EasyPermissions

fun Context.isPermissionGranted(permission: String): Boolean {
return ContextCompat.checkSelfPermission(this, permission) == PackageManager.PERMISSION_GRANTED
}

@SuppressLint("MissingPermission")
fun View.isPermissionGranted(permission: String): Boolean {
return context.isPermissionGranted(permission)
}


fun Activity.hasPermission(permission: String) = EasyPermissions.hasPermissions(
this,
permission
)

fun Activity.requestPermission(permission: String, requestCode: Int, rationalText: String) {
EasyPermissions.requestPermissions(
this,
rationalText,
requestCode,
permission
)
}

fun Activity.enableRequestPermission(permission: String): Boolean {
return EasyPermissions.somePermissionPermanentlyDenied(this, listOf(permission))
}
2 changes: 1 addition & 1 deletion app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
android:id="@+id/open_pdf"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:backgroundTint="@color/colorPrimary"
android:text="Open pdf"
android:textAllCaps="false"
android:backgroundTint="@color/colorPrimary"
android:textColor="#ffffff"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
Expand Down
32 changes: 13 additions & 19 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,21 +1,15 @@
# Project-wide Gradle settings.
# IDE (e.g. Android Studio) users:
# Gradle settings configured through the IDE *will override*
# any settings specified in this file.
# For more details on how to configure your build environment visit
# http://www.gradle.org/docs/current/userguide/build_environment.html
# Specifies the JVM arguments used for the daemon process.
# The setting is particularly useful for tweaking memory settings.
org.gradle.jvmargs=-Xmx2048m
# When configured, Gradle will run in incubating parallel mode.
# This option should only be used with decoupled projects. More details, visit
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
# org.gradle.parallel=true
# AndroidX package structure to make it clearer which packages are bundled with the
# Android operating system, and which are packaged with your app"s APK
# https://developer.android.com/topic/libraries/support-library/androidx-rn
# Gradle
org.gradle.jvmargs=-Xmx8192m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
org.gradle.parallel=true
org.gradle.configureondemand=true
org.gradle.daemon=true
#
# Kotlin
kotlin.code.style=official
#
# Android
android.useAndroidX=true
# Automatically convert third-party libraries to use AndroidX
android.enableJetifier=true
# Kotlin code style for this project: "official" or "obsolete":
kotlin.code.style=official
android.databinding.incremental=true
android.viewbinding.incremental=true
android.lifecycleProcessor.incremental=true
5 changes: 4 additions & 1 deletion pdfViewer/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ android {
compileSdkVersion 33

defaultConfig {
minSdkVersion 16
minSdkVersion 23
targetSdkVersion 33
multiDexEnabled true
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
Expand Down Expand Up @@ -48,5 +48,8 @@ dependencies {
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.4'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.0'
// easy permissions
implementation 'com.vmadalin:easypermissions-ktx:1.0.0'
implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.4.0'

}
3 changes: 3 additions & 0 deletions pdfViewer/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
<uses-permission android:name="android.permission.ACCESS_MEDIA_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.READ_MEDIA_AUDIO" />
<uses-permission android:name="android.permission.READ_MEDIA_IMAGES" />
<uses-permission android:name="android.permission.READ_MEDIA_VIDEO" />

<application android:requestLegacyExternalStorage="true">
<activity
Expand Down
Loading