From d8e4ae757dd2387889bc784977820a9efa5cebf0 Mon Sep 17 00:00:00 2001 From: Hans Date: Wed, 19 Dec 2018 10:32:45 +0100 Subject: [PATCH 1/2] added kotlin to project, refs #319 --- app/build.gradle | 9 +++++++-- build.gradle | 4 +++- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index c117785d9..e8fa0fcea 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -1,4 +1,6 @@ apply plugin: 'com.android.application' +apply plugin: 'kotlin-android' +apply plugin: 'kotlin-android-extensions' android { compileSdkVersion = 27 @@ -16,8 +18,7 @@ android { testInstrumentationRunner = "android.test.InstrumentationTestRunner" ndk { - abiFilters 'x86', 'x86_64', 'armeabi', 'armeabi-v7a', - 'arm64-v8a', 'mips', 'mips64' + abiFilters 'x86', 'x86_64', 'armeabi-v7a', 'arm64-v8a' } } @@ -57,4 +58,8 @@ dependencies { implementation 'com.madgag.spongycastle:prov:1.58.0.0' implementation 'joda-time:joda-time:2.9.4' implementation 'com.android.support:support-compat:27.1.1' + implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" +} +repositories { + mavenCentral() } diff --git a/build.gradle b/build.gradle index 46cee941e..a0963b5cd 100644 --- a/build.gradle +++ b/build.gradle @@ -1,15 +1,17 @@ // Top-level build file where you can add configuration options common to all sub-projects/modules. buildscript { + ext.kotlin_version = '1.3.11' repositories { + google() jcenter() maven { url 'https://maven.google.com/' name 'Google' } - google() } dependencies { classpath 'com.android.tools.build:gradle:3.1.2' + classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" } } From becf352c228b140f953447ff150f99098868da70 Mon Sep 17 00:00:00 2001 From: Hans Date: Wed, 19 Dec 2018 10:34:00 +0100 Subject: [PATCH 2/2] updates to xml layout and file selection Activity and Adapter to show both a short filename and a full filepath resolving issue: Add a display name to recently used database list #319 --- .../fileselect/FileSelectActivity.java | 7 ++-- .../fileselect/RecentFileAdapter.kt | 28 +++++++++++++++ app/src/main/res/layout/file_row.xml | 35 ++++++++++++++++--- 3 files changed, 61 insertions(+), 9 deletions(-) create mode 100644 app/src/main/java/com/keepassdroid/fileselect/RecentFileAdapter.kt diff --git a/app/src/main/java/com/keepassdroid/fileselect/FileSelectActivity.java b/app/src/main/java/com/keepassdroid/fileselect/FileSelectActivity.java index 5a22ac3e5..0136ebb2c 100644 --- a/app/src/main/java/com/keepassdroid/fileselect/FileSelectActivity.java +++ b/app/src/main/java/com/keepassdroid/fileselect/FileSelectActivity.java @@ -79,9 +79,8 @@ public class FileSelectActivity extends Activity { - private static final int MY_PERMISSIONS_REQUEST_EXTERNAL_STORAGE = 111; private ListView mList; - private ListAdapter mAdapter; + private RecentFileAdapter mAdapter; private static final int CMENU_CLEAR = Menu.FIRST; @@ -331,10 +330,10 @@ public void run() { private void fillData() { // Set the initial value of the filename - EditText filename = (EditText) findViewById(R.id.file_filename); + EditText filename = findViewById(R.id.file_filename); filename.setText(Environment.getExternalStorageDirectory().getAbsolutePath() + getString(R.string.default_file_path)); - mAdapter = new ArrayAdapter(this, R.layout.file_row, R.id.file_filename, fileHistory.getDbList()); + mAdapter = new RecentFileAdapter(this, fileHistory.getDbList()); mList.setAdapter(mAdapter); } diff --git a/app/src/main/java/com/keepassdroid/fileselect/RecentFileAdapter.kt b/app/src/main/java/com/keepassdroid/fileselect/RecentFileAdapter.kt new file mode 100644 index 000000000..dd86d848b --- /dev/null +++ b/app/src/main/java/com/keepassdroid/fileselect/RecentFileAdapter.kt @@ -0,0 +1,28 @@ +package com.keepassdroid.fileselect + +import android.content.Context +import android.view.View +import android.view.ViewGroup +import android.widget.ArrayAdapter +import com.android.keepass.R +import kotlinx.android.synthetic.main.file_row.view.filename +import kotlinx.android.synthetic.main.file_row.view.filepath +import android.view.LayoutInflater + + + +class RecentFileAdapter(context: Context, val items: List) + : ArrayAdapter(context, R.layout.file_row, R.id.file_filename, items) { + + override fun getView(position: Int, convertView: View?, parent: ViewGroup?): View? { + var itemView = convertView + if( itemView == null ){ + val vi = context.getSystemService(Context.LAYOUT_INFLATER_SERVICE) as LayoutInflater + itemView = vi.inflate(R.layout.file_row, null) + } + itemView?.filename?.text = items.get(position).substringAfterLast('/') + itemView?.filepath?.text = items.get(position) + + return itemView + } +} diff --git a/app/src/main/res/layout/file_row.xml b/app/src/main/res/layout/file_row.xml index f48146979..02087575f 100644 --- a/app/src/main/res/layout/file_row.xml +++ b/app/src/main/res/layout/file_row.xml @@ -1,5 +1,4 @@ - - - \ No newline at end of file + android:orientation="vertical"> + + + + + +