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

Convert to KOTLIN #24

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
9 changes: 8 additions & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'

android {
compileSdkVersion rootProject.ext.compileSdkVersion as Integer
Expand All @@ -24,8 +25,10 @@ android {

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation "androidx.core:core-ktx:1.3.1"
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"

testImplementation 'junit:junit:4.12'
testImplementation 'junit:junit:4.13.1'
implementation project(':audiowidget')

// Support
Expand All @@ -35,3 +38,7 @@ dependencies {
// Glide
implementation rootProject.ext.glideDependencies.glide
}

repositories {
mavenCentral()
}
Original file line number Diff line number Diff line change
@@ -1,113 +1,96 @@
package com.cleveroad.audiowidget.example;
package com.cleveroad.audiowidget.example

import android.content.Context;

import androidx.loader.content.AsyncTaskLoader;
import android.content.Context
import androidx.loader.content.AsyncTaskLoader

/**
* Base AsyncTaskLoader implementation
*/
abstract class BaseAsyncTaskLoader<T> extends AsyncTaskLoader<T> {
protected T mData;

public BaseAsyncTaskLoader(Context context) {
super(context);
}
internal abstract class BaseAsyncTaskLoader<T>(context: Context) : AsyncTaskLoader<T>(context) {
private var mData: T? = null

/**
* Called when there is new data to deliver to the client. The
* super class will take care of delivering it; the implementation
* here just adds a little more logic.
*/
@Override
public void deliverResult(T data) {
if (isReset()) {
override fun deliverResult(data: T?) {
if (isReset) {
// An async query came in while the loader is stopped. We
// don't need the result.
if (data != null) {
onReleaseResources(data);
}
data?.let { onReleaseResources(it) }
}
T oldData = mData;
mData = data;

if (isStarted()) {
val oldData = mData
mData = data
if (isStarted) {
// If the Loader is currently started, we can immediately
// deliver its results.
super.deliverResult(data);
super.deliverResult(data)
}

// At this point we can release the resources associated with
// 'oldData' if needed; now that the new result is delivered we
// know that it is no longer in use.
if (oldData != null) {
onReleaseResources(oldData);
}
oldData?.let { onReleaseResources(it) }
}

/**
* Handles a request to start the Loader.
*/
@Override
protected void onStartLoading() {
override fun onStartLoading() {
if (mData != null) {
// If we currently have a result available, deliver it
// immediately.
deliverResult(mData);
deliverResult(mData)
}

if (takeContentChanged() || mData == null) {
// If the data has changed since the last time it was loaded
// or is not currently available, start a load.
forceLoad();
forceLoad()
}
}

/**
* Handles a request to stop the Loader.
*/
@Override
protected void onStopLoading() {
override fun onStopLoading() {
// Attempt to cancel the current load task if possible.
cancelLoad();
cancelLoad()
}

/**
* Handles a request to cancel a load.
*/
@Override
public void onCanceled(T data) {
super.onCanceled(data);

override fun onCanceled(data: T?) {
super.onCanceled(data)
// At this point we can release the resources associated with 'apps'
// if needed.
onReleaseResources(data);
onReleaseResources(data)
}

/**
* Handles a request to completely reset the Loader.
*/
@Override
protected void onReset() {
super.onReset();
override fun onReset() {
super.onReset()

// Ensure the loader is stopped
onStopLoading();
onStopLoading()

// At this point we can release the resources associated with 'apps'
// if needed.
if (mData != null) {
onReleaseResources(mData);
mData = null;
onReleaseResources(mData)
mData = null
}
}

/**
* Helper function to take care of releasing resources associated
* with an actively loaded data set.
*/
protected void onReleaseResources(T apps) {
private fun onReleaseResources(apps: T?) {
// For a simple List<> there is nothing to do. For something
// like a Cursor, we would close it here.
}
}
}
155 changes: 0 additions & 155 deletions app/src/main/java/com/cleveroad/audiowidget/example/BaseFilter.java

This file was deleted.

Loading