Skip to content

Commit

Permalink
Merge branch 'release/1.9.8' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
wax911 committed Apr 10, 2022
2 parents 271c472 + 53b3f8b commit 89f0f05
Show file tree
Hide file tree
Showing 15 changed files with 234 additions and 131 deletions.
4 changes: 2 additions & 2 deletions app/.meta/version.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"code": 1090700,
"code": 1090800,
"migration": false,
"minSdk": 17,
"releaseNotes": "",
"version": "1.9.7",
"version": "1.9.8",
"appId": "com.mxt.anitrend"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package com.mxt.anitrend.base.custom.activity

import android.content.Context
import android.view.Menu
import androidx.fragment.app.FragmentActivity
import timber.log.Timber
import com.mxt.anitrend.view.activity.index.MainActivity

private fun Context.unsupportedFeature() {
Timber.i("$packageName does not support checking updates, migrate to play services")
}

private fun FragmentActivity.onLatestUpdateInstalled() {
unsupportedFeature()
}

private fun FragmentActivity.onUpdateChecked(silent: Boolean, menuItems: Menu) {
unsupportedFeature()
}

fun FragmentActivity.launchUpdateWorker(menuItems: Menu) {
unsupportedFeature()
}

fun MainActivity.checkUpdate() {
unsupportedFeature()
}
1 change: 1 addition & 0 deletions app/src/app/res/values/config.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<bool name="display_adult_content_pref">false</bool>
<bool name="display_update_channel_pref">false</bool>
</resources>
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
package com.mxt.anitrend.base.custom.activity

import android.Manifest
import android.content.Context
import android.content.pm.PackageManager
import android.view.Menu
import android.view.View
import android.widget.TextView
import android.widget.Toast
import androidx.core.app.ActivityCompat
import androidx.core.content.ContextCompat
import androidx.fragment.app.FragmentActivity
import androidx.work.WorkInfo
import androidx.work.WorkManager
import com.afollestad.materialdialogs.DialogAction
import com.mxt.anitrend.R
import com.mxt.anitrend.base.interfaces.event.BottomSheetChoice
import com.mxt.anitrend.service.DownloaderService
import com.mxt.anitrend.util.DialogUtil
import com.mxt.anitrend.util.KeyUtil
import com.mxt.anitrend.util.NotifyUtil
import timber.log.Timber
import com.mxt.anitrend.view.activity.index.MainActivity
import com.mxt.anitrend.view.sheet.BottomSheetMessage

private fun FragmentActivity.onLatestUpdateInstalled() {
NotifyUtil.createAlerter(
this,
getString(R.string.title_update_infodadat),
getString(R.string.app_no_date),
R.drawable.ic_cloud_done_white_24dp,
R.color.colorStateGreen
)
}

private fun MainActivity.onUpdateChecked(silent: Boolean, menuItems: Menu) {
val remoteVersion = presenter.database.remoteVersion

if (remoteVersion != null) {
if (remoteVersion.isNewerVersion) {
// If a new version of the application is available on GitHub
val mAppUpdateWidget = menuItems.findItem(R.id.nav_check_update)
.actionView.findViewById<TextView>(R.id.app_update_info)
mAppUpdateWidget.text = getString(R.string.app_update, remoteVersion.version)
mAppUpdateWidget.visibility = View.VISIBLE
} else if (!silent) {
onLatestUpdateInstalled()
}
}
}

fun MainActivity.launchUpdateWorker(menuItems: Menu) {
WorkManager.getInstance(this)
.getWorkInfosByTagLiveData(
KeyUtil.WorkUpdaterId
).observe(this) { workInfoList ->
workInfoList.firstOrNull { workInfo ->
workInfo.state == WorkInfo.State.SUCCEEDED
}?.run {
onUpdateChecked(
outputData.getBoolean(
KeyUtil.WorkUpdaterSilentId,
false
),
menuItems
)
}
}
}

