Skip to content
This repository has been archived by the owner on Dec 3, 2024. It is now read-only.

Commit

Permalink
Merge pull request #8 from ngti/release-1.1
Browse files Browse the repository at this point in the history
Release 1.1
  • Loading branch information
MikeMostovyi authored Sep 15, 2021
2 parents 05b4384 + 3694b0b commit 73492d7
Show file tree
Hide file tree
Showing 16 changed files with 152 additions and 172 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ Androscope supports Android applications with minimum API level 16.
Add Androscope dependency to your Gradle script:

```
debugImplementation 'nl.ngti:androscope:1.0'
debugImplementation 'nl.ngti:androscope:1.1'
```

Also make sure [Java 8 language features support](https://developer.android.com/studio/write/java8-support#supported_features) is enabled (required since 1.0-RC4).
Expand Down
6 changes: 4 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'

android {
compileSdkVersion 31
Expand All @@ -22,12 +21,15 @@ android {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
buildFeatures {
viewBinding true
}
}

dependencies {
implementation 'androidx.appcompat:appcompat:1.3.1'
implementation 'androidx.constraintlayout:constraintlayout:2.1.0'
implementation 'androidx.work:work-runtime:2.6.0'
implementation 'androidx.work:work-runtime:2.7.0-beta01'
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test:runner:1.4.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
Expand Down
37 changes: 22 additions & 15 deletions app/src/main/java/nl/ngti/androscope/test/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,34 +5,40 @@ import android.content.Context
import android.content.Intent
import android.os.Build
import android.os.Bundle
import android.view.View
import androidx.appcompat.app.AppCompatActivity
import nl.ngti.androscope.AndroscopeActivity
import nl.ngti.androscope.test.databinding.ActivityMainBinding

class MainActivity : AppCompatActivity(R.layout.activity_main), View.OnClickListener {
class MainActivity : AppCompatActivity() {

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)

findViewById<View>(R.id.open_androscope_activity).setOnClickListener(this)
findViewById<View>(R.id.button_grant_storage_permission).setOnClickListener(this)
findViewById<View>(R.id.button_grant_contacts_permission).setOnClickListener(this)
ActivityMainBinding.inflate(layoutInflater).apply {
setContentView(root)
bindViews()
}

addSamplePreferences()
}

override fun onClick(v: View) {
when (v.id) {
R.id.open_androscope_activity -> openAndroscopeActivity()
R.id.button_grant_contacts_permission -> requestPermissions(Manifest.permission.READ_CONTACTS)
R.id.button_grant_storage_permission -> requestPermissions(Manifest.permission.WRITE_EXTERNAL_STORAGE)
private fun ActivityMainBinding.bindViews() {
openAndroscopeActivity.setOnClickListener {
openAndroscopeActivity()
}
buttonGrantStoragePermission.setOnClickListener {
requestPermissions(Manifest.permission.WRITE_EXTERNAL_STORAGE)
}
buttonGrantContactsPermission.setOnClickListener {
requestPermissions(Manifest.permission.READ_CONTACTS)
}
}

private fun addSamplePreferences() {
val prefs = getSharedPreferences("sample", Context.MODE_PRIVATE)
if (!prefs.contains("sample_key")) {
prefs.edit().putString("sample_key", "Sample Value").apply()
getSharedPreferences("sample", Context.MODE_PRIVATE).run {
if (!contains("sample_key")) {
edit().putString("sample_key", "Sample Value").apply()
}
}
}

Expand All @@ -43,7 +49,8 @@ class MainActivity : AppCompatActivity(R.layout.activity_main), View.OnClickList
}

private fun openAndroscopeActivity() {
val intent = Intent(this, AndroscopeActivity::class.java)
startActivity(intent)
Intent(this, AndroscopeActivity::class.java).also {
startActivity(it)
}
}
}
6 changes: 2 additions & 4 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
ext.kotlin_version = '1.5.21'
ext.kotlin_version = '1.5.30'

repositories {
google()
jcenter()
mavenCentral()
}
dependencies {
Expand All @@ -14,15 +13,14 @@ buildscript {
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath "org.jetbrains.dokka:dokka-gradle-plugin:0.10.1"
classpath "org.jetbrains.dokka:dokka-gradle-plugin:$kotlin_version"
classpath 'com.vanniktech:gradle-maven-publish-plugin:0.17.0'
}
}

allprojects {
repositories {
google()
jcenter()
mavenCentral()
}
}
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ org.gradle.jvmargs=-Xmx1536m
# org.gradle.parallel=true

GROUP=nl.ngti
VERSION_NAME=1.0
VERSION_NAME=1.1

POM_URL=https://github.com/ngti/androscope
POM_SCM_URL=https://github.com/ngti/androscope
Expand Down
9 changes: 0 additions & 9 deletions lib-androscope/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ android {
defaultConfig {
minSdkVersion 16
targetSdkVersion 31
versionCode 1
versionName "1.0"

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
consumerProguardFiles 'consumer-rules.pro'
Expand All @@ -34,7 +32,6 @@ android {

dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
implementation "androidx.lifecycle:lifecycle-livedata-core-ktx:2.3.1"
implementation 'androidx.activity:activity-ktx:1.3.1'
implementation 'androidx.core:core-ktx:1.6.0'
implementation 'org.nanohttpd:nanohttpd-webserver:2.3.1'
Expand All @@ -45,10 +42,4 @@ dependencies {
}

apply plugin: 'org.jetbrains.dokka'

dokka {
outputFormat = 'html'
outputDirectory = "$buildDir/javadoc"
}

apply plugin: "com.vanniktech.maven.publish"
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import android.view.View
import android.widget.Button
import android.widget.TextView
import androidx.activity.ComponentActivity
import androidx.lifecycle.observe
import nl.ngti.androscope.service.AndroscopeService
import nl.ngti.androscope.service.AndroscopeService.LocalBinder

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,26 +53,3 @@ internal class FileSystemData(
}
}
}

private data class SortParams(
private val sortOrder: String?,
private val sortColumn: String?
) {

val comparator: Comparator<FileSystemEntry>
get() {
var result = SortParamsUtil.getFolderComparator()
sortOrderComparator?.let {
result = result then it
}
return result
}

private val sortOrderComparator: Comparator<FileSystemEntry>?
get() =
sortOrder?.let { order ->
sortColumn?.let { column ->
SortParamsUtil.getSortingComparator(order, column)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package nl.ngti.androscope.responses.files
import nl.ngti.androscope.responses.common.indexOfExtension
import java.io.File

private const val NOT_INITIALIZED = -1L

internal interface IFormatter {

fun formatFileSize(size: Long): String
Expand All @@ -28,22 +30,22 @@ internal class FileSystemEntry internal constructor(
var size: String? = null

@Transient
private var dateOnDemand: Long = -1
private var dateOnDemand: Long = NOT_INITIALIZED

val dateAsLong: Long
get() {
if (dateOnDemand == -1L) {
if (dateOnDemand == NOT_INITIALIZED) {
dateOnDemand = file.lastModified()
}
return dateOnDemand
}

@Transient
private var sizeOnDemand: Long = if (isFolder) 0 else -1
private var sizeOnDemand: Long = if (isFolder) 0 else NOT_INITIALIZED

val sizeAsLong: Long
get() {
if (sizeOnDemand == -1L) {
if (sizeOnDemand == NOT_INITIALIZED) {
sizeOnDemand = file.length()
}
return sizeOnDemand
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
package nl.ngti.androscope.responses.files

import java.lang.IllegalArgumentException
import java.util.Collections
import kotlin.Comparator

internal data class SortParams(
private val sortOrder: String?,
private val sortColumn: String?
) {

val comparator: Comparator<FileSystemEntry>
get() {
var result = folderComparator
sortOrderComparator?.let {
result = result then it
}
return result
}

private val sortOrderComparator: Comparator<FileSystemEntry>?
get() =
sortOrder?.let { order ->
sortColumn?.let { column ->
getSortingComparator(order, column)
}
}

companion object {
val folderComparator: Comparator<FileSystemEntry>
get() = compare(valueSelector = {
it.isFolder
}) { a, b ->
// Folders should be shown first
java.lang.Boolean.compare(b, a)
}

fun getSortingComparator(order: String, column: String): Comparator<FileSystemEntry> {
val nameComparator = compareStrings(FileSystemEntry::name)
val mainComparator: Comparator<FileSystemEntry> = when (column) {
"name" -> nameComparator
"extension" -> compareStrings(FileSystemEntry::extension)
"date" -> compareLong(FileSystemEntry::dateAsLong)
"size" -> compareLong(FileSystemEntry::sizeAsLong)
else -> throw IllegalArgumentException("Illegal sort column: $column")
}
var comparator: Comparator<FileSystemEntry> = if (mainComparator !== nameComparator) {
mainComparator then nameComparator
} else {
mainComparator
}
if ("desc" == order) {
comparator = Collections.reverseOrder(comparator)
}
return comparator
}

private fun compareStrings(selector: FileSystemEntryValueSelector<String>) = compare(selector) { a, b ->
a.compareTo(b, ignoreCase = true)
}

private fun compareLong(selector: FileSystemEntryValueSelector<Long>) = compare(selector) { a, b ->
a.compareTo(b)
}

private inline fun <T> compare(
valueSelector: FileSystemEntryValueSelector<T>,
crossinline compareBlock: (a: T, b: T) -> Int
): Comparator<FileSystemEntry> {
return Comparator { a: FileSystemEntry, b: FileSystemEntry ->
compareBlock(valueSelector(a), valueSelector(b))
}
}

private fun interface FileSystemEntryValueSelector<T> {
operator fun invoke(entry: FileSystemEntry): T
}
}
}
Loading

0 comments on commit 73492d7

Please sign in to comment.