Skip to content

Commit

Permalink
Fixed Tldr not fetching latest commands. Updated to androidx. UI enha…
Browse files Browse the repository at this point in the history
…ncements
  • Loading branch information
vijjusri14 committed Jan 18, 2021
1 parent b33394e commit fe35b72
Show file tree
Hide file tree
Showing 34 changed files with 359 additions and 235 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
## tldroid
## tldroid (Working Clone)
[tldr](https://github.com/tldr-pages/tldr) Android client written in [Kotlin](https://kotlinlang.org/), uses [data binding](http://developer.android.com/tools/data-binding/guide.html), [Constraint Layout](http://tools.android.com/tech-docs/layout-editor), tested with [Android testing support library](https://google.github.io/android-testing-support-library/), compatible with Android 2.3 and up.


Expand Down
68 changes: 35 additions & 33 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,25 @@ apply plugin: 'kotlin-kapt'
apply plugin: 'jacoco'

android {
compileSdkVersion 25
buildToolsVersion "25.0.3"
compileSdkVersion 30
buildToolsVersion '30.0.3'

defaultConfig {
applicationId "io.github.hidroh.tldroid"
minSdkVersion 9
targetSdkVersion 25
minSdkVersion 14
targetSdkVersion 30
versionCode 10
versionName "1.6"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
testInstrumentationRunner 'androidx.test.runner.AndroidJUnitRunner'
resConfigs "en"
vectorDrawables.useSupportLibrary true
}

buildTypes {
debug {
testCoverageEnabled true
minifyEnabled true
useProguard false
minifyEnabled false
// useProguard false
proguardFile getDefaultProguardFile('proguard-android-optimize.txt')
proguardFile 'proguard-rules.pro'
}
Expand All @@ -33,8 +34,8 @@ android {
androidTest.java.srcDirs += 'src/androidTest/kotlin'
}

dataBinding {
enabled = true
buildFeatures {
dataBinding = true
}

testOptions {
Expand Down Expand Up @@ -70,39 +71,40 @@ android {
}

dependencies {
implementation "com.android.support:design:$supportLibraryVersion",
'com.android.support.constraint:constraint-layout:1.0.2',
implementation 'com.google.android.material:material:1.2.1',
'androidx.constraintlayout:constraintlayout:2.0.4',
'com.github.rjeschke:txtmark:0.13',
'com.squareup.moshi:moshi:1.2.0',
'com.squareup.okio:okio:1.8.0',
"org.jetbrains.kotlin:kotlin-stdlib:$kotlinVersion"
kapt "com.android.databinding:compiler:2.3.2"
testImplementation 'junit:junit:4.12',
'com.squareup.moshi:moshi-kotlin:1.11.0',
'com.squareup.okio:okio:3.0.0-alpha.1',
"org.jetbrains.kotlin:kotlin-stdlib:${kotlinVersion}",
'androidx.preference:preference-ktx:1.1.1'
kapt 'androidx.databinding:databinding-compiler:4.1.1'
testImplementation 'junit:junit:4.13.1',
'org.mockito:mockito-core:1.10.19',
'org.powermock:powermock-module-junit4:1.6.2',
'org.powermock:powermock-api-mockito:1.6.2',
'org.assertj:assertj-core:1.7.1', // test against android.jar which uses JDK6
'com.squareup.okhttp3:mockwebserver:3.3.1'
androidTestImplementation 'org.assertj:assertj-core:2.4.1',
"com.android.support:support-annotations:$supportLibraryVersion",
'com.android.support.test:runner:0.5',
'com.android.support.test:rules:0.5',
'com.android.support.test.espresso:espresso-core:2.2.2',
'com.android.support.test.espresso:espresso-idling-resource:2.2.2',
'com.android.support.test.espresso:espresso-intents:2.2.2',
'com.android.support.test.espresso:espresso-web:2.2.2'
'org.powermock:powermock-module-junit4:1.6.6',
'org.powermock:powermock-api-mockito:1.6.6',
'org.assertj:assertj-core:3.18.1', // test against android.jar which uses JDK6
'com.squareup.okhttp3:mockwebserver:4.9.0'
androidTestImplementation 'org.assertj:assertj-core:3.18.1',
'androidx.annotation:annotation:1.1.0',
'androidx.test.ext:junit:1.1.2',
'androidx.test:rules:1.3.0',
'androidx.test.espresso:espresso-core:3.3.0',
'androidx.test.espresso:espresso-idling-resource:3.3.0',
'androidx.test.espresso:espresso-intents:3.3.0',
'androidx.test.espresso:espresso-web:3.3.0'
}

task jacocoTestReport(type: JacocoReport, dependsOn: ['connectedAndroidTest', 'testDebugUnitTest']) {
sourceDirectories = files android.sourceSets.main.java.srcDirs
classDirectories = fileTree(
getSourceDirectories().setFrom(files(android.sourceSets.main.java.srcDirs))
classDirectories.setFrom(fileTree(
dir: "${buildDir}/intermediates/classes/debug",
exclude: ['**/R.class', '**/R$*.class', '**/databinding/**']
)
executionData = fileTree(
))
getExecutionData().setFrom(fileTree(
dir: "${buildDir}",
include: ['**/*.exec', '**/*.ec']
)
))
reports {
html.destination file("${buildDir}/reports/jacoco/html")
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
package io.github.hidroh.tldroid

import android.content.Intent
import android.support.test.InstrumentationRegistry
import android.support.test.espresso.Espresso.onView
import android.support.test.espresso.action.ViewActions.click
import android.support.test.espresso.intent.Intents.intended
import android.support.test.espresso.intent.matcher.ComponentNameMatchers.hasClassName
import android.support.test.espresso.intent.matcher.IntentMatchers.hasComponent
import android.support.test.espresso.intent.rule.IntentsTestRule
import android.support.test.espresso.matcher.ViewMatchers.withContentDescription
import android.support.test.espresso.matcher.ViewMatchers.withId
import android.support.test.espresso.web.assertion.WebViewAssertions.webContent
import android.support.test.espresso.web.matcher.DomMatchers.containingTextInBody
import android.support.test.espresso.web.sugar.Web.onWebView
import android.support.test.runner.AndroidJUnit4
import androidx.test.platform.app.InstrumentationRegistry
import androidx.test.espresso.Espresso.onView
import androidx.test.espresso.action.ViewActions.click
import androidx.test.espresso.intent.Intents.intended
import androidx.test.espresso.intent.matcher.ComponentNameMatchers.hasClassName
import androidx.test.espresso.intent.matcher.IntentMatchers.hasComponent
import androidx.test.espresso.intent.rule.IntentsTestRule
import androidx.test.espresso.matcher.ViewMatchers.withContentDescription
import androidx.test.espresso.matcher.ViewMatchers.withId
import androidx.test.espresso.web.assertion.WebViewAssertions.webContent
import androidx.test.espresso.web.matcher.DomMatchers.containingTextInBody
import androidx.test.espresso.web.sugar.Web.onWebView
import androidx.test.ext.junit.runners.AndroidJUnit4
import org.assertj.core.api.Assertions.assertThat
import org.junit.After
import org.junit.Rule
Expand Down Expand Up @@ -45,7 +45,7 @@ class CommandActivityTest {
@Test
fun testHomeClick() {
intentsRule.launchActivity(Intent().putExtra(CommandActivity.EXTRA_QUERY, "ls"))
onView(withContentDescription(InstrumentationRegistry.getTargetContext()
onView(withContentDescription(InstrumentationRegistry.getInstrumentation().targetContext
.getString(R.string.abc_action_bar_up_description)))
.perform(click())
assertThat(intentsRule.activity.isFinishing || intentsRule.activity.isDestroyed)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
package io.github.hidroh.tldroid

import android.app.Activity
import androidx.appcompat.app.AppCompatActivity
import android.content.ContentValues
import android.support.test.InstrumentationRegistry
import android.support.test.espresso.Espresso.onData
import android.support.test.espresso.Espresso.onView
import android.support.test.espresso.action.ViewActions.*
import android.support.test.espresso.assertion.ViewAssertions.doesNotExist
import android.support.test.espresso.assertion.ViewAssertions.matches
import android.support.test.espresso.intent.Intents.intended
import android.support.test.espresso.intent.matcher.ComponentNameMatchers.hasClassName
import android.support.test.espresso.intent.matcher.IntentMatchers.hasComponent
import android.support.test.espresso.intent.rule.IntentsTestRule
import android.support.test.espresso.matcher.CursorMatchers
import android.support.test.espresso.matcher.RootMatchers.isDialog
import android.support.test.espresso.matcher.RootMatchers.withDecorView
import android.support.test.espresso.matcher.ViewMatchers.*
import android.support.test.espresso.web.assertion.WebViewAssertions.webContent
import android.support.test.espresso.web.matcher.DomMatchers.containingTextInBody
import android.support.test.espresso.web.sugar.Web.onWebView
import android.support.test.runner.AndroidJUnit4
import androidx.test.platform.app.InstrumentationRegistry
import androidx.test.espresso.Espresso.onData
import androidx.test.espresso.Espresso.onView
import androidx.test.espresso.action.ViewActions.*
import androidx.test.espresso.assertion.ViewAssertions.doesNotExist
import androidx.test.espresso.assertion.ViewAssertions.matches
import androidx.test.espresso.intent.Intents.intended
import androidx.test.espresso.intent.matcher.ComponentNameMatchers.hasClassName
import androidx.test.espresso.intent.matcher.IntentMatchers.hasComponent
import androidx.test.espresso.intent.rule.IntentsTestRule
import androidx.test.espresso.matcher.CursorMatchers
import androidx.test.espresso.matcher.RootMatchers.isDialog
import androidx.test.espresso.matcher.RootMatchers.withDecorView
import androidx.test.espresso.matcher.ViewMatchers.*
import androidx.test.espresso.web.assertion.WebViewAssertions.webContent
import androidx.test.espresso.web.matcher.DomMatchers.containingTextInBody
import androidx.test.espresso.web.sugar.Web.onWebView
import androidx.test.ext.junit.runners.AndroidJUnit4
import io.github.hidroh.tldroid.test.EspressoHelper.waitForAtMost
import org.hamcrest.Matchers.`is`
import org.hamcrest.Matchers.not
Expand Down Expand Up @@ -74,19 +74,19 @@ class MainActivityTest {
intended(hasComponent(hasClassName(CommandActivity::class.java.name)))
}

class CustomTestRule<T : Activity>(activityClass: Class<T>?) : IntentsTestRule<T>(activityClass) {
class CustomTestRule<T : AppCompatActivity>(activityClass: Class<T>?) : IntentsTestRule<T>(activityClass) {
override fun beforeActivityLaunched() {
super.beforeActivityLaunched()
val cv = ContentValues()
cv.put(TldrProvider.CommandEntry.COLUMN_NAME, "ls")
cv.put(TldrProvider.CommandEntry.COLUMN_PLATFORM, "common")
InstrumentationRegistry.getTargetContext().contentResolver
InstrumentationRegistry.getInstrumentation().targetContext.contentResolver
.insert(TldrProvider.URI_COMMAND, cv);
}

override fun afterActivityFinished() {
super.afterActivityFinished()
InstrumentationRegistry.getTargetContext().contentResolver
InstrumentationRegistry.getInstrumentation().targetContext.contentResolver
.delete(TldrProvider.URI_COMMAND, null, null)
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package io.github.hidroh.tldroid

import android.content.Context
import android.support.annotation.WorkerThread
import androidx.annotation.WorkerThread

class MarkdownProcessor(private val platform: String?) {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package io.github.hidroh.tldroid

import android.content.Intent
import android.support.test.InstrumentationRegistry
import android.support.test.espresso.Espresso.onView
import android.support.test.espresso.action.ViewActions.*
import android.support.test.espresso.assertion.ViewAssertions.matches
import android.support.test.espresso.intent.rule.IntentsTestRule
import android.support.test.espresso.matcher.ViewMatchers.*
import android.support.test.runner.AndroidJUnit4
import androidx.test.platform.app.InstrumentationRegistry
import androidx.test.espresso.Espresso.onView
import androidx.test.espresso.action.ViewActions.*
import androidx.test.espresso.assertion.ViewAssertions.matches
import androidx.test.espresso.intent.rule.IntentsTestRule
import androidx.test.espresso.matcher.ViewMatchers.*
import androidx.test.ext.junit.runners.AndroidJUnit4
import org.hamcrest.Matchers.not
import org.junit.Rule
import org.junit.Test
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package io.github.hidroh.tldroid

import android.support.test.InstrumentationRegistry
import android.support.test.runner.AndroidJUnit4
import androidx.test.platform.app.InstrumentationRegistry
import androidx.test.ext.junit.runners.AndroidJUnit4
import org.assertj.core.api.Assertions.assertThat
import org.junit.After
import org.junit.Before
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package io.github.hidroh.tldroid

import android.content.ContentValues
import android.support.test.InstrumentationRegistry
import android.support.test.runner.AndroidJUnit4
import androidx.test.platform.app.InstrumentationRegistry
import androidx.test.ext.junit.runners.AndroidJUnit4
import android.test.ProviderTestCase2
import org.assertj.core.api.Assertions.assertThat
import org.junit.Before
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package io.github.hidroh.tldroid.test

import android.support.test.espresso.PerformException
import android.support.test.espresso.UiController
import android.support.test.espresso.ViewAction
import android.support.test.espresso.matcher.ViewMatchers.isRoot
import android.support.test.espresso.util.HumanReadables
import android.support.test.espresso.util.TreeIterables
import androidx.test.espresso.PerformException
import androidx.test.espresso.UiController
import androidx.test.espresso.ViewAction
import androidx.test.espresso.matcher.ViewMatchers.isRoot
import androidx.test.espresso.util.HumanReadables
import androidx.test.espresso.util.TreeIterables
import android.view.View
import org.hamcrest.Matcher
import java.util.concurrent.TimeoutException
Expand Down
5 changes: 4 additions & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.WAKE_LOCK" />

<application
android:name=".Application"
Expand Down Expand Up @@ -34,7 +35,9 @@
android:windowSoftInputMode="stateAlwaysVisible|adjustResize">
</activity>

<service android:name=".SyncService" android:exported="false" />
<service android:name=".SyncService"
android:permission="android.permission.BIND_JOB_SERVICE"
android:exported="false" />

<provider
android:authorities="io.github.hidroh.tldroid.provider"
Expand Down
13 changes: 9 additions & 4 deletions app/src/main/kotlin/io/github/hidroh/tldroid/Application.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,19 @@ import android.graphics.Typeface
class Application : android.app.Application() {
companion object {
var MONOSPACE_TYPEFACE: Typeface? = null
var indexIntent = Intent().apply{
putExtra(SyncService.EXTRA_ASSET_TYPE, SyncService.ASSET_TYPE_INDEX)
}
var zipIntent = Intent().apply{
putExtra(SyncService.EXTRA_ASSET_TYPE, SyncService.ASSET_TYPE_ZIP)
}
}

override fun onCreate() {
super.onCreate()
MONOSPACE_TYPEFACE = Typeface.createFromAsset(assets, "RobotoMono-Regular.ttf")
startService(Intent(this, SyncService::class.java)
.putExtra(SyncService.EXTRA_ASSET_TYPE, SyncService.ASSET_TYPE_INDEX))
startService(Intent(this, SyncService::class.java)
.putExtra(SyncService.EXTRA_ASSET_TYPE, SyncService.ASSET_TYPE_ZIP))
SyncService.enqueueWork(this, indexIntent)
SyncService.enqueueWork(this, zipIntent)
}

}
10 changes: 5 additions & 5 deletions app/src/main/kotlin/io/github/hidroh/tldroid/Bindings.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ package io.github.hidroh.tldroid

import android.content.Context
import android.database.Cursor
import android.databinding.BaseObservable
import android.databinding.BindingAdapter
import android.support.annotation.AttrRes
import android.support.annotation.IdRes
import android.support.v4.content.ContextCompat
import androidx.databinding.BaseObservable
import androidx.databinding.BindingAdapter
import androidx.annotation.AttrRes
import androidx.annotation.IdRes
import androidx.core.content.ContextCompat
import android.text.SpannableString
import android.text.Spanned
import android.text.TextUtils
Expand Down
Loading

0 comments on commit fe35b72

Please sign in to comment.