Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wyvern 4.0.2 #58

Merged
merged 22 commits into from
Oct 11, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,5 @@
/captures
/app/release
/projectFilesBackup
gradlew
gradlew.bat
.externalNativeBuild
/gradle.properties
30 changes: 15 additions & 15 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,34 +1,34 @@
language: android
sudo: required
jdk: oraclejdk8
android:
components:
android:
components:
- tools
- platform-tools
- build-tools-27.0.3
- android-28
- android-22
- Extra-android-support
- extra-google-google_play_services
- extra-android-m2repository
- extra-google-m2repository
- build-tools-28.0.2 # Same version as specified in build.gradle
- android-28 # SDK version
- android-22 # For Emulator
- extra-android-m2repository
- extra-google-m2repository
- Extra-android-support
- extra-google-google_play_services
- addon-google_apis-google-27
- sys-img-armeabi-v7a-android-22
- sys-img-armeabi-v7a-android-22 # Android Image

licenses:
- android-sdk-preview-license-.+
- android-sdk-license-.+
- google-gdk-license-.+

before_install:
- chmod +x gradlew

before_script:
- wget http://services.gradle.org/distributions/gradle-4.4-bin.zip
- unzip gradle-4.4-bin.zip
- export GRADLE_HOME=$PWD/gradle-4.4
- export PATH=$GRADLE_HOME/bin:$PATH
- echo no | android create avd --force -n test -t android-22 --abi armeabi-v7a
- emulator -avd test -no-audio -no-window &
- android-wait-for-emulator
- adb shell input keyevent 82 &

after_success:
- chmod +x ./upload-apk.sh
- ./upload-apk.sh
11 changes: 8 additions & 3 deletions VersionHistory.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,25 @@

Version 4.0 (Wyvern)
----------------------
**MessageCounter 4.0.2 [Oct 2018]**
- Fix for JobService scheduling issues #55
- Consume In-App Purchases #57
- Use new In-App products

**MessageCounter 4.0.1 [Sep 2018]**
- Prevent multiple indexing at same time
- Set LaunchMode for MainActivity
- Handle IllegalStateException when setting Fragment

**MessageCounter 4.0.0 [Sep 2018]**
- Application rewrite and new architecture
- Application rewrite and new architecture #43
- Improve performance
- Use Material Theme

Version 3.3 (Valkyrie)
----------------------
**MessageCounter 3.3.0 [Oct 2017]**
- Bottom Navigation View
- Bottom Navigation View #25
- Ignore List

Version 3.2 (Unicorn)
Expand All @@ -26,7 +31,7 @@ Version 3.2 (Unicorn)
- Experimental Feature to count messages sent when service is not running

**MessageCounter 3.2.1 [Aug 2017]**
- Support for German
- Support for German #15
- Multi Length message support