fun MainActivity.checkUpdate() {
when (ContextCompat.checkSelfPermission(
applicationContext,
Manifest.permission.WRITE_EXTERNAL_STORAGE
)) {
PackageManager.PERMISSION_GRANTED -> {
mBottomSheet = BottomSheetMessage.Builder()
.setText(R.string.drawer_update_text)
.setTitle(R.string.drawer_update_title)
.setPositiveText(R.string.Yes)
.setNegativeText(R.string.No)
.buildWithCallback(object : BottomSheetChoice {
override fun onPositiveButton() {
val versionBase = presenter.database.remoteVersion
if (versionBase != null && versionBase.isNewerVersion)
DownloaderService.downloadNewVersion(
this@checkUpdate,
versionBase
)
else presenter.checkForUpdates(false)
}

override fun onNegativeButton() {

}
})
showBottomSheet()
}
PackageManager.PERMISSION_DENIED -> if (ActivityCompat.shouldShowRequestPermissionRationale(
this,
Manifest.permission.WRITE_EXTERNAL_STORAGE
)
)
DialogUtil.createMessage(
this,
R.string.title_permission_write,
R.string.text_permission_write
) { _, which ->
when (which) {
DialogAction.POSITIVE -> ActivityCompat.requestPermissions(
this,
arrayOf(Manifest.permission.WRITE_EXTERNAL_STORAGE),
ActivityBase.REQUEST_PERMISSION
)
DialogAction.NEGATIVE -> NotifyUtil.makeText(
this,
R.string.canceled_by_user,
Toast.LENGTH_SHORT
).show()
else -> {}
}
}
else
requestPermissionIfMissing(Manifest.permission.WRITE_EXTERNAL_STORAGE)
}
}
1 change: 1 addition & 0 deletions app/src/github/res/values/config.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<bool name="display_adult_content_pref">true</bool>
<bool name="display_update_channel_pref">true</bool>
</resources>
28 changes: 24 additions & 4 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
<activity
android:name=".view.activity.base.SettingsActivity"
android:label="@string/title_activity_settings"
android:exported="true"
android:parentActivityName=".view.activity.index.MainActivity">
<meta-data
android:name="android.support.PARENT_ACTIVITY"
Expand All @@ -56,15 +57,17 @@
</activity>
<activity
android:name=".view.activity.index.MainActivity"
android:label="@string/app_name"
android:launchMode="singleTop" />
android:launchMode="singleTop"
android:exported="true" />
<activity
android:name=".view.activity.detail.NotificationActivity"
android:label="@string/title_activity_notification"
android:launchMode="singleTop" />
android:launchMode="singleTop"
android:exported="true" />
<activity
android:name=".view.activity.detail.MessageActivity"
android:label="@string/title_activity_message" />
android:label="@string/title_activity_message"
android:exported="true"/>
<activity
android:name=".view.activity.index.LoginActivity"
android:exported="true"
Expand All @@ -83,6 +86,7 @@
</activity>
<activity
android:name=".view.activity.detail.ProfileActivity"
android:exported="true"
android:label="@string/drawer_title_profile">
<intent-filter>
<data
Expand All @@ -98,6 +102,7 @@
</activity>
<activity
android:name=".view.activity.detail.MediaActivity"
android:exported="true"
android:label="@string/title_activity_series">
<intent-filter>
<data
Expand All @@ -117,6 +122,7 @@
</activity>
<activity
android:name=".view.activity.detail.CharacterActivity"
android:exported="true"
android:label="@string/title_activity_character">
<intent-filter>
<data
Expand All @@ -132,6 +138,7 @@
</activity>
<activity
android:name=".view.activity.detail.StaffActivity"
android:exported="true"
android:label="@string/title_activity_staff">
<intent-filter>
<data
Expand All @@ -151,6 +158,7 @@
</activity>
<activity
android:name=".view.activity.detail.StudioActivity"
android:exported="true"
android:label="@string/title_activity_studio">
<intent-filter>
<data
Expand All @@ -166,27 +174,34 @@
</activity>
<activity
android:name=".view.activity.detail.FavouriteActivity"
android:exported="true"
android:label="@string/title_favourites_list" />
<activity
android:name=".view.activity.detail.MediaListActivity"
android:exported="true"
android:label="@string/title_activity_user_list_view" />
<activity
android:name=".view.activity.detail.MediaBrowseActivity"
android:exported="true"
android:launchMode="singleTop" />
<activity
android:name=".view.activity.base.AboutActivity"
android:exported="true"
android:label="@string/nav_about"
android:launchMode="singleTop" />
<activity
android:name=".view.activity.base.LoggingActivity"
android:exported="true"
android:label="@string/title_activity_logging"
android:launchMode="singleTop" />
<activity
android:name=".view.activity.index.SearchActivity"
android:exported="true"
android:label="@string/action_search"
android:launchMode="singleTop" />
<activity
android:name=".view.activity.detail.CommentActivity"
android:exported="true"
android:label="@string/title_activity_reply"
android:launchMode="singleTop">
<intent-filter>
Expand All @@ -203,6 +218,7 @@
</activity>
<activity
android:name=".view.activity.base.SharedContentActivity"
android:exported="true"
android:label="@string/menu_title_new_activity_post"
android:launchMode="singleTop"
android:theme="@style/AppThemeLight.Translucent">
Expand All @@ -217,15 +233,19 @@
</activity>
<activity
android:name=".view.activity.base.WelcomeActivity"
android:exported="true"
android:launchMode="singleTop" />
<activity
android:name=".view.activity.base.ImagePreviewActivity"
android:exported="true"
android:launchMode="singleTop" />
<activity
android:name=".view.activity.base.GiphyPreviewActivity"
android:exported="true"
android:launchMode="singleTop" />
<activity
android:name=".view.activity.base.VideoPlayerActivity"
android:exported="true"
android:configChanges="keyboardHidden|orientation|screenLayout|screenSize"
android:launchMode="singleTop" />

Expand Down
4 changes: 4 additions & 0 deletions app/src/main/java/com/mxt/anitrend/extension/ContextExt.kt
Original file line number Diff line number Diff line change
Expand Up @@ -185,4 +185,8 @@ fun Context.logFile(): File {
val log = File(logDirectory(), "${packageName}.log")
if (!log.exists()) log.mkdirs()
return log
}

fun Context.supportsAutoUpdates(): Boolean {
return resources.getBoolean(R.bool.display_update_channel_pref)
}
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ open class BasePresenter(context: Context?) : CommonPresenter(context) {
.addMigration(Migrations.MIGRATION_109_134)
.addMigration(Migrations.MIGRATION_135_136)
.addMigration(Migrations.MIGRATION_18400_18500)
.addMigration(Migrations.MIGRATION_1090700_1090800)
.build(context)
return migrationUtil.applyMigration()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.mxt.anitrend.util.migration

import android.content.Context
import com.mxt.anitrend.util.Settings
import timber.log.Timber

/**
* Creates a new migration between [startVersion] and [endVersion].
Expand All @@ -13,7 +14,9 @@ abstract class Migration(
val startVersion: Int,
val endVersion: Int
) {
abstract fun applyMigration(context: Context, settings: Settings)
open fun applyMigration(context: Context, settings: Settings) {
Timber.i("Applying migrations for $this")
}

/**
* Indicates whether some other object is "equal to" this one. Implementations must fulfil the following
Expand Down
Loading

0 comments on commit 89f0f05

Please sign in to comment.