diff --git a/.gitignore b/.gitignore index c6cbe56..5f94008 100644 --- a/.gitignore +++ b/.gitignore @@ -1,8 +1,7 @@ *.iml .gradle /local.properties -/.idea/workspace.xml -/.idea/libraries +/.idea .DS_Store /build /captures diff --git a/.idea/compiler.xml b/.idea/compiler.xml deleted file mode 100644 index 96cc43e..0000000 --- a/.idea/compiler.xml +++ /dev/null @@ -1,22 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/copyright/profiles_settings.xml b/.idea/copyright/profiles_settings.xml deleted file mode 100644 index e7bedf3..0000000 --- a/.idea/copyright/profiles_settings.xml +++ /dev/null @@ -1,3 +0,0 @@ - - - \ No newline at end of file diff --git a/.idea/encodings.xml b/.idea/encodings.xml deleted file mode 100644 index 97626ba..0000000 --- a/.idea/encodings.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/.idea/gradle.xml b/.idea/gradle.xml index fe72da5..7ac24c7 100644 --- a/.idea/gradle.xml +++ b/.idea/gradle.xml @@ -3,9 +3,8 @@ - - - - - - - + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml index f05212f..90879b2 100644 --- a/.idea/modules.xml +++ b/.idea/modules.xml @@ -3,7 +3,7 @@ - + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml index 35eb1dd..8306744 100644 --- a/.idea/vcs.xml +++ b/.idea/vcs.xml @@ -2,5 +2,6 @@ + \ No newline at end of file diff --git a/app/build.gradle b/app/build.gradle index ff4e406..392272d 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -2,14 +2,14 @@ apply plugin: 'com.android.application' apply plugin: 'kotlin-android' android { - compileSdkVersion 27 - buildToolsVersion '26.0.2' + compileSdkVersion 28 + buildToolsVersion '28.0.3' defaultConfig { applicationId "pakutoma.iijmiocouponwidget" minSdkVersion 21 - versionCode 3 - versionName "2.1" - targetSdkVersion 27 + versionCode 6 + versionName "2.2" + targetSdkVersion 28 } buildTypes { release { @@ -32,25 +32,15 @@ android { } dependencies { - compile fileTree(include: ['*.jar'], dir: 'libs') - testCompile 'junit:junit:4.12' - compile 'com.android.support:appcompat-v7:27.1.0' - compile 'com.github.kittinunf.fuel:fuel:1.12.1' - compile 'com.github.kittinunf.fuel:fuel-moshi:1.12.1' - compile 'com.squareup.moshi:moshi:1.5.0' - compile 'com.squareup.moshi:moshi-kotlin:1.5.0' - compile "org.jetbrains.anko:anko-sqlite:0.10.4" - compile "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" - compile "org.jetbrains.kotlinx:kotlinx-coroutines-core:0.22.3" - compile "org.jetbrains.kotlinx:kotlinx-coroutines-android:0.22.3" -} - -repositories { - mavenCentral() -} - -kotlin { - experimental { - coroutines "enable" - } + implementation fileTree(include: ['*.jar'], dir: 'libs') + testImplementation 'junit:junit:4.12' + implementation 'com.android.support:appcompat-v7:28.0.0' + implementation 'com.github.kittinunf.fuel:fuel:2.0.1' + implementation 'com.github.kittinunf.fuel:fuel-moshi:2.0.1' + implementation 'com.squareup.moshi:moshi:1.8.0' + implementation 'com.squareup.moshi:moshi-kotlin:1.8.0' + implementation 'org.jetbrains.anko:anko-sqlite:0.10.8' + implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" + implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.1.1' + implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.1.1' } diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 06c51d9..8b3da2c 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -4,6 +4,8 @@ + + -

mioWidget 2.1

-

Copyright (c) 2018 @pakutoma

+

mioWidget 2.2

+

Copyright (c) 2019 @pakutoma

\ No newline at end of file diff --git a/app/src/main/java/pakutoma/iijmiocouponwidget/service/CouponFunctions.kt b/app/src/main/java/pakutoma/iijmiocouponwidget/service/CouponFunctions.kt index 11f3370..f4db411 100644 --- a/app/src/main/java/pakutoma/iijmiocouponwidget/service/CouponFunctions.kt +++ b/app/src/main/java/pakutoma/iijmiocouponwidget/service/CouponFunctions.kt @@ -1,12 +1,8 @@ package pakutoma.iijmiocouponwidget.service import android.content.Context -import android.database.sqlite.SQLiteException import android.widget.Toast -import com.github.kittinunf.fuel.core.HttpException -import kotlinx.coroutines.experimental.android.UI -import kotlinx.coroutines.experimental.launch -import kotlinx.coroutines.experimental.withContext +import kotlinx.coroutines.* import org.jetbrains.anko.db.* import org.jetbrains.anko.defaultSharedPreferences import pakutoma.iijmiocouponwidget.R @@ -47,7 +43,7 @@ private suspend fun accessCoupon(context: Context, change: Boolean) { } catch (e: NotFoundValidTokenException) { editor.putString("X-IIJmio-Authorization", "") showResult(context, change, false) - } catch (e: HttpException) { + } catch (e: Exception) { showResult(context, change, true, false) } if (change) { @@ -56,7 +52,7 @@ private suspend fun accessCoupon(context: Context, change: Boolean) { editor.apply() } -private suspend fun showResult(context: Context, change: Boolean, hasToken: Boolean, couldGet: Boolean = false, remains: Int = -1, isCouponEnabled: Boolean = false) = withContext(UI) { +private suspend fun showResult(context: Context, change: Boolean, hasToken: Boolean, couldGet: Boolean = false, remains: Int = -1, isCouponEnabled: Boolean = false) = withContext(Dispatchers.Main) { if (change) { sendToast(context, hasToken, couldGet, isCouponEnabled) } @@ -65,7 +61,7 @@ private suspend fun showResult(context: Context, change: Boolean, hasToken: Bool private suspend fun fetchCouponInfo(context: Context, coupon: CouponAPI, change: Boolean): Triple> { val couponInfo = coupon.fetchCouponInfo() - launch { updateDb(context, couponInfo) } + val db = GlobalScope.async { updateDb(context, couponInfo) } val (enablePlans, enableLines) = getEnablePlansAndLines(context, couponInfo) val isCouponEnabledNow = if (enableLines.isEmpty()) { couponInfo.planInfoList[0].lineInfoList[0].couponUse @@ -85,6 +81,7 @@ private suspend fun fetchCouponInfo(context: Context, coupon: CouponAPI, change: couponInfo.planInfoList.flatMap { it.lineInfoList.filter { x -> enableLines.any { it == x.number } }.map { it.serviceCode } } } } + db.await() return Triple(isCouponEnabled, remains, serviceCodeList) } @@ -136,6 +133,7 @@ private fun sendToast(context: Context, hasToken: Boolean, couldChange: Boolean } if (!couldChange) { Toast.makeText(context, "切り替えに失敗しました。", Toast.LENGTH_SHORT).show() + return } Toast.makeText(context, "クーポンを" + (if (isCouponEnabled) "ON" else "OFF") + "に変更しました。", Toast.LENGTH_SHORT).show() } \ No newline at end of file diff --git a/app/src/main/java/pakutoma/iijmiocouponwidget/service/FetchRemainsJobService.kt b/app/src/main/java/pakutoma/iijmiocouponwidget/service/FetchRemainsJobService.kt index e5f238d..614057a 100644 --- a/app/src/main/java/pakutoma/iijmiocouponwidget/service/FetchRemainsJobService.kt +++ b/app/src/main/java/pakutoma/iijmiocouponwidget/service/FetchRemainsJobService.kt @@ -1,30 +1,14 @@ package pakutoma.iijmiocouponwidget.service import android.app.job.JobParameters -import android.content.Context -import kotlinx.coroutines.experimental.launch -import pakutoma.iijmiocouponwidget.R - -import java.io.IOException +import kotlinx.coroutines.launch import android.app.job.JobService -import com.github.kittinunf.fuel.core.HttpException -import kotlinx.coroutines.experimental.android.UI -import kotlinx.coroutines.experimental.withContext - -import pakutoma.iijmiocouponwidget.utility.CouponAPI -import pakutoma.iijmiocouponwidget.exception.NotFoundValidTokenException -import pakutoma.iijmiocouponwidget.utility.CouponInfo -import pakutoma.iijmiocouponwidget.widget.updateSwitchStatus - +import kotlinx.coroutines.GlobalScope -/** - * Created by PAKUTOMA on 2016/06/21. - * Get Traffic Function - */ class FetchRemainsJobService : JobService() { override fun onStartJob(params: JobParameters?): Boolean { - launch { + GlobalScope.launch { fetchRemains(applicationContext) jobFinished(params, true) } diff --git a/app/src/main/java/pakutoma/iijmiocouponwidget/service/FetchRemainsService.kt b/app/src/main/java/pakutoma/iijmiocouponwidget/service/FetchRemainsService.kt index 35d4c38..0eeeee0 100644 --- a/app/src/main/java/pakutoma/iijmiocouponwidget/service/FetchRemainsService.kt +++ b/app/src/main/java/pakutoma/iijmiocouponwidget/service/FetchRemainsService.kt @@ -3,21 +3,13 @@ package pakutoma.iijmiocouponwidget.service import android.annotation.TargetApi import android.app.Notification import android.app.Service -import android.content.Context import android.content.Intent import android.os.Build import android.os.IBinder -import com.github.kittinunf.fuel.core.HttpException -import kotlinx.coroutines.experimental.android.UI -import kotlinx.coroutines.experimental.launch -import kotlinx.coroutines.experimental.withContext +import kotlinx.coroutines.GlobalScope +import kotlinx.coroutines.launch import pakutoma.iijmiocouponwidget.R -import pakutoma.iijmiocouponwidget.exception.NotFoundValidTokenException -import pakutoma.iijmiocouponwidget.utility.CouponAPI -import pakutoma.iijmiocouponwidget.utility.CouponInfo import pakutoma.iijmiocouponwidget.widget.changeToFetchingMode -import pakutoma.iijmiocouponwidget.widget.updateSwitchStatus -import java.io.IOException /** * Created by PAKUTOMA on 2018/03/06. @@ -35,7 +27,9 @@ class FetchRemainsService : Service() { if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { val notification = Notification .Builder(applicationContext, "switch_service") - .setContentTitle(applicationContext.getString(R.string.switch_notification)) + .setSmallIcon(R.drawable.ic_notification) + .setContentTitle(applicationContext.getString(R.string.notification_title)) + .setContentText(applicationContext.getString(R.string.fetch_remains_notification_text)) .build() startForeground(FETCH_REMAINS_NOTIFICATION_ID, notification) } @@ -43,7 +37,7 @@ class FetchRemainsService : Service() { override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int { changeToFetchingMode(applicationContext) - launch { + GlobalScope.launch { fetchRemains(applicationContext) stopSelf() } diff --git a/app/src/main/java/pakutoma/iijmiocouponwidget/service/SwitchCouponService.kt b/app/src/main/java/pakutoma/iijmiocouponwidget/service/SwitchCouponService.kt index e16e7bc..03f468e 100644 --- a/app/src/main/java/pakutoma/iijmiocouponwidget/service/SwitchCouponService.kt +++ b/app/src/main/java/pakutoma/iijmiocouponwidget/service/SwitchCouponService.kt @@ -2,24 +2,24 @@ package pakutoma.iijmiocouponwidget.service import android.annotation.TargetApi import android.app.Notification +import android.app.NotificationManager import android.app.Service import android.content.Context import android.content.Intent +import android.content.SharedPreferences +import android.net.ConnectivityManager +import android.net.Network +import android.net.NetworkRequest import android.os.IBinder import android.widget.Toast -import kotlinx.coroutines.experimental.android.UI -import kotlinx.coroutines.experimental.launch -import kotlinx.coroutines.experimental.withContext - import pakutoma.iijmiocouponwidget.R import pakutoma.iijmiocouponwidget.activity.OpenBrowserActivity -import pakutoma.iijmiocouponwidget.exception.NotFoundValidTokenException -import pakutoma.iijmiocouponwidget.utility.CouponAPI import pakutoma.iijmiocouponwidget.widget.changeToWaitMode import pakutoma.iijmiocouponwidget.widget.setSwitchPendingIntent -import pakutoma.iijmiocouponwidget.widget.updateSwitchStatus import android.os.Build -import com.github.kittinunf.fuel.core.HttpException +import kotlinx.coroutines.* +import kotlin.coroutines.resume +import kotlin.coroutines.suspendCoroutine /** @@ -30,45 +30,70 @@ class SwitchCouponService : Service() { companion object { private const val SWITCH_COUPON_NOTIFICATION_ID = 1 + private var builder: Notification.Builder? = null } override fun onCreate() { super.onCreate() - @TargetApi(Build.VERSION_CODES.O) - if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { - val notification = Notification - .Builder(applicationContext, "switch_service") - .setContentTitle(applicationContext.getString(R.string.switch_notification)) - .build() - startForeground(SWITCH_COUPON_NOTIFICATION_ID, notification) - } + builder = notifyInitialNotification() } override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int { - val preferences = getSharedPreferences("iijmio_token", Context.MODE_PRIVATE) - val accessToken = preferences.getString("X-IIJmio-Authorization", "") + val preferences = getSharedPreferences("iijmio_token", Context.MODE_PRIVATE); + if (preferences == null) { + stopSelf() + return START_NOT_STICKY + } + + val timeFromFinish = System.currentTimeMillis() - preferences.getLong("last_click_time", 0); + val editor = preferences.edit() + if (timeFromFinish > 3000 * 60) { + // サービス異常終了時への対処 + editor.putBoolean("SwitchCouponServiceIsRunning", false) + editor.apply() + } + val running = preferences.getBoolean("SwitchCouponServiceIsRunning", false) + if (running) { + Toast.makeText(this, "クーポン切替中です", Toast.LENGTH_SHORT).show() + return START_NOT_STICKY + } + editor.putBoolean("SwitchCouponServiceIsRunning", true) + editor.apply() + + val accessToken = preferences.getString("X-IIJmio-Authorization", "") if (accessToken == "") { val authIntent = Intent(applicationContext, OpenBrowserActivity::class.java) authIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) startActivity(authIntent) setSwitchPendingIntent(applicationContext) - stopSelf() - return START_NOT_STICKY - } - - val lastClickTime = preferences.getLong("last_click_time", 0) - if (System.currentTimeMillis() - lastClickTime < 1000 * 60) { - Toast.makeText(this, "API limit: あと" + java.lang.Long.toString((1000 * 60 - (System.currentTimeMillis() - lastClickTime)) / 1000) + "秒お待ち下さい。", Toast.LENGTH_SHORT).show() - setSwitchPendingIntent(applicationContext) - stopSelf() + exit(editor) return START_NOT_STICKY } changeToWaitMode(applicationContext, preferences.getBoolean("is_coupon_enabled", false)) - launch { - switchCoupon(applicationContext) - stopSelf() + updateNotification(builder, applicationContext.getString(R.string.switch_coupon_notification_text)) + + val cm = applicationContext.getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager + val networkRequest = NetworkRequest.Builder().build() + GlobalScope.launch { + if (timeFromFinish < 1000 * 60) { + val remainingTime = 1000 * 60 - timeFromFinish + withContext(Dispatchers.Main) { + Toast.makeText(applicationContext, "API limit: " + java.lang.Long.toString(remainingTime / 1000) + "秒後に切替を行います", Toast.LENGTH_SHORT).show() + } + updateNotification(builder, applicationContext.getString(R.string.switch_coupon_notification_wait_text)) + delay(1000 * 60 - timeFromFinish) + } + val network = withTimeoutOrNull(1000 * 60) { + waitNetworkAvailable(cm, networkRequest) + } + if (network != null) { + switchCoupon(applicationContext) + } else { + Toast.makeText(applicationContext, "接続に失敗しました", Toast.LENGTH_SHORT).show() + } + exit(editor) } return Service.START_NOT_STICKY } @@ -77,4 +102,46 @@ class SwitchCouponService : Service() { return null } + private fun exit(editor: SharedPreferences.Editor) { + editor.putBoolean("SwitchCouponServiceIsRunning", false); + editor.apply() + stopSelf() + } + + private suspend fun waitNetworkAvailable(cm: ConnectivityManager, networkRequest: NetworkRequest): Network? = suspendCoroutine { cont -> + val callback = object : ConnectivityManager.NetworkCallback() { + override fun onAvailable(network: Network?) { + super.onAvailable(network) + cm.unregisterNetworkCallback(this); + cont.resume(network) + } + } + cm.registerNetworkCallback(networkRequest, callback) + } + + private fun notifyInitialNotification(): Notification.Builder? { + @TargetApi(Build.VERSION_CODES.O) + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { + val builder = Notification.Builder(applicationContext, "switch_service") + builder.setSmallIcon(R.drawable.ic_notification) + .setContentTitle(applicationContext.getString(R.string.notification_title)) + .setContentText(applicationContext.getString(R.string.notification_text)) + startForeground(SwitchCouponService.SWITCH_COUPON_NOTIFICATION_ID, builder.build()) + return builder + } else { + return null + } + } + + private fun updateNotification(builder: Notification.Builder?, text: String) { + @TargetApi(Build.VERSION_CODES.O) + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O && builder != null) { + val notificationManager = getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager + builder.setContentText(text) + notificationManager.notify(SWITCH_COUPON_NOTIFICATION_ID, builder.build()) + } + } + } + + diff --git a/app/src/main/java/pakutoma/iijmiocouponwidget/utility/CouponAPI.kt b/app/src/main/java/pakutoma/iijmiocouponwidget/utility/CouponAPI.kt index ff6dce5..6151b3b 100644 --- a/app/src/main/java/pakutoma/iijmiocouponwidget/utility/CouponAPI.kt +++ b/app/src/main/java/pakutoma/iijmiocouponwidget/utility/CouponAPI.kt @@ -1,17 +1,20 @@ package pakutoma.iijmiocouponwidget.utility import com.github.kittinunf.fuel.core.FuelManager +import com.github.kittinunf.fuel.core.extensions.jsonBody import com.github.kittinunf.fuel.httpGet import com.github.kittinunf.fuel.httpPut import com.github.kittinunf.fuel.moshi.responseObject import com.github.kittinunf.result.Result import com.github.kittinunf.result.getAs import com.squareup.moshi.Moshi -import kotlinx.coroutines.experimental.CommonPool -import kotlinx.coroutines.experimental.withContext +import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.withContext import pakutoma.iijmiocouponwidget.exception.NotFoundValidTokenException import pakutoma.iijmiocouponwidget.exception.UndefinedPlanException -import kotlin.coroutines.experimental.suspendCoroutine +import kotlin.coroutines.resume +import kotlin.coroutines.resumeWithException +import kotlin.coroutines.suspendCoroutine /** * iijmio coupon switch api wrapper @@ -29,17 +32,16 @@ class CouponAPI constructor(developerID: String, accessToken: String) { } suspend fun fetchCouponInfo(): CouponInfo { - val fetchedData = withContext(CommonPool) { sendHttpGetCouponInfo() } + val fetchedData = withContext(Dispatchers.Default) { sendHttpGetCouponInfo() } return convert(fetchedData) } private suspend fun sendHttpGetCouponInfo(): CouponDataFromJson = suspendCoroutine { cont -> "/coupon/".httpGet() - .responseObject { _, _, result -> + .responseObject { _, response, result -> when (result) { is Result.Failure -> { - val (data, _) = result - if (data?.returnCode?.contains("User Authorization Failure") == true) { + if (response.statusCode == 403) { cont.resumeWithException(NotFoundValidTokenException("User Authorization Failure")) } cont.resumeWithException(result.getAs()!!) @@ -56,16 +58,18 @@ class CouponAPI constructor(developerID: String, accessToken: String) { val moshi = Moshi.Builder().build() val adapter = moshi.adapter(CouponDataToJson::class.java) val json = adapter.toJson(couponDataToJson) - return withContext(CommonPool) { sendHttpPutCouponStatus(json) } + return withContext(Dispatchers.Default) { sendHttpPutCouponStatus(json) } } private suspend fun sendHttpPutCouponStatus(json: String): ReturnCodeFromJson = suspendCoroutine { cont -> "/coupon/".httpPut() - .header("Content-Type" to "application/json") - .body(json) - .responseObject { _, _, result -> + .jsonBody(json) + .responseObject { _, response, result -> when (result) { is Result.Failure -> { + if (response.statusCode == 403) { + cont.resumeWithException(NotFoundValidTokenException("User Authorization Failure")) + } cont.resumeWithException(result.getAs()!!) } is Result.Success -> { diff --git a/app/src/main/java/pakutoma/iijmiocouponwidget/widget/SwitchWidget.kt b/app/src/main/java/pakutoma/iijmiocouponwidget/widget/SwitchWidget.kt index c614bec..e62c868 100644 --- a/app/src/main/java/pakutoma/iijmiocouponwidget/widget/SwitchWidget.kt +++ b/app/src/main/java/pakutoma/iijmiocouponwidget/widget/SwitchWidget.kt @@ -31,7 +31,6 @@ import java.util.concurrent.TimeUnit class SwitchWidget : AppWidgetProvider() { companion object { - private const val JOB_ID = 1 private const val NOTIFICATION_CHANNEL_ID = "switch_service" } @@ -60,7 +59,7 @@ class SwitchWidget : AppWidgetProvider() { override fun onDisabled(context: Context) { val jobScheduler = context.getSystemService(Context.JOB_SCHEDULER_SERVICE) as JobScheduler - jobScheduler.cancel(JOB_ID) + jobScheduler.cancel(context.resources.getInteger(R.integer.periodic_fetch_remains)) super.onDisabled(context) } @@ -82,8 +81,9 @@ class SwitchWidget : AppWidgetProvider() { private fun registerFetchRemainsJobService(context: Context) { val jobScheduler = context.getSystemService(Context.JOB_SCHEDULER_SERVICE) as JobScheduler val jobs = jobScheduler.allPendingJobs - if(jobs?.any { it.id == JOB_ID } != true) { - val jobInfo = JobInfo.Builder(JOB_ID, ComponentName(context, FetchRemainsJobService::class.java)) + val jobId = context.resources.getInteger(R.integer.periodic_fetch_remains) + if(jobs?.any { it.id == jobId } != true) { + val jobInfo = JobInfo.Builder(jobId, ComponentName(context, FetchRemainsJobService::class.java)) .setRequiredNetworkType(JobInfo.NETWORK_TYPE_ANY) .setPeriodic(TimeUnit.MINUTES.toMillis(15)) .setPersisted(true) @@ -138,11 +138,10 @@ fun updateSwitchStatus(context: Context, hasToken: Boolean, couldGet: Boolean, r remoteViews.setTextViewText(R.id.data_traffic, convertPrefixString(remains)) } val clickIntent = Intent(context, SwitchCouponService::class.java) - val pendingIntent: PendingIntent - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { - pendingIntent = PendingIntent.getForegroundService(context, 0, clickIntent, FLAG_CANCEL_CURRENT) + val pendingIntent = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { + PendingIntent.getForegroundService(context, 0, clickIntent, FLAG_CANCEL_CURRENT) } else { - pendingIntent = PendingIntent.getService(context, 0, clickIntent, FLAG_CANCEL_CURRENT) + PendingIntent.getService(context, 0, clickIntent, FLAG_CANCEL_CURRENT) } remoteViews.setOnClickPendingIntent(R.id.transparent_button, pendingIntent) val thisWidget = ComponentName(context, SwitchWidget::class.java) @@ -161,11 +160,10 @@ private fun convertPrefixString(traffic: Int): String { fun setSwitchPendingIntent(context: Context) { val remoteViews = RemoteViews(context.packageName, R.layout.switch_widget) val clickIntent = Intent(context, SwitchCouponService::class.java) - val pendingIntent: PendingIntent - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { - pendingIntent = PendingIntent.getForegroundService(context, 0, clickIntent, FLAG_CANCEL_CURRENT) + val pendingIntent = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { + PendingIntent.getForegroundService(context, 0, clickIntent, FLAG_CANCEL_CURRENT) } else { - pendingIntent = PendingIntent.getService(context, 0, clickIntent, FLAG_CANCEL_CURRENT) + PendingIntent.getService(context, 0, clickIntent, FLAG_CANCEL_CURRENT) } remoteViews.setOnClickPendingIntent(R.id.transparent_button, pendingIntent) val thisWidget = ComponentName(context, SwitchWidget::class.java) diff --git a/app/src/main/res/drawable/ic_notification.xml b/app/src/main/res/drawable/ic_notification.xml new file mode 100644 index 0000000..ea54187 --- /dev/null +++ b/app/src/main/res/drawable/ic_notification.xml @@ -0,0 +1,4 @@ + + + diff --git a/app/src/main/res/values/jobs.xml b/app/src/main/res/values/jobs.xml new file mode 100644 index 0000000..8d7f006 --- /dev/null +++ b/app/src/main/res/values/jobs.xml @@ -0,0 +1,4 @@ + + + 1 + \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index bf2c98b..0071229 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -4,9 +4,17 @@ IilCI1xrAgqKrXV9Zt4 クーポン切り替え・通信量取得 - 通信中 - 残量表示・スイッチの設定 + mioWidget + 通信しています + クーポン残量を取得しています + クーポンを切り替えています + クーポン切り替えを待機しています + 切替回線・表示プランの設定 + 詳細設定 残量を表示するプラン 切り替えを行う回線 通信規制中 + クーポン切り替えのリトライ + 通信失敗時にリトライを行う + APIリミット時にリトライを行う diff --git a/app/src/test/java/pakutoma/iijmiocouponwidget/utility/CouponAPITest.kt b/app/src/test/java/pakutoma/iijmiocouponwidget/utility/CouponAPITest.kt index 9e4e6ac..8c49936 100644 --- a/app/src/test/java/pakutoma/iijmiocouponwidget/utility/CouponAPITest.kt +++ b/app/src/test/java/pakutoma/iijmiocouponwidget/utility/CouponAPITest.kt @@ -1,8 +1,6 @@ package pakutoma.iijmiocouponwidget.utility -import kotlinx.coroutines.experimental.async -import kotlinx.coroutines.experimental.launch -import kotlinx.coroutines.experimental.runBlocking +import kotlinx.coroutines.runBlocking import org.junit.Test import org.junit.Assert.* @@ -11,7 +9,7 @@ import org.junit.Assert.* * Created by PAKUTOMA on 2018/02/21. */ class CouponAPITest { - private val accessToken = "Pns2pgN62W6po8wv23v2YHzW87E0kPn1519200200" + private val accessToken = "HfXcx3zYSrG3ukkQtZjsQATkqX191aw1553251721" private val developerID = "IilCI1xrAgqKrXV9Zt4" @Test fun fetchCouponInfo() { diff --git a/build.gradle b/build.gradle index 103cdda..36a9778 100644 --- a/build.gradle +++ b/build.gradle @@ -1,13 +1,13 @@ // Top-level build file where you can add configuration options common to all sub-projects/modules. buildscript { - ext.kotlin_version = '1.2.30' + ext.kotlin_version = '1.3.21' repositories { jcenter() google() } dependencies { - classpath 'com.android.tools.build:gradle:3.0.1' + classpath 'com.android.tools.build:gradle:3.3.2' classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" classpath "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version" classpath "org.jetbrains.kotlin:kotlin-reflect:$kotlin_version" @@ -19,6 +19,7 @@ buildscript { allprojects { repositories { + mavenCentral() jcenter() google() } diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 1a59dfa..7dcd8a5 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ -#Sun Feb 18 15:01:11 JST 2018 +#Thu Mar 21 15:51:22 JST 2019 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.1-all.zip