Version 3.0 (Talisman)
Expand Down
6 changes: 3 additions & 3 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ android {
minSdkVersion 16
// Remember to update .travis.yml with android version
targetSdkVersion 28
versionCode 403
versionName "4.0.1"
versionCode 404
versionName "4.0.2"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
javaCompileOptions {
annotationProcessorOptions {
Expand Down Expand Up @@ -59,7 +59,7 @@ dependencies {
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
implementation "com.ae.apps:android-libraries:$ae_apps_lib_version"
implementation 'org.jetbrains.anko:anko-commons:0.10.4'
implementation 'com.google.android.gms:play-services-oss-licenses:16.0.0'
implementation 'com.google.android.gms:play-services-oss-licenses:16.0.1'
implementation 'com.android.billingclient:billing:1.1'
implementation "android.arch.persistence.room:runtime:$room_version"
kapt "android.arch.persistence.room:compiler:$room_version"
Expand Down
Binary file added app/src/debug/ic_launcher-web.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions app/src/debug/res/mipmap-anydpi-v26/ic_launcher.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
<background android:drawable="@color/ic_launcher_background"/>
<foreground android:drawable="@mipmap/ic_launcher_foreground"/>
</adaptive-icon>
5 changes: 5 additions & 0 deletions app/src/debug/res/mipmap-anydpi-v26/ic_launcher_round.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
<background android:drawable="@color/ic_launcher_background"/>
<foreground android:drawable="@mipmap/ic_launcher_foreground"/>
</adaptive-icon>
Binary file added app/src/debug/res/mipmap-hdpi/ic_launcher.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/debug/res/mipmap-mdpi/ic_launcher.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/debug/res/mipmap-xhdpi/ic_launcher.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/debug/res/mipmap-xxhdpi/ic_launcher.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/debug/res/mipmap-xxxhdpi/ic_launcher.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions app/src/debug/res/values/ic_launcher_background.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="ic_launcher_background">#FF9800</color>
</resources>
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ import com.ae.apps.messagecounter.data.repositories.IgnoredNumbersRepository
import com.ae.apps.messagecounter.data.repositories.getDurationDateString
import com.ae.apps.messagecounter.data.repositories.getIndexFromDate
import org.jetbrains.anko.doAsync
import java.lang.Long
import java.util.*

/**
Expand Down Expand Up @@ -63,7 +62,7 @@ class MessageCounter(private val counterRepository: CounterRepository,
*/
fun indexMessages(context: Context, observer: MessageCounterObserver?) {
// Prevent multiple indexing process to run at the same time
if(!preferenceRepository.isIndexInProcess()){
if (!preferenceRepository.isIndexInProcess()) {
doMessageIndex(context, observer)
} else {
Log.d(TAG, "Message Indexing in Process")
Expand All @@ -89,7 +88,7 @@ class MessageCounter(private val counterRepository: CounterRepository,
// Convert this row into a Message object and handle multipart messages
val message = getMessageFromCursor(newMessagesCursor!!)

messageSentDate.timeInMillis = Long.parseLong(message.date)
messageSentDate.timeInMillis = message.date.toLong()
lastIndexedTimeStamp = message.date
lastIndexedMessageId = message.id

Expand Down Expand Up @@ -142,7 +141,7 @@ class MessageCounter(private val counterRepository: CounterRepository,
SORT_BY_DATE)
}

private fun getDeltaTimeStamp() = (System.currentTimeMillis() + TIME_DELTA ).toString()
private fun getDeltaTimeStamp() = (System.currentTimeMillis() + TIME_DELTA).toString()

fun checkIfMessageLimitCrossed(): Boolean {
if (preferenceRepository.messageLimitNotificationEnabled()) {
Expand All @@ -162,7 +161,7 @@ class MessageCounter(private val counterRepository: CounterRepository,
* Make sure to call this from another thread since db access on main thread
* will not work
*/
fun getSentCountDetailsForWidget():SentCountDetails {
fun getSentCountDetailsForWidget(): SentCountDetails {
val limit: Int = preferenceRepository.getMessageLimitValue()
val cycleStartDate = preferenceRepository.getCycleStartDate()
val today = Calendar.getInstance().time
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ val SMS_TABLE_MINIMAL_PROJECTION = arrayOf(COLUMN_NAME_ID,
COLUMN_NAME_PERSON)

val SELECT_SENT_MESSAGES_AFTER_DATE = "person is null and protocol is null and $COLUMN_NAME_DATE > ? "
val SELECT_SENT_MESSAGES_AFTER_LAST = "and _id > ?"
const val SELECT_SENT_MESSAGES_AFTER_LAST = "and _id > ?"
val SORT_BY_DATE = "$COLUMN_NAME_DATE ASC"

const val DEFAULT_MESSAGE_COUNT = 1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ abstract class DonationsBaseFragment : Fragment(), PurchasesUpdatedListener {

protected abstract fun getSkus(): List<String>

protected abstract fun handlePurchaseError(purchases: List<Purchase>?)
protected abstract fun handlePurchaseError(purchases: List<Purchase>?, responseCode: Int)

protected abstract fun handleUserCancelled(purchases: List<Purchase>?)

Expand All @@ -50,7 +50,7 @@ abstract class DonationsBaseFragment : Fragment(), PurchasesUpdatedListener {
protected abstract fun skuDetailsResponse(skuDetails: List<SkuDetails>)

/**
* A successful purchase
* Method invoked on a successful purchase
*
* @param purchase purchase details
*/
Expand Down Expand Up @@ -114,6 +114,16 @@ abstract class DonationsBaseFragment : Fragment(), PurchasesUpdatedListener {
}
}

/**
* Consume the Purchase so that it could be bought again
*
* @param purchaseToken the purchase token
* @param listener a callback when the purchase is consumed
*/
fun consumeAsync(purchaseToken:String, listener:ConsumeResponseListener){
mBillingClient!!.consumeAsync(purchaseToken, listener)
}

override fun onPurchasesUpdated(responseCode: Int, purchases: List<Purchase>?) {
if (responseCode == BillingClient.BillingResponse.OK && null != purchases) {
for (purchase in purchases) {
Expand All @@ -124,7 +134,7 @@ abstract class DonationsBaseFragment : Fragment(), PurchasesUpdatedListener {
handleUserCancelled(purchases)
} else {
// Handle an error flow
handlePurchaseError(purchases)
handlePurchaseError(purchases, responseCode)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,17 @@ import android.view.ViewGroup
import android.widget.Toast
import com.ae.apps.messagecounter.R
import com.ae.apps.messagecounter.data.preferences.PreferenceRepository
import com.android.billingclient.api.ConsumeResponseListener
import com.android.billingclient.api.Purchase
import com.android.billingclient.api.SkuDetails
import kotlinx.android.synthetic.main.fragment_donations.*

class DonationsFragment : DonationsBaseFragment() {
class DonationsFragment : DonationsBaseFragment(), ConsumeResponseListener {

companion object {
const val SKU_SMALL = "product_small"
const val SKU_MEDIUM = "product_medium"
const val SKU_LARGE = "product_large"
const val SKU_SMALL = "product_small2"
const val SKU_MEDIUM = "product_medium2"
const val SKU_LARGE = "product_large2"

fun newInstance() = DonationsFragment()
}
Expand All @@ -55,10 +56,6 @@ class DonationsFragment : DonationsBaseFragment() {
}

override fun skuDetailsResponse(skuDetails: List<SkuDetails>) {
/*Toast.makeText(requireContext(),
"skuDetailsResponse size:" + skuDetails.size,
Toast.LENGTH_SHORT)
.show()*/
skuDetails.forEach {
when {
it.sku == SKU_SMALL -> txtDonateSmallPrice.text = it.price
Expand All @@ -69,18 +66,27 @@ class DonationsFragment : DonationsBaseFragment() {
}

override fun handlePurchase(purchase: Purchase) {
// Consume the Purchase so that it can be bought again
consumeAsync(purchase.purchaseToken, this)

Toast.makeText(requireContext(),
"Thank You for your donation with order id" + purchase.orderId,
Toast.LENGTH_SHORT)
.show()
"Thank You for your donation, order id " + purchase.orderId,
Toast.LENGTH_SHORT).show()
val preferenceRepository = PreferenceRepository.newInstance(
PreferenceManager.getDefaultSharedPreferences(requireContext()))
preferenceRepository.saveDonationsMade()
}

override fun handlePurchaseError(purchases: List<Purchase>?) {
override fun onConsumeResponse(responseCode: Int, purchaseToken: String?) {
/*Toast.makeText(requireContext(),
"Purchase Confirmed",
Toast.LENGTH_SHORT).show()
*/
}

override fun handlePurchaseError(purchases: List<Purchase>?, responseCode: Int) {
Toast.makeText(requireContext(),
"purchase error occurred",
"Purchase error occurred. Code $responseCode",
Toast.LENGTH_SHORT)
.show()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import android.support.annotation.RequiresApi
import com.ae.apps.common.managers.SMSManager
import com.ae.apps.messagecounter.observers.SMSObserver
import org.jetbrains.anko.doAsync
//import org.jetbrains.anko.longToast
import org.jetbrains.anko.runOnUiThread

@RequiresApi(Build.VERSION_CODES.N)
class CounterJobService : JobService() {
Expand All @@ -38,47 +38,68 @@ class CounterJobService : JobService() {
private const val THREAD_NAME = "AnotherThread"
private const val JOB_ID = 180803
private const val DELAY_MIN: Long = 500
private const val DELAY_MAX: Long = 1000 * 5
private const val DELAY_MAX: Long = 1000 * 4

fun registerJob(context: Context): Boolean {
fun registerJob(context: Context, cancelAndReschedule: Boolean = false): Boolean {
val component = ComponentName(context, CounterJobService::class.java)
val contentUri = JobInfo.TriggerContentUri(Uri.parse(SMSManager.SMS_URI_ALL),
JobInfo.TriggerContentUri.FLAG_NOTIFY_FOR_DESCENDANTS)
val jobInfo = JobInfo.Builder(JOB_ID, component)
.addTriggerContentUri(contentUri)
.setTriggerContentUpdateDelay(DELAY_MIN)
.setTriggerContentMaxDelay(DELAY_MAX)
.setMinimumLatency(DELAY_MIN)
.setBackoffCriteria(DELAY_MAX, JobInfo.BACKOFF_POLICY_LINEAR)
.build()

// Schedule a Job if not already done so
val scheduler: JobScheduler = context.getSystemService(Context.JOB_SCHEDULER_SERVICE) as JobScheduler
if (CounterServiceHelper.isJobNotRunning(scheduler, JOB_ID)) {
val result = scheduler.schedule(jobInfo)
return (result == JobScheduler.RESULT_SUCCESS)
}
val isJobRunning = CounterServiceHelper.isJobRunning(scheduler, JOB_ID)

return false
if (isJobRunning) {
if (cancelAndReschedule) {
scheduler.cancel(JOB_ID)
} else {
return true
}
}
val result = scheduler.schedule(jobInfo)
// val pendingJobsCount = scheduler.allPendingJobs.size
// Toast.makeText(context, "Job scheduled ${result == 1}, total jobs $pendingJobsCount", Toast.LENGTH_SHORT).show()
return (result == JobScheduler.RESULT_SUCCESS)
}
}

// @TargetApi(Build.VERSION_CODES.O)
override fun onStartJob(params: JobParameters?): Boolean {
val context = baseContext
val handlerThread = HandlerThread(THREAD_NAME)
handlerThread.start()
val handler = Handler(handlerThread.looper)
//longToast("onStartJob")

/* Debug toast with JobStart time
if (BuildConfig.DEBUG && Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
val timeNow = LocalDateTime.now().format(DateTimeFormatter.ofLocalizedDateTime(FormatStyle.MEDIUM))
longToast("onStartJob at $timeNow")
}*/

doAsync {
val observer = SMSObserver(handler, context)
observer.onChange(false)

jobFinished(params, true)
// Mark this job as completed
jobFinished(params, false)

// Reschedule another job to monitor SMS Content Provider
runOnUiThread {
registerJob(context, true)
}
}

return true
}

override fun onStopJob(params: JobParameters?): Boolean {
// longToast("onStopJob")
return true
}

Expand Down
4 changes: 2 additions & 2 deletions app/src/main/res/values-de/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@
-->
<resources>
<string name="app_name">Nachrichtenzähler</string>
<string name="app_version">Version 4.0.1</string>
<string name="app_version">Version 4.0.2</string>
<string name="app_code_name">Wyvern</string>
<string name="app_release_date">Sep 2018</string>
<string name="app_release_date">Oct 2018</string>
<string name="app_desc">Message Counter zeigt Nachrichten Posteingangsstatistiken und Anzahl der Nachrichten von jedem Ihrer Kontakte an.</string>
<string name="app_disclaim">Haftungsausschluss: Diese App wird für pädagogische Zwecke erstellt und hat daher keine Garantie oder Unterstützung. Da undokumentierte Android-APIs verwendet werden, funktioniert diese App möglicherweise nicht wie erwartet auf allen Geräten.</string>
<string name="app_developer_info">Entworfen und entwickelt bei ae Labs</string>
Expand Down
Loading