Skip to content

Commit

Permalink
Merge pull request #4 from apozas/master
Browse files Browse the repository at this point in the history
Sync w/ upstream.
  • Loading branch information
igor-cali authored Dec 6, 2020
2 parents 283feb8 + 735bac9 commit 8c26e17
Show file tree
Hide file tree
Showing 74 changed files with 3,188 additions and 1,666 deletions.
12 changes: 12 additions & 0 deletions .github/FUNDING.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# These are supported funding model platforms

github: # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2]
patreon: # Replace with a single Patreon username
open_collective: # Replace with a single Open Collective username
ko_fi: # Replace with a single Ko-fi username
tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel
community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry
liberapay: # Replace with a single Liberapay username
issuehunt: # Replace with a single IssueHunt username
otechie: # Replace with a single Otechie username
custom: ['https://paypal.me/apozasker'] # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2']
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ Every day Contact Diary will prompt you to insert the events you have attended a
- Configurable notification time, so the prompt does not interfere with your daily workflow.
- Show only potentially risky contacts.
- Automatic removal of entries older than 15 days.
- Export your latest contacts to a CSV file that you can share with the authorities.
- JUST ONE PERMISSION, that needed for the app being able to notify you after device restarts. Nothing else.
- In particular, NO INTERNET permission. The information entered is yours, and it never leaves your device.

Expand Down
17 changes: 9 additions & 8 deletions android_app/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,17 @@ apply plugin: 'kotlin-android-extensions'

