Skip to content

Commit c52ccdc

Browse files
committed
add: init project
1 parent be26c8c commit c52ccdc

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+960
-0
lines changed

app/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/build

app/build.gradle

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
plugins {
2+
id 'com.android.application'
3+
id 'org.jetbrains.kotlin.android'
4+
}
5+
6+
android {
7+
compileSdk 32
8+
9+
defaultConfig {
10+
applicationId "com.gofarsi.book"
11+
minSdk 21
12+
targetSdk 32
13+
versionCode 1
14+
versionName "1.0.0"
15+
16+
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
17+
}
18+
19+
buildTypes {
20+
release {
21+
minifyEnabled false
22+
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
23+
}
24+
}
25+
compileOptions {
26+
sourceCompatibility JavaVersion.VERSION_1_8
27+
targetCompatibility JavaVersion.VERSION_1_8
28+
}
29+
kotlinOptions {
30+
jvmTarget = '1.8'
31+
}
32+
}
33+
34+
dependencies {
35+
36+
implementation 'androidx.core:core-ktx:1.7.0'
37+
implementation 'androidx.appcompat:appcompat:1.5.1'
38+
implementation 'com.google.android.material:material:1.7.0'
39+
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
40+
testImplementation 'junit:junit:4.13.2'
41+
androidTestImplementation 'androidx.test.ext:junit:1.1.4'
42+
androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.0'
43+
}

app/proguard-rules.pro

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Add project specific ProGuard rules here.
2+
# You can control the set of applied configuration files using the
3+
# proguardFiles setting in build.gradle.
4+
#
5+
# For more details, see
6+
# http://developer.android.com/guide/developing/tools/proguard.html
7+
8+
# If your project uses WebView with JS, uncomment the following
9+
# and specify the fully qualified class name to the JavaScript interface
10+
# class:
11+
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12+
# public *;
13+
#}
14+
15+
# Uncomment this to preserve the line number information for
16+
# debugging stack traces.
17+
#-keepattributes SourceFile,LineNumberTable
18+
19+
# If you keep the line number information, uncomment this to
20+
# hide the original source file name.
21+
#-renamesourcefileattribute SourceFile

app/release/app-release.apk

4.21 MB
Binary file not shown.

app/release/output-metadata.json

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{
2+
"version": 3,
3+
"artifactType": {
4+
"type": "APK",
5+
"kind": "Directory"
6+
},
7+
"applicationId": "com.gofarsi.book",
8+
"variantName": "release",
9+
"elements": [
10+
{
11+
"type": "SINGLE",
12+
"filters": [],
13+
"attributes": [],
14+
"versionCode": 1,
15+
"versionName": "1.0.0",
16+
"outputFile": "app-release.apk"
17+
}
18+
],
19+
"elementType": "File"
20+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package com.book.gofarsi
2+
3+
import androidx.test.platform.app.InstrumentationRegistry
4+
import androidx.test.ext.junit.runners.AndroidJUnit4
5+
6+
import org.junit.Test
7+
import org.junit.runner.RunWith
8+
9+
import org.junit.Assert.*
10+
11+
/**
12+
* Instrumented test, which will execute on an Android device.
13+
*
14+
* See [testing documentation](http://d.android.com/tools/testing).
15+
*/
16+
@RunWith(AndroidJUnit4::class)
17+
class ExampleInstrumentedTest {
18+
@Test
19+
fun useAppContext() {
20+
// Context of the app under test.
21+
val appContext = InstrumentationRegistry.getInstrumentation().targetContext
22+
assertEquals("com.book.gofarsi", appContext.packageName)
23+
}
24+
}

app/src/main/AndroidManifest.xml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
3+
xmlns:tools="http://schemas.android.com/tools"
4+
package="com.book.gofarsi">
5+
<uses-permission android:name="android.permission.INTERNET" />
6+
<application
7+
android:allowBackup="true"
8+
android:dataExtractionRules="@xml/data_extraction_rules"
9+
android:fullBackupContent="@xml/backup_rules"
10+
android:icon="@mipmap/ic_launcher"
11+
android:label="@string/app_name"
12+
android:roundIcon="@mipmap/ic_launcher_round"
13+
android:supportsRtl="true"
14+
android:theme="@style/Theme.GoFarsi"
15+
tools:targetApi="31">
16+
<activity
17+
android:name=".WebActivity"
18+
android:exported="true">
19+
<intent-filter>
20+
<action android:name="android.intent.action.MAIN" />
21+
22+
<category android:name="android.intent.category.LAUNCHER" />
23+
</intent-filter>
24+
</activity>
25+
</application>
26+
27+
</manifest>
19.9 KB
Loading
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package com.book.gofarsi
2+
3+
import androidx.appcompat.app.AppCompatActivity
4+
import android.os.Bundle
5+
6+
class MainActivity : AppCompatActivity() {
7+
override fun onCreate(savedInstanceState: Bundle?) {
8+
super.onCreate(savedInstanceState)
9+
setContentView(R.layout.activity_main)
10+
}
11+
}
Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
package com.book.gofarsi
2+
3+
import android.content.Context
4+
import android.content.Intent
5+
import android.os.Build
6+
import android.os.Bundle
7+
import android.os.Handler
8+
import android.os.Looper
9+
import android.view.View
10+
import android.webkit.CookieManager
11+
import android.webkit.WebSettings
12+
import android.webkit.WebView
13+
import android.webkit.WebViewClient
14+
import android.widget.RelativeLayout
15+
import android.widget.TextView
16+
import androidx.appcompat.app.AppCompatActivity
17+
18+
19+
//import org.jsoup.Jsoup
20+
21+
class WebActivity : AppCompatActivity() {
22+
var myWebView :WebView? = null;
23+
override fun onCreate(savedInstanceState: Bundle?) {
24+
super.onCreate(savedInstanceState)
25+
setContentView(R.layout.activity_web)
26+
27+
// webSettings()
28+
29+
var title = intent.extras?.getString(KEY_TITLE) ?: ""
30+
var link = intent.extras?.getString(KEY_LINK) ?: ""
31+
32+
link = "https://book.gofarsi.ir/"
33+
34+
findViewById<TextView>(R.id.tvVersion).text = BuildConfig.VERSION_NAME
35+
myWebView = findViewById(R.id.webview);
36+
loadWebView(this, link, myWebView!!)
37+
var view = findViewById<RelativeLayout>(R.id.loading)
38+
Handler(Looper.getMainLooper()).postDelayed({
39+
view.visibility = View.INVISIBLE
40+
}, 5000)
41+
42+
}
43+
44+
45+
/* fun getNewContent(htmltext: String): String {
46+
47+
val doc = Jsoup.parse(htmltext)
48+
val elements = doc.getElementsByTag("img")
49+
for (element in elements) {
50+
element.attr("width", "100%").attr("height", "auto")
51+
}
52+
53+
return doc.toString()
54+
}*/
55+
56+
57+
companion object {
58+
val KEY_TITLE = "title"
59+
val KEY_LINK = "link"
60+
fun navigate(context: Context, title: String, link: String) {
61+
val intent = Intent(context, WebActivity::class.java).apply {
62+
putExtra(KEY_TITLE, title)
63+
putExtra(KEY_LINK, link)
64+
}
65+
context.startActivity(intent)
66+
}
67+
68+
fun loadWebView(context: Context, content: String, myWebView: WebView) {
69+
70+
setSettingWebView(context, myWebView)
71+
myWebView.loadUrl(content)
72+
73+
}
74+
75+
private fun setSettingWebView(context: Context, myWebView: WebView) {
76+
myWebView?.let {
77+
it.settings?.builtInZoomControls = false
78+
it.settings?.databaseEnabled = true
79+
it.settings?.domStorageEnabled = true
80+
it.settings?.setGeolocationEnabled(true)
81+
it.settings?.loadWithOverviewMode = true
82+
it.settings?.useWideViewPort = true
83+
it.isScrollbarFadingEnabled = false
84+
85+
it.clearCache(false)
86+
// it.settings?.setAppCachePath(context.cacheDir?.absolutePath)
87+
// it.settings?.setAppCacheEnabled(true)
88+
it.settings?.allowFileAccess = true
89+
it.settings?.javaScriptEnabled = true
90+
it.settings?.cacheMode = WebSettings.LOAD_DEFAULT
91+
it.settings?.defaultTextEncodingName = "utf-8"
92+
it.settings?.javaScriptCanOpenWindowsAutomatically = true
93+
94+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
95+
CookieManager.getInstance().setAcceptThirdPartyCookies(it, true)
96+
}
97+
it.settings?.pluginState = WebSettings.PluginState.ON
98+
}
99+
myWebView.webViewClient = object : WebViewClient() {
100+
override fun shouldOverrideUrlLoading(view: WebView, url: String): Boolean {
101+
return false
102+
}
103+
}
104+
}
105+
}
106+
107+
override fun onBackPressed() {
108+
if (myWebView?.canGoBack() == true) {
109+
myWebView?.goBack()
110+
} else {
111+
super.onBackPressed()
112+
}
113+
}
114+
}

0 commit comments

Comments
 (0)