android {
compileSdkVersion 30
buildToolsVersion "30.0.1"
buildToolsVersion "30.0.2"

defaultConfig {
applicationId "com.apozas.contactdiary"
minSdkVersion 14
targetSdkVersion 30
versionCode 10
versionName "1.1.4"
versionCode 12
versionName "1.3.0"

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
multiDexEnabled true
}

applicationVariants.all { variant ->
Expand Down Expand Up @@ -46,14 +47,14 @@ android {
dependencies {
implementation fileTree(dir: "libs", include: ["*.jar"])
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
implementation 'androidx.core:core-ktx:1.3.1'
implementation 'androidx.core:core-ktx:1.3.2'
implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'com.google.android.material:material:1.2.1'
implementation 'androidx.constraintlayout:constraintlayout:2.0.1'
implementation 'androidx.navigation:navigation-fragment-ktx:2.3.0'
implementation 'androidx.navigation:navigation-ui-ktx:2.3.0'
implementation 'androidx.preference:preference:1.1.1'
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
implementation 'androidx.navigation:navigation-fragment-ktx:2.3.1'
implementation 'androidx.navigation:navigation-ui-ktx:2.3.1'
implementation 'androidx.preference:preference-ktx:1.1.1'
implementation 'com.android.support:multidex:1.0.3'
testImplementation 'junit:junit:4.13'
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
Expand Down
15 changes: 13 additions & 2 deletions android_app/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -54,18 +54,29 @@
<activity android:name=".SettingsActivity"
android:label="@string/options"
android:parentActivityName=".MainActivity"
android:launchMode="singleTop">
android:launchMode="singleTop"
android:screenOrientation="portrait" >
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value=".MainActivity"/>
</activity>
<activity android:name=".PrivacyActivity"
android:label="@string/privacy_title">
android:label="@string/privacy_title"
android:screenOrientation="portrait" >
<intent-filter>
<action android:name="${applicationId}.PrivacyActivity" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name=".ThanksActivity"
android:label="@string/acknowledgments"
android:screenOrientation="portrait" >
<intent-filter>
<action android:name="${applicationId}.ThanksActivity" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<receiver
android:name=".NotificationReceiver"
android:enabled="true" >
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,16 @@ class ContactDatabase {
const val TYPE_COLUMN = "Type"
const val NAME_COLUMN = "Name"
const val PLACE_COLUMN = "Place"
const val DATETIME_COLUMN = "Timestamp"
const val TIMESTAMP_COLUMN = "Timestamp"
const val DURATION_COLUMN = "Duration"
const val PHONE_COLUMN = "Phone"
const val RELATIVE_COLUMN = "Relative"
const val COMPANIONS_COLUMN = "Companions"
const val CLOSECONTACT_COLUMN = "CloseContact"
const val ENCOUNTER_COLUMN = "EncounterType"
const val NOTES_COLUMN = "Notes"
const val TIME_BEGIN_COLUMN = "BeginTime"
const val TIME_END_COLUMN = "EndTime"
}
}

Expand All @@ -42,7 +45,8 @@ class ContactDatabase {
"${ContactDatabase.FeedEntry.TYPE_COLUMN} TEXT," +
"${ContactDatabase.FeedEntry.NAME_COLUMN} TEXT," +
"${ContactDatabase.FeedEntry.PLACE_COLUMN} TEXT," +
"${ContactDatabase.FeedEntry.DATETIME_COLUMN} INT," +
"${ContactDatabase.FeedEntry.TIME_BEGIN_COLUMN} INT," +
"${ContactDatabase.FeedEntry.TIME_END_COLUMN} INT," +
"${ContactDatabase.FeedEntry.PHONE_COLUMN} TEXT," +
"${ContactDatabase.FeedEntry.RELATIVE_COLUMN} TINYINT," +
"${ContactDatabase.FeedEntry.COMPANIONS_COLUMN} TEXT," +
Expand All @@ -52,5 +56,24 @@ class ContactDatabase {
const val SQL_DELETE_ENTRIES = "DROP TABLE IF EXISTS ${ContactDatabase.FeedEntry.TABLE_NAME}"
const val SQL_UPDATE_2 = "ALTER TABLE ${ContactDatabase.FeedEntry.TABLE_NAME} ADD COLUMN " +
"${ContactDatabase.FeedEntry.NOTES_COLUMN} TEXT"
const val SQL_UPDATE_3 = "ALTER TABLE ${ContactDatabase.FeedEntry.TABLE_NAME} ADD COLUMN " +
"${ContactDatabase.FeedEntry.DURATION_COLUMN} INT"
const val SQL_UPDATE_4_PART1 = "ALTER TABLE ${ContactDatabase.FeedEntry.TABLE_NAME} RENAME " +
"TO tmp_table"
const val SQL_UPDATE_4_PART2 = "INSERT INTO ${ContactDatabase.FeedEntry.TABLE_NAME}(" +
"${BaseColumns._ID}, ${ContactDatabase.FeedEntry.TYPE_COLUMN}, " +
"${ContactDatabase.FeedEntry.NAME_COLUMN}, ${ContactDatabase.FeedEntry.PLACE_COLUMN}, " +
"${ContactDatabase.FeedEntry.TIME_BEGIN_COLUMN}, ${ContactDatabase.FeedEntry.PHONE_COLUMN}, " +
"${ContactDatabase.FeedEntry.RELATIVE_COLUMN}, ${ContactDatabase.FeedEntry.COMPANIONS_COLUMN}, " +
"${ContactDatabase.FeedEntry.ENCOUNTER_COLUMN}, ${ContactDatabase.FeedEntry.CLOSECONTACT_COLUMN}, " +
"${ContactDatabase.FeedEntry.NOTES_COLUMN}) " +
"SELECT ${BaseColumns._ID}, ${ContactDatabase.FeedEntry.TYPE_COLUMN}, " +
"${ContactDatabase.FeedEntry.NAME_COLUMN}, ${ContactDatabase.FeedEntry.PLACE_COLUMN}, " +
"${ContactDatabase.FeedEntry.TIMESTAMP_COLUMN}, ${ContactDatabase.FeedEntry.PHONE_COLUMN}, " +
"${ContactDatabase.FeedEntry.RELATIVE_COLUMN}, ${ContactDatabase.FeedEntry.COMPANIONS_COLUMN}, " +
"${ContactDatabase.FeedEntry.ENCOUNTER_COLUMN}, ${ContactDatabase.FeedEntry.CLOSECONTACT_COLUMN}, " +
"${ContactDatabase.FeedEntry.NOTES_COLUMN} " +
"FROM tmp_table"
const val SQL_UPDATE_4_PART3 = "DROP TABLE tmp_table"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,19 @@ package com.apozas.contactdiary
*/

import android.content.Context
import android.content.res.Configuration
import android.database.Cursor
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import androidx.appcompat.app.AppCompatDelegate
import androidx.cursoradapter.widget.CursorAdapter
import java.text.DateFormat
import java.util.*

class DataCursorAdapter(context: Context?, c: Cursor?) : CursorAdapter(context, c, 0) {
private var mDateColumnIndex = cursor.getColumnIndex(ContactDatabase.ContactDatabase.FeedEntry.DATETIME_COLUMN)
private var mDateColumnIndex = cursor.getColumnIndex(ContactDatabase.ContactDatabase.FeedEntry.TIME_BEGIN_COLUMN)
private val formatter: DateFormat = DateFormat.getDateInstance(DateFormat.MEDIUM)
private val inflater = context?.getSystemService(Context.LAYOUT_INFLATER_SERVICE) as LayoutInflater

Expand All @@ -38,7 +40,8 @@ class DataCursorAdapter(context: Context?, c: Cursor?) : CursorAdapter(context,
var contact = ""
if (cursor != null) {
contact = cursor.getString(
cursor.getColumnIndex(ContactDatabase.ContactDatabase.FeedEntry.NAME_COLUMN))
cursor.getColumnIndex(ContactDatabase.ContactDatabase.FeedEntry.NAME_COLUMN)
)
}

val listItem = view?.findViewById(R.id.list_item) as TextView
Expand All @@ -52,11 +55,13 @@ class DataCursorAdapter(context: Context?, c: Cursor?) : CursorAdapter(context,
R.layout.list_layout, parent, false
)
}

// Set the data for the row
cursor.moveToPosition(position)
val listItemHeader = convertView?.findViewById(R.id.list_item_header) as TextView
val listItem = convertView?.findViewById(R.id.list_item) as TextView
val listDivider = convertView?.findViewById(R.id.list_divider) as View
val headerDivider = convertView?.findViewById(R.id.header_divider) as View
listItem.text = cursor.getString(cursor.getColumnIndex(ContactDatabase.ContactDatabase.FeedEntry.NAME_COLUMN))

if (position - 1 >= 0) {
Expand All @@ -67,19 +72,52 @@ class DataCursorAdapter(context: Context?, c: Cursor?) : CursorAdapter(context,
if (currentDate.equals(previousDate, ignoreCase = true)) {
// The dates are the same so abort everything as we already set the header before
listItemHeader.visibility = View.GONE
listDivider.visibility = View.VISIBLE
if (isNightModeActive(convertView)) {
listDivider.visibility = View.GONE
listDivider.layoutParams.height = 3
} else { listDivider.visibility = View.VISIBLE }
} else {
// This is the first occurrence of this date so show the header
listItemHeader.visibility = View.VISIBLE
listItemHeader.text = currentDate
listDivider.visibility = View.GONE
if (isNightModeActive(convertView)) {
listDivider.visibility = View.VISIBLE
headerDivider.visibility = View.VISIBLE
listDivider.layoutParams.height = 3
headerDivider.layoutParams.height = 3
} else { listDivider.visibility = View.GONE }
}
} else {
// This is position 0 and we need a header here
listItemHeader.visibility = View.VISIBLE
listItemHeader.text = formatter.format(Date(cursor.getLong(mDateColumnIndex)))
listDivider.visibility = View.GONE
if (isNightModeActive(convertView)) {
listDivider.visibility = View.VISIBLE
listDivider.layoutParams.height = 3
headerDivider.visibility = View.VISIBLE
} else {
listDivider.visibility = View.GONE
headerDivider.visibility = View.GONE
}
}
return convertView
}

private fun isNightModeActive(context: View?): Boolean {
val defaultNightMode = AppCompatDelegate.getDefaultNightMode()
if (defaultNightMode == AppCompatDelegate.MODE_NIGHT_YES) {
return true
}
if (defaultNightMode == AppCompatDelegate.MODE_NIGHT_NO) {
return false
}
val currentNightMode = (context!!.resources.configuration.uiMode
and Configuration.UI_MODE_NIGHT_MASK)
when (currentNightMode) {
Configuration.UI_MODE_NIGHT_NO -> return false
Configuration.UI_MODE_NIGHT_YES -> return true
Configuration.UI_MODE_NIGHT_UNDEFINED -> return false
}
return false
}
}
Loading

0 comments on commit 8c26e17

Please sign in to comment.